X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLevel1CommandsLib%2FIf.c;h=f548c2ea7847e7a03f151eaa613bda2696cfd20a;hb=0861edab304ce5eb6c721eb3e3b90c8d06abb50b;hp=62c713e58973b473cd2465bdb5cdf5519d40ca43;hpb=f1518f69703e1086f346a6e9d8e5a59855954178;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c index 62c713e589..f548c2ea78 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c @@ -1,7 +1,8 @@ /** @file Main file for If and else shell level 1 function. - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2013 - 2015, Hewlett-Packard Development Company, L.P.
+ Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
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 @@ -39,8 +40,8 @@ typedef enum { /** Extract the next fragment, if there is one. - @param[in,out] Statement The current remaining statement. - @param[in] Fragment The current fragment. + @param[in, out] Statement The current remaining statement. + @param[in] Fragment The current fragment. @retval FALSE There is not another fragment. @retval TRUE There is another fragment. @@ -95,10 +96,7 @@ IsValidProfile ( CONST CHAR16 *TempLocation; ProfilesString = ShellGetEnvironmentVariable(L"profiles"); - // - // According to the Shell spec this is a required environment variable. - // - ASSERT(ProfileString != NULL); + ASSERT(ProfilesString != NULL); TempLocation = StrStr(ProfilesString, String); if ((TempLocation != NULL) && (*(TempLocation-1) == L';') && (*(TempLocation+StrLen(String)) == L';')) { return (TRUE); @@ -168,7 +166,6 @@ TestOperation ( } } return (FALSE); - break; case OperatorUnsignedLessThan: case OperatorLessThan: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { @@ -204,7 +201,6 @@ TestOperation ( } return (FALSE); - break; case OperatorEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // @@ -232,7 +228,6 @@ TestOperation ( } } return (FALSE); - break; case OperatorNotEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // @@ -260,7 +255,6 @@ TestOperation ( } } return (FALSE); - break; case OperatorUnsignedGreaterOrEqual: case OperatorGreatorOrEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { @@ -295,7 +289,6 @@ TestOperation ( } } return (FALSE); - break; case OperatorLessOrEqual: case OperatorUnsignedLessOrEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { @@ -330,7 +323,6 @@ TestOperation ( } } return (FALSE); - break; default: ASSERT(FALSE); return (FALSE); @@ -340,15 +332,15 @@ TestOperation ( /** Process an if statement and determine if its is valid or not. - @param[in,out] PassingState Opon entry, the current state. Upon exit, - the new state. - @param[in] StartParameterNumber The number of the first parameter of - this statement. - @param[in] EndParameterNumber The number of the final parameter of - this statement. - @param[in] OperatorToUse The type of termination operator. - @param[in] CaseInsensitive TRUE for case insensitive, FALSE otherwise. - @param[in] ForceStringCompare TRUE for all string based, FALSE otherwise. + @param[in, out] PassingState Opon entry, the current state. Upon exit, + the new state. + @param[in] StartParameterNumber The number of the first parameter of + this statement. + @param[in] EndParameterNumber The number of the final parameter of + this statement. + @param[in] OperatorToUse The type of termination operator. + @param[in] CaseInsensitive TRUE for case insensitive, FALSE otherwise. + @param[in] ForceStringCompare TRUE for all string based, FALSE otherwise. @retval EFI_INVALID_PARAMETER A parameter was invalid. @retval EFI_SUCCESS The operation was successful. @@ -664,12 +656,9 @@ BuildNextStatement ( OUT END_TAG_TYPE *EndTag ) { - CHAR16 *Buffer; - UINTN BufferSize; - *EndTag = EndTagMax; - for(Buffer = NULL, BufferSize = 0 + for( ; ParameterNumber < gEfiShellParametersProtocol->Argc ; ParameterNumber++ ) { @@ -741,8 +730,15 @@ MoveToTagSpecial ( // CommandName = NULL; CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0); + if (CommandName == NULL) { + continue; + } CommandWalker = CommandName; - while (CommandWalker[0] == L' ') { + + // + // Skip leading spaces and tabs. + // + while ((CommandWalker[0] == L' ') || (CommandWalker[0] == L'\t')) { CommandWalker++; } TempLocation = StrStr(CommandWalker, L" "); @@ -835,12 +831,12 @@ ShellCommandRunIf ( ASSERT_EFI_ERROR(Status); if (!gEfiShellProtocol->BatchIsActive()) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"If"); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"if"); return (SHELL_UNSUPPORTED); } if (gEfiShellParametersProtocol->Argc < 3) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"if"); return (SHELL_INVALID_PARAMETER); } @@ -855,7 +851,7 @@ ShellCommandRunIf ( NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, - L"EnfIf", + L"EndIf", L"If", CurrentScriptFile!=NULL && CurrentScriptFile->CurrentCommand!=NULL @@ -918,12 +914,12 @@ ShellCommandRunIf ( // we are at the then // if (CurrentParameter+1 != gEfiShellParametersProtocol->Argc) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TEXT_AFTER_THEN), gShellLevel1HiiHandle); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_TEXT_AFTER_THEN), gShellLevel1HiiHandle, L"if"); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = PerformResultOperation(CurrentValue); if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_AFTER_BAD), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[CurrentParameter]); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_AFTER_BAD), gShellLevel1HiiHandle, L"if", gEfiShellParametersProtocol->Argv[CurrentParameter]); ShellStatus = SHELL_INVALID_PARAMETER; } } @@ -961,7 +957,7 @@ ShellCommandRunIf ( if ((Ending == EndTagOr && CurrentValue) || (Ending == EndTagAnd && !CurrentValue)) { Status = PerformResultOperation(CurrentValue); if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_AFTER_BAD), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[CurrentParameter]); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_AFTER_BAD), gShellLevel1HiiHandle, L"if", gEfiShellParametersProtocol->Argv[CurrentParameter]); ShellStatus = SHELL_INVALID_PARAMETER; } break; @@ -999,7 +995,7 @@ ShellCommandRunElse ( ASSERT_EFI_ERROR(CommandInit()); if (gEfiShellParametersProtocol->Argc > 1) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"if"); return (SHELL_INVALID_PARAMETER); } @@ -1074,7 +1070,7 @@ ShellCommandRunEndIf ( ASSERT_EFI_ERROR(CommandInit()); if (gEfiShellParametersProtocol->Argc > 1) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"if"); return (SHELL_INVALID_PARAMETER); }