\r
#include "Shell.h"\r
\r
-/**\r
- Return the next location of a non-escaped character from a command line string;\r
-\r
- @param[in] String the string to parse\r
- @param[in] Character the character to look for\r
-\r
- @retval the location of the character in the string or the end of the string\r
-**/\r
-CONST CHAR16*\r
-EFIAPI\r
-FindCharacter(\r
- IN CONST CHAR16 *String,\r
- IN CONST CHAR16 Character\r
- )\r
-{\r
- CONST CHAR16 *Walker;\r
-\r
- for (Walker = String ; *Walker != Character && *Walker != CHAR_NULL; Walker++) {\r
- if (*Walker == L'^') {\r
- Walker++;\r
- }\r
- }\r
- return Walker;\r
-}\r
-\r
/**\r
Return the next parameter's end from a command line string;\r
\r
IN CONST CHAR16 *String\r
)\r
{\r
- CONST CHAR16 *NextSpace;\r
- CONST CHAR16 *NextQuote;\r
CONST CHAR16 *First;\r
CONST CHAR16 *CloseQuote;\r
\r
- NextSpace = FindCharacter (String, L' ' );\r
- NextQuote = FindCharacter (String, L'\"');\r
- First = MIN (NextQuote, NextSpace);\r
+ First = FindFirstCharacter(String, L" \"", L'^');\r
\r
//\r
// nothing, all one parameter remaining\r
// If space before a quote (or neither found, i.e. both CHAR_NULL),\r
// then that's the end.\r
//\r
- if (First == NextSpace) {\r
- return (NextSpace);\r
+ if (*First == L' ') {\r
+ return (First);\r
}\r
\r
- CloseQuote = FindCharacter (First+1, L'\"');\r
+ CloseQuote = FindFirstCharacter (First+1, L"\"", L'^');\r
\r
//\r
- // We did not find a terminator... return the end of the string\r
+ // We did not find a terminator...\r
//\r
if (*CloseQuote == CHAR_NULL) {\r
return (NULL);\r
IN CONST UINTN Length\r
)\r
{\r
- CHAR16 *NextDelim;\r
+ CONST CHAR16 *NextDelim;\r
\r
if (Walker == NULL\r
||*Walker == NULL\r
return (EFI_INVALID_PARAMETER);\r
}\r
\r
- NextDelim = (CHAR16*)FindEndOfParameter(*Walker);\r
+ NextDelim = FindEndOfParameter(*Walker);\r
\r
if (NextDelim == NULL){\r
DEBUG_CODE_BEGIN();\r
(*TempParameter)[NextDelim - *Walker] = CHAR_NULL;\r
}\r
\r
- *Walker = NextDelim;\r
-\r
//\r
- // Now remove any quotes surrounding entire parameters\r
+ // Update Walker for the next iteration through the function\r
//\r
- if ((*TempParameter)[0] == L'\"' && (*TempParameter)[StrLen (*TempParameter)-1] == L'\"') {\r
- (*TempParameter)[StrLen (*TempParameter)-1] = CHAR_NULL;\r
- CopyMem ((*TempParameter), (*TempParameter)+1, StrSize ((*TempParameter)+1));\r
- }\r
+ *Walker = (CHAR16*)NextDelim;\r
\r
//\r
// Remove any non-escaped quotes in the string\r
+ // Remove any remaining escape characters in the string\r
//\r
- for (NextDelim = StrStr(*TempParameter, L"\""); NextDelim != NULL && *NextDelim != CHAR_NULL; NextDelim = StrStr(NextDelim, L"\"")) {\r
- //\r
- // Make sure I found a quote character properly.\r
- //\r
- ASSERT(*NextDelim == L'\"');\r
+ for (NextDelim = FindFirstCharacter(*TempParameter, L"\"^", CHAR_NULL) \r
+ ; *NextDelim != CHAR_NULL \r
+ ; NextDelim = FindFirstCharacter(NextDelim, L"\"^", CHAR_NULL)\r
+ ) {\r
+ if (*NextDelim == L'^') {\r
\r
- //\r
- // Only remove quotes that do not have a preceeding ^\r
- //\r
- if ((NextDelim > (*TempParameter) && (*(NextDelim - 1) != L'^')) || (NextDelim == (*TempParameter))) {\r
- CopyMem (NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
- } else {\r
+ //\r
+ // eliminate the escape ^\r
+ //\r
+ CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
NextDelim++;\r
- }\r
- }\r
+ } else if (*NextDelim == L'\"') {\r
\r
- //\r
- // Remove any escape charactersin the parameter before returning it\r
- // all escape character processing is complete at this time\r
- //\r
- for (NextDelim = StrStr(*TempParameter, L"^"); NextDelim != NULL && *NextDelim != CHAR_NULL; NextDelim = StrStr(NextDelim, L"^")) {\r
- //\r
- // Make sure I found an escape character properly.\r
- //\r
- ASSERT(*NextDelim == L'^');\r
-\r
- CopyMem (NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
-\r
- //\r
- // If we had 2 escapes in a row, leave one behind\r
- //\r
- if (*NextDelim == L'^') {\r
- NextDelim++;\r
+ //\r
+ // eliminate the unescaped quote\r
+ //\r
+ CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
}\r
}\r
\r