\r
FirstQuote = FindNextInstance (CmdLine, L"\"", TRUE);\r
SecondQuote = NULL;\r
- TempSpot = ShellFindFirstCharacter(CmdLine, L"|", TRUE);\r
+ TempSpot = FindFirstCharacter(CmdLine, L"|", L'^');\r
\r
if (FirstQuote == NULL || \r
TempSpot == NULL || \r
continue;\r
} else {\r
FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
- TempSpot = ShellFindFirstCharacter(TempSpot + 1, L"|", TRUE);\r
+ TempSpot = FindFirstCharacter(TempSpot + 1, L"|", L'^');\r
continue;\r
} \r
}\r
}\r
\r
ShellFreeEnvVarList ();\r
- ShellSetRawCmdLine (NULL);\r
\r
if (ShellCommandGetExit()) {\r
return ((EFI_STATUS)ShellCommandGetExitCode());\r
return (EFI_OUT_OF_RESOURCES);\r
}\r
TempWalker = (CHAR16*)Temp;\r
- if (!EFI_ERROR (ShellGetNextParameter (&TempWalker, FirstParameter, StrSize(CmdLine), TRUE))) {\r
+ if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine), TRUE))) {\r
if (GetOperationType(FirstParameter) == Unknown_Invalid) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
SetLastError(SHELL_NOT_FOUND);\r
//\r
// recurse to verify the next item\r
//\r
- TempSpot = ShellFindFirstCharacter(CmdLine, L"|", TRUE) + 1;\r
+ TempSpot = FindFirstCharacter(CmdLine, L"|", L'^') + 1;\r
if (*TempSpot == L'a' && \r
(*(TempSpot + 1) == L' ' || *(TempSpot + 1) == CHAR_NULL)\r
) {\r
\r
Walker = *CmdLine;\r
while(Walker != NULL && *Walker != CHAR_NULL) {\r
- if (!EFI_ERROR (ShellGetNextParameter (&Walker, CurrentParameter, StrSize(*CmdLine), TRUE))) {\r
+ if (!EFI_ERROR(GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine), TRUE))) {\r
if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {\r
CurrentParameter[0] = L' ';\r
CurrentParameter[1] = L' ';\r
CHAR16 *FirstParameter;\r
CHAR16 *TempWalker;\r
SHELL_OPERATION_TYPES Type;\r
- CHAR16 *OldCmdLine;\r
\r
ASSERT(CmdLine != NULL);\r
if (StrLen(CmdLine) == 0) {\r
}\r
\r
Status = EFI_SUCCESS;\r
- FirstParameter = NULL;\r
CleanOriginal = NULL;\r
- OldCmdLine = NULL;\r
\r
CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);\r
if (CleanOriginal == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Done;\r
+ return (EFI_OUT_OF_RESOURCES);\r
}\r
\r
TrimSpaces(&CleanOriginal);\r
// Handle case that passed in command line is just 1 or more " " characters.\r
//\r
if (StrLen (CleanOriginal) == 0) {\r
- Status = EFI_SUCCESS;\r
- goto Done;\r
+ SHELL_FREE_NON_NULL(CleanOriginal);\r
+ return (EFI_SUCCESS);\r
}\r
\r
Status = ProcessCommandLineToFinal(&CleanOriginal);\r
if (EFI_ERROR(Status)) {\r
- goto Done;\r
+ SHELL_FREE_NON_NULL(CleanOriginal);\r
+ return (Status);\r
}\r
\r
- OldCmdLine = ShellGetRawCmdLine ();\r
- ShellSetRawCmdLine (CleanOriginal);\r
-\r
//\r
// We don't do normal processing with a split command line (output from one command input to another)\r
//\r
if (ContainsSplit(CleanOriginal)) {\r
Status = ProcessNewSplitCommandLine(CleanOriginal);\r
- goto Done;\r
- }\r
+ SHELL_FREE_NON_NULL(CleanOriginal);\r
+ return (Status);\r
+ } \r
\r
//\r
// We need the first parameter information so we can determine the operation type\r
//\r
FirstParameter = AllocateZeroPool(StrSize(CleanOriginal));\r
if (FirstParameter == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto Done;\r
+ SHELL_FREE_NON_NULL(CleanOriginal);\r
+ return (EFI_OUT_OF_RESOURCES);\r
}\r
TempWalker = CleanOriginal;\r
- if (!EFI_ERROR (ShellGetNextParameter (&TempWalker, FirstParameter, StrSize(CleanOriginal), TRUE))) {\r
+ if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal), TRUE))) {\r
//\r
// Depending on the first parameter we change the behavior\r
//\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
SetLastError(SHELL_NOT_FOUND);\r
}\r
-\r
-Done:\r
- ShellSetRawCmdLine (OldCmdLine);\r
- SHELL_FREE_NON_NULL (OldCmdLine);\r
- SHELL_FREE_NON_NULL (CleanOriginal);\r
- SHELL_FREE_NON_NULL (FirstParameter);\r
+ \r
+ SHELL_FREE_NON_NULL(CleanOriginal);\r
+ SHELL_FREE_NON_NULL(FirstParameter);\r
\r
return (Status);\r
}\r
return (Status);\r
}\r
\r
+/**\r
+ Return the pointer to the first occurrence of any character from a list of characters.\r
+\r
+ @param[in] String the string to parse\r
+ @param[in] CharacterList the list of character to look for\r
+ @param[in] EscapeCharacter An escape character to skip\r
+\r
+ @return the location of the first character in the string\r
+ @retval CHAR_NULL no instance of any character in CharacterList was found in String\r
+**/\r
+CONST CHAR16*\r
+EFIAPI\r
+FindFirstCharacter(\r
+ IN CONST CHAR16 *String,\r
+ IN CONST CHAR16 *CharacterList,\r
+ IN CONST CHAR16 EscapeCharacter\r
+ )\r
+{\r
+ UINT32 WalkChar;\r
+ UINT32 WalkStr;\r
+\r
+ for (WalkStr = 0; WalkStr < StrLen(String); WalkStr++) {\r
+ if (String[WalkStr] == EscapeCharacter) {\r
+ WalkStr++;\r
+ continue;\r
+ }\r
+ for (WalkChar = 0; WalkChar < StrLen(CharacterList); WalkChar++) {\r
+ if (String[WalkStr] == CharacterList[WalkChar]) {\r
+ return (&String[WalkStr]);\r
+ }\r
+ }\r
+ }\r
+ return (String + StrLen(String));\r
+}\r
IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r
);\r
\r
+/**\r
+ Return the pointer to the first occurrence of any character from a list of characters.\r
+\r
+ @param[in] String the string to parse\r
+ @param[in] CharacterList the list of character to look for\r
+ @param[in] EscapeCharacter An escape character to skip\r
+\r
+ @return the location of the first character in the string\r
+ @retval CHAR_NULL no instance of any character in CharacterList was found in String\r
+**/\r
+CONST CHAR16*\r
+EFIAPI\r
+FindFirstCharacter(\r
+ IN CONST CHAR16 *String,\r
+ IN CONST CHAR16 *CharacterList,\r
+ IN CONST CHAR16 EscapeCharacter\r
+ );\r
+\r
/**\r
Cleans off leading and trailing spaces and tabs.\r
\r
\r
BOOLEAN AsciiRedirection = FALSE;\r
\r
+/**\r
+ Return the next parameter's end from a command line string.\r
+\r
+ @param[in] String the string to parse\r
+**/\r
+CONST CHAR16*\r
+EFIAPI\r
+FindEndOfParameter(\r
+ IN CONST CHAR16 *String\r
+ )\r
+{\r
+ CONST CHAR16 *First;\r
+ CONST CHAR16 *CloseQuote;\r
+\r
+ First = FindFirstCharacter(String, L" \"", L'^');\r
+\r
+ //\r
+ // nothing, all one parameter remaining\r
+ //\r
+ if (*First == CHAR_NULL) {\r
+ return (First);\r
+ }\r
+\r
+ //\r
+ // If space before a quote (or neither found, i.e. both CHAR_NULL),\r
+ // then that's the end.\r
+ //\r
+ if (*First == L' ') {\r
+ return (First);\r
+ }\r
+\r
+ CloseQuote = FindFirstCharacter (First+1, L"\"", L'^');\r
+\r
+ //\r
+ // We did not find a terminator...\r
+ //\r
+ if (*CloseQuote == CHAR_NULL) {\r
+ return (NULL);\r
+ }\r
+\r
+ return (FindEndOfParameter (CloseQuote+1));\r
+}\r
+\r
+/**\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
+ is moved *Walker will be set to NULL;\r
+\r
+ Temp Parameter must be large enough to hold the parameter before calling this\r
+ function.\r
+\r
+ This will also remove all remaining ^ characters after processing.\r
+\r
+ @param[in, out] Walker pointer to string of command line. Adjusted to\r
+ reminaing command line on return\r
+ @param[in, out] TempParameter pointer to string of command line item extracted.\r
+ @param[in] Length buffer size of TempParameter.\r
+ @param[in] StripQuotation if TRUE then strip the quotation marks surrounding\r
+ the parameters.\r
+\r
+ @return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.\r
+ @return EFI_NOT_FOUND A closing " could not be found on the specified string\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetNextParameter(\r
+ IN OUT CHAR16 **Walker,\r
+ IN OUT CHAR16 **TempParameter,\r
+ IN CONST UINTN Length,\r
+ IN BOOLEAN StripQuotation\r
+ )\r
+{\r
+ CONST CHAR16 *NextDelim;\r
+\r
+ if (Walker == NULL\r
+ ||*Walker == NULL\r
+ ||TempParameter == NULL\r
+ ||*TempParameter == NULL\r
+ ){\r
+ return (EFI_INVALID_PARAMETER);\r
+ }\r
+\r
+\r
+ //\r
+ // make sure we dont have any leading spaces\r
+ //\r
+ while ((*Walker)[0] == L' ') {\r
+ (*Walker)++;\r
+ }\r
+\r
+ //\r
+ // make sure we still have some params now...\r
+ //\r
+ if (StrLen(*Walker) == 0) {\r
+DEBUG_CODE_BEGIN();\r
+ *Walker = NULL;\r
+DEBUG_CODE_END();\r
+ return (EFI_INVALID_PARAMETER);\r
+ }\r
+\r
+ NextDelim = FindEndOfParameter(*Walker);\r
+\r
+ if (NextDelim == NULL){\r
+DEBUG_CODE_BEGIN();\r
+ *Walker = NULL;\r
+DEBUG_CODE_END();\r
+ return (EFI_NOT_FOUND);\r
+ }\r
+\r
+ StrnCpyS(*TempParameter, Length / sizeof(CHAR16), (*Walker), NextDelim - *Walker);\r
+\r
+ //\r
+ // Add a CHAR_NULL if we didnt get one via the copy\r
+ //\r
+ if (*NextDelim != CHAR_NULL) {\r
+ (*TempParameter)[NextDelim - *Walker] = CHAR_NULL;\r
+ }\r
+\r
+ //\r
+ // Update Walker for the next iteration through the function\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 = FindFirstCharacter(*TempParameter, L"\"^", CHAR_NULL) \r
+ ; *NextDelim != CHAR_NULL \r
+ ; NextDelim = FindFirstCharacter(NextDelim, L"\"^", CHAR_NULL)\r
+ ) {\r
+ if (*NextDelim == L'^') {\r
+\r
+ //\r
+ // eliminate the escape ^\r
+ //\r
+ CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
+ NextDelim++;\r
+ } else if (*NextDelim == L'\"') {\r
+\r
+ //\r
+ // eliminate the unescaped quote\r
+ //\r
+ if (StripQuotation) {\r
+ CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
+ } else{\r
+ NextDelim++;\r
+ }\r
+ }\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
/**\r
Function to populate Argc and Argv.\r
\r
; Walker != NULL && *Walker != CHAR_NULL\r
; Count++\r
) {\r
- if (EFI_ERROR (ShellGetNextParameter (&Walker, TempParameter, Size, TRUE))) {\r
+ if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, TRUE))) {\r
break;\r
}\r
}\r
Walker = (CHAR16*)NewCommandLine;\r
while(Walker != NULL && *Walker != CHAR_NULL) {\r
SetMem16(TempParameter, Size, CHAR_NULL);\r
- if (EFI_ERROR (ShellGetNextParameter (&Walker, TempParameter, Size, StripQuotation))) {\r
+ if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, StripQuotation))) {\r
Status = EFI_INVALID_PARAMETER;\r
goto Done;\r
}\r
IN OUT UINTN *Argc\r
);\r
\r
+/**\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
+ is moved *Walker will be set to NULL;\r
+\r
+ Temp Parameter must be large enough to hold the parameter before calling this\r
+ function.\r
+\r
+ @param[in, out] Walker pointer to string of command line. Adjusted to\r
+ reminaing command line on return\r
+ @param[in, out] TempParameter pointer to string of command line item extracted.\r
+ @param[in] Length Length of (*TempParameter) in bytes\r
+ @param[in] StripQuotation if TRUE then strip the quotation marks surrounding\r
+ the parameters.\r
+\r
+ @return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.\r
+ @return EFI_NOT_FOUND A closing " could not be found on the specified string\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetNextParameter(\r
+ IN OUT CHAR16 **Walker,\r
+ IN OUT CHAR16 **TempParameter,\r
+ IN CONST UINTN Length,\r
+ IN BOOLEAN StripQuotation\r
+ );\r
+\r
#endif //_SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_\r
\r
IN UINTN DataSize,\r
IN VOID *UserData\r
);\r
-\r
-/**\r
- Return the pointer to the first occurrence of any character from a list of characters.\r
-\r
- @param[in] String The string to parse\r
- @param[in] CharacterList The list of character to look for\r
- @param[in] IgnoreEscapedCharacter TRUE to ignore escaped characters\r
-\r
- @return The location of the first character in the String.\r
- @return Pointer to the ending NULL character of the String.\r
-**/\r
-CONST CHAR16*\r
-EFIAPI\r
-ShellFindFirstCharacter (\r
- IN CONST CHAR16 *String,\r
- IN CONST CHAR16 *CharacterList,\r
- IN CONST BOOLEAN IgnoreEscapedCharacter\r
- );\r
-\r
-/**\r
- return the next parameter from a command line string;\r
-\r
- This function moves the next parameter from Walker into NextParameter and moves\r
- Walker up past that parameter for recursive calling. When the final parameter\r
- is moved *Walker will be set to NULL;\r
-\r
- @param[in, out] Walker pointer to string of command line. Adjusted to\r
- reminaing command line on return\r
- @param[in, out] NextParameter string of command line item extracted.\r
- @param[in] Length Length of TempParameter in bytes\r
- @param[in] StripQuotation if TRUE then strip the quotation marks surrounding\r
- the parameters.\r
-\r
- @return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.\r
- @return EFI_NOT_FOUND A closing " could not be found on the specified string\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ShellGetNextParameter(\r
- IN OUT CHAR16 **Walker,\r
- IN OUT CHAR16 *NextParameter,\r
- IN CONST UINTN Length,\r
- IN BOOLEAN StripQuotation\r
- );\r
-\r
#endif //_SHELL_COMMAND_LIB_\r
return (EFI_SUCCESS);\r
}\r
\r
-/**\r
- Return the pointer to the first occurrence of any character from a list of characters.\r
-\r
- @param[in] String The string to parse\r
- @param[in] CharacterList The list of character to look for\r
- @param[in] IgnoreEscapedCharacter TRUE to ignore escaped characters\r
-\r
- @return The location of the first character in the String.\r
- @return Pointer to the ending NULL character of the String.\r
-**/\r
-CONST CHAR16*\r
-EFIAPI\r
-ShellFindFirstCharacter (\r
- IN CONST CHAR16 *String,\r
- IN CONST CHAR16 *CharacterList,\r
- IN CONST BOOLEAN IgnoreEscapedCharacter\r
- )\r
-{\r
- UINTN WalkChar;\r
- UINTN WalkStr;\r
-\r
- for (WalkStr = 0; WalkStr < StrLen (String); WalkStr++) {\r
- if (IgnoreEscapedCharacter && (String[WalkStr] == L'^')) {\r
- WalkStr++;\r
- continue;\r
- }\r
- for (WalkChar = 0; WalkChar < StrLen (CharacterList); WalkChar++) {\r
- if (String[WalkStr] == CharacterList[WalkChar]) {\r
- return &String[WalkStr];\r
- }\r
- }\r
- }\r
- return &String[WalkStr];\r
-}\r
-\r
-/**\r
- Return the next parameter's end from a command line string.\r
-\r
- @param[in] String the string to parse\r
-**/\r
-CONST CHAR16*\r
-FindEndOfParameter(\r
- IN CONST CHAR16 *String\r
- )\r
-{\r
- CONST CHAR16 *First;\r
- CONST CHAR16 *CloseQuote;\r
-\r
- First = ShellFindFirstCharacter (String, L" \"", TRUE);\r
-\r
- //\r
- // nothing, all one parameter remaining\r
- //\r
- if (*First == CHAR_NULL) {\r
- return (First);\r
- }\r
-\r
- //\r
- // If space before a quote (or neither found, i.e. both CHAR_NULL),\r
- // then that's the end.\r
- //\r
- if (*First == L' ') {\r
- return (First);\r
- }\r
-\r
- CloseQuote = ShellFindFirstCharacter (First+1, L"\"", TRUE);\r
-\r
- //\r
- // We did not find a terminator...\r
- //\r
- if (*CloseQuote == CHAR_NULL) {\r
- return (NULL);\r
- }\r
-\r
- return (FindEndOfParameter (CloseQuote+1));\r
-}\r
-\r
-/**\r
- Return the next parameter from a command line string.\r
-\r
- This function moves the next parameter from Walker into NextParameter and moves\r
- Walker up past that parameter for recursive calling. When the final parameter\r
- is moved *Walker will be set to NULL;\r
-\r
- This will also remove all remaining ^ characters after processing.\r
-\r
- @param[in, out] Walker pointer to string of command line. Adjusted to\r
- reminaing command line on return\r
- @param[in, out] NextParameter pointer to string of command line item extracted.\r
- @param[in] Length buffer size of TempParameter.\r
- @param[in] StripQuotation if TRUE then strip the quotation marks surrounding\r
- the parameters.\r
-\r
- @return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.\r
- @return EFI_NOT_FOUND A closing " could not be found on the specified string\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ShellGetNextParameter (\r
- IN OUT CHAR16 **Walker,\r
- IN OUT CHAR16 *NextParameter,\r
- IN CONST UINTN Length,\r
- IN BOOLEAN StripQuotation\r
- )\r
-{\r
- CONST CHAR16 *NextDelim;\r
-\r
- if (Walker == NULL\r
- ||*Walker == NULL\r
- ||NextParameter == NULL\r
- ){\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // make sure we dont have any leading spaces\r
- //\r
- while ((*Walker)[0] == L' ') {\r
- (*Walker)++;\r
- }\r
-\r
- //\r
- // make sure we still have some params now...\r
- //\r
- if (StrLen(*Walker) == 0) {\r
- DEBUG_CODE (\r
- *Walker = NULL;\r
- );\r
- return (EFI_INVALID_PARAMETER);\r
- }\r
-\r
- NextDelim = FindEndOfParameter(*Walker);\r
-\r
- if (NextDelim == NULL){\r
- DEBUG_CODE (\r
- *Walker = NULL;\r
- );\r
- return (EFI_NOT_FOUND);\r
- }\r
-\r
- StrnCpyS(NextParameter, Length / sizeof(CHAR16), (*Walker), NextDelim - *Walker);\r
-\r
- //\r
- // Add a CHAR_NULL if we didnt get one via the copy\r
- //\r
- if (*NextDelim != CHAR_NULL) {\r
- NextParameter[NextDelim - *Walker] = CHAR_NULL;\r
- }\r
-\r
- //\r
- // Update Walker for the next iteration through the function\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 = ShellFindFirstCharacter(NextParameter, L"\"^", FALSE)\r
- ; *NextDelim != CHAR_NULL\r
- ; NextDelim = ShellFindFirstCharacter(NextDelim, L"\"^", FALSE)\r
- ) {\r
- if (*NextDelim == L'^') {\r
-\r
- //\r
- // eliminate the escape ^\r
- //\r
- CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
- NextDelim++;\r
- } else if (*NextDelim == L'\"') {\r
-\r
- //\r
- // eliminate the unescaped quote\r
- //\r
- if (StripQuotation) {\r
- CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));\r
- } else {\r
- NextDelim++;\r
- }\r
- }\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
/**\r
Constructor for the Shell Command library.\r
\r