TianoCore EDK2 master
Loading...
Searching...
No Matches
Goto.c
Go to the documentation of this file.
1
11
19EFIAPI
21 IN EFI_HANDLE ImageHandle,
22 IN EFI_SYSTEM_TABLE *SystemTable
23 )
24{
25 EFI_STATUS Status;
26 LIST_ENTRY *Package;
27 CHAR16 *ProblemParam;
28 SHELL_STATUS ShellStatus;
29 CHAR16 *CompareString;
30 UINTN Size;
31 SCRIPT_FILE *CurrentScriptFile;
32
33 ShellStatus = SHELL_SUCCESS;
34 CompareString = NULL;
35
36 //
37 // initialize the shell lib (we must be in non-auto-init...)
38 //
39 Status = ShellInitialize ();
40 ASSERT_EFI_ERROR (Status);
41
42 Status = CommandInit ();
43 ASSERT_EFI_ERROR (Status);
44
45 if (!gEfiShellProtocol->BatchIsActive ()) {
46 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto");
47 return (SHELL_UNSUPPORTED);
48 }
49
50 //
51 // parse the command line
52 //
53 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
54 if (EFI_ERROR (Status)) {
55 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
56 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, L"goto", ProblemParam);
57 FreePool (ProblemParam);
58 ShellStatus = SHELL_INVALID_PARAMETER;
59 } else {
60 ASSERT (FALSE);
61 }
62 } else {
63 if (ShellCommandLineGetRawValue (Package, 2) != NULL) {
64 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"goto");
65 ShellStatus = SHELL_INVALID_PARAMETER;
66 } else if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
67 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"goto");
68 ShellStatus = SHELL_INVALID_PARAMETER;
69 } else {
70 Size = 0;
71 ASSERT ((CompareString == NULL && Size == 0) || (CompareString != NULL));
72 CompareString = StrnCatGrow (&CompareString, &Size, L":", 0);
73 CompareString = StrnCatGrow (&CompareString, &Size, ShellCommandLineGetRawValue (Package, 1), 0);
74 if (CompareString == NULL) {
77 }
78
79 //
80 // Check forwards and then backwards for a label...
81 //
82 if (!MoveToTag (GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile (), FALSE, FALSE, TRUE)) {
83 CurrentScriptFile = ShellCommandGetCurrentScriptFile ();
85 -1,
86 -1,
87 NULL,
88 STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
89 gShellLevel1HiiHandle,
90 CompareString,
91 L"Goto",
92 CurrentScriptFile != NULL
93 && CurrentScriptFile->CurrentCommand != NULL
94 ? CurrentScriptFile->CurrentCommand->Line : 0
95 );
96 ShellStatus = SHELL_NOT_FOUND;
97 }
98
99 FreePool (CompareString);
100 }
101
103 }
104
105 return (ShellStatus);
106}
UINT64 UINTN
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:333
VOID EFIAPI FreePool(IN VOID *Buffer)
SHELL_STATUS EFIAPI ShellCommandRunGoto(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Goto.c:20
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_OUT_OF_RESOURCES
Definition: Shell.h:73
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_UNSUPPORTED
Definition: Shell.h:40
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_STATUS EFIAPI CommandInit(VOID)
SCRIPT_FILE *EFIAPI ShellCommandGetCurrentScriptFile(VOID)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
SHELL_PARAM_ITEM EmptyParamList[]
Helper structure for no parameters (besides -? and -b)
Definition: UefiShellLib.c:19
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define STRING_TOKEN(t)
BOOLEAN 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)
UINTN Line
What line of the script file this was on.
SCRIPT_COMMAND_LIST * CurrentCommand
The command currently being operated. If !=NULL must be a member of CommandList.