ShellPkg: Move FindFirstCharacter/GetNextParameter to ShellCommandLib
And add Shell prefix to the two library APIs. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
This commit is contained in:
@ -213,7 +213,7 @@ ContainsSplit(
|
||||
|
||||
FirstQuote = FindNextInstance (CmdLine, L"\"", TRUE);
|
||||
SecondQuote = NULL;
|
||||
TempSpot = FindFirstCharacter(CmdLine, L"|", L'^');
|
||||
TempSpot = ShellFindFirstCharacter(CmdLine, L"|", TRUE);
|
||||
|
||||
if (FirstQuote == NULL ||
|
||||
TempSpot == NULL ||
|
||||
@ -236,7 +236,7 @@ ContainsSplit(
|
||||
continue;
|
||||
} else {
|
||||
FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);
|
||||
TempSpot = FindFirstCharacter(TempSpot + 1, L"|", L'^');
|
||||
TempSpot = ShellFindFirstCharacter(TempSpot + 1, L"|", TRUE);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -716,6 +716,7 @@ FreeResources:
|
||||
}
|
||||
|
||||
ShellFreeEnvVarList ();
|
||||
ShellSetRawCmdLine (NULL);
|
||||
|
||||
if (ShellCommandGetExit()) {
|
||||
return ((EFI_STATUS)ShellCommandGetExitCode());
|
||||
@ -1992,7 +1993,7 @@ IsValidSplit(
|
||||
return (EFI_OUT_OF_RESOURCES);
|
||||
}
|
||||
TempWalker = (CHAR16*)Temp;
|
||||
if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine), TRUE))) {
|
||||
if (!EFI_ERROR (ShellGetNextParameter (&TempWalker, FirstParameter, StrSize(CmdLine), TRUE))) {
|
||||
if (GetOperationType(FirstParameter) == Unknown_Invalid) {
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
|
||||
SetLastError(SHELL_NOT_FOUND);
|
||||
@ -2041,7 +2042,7 @@ VerifySplit(
|
||||
//
|
||||
// recurse to verify the next item
|
||||
//
|
||||
TempSpot = FindFirstCharacter(CmdLine, L"|", L'^') + 1;
|
||||
TempSpot = ShellFindFirstCharacter(CmdLine, L"|", TRUE) + 1;
|
||||
if (*TempSpot == L'a' &&
|
||||
(*(TempSpot + 1) == L' ' || *(TempSpot + 1) == CHAR_NULL)
|
||||
) {
|
||||
@ -2158,7 +2159,7 @@ DoHelpUpdate(
|
||||
|
||||
Walker = *CmdLine;
|
||||
while(Walker != NULL && *Walker != CHAR_NULL) {
|
||||
if (!EFI_ERROR(GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine), TRUE))) {
|
||||
if (!EFI_ERROR (ShellGetNextParameter (&Walker, CurrentParameter, StrSize(*CmdLine), TRUE))) {
|
||||
if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {
|
||||
CurrentParameter[0] = L' ';
|
||||
CurrentParameter[1] = L' ';
|
||||
@ -2589,6 +2590,7 @@ RunShellCommand(
|
||||
CHAR16 *FirstParameter;
|
||||
CHAR16 *TempWalker;
|
||||
SHELL_OPERATION_TYPES Type;
|
||||
CHAR16 *OldCmdLine;
|
||||
|
||||
ASSERT(CmdLine != NULL);
|
||||
if (StrLen(CmdLine) == 0) {
|
||||
@ -2596,11 +2598,14 @@ RunShellCommand(
|
||||
}
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
FirstParameter = NULL;
|
||||
CleanOriginal = NULL;
|
||||
OldCmdLine = NULL;
|
||||
|
||||
CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);
|
||||
if (CleanOriginal == NULL) {
|
||||
return (EFI_OUT_OF_RESOURCES);
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
TrimSpaces(&CleanOriginal);
|
||||
@ -2627,35 +2632,36 @@ RunShellCommand(
|
||||
// Handle case that passed in command line is just 1 or more " " characters.
|
||||
//
|
||||
if (StrLen (CleanOriginal) == 0) {
|
||||
SHELL_FREE_NON_NULL(CleanOriginal);
|
||||
return (EFI_SUCCESS);
|
||||
Status = EFI_SUCCESS;
|
||||
goto Done;
|
||||
}
|
||||
|
||||
Status = ProcessCommandLineToFinal(&CleanOriginal);
|
||||
if (EFI_ERROR(Status)) {
|
||||
SHELL_FREE_NON_NULL(CleanOriginal);
|
||||
return (Status);
|
||||
goto Done;
|
||||
}
|
||||
|
||||
OldCmdLine = ShellGetRawCmdLine ();
|
||||
ShellSetRawCmdLine (CleanOriginal);
|
||||
|
||||
//
|
||||
// We don't do normal processing with a split command line (output from one command input to another)
|
||||
//
|
||||
if (ContainsSplit(CleanOriginal)) {
|
||||
Status = ProcessNewSplitCommandLine(CleanOriginal);
|
||||
SHELL_FREE_NON_NULL(CleanOriginal);
|
||||
return (Status);
|
||||
}
|
||||
goto Done;
|
||||
}
|
||||
|
||||
//
|
||||
// We need the first parameter information so we can determine the operation type
|
||||
//
|
||||
FirstParameter = AllocateZeroPool(StrSize(CleanOriginal));
|
||||
if (FirstParameter == NULL) {
|
||||
SHELL_FREE_NON_NULL(CleanOriginal);
|
||||
return (EFI_OUT_OF_RESOURCES);
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto Done;
|
||||
}
|
||||
TempWalker = CleanOriginal;
|
||||
if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal), TRUE))) {
|
||||
if (!EFI_ERROR (ShellGetNextParameter (&TempWalker, FirstParameter, StrSize(CleanOriginal), TRUE))) {
|
||||
//
|
||||
// Depending on the first parameter we change the behavior
|
||||
//
|
||||
@ -2680,9 +2686,12 @@ RunShellCommand(
|
||||
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);
|
||||
SetLastError(SHELL_NOT_FOUND);
|
||||
}
|
||||
|
||||
SHELL_FREE_NON_NULL(CleanOriginal);
|
||||
SHELL_FREE_NON_NULL(FirstParameter);
|
||||
|
||||
Done:
|
||||
ShellSetRawCmdLine (OldCmdLine);
|
||||
SHELL_FREE_NON_NULL (OldCmdLine);
|
||||
SHELL_FREE_NON_NULL (CleanOriginal);
|
||||
SHELL_FREE_NON_NULL (FirstParameter);
|
||||
|
||||
return (Status);
|
||||
}
|
||||
@ -3120,37 +3129,3 @@ RunScriptFile (
|
||||
return (Status);
|
||||
}
|
||||
|
||||
/**
|
||||
Return the pointer to the first occurrence of any character from a list of characters.
|
||||
|
||||
@param[in] String the string to parse
|
||||
@param[in] CharacterList the list of character to look for
|
||||
@param[in] EscapeCharacter An escape character to skip
|
||||
|
||||
@return the location of the first character in the string
|
||||
@retval CHAR_NULL no instance of any character in CharacterList was found in String
|
||||
**/
|
||||
CONST CHAR16*
|
||||
EFIAPI
|
||||
FindFirstCharacter(
|
||||
IN CONST CHAR16 *String,
|
||||
IN CONST CHAR16 *CharacterList,
|
||||
IN CONST CHAR16 EscapeCharacter
|
||||
)
|
||||
{
|
||||
UINT32 WalkChar;
|
||||
UINT32 WalkStr;
|
||||
|
||||
for (WalkStr = 0; WalkStr < StrLen(String); WalkStr++) {
|
||||
if (String[WalkStr] == EscapeCharacter) {
|
||||
WalkStr++;
|
||||
continue;
|
||||
}
|
||||
for (WalkChar = 0; WalkChar < StrLen(CharacterList); WalkChar++) {
|
||||
if (String[WalkStr] == CharacterList[WalkChar]) {
|
||||
return (&String[WalkStr]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (String + StrLen(String));
|
||||
}
|
||||
|
Reference in New Issue
Block a user