ShellPkg: Refactor Variable replacement into separate function

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14974 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Jaben Carsey
2013-12-12 21:44:23 +00:00
committed by jcarsey
parent ca53c0af00
commit 1ef61d0390

View File

@ -1430,6 +1430,32 @@ RunSplitCommand(
return (Status); return (Status);
} }
/**
Take the original command line, substitute any variables, free
the original string, return the modified copy
@param[in] CmdLine pointer to the command line to update
@param[out]CmdName upon successful return the name of the command to be run
@retval EFI_SUCCESS the function was successful
@retval EFI_OUT_OF_RESOURCES a memory allocation failed
**/
EFI_STATUS
EFIAPI
ShellSubstituteVariables(
IN CHAR16 **CmdLine
)
{
CHAR16 *NewCmdLine;
NewCmdLine = ShellConvertVariables(*CmdLine);
SHELL_FREE_NON_NULL(*CmdLine);
if (NewCmdLine == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
*CmdLine = NewCmdLine;
return (EFI_SUCCESS);
}
/** /**
Take the original command line, substitute any alias in the first group of space delimited characters, free Take the original command line, substitute any alias in the first group of space delimited characters, free
the original string, return the modified copy the original string, return the modified copy
@ -1526,7 +1552,6 @@ RunCommand(
CHAR16 **Argv; CHAR16 **Argv;
BOOLEAN LastError; BOOLEAN LastError;
CHAR16 LeString[19]; CHAR16 LeString[19];
CHAR16 *PostVariableCmdLine;
CHAR16 *CommandWithPath; CHAR16 *CommandWithPath;
CONST EFI_DEVICE_PATH_PROTOCOL *DevPath; CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;
CONST CHAR16 *TempLocation; CONST CHAR16 *TempLocation;
@ -1546,7 +1571,6 @@ RunCommand(
} }
CommandName = NULL; CommandName = NULL;
PostVariableCmdLine = NULL;
CommandWithPath = NULL; CommandWithPath = NULL;
DevPath = NULL; DevPath = NULL;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
@ -1576,18 +1600,17 @@ RunCommand(
return (Status); return (Status);
} }
PostVariableCmdLine = ShellConvertVariables(CleanOriginal); Status = ShellSubstituteVariables(&CleanOriginal);
if (EFI_ERROR(Status)) {
if (PostVariableCmdLine == NULL) { return (Status);
return (EFI_OUT_OF_RESOURCES);
} }
TrimSpaces(&PostVariableCmdLine); TrimSpaces(&CleanOriginal);
// //
// We dont do normal processing with a split command line (output from one command input to another) // We dont do normal processing with a split command line (output from one command input to another)
// //
if (ContainsSplit(PostVariableCmdLine)) { if (ContainsSplit(CleanOriginal)) {
// //
// are we in an existing split??? // are we in an existing split???
// //
@ -1596,24 +1619,24 @@ RunCommand(
} }
if (Split == NULL) { if (Split == NULL) {
Status = RunSplitCommand(PostVariableCmdLine, NULL, NULL); Status = RunSplitCommand(CleanOriginal, NULL, NULL);
} else { } else {
Status = RunSplitCommand(PostVariableCmdLine, Split->SplitStdIn, Split->SplitStdOut); Status = RunSplitCommand(CleanOriginal, Split->SplitStdIn, Split->SplitStdOut);
} }
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, PostVariableCmdLine); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CleanOriginal);
} }
} else { } else {
// //
// If this is a mapped drive change handle that... // If this is a mapped drive change handle that...
// //
if (PostVariableCmdLine[(StrLen(PostVariableCmdLine)-1)] == L':' && StrStr(PostVariableCmdLine, L" ") == NULL) { if (CleanOriginal[(StrLen(CleanOriginal)-1)] == L':' && StrStr(CleanOriginal, L" ") == NULL) {
Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, PostVariableCmdLine); Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, CleanOriginal);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_MAPPING), ShellInfoObject.HiiHandle, PostVariableCmdLine); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_MAPPING), ShellInfoObject.HiiHandle, CleanOriginal);
} }
FreePool(PostVariableCmdLine); FreePool(CleanOriginal);
return (Status); return (Status);
} }
@ -1622,7 +1645,7 @@ RunCommand(
Status = UpdateStdInStdOutStdErr(ShellInfoObject.NewShellParametersProtocol, PostVariableCmdLine, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo); Status = UpdateStdInStdOutStdErr(ShellInfoObject.NewShellParametersProtocol, CleanOriginal, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
if (Status == EFI_NOT_FOUND) { if (Status == EFI_NOT_FOUND) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle);
@ -1630,12 +1653,12 @@ RunCommand(
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);
} }
} else { } else {
TrimSpaces(&PostVariableCmdLine); TrimSpaces(&CleanOriginal);
// //
// get the argc and argv updated for internal commands // get the argc and argv updated for internal commands
// //
Status = UpdateArgcArgv(ShellInfoObject.NewShellParametersProtocol, PostVariableCmdLine, &Argv, &Argc); Status = UpdateArgcArgv(ShellInfoObject.NewShellParametersProtocol, CleanOriginal, &Argv, &Argc);
ASSERT_EFI_ERROR(Status); ASSERT_EFI_ERROR(Status);
for (Count = 0 ; Count < ShellInfoObject.NewShellParametersProtocol->Argc ; Count++) { for (Count = 0 ; Count < ShellInfoObject.NewShellParametersProtocol->Argc ; Count++) {
@ -1727,7 +1750,7 @@ RunCommand(
Status = InternalShellExecuteDevicePath( Status = InternalShellExecuteDevicePath(
&gImageHandle, &gImageHandle,
DevPath, DevPath,
PostVariableCmdLine, CleanOriginal,
NULL, NULL,
&StatusCode &StatusCode
); );
@ -1772,7 +1795,6 @@ RunCommand(
SHELL_FREE_NON_NULL(CommandName); SHELL_FREE_NON_NULL(CommandName);
SHELL_FREE_NON_NULL(CommandWithPath); SHELL_FREE_NON_NULL(CommandWithPath);
SHELL_FREE_NON_NULL(PostVariableCmdLine);
SHELL_FREE_NON_NULL(CleanOriginal); SHELL_FREE_NON_NULL(CleanOriginal);
return (Status); return (Status);