X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLevel1CommandsLib%2FIf.c;h=35c5ca6835817f942e6044d72c7641c0eb278558;hp=a3c4482bb3bfc3284347a7deba775f65e1ee3f0c;hb=2d70c90d2e8bf4405c5c16c0c7ea5b2446d1517a;hpb=33c031ee2092282a069ce07d30202082ceaf61fe diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c index a3c4482bb3..35c5ca6835 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.
+ (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
+ Copyright (c) 2009 - 2016, 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,17 +40,19 @@ 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. + @param[out] Match TRUE when there is another Fragment in Statement, + FALSE otherwise. - @retval FALSE There is not another fragment. - @retval TRUE There is another fragment. + @retval EFI_SUCCESS The match operation is performed successfully. + @retval EFI_OUT_OF_RESOURCES Out of resources. **/ -BOOLEAN -EFIAPI +EFI_STATUS IsNextFragment ( IN OUT CONST CHAR16 **Statement, - IN CONST CHAR16 *Fragment + IN CONST CHAR16 *Fragment, + OUT BOOLEAN *Match ) { CHAR16 *Tester; @@ -57,7 +60,9 @@ IsNextFragment ( Tester = NULL; Tester = StrnCatGrow(&Tester, NULL, *Statement, StrLen(Fragment)); - ASSERT(Tester != NULL); + if (Tester == NULL) { + return EFI_OUT_OF_RESOURCES; + } Tester[StrLen(Fragment)] = CHAR_NULL; if (gUnicodeCollation->StriColl( gUnicodeCollation, @@ -70,11 +75,12 @@ IsNextFragment ( while (*Statement[0] == L' ') { (*Statement)++; } - FreePool(Tester); - return (TRUE); + *Match = TRUE; + } else { + *Match = FALSE; } FreePool(Tester); - return (FALSE); + return EFI_SUCCESS; } /** @@ -86,7 +92,6 @@ IsNextFragment ( @retval FALSE String is not a valid profile. **/ BOOLEAN -EFIAPI IsValidProfile ( IN CONST CHAR16 *String ) @@ -95,6 +100,7 @@ IsValidProfile ( CONST CHAR16 *TempLocation; ProfilesString = ShellGetEnvironmentVariable(L"profiles"); + ASSERT(ProfilesString != NULL); TempLocation = StrStr(ProfilesString, String); if ((TempLocation != NULL) && (*(TempLocation-1) == L';') && (*(TempLocation+StrLen(String)) == L';')) { return (TRUE); @@ -114,7 +120,6 @@ IsValidProfile ( @return The result of the comparison. **/ BOOLEAN -EFIAPI TestOperation ( IN CONST CHAR16 *Compare1, IN CONST CHAR16 *Compare2, @@ -164,7 +169,6 @@ TestOperation ( } } return (FALSE); - break; case OperatorUnsignedLessThan: case OperatorLessThan: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { @@ -200,7 +204,6 @@ TestOperation ( } return (FALSE); - break; case OperatorEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // @@ -228,7 +231,6 @@ TestOperation ( } } return (FALSE); - break; case OperatorNotEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // @@ -256,7 +258,6 @@ TestOperation ( } } return (FALSE); - break; case OperatorUnsignedGreaterOrEqual: case OperatorGreatorOrEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { @@ -291,7 +292,6 @@ TestOperation ( } } return (FALSE); - break; case OperatorLessOrEqual: case OperatorUnsignedLessOrEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { @@ -326,7 +326,6 @@ TestOperation ( } } return (FALSE); - break; default: ASSERT(FALSE); return (FALSE); @@ -336,21 +335,20 @@ 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. **/ EFI_STATUS -EFIAPI ProcessStatement ( IN OUT BOOLEAN *PassingState, IN UINTN StartParameterNumber, @@ -369,14 +367,16 @@ ProcessStatement ( CHAR16 *Compare2; CHAR16 HexString[20]; CHAR16 *TempSpot; + BOOLEAN Match; ASSERT((END_TAG_TYPE)OperatorToUse != EndTagThen); Status = EFI_SUCCESS; BinOp = OperatorMax; OperationResult = FALSE; + Match = FALSE; StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber]; - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"not")) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"not", &Match)) && Match) { NotPresent = TRUE; StatementWalker = gEfiShellParametersProtocol->Argv[++StartParameterNumber]; } else { @@ -386,16 +386,19 @@ ProcessStatement ( // // now check for 'boolfunc' operators // - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"isint")) { - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"isint", &Match)) && Match) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match + && StatementWalker[StrLen(StatementWalker)-1] == L')') { StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL; OperationResult = ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE); } else { Status = EFI_INVALID_PARAMETER; ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"isint"); } - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exists") || IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exist")) { - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') { + } else if ((!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exists", &Match)) && Match) || + (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"exist", &Match)) && Match)) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match && + StatementWalker[StrLen(StatementWalker)-1] == L')') { StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL; // // is what remains a file in CWD??? @@ -407,8 +410,9 @@ ProcessStatement ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"exist(s)"); Status = EFI_INVALID_PARAMETER; } - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"available")) { - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"available", &Match)) && Match) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match && + StatementWalker[StrLen(StatementWalker)-1] == L')') { StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL; // // is what remains a file in the CWD or path??? @@ -418,8 +422,9 @@ ProcessStatement ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"available"); Status = EFI_INVALID_PARAMETER; } - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"profile")) { - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && StatementWalker[StrLen(StatementWalker)-1] == L')') { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"profile", &Match)) && Match) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match && + StatementWalker[StrLen(StatementWalker)-1] == L')') { // // Chop off that ')' // @@ -444,9 +449,9 @@ ProcessStatement ( // get the first item // StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber]; - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror")) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror", &Match)) && Match) { TempSpot = StrStr(StatementWalker, L")"); - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match && TempSpot != NULL) { *TempSpot = CHAR_NULL; if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) { UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT); @@ -461,9 +466,9 @@ ProcessStatement ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror"); Status = EFI_INVALID_PARAMETER; } - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror", &Match)) && Match) { TempSpot = StrStr(StatementWalker, L")"); - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match && TempSpot != NULL) { *TempSpot = CHAR_NULL; if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) { UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>2)); @@ -478,9 +483,9 @@ ProcessStatement ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror"); Status = EFI_INVALID_PARAMETER; } - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"oemerror")) { + } else if (!EFI_ERROR (IsNextFragment ((CONST CHAR16**)(&StatementWalker), L"oemerror", &Match)) && Match) { TempSpot = StrStr(StatementWalker, L")"); - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match && TempSpot != NULL) { TempSpot = CHAR_NULL; if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) { UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>1)); @@ -513,27 +518,27 @@ ProcessStatement ( // ASSERT(StartParameterNumber+1Argv[StartParameterNumber+1]; - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"gt")) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"gt", &Match)) && Match) { BinOp = OperatorGreaterThan; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"lt")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"lt", &Match)) && Match) { BinOp = OperatorLessThan; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"eq")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"eq", &Match)) && Match) { BinOp = OperatorEqual; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ne")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ne", &Match)) && Match) { BinOp = OperatorNotEqual; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ge")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ge", &Match)) && Match) { BinOp = OperatorGreatorOrEqual; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"le")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"le", &Match)) && Match) { BinOp = OperatorLessOrEqual; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"==")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"==", &Match)) && Match) { BinOp = OperatorEqual; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ugt")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ugt", &Match)) && Match) { BinOp = OperatorUnisgnedGreaterThan; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ult")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ult", &Match)) && Match) { BinOp = OperatorUnsignedLessThan; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"uge")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"uge", &Match)) && Match) { BinOp = OperatorUnsignedGreaterOrEqual; - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ule")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ule", &Match)) && Match) { BinOp = OperatorUnsignedLessOrEqual; } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_INVALID_BINOP), gShellLevel1HiiHandle, StatementWalker); @@ -545,9 +550,9 @@ ProcessStatement ( // ASSERT(StartParameterNumber+2<=EndParameterNumber); StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber+2]; - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror")) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror", &Match)) && Match) { TempSpot = StrStr(StatementWalker, L")"); - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match && TempSpot != NULL) { TempSpot = CHAR_NULL; if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) { UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT); @@ -565,9 +570,9 @@ ProcessStatement ( // // can this be collapsed into the above? // - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror")) { + } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror", &Match)) && Match) { TempSpot = StrStr(StatementWalker, L")"); - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match && TempSpot != NULL) { TempSpot = CHAR_NULL; if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) { UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>2)); @@ -582,9 +587,9 @@ ProcessStatement ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror"); Status = EFI_INVALID_PARAMETER; } - } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"oemerror")) { + } else if (!EFI_ERROR (IsNextFragment ((CONST CHAR16**)(&StatementWalker), L"oemerror", &Match)) && Match) { TempSpot = StrStr(StatementWalker, L")"); - if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(") && TempSpot != NULL) { + if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"(", &Match)) && Match && TempSpot != NULL) { TempSpot = CHAR_NULL; if (ShellIsHexOrDecimalNumber(StatementWalker, FALSE, FALSE)) { UnicodeSPrint(HexString, sizeof(HexString), L"0x%x", ShellStrToUintn(StatementWalker)|MAX_BIT|(MAX_BIT>>1)); @@ -653,19 +658,15 @@ ProcessStatement ( @retval FALSE A valid statement was not found. **/ BOOLEAN -EFIAPI BuildNextStatement ( IN UINTN ParameterNumber, OUT UINTN *EndParameter, OUT END_TAG_TYPE *EndTag ) { - CHAR16 *Buffer; - UINTN BufferSize; - *EndTag = EndTagMax; - for(Buffer = NULL, BufferSize = 0 + for( ; ParameterNumber < gEfiShellParametersProtocol->Argc ; ParameterNumber++ ) { @@ -708,7 +709,6 @@ BuildNextStatement ( @retval FALSE Something went wrong. **/ BOOLEAN -EFIAPI MoveToTagSpecial ( IN SCRIPT_FILE *ScriptFile ) @@ -737,8 +737,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" "); @@ -792,7 +799,6 @@ MoveToTagSpecial ( @retval EFI_NOT_FOUND The ending tag could not be found. **/ EFI_STATUS -EFIAPI PerformResultOperation ( IN CONST BOOLEAN Result ) @@ -825,36 +831,37 @@ ShellCommandRunIf ( BOOLEAN CurrentValue; END_TAG_TYPE Ending; END_TAG_TYPE PreviousEnding; - + SCRIPT_FILE *CurrentScriptFile; Status = CommandInit(); 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); } // // Make sure that an End exists. // - if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), TRUE, TRUE, FALSE)) { + CurrentScriptFile = ShellCommandGetCurrentScriptFile(); + if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, - L"EnfIf", + L"EndIf", L"If", - ShellCommandGetCurrentScriptFile()!=NULL - &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL - ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0); + CurrentScriptFile!=NULL + && CurrentScriptFile->CurrentCommand!=NULL + ? CurrentScriptFile->CurrentCommand->Line:0); return (SHELL_DEVICE_ERROR); } @@ -913,12 +920,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; } } @@ -928,7 +935,18 @@ ShellCommandRunIf ( // build up the next statement for analysis // if (!BuildNextStatement(CurrentParameter, &EndParameter, &Ending)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_NO_MATCHING), gShellLevel1HiiHandle, L"Then", L"If", ShellCommandGetCurrentScriptFile()->CurrentCommand->Line); + CurrentScriptFile = ShellCommandGetCurrentScriptFile(); + ShellPrintHiiEx( + -1, + -1, + NULL, + STRING_TOKEN (STR_SYNTAX_NO_MATCHING), + gShellLevel1HiiHandle, + L"Then", + L"If", + CurrentScriptFile!=NULL + && CurrentScriptFile->CurrentCommand!=NULL + ? CurrentScriptFile->CurrentCommand->Line:0); ShellStatus = SHELL_INVALID_PARAMETER; } else { // @@ -945,7 +963,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; @@ -979,10 +997,14 @@ ShellCommandRunElse ( IN EFI_SYSTEM_TABLE *SystemTable ) { - ASSERT_EFI_ERROR(CommandInit()); + EFI_STATUS Status; + SCRIPT_FILE *CurrentScriptFile; + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); 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); } @@ -991,8 +1013,9 @@ ShellCommandRunElse ( return (SHELL_UNSUPPORTED); } + CurrentScriptFile = ShellCommandGetCurrentScriptFile(); - if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) { + if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, CurrentScriptFile, FALSE, TRUE, FALSE)) { ShellPrintHiiEx( -1, -1, @@ -1001,12 +1024,12 @@ ShellCommandRunElse ( gShellLevel1HiiHandle, L"If", L"Else", - ShellCommandGetCurrentScriptFile()!=NULL - &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL - ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0); + CurrentScriptFile!=NULL + && CurrentScriptFile->CurrentCommand!=NULL + ? CurrentScriptFile->CurrentCommand->Line:0); return (SHELL_DEVICE_ERROR); } - if (!MoveToTag(GetPreviousNode, L"if", L"else", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) { + if (!MoveToTag(GetPreviousNode, L"if", L"else", NULL, CurrentScriptFile, FALSE, TRUE, FALSE)) { ShellPrintHiiEx( -1, -1, @@ -1015,13 +1038,13 @@ ShellCommandRunElse ( gShellLevel1HiiHandle, L"If", L"Else", - ShellCommandGetCurrentScriptFile()!=NULL - &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL - ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0); + CurrentScriptFile!=NULL + && CurrentScriptFile->CurrentCommand!=NULL + ? CurrentScriptFile->CurrentCommand->Line:0); return (SHELL_DEVICE_ERROR); } - if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE)) { + if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, CurrentScriptFile, FALSE, FALSE, FALSE)) { ShellPrintHiiEx( -1, -1, @@ -1030,9 +1053,9 @@ ShellCommandRunElse ( gShellLevel1HiiHandle, L"EndIf", "Else", - ShellCommandGetCurrentScriptFile()!=NULL - &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL - ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0); + CurrentScriptFile!=NULL + && CurrentScriptFile->CurrentCommand!=NULL + ? CurrentScriptFile->CurrentCommand->Line:0); return (SHELL_DEVICE_ERROR); } @@ -1052,10 +1075,14 @@ ShellCommandRunEndIf ( IN EFI_SYSTEM_TABLE *SystemTable ) { - ASSERT_EFI_ERROR(CommandInit()); + EFI_STATUS Status; + SCRIPT_FILE *CurrentScriptFile; + + Status = CommandInit (); + ASSERT_EFI_ERROR (Status); 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); } @@ -1064,7 +1091,8 @@ ShellCommandRunEndIf ( return (SHELL_UNSUPPORTED); } - if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, ShellCommandGetCurrentScriptFile(), FALSE, TRUE, FALSE)) { + CurrentScriptFile = ShellCommandGetCurrentScriptFile(); + if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, CurrentScriptFile, FALSE, TRUE, FALSE)) { ShellPrintHiiEx( -1, -1, @@ -1073,9 +1101,9 @@ ShellCommandRunEndIf ( gShellLevel1HiiHandle, L"If", L"EndIf", - ShellCommandGetCurrentScriptFile()!=NULL - &&ShellCommandGetCurrentScriptFile()->CurrentCommand!=NULL - ?ShellCommandGetCurrentScriptFile()->CurrentCommand->Line:0); + CurrentScriptFile!=NULL + && CurrentScriptFile->CurrentCommand!=NULL + ? CurrentScriptFile->CurrentCommand->Line:0); return (SHELL_DEVICE_ERROR); }