Revision: 16682
          http://sourceforge.net/p/edk2/code/16682
Author:   jcarsey
Date:     2015-01-30 16:29:20 +0000 (Fri, 30 Jan 2015)
Log Message:
-----------
ShellPkg: Refactor quote and escape search to use new function

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <[email protected]>
Signed-off-by: Joe Peterson <[email protected]>
Reviewed-by: Shumin Qiu <[email protected]>
Reviewed-by: Tapan Shah <[email protected]>

Modified Paths:
--------------
    trunk/edk2/ShellPkg/Application/Shell/ShellParametersProtocol.c

Modified: trunk/edk2/ShellPkg/Application/Shell/ShellParametersProtocol.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/ShellParametersProtocol.c     
2015-01-30 16:28:22 UTC (rev 16681)
+++ trunk/edk2/ShellPkg/Application/Shell/ShellParametersProtocol.c     
2015-01-30 16:29:20 UTC (rev 16682)
@@ -18,31 +18,6 @@
 #include "Shell.h"
 
 /**
-  Return the next location of a non-escaped character from a command line 
string;
-
-  @param[in] String        the string to parse
-  @param[in] Character     the character to look for
-
-  @retval the location of the character in the string or the end of the string
-**/
-CONST CHAR16*
-EFIAPI
-FindCharacter(
-  IN CONST CHAR16 *String,
-  IN CONST CHAR16 Character
-  )
-{
-  CONST CHAR16 *Walker;
-
-  for (Walker = String ; *Walker != Character && *Walker != CHAR_NULL; 
Walker++) {
-    if (*Walker == L'^') {
-      Walker++;
-    }
-  }
-  return Walker;
-}
-
-/**
   Return the next parameter's end from a command line string;
 
   @param[in] String        the string to parse
@@ -53,14 +28,10 @@
   IN CONST CHAR16 *String
   )
 {
-  CONST CHAR16 *NextSpace;
-  CONST CHAR16 *NextQuote;
   CONST CHAR16 *First;
   CONST CHAR16 *CloseQuote;
 
-  NextSpace = FindCharacter (String, L' ' );
-  NextQuote = FindCharacter (String, L'\"');
-  First = MIN (NextQuote, NextSpace);
+  First = FindFirstCharacter(String, L" \"", L'^');
 
   //
   // nothing, all one parameter remaining
@@ -73,14 +44,14 @@
   // If space before a quote (or neither found, i.e. both CHAR_NULL),
   // then that's the end.
   //
-  if (First == NextSpace) {
-    return (NextSpace);
+  if (*First == L' ') {
+    return (First);
   }
 
-  CloseQuote = FindCharacter (First+1, L'\"');
+  CloseQuote = FindFirstCharacter (First+1, L"\"", L'^');
 
   //
-  // We did not find a terminator... return the end of the string
+  // We did not find a terminator...
   //
   if (*CloseQuote == CHAR_NULL) {
     return (NULL);
@@ -117,7 +88,7 @@
   IN CONST UINTN  Length
   )
 {
-  CHAR16 *NextDelim;
+  CONST CHAR16 *NextDelim;
 
   if (Walker           == NULL
     ||*Walker          == NULL
@@ -145,7 +116,7 @@
     return (EFI_INVALID_PARAMETER);
   }
 
-  NextDelim = (CHAR16*)FindEndOfParameter(*Walker);
+  NextDelim = FindEndOfParameter(*Walker);
 
   if (NextDelim == NULL){
 DEBUG_CODE_BEGIN();
@@ -163,52 +134,32 @@
     (*TempParameter)[NextDelim - *Walker] = CHAR_NULL;
   }
 
-  *Walker = NextDelim;
-
   //
-  // Now remove any quotes surrounding entire parameters
+  // Update Walker for the next iteration through the function
   //
-  if ((*TempParameter)[0] == L'\"' && (*TempParameter)[StrLen 
(*TempParameter)-1] == L'\"') {
-    (*TempParameter)[StrLen (*TempParameter)-1] = CHAR_NULL;
-    CopyMem ((*TempParameter), (*TempParameter)+1, StrSize 
((*TempParameter)+1));
-  }
+  *Walker = (CHAR16*)NextDelim;
 
   //
   // Remove any non-escaped quotes in the string
+  // Remove any remaining escape characters in the string
   //
-  for (NextDelim = StrStr(*TempParameter, L"\""); NextDelim != NULL && 
*NextDelim != CHAR_NULL; NextDelim = StrStr(NextDelim, L"\"")) {
-    //
-    // Make sure I found a quote character properly.
-    //
-    ASSERT(*NextDelim == L'\"');
+  for (NextDelim = FindFirstCharacter(*TempParameter, L"\"^", CHAR_NULL) 
+    ; *NextDelim != CHAR_NULL 
+    ; NextDelim = FindFirstCharacter(NextDelim, L"\"^", CHAR_NULL)
+    ) {
+    if (*NextDelim == L'^') {
 
-    //
-    // Only remove quotes that do not have a preceeding ^
-    //
-    if ((NextDelim > (*TempParameter) && (*(NextDelim - 1) != L'^')) || 
(NextDelim == (*TempParameter))) {
-      CopyMem (NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
-    } else {
+      //
+      // eliminate the escape ^
+      //
+      CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
       NextDelim++;
-    }
-  }
+    } else if (*NextDelim == L'\"') {
 
-  //
-  // Remove any escape charactersin the parameter before returning it
-  // all escape character processing is complete at this time
-  //
-  for (NextDelim = StrStr(*TempParameter, L"^"); NextDelim != NULL && 
*NextDelim != CHAR_NULL; NextDelim = StrStr(NextDelim, L"^")) {
-    //
-    // Make sure I found an escape character properly.
-    //
-    ASSERT(*NextDelim == L'^');
-
-    CopyMem (NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
-
-    //
-    // If we had 2 escapes in a row, leave one behind
-    //
-    if (*NextDelim == L'^') {
-      NextDelim++;
+      //
+      // eliminate the unescaped quote
+      //
+      CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
     }
   }
 


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to