]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel1CommandsLib / Goto.c
1 /** @file
2 Main file for goto shell level 1 function.
3
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "UefiShellLevel1CommandsLib.h"
11
12 /**
13 Function for 'goto' command.
14
15 @param[in] ImageHandle Handle to the Image (NULL if Internal).
16 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
17 **/
18 SHELL_STATUS
19 EFIAPI
20 ShellCommandRunGoto (
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 //
75 // Check forwards and then backwards for a label...
76 //
77 if (!MoveToTag (GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile (), FALSE, FALSE, TRUE)) {
78 CurrentScriptFile = ShellCommandGetCurrentScriptFile ();
79 ShellPrintHiiEx (
80 -1,
81 -1,
82 NULL,
83 STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
84 gShellLevel1HiiHandle,
85 CompareString,
86 L"Goto",
87 CurrentScriptFile != NULL
88 && CurrentScriptFile->CurrentCommand != NULL
89 ? CurrentScriptFile->CurrentCommand->Line : 0
90 );
91 ShellStatus = SHELL_NOT_FOUND;
92 }
93
94 FreePool (CompareString);
95 }
96
97 ShellCommandLineFreeVarList (Package);
98 }
99
100 return (ShellStatus);
101 }