1 | /** @file
|
---|
2 | Main file for NULL named library for level 1 shell command functions.
|
---|
3 |
|
---|
4 | (C) Copyright 2013 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
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
10 | #include "UefiShellLevel1CommandsLib.h"
|
---|
11 |
|
---|
12 | STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
|
---|
13 | EFI_HANDLE gShellLevel1HiiHandle = NULL;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | Return the help text filename. Only used if no HII information found.
|
---|
17 |
|
---|
18 | @retval the filename.
|
---|
19 | **/
|
---|
20 | CONST CHAR16*
|
---|
21 | EFIAPI
|
---|
22 | ShellCommandGetManFileNameLevel1 (
|
---|
23 | VOID
|
---|
24 | )
|
---|
25 | {
|
---|
26 | return (mFileName);
|
---|
27 | }
|
---|
28 |
|
---|
29 | /**
|
---|
30 | Constructor for the Shell Level 1 Commands library.
|
---|
31 |
|
---|
32 | Install the handlers for level 1 UEFI Shell 2.0 commands.
|
---|
33 |
|
---|
34 | @param ImageHandle the image handle of the process
|
---|
35 | @param SystemTable the EFI System Table pointer
|
---|
36 |
|
---|
37 | @retval EFI_SUCCESS the shell command handlers were installed sucessfully
|
---|
38 | @retval EFI_UNSUPPORTED the shell level required was not found.
|
---|
39 | **/
|
---|
40 | EFI_STATUS
|
---|
41 | EFIAPI
|
---|
42 | ShellLevel1CommandsLibConstructor (
|
---|
43 | IN EFI_HANDLE ImageHandle,
|
---|
44 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
45 | )
|
---|
46 | {
|
---|
47 | //
|
---|
48 | // if shell level is less than 2 do nothing
|
---|
49 | //
|
---|
50 | if (PcdGet8(PcdShellSupportLevel) < 1) {
|
---|
51 | return (EFI_SUCCESS);
|
---|
52 | }
|
---|
53 |
|
---|
54 | gShellLevel1HiiHandle = HiiAddPackages (&gShellLevel1HiiGuid, gImageHandle, UefiShellLevel1CommandsLibStrings, NULL);
|
---|
55 | if (gShellLevel1HiiHandle == NULL) {
|
---|
56 | return (EFI_DEVICE_ERROR);
|
---|
57 | }
|
---|
58 |
|
---|
59 | //
|
---|
60 | // install our shell command handlers that are always installed
|
---|
61 | //
|
---|
62 | ShellCommandRegisterCommandName(L"stall", ShellCommandRunStall , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_STALL) ));
|
---|
63 | ShellCommandRegisterCommandName(L"for", ShellCommandRunFor , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_FOR) ));
|
---|
64 | ShellCommandRegisterCommandName(L"goto", ShellCommandRunGoto , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_GOTO) ));
|
---|
65 | ShellCommandRegisterCommandName(L"if", ShellCommandRunIf , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_IF) ));
|
---|
66 | ShellCommandRegisterCommandName(L"shift", ShellCommandRunShift , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_SHIFT) ));
|
---|
67 | ShellCommandRegisterCommandName(L"exit", ShellCommandRunExit , ShellCommandGetManFileNameLevel1, 1, L"", TRUE , gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_EXIT) ));
|
---|
68 | ShellCommandRegisterCommandName(L"else", ShellCommandRunElse , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ELSE) ));
|
---|
69 | ShellCommandRegisterCommandName(L"endif", ShellCommandRunEndIf , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDIF) ));
|
---|
70 | ShellCommandRegisterCommandName(L"endfor", ShellCommandRunEndFor , ShellCommandGetManFileNameLevel1, 1, L"", FALSE, gShellLevel1HiiHandle, (EFI_STRING_ID)(PcdGet8(PcdShellSupportLevel) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDFOR)));
|
---|
71 |
|
---|
72 | return (EFI_SUCCESS);
|
---|
73 | }
|
---|
74 |
|
---|
75 | /**
|
---|
76 | Destructor for the library. free any resources.
|
---|
77 |
|
---|
78 | @param ImageHandle The image handle of the process.
|
---|
79 | @param SystemTable The EFI System Table pointer.
|
---|
80 | **/
|
---|
81 | EFI_STATUS
|
---|
82 | EFIAPI
|
---|
83 | ShellLevel1CommandsLibDestructor (
|
---|
84 | IN EFI_HANDLE ImageHandle,
|
---|
85 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
86 | )
|
---|
87 | {
|
---|
88 | if (gShellLevel1HiiHandle != NULL) {
|
---|
89 | HiiRemovePackages(gShellLevel1HiiHandle);
|
---|
90 | }
|
---|
91 | return (EFI_SUCCESS);
|
---|
92 | }
|
---|
93 |
|
---|
94 | /**
|
---|
95 | Test a node to see if meets the criterion.
|
---|
96 |
|
---|
97 | It functions so that count starts at 1 and it increases or decreases when it
|
---|
98 | hits the specified tags. when it hits zero the location has been found.
|
---|
99 |
|
---|
100 | DecrementerTag and IncrementerTag are used to get around for/endfor and
|
---|
101 | similar paired types where the entire middle should be ignored.
|
---|
102 |
|
---|
103 | If label is used it will be used instead of the count.
|
---|
104 |
|
---|
105 | @param[in] Function The function to use to enumerate through the
|
---|
106 | list. Normally GetNextNode or GetPreviousNode.
|
---|
107 | @param[in] DecrementerTag The tag to decrement the count at.
|
---|
108 | @param[in] IncrementerTag The tag to increment the count at.
|
---|
109 | @param[in] Label A label to look for.
|
---|
110 | @param[in, out] ScriptFile The pointer to the current script file structure.
|
---|
111 | @param[in] MovePast TRUE makes function return 1 past the found
|
---|
112 | location.
|
---|
113 | @param[in] FindOnly TRUE to not change the ScriptFile.
|
---|
114 | @param[in] CommandNode The pointer to the Node to test.
|
---|
115 | @param[in, out] TargetCount The pointer to the current count.
|
---|
116 | **/
|
---|
117 | BOOLEAN
|
---|
118 | TestNodeForMove (
|
---|
119 | IN CONST LIST_MANIP_FUNC Function,
|
---|
120 | IN CONST CHAR16 *DecrementerTag,
|
---|
121 | IN CONST CHAR16 *IncrementerTag,
|
---|
122 | IN CONST CHAR16 *Label OPTIONAL,
|
---|
123 | IN OUT SCRIPT_FILE *ScriptFile,
|
---|
124 | IN CONST BOOLEAN MovePast,
|
---|
125 | IN CONST BOOLEAN FindOnly,
|
---|
126 | IN CONST SCRIPT_COMMAND_LIST *CommandNode,
|
---|
127 | IN OUT UINTN *TargetCount
|
---|
128 | )
|
---|
129 | {
|
---|
130 | BOOLEAN Found;
|
---|
131 | CHAR16 *CommandName;
|
---|
132 | CHAR16 *CommandNameWalker;
|
---|
133 | CHAR16 *TempLocation;
|
---|
134 |
|
---|
135 | Found = FALSE;
|
---|
136 |
|
---|
137 | //
|
---|
138 | // get just the first part of the command line...
|
---|
139 | //
|
---|
140 | CommandName = NULL;
|
---|
141 | CommandName = StrnCatGrow(&CommandName, NULL, CommandNode->Cl, 0);
|
---|
142 | if (CommandName == NULL) {
|
---|
143 | return (FALSE);
|
---|
144 | }
|
---|
145 |
|
---|
146 | CommandNameWalker = CommandName;
|
---|
147 |
|
---|
148 | //
|
---|
149 | // Skip leading spaces and tabs.
|
---|
150 | //
|
---|
151 | while ((CommandNameWalker[0] == L' ') || (CommandNameWalker[0] == L'\t')) {
|
---|
152 | CommandNameWalker++;
|
---|
153 | }
|
---|
154 | TempLocation = StrStr(CommandNameWalker, L" ");
|
---|
155 |
|
---|
156 | if (TempLocation != NULL) {
|
---|
157 | *TempLocation = CHAR_NULL;
|
---|
158 | }
|
---|
159 |
|
---|
160 | //
|
---|
161 | // did we find a nested item ?
|
---|
162 | //
|
---|
163 | if (gUnicodeCollation->StriColl(
|
---|
164 | gUnicodeCollation,
|
---|
165 | (CHAR16*)CommandNameWalker,
|
---|
166 | (CHAR16*)IncrementerTag) == 0) {
|
---|
167 | (*TargetCount)++;
|
---|
168 | } else if (gUnicodeCollation->StriColl(
|
---|
169 | gUnicodeCollation,
|
---|
170 | (CHAR16*)CommandNameWalker,
|
---|
171 | (CHAR16*)DecrementerTag) == 0) {
|
---|
172 | if (*TargetCount > 0) {
|
---|
173 | (*TargetCount)--;
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | //
|
---|
178 | // did we find the matching one...
|
---|
179 | //
|
---|
180 | if (Label == NULL) {
|
---|
181 | if (*TargetCount == 0) {
|
---|
182 | Found = TRUE;
|
---|
183 | if (!FindOnly) {
|
---|
184 | if (MovePast) {
|
---|
185 | ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
|
---|
186 | } else {
|
---|
187 | ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
|
---|
188 | }
|
---|
189 | }
|
---|
190 | }
|
---|
191 | } else {
|
---|
192 | if (gUnicodeCollation->StriColl(
|
---|
193 | gUnicodeCollation,
|
---|
194 | (CHAR16*)CommandNameWalker,
|
---|
195 | (CHAR16*)Label) == 0
|
---|
196 | && (*TargetCount) == 0) {
|
---|
197 | Found = TRUE;
|
---|
198 | if (!FindOnly) {
|
---|
199 | //
|
---|
200 | // we found the target label without loops
|
---|
201 | //
|
---|
202 | if (MovePast) {
|
---|
203 | ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
|
---|
204 | } else {
|
---|
205 | ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
|
---|
206 | }
|
---|
207 | }
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | //
|
---|
212 | // Free the memory for this loop...
|
---|
213 | //
|
---|
214 | FreePool(CommandName);
|
---|
215 | return (Found);
|
---|
216 | }
|
---|
217 |
|
---|
218 | /**
|
---|
219 | Move the script pointer from 1 tag (line) to another.
|
---|
220 |
|
---|
221 | It functions so that count starts at 1 and it increases or decreases when it
|
---|
222 | hits the specified tags. when it hits zero the location has been found.
|
---|
223 |
|
---|
224 | DecrementerTag and IncrementerTag are used to get around for/endfor and
|
---|
225 | similar paired types where the entire middle should be ignored.
|
---|
226 |
|
---|
227 | If label is used it will be used instead of the count.
|
---|
228 |
|
---|
229 | @param[in] Function The function to use to enumerate through the
|
---|
230 | list. Normally GetNextNode or GetPreviousNode.
|
---|
231 | @param[in] DecrementerTag The tag to decrement the count at.
|
---|
232 | @param[in] IncrementerTag The tag to increment the count at.
|
---|
233 | @param[in] Label A label to look for.
|
---|
234 | @param[in, out] ScriptFile The pointer to the current script file structure.
|
---|
235 | @param[in] MovePast TRUE makes function return 1 past the found
|
---|
236 | location.
|
---|
237 | @param[in] FindOnly TRUE to not change the ScriptFile.
|
---|
238 | @param[in] WrapAroundScript TRUE to wrap end-to-begining or vise versa in
|
---|
239 | searching.
|
---|
240 | **/
|
---|
241 | BOOLEAN
|
---|
242 | MoveToTag (
|
---|
243 | IN CONST LIST_MANIP_FUNC Function,
|
---|
244 | IN CONST CHAR16 *DecrementerTag,
|
---|
245 | IN CONST CHAR16 *IncrementerTag,
|
---|
246 | IN CONST CHAR16 *Label OPTIONAL,
|
---|
247 | IN OUT SCRIPT_FILE *ScriptFile,
|
---|
248 | IN CONST BOOLEAN MovePast,
|
---|
249 | IN CONST BOOLEAN FindOnly,
|
---|
250 | IN CONST BOOLEAN WrapAroundScript
|
---|
251 | )
|
---|
252 | {
|
---|
253 | SCRIPT_COMMAND_LIST *CommandNode;
|
---|
254 | BOOLEAN Found;
|
---|
255 | UINTN TargetCount;
|
---|
256 |
|
---|
257 | if (Label == NULL) {
|
---|
258 | TargetCount = 1;
|
---|
259 | } else {
|
---|
260 | TargetCount = 0;
|
---|
261 | }
|
---|
262 |
|
---|
263 | if (ScriptFile == NULL) {
|
---|
264 | return FALSE;
|
---|
265 | }
|
---|
266 |
|
---|
267 | for (CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &ScriptFile->CurrentCommand->Link), Found = FALSE
|
---|
268 | ; !IsNull(&ScriptFile->CommandList, &CommandNode->Link)&& !Found
|
---|
269 | ; CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link)
|
---|
270 | ){
|
---|
271 | Found = TestNodeForMove(
|
---|
272 | Function,
|
---|
273 | DecrementerTag,
|
---|
274 | IncrementerTag,
|
---|
275 | Label,
|
---|
276 | ScriptFile,
|
---|
277 | MovePast,
|
---|
278 | FindOnly,
|
---|
279 | CommandNode,
|
---|
280 | &TargetCount);
|
---|
281 | }
|
---|
282 |
|
---|
283 | if (WrapAroundScript && !Found) {
|
---|
284 | for (CommandNode = (SCRIPT_COMMAND_LIST *)GetFirstNode(&ScriptFile->CommandList), Found = FALSE
|
---|
285 | ; CommandNode != ScriptFile->CurrentCommand && !Found
|
---|
286 | ; CommandNode = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link)
|
---|
287 | ){
|
---|
288 | Found = TestNodeForMove(
|
---|
289 | Function,
|
---|
290 | DecrementerTag,
|
---|
291 | IncrementerTag,
|
---|
292 | Label,
|
---|
293 | ScriptFile,
|
---|
294 | MovePast,
|
---|
295 | FindOnly,
|
---|
296 | CommandNode,
|
---|
297 | &TargetCount);
|
---|
298 | }
|
---|
299 | }
|
---|
300 | return (Found);
|
---|
301 | }
|
---|
302 |
|
---|