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