2 Main file for goto shell level 1 function.
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellLevel1CommandsLib.h"
18 Function for 'goto' command.
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
26 IN EFI_HANDLE ImageHandle
,
27 IN EFI_SYSTEM_TABLE
*SystemTable
33 SHELL_STATUS ShellStatus
;
34 CHAR16
*CompareString
;
37 ShellStatus
= SHELL_SUCCESS
;
41 // initialize the shell lib (we must be in non-auto-init...)
43 Status
= ShellInitialize();
44 ASSERT_EFI_ERROR(Status
);
46 Status
= CommandInit();
47 ASSERT_EFI_ERROR(Status
);
49 if (!gEfiShellProtocol
->BatchIsActive()) {
50 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_NO_SCRIPT
), gShellLevel1HiiHandle
, L
"Goto");
51 return (SHELL_UNSUPPORTED
);
55 // parse the command line
57 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
58 if (EFI_ERROR(Status
)) {
59 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
60 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel1HiiHandle
, ProblemParam
);
61 FreePool(ProblemParam
);
62 ShellStatus
= SHELL_INVALID_PARAMETER
;
67 if (ShellCommandLineGetRawValue(Package
, 2) != NULL
) {
68 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel1HiiHandle
);
69 ShellStatus
= SHELL_INVALID_PARAMETER
;
70 } else if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
71 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel1HiiHandle
);
72 ShellStatus
= SHELL_INVALID_PARAMETER
;
75 ASSERT((CompareString
== NULL
&& Size
== 0) || (CompareString
!= NULL
));
76 CompareString
= StrnCatGrow(&CompareString
, &Size
, L
":", 0);
77 CompareString
= StrnCatGrow(&CompareString
, &Size
, ShellCommandLineGetRawValue(Package
, 1), 0);
79 // Check forwards and then backwards for a label...
81 if (!MoveToTag(GetNextNode
, L
"endfor", L
"for", CompareString
, ShellCommandGetCurrentScriptFile(), FALSE
, FALSE
, TRUE
)) {
86 STRING_TOKEN (STR_SYNTAX_NO_MATCHING
),
87 gShellLevel1HiiHandle
,
90 ShellCommandGetCurrentScriptFile()!=NULL
91 &&ShellCommandGetCurrentScriptFile()->CurrentCommand
!=NULL
92 ?ShellCommandGetCurrentScriptFile()->CurrentCommand
->Line
:0);
93 ShellStatus
= SHELL_NOT_FOUND
;
95 FreePool(CompareString
);
97 ShellCommandLineFreeVarList (Package
);
100 return (ShellStatus
);