2 Main file for goto shell level 1 function.
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
10 #include "UefiShellLevel1CommandsLib.h"
13 Function for 'goto' command.
15 @param[in] ImageHandle Handle to the Image (NULL if Internal).
16 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
21 IN EFI_HANDLE ImageHandle
,
22 IN EFI_SYSTEM_TABLE
*SystemTable
28 SHELL_STATUS ShellStatus
;
29 CHAR16
*CompareString
;
31 SCRIPT_FILE
*CurrentScriptFile
;
33 ShellStatus
= SHELL_SUCCESS
;
37 // initialize the shell lib (we must be in non-auto-init...)
39 Status
= ShellInitialize ();
40 ASSERT_EFI_ERROR (Status
);
42 Status
= CommandInit ();
43 ASSERT_EFI_ERROR (Status
);
45 if (!gEfiShellProtocol
->BatchIsActive ()) {
46 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_NO_SCRIPT
), gShellLevel1HiiHandle
, L
"Goto");
47 return (SHELL_UNSUPPORTED
);
51 // parse the command line
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
;
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
;
71 ASSERT ((CompareString
== NULL
&& Size
== 0) || (CompareString
!= NULL
));
72 CompareString
= StrnCatGrow (&CompareString
, &Size
, L
":", 0);
73 CompareString
= StrnCatGrow (&CompareString
, &Size
, ShellCommandLineGetRawValue (Package
, 1), 0);
75 // Check forwards and then backwards for a label...
77 if (!MoveToTag (GetNextNode
, L
"endfor", L
"for", CompareString
, ShellCommandGetCurrentScriptFile (), FALSE
, FALSE
, TRUE
)) {
78 CurrentScriptFile
= ShellCommandGetCurrentScriptFile ();
83 STRING_TOKEN (STR_SYNTAX_NO_MATCHING
),
84 gShellLevel1HiiHandle
,
87 CurrentScriptFile
!= NULL
88 && CurrentScriptFile
->CurrentCommand
!= NULL
89 ? CurrentScriptFile
->CurrentCommand
->Line
: 0
91 ShellStatus
= SHELL_NOT_FOUND
;
94 FreePool (CompareString
);
97 ShellCommandLineFreeVarList (Package
);
100 return (ShellStatus
);