]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c
Comment's added and fixed.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel1CommandsLib / Goto.c
1 /** @file
2 Main file for goto shell level 1 function.
3
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
9
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.
12
13 **/
14
15 #include "UefiShellLevel1CommandsLib.h"
16
17 /**
18 Function for 'goto' command.
19
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
22 **/
23 SHELL_STATUS
24 EFIAPI
25 ShellCommandRunGoto (
26 IN EFI_HANDLE ImageHandle,
27 IN EFI_SYSTEM_TABLE *SystemTable
28 )
29 {
30 EFI_STATUS Status;
31 LIST_ENTRY *Package;
32 CHAR16 *ProblemParam;
33 SHELL_STATUS ShellStatus;
34 CHAR16 *CompareString;
35 UINTN Size;
36 SCRIPT_FILE *CurrentScriptFile;
37
38 ShellStatus = SHELL_SUCCESS;
39 CompareString = NULL;
40
41 //
42 // initialize the shell lib (we must be in non-auto-init...)
43 //
44 Status = ShellInitialize();
45 ASSERT_EFI_ERROR(Status);
46
47 Status = CommandInit();
48 ASSERT_EFI_ERROR(Status);
49
50 if (!gEfiShellProtocol->BatchIsActive()) {
51 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto");
52 return (SHELL_UNSUPPORTED);
53 }
54
55 //
56 // parse the command line
57 //
58 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
59 if (EFI_ERROR(Status)) {
60 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
61 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam);
62 FreePool(ProblemParam);
63 ShellStatus = SHELL_INVALID_PARAMETER;
64 } else {
65 ASSERT(FALSE);
66 }
67 } else {
68 if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
69 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
70 ShellStatus = SHELL_INVALID_PARAMETER;
71 } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
72 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
73 ShellStatus = SHELL_INVALID_PARAMETER;
74 } else {
75 Size = 0;
76 ASSERT((CompareString == NULL && Size == 0) || (CompareString != NULL));
77 CompareString = StrnCatGrow(&CompareString, &Size, L":", 0);
78 CompareString = StrnCatGrow(&CompareString, &Size, ShellCommandLineGetRawValue(Package, 1), 0);
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();
84 ShellPrintHiiEx(
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 ShellStatus = SHELL_NOT_FOUND;
96 }
97 FreePool(CompareString);
98 }
99 ShellCommandLineFreeVarList (Package);
100 }
101
102 return (ShellStatus);
103 }
104