X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShell.c;h=ef757dec0fa724f87b490cd45fde513fed3a16d1;hb=6ba2921da3c0b7db303b6db44810158a1fefd737;hp=878a3852a5e56c4cdd5c4b21186a6b585f19a3b3;hpb=1921657354d52f874679b9d117b37e6b36641abf;p=mirror_edk2.git diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 878a3852a5..ef757dec0f 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1,7 +1,8 @@ /** @file This is THE shell (application) - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.
+ Copyright (c) 2013, Hewlett-Packard Development Company, L.P. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -23,22 +24,24 @@ SHELL_INFO ShellInfoObject = { FALSE, FALSE, { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, + {{ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + }}, 0, NULL, NULL }, - {0,0}, + {{NULL, NULL}, NULL}, { - {0,0}, + {{NULL, NULL}, NULL}, 0, 0, TRUE @@ -50,8 +53,12 @@ SHELL_INFO ShellInfoObject = { NULL, NULL, NULL, - {0,0,NULL,NULL}, - {0,0}, + {{NULL, NULL}, NULL, NULL}, + {{NULL, NULL}, NULL, NULL}, + NULL, + NULL, + NULL, + NULL, NULL, NULL, NULL, @@ -63,6 +70,83 @@ STATIC CONST CHAR16 mScriptExtension[] = L".NSH"; STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI"; STATIC CONST CHAR16 mStartupScript[] = L"startup.nsh"; +/** + Cleans off leading and trailing spaces and tabs + + @param[in] String pointer to the string to trim them off +**/ +EFI_STATUS +EFIAPI +TrimSpaces( + IN CHAR16 **String + ) +{ + ASSERT(String != NULL); + ASSERT(*String!= NULL); + // + // Remove any spaces and tabs at the beginning of the (*String). + // + while (((*String)[0] == L' ') || ((*String)[0] == L'\t')) { + CopyMem((*String), (*String)+1, StrSize((*String)) - sizeof((*String)[0])); + } + + // + // Remove any spaces at the end of the (*String). + // + while ((*String)[StrLen((*String))-1] == L' ') { + (*String)[StrLen((*String))-1] = CHAR_NULL; + } + + return (EFI_SUCCESS); +} + +/** + Find a command line contains a split operation + + @param[in] CmdLine The command line to parse. + + @retval A pointer to the | character in CmdLine or NULL if not present. +**/ +CONST +CHAR16* +EFIAPI +FindSplit( + IN CONST CHAR16 *CmdLine + ) +{ + CONST CHAR16 *TempSpot; + TempSpot = NULL; + if (StrStr(CmdLine, L"|") != NULL) { + for (TempSpot = CmdLine ; TempSpot != NULL && *TempSpot != CHAR_NULL ; TempSpot++) { + if (*TempSpot == L'^' && *(TempSpot+1) == L'|') { + TempSpot++; + } else if (*TempSpot == L'|') { + break; + } + } + } + return (TempSpot); +} + +/** + Determine if a command line contains a split operation + + @param[in] CmdLine The command line to parse. + + @retval TRUE CmdLine has a valid split. + @retval FALSE CmdLine does not have a valid split. +**/ +BOOLEAN +EFIAPI +ContainsSplit( + IN CONST CHAR16 *CmdLine + ) +{ + CONST CHAR16 *TempSpot; + TempSpot = FindSplit(CmdLine); + return (TempSpot != NULL && *TempSpot != CHAR_NULL); +} + /** Function to start monitoring for CTRL-S using SimpleTextInputEx. This feature's enabled state was not known when the shell initially launched. @@ -124,7 +208,7 @@ InternalEfiShellStartCtrlSMonitor( SimpleEx, &KeyData, NotificationFunction, - &ShellInfoObject.CtrlSNotifyHandle2); + &ShellInfoObject.CtrlSNotifyHandle3); } KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED; if (!EFI_ERROR(Status)) { @@ -132,7 +216,7 @@ InternalEfiShellStartCtrlSMonitor( SimpleEx, &KeyData, NotificationFunction, - &ShellInfoObject.CtrlSNotifyHandle2); + &ShellInfoObject.CtrlSNotifyHandle4); } return (Status); } @@ -290,11 +374,28 @@ UefiMain ( 0, gST->ConOut->Mode->CursorRow, NULL, - STRING_TOKEN (STR_VER_OUTPUT_MAIN), + STRING_TOKEN (STR_VER_OUTPUT_MAIN_SHELL), ShellInfoObject.HiiHandle, SupportLevel[PcdGet8(PcdShellSupportLevel)], gEfiShellProtocol->MajorVersion, - gEfiShellProtocol->MinorVersion, + gEfiShellProtocol->MinorVersion + ); + + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_VER_OUTPUT_MAIN_SUPPLIER), + ShellInfoObject.HiiHandle, + (CHAR16 *) PcdGetPtr (PcdShellSupplier) + ); + + ShellPrintHiiEx ( + -1, + -1, + NULL, + STRING_TOKEN (STR_VER_OUTPUT_MAIN_UEFI), + ShellInfoObject.HiiHandle, (gST->Hdr.Revision&0xffff0000)>>16, (gST->Hdr.Revision&0x0000ffff), gST->FirmwareVendor, @@ -375,7 +476,7 @@ UefiMain ( Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath); } - if (!ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) { + if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) { // // begin the UI waiting loop // @@ -435,7 +536,7 @@ UefiMain ( } if (ShellInfoObject.NewEfiShellProtocol != NULL){ if (ShellInfoObject.NewEfiShellProtocol->IsRootShell()){ - ShellInfoObject.NewEfiShellProtocol->SetEnv(L"cwd", L"", TRUE); + InternalEfiShellSetEnv(L"cwd", NULL, TRUE); } CleanUpShellProtocol(ShellInfoObject.NewEfiShellProtocol); DEBUG_CODE(ShellInfoObject.NewEfiShellProtocol = NULL;); @@ -636,6 +737,7 @@ STATIC CONST SHELL_PARAM_ITEM mShellParamList[] = { {L"-noversion", TypeFlag}, {L"-startup", TypeFlag}, {L"-delay", TypeValue}, + {L"-_exit", TypeFlag}, {NULL, TypeMax} }; @@ -743,6 +845,7 @@ ProcessCommandLine( ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap = ShellCommandLineGetFlag(Package, L"-nomap"); ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion = ShellCommandLineGetFlag(Package, L"-noversion"); ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay = ShellCommandLineGetFlag(Package, L"-delay"); + ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit = ShellCommandLineGetFlag(Package, L"-_exit"); ShellInfoObject.ShellInitSettings.Delay = 5; @@ -827,20 +930,22 @@ DoStartupScript( return (EFI_SUCCESS); } + gST->ConOut->EnableCursor(gST->ConOut, FALSE); // // print out our warning and see if they press a key // - for ( Status = EFI_UNSUPPORTED, Delay = ShellInfoObject.ShellInitSettings.Delay * 10 + for ( Status = EFI_UNSUPPORTED, Delay = ShellInfoObject.ShellInitSettings.Delay ; Delay != 0 && EFI_ERROR(Status) ; Delay-- ){ - ShellPrintHiiEx(0, gST->ConOut->Mode->CursorRow, NULL, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION), ShellInfoObject.HiiHandle, Delay/10); - gBS->Stall (100000); + ShellPrintHiiEx(0, gST->ConOut->Mode->CursorRow, NULL, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION), ShellInfoObject.HiiHandle, Delay); + gBS->Stall (1000000); if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) { Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); } } ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle); + gST->ConOut->EnableCursor(gST->ConOut, TRUE); // // ESC was pressed @@ -1075,6 +1180,7 @@ ShellConvertVariables ( CHAR16 *NewCommandLine1; CHAR16 *NewCommandLine2; CHAR16 *Temp; + CHAR16 *Temp2; UINTN ItemSize; CHAR16 *ItemTemp; SCRIPT_FILE *CurrentScriptFile; @@ -1132,15 +1238,6 @@ ShellConvertVariables ( } } - // - // Quick out if none were found... - // - if (NewSize == StrSize(OriginalCommandLine)) { - ASSERT(Temp == NULL); - Temp = StrnCatGrow(&Temp, NULL, OriginalCommandLine, 0); - return (Temp); - } - // // now do the replacements... // @@ -1172,8 +1269,51 @@ ShellConvertVariables ( ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE); StrCpy(NewCommandLine1, NewCommandLine2); } + + // + // Remove non-existant environment variables in scripts only + // + for (Temp = NewCommandLine1 ; Temp != NULL ; ) { + Temp = StrStr(Temp, L"%"); + if (Temp == NULL) { + break; + } + while (*(Temp - 1) == L'^') { + Temp = StrStr(Temp + 1, L"%"); + if (Temp == NULL) { + break; + } + } + if (Temp == NULL) { + break; + } + + Temp2 = StrStr(Temp + 1, L"%"); + if (Temp2 == NULL) { + break; + } + while (*(Temp2 - 1) == L'^') { + Temp2 = StrStr(Temp2 + 1, L"%"); + if (Temp2 == NULL) { + break; + } + } + if (Temp2 == NULL) { + break; + } + + Temp2++; + CopyMem(Temp, Temp2, StrSize(Temp2)); + } + } + // + // Now cleanup any straggler intentionally ignored "%" characters + // + ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE); + StrCpy(NewCommandLine1, NewCommandLine2); + FreePool(NewCommandLine2); FreePool(ItemTemp); @@ -1290,6 +1430,164 @@ RunSplitCommand( 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 + 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 +ShellSubstituteAliases( + IN CHAR16 **CmdLine + ) +{ + CHAR16 *NewCmdLine; + CHAR16 *CommandName; + EFI_STATUS Status; + UINTN PostAliasSize; + ASSERT(CmdLine != NULL); + ASSERT(*CmdLine!= NULL); + + + CommandName = NULL; + if (StrStr((*CmdLine), L" ") == NULL){ + StrnCatGrow(&CommandName, NULL, (*CmdLine), 0); + } else { + StrnCatGrow(&CommandName, NULL, (*CmdLine), StrStr((*CmdLine), L" ") - (*CmdLine)); + } + + // + // This cannot happen 'inline' since the CmdLine can need extra space. + // + NewCmdLine = NULL; + if (!ShellCommandIsCommandOnList(CommandName)) { + // + // Convert via alias + // + Status = ShellConvertAlias(&CommandName); + if (EFI_ERROR(Status)){ + return (Status); + } + PostAliasSize = 0; + NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, CommandName, 0); + if (NewCmdLine == NULL) { + SHELL_FREE_NON_NULL(CommandName); + SHELL_FREE_NON_NULL(*CmdLine); + return (EFI_OUT_OF_RESOURCES); + } + NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, StrStr((*CmdLine), L" "), 0); + if (NewCmdLine == NULL) { + SHELL_FREE_NON_NULL(CommandName); + SHELL_FREE_NON_NULL(*CmdLine); + return (EFI_OUT_OF_RESOURCES); + } + } else { + NewCmdLine = StrnCatGrow(&NewCmdLine, NULL, (*CmdLine), 0); + } + + SHELL_FREE_NON_NULL(*CmdLine); + SHELL_FREE_NON_NULL(CommandName); + + // + // re-assign the passed in double pointer to point to our newly allocated buffer + // + *CmdLine = NewCmdLine; + + return (EFI_SUCCESS); +} + +/** + Takes the Argv[0] part of the command line and determine the meaning of it. +**/ +SHELL_OPERATION_TYPES +EFIAPI +GetOperationType( + IN CONST CHAR16 *CmdName + ) +{ + CHAR16* FileWithPath; + CONST CHAR16* TempLocation; + CONST CHAR16* TempLocation2; + + FileWithPath = NULL; + // + // test for an internal command. + // + if (ShellCommandIsCommandOnList(CmdName)) { + return (INTERNAL_COMMAND); + } + + // + // Test for file system change request. anything ending with : and cant have spaces. + // + if (CmdName[(StrLen(CmdName)-1)] == L':') { + if (StrStr(CmdName, L" ") != NULL) { + return (UNKNOWN_INVALID); + } + return (FILE_SYS_CHANGE); + } + + // + // Test for a file + // + if ((FileWithPath = ShellFindFilePathEx(CmdName, mExecutableExtensions)) != NULL) { + // + // See if that file has a script file extension + // + if (StrLen(FileWithPath) > 4) { + TempLocation = FileWithPath+StrLen(FileWithPath)-4; + TempLocation2 = mScriptExtension; + if (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0) { + SHELL_FREE_NON_NULL(FileWithPath); + return (SCRIPT_FILE_NAME); + } + } + + // + // Was a file, but not a script. we treat this as an application. + // + SHELL_FREE_NON_NULL(FileWithPath); + return (EFI_APPLICATION); + } + + SHELL_FREE_NON_NULL(FileWithPath); + // + // No clue what this is... return invalid flag... + // + return (UNKNOWN_INVALID); +} + /** Function will process and run a command line. @@ -1308,15 +1606,13 @@ RunCommand( ) { EFI_STATUS Status; + EFI_STATUS StatusCode; CHAR16 *CommandName; SHELL_STATUS ShellStatus; UINTN Argc; CHAR16 **Argv; BOOLEAN LastError; - CHAR16 LeString[11]; - CHAR16 *PostAliasCmdLine; - UINTN PostAliasSize; - CHAR16 *PostVariableCmdLine; + CHAR16 LeString[19]; CHAR16 *CommandWithPath; CONST EFI_DEVICE_PATH_PROTOCOL *DevPath; CONST CHAR16 *TempLocation; @@ -1325,7 +1621,6 @@ RunCommand( SHELL_FILE_HANDLE OriginalStdOut; SHELL_FILE_HANDLE OriginalStdErr; SYSTEM_TABLE_INFO OriginalSystemTableInfo; - CHAR16 *TempLocation3; UINTN Count; UINTN Count2; CHAR16 *CleanOriginal; @@ -1337,8 +1632,6 @@ RunCommand( } CommandName = NULL; - PostVariableCmdLine = NULL; - PostAliasCmdLine = NULL; CommandWithPath = NULL; DevPath = NULL; Status = EFI_SUCCESS; @@ -1349,79 +1642,36 @@ RunCommand( if (CleanOriginal == NULL) { return (EFI_OUT_OF_RESOURCES); } - while (CleanOriginal[StrLen(CleanOriginal)-1] == L' ') { - CleanOriginal[StrLen(CleanOriginal)-1] = CHAR_NULL; - } - while (CleanOriginal[0] == L' ') { - CopyMem(CleanOriginal, CleanOriginal+1, StrSize(CleanOriginal) - sizeof(CleanOriginal[0])); - } - CommandName = NULL; - if (StrStr(CleanOriginal, L" ") == NULL){ - StrnCatGrow(&CommandName, NULL, CleanOriginal, 0); - } else { - StrnCatGrow(&CommandName, NULL, CleanOriginal, StrStr(CleanOriginal, L" ") - CleanOriginal); - } - - ASSERT(PostAliasCmdLine == NULL); - if (!ShellCommandIsCommandOnList(CommandName)) { - // - // Convert via alias - // - Status = ShellConvertAlias(&CommandName); - PostAliasSize = 0; - PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, &PostAliasSize, CommandName, 0); - PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, &PostAliasSize, StrStr(CleanOriginal, L" "), 0); - ASSERT_EFI_ERROR(Status); - } else { - PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, NULL, CleanOriginal, 0); - } - - if (CleanOriginal != NULL) { - FreePool(CleanOriginal); - CleanOriginal = NULL; - } - - if (CommandName != NULL) { - FreePool(CommandName); - CommandName = NULL; - } - - PostVariableCmdLine = ShellConvertVariables(PostAliasCmdLine); + TrimSpaces(&CleanOriginal); // - // we can now free the modified by alias command line + // Handle case that passed in command line is just 1 or more " " characters. // - if (PostAliasCmdLine != NULL) { - FreePool(PostAliasCmdLine); - PostAliasCmdLine = NULL; + if (StrLen (CleanOriginal) == 0) { + if (CleanOriginal != NULL) { + FreePool(CleanOriginal); + CleanOriginal = NULL; + } + return (EFI_SUCCESS); } - if (PostVariableCmdLine == NULL) { - return (EFI_OUT_OF_RESOURCES); + Status = ShellSubstituteAliases(&CleanOriginal); + if (EFI_ERROR(Status)) { + return (Status); } - while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') { - PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL; - } - while (PostVariableCmdLine[0] == L' ') { - CopyMem(PostVariableCmdLine, PostVariableCmdLine+1, StrSize(PostVariableCmdLine) - sizeof(PostVariableCmdLine[0])); + Status = ShellSubstituteVariables(&CleanOriginal); + if (EFI_ERROR(Status)) { + return (Status); } + TrimSpaces(&CleanOriginal); + // // We dont do normal processing with a split command line (output from one command input to another) // - TempLocation3 = NULL; - if (StrStr(PostVariableCmdLine, L"|") != NULL) { - for (TempLocation3 = PostVariableCmdLine ; TempLocation3 != NULL && *TempLocation3 != CHAR_NULL ; TempLocation3++) { - if (*TempLocation3 == L'^' && *(TempLocation3+1) == L'|') { - TempLocation3++; - } else if (*TempLocation3 == L'|') { - break; - } - } - } - if (TempLocation3 != NULL && *TempLocation3 != CHAR_NULL) { + if (ContainsSplit(CleanOriginal)) { // // are we in an existing split??? // @@ -1430,24 +1680,24 @@ RunCommand( } if (Split == NULL) { - Status = RunSplitCommand(PostVariableCmdLine, NULL, NULL); + Status = RunSplitCommand(CleanOriginal, NULL, NULL); } else { - Status = RunSplitCommand(PostVariableCmdLine, Split->SplitStdIn, Split->SplitStdOut); + Status = RunSplitCommand(CleanOriginal, Split->SplitStdIn, Split->SplitStdOut); } 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 { // // If this is a mapped drive change handle that... // - if (PostVariableCmdLine[(StrLen(PostVariableCmdLine)-1)] == L':' && StrStr(PostVariableCmdLine, L" ") == NULL) { - Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, PostVariableCmdLine); + if (CleanOriginal[(StrLen(CleanOriginal)-1)] == L':' && StrStr(CleanOriginal, L" ") == NULL) { + Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, CleanOriginal); 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); } @@ -1456,7 +1706,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 (Status == EFI_NOT_FOUND) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle); @@ -1464,17 +1714,12 @@ RunCommand( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle); } } else { - while (PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] == L' ') { - PostVariableCmdLine[StrLen(PostVariableCmdLine)-1] = CHAR_NULL; - } - while (PostVariableCmdLine[0] == L' ') { - CopyMem(PostVariableCmdLine, PostVariableCmdLine+1, StrSize(PostVariableCmdLine) - sizeof(PostVariableCmdLine[0])); - } - + TrimSpaces(&CleanOriginal); + // // 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); for (Count = 0 ; Count < ShellInfoObject.NewShellParametersProtocol->Argc ; Count++) { @@ -1510,10 +1755,15 @@ RunCommand( if (!EFI_ERROR(Status)) { Status = ShellCommandRunCommandHandler(ShellInfoObject.NewShellParametersProtocol->Argv[0], &ShellStatus, &LastError); ASSERT_EFI_ERROR(Status); - UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%08x", ShellStatus); - DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE);); + + if (sizeof(EFI_STATUS) == sizeof(UINT64)) { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellStatus); + } else { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ShellStatus); + } + DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE);); if (LastError) { - InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE); + InternalEfiShellSetEnv(L"lasterror", LeString, TRUE); } // // Pass thru the exitcode from the app. @@ -1539,6 +1789,14 @@ RunCommand( } if (CommandWithPath == NULL || ShellIsDirectory(CommandWithPath) == EFI_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, ShellInfoObject.NewShellParametersProtocol->Argv[0]); + + if (sizeof(EFI_STATUS) == sizeof(UINT64)) { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", EFI_NOT_FOUND); + } else { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", EFI_NOT_FOUND); + } + DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE);); + InternalEfiShellSetEnv(L"lasterror", LeString, TRUE); } else { // // Check if it's a NSH (script) file. @@ -1553,13 +1811,32 @@ RunCommand( Status = InternalShellExecuteDevicePath( &gImageHandle, DevPath, - PostVariableCmdLine, + CleanOriginal, NULL, - NULL + &StatusCode ); + + // + // Update last error status. + // + if (sizeof(EFI_STATUS) == sizeof(UINT64)) { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", StatusCode); + } else { + UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", StatusCode); + } + DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE);); + InternalEfiShellSetEnv(L"lasterror", LeString, TRUE); } } } + + // + // Print some error info. + // + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR), ShellInfoObject.HiiHandle, (VOID*)(Status)); + } + CommandName = StrnCatGrow(&CommandName, NULL, ShellInfoObject.NewShellParametersProtocol->Argv[0], 0); RestoreArgcArgv(ShellInfoObject.NewShellParametersProtocol, &Argv, &Argc); @@ -1579,7 +1856,7 @@ RunCommand( SHELL_FREE_NON_NULL(CommandName); SHELL_FREE_NON_NULL(CommandWithPath); - SHELL_FREE_NON_NULL(PostVariableCmdLine); + SHELL_FREE_NON_NULL(CleanOriginal); return (Status); } @@ -1830,9 +2107,15 @@ RunScriptFileHandle ( Status = RunCommand(CommandLine3+1); // - // Now restore the pre-'@' echo state. + // If command was "@echo -off" or "@echo -on" then don't restore echo state // - ShellCommandSetEchoState(PreCommandEchoState); + if (StrCmp (L"@echo -off", CommandLine3) != 0 && + StrCmp (L"@echo -on", CommandLine3) != 0) { + // + // Now restore the pre-'@' echo state. + // + ShellCommandSetEchoState(PreCommandEchoState); + } } else { if (ShellCommandGetEchoState()) { CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd"); @@ -1848,14 +2131,20 @@ RunScriptFileHandle ( } if (ShellCommandGetScriptExit()) { - UnicodeSPrint(LeString, sizeof(LeString)*sizeof(LeString[0]), L"0x%Lx", ShellCommandGetExitCode()); - DEBUG_CODE(InternalEfiShellSetEnv(L"DebugLasterror", LeString, TRUE);); - InternalEfiShellSetEnv(L"Lasterror", LeString, TRUE); + // + // ShellCommandGetExitCode() always returns a UINT64 + // + UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode()); + DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE);); + InternalEfiShellSetEnv(L"lasterror", LeString, TRUE); ShellCommandRegisterExit(FALSE, 0); Status = EFI_SUCCESS; break; } + if (ShellGetExecutionBreakFlag()) { + break; + } if (EFI_ERROR(Status)) { break; }