From 77dcec128bde3e7f0db64d60501b5a072f9f0e8f Mon Sep 17 00:00:00 2001 From: jcarsey Date: Fri, 25 Mar 2011 20:43:03 +0000 Subject: [PATCH] Updating level 1 commands. exit - correctly convert the parameter to the return code. for - update string-to-number conversion. if - use shell string-to-number conversion and add comments. stall- add command main lib files: add comments, clarify user visible strings, add stall. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11420 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Library/UefiShellLevel1CommandsLib/Exit.c | 31 ++- .../Library/UefiShellLevel1CommandsLib/For.c | 87 ++++--- .../Library/UefiShellLevel1CommandsLib/If.c | 230 ++++++++++++------ .../UefiShellLevel1CommandsLib/Stall.c | 83 +++++++ .../UefiShellLevel1CommandsLib.c | 63 ++++- .../UefiShellLevel1CommandsLib.h | 53 +++- .../UefiShellLevel1CommandsLib.inf | 3 +- .../UefiShellLevel1CommandsLib.uni | Bin 36138 -> 38174 bytes 8 files changed, 414 insertions(+), 136 deletions(-) create mode 100644 ShellPkg/Library/UefiShellLevel1CommandsLib/Stall.c diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c index 2f2a5bf565..5620d023b1 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c @@ -1,7 +1,7 @@ /** @file Main file for exit shell level 1 function. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -36,6 +36,8 @@ ShellCommandRunExit ( LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; + UINT64 RetVal; + CONST CHAR16 *Return; ShellStatus = SHELL_SUCCESS; @@ -62,16 +64,29 @@ ShellCommandRunExit ( } } else { - // - // If we are in a batch file and /b then pass TRUE otherwise false... - // - ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b"))); - // // return the specified error code // - if (ShellCommandLineGetRawValue(Package, 1) != NULL) { - ShellStatus = (SHELL_STATUS)(ShellStrToUintn(ShellCommandLineGetRawValue(Package, 1))); + Return = ShellCommandLineGetRawValue(Package, 1); + if (Return != NULL) { + Status = ShellConvertStringToUint64(Return, &RetVal, FALSE, FALSE); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, Return); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + // + // If we are in a batch file and /b then pass TRUE otherwise false... + // + ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b"))); + + ShellStatus = (SHELL_STATUS)(RetVal); + } + } else { + // If we are in a batch file and /b then pass TRUE otherwise false... + // + ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b"))); + + ShellStatus = (SHELL_STATUS)0; } ShellCommandLineFreeVarList (Package); diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c index 297a137664..006ce6c675 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c @@ -1,7 +1,7 @@ /** @file Main file for endfor and for shell level 1 functions. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -15,6 +15,14 @@ #include "UefiShellLevel1CommandsLib.h" #include +/** + Determine if a valid string is a valid number for the 'for' command. + + @param[in] Number The pointer to the string representation of the number to test. + + @retval TRUE The number is valid. + @retval FALSE The number is not valid. +**/ BOOLEAN EFIAPI ShellIsValidForNumber ( @@ -308,7 +316,7 @@ ShellCommandRunFor ( ||!((gEfiShellParametersProtocol->Argv[1][1] >= L'a' && gEfiShellParametersProtocol->Argv[1][1] <= L'z') ||(gEfiShellParametersProtocol->Argv[1][1] >= L'A' && gEfiShellParametersProtocol->Argv[1][1] <= L'Z')) ) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_VAR), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[2]); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_VAR), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[1]); return (SHELL_INVALID_PARAMETER); } @@ -379,7 +387,7 @@ ShellCommandRunFor ( if (ArgSet == NULL) { // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0); } else { - ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0); + ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0); } ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0); // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0); @@ -397,49 +405,60 @@ ShellCommandRunFor ( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line); ShellStatus = SHELL_INVALID_PARAMETER; } else { - ArgSetWalker++; - while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') { - ArgSetWalker++; + TempSpot = StrStr(ArgSetWalker, L")"); + if (TempSpot != NULL) { + TempString = TempSpot+1; + if (*(TempString) != CHAR_NULL) { + while(TempString != NULL && *TempString == L' ') { + TempString++; + } + if (StrLen(TempString) > 0) { + TempSpot = NULL; + } + } } - if (!ShellIsValidForNumber(ArgSetWalker)) { + if (TempSpot == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line); ShellStatus = SHELL_INVALID_PARAMETER; } else { - if (ArgSetWalker[0] == L'-') { - Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1); - } else { - Info->Current = (INTN)ShellStrToUintn(ArgSetWalker); - } - ArgSetWalker = StrStr(ArgSetWalker, L" "); + *TempSpot = CHAR_NULL; + ArgSetWalker++; while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') { ArgSetWalker++; } - if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){ + if (!ShellIsValidForNumber(ArgSetWalker)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (ArgSetWalker[0] == L'-') { - Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1); + Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1); } else { - Info->End = (INTN)ShellStrToUintn(ArgSetWalker); + Info->Current = (INTN)ShellStrToUintn(ArgSetWalker); } - if (Info->Current < Info->End) { - Info->Step = 1; - } else { - Info->Step = -1; - } - ArgSetWalker = StrStr(ArgSetWalker, L" "); while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') { ArgSetWalker++; } - if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) { - TempSpot = StrStr(ArgSetWalker, L")"); - if (TempSpot == NULL) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line); - ShellStatus = SHELL_INVALID_PARAMETER; + if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + if (ArgSetWalker[0] == L'-') { + Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1); } else { - *TempSpot = CHAR_NULL; + Info->End = (INTN)ShellStrToUintn(ArgSetWalker); + } + if (Info->Current < Info->End) { + Info->Step = 1; + } else { + Info->Step = -1; + } + + ArgSetWalker = StrStr(ArgSetWalker, L" "); + while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') { + ArgSetWalker++; + } + if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) { if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line); ShellStatus = SHELL_INVALID_PARAMETER; @@ -452,8 +471,14 @@ ShellCommandRunFor ( } else { Info->Step = (INTN)ShellStrToUintn(ArgSetWalker); } + + if (StrStr(ArgSetWalker, L" ") != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), gShellLevel1HiiHandle, ArgSet, ShellCommandGetCurrentScriptFile()->CurrentCommand->Line); + ShellStatus = SHELL_INVALID_PARAMETER; + } } } + } } } @@ -529,9 +554,9 @@ ShellCommandRunFor ( if (Info->CurrentValue[0] == L'\"') { Info->CurrentValue++; } - while (Info->CurrentValue[0] == L' ') { - Info->CurrentValue++; - } +// while (Info->CurrentValue[0] == L' ') { +// Info->CurrentValue++; +// } if (Info->CurrentValue[0] == L'\"') { Info->CurrentValue++; } diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c index f3fc6b06a8..59069e568f 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c @@ -1,7 +1,7 @@ /** @file Main file for If and else shell level 1 function. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -15,34 +15,40 @@ #include "UefiShellLevel1CommandsLib.h" #include - - - typedef enum { - END_TAG_OR, - END_TAG_AND, - END_TAG_THEN, - END_TAG_MAX + EndTagOr, + EndTagAnd, + EndTagThen, + EndTagMax } END_TAG_TYPE; typedef enum { - OPERATOR_GT, - OPERATOR_LT, - OPERATOR_EQ, - OPERATOR_NE, - OPERATOR_GE, - OPERATOR_LE, - OPERATOR_UGT, - OPERATOR_ULT, - OPERATOR_UGE, - OPERATOR_ULE, - OPERATOR_MAX + OperatorGreaterThan, + OperatorLessThan, + OperatorEqual, + OperatorNotEqual, + OperatorGreatorOrEqual, + OperatorLessOrEqual, + OperatorUnisgnedGreaterThan, + OperatorUnsignedLessThan, + OperatorUnsignedGreaterOrEqual, + OperatorUnsignedLessOrEqual, + OperatorMax } BIN_OPERATOR_TYPE; +/** + Extract the next fragment, if there is one. + + @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. +**/ BOOLEAN EFIAPI IsNextFragment ( - IN CONST CHAR16 **Statement, + IN OUT CONST CHAR16 **Statement, IN CONST CHAR16 *Fragment ) { @@ -71,6 +77,14 @@ IsNextFragment ( return (FALSE); } +/** + Determine if String represents a valid profile. + + @param[in] String The pointer to the string to test. + + @retval TRUE String is a valid profile. + @retval FALSE String is not a valid profile. +**/ BOOLEAN EFIAPI IsValidProfile ( @@ -88,6 +102,17 @@ IsValidProfile ( return (FALSE); } +/** + Do a comparison between 2 things. + + @param[in] Compare1 The first item to compare. + @param[in] Compare2 The second item to compare. + @param[in] BinOp The type of comparison to perform. + @param[in] CaseInsensitive TRUE to do non-case comparison, FALSE otherwise. + @param[in] ForceStringCompare TRUE to force string comparison, FALSE otherwise. + + @return The result of the comparison. +**/ BOOLEAN EFIAPI TestOperation ( @@ -105,8 +130,8 @@ TestOperation ( // "Compare1 BinOp Compare2" // switch (BinOp) { - case OPERATOR_UGT: - case OPERATOR_GT: + case OperatorUnisgnedGreaterThan: + case OperatorGreaterThan: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare @@ -119,16 +144,16 @@ TestOperation ( // numeric compare // if (Compare1[0] == L'-') { - Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1); + Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { - Cmp1 = (INTN)StrDecimalToUintn(Compare1); + Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { - Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1); + Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { - Cmp2 = (INTN)StrDecimalToUintn(Compare2); + Cmp2 = (INTN)ShellStrToUintn(Compare2); } - if (BinOp == OPERATOR_GT) { + if (BinOp == OperatorGreaterThan) { if (Cmp1 > Cmp2) { return (TRUE); } @@ -140,8 +165,8 @@ TestOperation ( } return (FALSE); break; - case OPERATOR_ULT: - case OPERATOR_LT: + case OperatorUnsignedLessThan: + case OperatorLessThan: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare @@ -154,16 +179,16 @@ TestOperation ( // numeric compare // if (Compare1[0] == L'-') { - Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1); + Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { - Cmp1 = (INTN)StrDecimalToUintn(Compare1); + Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { - Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1); + Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { - Cmp2 = (INTN)StrDecimalToUintn(Compare2); + Cmp2 = (INTN)ShellStrToUintn(Compare2); } - if (BinOp == OPERATOR_LT) { + if (BinOp == OperatorLessThan) { if (Cmp1 < Cmp2) { return (TRUE); } @@ -176,7 +201,7 @@ TestOperation ( } return (FALSE); break; - case OPERATOR_EQ: + case OperatorEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare @@ -204,7 +229,7 @@ TestOperation ( } return (FALSE); break; - case OPERATOR_NE: + case OperatorNotEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare @@ -217,14 +242,14 @@ TestOperation ( // numeric compare // if (Compare1[0] == L'-') { - Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1); + Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { - Cmp1 = (INTN)StrDecimalToUintn(Compare1); + Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { - Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1); + Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { - Cmp2 = (INTN)StrDecimalToUintn(Compare2); + Cmp2 = (INTN)ShellStrToUintn(Compare2); } if (Cmp1 != Cmp2) { return (TRUE); @@ -232,8 +257,8 @@ TestOperation ( } return (FALSE); break; - case OPERATOR_UGE: - case OPERATOR_GE: + case OperatorUnsignedGreaterOrEqual: + case OperatorGreatorOrEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare @@ -246,16 +271,16 @@ TestOperation ( // numeric compare // if (Compare1[0] == L'-') { - Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1); + Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { - Cmp1 = (INTN)StrDecimalToUintn(Compare1); + Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { - Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1); + Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { - Cmp2 = (INTN)StrDecimalToUintn(Compare2); + Cmp2 = (INTN)ShellStrToUintn(Compare2); } - if (BinOp == OPERATOR_GE) { + if (BinOp == OperatorGreatorOrEqual) { if (Cmp1 >= Cmp2) { return (TRUE); } @@ -267,8 +292,8 @@ TestOperation ( } return (FALSE); break; - case OPERATOR_LE: - case OPERATOR_ULE: + case OperatorLessOrEqual: + case OperatorUnsignedLessOrEqual: if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) { // // string compare @@ -281,16 +306,16 @@ TestOperation ( // numeric compare // if (Compare1[0] == L'-') { - Cmp1 = 0 - (INTN)StrDecimalToUintn(Compare1+1); + Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1); } else { - Cmp1 = (INTN)StrDecimalToUintn(Compare1); + Cmp1 = (INTN)ShellStrToUintn(Compare1); } if (Compare2[0] == L'-') { - Cmp2 = 0 - (INTN)StrDecimalToUintn(Compare2+1); + Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1); } else { - Cmp2 = (INTN)StrDecimalToUintn(Compare2); + Cmp2 = (INTN)ShellStrToUintn(Compare2); } - if (BinOp == OPERATOR_LE) { + if (BinOp == OperatorLessOrEqual) { if (Cmp1 <= Cmp2) { return (TRUE); } @@ -308,6 +333,22 @@ 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. + + @retval EFI_INVALID_PARAMETER A parameter was invalid. + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS EFIAPI ProcessStatement ( @@ -329,10 +370,10 @@ ProcessStatement ( CHAR16 HexString[20]; CHAR16 *TempSpot; - ASSERT((END_TAG_TYPE)OperatorToUse != END_TAG_THEN); + ASSERT((END_TAG_TYPE)OperatorToUse != EndTagThen); Status = EFI_SUCCESS; - BinOp = OPERATOR_MAX; + BinOp = OperatorMax; OperationResult = FALSE; StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber]; if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"not")) { @@ -397,7 +438,7 @@ ProcessStatement ( // Compare1 = NULL; Compare2 = NULL; - BinOp = OPERATOR_MAX; + BinOp = OperatorMax; // // get the first item @@ -473,27 +514,27 @@ ProcessStatement ( ASSERT(StartParameterNumber+1Argv[StartParameterNumber+1]; if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"gt")) { - BinOp = OPERATOR_GT; + BinOp = OperatorGreaterThan; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"lt")) { - BinOp = OPERATOR_LT; + BinOp = OperatorLessThan; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"eq")) { - BinOp = OPERATOR_EQ; + BinOp = OperatorEqual; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ne")) { - BinOp = OPERATOR_NE; + BinOp = OperatorNotEqual; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ge")) { - BinOp = OPERATOR_GE; + BinOp = OperatorGreatorOrEqual; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"le")) { - BinOp = OPERATOR_LE; + BinOp = OperatorLessOrEqual; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"==")) { - BinOp = OPERATOR_EQ; + BinOp = OperatorEqual; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ugt")) { - BinOp = OPERATOR_UGT; + BinOp = OperatorUnisgnedGreaterThan; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ult")) { - BinOp = OPERATOR_ULT; + BinOp = OperatorUnsignedLessThan; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"uge")) { - BinOp = OPERATOR_UGE; + BinOp = OperatorUnsignedGreaterOrEqual; } else if (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ule")) { - BinOp = OPERATOR_ULE; + BinOp = OperatorUnsignedLessOrEqual; } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_INVALID_BINOP), gShellLevel1HiiHandle, StatementWalker); Status = EFI_INVALID_PARAMETER; @@ -566,7 +607,7 @@ ProcessStatement ( Compare2 = StrnCatGrow(&Compare2, NULL, StatementWalker, 0); } - if (Compare1 != NULL && Compare2 != NULL && BinOp != OPERATOR_MAX) { + if (Compare1 != NULL && Compare2 != NULL && BinOp != OperatorMax) { OperationResult = TestOperation(Compare1, Compare2, BinOp, CaseInsensitive, ForceStringCompare); } @@ -583,13 +624,13 @@ ProcessStatement ( OperationResult = (BOOLEAN)(!OperationResult); } switch(OperatorToUse) { - case END_TAG_OR: + case EndTagOr: *PassingState = (BOOLEAN)(*PassingState || OperationResult); break; - case END_TAG_AND: + case EndTagAnd: *PassingState = (BOOLEAN)(*PassingState && OperationResult); break; - case END_TAG_MAX: + case EndTagMax: *PassingState = (BOOLEAN)(OperationResult); break; default: @@ -599,6 +640,18 @@ ProcessStatement ( return (Status); } +/** + Break up the next part of the if statement (until the next 'and', 'or', or 'then'). + + @param[in] ParameterNumber The current parameter number. + @param[out] EndParameter Upon successful return, will point to the + parameter to start the next iteration with. + @param[out] EndTag Upon successful return, will point to the + type that was found at the end of this statement. + + @retval TRUE A valid statement was found. + @retval FALSE A valid statement was not found. +**/ BOOLEAN EFIAPI BuildNextStatement ( @@ -610,7 +663,7 @@ BuildNextStatement ( CHAR16 *Buffer; UINTN BufferSize; - *EndTag = END_TAG_MAX; + *EndTag = EndTagMax; for(Buffer = NULL, BufferSize = 0 ; ParameterNumber < gEfiShellParametersProtocol->Argc @@ -621,30 +674,39 @@ BuildNextStatement ( gEfiShellParametersProtocol->Argv[ParameterNumber], L"or") == 0) { *EndParameter = ParameterNumber - 1; - *EndTag = END_TAG_OR; + *EndTag = EndTagOr; break; } else if (gUnicodeCollation->StriColl( gUnicodeCollation, gEfiShellParametersProtocol->Argv[ParameterNumber], L"and") == 0) { *EndParameter = ParameterNumber - 1; - *EndTag = END_TAG_AND; + *EndTag = EndTagAnd; break; } else if (gUnicodeCollation->StriColl( gUnicodeCollation, gEfiShellParametersProtocol->Argv[ParameterNumber], L"then") == 0) { *EndParameter = ParameterNumber - 1; - *EndTag = END_TAG_THEN; + *EndTag = EndTagThen; break; } } - if (*EndTag == END_TAG_MAX) { + if (*EndTag == EndTagMax) { return (FALSE); } return (TRUE); } +/** + Move the script file pointer to a different place in the script file. + This one is special since it handles the if/else/endif syntax. + + @param[in] ScriptFile The script file from GetCurrnetScriptFile(). + + @retval TRUE The move target was found and the move was successful. + @retval FALSE Something went wrong. +**/ BOOLEAN EFIAPI MoveToTagSpecial ( @@ -721,6 +783,14 @@ MoveToTagSpecial ( return (Found); } +/** + Deal with the result of the if operation. + + @param[in] Result The result of the if. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_NOT_FOUND The ending tag could not be found. +**/ EFI_STATUS EFIAPI PerformResultOperation ( @@ -822,7 +892,7 @@ ShellCommandRunIf ( ForceString = FALSE; } - for ( ShellStatus = SHELL_SUCCESS, CurrentValue = FALSE, Ending = END_TAG_MAX + for ( ShellStatus = SHELL_SUCCESS, CurrentValue = FALSE, Ending = EndTagMax ; CurrentParameter < gEfiShellParametersProtocol->Argc && ShellStatus == SHELL_SUCCESS ; CurrentParameter++) { if (gUnicodeCollation->StriColl( @@ -862,7 +932,7 @@ ShellCommandRunIf ( // // Optomize to get out of the loop early... // - if ((Ending == END_TAG_OR && CurrentValue) || (Ending == END_TAG_AND && !CurrentValue)) { + 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]); @@ -877,7 +947,7 @@ ShellCommandRunIf ( // // Skip over the or or and parameter. // - if (Ending == END_TAG_OR || Ending == END_TAG_AND) { + if (Ending == EndTagOr || Ending == EndTagAnd) { CurrentParameter++; } } diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/Stall.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/Stall.c new file mode 100644 index 0000000000..2270323190 --- /dev/null +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/Stall.c @@ -0,0 +1,83 @@ +/** @file + Main file for stall shell level 1 function. + + Copyright (c) 2011, 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 + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include "UefiShellLevel1CommandsLib.h" + +/** + Function for 'stall' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunStall ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + SHELL_STATUS ShellStatus; + UINT64 Intermediate; + + ShellStatus = SHELL_SUCCESS; + + // + // initialize the shell lib (we must be in non-auto-init...) + // + Status = ShellInitialize(); + ASSERT_EFI_ERROR(Status); + + Status = CommandInit(); + ASSERT_EFI_ERROR(Status); + + // + // parse the command line + // + Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); + if (EFI_ERROR(Status)) { + if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam); + FreePool(ProblemParam); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + if (ShellCommandLineGetRawValue(Package, 2) != NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = ShellConvertStringToUint64(ShellCommandLineGetRawValue(Package, 1), &Intermediate, FALSE, FALSE); + if (EFI_ERROR(Status) || ((UINT64)(UINTN)(Intermediate)) != Intermediate) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel1HiiHandle, ShellCommandLineGetRawValue(Package, 1)); + ShellStatus = SHELL_INVALID_PARAMETER; + } else { + Status = gBS->Stall((UINTN)Intermediate); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_STALL_FAILED), gShellLevel1HiiHandle, Status); + ShellStatus = SHELL_DEVICE_ERROR; + } + } + } + ShellCommandLineFreeVarList (Package); + } + return (ShellStatus); +} + diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c index 47b6f92864..bae834f164 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c @@ -1,7 +1,7 @@ /** @file Main file for NULL named library for level 1 shell command functions. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -22,6 +22,11 @@ CONST EFI_GUID gShellLevel1HiiGuid = \ }; +/** + Return the help text filename. Only used if no HII information found. + + @retval the filename. +**/ CONST CHAR16* EFIAPI ShellCommandGetManFileNameLevel1 ( @@ -64,6 +69,7 @@ ShellLevel1CommandsLibConstructor ( // // install our shell command handlers that are always installed // + ShellCommandRegisterCommandName(L"stall", ShellCommandRunStall , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_STALL) )); ShellCommandRegisterCommandName(L"for", ShellCommandRunFor , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_FOR) )); ShellCommandRegisterCommandName(L"goto", ShellCommandRunGoto , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_GOTO) )); ShellCommandRegisterCommandName(L"if", ShellCommandRunIf , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_IF) )); @@ -78,6 +84,9 @@ ShellLevel1CommandsLibConstructor ( /** Destructor for the library. free any resources. + + @param ImageHandle The image handle of the process. + @param SystemTable The EFI System Table pointer. **/ EFI_STATUS EFIAPI @@ -92,6 +101,29 @@ ShellLevel1CommandsLibDestructor ( return (EFI_SUCCESS); } +/** + Test a node to see if meets the criterion. + + It functions so that count starts at 1 and it increases or decreases when it + hits the specified tags. when it hits zero the location has been found. + + DecrementerTag and IncrementerTag are used to get around for/endfor and + similar paired types where the entire middle should be ignored. + + If label is used it will be used instead of the count. + + @param[in] Function The function to use to enumerate through the + list. Normally GetNextNode or GetPreviousNode. + @param[in] DecrementerTag The tag to decrement the count at. + @param[in] IncrementerTag The tag to increment the count at. + @param[in] Label A label to look for. + @param[in,out] ScriptFile The pointer to the current script file structure. + @param[in] MovePast TRUE makes function return 1 past the found + location. + @param[in] FindOnly TRUE to not change the ScriptFile. + @param[in] CommandNode The pointer to the Node to test. + @param[in,out] TargetCount The pointer to the current count. +**/ BOOLEAN EFIAPI TestNodeForMove ( @@ -99,11 +131,11 @@ TestNodeForMove ( IN CONST CHAR16 *DecrementerTag, IN CONST CHAR16 *IncrementerTag, IN CONST CHAR16 *Label OPTIONAL, - IN SCRIPT_FILE *ScriptFile, + IN OUT SCRIPT_FILE *ScriptFile, IN CONST BOOLEAN MovePast, IN CONST BOOLEAN FindOnly, IN CONST SCRIPT_COMMAND_LIST *CommandNode, - IN UINTN *TargetCount + IN OUT UINTN *TargetCount ) { BOOLEAN Found; @@ -186,6 +218,29 @@ TestNodeForMove ( return (Found); } +/** + Move the script pointer from 1 tag (line) to another. + + It functions so that count starts at 1 and it increases or decreases when it + hits the specified tags. when it hits zero the location has been found. + + DecrementerTag and IncrementerTag are used to get around for/endfor and + similar paired types where the entire middle should be ignored. + + If label is used it will be used instead of the count. + + @param[in] Function The function to use to enumerate through the + list. Normally GetNextNode or GetPreviousNode. + @param[in] DecrementerTag The tag to decrement the count at. + @param[in] IncrementerTag The tag to increment the count at. + @param[in] Label A label to look for. + @param[in,out] ScriptFile The pointer to the current script file structure. + @param[in] MovePast TRUE makes function return 1 past the found + location. + @param[in] FindOnly TRUE to not change the ScriptFile. + @param[in] WrapAroundScript TRUE to wrap end-to-begining or vise versa in + searching. +**/ BOOLEAN EFIAPI MoveToTag ( @@ -193,7 +248,7 @@ MoveToTag ( IN CONST CHAR16 *DecrementerTag, IN CONST CHAR16 *IncrementerTag, IN CONST CHAR16 *Label OPTIONAL, - IN SCRIPT_FILE *ScriptFile, + IN OUT SCRIPT_FILE *ScriptFile, IN CONST BOOLEAN MovePast, IN CONST BOOLEAN FindOnly, IN CONST BOOLEAN WrapAroundScript diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.h b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.h index b0aa51bc1b..eadb501e20 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.h +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.h @@ -1,7 +1,7 @@ /** @file Main file for NULL named library for level 1 shell command functions. - Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2011, 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 @@ -12,6 +12,9 @@ **/ +#if !defined (_UEFI_SHELL_LEVEL1_COMMANDS_LIB_H_) +#define _UEFI_SHELL_LEVEL1_COMMANDS_LIB_H_ + #include #include @@ -39,6 +42,19 @@ extern EFI_HANDLE gShellLevel1HiiHandle; extern CONST EFI_GUID gShellLevel1HiiGuid; +/** + Function for 'stall' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +SHELL_STATUS +EFIAPI +ShellCommandRunStall ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ); + /** Function for 'exit' command. @@ -156,16 +172,27 @@ LIST_ENTRY * ); /** - Function to move to a spacified tag in a script file structure. - - @param[in] Function The pointer to the function to move with. - @param[in] DecrementerTag The pointer to a string to decrement upon finding. - @param[in] IncrementerTag The pointer to a string to increment upon finding. - @param[in] Label A Label to look for. - @param[in] ScriptFile The script file structure to look in. - @param[in] MovePast TRUE to go to the element just after the found one. FALSE otherwise. - @param[in] FindOnly FALSE to change the execution point in the script file structure. TRUE otherwise. - @param[in] WrapAroundScript TRUE to go to begining when end is hit, or vise versa. FALSE otherwise. + Move the script pointer from 1 tag (line) to another. + + It functions so that count starts at 1 and it increases or decreases when it + hits the specified tags. when it hits zero the location has been found. + + DecrementerTag and IncrementerTag are used to get around for/endfor and + similar paired types where the entire middle should be ignored. + + If label is used it will be used instead of the count. + + @param[in] Function The function to use to enumerate through the + list. Normally GetNextNode or GetPreviousNode. + @param[in] DecrementerTag The tag to decrement the count at. + @param[in] IncrementerTag The tag to increment the count at. + @param[in] Label A label to look for. + @param[in,out] ScriptFile The pointer to the current script file structure. + @param[in] MovePast TRUE makes function return 1 past the found + location. + @param[in] FindOnly TRUE to not change the ScriptFile. + @param[in] WrapAroundScript TRUE to wrap end-to-begining or vise versa in + searching. **/ BOOLEAN EFIAPI @@ -174,9 +201,11 @@ MoveToTag ( IN CONST CHAR16 *DecrementerTag, IN CONST CHAR16 *IncrementerTag, IN CONST CHAR16 *Label OPTIONAL, - IN SCRIPT_FILE *ScriptFile, + IN OUT SCRIPT_FILE *ScriptFile, IN CONST BOOLEAN MovePast, IN CONST BOOLEAN FindOnly, IN CONST BOOLEAN WrapAroundScript ); +#endif + diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf index b4697f3908..8b04b7d369 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf @@ -1,7 +1,7 @@ ## @file # Provides shell level 1 functions # -# Copyright (c) 2009-2010, Intel Corporation. All rights reserved.
+# Copyright (c) 2009-2011, 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 @@ -31,6 +31,7 @@ If.c For.c Shift.c + Stall.c [Packages] MdePkg/MdePkg.dec diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.uni b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.uni index 47e44ca7b386b212f46204969e51f2be440660a1..56bfaea92d4d54e35cd01b79e1981ac77bf3856f 100644 GIT binary patch delta 1231 zcmZ`(O=}ZT6unkV6Jx9~Ov2y?(_)}?QFYPcN{l9IK%1C}>821SX=(?ONt;Y8E@}x@ zaN)vocP>N_Togg1zrekV`U}LB3pZ}vdG5TKWU$B(`rfH_n-P&^ru(ynA1=hlaD6#X;v6antmt5n#a23#b)Z0p8Xi>xku^j* z9_1c(eVju#-dooBFf%(fLc%SVY|a(Yawf`)$%}F9ktvN>9pQ-BhF zZx;Frs>!I8E5(r=pos-spSg;Nw>N=^4tTq*UkKwYQ3-X$dLMUN8ewYp8D85Xdqe#3aH7;V-Vd(uN3Q`n(!6oYF-WDFAm)av(JNJ4a{X8b&qWY zTq_hq-uP3hiDu*K;t=`2(ZkFIQANcO;!p48fSEY72|oyP{{i#eD~U_uGsDaA=ZE+_ Ot>9z@-kG5Uout2zNB}zk delta 90 zcmbQYifPp>rU?Oz1{(u^vT~L&Br@bMWHO{o4rhCf#A8eoo}9pLFgcH-2}$%X$8&b5 Yj>#LjtT$_Mg|SV3&?B-rL$Ik900Y$=#sB~S -- 2.39.2