summaryrefslogtreecommitdiff
path: root/Core/ShellPkg/Library/UefiShellLevel1CommandsLib
diff options
context:
space:
mode:
Diffstat (limited to 'Core/ShellPkg/Library/UefiShellLevel1CommandsLib')
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c97
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c754
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c105
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c1117
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c64
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Stall.c84
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c310
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.h211
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf58
-rw-r--r--Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.uni504
10 files changed, 3304 insertions, 0 deletions
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c
new file mode 100644
index 0000000000..08e40dfc05
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c
@@ -0,0 +1,97 @@
+/** @file
+ Main file for exit shell level 1 function.
+
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<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
+ 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"
+
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
+ {L"/b", TypeFlag},
+ {NULL, TypeMax}
+ };
+
+/**
+ Function for 'exit' 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
+ShellCommandRunExit (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ LIST_ENTRY *Package;
+ CHAR16 *ProblemParam;
+ SHELL_STATUS ShellStatus;
+ UINT64 RetVal;
+ CONST CHAR16 *Return;
+
+ 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 (ParamList, &Package, &ProblemParam, TRUE);
+ if (EFI_ERROR(Status)) {
+ if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, L"exit", ProblemParam);
+ FreePool(ProblemParam);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ ASSERT(FALSE);
+ }
+ } else {
+
+ //
+ // return the specified error code
+ //
+ 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_PARAM_INV), gShellLevel1HiiHandle, L"exit", 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")), RetVal);
+
+ ShellStatus = SHELL_SUCCESS;
+ }
+ } else {
+ // If we are in a batch file and /b then pass TRUE otherwise false...
+ //
+ ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), 0);
+
+ ShellStatus = SHELL_SUCCESS;
+ }
+
+ ShellCommandLineFreeVarList (Package);
+ }
+ return (ShellStatus);
+}
+
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
new file mode 100644
index 0000000000..6cfe8a78fe
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
@@ -0,0 +1,754 @@
+/** @file
+ Main file for endfor and for shell level 1 functions.
+
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
+ Copyright (c) 2009 - 2016, 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
+ 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"
+#include <Library/PrintLib.h>
+
+/**
+ 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 (
+ IN CONST CHAR16 *Number
+ )
+{
+ if (Number == NULL || *Number == CHAR_NULL) {
+ return (FALSE);
+ }
+
+ if (*Number == L'-') {
+ Number++;
+ }
+
+ if (StrLen(Number) == 0) {
+ return (FALSE);
+ }
+
+ if (StrLen(Number) >= 7) {
+ if ((StrStr(Number, L" ") == NULL) || (((StrStr(Number, L" ") != NULL) && (StrStr(Number, L" ") - Number) >= 7))) {
+ return (FALSE);
+ }
+ }
+
+ if (!ShellIsDecimalDigitCharacter(*Number)) {
+ return (FALSE);
+ }
+
+ return (TRUE);
+}
+
+/**
+ Function for 'endfor' 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
+ShellCommandRunEndFor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ BOOLEAN Found;
+ SCRIPT_FILE *CurrentScriptFile;
+
+ Status = CommandInit();
+ ASSERT_EFI_ERROR(Status);
+
+ if (!gEfiShellProtocol->BatchIsActive()) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"endfor");
+ return (SHELL_UNSUPPORTED);
+ }
+
+ if (gEfiShellParametersProtocol->Argc > 1) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"endfor");
+ return (SHELL_INVALID_PARAMETER);
+ }
+
+ Found = MoveToTag(GetPreviousNode, L"for", L"endfor", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE);
+
+ if (!Found) {
+ CurrentScriptFile = ShellCommandGetCurrentScriptFile();
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
+ gShellLevel1HiiHandle,
+ L"For",
+ L"EndFor",
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ return (SHELL_NOT_FOUND);
+ }
+ return (SHELL_SUCCESS);
+}
+
+typedef struct {
+ UINT32 Signature;
+ INTN Current;
+ INTN End;
+ INTN Step;
+ CHAR16 *ReplacementName;
+ CHAR16 *CurrentValue;
+ BOOLEAN RemoveSubstAlias;
+ CHAR16 Set[1];
+ } SHELL_FOR_INFO;
+#define SIZE_OF_SHELL_FOR_INFO OFFSET_OF (SHELL_FOR_INFO, Set)
+#define SHELL_FOR_INFO_SIGNATURE SIGNATURE_32 ('S', 'F', 'I', 's')
+
+/**
+ Update the value of a given alias on the list. If the alias is not there then add it.
+
+ @param[in] Alias The alias to test for.
+ @param[in] CommandString The updated command string.
+ @param[in, out] List The list to search.
+
+ @retval EFI_SUCCESS The operation was completed successfully.
+ @retval EFI_OUT_OF_RESOURCES There was not enough free memory.
+**/
+EFI_STATUS
+EFIAPI
+InternalUpdateAliasOnList(
+ IN CONST CHAR16 *Alias,
+ IN CONST CHAR16 *CommandString,
+ IN OUT LIST_ENTRY *List
+ )
+{
+ ALIAS_LIST *Node;
+ BOOLEAN Found;
+
+ //
+ // assert for NULL parameter
+ //
+ ASSERT(Alias != NULL);
+
+ //
+ // check for the Alias
+ //
+ for ( Node = (ALIAS_LIST *)GetFirstNode(List), Found = FALSE
+ ; !IsNull(List, &Node->Link)
+ ; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)
+ ){
+ ASSERT(Node->CommandString != NULL);
+ ASSERT(Node->Alias != NULL);
+ if (StrCmp(Node->Alias, Alias)==0) {
+ FreePool(Node->CommandString);
+ Node->CommandString = NULL;
+ Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);
+ Found = TRUE;
+ break;
+ }
+ }
+ if (!Found) {
+ Node = AllocateZeroPool(sizeof(ALIAS_LIST));
+ if (Node == NULL) {
+ return (EFI_OUT_OF_RESOURCES);
+ }
+ ASSERT(Node->Alias == NULL);
+ Node->Alias = StrnCatGrow(&Node->Alias, NULL, Alias, 0);
+ ASSERT(Node->CommandString == NULL);
+ Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);
+ InsertTailList(List, &Node->Link);
+ }
+ return (EFI_SUCCESS);
+}
+
+/**
+ Find out if an alias is on the given list.
+
+ @param[in] Alias The alias to test for.
+ @param[in] List The list to search.
+
+ @retval TRUE The alias is on the list.
+ @retval FALSE The alias is not on the list.
+**/
+BOOLEAN
+EFIAPI
+InternalIsAliasOnList(
+ IN CONST CHAR16 *Alias,
+ IN CONST LIST_ENTRY *List
+ )
+{
+ ALIAS_LIST *Node;
+
+ //
+ // assert for NULL parameter
+ //
+ ASSERT(Alias != NULL);
+
+ //
+ // check for the Alias
+ //
+ for ( Node = (ALIAS_LIST *)GetFirstNode(List)
+ ; !IsNull(List, &Node->Link)
+ ; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)
+ ){
+ ASSERT(Node->CommandString != NULL);
+ ASSERT(Node->Alias != NULL);
+ if (StrCmp(Node->Alias, Alias)==0) {
+ return (TRUE);
+ }
+ }
+ return (FALSE);
+}
+
+/**
+ Remove an alias from the given list.
+
+ @param[in] Alias The alias to remove.
+ @param[in, out] List The list to search.
+**/
+BOOLEAN
+EFIAPI
+InternalRemoveAliasFromList(
+ IN CONST CHAR16 *Alias,
+ IN OUT LIST_ENTRY *List
+ )
+{
+ ALIAS_LIST *Node;
+
+ //
+ // assert for NULL parameter
+ //
+ ASSERT(Alias != NULL);
+
+ //
+ // check for the Alias
+ //
+ for ( Node = (ALIAS_LIST *)GetFirstNode(List)
+ ; !IsNull(List, &Node->Link)
+ ; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)
+ ){
+ ASSERT(Node->CommandString != NULL);
+ ASSERT(Node->Alias != NULL);
+ if (StrCmp(Node->Alias, Alias)==0) {
+ RemoveEntryList(&Node->Link);
+ FreePool(Node->Alias);
+ FreePool(Node->CommandString);
+ FreePool(Node);
+ return (TRUE);
+ }
+ }
+ return (FALSE);
+}
+
+/**
+ Function to determine whether a string is decimal or hex representation of a number
+ and return the number converted from the string.
+
+ @param[in] String String representation of a number
+
+ @return the number
+ @retval (UINTN)(-1) An error ocurred.
+**/
+UINTN
+EFIAPI
+ReturnUintn(
+ IN CONST CHAR16 *String
+ )
+{
+ UINT64 RetVal;
+
+ if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, FALSE, TRUE))) {
+ return ((UINTN)RetVal);
+ }
+ return ((UINTN)(-1));
+}
+
+/**
+ Function for 'for' 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
+ShellCommandRunFor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ SHELL_STATUS ShellStatus;
+ SCRIPT_FILE *CurrentScriptFile;
+ CHAR16 *ArgSet;
+ CHAR16 *ArgSetWalker;
+ CHAR16 *Parameter;
+ UINTN ArgSize;
+ UINTN LoopVar;
+ SHELL_FOR_INFO *Info;
+ CHAR16 *TempString;
+ CHAR16 *TempSpot;
+ BOOLEAN FirstPass;
+ EFI_SHELL_FILE_INFO *Node;
+ EFI_SHELL_FILE_INFO *FileList;
+ UINTN NewSize;
+
+ ArgSet = NULL;
+ ArgSize = 0;
+ ShellStatus = SHELL_SUCCESS;
+ ArgSetWalker = NULL;
+ TempString = NULL;
+ Parameter = NULL;
+ FirstPass = FALSE;
+
+ //
+ // initialize the shell lib (we must be in non-auto-init...)
+ //
+ Status = ShellInitialize();
+ ASSERT_EFI_ERROR(Status);
+
+ Status = CommandInit();
+ ASSERT_EFI_ERROR(Status);
+
+ if (!gEfiShellProtocol->BatchIsActive()) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"for");
+ return (SHELL_UNSUPPORTED);
+ }
+
+ if (gEfiShellParametersProtocol->Argc < 4) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"for");
+ return (SHELL_INVALID_PARAMETER);
+ }
+
+ CurrentScriptFile = ShellCommandGetCurrentScriptFile();
+ ASSERT(CurrentScriptFile != NULL);
+
+ if ((CurrentScriptFile->CurrentCommand != NULL) && (CurrentScriptFile->CurrentCommand->Data == NULL)) {
+ FirstPass = TRUE;
+
+ //
+ // Make sure that an End exists.
+ //
+ if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
+ gShellLevel1HiiHandle,
+ L"EndFor",
+ L"For",
+ CurrentScriptFile->CurrentCommand->Line);
+ return (SHELL_DEVICE_ERROR);
+ }
+
+ //
+ // Process the line.
+ //
+ if (gEfiShellParametersProtocol->Argv[1][0] != L'%' || gEfiShellParametersProtocol->Argv[1][2] != CHAR_NULL
+ ||!((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[1]);
+ return (SHELL_INVALID_PARAMETER);
+ }
+
+ if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ L"in",
+ gEfiShellParametersProtocol->Argv[2]) == 0) {
+ for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
+ ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
+ if (StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"*") != NULL
+ ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"?") != NULL
+ ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"[") != NULL
+ ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"]") != NULL) {
+ FileList = NULL;
+ Status = ShellOpenFileMetaArg ((CHAR16*)gEfiShellParametersProtocol->Argv[LoopVar], EFI_FILE_MODE_READ, &FileList);
+ if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
+ } else {
+ for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
+ ; !IsNull(&FileList->Link, &Node->Link)
+ ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
+ ){
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Node->FullName, 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
+ }
+ ShellCloseFileMetaArg(&FileList);
+ }
+ } else {
+ Parameter = gEfiShellParametersProtocol->Argv[LoopVar];
+ if (Parameter[0] == L'\"' && Parameter[StrLen(Parameter)-1] == L'\"') {
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Parameter, 0);
+ } else {
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Parameter, 0);
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
+ }
+ }
+ }
+ if (ArgSet == NULL) {
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ } else {
+ //
+ // set up for an 'in' for loop
+ //
+ NewSize = StrSize(ArgSet);
+ NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);
+ Info = AllocateZeroPool(NewSize);
+ if (Info == NULL) {
+ FreePool (ArgSet);
+ return SHELL_OUT_OF_RESOURCES;
+ }
+ Info->Signature = SHELL_FOR_INFO_SIGNATURE;
+ CopyMem(Info->Set, ArgSet, StrSize(ArgSet));
+ NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);
+ CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);
+ Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);
+ Info->CurrentValue = (CHAR16*)Info->Set;
+ Info->Step = 0;
+ Info->Current = 0;
+ Info->End = 0;
+
+ if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
+ Info->RemoveSubstAlias = FALSE;
+ } else {
+ Info->RemoveSubstAlias = TRUE;
+ }
+ CurrentScriptFile->CurrentCommand->Data = Info;
+ }
+ } else if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ L"run",
+ gEfiShellParametersProtocol->Argv[2]) == 0) {
+ for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
+ ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
+ if (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L")") != NULL &&
+ (LoopVar + 1) < gEfiShellParametersProtocol->Argc
+ ) {
+ return (SHELL_INVALID_PARAMETER);
+ }
+ if (ArgSet == NULL) {
+// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
+ } else {
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
+ }
+ ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
+// ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
+ }
+ if (ArgSet == NULL) {
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ } else {
+ //
+ // set up for a 'run' for loop
+ //
+ Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));
+ if (Info == NULL) {
+ FreePool (ArgSet);
+ return SHELL_OUT_OF_RESOURCES;
+ }
+ Info->Signature = SHELL_FOR_INFO_SIGNATURE;
+ CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));
+ Info->ReplacementName = Info->Set;
+ Info->CurrentValue = NULL;
+ ArgSetWalker = ArgSet;
+ if (ArgSetWalker[0] != L'(') {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
+ gShellLevel1HiiHandle,
+ ArgSet,
+ CurrentScriptFile->CurrentCommand->Line);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ 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 (TempSpot == NULL) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
+ gShellLevel1HiiHandle,
+ CurrentScriptFile->CurrentCommand->Line);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ *TempSpot = CHAR_NULL;
+ ArgSetWalker++;
+ while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
+ ArgSetWalker++;
+ }
+ if (!ShellIsValidForNumber(ArgSetWalker)) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
+ gShellLevel1HiiHandle,
+ ArgSet,
+ CurrentScriptFile->CurrentCommand->Line);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ if (ArgSetWalker[0] == L'-') {
+ Info->Current = 0 - (INTN)ReturnUintn(ArgSetWalker+1);
+ } else {
+ Info->Current = (INTN)ReturnUintn(ArgSetWalker);
+ }
+ ArgSetWalker = StrStr(ArgSetWalker, L" ");
+ while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
+ ArgSetWalker++;
+ }
+ if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
+ gShellLevel1HiiHandle,
+ ArgSet,
+ CurrentScriptFile->CurrentCommand->Line);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ if (ArgSetWalker[0] == L'-') {
+ Info->End = 0 - (INTN)ReturnUintn(ArgSetWalker+1);
+ } else {
+ Info->End = (INTN)ReturnUintn(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,
+ CurrentScriptFile->CurrentCommand->Line);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ if (*ArgSetWalker == L')') {
+ ASSERT(Info->Step == 1 || Info->Step == -1);
+ } else {
+ if (ArgSetWalker[0] == L'-') {
+ Info->Step = 0 - (INTN)ReturnUintn(ArgSetWalker+1);
+ } else {
+ Info->Step = (INTN)ReturnUintn(ArgSetWalker);
+ }
+
+ if (StrStr(ArgSetWalker, L" ") != NULL) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
+ gShellLevel1HiiHandle,
+ ArgSet,
+ CurrentScriptFile->CurrentCommand->Line);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ }
+ }
+
+ }
+ }
+ }
+ }
+ }
+ if (ShellStatus == SHELL_SUCCESS) {
+ if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
+ Info->RemoveSubstAlias = FALSE;
+ } else {
+ Info->RemoveSubstAlias = TRUE;
+ }
+ }
+ if (CurrentScriptFile->CurrentCommand != NULL) {
+ CurrentScriptFile->CurrentCommand->Data = Info;
+ }
+ }
+ } else {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
+ gShellLevel1HiiHandle,
+ ArgSet,
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ } else {
+ //
+ // These need to be NULL since they are used to determine if this is the first pass later on...
+ //
+ ASSERT(ArgSetWalker == NULL);
+ ASSERT(ArgSet == NULL);
+ }
+
+ if (CurrentScriptFile != NULL && CurrentScriptFile->CurrentCommand != NULL) {
+ Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data;
+ if (CurrentScriptFile->CurrentCommand->Reset) {
+ Info->CurrentValue = (CHAR16*)Info->Set;
+ FirstPass = TRUE;
+ CurrentScriptFile->CurrentCommand->Reset = FALSE;
+ }
+ } else {
+ ShellStatus = SHELL_UNSUPPORTED;
+ Info = NULL;
+ }
+ if (ShellStatus == SHELL_SUCCESS) {
+ ASSERT(Info != NULL);
+ if (Info->Step != 0) {
+ //
+ // only advance if not the first pass
+ //
+ if (!FirstPass) {
+ //
+ // sequence version of for loop...
+ //
+ Info->Current += Info->Step;
+ }
+
+ TempString = AllocateZeroPool(50*sizeof(CHAR16));
+ UnicodeSPrint(TempString, 50*sizeof(CHAR16), L"%d", Info->Current);
+ InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
+ FreePool(TempString);
+
+ if ((Info->Step > 0 && Info->Current > Info->End) || (Info->Step < 0 && Info->Current < Info->End)) {
+ CurrentScriptFile->CurrentCommand->Data = NULL;
+ //
+ // find the matching endfor (we're done with the loop)
+ //
+ if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
+ gShellLevel1HiiHandle,
+ L"EndFor",
+ L"For",
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ ShellStatus = SHELL_DEVICE_ERROR;
+ }
+ if (Info->RemoveSubstAlias) {
+ //
+ // remove item from list
+ //
+ InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);
+ }
+ FreePool(Info);
+ }
+ } else {
+ //
+ // Must be in 'in' version of for loop...
+ //
+ ASSERT(Info->Set != NULL);
+ if (Info->CurrentValue != NULL && *Info->CurrentValue != CHAR_NULL) {
+ if (Info->CurrentValue[0] == L' ') {
+ Info->CurrentValue++;
+ }
+ if (Info->CurrentValue[0] == L'\"') {
+ Info->CurrentValue++;
+ }
+ //
+ // do the next one of the set
+ //
+ ASSERT(TempString == NULL);
+ TempString = StrnCatGrow(&TempString, NULL, Info->CurrentValue, 0);
+ if (TempString == NULL) {
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ } else {
+ TempSpot = StrStr(TempString, L"\" \"");
+ if (TempSpot != NULL) {
+ *TempSpot = CHAR_NULL;
+ }
+ while (TempString[StrLen(TempString)-1] == L'\"') {
+ TempString[StrLen(TempString)-1] = CHAR_NULL;
+ }
+ InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
+ Info->CurrentValue += StrLen(TempString);
+
+ if (Info->CurrentValue[0] == L'\"') {
+ Info->CurrentValue++;
+ }
+ FreePool(TempString);
+ }
+ } else {
+ CurrentScriptFile->CurrentCommand->Data = NULL;
+ //
+ // find the matching endfor (we're done with the loop)
+ //
+ if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
+ gShellLevel1HiiHandle,
+ L"EndFor",
+ L"For",
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ ShellStatus = SHELL_DEVICE_ERROR;
+ }
+ if (Info->RemoveSubstAlias) {
+ //
+ // remove item from list
+ //
+ InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);
+ }
+ FreePool(Info);
+ }
+ }
+ }
+ if (ArgSet != NULL) {
+ FreePool(ArgSet);
+ }
+ return (ShellStatus);
+}
+
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c
new file mode 100644
index 0000000000..88e290daa7
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c
@@ -0,0 +1,105 @@
+/** @file
+ Main file for goto shell level 1 function.
+
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
+ Copyright (c) 2009 - 2010, 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
+ 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 'goto' 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
+ShellCommandRunGoto (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ LIST_ENTRY *Package;
+ CHAR16 *ProblemParam;
+ SHELL_STATUS ShellStatus;
+ CHAR16 *CompareString;
+ UINTN Size;
+ SCRIPT_FILE *CurrentScriptFile;
+
+ ShellStatus = SHELL_SUCCESS;
+ CompareString = NULL;
+
+ //
+ // initialize the shell lib (we must be in non-auto-init...)
+ //
+ Status = ShellInitialize();
+ ASSERT_EFI_ERROR(Status);
+
+ Status = CommandInit();
+ ASSERT_EFI_ERROR(Status);
+
+ if (!gEfiShellProtocol->BatchIsActive()) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto");
+ return (SHELL_UNSUPPORTED);
+ }
+
+ //
+ // 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, L"goto", 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, L"goto");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"goto");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ Size = 0;
+ ASSERT((CompareString == NULL && Size == 0) || (CompareString != NULL));
+ CompareString = StrnCatGrow(&CompareString, &Size, L":", 0);
+ CompareString = StrnCatGrow(&CompareString, &Size, ShellCommandLineGetRawValue(Package, 1), 0);
+ //
+ // Check forwards and then backwards for a label...
+ //
+ if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) {
+ CurrentScriptFile = ShellCommandGetCurrentScriptFile();
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
+ gShellLevel1HiiHandle,
+ CompareString,
+ L"Goto",
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ ShellStatus = SHELL_NOT_FOUND;
+ }
+ FreePool(CompareString);
+ }
+ ShellCommandLineFreeVarList (Package);
+ }
+
+ return (ShellStatus);
+}
+
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
new file mode 100644
index 0000000000..37e196c2c1
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c
@@ -0,0 +1,1117 @@
+/** @file
+ Main file for If and else shell level 1 function.
+
+ (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
+ Copyright (c) 2009 - 2016, 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
+ 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"
+#include <Library/PrintLib.h>
+
+typedef enum {
+ EndTagOr,
+ EndTagAnd,
+ EndTagThen,
+ EndTagMax
+} END_TAG_TYPE;
+
+typedef enum {
+ 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.
+ @param[out] Match TRUE when there is another Fragment in Statement,
+ FALSE otherwise.
+
+ @retval EFI_SUCCESS The match operation is performed successfully.
+ @retval EFI_OUT_OF_RESOURCES Out of resources.
+**/
+EFI_STATUS
+IsNextFragment (
+ IN OUT CONST CHAR16 **Statement,
+ IN CONST CHAR16 *Fragment,
+ OUT BOOLEAN *Match
+ )
+{
+ CHAR16 *Tester;
+
+ Tester = NULL;
+
+ Tester = StrnCatGrow(&Tester, NULL, *Statement, StrLen(Fragment));
+ if (Tester == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ Tester[StrLen(Fragment)] = CHAR_NULL;
+ if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ (CHAR16*)Fragment,
+ Tester) == 0) {
+ //
+ // increment the string pointer to the end of what we found and then chop off spaces...
+ //
+ *Statement+=StrLen(Fragment);
+ while (*Statement[0] == L' ') {
+ (*Statement)++;
+ }
+ *Match = TRUE;
+ } else {
+ *Match = FALSE;
+ }
+ FreePool(Tester);
+ return EFI_SUCCESS;
+}
+
+/**
+ 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 (
+ IN CONST CHAR16 *String
+ )
+{
+ CONST CHAR16 *ProfilesString;
+ 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);
+ }
+ 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 (
+ IN CONST CHAR16 *Compare1,
+ IN CONST CHAR16 *Compare2,
+ IN CONST BIN_OPERATOR_TYPE BinOp,
+ IN CONST BOOLEAN CaseInsensitive,
+ IN CONST BOOLEAN ForceStringCompare
+ )
+{
+ INTN Cmp1;
+ INTN Cmp2;
+
+ //
+ // "Compare1 BinOp Compare2"
+ //
+ switch (BinOp) {
+ case OperatorUnisgnedGreaterThan:
+ case OperatorGreaterThan:
+ if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
+ //
+ // string compare
+ //
+ if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) > 0) || (StringCompare(&Compare1, &Compare2) > 0)) {
+ return (TRUE);
+ }
+ } else {
+ //
+ // numeric compare
+ //
+ if (Compare1[0] == L'-') {
+ Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1);
+ } else {
+ Cmp1 = (INTN)ShellStrToUintn(Compare1);
+ }
+ if (Compare2[0] == L'-') {
+ Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1);
+ } else {
+ Cmp2 = (INTN)ShellStrToUintn(Compare2);
+ }
+ if (BinOp == OperatorGreaterThan) {
+ if (Cmp1 > Cmp2) {
+ return (TRUE);
+ }
+ } else {
+ if ((UINTN)Cmp1 > (UINTN)Cmp2) {
+ return (TRUE);
+ }
+ }
+ }
+ return (FALSE);
+ case OperatorUnsignedLessThan:
+ case OperatorLessThan:
+ if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
+ //
+ // string compare
+ //
+ if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) < 0) || (StringCompare(&Compare1, &Compare2) < 0)) {
+ return (TRUE);
+ }
+ } else {
+ //
+ // numeric compare
+ //
+ if (Compare1[0] == L'-') {
+ Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1);
+ } else {
+ Cmp1 = (INTN)ShellStrToUintn(Compare1);
+ }
+ if (Compare2[0] == L'-') {
+ Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1);
+ } else {
+ Cmp2 = (INTN)ShellStrToUintn(Compare2);
+ }
+ if (BinOp == OperatorLessThan) {
+ if (Cmp1 < Cmp2) {
+ return (TRUE);
+ }
+ } else {
+ if ((UINTN)Cmp1 < (UINTN)Cmp2) {
+ return (TRUE);
+ }
+ }
+
+ }
+ return (FALSE);
+ case OperatorEqual:
+ if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
+ //
+ // string compare
+ //
+ if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) == 0) || (StringCompare(&Compare1, &Compare2) == 0)) {
+ return (TRUE);
+ }
+ } else {
+ //
+ // numeric compare
+ //
+ if (Compare1[0] == L'-') {
+ Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1);
+ } else {
+ Cmp1 = (INTN)ShellStrToUintn(Compare1);
+ }
+ if (Compare2[0] == L'-') {
+ Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1);
+ } else {
+ Cmp2 = (INTN)ShellStrToUintn(Compare2);
+ }
+ if (Cmp1 == Cmp2) {
+ return (TRUE);
+ }
+ }
+ return (FALSE);
+ case OperatorNotEqual:
+ if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
+ //
+ // string compare
+ //
+ if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) != 0) || (StringCompare(&Compare1, &Compare2) != 0)) {
+ return (TRUE);
+ }
+ } else {
+ //
+ // numeric compare
+ //
+ if (Compare1[0] == L'-') {
+ Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1);
+ } else {
+ Cmp1 = (INTN)ShellStrToUintn(Compare1);
+ }
+ if (Compare2[0] == L'-') {
+ Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1);
+ } else {
+ Cmp2 = (INTN)ShellStrToUintn(Compare2);
+ }
+ if (Cmp1 != Cmp2) {
+ return (TRUE);
+ }
+ }
+ return (FALSE);
+ case OperatorUnsignedGreaterOrEqual:
+ case OperatorGreatorOrEqual:
+ if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
+ //
+ // string compare
+ //
+ if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) >= 0) || (StringCompare(&Compare1, &Compare2) >= 0)) {
+ return (TRUE);
+ }
+ } else {
+ //
+ // numeric compare
+ //
+ if (Compare1[0] == L'-') {
+ Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1);
+ } else {
+ Cmp1 = (INTN)ShellStrToUintn(Compare1);
+ }
+ if (Compare2[0] == L'-') {
+ Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1);
+ } else {
+ Cmp2 = (INTN)ShellStrToUintn(Compare2);
+ }
+ if (BinOp == OperatorGreatorOrEqual) {
+ if (Cmp1 >= Cmp2) {
+ return (TRUE);
+ }
+ } else {
+ if ((UINTN)Cmp1 >= (UINTN)Cmp2) {
+ return (TRUE);
+ }
+ }
+ }
+ return (FALSE);
+ case OperatorLessOrEqual:
+ case OperatorUnsignedLessOrEqual:
+ if (ForceStringCompare || !ShellIsHexOrDecimalNumber(Compare1, FALSE, FALSE) || !ShellIsHexOrDecimalNumber(Compare2, FALSE, FALSE)) {
+ //
+ // string compare
+ //
+ if ((CaseInsensitive && StringNoCaseCompare(&Compare1, &Compare2) <= 0) || (StringCompare(&Compare1, &Compare2) <= 0)) {
+ return (TRUE);
+ }
+ } else {
+ //
+ // numeric compare
+ //
+ if (Compare1[0] == L'-') {
+ Cmp1 = 0 - (INTN)ShellStrToUintn(Compare1+1);
+ } else {
+ Cmp1 = (INTN)ShellStrToUintn(Compare1);
+ }
+ if (Compare2[0] == L'-') {
+ Cmp2 = 0 - (INTN)ShellStrToUintn(Compare2+1);
+ } else {
+ Cmp2 = (INTN)ShellStrToUintn(Compare2);
+ }
+ if (BinOp == OperatorLessOrEqual) {
+ if (Cmp1 <= Cmp2) {
+ return (TRUE);
+ }
+ } else {
+ if ((UINTN)Cmp1 <= (UINTN)Cmp2) {
+ return (TRUE);
+ }
+ }
+ }
+ return (FALSE);
+ default:
+ ASSERT(FALSE);
+ return (FALSE);
+ }
+}
+
+/**
+ 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 (
+ IN OUT BOOLEAN *PassingState,
+ IN UINTN StartParameterNumber,
+ IN UINTN EndParameterNumber,
+ IN CONST END_TAG_TYPE OperatorToUse,
+ IN CONST BOOLEAN CaseInsensitive,
+ IN CONST BOOLEAN ForceStringCompare
+ )
+{
+ EFI_STATUS Status;
+ BOOLEAN OperationResult;
+ BOOLEAN NotPresent;
+ CHAR16 *StatementWalker;
+ BIN_OPERATOR_TYPE BinOp;
+ CHAR16 *Compare1;
+ 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 (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"not", &Match)) && Match) {
+ NotPresent = TRUE;
+ StatementWalker = gEfiShellParametersProtocol->Argv[++StartParameterNumber];
+ } else {
+ NotPresent = FALSE;
+ }
+
+ //
+ // now check for 'boolfunc' operators
+ //
+ 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 ((!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???
+ //
+ OperationResult = (BOOLEAN)(ShellFileExists(StatementWalker)==EFI_SUCCESS);
+ } else if (StatementWalker[0] == CHAR_NULL && StartParameterNumber+1 == EndParameterNumber) {
+ OperationResult = (BOOLEAN)(ShellFileExists(gEfiShellParametersProtocol->Argv[++StartParameterNumber])==EFI_SUCCESS);
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"exist(s)");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } 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???
+ //
+ OperationResult = (BOOLEAN)(ShellIsFileInPath(StatementWalker)==EFI_SUCCESS);
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"available");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } 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 ')'
+ //
+ StatementWalker[StrLen(StatementWalker)-1] = CHAR_NULL;
+ OperationResult = IsValidProfile(StatementWalker);
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"profile");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else if (StartParameterNumber+1 >= EndParameterNumber) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[StartParameterNumber]);
+ Status = EFI_INVALID_PARAMETER;
+ } else {
+ //
+ // must be 'item binop item' style
+ //
+ Compare1 = NULL;
+ Compare2 = NULL;
+ BinOp = OperatorMax;
+
+ //
+ // get the first item
+ //
+ StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber];
+ if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror", &Match)) && Match) {
+ TempSpot = StrStr(StatementWalker, L")");
+ 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);
+ ASSERT(Compare1 == NULL);
+ Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0);
+ StatementWalker += StrLen(StatementWalker) + 1;
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror", &Match)) && Match) {
+ TempSpot = StrStr(StatementWalker, L")");
+ 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));
+ ASSERT(Compare1 == NULL);
+ Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0);
+ StatementWalker += StrLen(StatementWalker) + 1;
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else if (!EFI_ERROR (IsNextFragment ((CONST CHAR16**)(&StatementWalker), L"oemerror", &Match)) && Match) {
+ TempSpot = StrStr(StatementWalker, L")");
+ 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));
+ ASSERT(Compare1 == NULL);
+ Compare1 = StrnCatGrow(&Compare1, NULL, HexString, 0);
+ StatementWalker += StrLen(StatementWalker) + 1;
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else {
+ ASSERT(Compare1 == NULL);
+ if (EndParameterNumber - StartParameterNumber > 2) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_STARTING), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[StartParameterNumber+2]);
+ Status = EFI_INVALID_PARAMETER;
+ } else {
+ //
+ // must be a raw string
+ //
+ Compare1 = StrnCatGrow(&Compare1, NULL, StatementWalker, 0);
+ }
+ }
+
+ //
+ // get the operator
+ //
+ ASSERT(StartParameterNumber+1<EndParameterNumber);
+ StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber+1];
+ if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"gt", &Match)) && Match) {
+ BinOp = OperatorGreaterThan;
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"lt", &Match)) && Match) {
+ BinOp = OperatorLessThan;
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"eq", &Match)) && Match) {
+ BinOp = OperatorEqual;
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ne", &Match)) && Match) {
+ BinOp = OperatorNotEqual;
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ge", &Match)) && Match) {
+ BinOp = OperatorGreatorOrEqual;
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"le", &Match)) && Match) {
+ BinOp = OperatorLessOrEqual;
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"==", &Match)) && Match) {
+ BinOp = OperatorEqual;
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ugt", &Match)) && Match) {
+ BinOp = OperatorUnisgnedGreaterThan;
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"ult", &Match)) && Match) {
+ BinOp = OperatorUnsignedLessThan;
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"uge", &Match)) && Match) {
+ BinOp = OperatorUnsignedGreaterOrEqual;
+ } 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);
+ Status = EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // get the second item
+ //
+ ASSERT(StartParameterNumber+2<=EndParameterNumber);
+ StatementWalker = gEfiShellParametersProtocol->Argv[StartParameterNumber+2];
+ if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"efierror", &Match)) && Match) {
+ TempSpot = StrStr(StatementWalker, L")");
+ 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);
+ ASSERT(Compare2 == NULL);
+ Compare2 = StrnCatGrow(&Compare2, NULL, HexString, 0);
+ StatementWalker += StrLen(StatementWalker) + 1;
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"efierror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ //
+ // can this be collapsed into the above?
+ //
+ } else if (!EFI_ERROR (IsNextFragment((CONST CHAR16**)(&StatementWalker), L"pierror", &Match)) && Match) {
+ TempSpot = StrStr(StatementWalker, L")");
+ 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));
+ ASSERT(Compare2 == NULL);
+ Compare2 = StrnCatGrow(&Compare2, NULL, HexString, 0);
+ StatementWalker += StrLen(StatementWalker) + 1;
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"pierror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else if (!EFI_ERROR (IsNextFragment ((CONST CHAR16**)(&StatementWalker), L"oemerror", &Match)) && Match) {
+ TempSpot = StrStr(StatementWalker, L")");
+ 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));
+ ASSERT(Compare2 == NULL);
+ Compare2 = StrnCatGrow(&Compare2, NULL, HexString, 0);
+ StatementWalker += StrLen(StatementWalker) + 1;
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_IN), gShellLevel1HiiHandle, L"oemerror");
+ Status = EFI_INVALID_PARAMETER;
+ }
+ } else {
+ //
+ // must be a raw string
+ //
+ ASSERT(Compare2 == NULL);
+ Compare2 = StrnCatGrow(&Compare2, NULL, StatementWalker, 0);
+ }
+
+ if (Compare1 != NULL && Compare2 != NULL && BinOp != OperatorMax) {
+ OperationResult = TestOperation(Compare1, Compare2, BinOp, CaseInsensitive, ForceStringCompare);
+ }
+
+ SHELL_FREE_NON_NULL(Compare1);
+ SHELL_FREE_NON_NULL(Compare2);
+ }
+
+ //
+ // done processing do result...
+ //
+
+ if (!EFI_ERROR(Status)) {
+ if (NotPresent) {
+ OperationResult = (BOOLEAN)(!OperationResult);
+ }
+ switch(OperatorToUse) {
+ case EndTagOr:
+ *PassingState = (BOOLEAN)(*PassingState || OperationResult);
+ break;
+ case EndTagAnd:
+ *PassingState = (BOOLEAN)(*PassingState && OperationResult);
+ break;
+ case EndTagMax:
+ *PassingState = (BOOLEAN)(OperationResult);
+ break;
+ default:
+ ASSERT(FALSE);
+ }
+ }
+ 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 (
+ IN UINTN ParameterNumber,
+ OUT UINTN *EndParameter,
+ OUT END_TAG_TYPE *EndTag
+ )
+{
+ *EndTag = EndTagMax;
+
+ for(
+ ; ParameterNumber < gEfiShellParametersProtocol->Argc
+ ; ParameterNumber++
+ ) {
+ if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[ParameterNumber],
+ L"or") == 0) {
+ *EndParameter = ParameterNumber - 1;
+ *EndTag = EndTagOr;
+ break;
+ } else if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[ParameterNumber],
+ L"and") == 0) {
+ *EndParameter = ParameterNumber - 1;
+ *EndTag = EndTagAnd;
+ break;
+ } else if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[ParameterNumber],
+ L"then") == 0) {
+ *EndParameter = ParameterNumber - 1;
+ *EndTag = EndTagThen;
+ break;
+ }
+ }
+ 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 (
+ IN SCRIPT_FILE *ScriptFile
+ )
+{
+ SCRIPT_COMMAND_LIST *CommandNode;
+ BOOLEAN Found;
+ UINTN TargetCount;
+ CHAR16 *CommandName;
+ CHAR16 *CommandWalker;
+ CHAR16 *TempLocation;
+
+ TargetCount = 1;
+ Found = FALSE;
+
+ if (ScriptFile == NULL) {
+ return FALSE;
+ }
+
+ for (CommandNode = (SCRIPT_COMMAND_LIST *)GetNextNode(&ScriptFile->CommandList, &ScriptFile->CurrentCommand->Link), Found = FALSE
+ ; !IsNull(&ScriptFile->CommandList, &CommandNode->Link) && !Found
+ ; CommandNode = (SCRIPT_COMMAND_LIST *)GetNextNode(&ScriptFile->CommandList, &CommandNode->Link)
+ ){
+
+ //
+ // get just the first part of the command line...
+ //
+ CommandName = NULL;
+ CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);
+ if (CommandName == NULL) {
+ continue;
+ }
+ CommandWalker = CommandName;
+
+ //
+ // Skip leading spaces and tabs.
+ //
+ while ((CommandWalker[0] == L' ') || (CommandWalker[0] == L'\t')) {
+ CommandWalker++;
+ }
+ TempLocation = StrStr(CommandWalker, L" ");
+
+ if (TempLocation != NULL) {
+ *TempLocation = CHAR_NULL;
+ }
+
+ //
+ // did we find a nested item ?
+ //
+ if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ (CHAR16*)CommandWalker,
+ L"If") == 0) {
+ TargetCount++;
+ } else if (TargetCount == 1 && gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ (CHAR16*)CommandWalker,
+ (CHAR16*)L"else") == 0) {
+ //
+ // else can only decrement the last part... not an nested if
+ // hence the TargetCount compare added
+ //
+ TargetCount--;
+ } else if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ (CHAR16*)CommandWalker,
+ (CHAR16*)L"endif") == 0) {
+ TargetCount--;
+ }
+ if (TargetCount == 0) {
+ ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode(&ScriptFile->CommandList, &CommandNode->Link);
+ Found = TRUE;
+ }
+
+ //
+ // Free the memory for this loop...
+ //
+ SHELL_FREE_NON_NULL(CommandName);
+ }
+ 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 (
+ IN CONST BOOLEAN Result
+ )
+{
+ if (Result || MoveToTagSpecial(ShellCommandGetCurrentScriptFile())) {
+ return (EFI_SUCCESS);
+ }
+ return (EFI_NOT_FOUND);
+}
+
+/**
+ Function for 'if' 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
+ShellCommandRunIf (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ SHELL_STATUS ShellStatus;
+ BOOLEAN CaseInsensitive;
+ BOOLEAN ForceString;
+ UINTN CurrentParameter;
+ UINTN EndParameter;
+ 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");
+ return (SHELL_UNSUPPORTED);
+ }
+
+ if (gEfiShellParametersProtocol->Argc < 3) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"if");
+ return (SHELL_INVALID_PARAMETER);
+ }
+
+ //
+ // Make sure that an End exists.
+ //
+ 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"EndIf",
+ L"If",
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ return (SHELL_DEVICE_ERROR);
+ }
+
+ //
+ // initialize the shell lib (we must be in non-auto-init...)
+ //
+ Status = ShellInitialize();
+ ASSERT_EFI_ERROR(Status);
+
+ CurrentParameter = 1;
+ EndParameter = 0;
+
+ if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[1],
+ L"/i") == 0 ||
+ gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[2],
+ L"/i") == 0 ||
+ (gEfiShellParametersProtocol->Argc > 3 && gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[3],
+ L"/i") == 0)) {
+ CaseInsensitive = TRUE;
+ CurrentParameter++;
+ } else {
+ CaseInsensitive = FALSE;
+ }
+ if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[1],
+ L"/s") == 0 ||
+ gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[2],
+ L"/s") == 0 ||
+ (gEfiShellParametersProtocol->Argc > 3 && gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[3],
+ L"/s") == 0)) {
+ ForceString = TRUE;
+ CurrentParameter++;
+ } else {
+ ForceString = FALSE;
+ }
+
+ for ( ShellStatus = SHELL_SUCCESS, CurrentValue = FALSE, Ending = EndTagMax
+ ; CurrentParameter < gEfiShellParametersProtocol->Argc && ShellStatus == SHELL_SUCCESS
+ ; CurrentParameter++) {
+ if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ gEfiShellParametersProtocol->Argv[CurrentParameter],
+ L"then") == 0) {
+ //
+ // we are at the then
+ //
+ if (CurrentParameter+1 != gEfiShellParametersProtocol->Argc) {
+ 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, L"if", gEfiShellParametersProtocol->Argv[CurrentParameter]);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ }
+ } else {
+ PreviousEnding = Ending;
+ //
+ // build up the next statement for analysis
+ //
+ if (!BuildNextStatement(CurrentParameter, &EndParameter, &Ending)) {
+ 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 {
+ //
+ // Analyze the statement
+ //
+ Status = ProcessStatement(&CurrentValue, CurrentParameter, EndParameter, PreviousEnding, CaseInsensitive, ForceString);
+ if (EFI_ERROR(Status)) {
+// ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SYNTAX_STARTING), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[CurrentParameter]);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else {
+ //
+ // Optomize to get out of the loop early...
+ //
+ 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, L"if", gEfiShellParametersProtocol->Argv[CurrentParameter]);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ }
+ break;
+ }
+ }
+ }
+ if (ShellStatus == SHELL_SUCCESS){
+ CurrentParameter = EndParameter;
+ //
+ // Skip over the or or and parameter.
+ //
+ if (Ending == EndTagOr || Ending == EndTagAnd) {
+ CurrentParameter++;
+ }
+ }
+ }
+ }
+ return (ShellStatus);
+}
+
+/**
+ Function for 'else' 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
+ShellCommandRunElse (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ 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, L"if");
+ return (SHELL_INVALID_PARAMETER);
+ }
+
+ if (!gEfiShellProtocol->BatchIsActive()) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Else");
+ return (SHELL_UNSUPPORTED);
+ }
+
+ CurrentScriptFile = ShellCommandGetCurrentScriptFile();
+
+ if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, CurrentScriptFile, FALSE, TRUE, FALSE)) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
+ gShellLevel1HiiHandle,
+ L"If",
+ L"Else",
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ return (SHELL_DEVICE_ERROR);
+ }
+ if (!MoveToTag(GetPreviousNode, L"if", L"else", NULL, CurrentScriptFile, FALSE, TRUE, FALSE)) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
+ gShellLevel1HiiHandle,
+ L"If",
+ L"Else",
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ return (SHELL_DEVICE_ERROR);
+ }
+
+ if (!MoveToTag(GetNextNode, L"endif", L"if", NULL, CurrentScriptFile, FALSE, FALSE, FALSE)) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
+ gShellLevel1HiiHandle,
+ L"EndIf",
+ "Else",
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ return (SHELL_DEVICE_ERROR);
+ }
+
+ return (SHELL_SUCCESS);
+}
+
+/**
+ Function for 'endif' 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
+ShellCommandRunEndIf (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ 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, L"if");
+ return (SHELL_INVALID_PARAMETER);
+ }
+
+ if (!gEfiShellProtocol->BatchIsActive()) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Endif");
+ return (SHELL_UNSUPPORTED);
+ }
+
+ CurrentScriptFile = ShellCommandGetCurrentScriptFile();
+ if (!MoveToTag(GetPreviousNode, L"if", L"endif", NULL, CurrentScriptFile, FALSE, TRUE, FALSE)) {
+ ShellPrintHiiEx(
+ -1,
+ -1,
+ NULL,
+ STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
+ gShellLevel1HiiHandle,
+ L"If",
+ L"EndIf",
+ CurrentScriptFile!=NULL
+ && CurrentScriptFile->CurrentCommand!=NULL
+ ? CurrentScriptFile->CurrentCommand->Line:0);
+ return (SHELL_DEVICE_ERROR);
+ }
+
+ return (SHELL_SUCCESS);
+}
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c
new file mode 100644
index 0000000000..08c54f8f7a
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Shift.c
@@ -0,0 +1,64 @@
+/** @file
+ Main file for Shift shell level 1 function.
+
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
+ Copyright (c) 2009 - 2010, 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
+ 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 'shift' 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
+ShellCommandRunShift (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ SCRIPT_FILE *CurrentScriptFile;
+ UINTN LoopVar;
+
+ Status = CommandInit();
+ ASSERT_EFI_ERROR(Status);
+
+ if (!gEfiShellProtocol->BatchIsActive()) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"shift");
+ return (SHELL_UNSUPPORTED);
+ }
+
+ CurrentScriptFile = ShellCommandGetCurrentScriptFile();
+ ASSERT(CurrentScriptFile != NULL);
+
+ if (CurrentScriptFile->Argc < 2) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"shift");
+ return (SHELL_UNSUPPORTED);
+ }
+
+ for (LoopVar = 0 ; LoopVar < CurrentScriptFile->Argc ; LoopVar++) {
+ if (LoopVar == 0) {
+ SHELL_FREE_NON_NULL(CurrentScriptFile->Argv[LoopVar]);
+ }
+ if (LoopVar < CurrentScriptFile->Argc -1) {
+ CurrentScriptFile->Argv[LoopVar] = CurrentScriptFile->Argv[LoopVar+1];
+ } else {
+ CurrentScriptFile->Argv[LoopVar] = NULL;
+ }
+ }
+ CurrentScriptFile->Argc--;
+ return (SHELL_SUCCESS);
+}
+
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Stall.c b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Stall.c
new file mode 100644
index 0000000000..476b1bc47f
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/Stall.c
@@ -0,0 +1,84 @@
+/** @file
+ Main file for stall shell level 1 function.
+
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
+ Copyright (c) 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
+ 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, L"stall", 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, L"stall");
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"stall");
+ 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_PARAM_INV), gShellLevel1HiiHandle, L"stall", 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, L"stall");
+ ShellStatus = SHELL_DEVICE_ERROR;
+ }
+ }
+ }
+ ShellCommandLineFreeVarList (Package);
+ }
+ return (ShellStatus);
+}
+
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c
new file mode 100644
index 0000000000..80d0dfe652
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.c
@@ -0,0 +1,310 @@
+/** @file
+ Main file for NULL named library for level 1 shell command functions.
+
+ (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<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
+ 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"
+
+STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
+EFI_HANDLE gShellLevel1HiiHandle = NULL;
+
+/**
+ Return the help text filename. Only used if no HII information found.
+
+ @retval the filename.
+**/
+CONST CHAR16*
+EFIAPI
+ShellCommandGetManFileNameLevel1 (
+ VOID
+ )
+{
+ return (mFileName);
+}
+
+/**
+ Constructor for the Shell Level 1 Commands library.
+
+ Install the handlers for level 1 UEFI Shell 2.0 commands.
+
+ @param ImageHandle the image handle of the process
+ @param SystemTable the EFI System Table pointer
+
+ @retval EFI_SUCCESS the shell command handlers were installed sucessfully
+ @retval EFI_UNSUPPORTED the shell level required was not found.
+**/
+EFI_STATUS
+EFIAPI
+ShellLevel1CommandsLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ //
+ // if shell level is less than 2 do nothing
+ //
+ if (PcdGet8(PcdShellSupportLevel) < 1) {
+ return (EFI_SUCCESS);
+ }
+
+ gShellLevel1HiiHandle = HiiAddPackages (&gShellLevel1HiiGuid, gImageHandle, UefiShellLevel1CommandsLibStrings, NULL);
+ if (gShellLevel1HiiHandle == NULL) {
+ return (EFI_DEVICE_ERROR);
+ }
+
+ //
+ // 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) ));
+ ShellCommandRegisterCommandName(L"shift", ShellCommandRunShift , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_SHIFT) ));
+ ShellCommandRegisterCommandName(L"exit", ShellCommandRunExit , ShellCommandGetManFileNameLevel1, 1, L"", TRUE , gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_EXIT) ));
+ ShellCommandRegisterCommandName(L"else", ShellCommandRunElse , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ELSE) ));
+ ShellCommandRegisterCommandName(L"endif", ShellCommandRunEndIf , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDIF) ));
+ ShellCommandRegisterCommandName(L"endfor", ShellCommandRunEndFor , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDFOR)));
+
+ return (EFI_SUCCESS);
+}
+
+/**
+ 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
+ShellLevel1CommandsLibDestructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ if (gShellLevel1HiiHandle != NULL) {
+ HiiRemovePackages(gShellLevel1HiiHandle);
+ }
+ 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 (
+ IN CONST LIST_MANIP_FUNC Function,
+ IN CONST CHAR16 *DecrementerTag,
+ IN CONST CHAR16 *IncrementerTag,
+ IN CONST CHAR16 *Label OPTIONAL,
+ IN OUT SCRIPT_FILE *ScriptFile,
+ IN CONST BOOLEAN MovePast,
+ IN CONST BOOLEAN FindOnly,
+ IN CONST SCRIPT_COMMAND_LIST *CommandNode,
+ IN OUT UINTN *TargetCount
+ )
+{
+ BOOLEAN Found;
+ CHAR16 *CommandName;
+ CHAR16 *CommandNameWalker;
+ CHAR16 *TempLocation;
+
+ Found = FALSE;
+
+ //
+ // get just the first part of the command line...
+ //
+ CommandName = NULL;
+ CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);
+ if (CommandName == NULL) {
+ return (FALSE);
+ }
+
+ CommandNameWalker = CommandName;
+
+ //
+ // Skip leading spaces and tabs.
+ //
+ while ((CommandNameWalker[0] == L' ') || (CommandNameWalker[0] == L'\t')) {
+ CommandNameWalker++;
+ }
+ TempLocation = StrStr(CommandNameWalker, L" ");
+
+ if (TempLocation != NULL) {
+ *TempLocation = CHAR_NULL;
+ }
+
+ //
+ // did we find a nested item ?
+ //
+ if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ (CHAR16*)CommandNameWalker,
+ (CHAR16*)IncrementerTag) == 0) {
+ (*TargetCount)++;
+ } else if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ (CHAR16*)CommandNameWalker,
+ (CHAR16*)DecrementerTag) == 0) {
+ if (*TargetCount > 0) {
+ (*TargetCount)--;
+ }
+ }
+
+ //
+ // did we find the matching one...
+ //
+ if (Label == NULL) {
+ if (*TargetCount == 0) {
+ Found = TRUE;
+ if (!FindOnly) {
+ if (MovePast) {
+ ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
+ } else {
+ ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
+ }
+ }
+ }
+ } else {
+ if (gUnicodeCollation->StriColl(
+ gUnicodeCollation,
+ (CHAR16*)CommandNameWalker,
+ (CHAR16*)Label) == 0
+ && (*TargetCount) == 0) {
+ Found = TRUE;
+ if (!FindOnly) {
+ //
+ // we found the target label without loops
+ //
+ if (MovePast) {
+ ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
+ } else {
+ ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
+ }
+ }
+ }
+ }
+
+ //
+ // Free the memory for this loop...
+ //
+ FreePool(CommandName);
+ 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 (
+ IN CONST LIST_MANIP_FUNC Function,
+ IN CONST CHAR16 *DecrementerTag,
+ IN CONST CHAR16 *IncrementerTag,
+ IN CONST CHAR16 *Label OPTIONAL,
+ IN OUT SCRIPT_FILE *ScriptFile,
+ IN CONST BOOLEAN MovePast,
+ IN CONST BOOLEAN FindOnly,
+ IN CONST BOOLEAN WrapAroundScript
+ )
+{
+ SCRIPT_COMMAND_LIST *CommandNode;
+ BOOLEAN Found;
+ UINTN TargetCount;
+
+ if (Label == NULL) {
+ TargetCount = 1;
+ } else {
+ TargetCount = 0;
+ }
+
+ if (ScriptFile == NULL) {
+ return FALSE;
+ }
+
+ for (CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &ScriptFile->CurrentCommand->Link), Found = FALSE
+ ; !IsNull(&ScriptFile->CommandList, &CommandNode->Link)&& !Found
+ ; CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link)
+ ){
+ Found = TestNodeForMove(
+ Function,
+ DecrementerTag,
+ IncrementerTag,
+ Label,
+ ScriptFile,
+ MovePast,
+ FindOnly,
+ CommandNode,
+ &TargetCount);
+ }
+
+ if (WrapAroundScript && !Found) {
+ for (CommandNode = (SCRIPT_COMMAND_LIST *)GetFirstNode(&ScriptFile->CommandList), Found = FALSE
+ ; CommandNode != ScriptFile->CurrentCommand && !Found
+ ; CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link)
+ ){
+ Found = TestNodeForMove(
+ Function,
+ DecrementerTag,
+ IncrementerTag,
+ Label,
+ ScriptFile,
+ MovePast,
+ FindOnly,
+ CommandNode,
+ &TargetCount);
+ }
+ }
+ return (Found);
+}
+
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.h b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.h
new file mode 100644
index 0000000000..c4ef536202
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.h
@@ -0,0 +1,211 @@
+/** @file
+ Main file for NULL named library for level 1 shell command functions.
+
+ Copyright (c) 2009 - 2013, 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
+ 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.
+
+**/
+
+#ifndef _UEFI_SHELL_LEVEL1_COMMANDS_LIB_H_
+#define _UEFI_SHELL_LEVEL1_COMMANDS_LIB_H_
+
+#include <Uefi.h>
+#include <ShellBase.h>
+
+#include <Guid/ShellLibHiiGuid.h>
+
+#include <Protocol/EfiShell.h>
+#include <Protocol/EfiShellParameters.h>
+#include <Protocol/DevicePath.h>
+#include <Protocol/LoadedImage.h>
+#include <Protocol/UnicodeCollation.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
+#include <Library/ShellCommandLib.h>
+#include <Library/ShellLib.h>
+#include <Library/SortLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/HiiLib.h>
+#include <Library/FileHandleLib.h>
+
+extern EFI_HANDLE gShellLevel1HiiHandle;
+
+/**
+ 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.
+
+ @param[in] ImageHandle Handle to the Image (NULL if Internal).
+ @param[in] SystemTable Pointer to the System Table (NULL if Internal).
+**/
+SHELL_STATUS
+EFIAPI
+ShellCommandRunExit (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+/**
+ Function for 'endif' 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
+ShellCommandRunEndIf (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+/**
+ Function for 'for' 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
+ShellCommandRunFor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+/**
+ Function for 'endfor' 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
+ShellCommandRunEndFor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+/**
+ Function for 'if' 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
+ShellCommandRunIf (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+/**
+ Function for 'goto' 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
+ShellCommandRunGoto (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+/**
+ Function for 'shift' 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
+ShellCommandRunShift (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+
+/**
+ Function for 'else' 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
+ShellCommandRunElse (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+///
+/// Function prototype for BOTH GetNextNode and GetPreviousNode...
+/// This is used to control the MoveToTag function direction...
+///
+typedef
+LIST_ENTRY *
+(EFIAPI *LIST_MANIP_FUNC)(
+ IN CONST LIST_ENTRY *List,
+ IN CONST LIST_ENTRY *Node
+ );
+
+/**
+ 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 (
+ IN CONST LIST_MANIP_FUNC Function,
+ IN CONST CHAR16 *DecrementerTag,
+ IN CONST CHAR16 *IncrementerTag,
+ IN CONST CHAR16 *Label OPTIONAL,
+ IN OUT SCRIPT_FILE *ScriptFile,
+ IN CONST BOOLEAN MovePast,
+ IN CONST BOOLEAN FindOnly,
+ IN CONST BOOLEAN WrapAroundScript
+ );
+
+#endif
+
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
new file mode 100644
index 0000000000..4d3713b460
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
@@ -0,0 +1,58 @@
+## @file
+# Provides shell level 1 functions
+#
+# Copyright (c) 2009-2015, 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
+# 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.
+#
+#
+##
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = UefiShellLevel1CommandsLib
+ FILE_GUID = 50cb6037-1102-47af-b2dd-9944b6eb1abe
+ MODULE_TYPE = UEFI_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = NULL|UEFI_APPLICATION UEFI_DRIVER
+ CONSTRUCTOR = ShellLevel1CommandsLibConstructor
+ DESTRUCTOR = ShellLevel1CommandsLibDestructor
+
+[Sources.common]
+ UefiShellLevel1CommandsLib.c
+ UefiShellLevel1CommandsLib.h
+ UefiShellLevel1CommandsLib.uni
+ Exit.c
+ Goto.c
+ If.c
+ For.c
+ Shift.c
+ Stall.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ MemoryAllocationLib
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ ShellCommandLib
+ ShellLib
+ UefiLib
+ UefiRuntimeServicesTableLib
+ UefiBootServicesTableLib
+ SortLib
+ PrintLib
+
+[Pcd.common]
+ gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel ## CONSUMES
+
+[Guids]
+ gShellLevel1HiiGuid ## SOMETIMES_CONSUMES ## HII
diff --git a/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.uni b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.uni
new file mode 100644
index 0000000000..73e8655ff5
--- /dev/null
+++ b/Core/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.uni
@@ -0,0 +1,504 @@
+// /**
+//
+// (C) Copyright 2014-2015 Hewlett-Packard Development Company, L.P.<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
+// 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.
+//
+// Module Name:
+//
+// UefiShellLevel2CommandsLib.uni
+//
+// Abstract:
+//
+// String definitions for UEFI Shell 2.0 level 1 commands
+//
+//
+// **/
+
+/=#
+
+#langdef en-US "english"
+
+#string STR_NO_SCRIPT #language en-US "The command '%H%s%N' is incorrect outside of a script\r\n"
+#string STR_GEN_PROBLEM #language en-US "%H%s%N: Unknown flag - '%H%s%N'\r\n"
+#string STR_GEN_PROBLEM_VAL #language en-US "%H%s%N: Bad value - '%H%s%N' for flag - '%H%s%N'\r\n"
+#string STR_GEN_PROBLEM_SCRIPT #language en-US "The argument '%B%s%N' is incorrect. Line: %d\r\n"
+#string STR_GEN_INV_VAR #language en-US "The script's Indexvar '%B%s%N' is incorrect\r\n"
+#string STR_GEN_TOO_FEW #language en-US "%H%s%N: Too few arguments\r\n"
+#string STR_GEN_TOO_MANY #language en-US "%H%s%N: Too many arguments\r\n"
+#string STR_GEN_PARAM_INV #language en-US "%H%s%N: Invalid argument - '%H%s%N'\r\n"
+
+#string STR_TEXT_AFTER_THEN #language en-US "%H%s%N: Then cannot be followed by anything\r\n"
+#string STR_SYNTAX_AFTER_BAD #language en-US "%H%s%N: Syntax after '%H%s%N' is incorrect\r\n"
+#string STR_SYNTAX_IN #language en-US "Syntax after analyzing %s\r\n"
+#string STR_SYNTAX_NO_MATCHING #language en-US "No matching '%H%s%N' for '%H%s%N' statement found. Line: %d\r\n"
+#string STR_INVALID_BINOP #language en-US "Binary operator not found first in '%H%s%N'\r\n"
+#string STR_SYNTAX_STARTING #language en-US "Syntax after %s\r\n"
+
+#string STR_STALL_FAILED #language en-US "%H%s%N: BootService Stall() failed\r\n"
+
+#string STR_GET_HELP_EXIT #language en-US ""
+".TH exit 0 "exits the script or shell"\r\n"
+".SH NAME\r\n"
+"Exits the UEFI Shell or the current script.\r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"EXIT [/b] [exit-code]\r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" /b - Indicates that only the current UEFI shell script should be\r\n"
+" terminated. Ignored if not used within a script.\r\n"
+" exit-code - If exiting a UEFI shell script, the value that will be placed\r\n"
+" into the environment variable lasterror. If exiting an instance\r\n"
+" of the UEFI shell, the value that will be returned to the\r\n"
+" caller. If not specified, then 0 will be returned.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. This command exits the UEFI Shell or, if /b is specified, the current\r\n"
+" script.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To exit shell successfully:\r\n"
+" Shell> exit\r\n"
+" \r\n"
+" * To exit the current UEFI shell script:\r\n"
+" Shell> exit /b \r\n"
+" \r\n"
+" * To exit a UEFI shell script with exit-code value returned to the caller:\r\n"
+" Shell> exit 0\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" 0 Exited normally\r\n"
+" exit-code The return value specified as an option.\r\n"
+
+#string STR_GET_HELP_FOR #language en-US ""
+".TH for 0 "starts a for loop"\r\n"
+".SH NAME\r\n"
+"Starts a loop based on 'for' syntax.\r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"FOR %indexvar IN set\r\n"
+" command [arguments]\r\n"
+" [command [arguments]]\r\n"
+" ...\r\n"
+"ENDFOR\r\n"
+" \r\n"
+"FOR %indexvar RUN (start end [step])\r\n"
+" command [arguments]\r\n"
+" [command [arguments]]\r\n"
+" ...\r\n"
+"ENDFOR\r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" %indexvar - Variable name used to index a set\r\n"
+" set - Set to be searched\r\n"
+" command [arguments] - Command to be executed with optional arguments\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. The FOR command executes one or more commands for each item in a set of\r\n"
+" items. The set may be text strings or filenames or a mixture of both,\r\n"
+" separated by spaces (if not in a quotation).\r\n"
+" 2. If the length of an element in the set is between 0 and 256, and if the\r\n"
+" string contains wildcards, the string will be treated as a file name\r\n"
+" containing wildcards, and be expanded before command is executed.\r\n"
+" 3. If after expansion no such files are found, the literal string itself is\r\n"
+" kept. %indexvar is any alphabet character from 'a' to 'z' or 'A' to 'Z',\r\n"
+" and they are case sensitive. It should not be a digit (0-9) because\r\n"
+" %digit will be interpreted as a positional argument on the command line\r\n"
+" that launches the script. The namespace for index variables is separate\r\n"
+" from that for environment variables, so if %indexvar has the same name as\r\n"
+" an existing environment variable, the environment variable will remain\r\n"
+" unchanged by the FOR loop.\r\n"
+" 4. Each command is executed once for each item in the set, with any\r\n"
+" occurrence of %indexvar in the command replacing with the current item.\r\n"
+" In the second format of FOR ... ENDFOR statement, %indexvar will be\r\n"
+" assigned a value from start to end with an interval of step. Start and\r\n"
+" end can be any integer whose length is less than 7 digits excluding sign,\r\n"
+" and it can also applied to step with one exception of zero. Step is\r\n"
+" optional, if step is not specified it will be automatically determined by\r\n"
+" following rule:\r\n"
+" if start <= end then step = 1, otherwise step = -1.\r\n"
+" start, end and step are divided by space.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * Sample FOR loop - listing all .txt files:\r\n"
+" echo -off\r\n"
+" for %a in *.txt\r\n"
+" echo %a exists\r\n"
+" endfor\r\n"
+" \r\n"
+" # \r\n"
+" # If in current directory, there are 2 files named file1.txt and file2.txt\r\n"
+" # then the output of the sample script will be as shown below.\r\n"
+" # \r\n"
+" Sample1> echo -off\r\n"
+" file1.txt exists\r\n"
+" file2.txt exists\r\n"
+" \r\n"
+" * Theoretically it is legal for 2 nested FOR commands to use the same\r\n"
+" alphabet letter as their index variable, for instance, a: \r\n"
+" #\r\n"
+" # Sample FOR loop from 1 to 3 with step 1\r\n"
+" #\r\n"
+" echo -off\r\n"
+" for %a run (1 3)\r\n"
+" echo %a\r\n"
+" endfor\r\n"
+" \r\n"
+" #\r\n"
+" # Sample FOR loop from 3 down to 1 with step -1\r\n"
+" #\r\n"
+" echo -off\r\n"
+" for %a run (3 1 -1)\r\n"
+" echo %a\r\n"
+" endfor\r\n"
+" \r\n"
+" #\r\n"
+" # Sample FOR loop - 2 nested for using same index variable\r\n"
+" #\r\n"
+" echo -off\r\n"
+" for %a in value1 value2\r\n"
+" for %a in value3 value4\r\n"
+" echo %a\r\n"
+" endfor\r\n"
+" endfor\r\n"
+" \r\n"
+" Note: When processing first FOR and before seeing the ENDFOR, the index\r\n"
+" variable %a has the value "value1", so in second FOR, the %a has\r\n"
+" been already defined and it will be replaced with the current value\r\n"
+" of %a. The string after substitution becomes FOR value1 in value3\r\n"
+" value4, which is not a legal FOR command. Thus only when the value\r\n"
+" of %a is also a single alphabet letter, the script will be executed\r\n"
+" without error. If 2 independent FOR commands use the same index\r\n"
+" variable, when the second FOR is encountered, the first FOR has\r\n"
+" already freed the variable so there will be no problem in this case.\r\n"
+
+#string STR_GET_HELP_ENDFOR #language en-US ""
+".TH endfor 0 "ends a for loop"\r\n"
+".SH NAME\r\n"
+"Ends a 'for' loop.\r\n"
+".SH SYNOPSIS\r\n"
+"See 'for' for usage.\r\n"
+".SH EXAMPLES\r\n"
+"See 'for' for examples.\r\n"
+
+#string STR_GET_HELP_GOTO #language en-US ""
+".TH goto 0 "moves to a label"\r\n"
+".SH NAME\r\n"
+"Moves around the point of execution in a script.\r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"GOTO label\r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" label - Specifies a location in batch file\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. The GOTO command directs script file execution to the line in the script\r\n"
+" file after the given label. The command is not supported from the\r\n"
+" interactive shell.\r\n"
+" 2. A label is a line beginning with a colon (:). It can appear either after\r\n"
+" the GOTO command, or before the GOTO command. The search for label is\r\n"
+" done forward in the script file, from the current file position. If the\r\n"
+" end of the file is reached, the search resumes at the top of the file and\r\n"
+" continues until label is found or the starting point is reached. If label\r\n"
+" is not found, the script process terminates and an error message is\r\n"
+" displayed. If a label is encountered but there is no GOTO command\r\n"
+" executed, the label lines are ignored.\r\n"
+" 3. Using GOTO command to jump into another for loop is not allowed,\r\n"
+" but jumping into an if statement is legal.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * This is a script:\r\n"
+" goto Done\r\n"
+" ...\r\n"
+" :Done\r\n"
+" cleanup.nsh\r\n"
+
+#string STR_GET_HELP_ENDIF #language en-US ""
+".TH endif 0 "ends an if block"\r\n"
+".SH NAME\r\n"
+"Ends the block of a script controlled by an 'if' statement.\r\n"
+".SH SYNOPSIS\r\n"
+"See 'if' for usage.\r\n"
+".SH EXAMPLES\r\n"
+"See 'if' for examples.\r\n"
+
+#string STR_GET_HELP_IF #language en-US ""
+".TH if 0 "controls the execution of a block of a script"\r\n"
+".SH NAME\r\n"
+"Executes commands in specified conditions.\r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"IF [NOT] EXIST filename THEN\r\n"
+" command [arguments]\r\n"
+" [command [arguments]]\r\n"
+" ...\r\n"
+"[ELSE\r\n"
+" command [arguments]\r\n"
+" [command [arguments]]\r\n"
+" ...\r\n"
+" ]\r\n"
+"ENDIF\r\n"
+" \r\n"
+"IF [/i] [NOT] string1 == string2 THEN\r\n"
+" command [arguments]\r\n"
+" [command [arguments]]\r\n"
+" ...\r\n"
+"[ELSE\r\n"
+" command [arguments]\r\n"
+" [command [arguments]]\r\n"
+" ...\r\n"
+" ]\r\n"
+"ENDIF\r\n"
+"if [/i][/s] ConditionalExpression THEN\r\n"
+" command [arguments]\r\n"
+" [command [arguments]]\r\n"
+" ...\r\n"
+"[ELSE\r\n"
+" command [arguments]\r\n"
+" [command [arguments]]\r\n"
+" ...\r\n"
+" ]\r\n"
+"ENDIF\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. The IF command executes one or more commands before the ELSE or ENDIF\r\n"
+" commands, if the specified condition is TRUE; otherwise commands between\r\n"
+" ELSE (if present) and ENDIF are executed.\r\n"
+" 2. In the first usage of IF, the EXIST condition is true when the file\r\n"
+" specified by filename exists. The filename argument may include device\r\n"
+" and path information. Also wildcard expansion is supported by this form.\r\n"
+" If more than one file matches the wildcard pattern, the condition\r\n"
+" evaluates to TRUE.\r\n"
+" 3. In the second usage, the string1 == string2 condition is TRUE if the two\r\n"
+" strings are identical. Here the comparison can be case sensitive or\r\n"
+" insensitive, it depends on the optional switch /i. If /i is specified,\r\n"
+" it will compare strings in the case insensitive manner; otherwise, it\r\n"
+" compares strings in the case sensitive manner.\r\n"
+" 4. In the third usage, general purpose comparison is supported using\r\n"
+" expressions optionally separated by AND or OR. Since < and > are used for\r\n"
+" redirection, the expressions use common two character (FORTRAN)\r\n"
+" abbreviations for the operators (augmented with unsigned equivalents):\r\n"
+" - Expressions : Conditional expressions are evaluated strictly from left\r\n"
+" to right. Complex conditionals requiring precedence may\r\n"
+" be implemented as nested IFs.\r\n"
+" The expressions used in the third usage can have the\r\n"
+" following syntax:\r\n"
+" conditional-expression := expression |\r\n"
+" expression and expression |\r\n"
+" expression or expression\r\n"
+" expression := expr | not expr\r\n"
+" expr := item binop item | boolfunc(string)\r\n"
+" item := mapfunc(string) | string\r\n"
+" mapfunc := efierror | pierror | oemerror\r\n"
+" boolfunc := isint | exists | available | profile\r\n"
+" binop := gt | lt | eq | ne | ge | le | == | ugt | ult |\r\n"
+" uge | ule\r\n"
+" - Comparisons : By default, comparisons are done numerically if the\r\n"
+" strings on both sides of the operator are numbers\r\n"
+" (as defined below) and in case sensitive character sort\r\n"
+" order otherwise. Spaces separate the operators from\r\n"
+" operands.\r\n"
+" 5. The /s option forces string comparisons and the /i option forces\r\n"
+" case-insensitive string comparisons. If either of these is used, the\r\n"
+" signed or unsigned versions of the operators have the same results.\r\n"
+" The /s and /i apply to the entire line and must appear at the start of\r\n"
+" the line (just after the if itself). The two may appear in either order.\r\n"
+" 6. When performing comparisons, the Unicode Byte Ordering Character is\r\n"
+" ignored at the beginning of any argument.\r\n"
+" 7. Comparison Operator Definition:\r\n"
+" gt : Greater than\r\n"
+" ugt : Unsigned Greater than\r\n"
+" lt : Less than\r\n"
+" ult : Unsigned Less than\r\n"
+" ge : Greater than or equal\r\n"
+" uge : Unsigned greater than or equal\r\n"
+" le : Less than or equal\r\n"
+" ule : Unsigned less than or equal\r\n"
+" ne : Not equal\r\n"
+" eq : Equals (semantically equivalent to ==)\r\n"
+" == : Equals (semantically equivalent to eq)\r\n"
+" 8. Error Mapping Functions are used to convert integers into UEFI, PI or OEM\r\n"
+" error codes.\r\n"
+" Functions used to convert integers into UEFI, PI or OEM error codes:\r\n"
+" UefiError : Sets top nibble of parameter to 1000 binary (0x8)\r\n"
+" PiError : Sets top nibble of parameter to 1010 binary (0xA)\r\n"
+" OemError : Sets top nibble of parameter to 1100 binary (0xC)\r\n"
+" Each function maps the small positive parameter into its equivalent error\r\n"
+" classification.\r\n"
+" For example:\r\n"
+" if %lasterror% == EfiError(8) then # Check for write protect.\r\n"
+" ...\r\n"
+" 9. Boolean Functions may only be used to modify operators in comparisons.\r\n"
+" The following built-in Boolean functions are also available:\r\n"
+" IsInt : Evaluates to true if the parameter string that follows\r\n"
+" is a number (as defined below) and false otherwise.\r\n"
+" Exists : Evaluates to true if the file specified by string exists\r\n"
+" is in the current working directory or false if not.\r\n"
+" Available : Evaluates to true if the file specified by string is in the\r\n"
+" current working directory or current path.\r\n"
+" Profile : Determines whether the parameter string matches one of the\r\n"
+" profile names in the profiles environment variable.\r\n"
+" 10. No spaces are allowed between function names and the open parenthesis,\r\n"
+" between the open parenthesis and the string or between the string and\r\n"
+" the closed parenthesis. Constant strings containing spaces must be\r\n"
+" quoted.\r\n"
+" 11. To avoid ambiguity and current or future incompatibility, users are\r\n"
+" strongly encouraged to surround constant strings that contain\r\n"
+" parenthesis with quotes in if statements.\r\n"
+" 12. Allowable number formats are decimal numbers and C-style case\r\n"
+" insensitive hexadecimal numbers. Numbers may be preceded by a\r\n"
+" "-" indicating a negative number.\r\n"
+" Examples:\r\n"
+" 13\r\n"
+" 46\r\n"
+" -0x3FFF\r\n"
+" 0x3fff\r\n"
+" 0x1234\r\n"
+" 13. Unsigned values must be less than 264. Signed integer values are bounded\r\n"
+" by -/+263.\r\n"
+" 14. Numbers are internally represented in two's compliment form. The\r\n"
+" representation of the number in the string has no bearing on the way\r\n"
+" that number is treated in an numeric expression - type is assigned by\r\n"
+" the operator. So, for example, -1 lt 2 is true but -1 ult 2 is false.\r\n"
+" 15. The IF command is only available in scripts.\r\n"
+" 16. The ELSE command is optional in an IF/ELSE statement.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * Sample script for "if" command usages 1 and 2:\r\n"
+" if exist fs0:\myscript.nsh then\r\n"
+" myscript myarg1 myarg2\r\n"
+" endif\r\n"
+" if %myvar% == runboth then\r\n"
+" myscript1\r\n"
+" myscript2\r\n"
+" else\r\n"
+" echo ^%myvar^% != runboth\r\n"
+" endif\r\n"
+" Note: In this example, if the script file myscript.nsh exists in fs0:\,\r\n"
+" this script will be launched with 2 arguments, myarg1 and myarg2.\r\n"
+" After that, environment variable %myvar% is checked to see if its\r\n"
+" value is runboth, if so, script myscript1 and myscript2 will be\r\n"
+" executed one after the other, otherwise a message %myvar% != runboth\r\n"
+" is printed.\r\n"
+" \r\n"
+" * Sample script for "if" command usage 3:\r\n"
+" :Redo\r\n"
+" echo Enter 0-6 or q to quit\r\n"
+" # assumes "input y" stores a character of user input into variable y\r\n"
+" InputCh MyVar\r\n"
+" if x%MyVar% eq x then\r\n"
+" echo Empty line. Try again\r\n"
+" goto Redo\r\n"
+" endif\r\n"
+" if IsInt(%MyVar%) and %MyVar% le 6 then\r\n"
+" myscript1 %MyVar%\r\n"
+" goto Redo\r\n"
+" endif\r\n"
+" if /i %MyVar% ne q then\r\n"
+" echo Invalid input\r\n"
+" goto Redo\r\n"
+" endif\r\n"
+" Note: In this example, the script requests user input and uses the if\r\n"
+" command for input validation. It checks for empty line first and\r\n"
+" then range checks the input.\r\n"
+
+#string STR_GET_HELP_SHIFT #language en-US ""
+".TH shift 0 "move parameters 1 down"\r\n"
+".SH NAME\r\n"
+"Shifts in-script parameter positions.\r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"SHIFT\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. The SHIFT command shifts the contents of a UEFI Shell script's positional\r\n"
+" parameters so that %1 is discarded, %2 is copied to %1, %3 is copied to\r\n"
+" %2, %4 is copied to %3 and so on. This allows UEFI Shell scripts to\r\n"
+" process script parameters from left to right.\r\n"
+" 2. This command does not change the UEFI shell environment variable\r\n"
+" lasterror.\r\n"
+" 3. The SHIFT command is available only in UEFI Shell scripts.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * Following script is a sample of 'shift' command:\r\n"
+" fs0:\> type shift.nsh\r\n"
+" #\r\n"
+" # shift.nsh\r\n"
+" # \r\n"
+" echo %1 %2 %3\r\n"
+" shift\r\n"
+" echo %1 %2\r\n"
+" \r\n"
+" * To execute the script with echo on:\r\n"
+" fs0:\> shift.nsh welcome UEFI world\r\n"
+" shift.nsh> echo welcome UEFI world\r\n"
+" welcome UEFI world\r\n"
+" shift\r\n"
+" echo UEFI world\r\n"
+" UEFI world\r\n"
+" \r\n"
+" * To execute the script with echo off:\r\n"
+" fs0:\> echo -off\r\n"
+" fs0:\> shift.nsh welcome UEFI world\r\n"
+" welcome UEFI world\r\n"
+" UEFI world\r\n"
+
+#string STR_GET_HELP_ELSE #language en-US ""
+".TH else 0 "part of an 'if' conditional statement"\r\n"
+".SH NAME\r\n"
+"Identifies the code executed when 'if' is FALSE.\r\n"
+".SH SYNOPSIS\r\n"
+"See 'else' for usage.\r\n"
+".SH EXAMPLES\r\n"
+"See 'if' for examples.\r\n"
+
+#string STR_GET_HELP_STALL #language en-US ""
+".TH stall 0 "stall the operation"\r\n"
+".SH NAME\r\n"
+"Stalls the operation for a specified number of microseconds.\r\n"
+".SH SYNOPSIS\r\n"
+" \r\n"
+"STALL time\r\n"
+".SH OPTIONS\r\n"
+" \r\n"
+" time - The number of microseconds for the processor to stall.\r\n"
+".SH DESCRIPTION\r\n"
+" \r\n"
+"NOTES:\r\n"
+" 1. This command would be used to establish a timed STALL of operations\r\n"
+" during a script.\r\n"
+" 2. Microseconds is in decimal units.\r\n"
+".SH EXAMPLES\r\n"
+" \r\n"
+"EXAMPLES:\r\n"
+" * To stall the processor for 1000000 microseconds:\r\n"
+" Shell> stall 1000000\r\n"
+".SH RETURNVALUES\r\n"
+" \r\n"
+"RETURN VALUES:\r\n"
+" SHELL_SUCCESS The action was completed as requested.\r\n"
+" SHELL_NOT_FOUND The requested option was not found.\r\n"
+" SHELL_INVALID_PARAMETER One of the passed in parameters was incorrectly\r\n"
+" formatted or its value was out of bounds.\r\n"
+" SHELL_DEVICE_ERROR There was a hardware error associated with this\r\n"
+" request.\r\n"
+