]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLevel1CommandsLib/Goto.c
ShellParametersProtocol - remove parsing from within quoted parameters.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel1CommandsLib / Goto.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for goto shell level 1 function.\r
3\r
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UefiShellLevel1CommandsLib.h"\r
16\r
17/**\r
18 Function for 'goto' command.\r
19\r
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
22**/\r
23SHELL_STATUS\r
24EFIAPI\r
25ShellCommandRunGoto (\r
26 IN EFI_HANDLE ImageHandle,\r
27 IN EFI_SYSTEM_TABLE *SystemTable\r
28 )\r
29{\r
30 EFI_STATUS Status;\r
31 LIST_ENTRY *Package;\r
32 CHAR16 *ProblemParam;\r
33 SHELL_STATUS ShellStatus;\r
34 CHAR16 *CompareString;\r
35 UINTN Size;\r
ae724571 36 SCRIPT_FILE *CurrentScriptFile;\r
a405b86d 37\r
38 ShellStatus = SHELL_SUCCESS;\r
39 CompareString = NULL;\r
40\r
41 //\r
42 // initialize the shell lib (we must be in non-auto-init...)\r
43 //\r
44 Status = ShellInitialize();\r
45 ASSERT_EFI_ERROR(Status);\r
46\r
47 Status = CommandInit();\r
48 ASSERT_EFI_ERROR(Status);\r
49\r
50 if (!gEfiShellProtocol->BatchIsActive()) {\r
51 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto");\r
52 return (SHELL_UNSUPPORTED);\r
53 }\r
54\r
55 //\r
56 // parse the command line\r
57 //\r
58 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r
59 if (EFI_ERROR(Status)) {\r
60 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
61 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam);\r
62 FreePool(ProblemParam);\r
63 ShellStatus = SHELL_INVALID_PARAMETER;\r
64 } else {\r
65 ASSERT(FALSE);\r
66 }\r
67 } else {\r
68 if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r
69 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);\r
70 ShellStatus = SHELL_INVALID_PARAMETER;\r
71 } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {\r
72 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);\r
73 ShellStatus = SHELL_INVALID_PARAMETER;\r
74 } else {\r
75 Size = 0;\r
76 ASSERT((CompareString == NULL && Size == 0) || (CompareString != NULL));\r
77 CompareString = StrnCatGrow(&CompareString, &Size, L":", 0);\r
78 CompareString = StrnCatGrow(&CompareString, &Size, ShellCommandLineGetRawValue(Package, 1), 0);\r
79 //\r
80 // Check forwards and then backwards for a label...\r
81 //\r
82 if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) {\r
ae724571 83 CurrentScriptFile = ShellCommandGetCurrentScriptFile();\r
33c031ee 84 ShellPrintHiiEx(\r
85 -1, \r
86 -1, \r
87 NULL, \r
88 STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r
89 gShellLevel1HiiHandle, \r
90 CompareString, \r
91 L"Goto", \r
ae724571 92 CurrentScriptFile!=NULL \r
93 && CurrentScriptFile->CurrentCommand!=NULL\r
94 ? CurrentScriptFile->CurrentCommand->Line:0);\r
a405b86d 95 ShellStatus = SHELL_NOT_FOUND;\r
96 }\r
97 FreePool(CompareString);\r
98 }\r
99 ShellCommandLineFreeVarList (Package);\r
100 }\r
101\r
102 return (ShellStatus);\r
103}\r
104\r