manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.\r
\r
Copyright (C) 2014, Red Hat, Inc.\r
- Copyright (c) 2013 Hewlett-Packard Development Company, L.P.\r
+ (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r
Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\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
+ Return the next parameter's end from a command line string.\r
\r
@param[in] String the string to parse\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
}\r
\r
/**\r
- Return the next parameter from a command line string;\r
+ Return the next parameter from a command line string.\r
\r
This function moves the next parameter from Walker into TempParameter and moves\r
Walker up past that parameter for recursive calling. When the final parameter\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
return (EFI_NOT_FOUND);\r
}\r
\r
- StrnCpy(*TempParameter, (*Walker), NextDelim - *Walker);\r
+ StrnCpyS(*TempParameter, Length, (*Walker), NextDelim - *Walker);\r
\r
//\r
// Add a CHAR_NULL if we didnt get one via the copy\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
//\r
// re-populate the string to support any filenames that were in quotes.\r
//\r
- StrnCpy(CommandLineCopy, NewCommandLine, StrLen(NewCommandLine));\r
+ StrnCpyS(CommandLineCopy, StrSize(CommandLineCopy)/sizeof(CHAR16), NewCommandLine, StrLen(NewCommandLine));\r
\r
if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)\r
&& ((UINTN)(FirstLocation - CommandLineCopy) < StrLen(NewCommandLine))\r