UINTN Size;\r
EFI_HANDLE ConInHandle;\r
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *OldConIn;\r
- UINTN ExitDataSize;\r
- CHAR16 *ExitData;\r
- SHELL_STATUS ExitStatus;\r
\r
if (PcdGet8(PcdShellSupportLevel) > 3) {\r
return (EFI_UNSUPPORTED);\r
// install our console logger. This will keep a log of the output for back-browsing\r
//\r
Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);\r
- if(EFI_ERROR (Status)) {\r
- ExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
- } else {\r
- ExitStatus = SHELL_SUCCESS;\r
- }\r
- \r
if (!EFI_ERROR(Status)) {\r
//\r
// Enable the cursor to be visible\r
// Display the mapping\r
//\r
if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {\r
- Status = RunCommand(L"map", NULL);\r
+ Status = RunCommand(L"map");\r
ASSERT_EFI_ERROR(Status);\r
}\r
\r
//\r
// process the startup script or launch the called app.\r
//\r
- Status = DoStartupScript(\r
- ShellInfoObject.ImageDevPath,\r
- ShellInfoObject.FileDevPath,\r
- &ExitStatus\r
- );\r
+ Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);\r
}\r
\r
if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
//\r
Status = DoShellPrompt();\r
} while (!ShellCommandGetExit());\r
- ExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();\r
}\r
if (OldConIn != NULL && ConInHandle != NULL) {\r
CloseSimpleTextInOnFile (gST->ConIn);\r
DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;);\r
}\r
\r
- if (!EFI_ERROR (Status)) {\r
- // If the command exited with an error, we pass this error out in the ExitData\r
- // so that it can be retrieved by the EfiShellExecute function (which may\r
- // start the shell with gBS->StartImage)\r
- if (ExitStatus != SHELL_SUCCESS) {\r
- // Allocate a buffer for exit data to pass to gBS->Exit().\r
- // This buffer will contain the empty string immediately followed by\r
- // the shell's exit status. (The empty string is required by the UEFI spec)\r
- ExitDataSize = (sizeof (CHAR16) + sizeof (SHELL_STATUS));\r
- ExitData = AllocatePool (ExitDataSize);\r
- if (ExitData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- ExitData[0] = '\0';\r
- // Use CopyMem to avoid alignment faults\r
- CopyMem ((ExitData + 1), &ExitStatus, sizeof (ExitStatus));\r
-\r
- gBS->Exit (ImageHandle, EFI_ABORTED, ExitDataSize, ExitData);\r
-\r
- ASSERT (FALSE);\r
- return EFI_SUCCESS;\r
- } else {\r
- return EFI_SUCCESS;\r
- }\r
- } else {\r
- return Status;\r
+ if (ShellCommandGetExit()) {\r
+ return ((EFI_STATUS)ShellCommandGetExitCode());\r
}\r
+ return (Status);\r
}\r
\r
/**\r
@param ImagePath the path to the image for shell. first place to look for the startup script\r
@param FilePath the path to the file for shell. second place to look for the startup script.\r
\r
- @param[out] ExitStatus The exit code of the script. Ignored if NULL.\r
-\r
@retval EFI_SUCCESS the variable is initialized.\r
**/\r
EFI_STATUS\r
EFIAPI\r
DoStartupScript(\r
- IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
- OUT SHELL_STATUS *ExitStatus\r
+ IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
)\r
{\r
EFI_STATUS Status;\r
StrnCat(FileStringPath, L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
StrnCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
}\r
- Status = RunCommand(FileStringPath, ExitStatus);\r
+ Status = RunCommand(FileStringPath);\r
FreePool(FileStringPath);\r
return (Status);\r
\r
// If we got a file, run it\r
//\r
if (!EFI_ERROR(Status) && FileHandle != NULL) {\r
- Status = RunScriptFile (\r
- mStartupScript,\r
- FileHandle,\r
- L"",\r
- ShellInfoObject.NewShellParametersProtocol,\r
- ExitStatus\r
- );\r
+ Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol);\r
ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);\r
} else {\r
FileStringPath = ShellFindFilePath(mStartupScript);\r
Status = EFI_SUCCESS;\r
ASSERT(FileHandle == NULL);\r
} else {\r
- Status = RunScriptFile(\r
- FileStringPath,\r
- NULL,\r
- L"",\r
- ShellInfoObject.NewShellParametersProtocol,\r
- ExitStatus\r
- );\r
+ Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);\r
FreePool(FileStringPath);\r
}\r
}\r
//\r
if (!EFI_ERROR (Status)) {\r
CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;\r
- Status = RunCommand(CmdLine, NULL);\r
+ Status = RunCommand(CmdLine);\r
}\r
\r
//\r
; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL\r
; MasterEnvList += StrLen(MasterEnvList) + 1\r
){\r
- *ItemTemp = L'%';\r
+ StrnCpy(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1);\r
StrnCat(ItemTemp, MasterEnvList, ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));\r
StrnCat(ItemTemp, L"%", ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16))-1 - StrLen(ItemTemp));\r
ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);\r
@param[in] StdIn The pointer to the Standard input.\r
@param[in] StdOut The pointer to the Standard output.\r
\r
- @param[out] ExitStatus The exit code of the last command in the pipeline.\r
- Ignored if NULL.\r
-\r
@retval EFI_SUCCESS The split command is executed successfully.\r
@retval other Some error occurs when executing the split command.\r
**/\r
RunSplitCommand(\r
IN CONST CHAR16 *CmdLine,\r
IN SHELL_FILE_HANDLE *StdIn,\r
- IN SHELL_FILE_HANDLE *StdOut,\r
- OUT SHELL_STATUS *ExitStatus\r
+ IN SHELL_FILE_HANDLE *StdOut\r
)\r
{\r
EFI_STATUS Status;\r
ASSERT(Split->SplitStdOut != NULL);\r
InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link);\r
\r
- Status = RunCommand(OurCommandLine, NULL);\r
+ Status = RunCommand(OurCommandLine);\r
\r
//\r
// move the output from the first to the in to the second.\r
ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0);\r
\r
if (!EFI_ERROR(Status)) {\r
- Status = RunCommand(NextCommandLine, ExitStatus);\r
+ Status = RunCommand(NextCommandLine);\r
}\r
\r
//\r
/**\r
Process a split based operation.\r
\r
- @param[in] CmdLine Pointer to the command line to process\r
- @param[out] ExitStatus The exit status of the command. Ignored if NULL.\r
- Invalid if this function returns an error.\r
+ @param[in] CmdLine pointer to the command line to process\r
\r
@retval EFI_SUCCESS The operation was successful\r
@return an error occured.\r
EFI_STATUS\r
EFIAPI\r
ProcessNewSplitCommandLine(\r
- IN CONST CHAR16 *CmdLine,\r
- OUT SHELL_STATUS *ExitStatus\r
+ IN CONST CHAR16 *CmdLine\r
)\r
{\r
SPLIT_LIST *Split;\r
}\r
\r
if (Split == NULL) {\r
- Status = RunSplitCommand(CmdLine, NULL, NULL, ExitStatus);\r
+ Status = RunSplitCommand(CmdLine, NULL, NULL);\r
} else {\r
- Status = RunSplitCommand(\r
- CmdLine,\r
- Split->SplitStdIn,\r
- Split->SplitStdOut,\r
- ExitStatus\r
- );\r
+ Status = RunSplitCommand(CmdLine, Split->SplitStdIn, Split->SplitStdOut);\r
}\r
if (EFI_ERROR(Status)) {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine);\r
@param[in] FirstParameter the first parameter on the command line\r
@param[in] ParamProtocol the shell parameters protocol pointer\r
\r
- @param[out] ExitStatus The exit code of the command. Ignored if NULL.\r
-\r
@retval EFI_SUCCESS The command was completed.\r
@retval EFI_ABORTED The command's operation was aborted.\r
**/\r
RunInternalCommand(\r
IN CONST CHAR16 *CmdLine,\r
IN CHAR16 *FirstParameter,\r
- IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r
- OUT SHELL_STATUS *ExitStatus OPTIONAL\r
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r
)\r
{\r
EFI_STATUS Status;\r
CHAR16 **Argv;\r
SHELL_STATUS CommandReturnedStatus;\r
BOOLEAN LastError;\r
+ CHAR16 *Walker;\r
+ CHAR16 *NewCmdLine; \r
+\r
+ NewCmdLine = AllocateCopyPool (StrSize (CmdLine), CmdLine);\r
+ if (NewCmdLine == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {\r
+ if (*Walker == L'^' && *(Walker+1) == L'#') {\r
+ CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));\r
+ }\r
+ }\r
\r
//\r
// get the argc and argv updated for internal commands\r
//\r
- Status = UpdateArgcArgv(ParamProtocol, CmdLine, &Argv, &Argc);\r
+ Status = UpdateArgcArgv(ParamProtocol, NewCmdLine, &Argv, &Argc);\r
if (!EFI_ERROR(Status)) {\r
//\r
// Run the internal command.\r
if (LastError) {\r
SetLastError(CommandReturnedStatus);\r
}\r
- if (ExitStatus != NULL) {\r
- *ExitStatus = CommandReturnedStatus;\r
- }\r
\r
//\r
// Pass thru the exitcode from the app.\r
Status = EFI_SUCCESS;\r
}\r
\r
+ FreePool (NewCmdLine);\r
return (Status);\r
}\r
\r
@param[in] FirstParameter the first parameter on the command line\r
@param[in] ParamProtocol the shell parameters protocol pointer\r
\r
- @param[out] ExitStatus The exit code of the command or file.\r
- Ignored if NULL.\r
-\r
@retval EFI_SUCCESS The command was completed.\r
@retval EFI_ABORTED The command's operation was aborted.\r
**/\r
IN SHELL_OPERATION_TYPES Type,\r
IN CONST CHAR16 *CmdLine,\r
IN CHAR16 *FirstParameter,\r
- IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r
- OUT SHELL_STATUS *ExitStatus\r
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r
)\r
{\r
EFI_STATUS Status;\r
\r
switch (Type) {\r
case Internal_Command:\r
- Status = RunInternalCommand(\r
- CmdLine,\r
- FirstParameter,\r
- ParamProtocol,\r
- &CalleeExitStatus\r
- );\r
+ Status = RunInternalCommand(CmdLine, FirstParameter, ParamProtocol);\r
break;\r
case Script_File_Name:\r
case Efi_Application:\r
}\r
switch (Type) {\r
case Script_File_Name:\r
- Status = RunScriptFile (\r
- CommandWithPath,\r
- NULL,\r
- CmdLine,\r
- ParamProtocol,\r
- &CalleeExitStatus\r
- );\r
+ Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);\r
break;\r
case Efi_Application:\r
//\r
DevPath,\r
CmdLine,\r
NULL,\r
- &StartStatus,\r
- NULL,\r
- NULL\r
+ &StartStatus\r
);\r
\r
SHELL_FREE_NON_NULL(DevPath);\r
\r
SHELL_FREE_NON_NULL(CommandWithPath);\r
\r
- if (ExitStatus != NULL) {\r
- *ExitStatus = CalleeExitStatus;\r
- }\r
-\r
return (Status);\r
}\r
\r
@param[in] FirstParameter the first parameter on the command line.\r
@param[in] ParamProtocol the shell parameters protocol pointer\r
\r
- @param[out] ExitStatus The exit code of the command or file.\r
- Ignored if NULL.\r
-\r
@retval EFI_SUCCESS The command was completed.\r
@retval EFI_ABORTED The command's operation was aborted.\r
**/\r
EFI_STATUS\r
EFIAPI\r
SetupAndRunCommandOrFile(\r
- IN SHELL_OPERATION_TYPES Type,\r
- IN CHAR16 *CmdLine,\r
- IN CHAR16 *FirstParameter,\r
- IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r
- OUT SHELL_STATUS *ExitStatus\r
+ IN SHELL_OPERATION_TYPES Type,\r
+ IN CHAR16 *CmdLine,\r
+ IN CHAR16 *FirstParameter,\r
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r
)\r
{\r
EFI_STATUS Status;\r
// Now run the command, script, or application\r
//\r
if (!EFI_ERROR(Status)) {\r
- Status = RunCommandOrFile(\r
- Type,\r
- CmdLine,\r
- FirstParameter,\r
- ParamProtocol,\r
- ExitStatus\r
- );\r
+ TrimSpaces(&CmdLine);\r
+ Status = RunCommandOrFile(Type, CmdLine, FirstParameter, ParamProtocol);\r
}\r
\r
//\r
command or dispatch an external application.\r
\r
@param[in] CmdLine The command line to parse.\r
- @param[out] ExitStatus The exit code of the command. Ignored if NULL.\r
\r
@retval EFI_SUCCESS The command was completed.\r
@retval EFI_ABORTED The command's operation was aborted.\r
EFI_STATUS\r
EFIAPI\r
RunCommand(\r
- IN CONST CHAR16 *CmdLine,\r
- OUT SHELL_STATUS *ExitStatus\r
+ IN CONST CHAR16 *CmdLine\r
)\r
{\r
EFI_STATUS Status;\r
for (TempWalker = CleanOriginal; TempWalker != NULL && *TempWalker != CHAR_NULL; TempWalker++) {\r
if (*TempWalker == L'^') {\r
if (*(TempWalker + 1) == L'#') {\r
- CopyMem (TempWalker, TempWalker + 1, StrSize (TempWalker) - sizeof (TempWalker[0]));\r
+ TempWalker++;\r
}\r
} else if (*TempWalker == L'#') {\r
*TempWalker = CHAR_NULL;\r
// We dont do normal processing with a split command line (output from one command input to another)\r
//\r
if (ContainsSplit(CleanOriginal)) {\r
- Status = ProcessNewSplitCommandLine(CleanOriginal, ExitStatus);\r
+ Status = ProcessNewSplitCommandLine(CleanOriginal);\r
SHELL_FREE_NON_NULL(CleanOriginal);\r
return (Status);\r
} \r
case Internal_Command:\r
case Script_File_Name:\r
case Efi_Application:\r
- Status = SetupAndRunCommandOrFile(\r
- Type,\r
- CleanOriginal,\r
- FirstParameter,\r
- ShellInfoObject.NewShellParametersProtocol,\r
- ExitStatus\r
- );\r
+ Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol);\r
break;\r
default:\r
//\r
@param[in] Handle The handle to the already opened file.\r
@param[in] Name The name of the script file.\r
\r
- @param[out] ExitStatus The exit code of the script. Ignored if NULL.\r
-\r
@retval EFI_SUCCESS the script completed sucessfully\r
**/\r
EFI_STATUS\r
EFIAPI\r
RunScriptFileHandle (\r
- IN SHELL_FILE_HANDLE Handle,\r
- IN CONST CHAR16 *Name,\r
- OUT SHELL_STATUS *ExitStatus\r
+ IN SHELL_FILE_HANDLE Handle,\r
+ IN CONST CHAR16 *Name\r
)\r
{\r
EFI_STATUS Status;\r
CONST CHAR16 *CurDir;\r
UINTN LineCount;\r
CHAR16 LeString[50];\r
- SHELL_STATUS CalleeExitStatus;\r
\r
ASSERT(!ShellCommandGetScriptExit());\r
- \r
- CalleeExitStatus = SHELL_SUCCESS;\r
\r
PreScriptEchoState = ShellCommandGetEchoState();\r
\r
//\r
for (CommandLine3 = CommandLine2 ; CommandLine3 != NULL && *CommandLine3 != CHAR_NULL ; CommandLine3++) {\r
if (*CommandLine3 == L'^') {\r
- if (*(CommandLine3+1) == L'#' || *(CommandLine3+1) == L':') {\r
+ if ( *(CommandLine3+1) == L':') {\r
CopyMem(CommandLine3, CommandLine3+1, StrSize(CommandLine3) - sizeof(CommandLine3[0]));\r
+ } else if (*(CommandLine3+1) == L'#') {\r
+ CommandLine3++;\r
}\r
} else if (*CommandLine3 == L'#') {\r
*CommandLine3 = CHAR_NULL;\r
//\r
PreCommandEchoState = ShellCommandGetEchoState();\r
ShellCommandSetEchoState(FALSE);\r
- Status = RunCommand(CommandLine3+1, NULL);\r
+ Status = RunCommand(CommandLine3+1);\r
\r
//\r
// If command was "@echo -off" or "@echo -on" then don't restore echo state\r
}\r
ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2);\r
}\r
- Status = RunCommand(CommandLine3, NULL);\r
+ Status = RunCommand(CommandLine3);\r
}\r
}\r
\r
//\r
// ShellCommandGetExitCode() always returns a UINT64\r
//\r
- CalleeExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();\r
- UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", CalleeExitStatus);\r
+ UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());\r
DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r
InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r
\r
break;\r
}\r
if (EFI_ERROR(Status)) {\r
- CalleeExitStatus = (SHELL_STATUS) Status;\r
break;\r
}\r
if (ShellCommandGetExit()) {\r
- CalleeExitStatus = (SHELL_STATUS) ShellCommandGetExitCode();\r
break;\r
}\r
}\r
if (ShellCommandGetCurrentScriptFile()==NULL) {\r
ShellCommandSetEchoState(PreScriptEchoState);\r
}\r
-\r
- if (ExitStatus != NULL) {\r
- *ExitStatus = CalleeExitStatus;\r
- }\r
-\r
return (EFI_SUCCESS);\r
}\r
\r
@param[in] CmdLine the command line to run.\r
@param[in] ParamProtocol the shell parameters protocol pointer\r
\r
- @param[out] ExitStatus The exit code of the script. Ignored if NULL.\r
-\r
@retval EFI_SUCCESS the script completed sucessfully\r
**/\r
EFI_STATUS\r
EFIAPI\r
RunScriptFile (\r
- IN CONST CHAR16 *ScriptPath,\r
- IN SHELL_FILE_HANDLE Handle OPTIONAL,\r
- IN CONST CHAR16 *CmdLine,\r
- IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r
- OUT SHELL_STATUS *ExitStatus\r
+ IN CONST CHAR16 *ScriptPath,\r
+ IN SHELL_FILE_HANDLE Handle OPTIONAL,\r
+ IN CONST CHAR16 *CmdLine,\r
+ IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r
)\r
{\r
EFI_STATUS Status;\r
//\r
// run it\r
//\r
- Status = RunScriptFileHandle(FileHandle, ScriptPath, ExitStatus);\r
+ Status = RunScriptFileHandle(FileHandle, ScriptPath);\r
\r
//\r
// now close the file\r
ShellCloseFile(&FileHandle);\r
}\r
} else {\r
- Status = RunScriptFileHandle(Handle, ScriptPath, ExitStatus);\r
+ Status = RunScriptFileHandle(Handle, ScriptPath);\r
}\r
}\r
\r