]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Add code to handle the split ('|') in a double-quoted string.
authorQiu Shumin <shumin.qiu@intel.com>
Fri, 26 Dec 2014 08:22:35 +0000 (08:22 +0000)
committershenshushi <shenshushi@Edk2>
Fri, 26 Dec 2014 08:22:35 +0000 (08:22 +0000)
This patch update the code in function 'ContainsSplit', and make 'ContainsSplit' depend on 'FindNextInstance'. So we move 'FindNextInstance' in front of 'ContainsSplit'.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16560 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/Shell.c

index 41fa78004dcca81646bd377e7655a6506d5a9510..de46a72b44339469f6cdea0a223f600b7391e8b4 100644 (file)
@@ -100,6 +100,48 @@ TrimSpaces(
   return (EFI_SUCCESS);\r
 }\r
 \r
+/**\r
+  Parse for the next instance of one string within another string. Can optionally make sure that \r
+  the string was not escaped (^ character) per the shell specification.\r
+\r
+  @param[in] SourceString             The string to search within\r
+  @param[in] FindString               The string to look for\r
+  @param[in] CheckForEscapeCharacter  TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+FindNextInstance(\r
+  IN CONST CHAR16   *SourceString,\r
+  IN CONST CHAR16   *FindString,\r
+  IN CONST BOOLEAN  CheckForEscapeCharacter\r
+  )\r
+{\r
+  CHAR16 *Temp;\r
+  if (SourceString == NULL) {\r
+    return (NULL);\r
+  }\r
+  Temp = StrStr(SourceString, FindString);\r
+\r
+  //\r
+  // If nothing found, or we dont care about escape characters\r
+  //\r
+  if (Temp == NULL || !CheckForEscapeCharacter) {\r
+    return (Temp);\r
+  }\r
+\r
+  //\r
+  // If we found an escaped character, try again on the remainder of the string\r
+  //\r
+  if ((Temp > (SourceString)) && *(Temp-1) == L'^') {\r
+    return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);\r
+  }\r
+\r
+  //\r
+  // we found the right character\r
+  //\r
+  return (Temp);\r
+}\r
+\r
 /**\r
   Find a command line contains a split operation\r
 \r
@@ -142,7 +184,39 @@ ContainsSplit(
   )\r
 {\r
   CONST CHAR16 *TempSpot;\r
-  TempSpot = FindSplit(CmdLine);\r
+  CONST CHAR16 *FirstQuote;\r
+  CONST CHAR16 *SecondQuote;\r
+\r
+  FirstQuote    = FindNextInstance (CmdLine, L"\"", TRUE);\r
+  SecondQuote   = NULL;\r
+  TempSpot      = FindSplit(CmdLine);\r
+\r
+  if (FirstQuote == NULL    || \r
+      TempSpot == NULL      || \r
+      TempSpot == CHAR_NULL || \r
+      FirstQuote > TempSpot\r
+      ) {\r
+    return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r
+  }\r
+\r
+  while ((TempSpot != NULL) && (*TempSpot != CHAR_NULL)) {\r
+    if (FirstQuote == NULL || FirstQuote > TempSpot) {\r
+      break;\r
+    }    \r
+    SecondQuote = FindNextInstance (FirstQuote + 1, L"\"", TRUE);\r
+    if (SecondQuote == NULL) {\r
+      break;\r
+    }\r
+    if (SecondQuote < TempSpot) {\r
+      FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
+      continue;\r
+    } else {\r
+      FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
+      TempSpot = FindSplit(TempSpot + 1);\r
+      continue;\r
+    } \r
+  }\r
+  \r
   return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r
 }\r
 \r
@@ -1232,48 +1306,6 @@ ShellConvertAlias(
   return (EFI_SUCCESS);\r
 }\r
 \r
-/**\r
-  Parse for the next instance of one string within another string. Can optionally make sure that \r
-  the string was not escaped (^ character) per the shell specification.\r
-\r
-  @param[in] SourceString             The string to search within\r
-  @param[in] FindString               The string to look for\r
-  @param[in] CheckForEscapeCharacter  TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances\r
-**/\r
-CHAR16*\r
-EFIAPI\r
-FindNextInstance(\r
-  IN CONST CHAR16   *SourceString,\r
-  IN CONST CHAR16   *FindString,\r
-  IN CONST BOOLEAN  CheckForEscapeCharacter\r
-  )\r
-{\r
-  CHAR16 *Temp;\r
-  if (SourceString == NULL) {\r
-    return (NULL);\r
-  }\r
-  Temp = StrStr(SourceString, FindString);\r
-\r
-  //\r
-  // If nothing found, or we dont care about escape characters\r
-  //\r
-  if (Temp == NULL || !CheckForEscapeCharacter) {\r
-    return (Temp);\r
-  }\r
-\r
-  //\r
-  // If we found an escaped character, try again on the remainder of the string\r
-  //\r
-  if ((Temp > (SourceString)) && *(Temp-1) == L'^') {\r
-    return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);\r
-  }\r
-\r
-  //\r
-  // we found the right character\r
-  //\r
-  return (Temp);\r
-}\r
-\r
 /**\r
   This function will eliminate unreplaced (and therefore non-found) environment variables.\r
 \r