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