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