diff options
author | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-03-25 20:43:03 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-03-25 20:43:03 +0000 |
commit | 77dcec128bde3e7f0db64d60501b5a072f9f0e8f (patch) | |
tree | 6ae0989456c54301f7c3d35f146316e3eae49324 /ShellPkg/Library/UefiShellLevel1CommandsLib/If.c | |
parent | a47c681fc0fd1c2ebc08973a4742f0188eafcf44 (diff) | |
download | edk2-platforms-77dcec128bde3e7f0db64d60501b5a072f9f0e8f.tar.xz |
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
Diffstat (limited to 'ShellPkg/Library/UefiShellLevel1CommandsLib/If.c')
-rw-r--r-- | ShellPkg/Library/UefiShellLevel1CommandsLib/If.c | 230 |
1 files changed, 150 insertions, 80 deletions
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.<BR>
+ Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
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 <Library/PrintLib.h>
-
-
-
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+1<EndParameterNumber);
StatementWalker = gEfiShellParametersProtocol->Argv[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++;
}
}
|