2 Main file for goto shell level 1 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellLevel1CommandsLib.h"
19 Function for 'goto' command.
21 @param[in] ImageHandle Handle to the Image (NULL if Internal).
22 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
27 IN EFI_HANDLE ImageHandle
,
28 IN EFI_SYSTEM_TABLE
*SystemTable
34 SHELL_STATUS ShellStatus
;
35 CHAR16
*CompareString
;
37 SCRIPT_FILE
*CurrentScriptFile
;
39 ShellStatus
= SHELL_SUCCESS
;
43 // initialize the shell lib (we must be in non-auto-init...)
45 Status
= ShellInitialize();
46 ASSERT_EFI_ERROR(Status
);
48 Status
= CommandInit();
49 ASSERT_EFI_ERROR(Status
);
51 if (!gEfiShellProtocol
->BatchIsActive()) {
52 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_NO_SCRIPT
), gShellLevel1HiiHandle
, L
"Goto");
53 return (SHELL_UNSUPPORTED
);
57 // parse the command line
59 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
60 if (EFI_ERROR(Status
)) {
61 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
62 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel1HiiHandle
, L
"goto", ProblemParam
);
63 FreePool(ProblemParam
);
64 ShellStatus
= SHELL_INVALID_PARAMETER
;
69 if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
70 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel1HiiHandle
, L
"goto");
71 ShellStatus
= SHELL_INVALID_PARAMETER
;
72 } else if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
73 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel1HiiHandle
, L
"goto");
74 ShellStatus
= SHELL_INVALID_PARAMETER
;
77 ASSERT((CompareString
== NULL
&& Size
== 0) || (CompareString
!= NULL
));
78 CompareString
= StrnCatGrow(&CompareString
, &Size
, L
":", 0);
79 CompareString
= StrnCatGrow(&CompareString
, &Size
, ShellCommandLineGetRawValue(Package
, 1), 0);
81 // Check forwards and then backwards for a label...
83 if (!MoveToTag(GetNextNode
, L
"endfor", L
"for", CompareString
, ShellCommandGetCurrentScriptFile(), FALSE
, FALSE
, TRUE
)) {
84 CurrentScriptFile
= ShellCommandGetCurrentScriptFile();
89 STRING_TOKEN (STR_SYNTAX_NO_MATCHING
),
90 gShellLevel1HiiHandle
,
93 CurrentScriptFile
!=NULL
94 && CurrentScriptFile
->CurrentCommand
!=NULL
95 ? CurrentScriptFile
->CurrentCommand
->Line
:0);
96 ShellStatus
= SHELL_NOT_FOUND
;
98 FreePool(CompareString
);
100 ShellCommandLineFreeVarList (Package
);
103 return (ShellStatus
);