]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Main file for endfor and for shell level 1 functions.\r | |
3 | \r | |
0861edab | 4 | Copyright (c) 2015, Hewlett-Packard Development Company, L.P.<BR>\r |
81cd2f53 | 5 | Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r |
a405b86d | 6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "UefiShellLevel1CommandsLib.h"\r | |
17 | #include <Library/PrintLib.h>\r | |
18 | \r | |
77dcec12 | 19 | /**\r |
20 | Determine if a valid string is a valid number for the 'for' command.\r | |
21 | \r | |
22 | @param[in] Number The pointer to the string representation of the number to test.\r | |
23 | \r | |
24 | @retval TRUE The number is valid.\r | |
25 | @retval FALSE The number is not valid.\r | |
26 | **/\r | |
a405b86d | 27 | BOOLEAN\r |
28 | EFIAPI\r | |
29 | ShellIsValidForNumber (\r | |
30 | IN CONST CHAR16 *Number\r | |
31 | )\r | |
32 | {\r | |
33 | if (Number == NULL || *Number == CHAR_NULL) {\r | |
34 | return (FALSE);\r | |
35 | }\r | |
36 | \r | |
37 | if (*Number == L'-') {\r | |
38 | Number++;\r | |
39 | }\r | |
40 | \r | |
41 | if (StrLen(Number) == 0) {\r | |
42 | return (FALSE);\r | |
43 | }\r | |
44 | \r | |
45 | if (StrLen(Number) >= 7) {\r | |
2d3759d8 | 46 | if ((StrStr(Number, L" ") == NULL) || (((StrStr(Number, L" ") != NULL) && (StrStr(Number, L" ") - Number) >= 7))) {\r |
a405b86d | 47 | return (FALSE);\r |
48 | }\r | |
49 | }\r | |
50 | \r | |
51 | if (!ShellIsDecimalDigitCharacter(*Number)) {\r | |
52 | return (FALSE);\r | |
53 | }\r | |
54 | \r | |
55 | return (TRUE);\r | |
56 | }\r | |
57 | \r | |
58 | /**\r | |
59 | Function for 'endfor' command.\r | |
60 | \r | |
61 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
62 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
63 | **/\r | |
64 | SHELL_STATUS\r | |
65 | EFIAPI\r | |
66 | ShellCommandRunEndFor (\r | |
67 | IN EFI_HANDLE ImageHandle,\r | |
68 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
69 | )\r | |
70 | {\r | |
71 | EFI_STATUS Status;\r | |
72 | BOOLEAN Found;\r | |
ae724571 | 73 | SCRIPT_FILE *CurrentScriptFile;\r |
a405b86d | 74 | \r |
75 | Status = CommandInit();\r | |
76 | ASSERT_EFI_ERROR(Status);\r | |
77 | \r | |
78 | if (!gEfiShellProtocol->BatchIsActive()) {\r | |
0861edab | 79 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"endfor");\r |
a405b86d | 80 | return (SHELL_UNSUPPORTED);\r |
81 | }\r | |
82 | \r | |
83 | if (gEfiShellParametersProtocol->Argc > 1) {\r | |
0861edab | 84 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"endfor");\r |
a405b86d | 85 | return (SHELL_INVALID_PARAMETER);\r |
86 | }\r | |
87 | \r | |
88 | Found = MoveToTag(GetPreviousNode, L"for", L"endfor", NULL, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, FALSE);\r | |
89 | \r | |
90 | if (!Found) {\r | |
ae724571 | 91 | CurrentScriptFile = ShellCommandGetCurrentScriptFile();\r |
33c031ee | 92 | ShellPrintHiiEx(\r |
93 | -1, \r | |
94 | -1, \r | |
95 | NULL, \r | |
96 | STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r | |
97 | gShellLevel1HiiHandle, \r | |
98 | L"For", \r | |
99 | L"EndFor", \r | |
ae724571 | 100 | CurrentScriptFile!=NULL\r |
101 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
102 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 103 | return (SHELL_NOT_FOUND);\r |
104 | }\r | |
105 | return (SHELL_SUCCESS);\r | |
106 | }\r | |
107 | \r | |
108 | typedef struct {\r | |
109 | UINT32 Signature;\r | |
110 | INTN Current;\r | |
111 | INTN End;\r | |
112 | INTN Step;\r | |
113 | CHAR16 *ReplacementName;\r | |
114 | CHAR16 *CurrentValue;\r | |
115 | BOOLEAN RemoveSubstAlias;\r | |
116 | CHAR16 Set[1];\r | |
117 | } SHELL_FOR_INFO;\r | |
118 | #define SIZE_OF_SHELL_FOR_INFO OFFSET_OF (SHELL_FOR_INFO, Set)\r | |
119 | #define SHELL_FOR_INFO_SIGNATURE SIGNATURE_32 ('S', 'F', 'I', 's')\r | |
120 | \r | |
121 | /**\r | |
122 | Update the value of a given alias on the list. If the alias is not there then add it.\r | |
123 | \r | |
4ff7e37b ED |
124 | @param[in] Alias The alias to test for.\r |
125 | @param[in] CommandString The updated command string.\r | |
126 | @param[in, out] List The list to search.\r | |
9ea69f8a | 127 | \r |
128 | @retval EFI_SUCCESS The operation was completed successfully.\r | |
129 | @retval EFI_OUT_OF_RESOURCES There was not enough free memory.\r | |
a405b86d | 130 | **/\r |
9ea69f8a | 131 | EFI_STATUS\r |
a405b86d | 132 | EFIAPI\r |
133 | InternalUpdateAliasOnList(\r | |
134 | IN CONST CHAR16 *Alias,\r | |
135 | IN CONST CHAR16 *CommandString,\r | |
136 | IN OUT LIST_ENTRY *List\r | |
137 | )\r | |
138 | {\r | |
139 | ALIAS_LIST *Node;\r | |
140 | BOOLEAN Found;\r | |
141 | \r | |
142 | //\r | |
143 | // assert for NULL parameter\r | |
144 | //\r | |
145 | ASSERT(Alias != NULL);\r | |
146 | \r | |
147 | //\r | |
148 | // check for the Alias\r | |
149 | //\r | |
150 | for ( Node = (ALIAS_LIST *)GetFirstNode(List), Found = FALSE\r | |
151 | ; !IsNull(List, &Node->Link)\r | |
152 | ; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)\r | |
153 | ){\r | |
154 | ASSERT(Node->CommandString != NULL);\r | |
155 | ASSERT(Node->Alias != NULL);\r | |
156 | if (StrCmp(Node->Alias, Alias)==0) {\r | |
157 | FreePool(Node->CommandString);\r | |
158 | Node->CommandString = NULL;\r | |
159 | Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);\r | |
160 | Found = TRUE;\r | |
161 | break;\r | |
162 | }\r | |
163 | }\r | |
164 | if (!Found) {\r | |
165 | Node = AllocateZeroPool(sizeof(ALIAS_LIST));\r | |
9ea69f8a | 166 | if (Node == NULL) {\r |
167 | return (EFI_OUT_OF_RESOURCES);\r | |
168 | }\r | |
a405b86d | 169 | ASSERT(Node->Alias == NULL);\r |
170 | Node->Alias = StrnCatGrow(&Node->Alias, NULL, Alias, 0);\r | |
171 | ASSERT(Node->CommandString == NULL);\r | |
172 | Node->CommandString = StrnCatGrow(&Node->CommandString, NULL, CommandString, 0);\r | |
173 | InsertTailList(List, &Node->Link);\r | |
174 | }\r | |
9ea69f8a | 175 | return (EFI_SUCCESS);\r |
a405b86d | 176 | }\r |
177 | \r | |
178 | /**\r | |
179 | Find out if an alias is on the given list.\r | |
180 | \r | |
181 | @param[in] Alias The alias to test for.\r | |
182 | @param[in] List The list to search.\r | |
183 | \r | |
184 | @retval TRUE The alias is on the list.\r | |
185 | @retval FALSE The alias is not on the list.\r | |
186 | **/\r | |
187 | BOOLEAN\r | |
188 | EFIAPI\r | |
189 | InternalIsAliasOnList(\r | |
190 | IN CONST CHAR16 *Alias,\r | |
191 | IN CONST LIST_ENTRY *List\r | |
192 | )\r | |
193 | {\r | |
194 | ALIAS_LIST *Node;\r | |
195 | \r | |
196 | //\r | |
197 | // assert for NULL parameter\r | |
198 | //\r | |
199 | ASSERT(Alias != NULL);\r | |
200 | \r | |
201 | //\r | |
202 | // check for the Alias\r | |
203 | //\r | |
204 | for ( Node = (ALIAS_LIST *)GetFirstNode(List)\r | |
205 | ; !IsNull(List, &Node->Link)\r | |
206 | ; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)\r | |
207 | ){\r | |
208 | ASSERT(Node->CommandString != NULL);\r | |
209 | ASSERT(Node->Alias != NULL);\r | |
210 | if (StrCmp(Node->Alias, Alias)==0) {\r | |
211 | return (TRUE);\r | |
212 | }\r | |
213 | }\r | |
214 | return (FALSE);\r | |
215 | }\r | |
216 | \r | |
217 | /**\r | |
218 | Remove an alias from the given list.\r | |
219 | \r | |
4ff7e37b ED |
220 | @param[in] Alias The alias to remove.\r |
221 | @param[in, out] List The list to search.\r | |
a405b86d | 222 | **/\r |
223 | BOOLEAN\r | |
224 | EFIAPI\r | |
225 | InternalRemoveAliasFromList(\r | |
226 | IN CONST CHAR16 *Alias,\r | |
227 | IN OUT LIST_ENTRY *List\r | |
228 | )\r | |
229 | {\r | |
230 | ALIAS_LIST *Node;\r | |
231 | \r | |
232 | //\r | |
233 | // assert for NULL parameter\r | |
234 | //\r | |
235 | ASSERT(Alias != NULL);\r | |
236 | \r | |
237 | //\r | |
238 | // check for the Alias\r | |
239 | //\r | |
240 | for ( Node = (ALIAS_LIST *)GetFirstNode(List)\r | |
241 | ; !IsNull(List, &Node->Link)\r | |
242 | ; Node = (ALIAS_LIST *)GetNextNode(List, &Node->Link)\r | |
243 | ){\r | |
244 | ASSERT(Node->CommandString != NULL);\r | |
245 | ASSERT(Node->Alias != NULL);\r | |
246 | if (StrCmp(Node->Alias, Alias)==0) {\r | |
247 | RemoveEntryList(&Node->Link);\r | |
248 | FreePool(Node->Alias);\r | |
249 | FreePool(Node->CommandString);\r | |
250 | FreePool(Node);\r | |
251 | return (TRUE);\r | |
252 | }\r | |
253 | }\r | |
254 | return (FALSE);\r | |
255 | }\r | |
256 | \r | |
e82edcf9 JC |
257 | /**\r |
258 | Function to determine whether a string is decimal or hex representation of a number\r | |
259 | and return the number converted from the string.\r | |
260 | \r | |
261 | @param[in] String String representation of a number\r | |
262 | \r | |
263 | @return the number\r | |
264 | @retval (UINTN)(-1) An error ocurred.\r | |
265 | **/\r | |
266 | UINTN\r | |
267 | EFIAPI\r | |
268 | ReturnUintn(\r | |
269 | IN CONST CHAR16 *String\r | |
270 | )\r | |
271 | {\r | |
272 | UINT64 RetVal;\r | |
273 | \r | |
c8186395 | 274 | if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, FALSE, TRUE))) {\r |
e82edcf9 JC |
275 | return ((UINTN)RetVal);\r |
276 | }\r | |
277 | return ((UINTN)(-1));\r | |
278 | }\r | |
279 | \r | |
a405b86d | 280 | /**\r |
281 | Function for 'for' command.\r | |
282 | \r | |
283 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
284 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
285 | **/\r | |
286 | SHELL_STATUS\r | |
287 | EFIAPI\r | |
288 | ShellCommandRunFor (\r | |
289 | IN EFI_HANDLE ImageHandle,\r | |
290 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
291 | )\r | |
292 | {\r | |
293 | EFI_STATUS Status;\r | |
294 | SHELL_STATUS ShellStatus;\r | |
295 | SCRIPT_FILE *CurrentScriptFile;\r | |
296 | CHAR16 *ArgSet;\r | |
297 | CHAR16 *ArgSetWalker;\r | |
3a3395f0 | 298 | CHAR16 *Parameter;\r |
a405b86d | 299 | UINTN ArgSize;\r |
300 | UINTN LoopVar;\r | |
301 | SHELL_FOR_INFO *Info;\r | |
302 | CHAR16 *TempString;\r | |
303 | CHAR16 *TempSpot;\r | |
304 | BOOLEAN FirstPass;\r | |
305 | EFI_SHELL_FILE_INFO *Node;\r | |
306 | EFI_SHELL_FILE_INFO *FileList;\r | |
307 | UINTN NewSize;\r | |
308 | \r | |
309 | ArgSet = NULL;\r | |
310 | ArgSize = 0;\r | |
311 | ShellStatus = SHELL_SUCCESS;\r | |
312 | ArgSetWalker = NULL;\r | |
313 | TempString = NULL;\r | |
3a3395f0 | 314 | Parameter = NULL;\r |
a405b86d | 315 | FirstPass = FALSE;\r |
316 | \r | |
317 | //\r | |
318 | // initialize the shell lib (we must be in non-auto-init...)\r | |
319 | //\r | |
320 | Status = ShellInitialize();\r | |
321 | ASSERT_EFI_ERROR(Status);\r | |
322 | \r | |
323 | Status = CommandInit();\r | |
324 | ASSERT_EFI_ERROR(Status);\r | |
325 | \r | |
326 | if (!gEfiShellProtocol->BatchIsActive()) {\r | |
0861edab | 327 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"for");\r |
a405b86d | 328 | return (SHELL_UNSUPPORTED);\r |
329 | }\r | |
330 | \r | |
331 | if (gEfiShellParametersProtocol->Argc < 4) {\r | |
0861edab | 332 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"for");\r |
a405b86d | 333 | return (SHELL_INVALID_PARAMETER);\r |
334 | }\r | |
335 | \r | |
336 | CurrentScriptFile = ShellCommandGetCurrentScriptFile();\r | |
337 | ASSERT(CurrentScriptFile != NULL);\r | |
338 | \r | |
81cd2f53 | 339 | if ((CurrentScriptFile->CurrentCommand != NULL) && (CurrentScriptFile->CurrentCommand->Data == NULL)) {\r |
a405b86d | 340 | FirstPass = TRUE;\r |
341 | \r | |
342 | //\r | |
343 | // Make sure that an End exists.\r | |
344 | //\r | |
345 | if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) {\r | |
33c031ee | 346 | ShellPrintHiiEx(\r |
347 | -1, \r | |
348 | -1, \r | |
349 | NULL, \r | |
350 | STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r | |
351 | gShellLevel1HiiHandle, \r | |
352 | L"EndFor", \r | |
353 | L"For", \r | |
81cd2f53 | 354 | CurrentScriptFile->CurrentCommand->Line);\r |
a405b86d | 355 | return (SHELL_DEVICE_ERROR);\r |
356 | }\r | |
357 | \r | |
358 | //\r | |
359 | // Process the line.\r | |
360 | //\r | |
361 | if (gEfiShellParametersProtocol->Argv[1][0] != L'%' || gEfiShellParametersProtocol->Argv[1][2] != CHAR_NULL\r | |
362 | ||!((gEfiShellParametersProtocol->Argv[1][1] >= L'a' && gEfiShellParametersProtocol->Argv[1][1] <= L'z')\r | |
363 | ||(gEfiShellParametersProtocol->Argv[1][1] >= L'A' && gEfiShellParametersProtocol->Argv[1][1] <= L'Z'))\r | |
364 | ) {\r | |
77dcec12 | 365 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_VAR), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[1]);\r |
a405b86d | 366 | return (SHELL_INVALID_PARAMETER);\r |
367 | }\r | |
368 | \r | |
369 | if (gUnicodeCollation->StriColl(\r | |
370 | gUnicodeCollation,\r | |
371 | L"in",\r | |
372 | gEfiShellParametersProtocol->Argv[2]) == 0) {\r | |
373 | for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r | |
374 | ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));\r | |
a405b86d | 375 | if (StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"*") != NULL\r |
376 | ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"?") != NULL\r | |
377 | ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"[") != NULL\r | |
378 | ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"]") != NULL) {\r | |
379 | FileList = NULL;\r | |
380 | Status = ShellOpenFileMetaArg ((CHAR16*)gEfiShellParametersProtocol->Argv[LoopVar], EFI_FILE_MODE_READ, &FileList);\r | |
381 | if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {\r | |
5b056113 | 382 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);\r |
a405b86d | 383 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);\r |
5b056113 | 384 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);\r |
a405b86d | 385 | } else {\r |
386 | for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)\r | |
387 | ; !IsNull(&FileList->Link, &Node->Link)\r | |
388 | ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)\r | |
389 | ){\r | |
390 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);\r | |
391 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Node->FullName, 0);\r | |
392 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);\r | |
393 | }\r | |
394 | ShellCloseFileMetaArg(&FileList);\r | |
395 | }\r | |
396 | } else {\r | |
3a3395f0 QS |
397 | Parameter = gEfiShellParametersProtocol->Argv[LoopVar];\r |
398 | if (Parameter[0] == L'\"' && Parameter[StrLen(Parameter)-1] == L'\"') {\r | |
399 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);\r | |
400 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Parameter, 0);\r | |
401 | } else {\r | |
402 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);\r | |
403 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Parameter, 0);\r | |
404 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);\r | |
405 | }\r | |
a405b86d | 406 | }\r |
a405b86d | 407 | }\r |
532691c8 | 408 | if (ArgSet == NULL) {\r |
409 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
a405b86d | 410 | } else {\r |
532691c8 | 411 | //\r |
412 | // set up for an 'in' for loop\r | |
413 | //\r | |
414 | NewSize = StrSize(ArgSet);\r | |
415 | NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);\r | |
416 | Info = AllocateZeroPool(NewSize);\r | |
417 | ASSERT(Info != NULL);\r | |
418 | Info->Signature = SHELL_FOR_INFO_SIGNATURE;\r | |
419 | CopyMem(Info->Set, ArgSet, StrSize(ArgSet));\r | |
420 | NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);\r | |
421 | CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);\r | |
422 | Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);\r | |
423 | Info->CurrentValue = (CHAR16*)Info->Set;\r | |
424 | Info->Step = 0;\r | |
425 | Info->Current = 0;\r | |
426 | Info->End = 0;\r | |
427 | \r | |
428 | if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {\r | |
429 | Info->RemoveSubstAlias = FALSE;\r | |
430 | } else {\r | |
431 | Info->RemoveSubstAlias = TRUE;\r | |
432 | }\r | |
433 | CurrentScriptFile->CurrentCommand->Data = Info;\r | |
a405b86d | 434 | }\r |
a405b86d | 435 | } else if (gUnicodeCollation->StriColl(\r |
436 | gUnicodeCollation,\r | |
437 | L"run",\r | |
438 | gEfiShellParametersProtocol->Argv[2]) == 0) {\r | |
439 | for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r | |
440 | ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));\r | |
441 | if (ArgSet == NULL) {\r | |
442 | // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);\r | |
443 | } else {\r | |
77dcec12 | 444 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);\r |
a405b86d | 445 | }\r |
446 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);\r | |
447 | // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);\r | |
448 | }\r | |
532691c8 | 449 | if (ArgSet == NULL) {\r |
450 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
a405b86d | 451 | } else {\r |
532691c8 | 452 | //\r |
453 | // set up for a 'run' for loop\r | |
454 | //\r | |
455 | Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));\r | |
456 | ASSERT(Info != NULL);\r | |
b471606b | 457 | Info->Signature = SHELL_FOR_INFO_SIGNATURE;\r |
532691c8 | 458 | CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));\r |
459 | Info->ReplacementName = Info->Set;\r | |
460 | Info->CurrentValue = NULL;\r | |
461 | ArgSetWalker = ArgSet;\r | |
462 | if (ArgSetWalker[0] != L'(') {\r | |
ae724571 | 463 | ShellPrintHiiEx(\r |
464 | -1, \r | |
465 | -1, \r | |
466 | NULL, \r | |
467 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
468 | gShellLevel1HiiHandle, \r | |
532691c8 | 469 | ArgSet, \r |
81cd2f53 | 470 | CurrentScriptFile->CurrentCommand->Line);\r |
a405b86d | 471 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
472 | } else {\r | |
532691c8 | 473 | TempSpot = StrStr(ArgSetWalker, L")");\r |
474 | if (TempSpot != NULL) {\r | |
475 | TempString = TempSpot+1;\r | |
476 | if (*(TempString) != CHAR_NULL) {\r | |
477 | while(TempString != NULL && *TempString == L' ') {\r | |
478 | TempString++;\r | |
479 | }\r | |
480 | if (StrLen(TempString) > 0) {\r | |
481 | TempSpot = NULL;\r | |
482 | }\r | |
483 | }\r | |
a405b86d | 484 | }\r |
532691c8 | 485 | if (TempSpot == NULL) {\r |
ae724571 | 486 | ShellPrintHiiEx(\r |
487 | -1, \r | |
488 | -1, \r | |
489 | NULL, \r | |
490 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
491 | gShellLevel1HiiHandle, \r | |
81cd2f53 | 492 | CurrentScriptFile->CurrentCommand->Line);\r |
a405b86d | 493 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
494 | } else {\r | |
532691c8 | 495 | *TempSpot = CHAR_NULL;\r |
496 | ArgSetWalker++;\r | |
a405b86d | 497 | while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r |
498 | ArgSetWalker++;\r | |
499 | }\r | |
532691c8 | 500 | if (!ShellIsValidForNumber(ArgSetWalker)) {\r |
ae724571 | 501 | ShellPrintHiiEx(\r |
502 | -1, \r | |
503 | -1, \r | |
504 | NULL, \r | |
505 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
506 | gShellLevel1HiiHandle, \r | |
507 | ArgSet, \r | |
81cd2f53 | 508 | CurrentScriptFile->CurrentCommand->Line);\r |
77dcec12 | 509 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
510 | } else {\r | |
511 | if (ArgSetWalker[0] == L'-') {\r | |
e82edcf9 | 512 | Info->Current = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r |
77dcec12 | 513 | } else {\r |
e82edcf9 | 514 | Info->Current = (INTN)ReturnUintn(ArgSetWalker);\r |
77dcec12 | 515 | }\r |
77dcec12 | 516 | ArgSetWalker = StrStr(ArgSetWalker, L" ");\r |
517 | while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r | |
518 | ArgSetWalker++;\r | |
519 | }\r | |
532691c8 | 520 | if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){\r |
521 | ShellPrintHiiEx(\r | |
522 | -1, \r | |
523 | -1, \r | |
524 | NULL, \r | |
525 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
526 | gShellLevel1HiiHandle, \r | |
527 | ArgSet, \r | |
81cd2f53 | 528 | CurrentScriptFile->CurrentCommand->Line);\r |
532691c8 | 529 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
530 | } else {\r | |
531 | if (ArgSetWalker[0] == L'-') {\r | |
e82edcf9 | 532 | Info->End = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r |
a405b86d | 533 | } else {\r |
e82edcf9 | 534 | Info->End = (INTN)ReturnUintn(ArgSetWalker);\r |
532691c8 | 535 | }\r |
536 | if (Info->Current < Info->End) {\r | |
537 | Info->Step = 1;\r | |
538 | } else {\r | |
539 | Info->Step = -1;\r | |
540 | }\r | |
541 | \r | |
542 | ArgSetWalker = StrStr(ArgSetWalker, L" ");\r | |
543 | while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r | |
544 | ArgSetWalker++;\r | |
545 | }\r | |
546 | if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) {\r | |
547 | if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){\r | |
548 | ShellPrintHiiEx(\r | |
549 | -1, \r | |
550 | -1, \r | |
551 | NULL, \r | |
552 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
553 | gShellLevel1HiiHandle, \r | |
554 | ArgSet, \r | |
81cd2f53 | 555 | CurrentScriptFile->CurrentCommand->Line);\r |
532691c8 | 556 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
a405b86d | 557 | } else {\r |
532691c8 | 558 | if (*ArgSetWalker == L')') {\r |
559 | ASSERT(Info->Step == 1 || Info->Step == -1);\r | |
a405b86d | 560 | } else {\r |
532691c8 | 561 | if (ArgSetWalker[0] == L'-') {\r |
e82edcf9 | 562 | Info->Step = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r |
532691c8 | 563 | } else {\r |
e82edcf9 | 564 | Info->Step = (INTN)ReturnUintn(ArgSetWalker);\r |
532691c8 | 565 | }\r |
566 | \r | |
567 | if (StrStr(ArgSetWalker, L" ") != NULL) {\r | |
568 | ShellPrintHiiEx(\r | |
569 | -1, \r | |
570 | -1, \r | |
571 | NULL, \r | |
572 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
573 | gShellLevel1HiiHandle, \r | |
574 | ArgSet, \r | |
81cd2f53 | 575 | CurrentScriptFile->CurrentCommand->Line);\r |
532691c8 | 576 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
577 | }\r | |
77dcec12 | 578 | }\r |
a405b86d | 579 | }\r |
532691c8 | 580 | \r |
a405b86d | 581 | }\r |
582 | }\r | |
583 | }\r | |
584 | }\r | |
585 | }\r | |
532691c8 | 586 | if (ShellStatus == SHELL_SUCCESS) {\r |
587 | if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {\r | |
588 | Info->RemoveSubstAlias = FALSE;\r | |
589 | } else {\r | |
590 | Info->RemoveSubstAlias = TRUE;\r | |
591 | }\r | |
592 | }\r | |
593 | if (CurrentScriptFile->CurrentCommand != NULL) {\r | |
594 | CurrentScriptFile->CurrentCommand->Data = Info;\r | |
a405b86d | 595 | }\r |
cbdd109b | 596 | }\r |
a405b86d | 597 | } else {\r |
ae724571 | 598 | ShellPrintHiiEx(\r |
599 | -1, \r | |
600 | -1, \r | |
601 | NULL, \r | |
602 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
603 | gShellLevel1HiiHandle, \r | |
604 | ArgSet, \r | |
605 | CurrentScriptFile!=NULL \r | |
606 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
607 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 608 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
609 | }\r | |
610 | } else {\r | |
611 | //\r | |
612 | // These need to be NULL since they are used to determine if this is the first pass later on...\r | |
613 | //\r | |
614 | ASSERT(ArgSetWalker == NULL);\r | |
615 | ASSERT(ArgSet == NULL);\r | |
616 | }\r | |
617 | \r | |
d8f8021c | 618 | if (CurrentScriptFile != NULL && CurrentScriptFile->CurrentCommand != NULL) {\r |
619 | Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data;\r | |
620 | if (CurrentScriptFile->CurrentCommand->Reset) {\r | |
621 | Info->CurrentValue = (CHAR16*)Info->Set;\r | |
622 | FirstPass = TRUE;\r | |
623 | CurrentScriptFile->CurrentCommand->Reset = FALSE;\r | |
624 | }\r | |
625 | } else {\r | |
626 | ShellStatus = SHELL_UNSUPPORTED;\r | |
627 | Info = NULL;\r | |
a405b86d | 628 | }\r |
629 | if (ShellStatus == SHELL_SUCCESS) {\r | |
630 | ASSERT(Info != NULL);\r | |
631 | if (Info->Step != 0) {\r | |
632 | //\r | |
633 | // only advance if not the first pass\r | |
634 | //\r | |
635 | if (!FirstPass) {\r | |
636 | //\r | |
637 | // sequence version of for loop...\r | |
638 | //\r | |
639 | Info->Current += Info->Step;\r | |
640 | }\r | |
641 | \r | |
642 | TempString = AllocateZeroPool(50*sizeof(CHAR16));\r | |
643 | UnicodeSPrint(TempString, 50*sizeof(CHAR16), L"%d", Info->Current);\r | |
644 | InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);\r | |
645 | FreePool(TempString);\r | |
646 | \r | |
647 | if ((Info->Step > 0 && Info->Current > Info->End) || (Info->Step < 0 && Info->Current < Info->End)) {\r | |
648 | CurrentScriptFile->CurrentCommand->Data = NULL;\r | |
649 | //\r | |
650 | // find the matching endfor (we're done with the loop)\r | |
651 | //\r | |
652 | if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {\r | |
ae724571 | 653 | ShellPrintHiiEx(\r |
654 | -1, \r | |
655 | -1, \r | |
656 | NULL, \r | |
657 | STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r | |
658 | gShellLevel1HiiHandle, \r | |
659 | L"EndFor", \r | |
660 | L"For", \r | |
661 | CurrentScriptFile!=NULL \r | |
662 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
663 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 664 | ShellStatus = SHELL_DEVICE_ERROR;\r |
665 | }\r | |
666 | if (Info->RemoveSubstAlias) {\r | |
667 | //\r | |
668 | // remove item from list\r | |
669 | //\r | |
670 | InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);\r | |
671 | }\r | |
672 | FreePool(Info);\r | |
673 | }\r | |
674 | } else {\r | |
675 | //\r | |
676 | // Must be in 'in' version of for loop...\r | |
677 | //\r | |
678 | ASSERT(Info->Set != NULL);\r | |
679 | if (Info->CurrentValue != NULL && *Info->CurrentValue != CHAR_NULL) {\r | |
b471606b | 680 | if (Info->CurrentValue[0] == L' ') {\r |
a405b86d | 681 | Info->CurrentValue++;\r |
682 | }\r | |
a405b86d | 683 | if (Info->CurrentValue[0] == L'\"') {\r |
684 | Info->CurrentValue++;\r | |
685 | }\r | |
686 | //\r | |
687 | // do the next one of the set\r | |
688 | //\r | |
689 | ASSERT(TempString == NULL);\r | |
690 | TempString = StrnCatGrow(&TempString, NULL, Info->CurrentValue, 0);\r | |
532691c8 | 691 | if (TempString == NULL) {\r |
692 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
693 | } else {\r | |
694 | TempSpot = StrStr(TempString, L"\" \"");\r | |
695 | if (TempSpot != NULL) {\r | |
696 | *TempSpot = CHAR_NULL;\r | |
697 | }\r | |
698 | while (TempString[StrLen(TempString)-1] == L'\"') {\r | |
699 | TempString[StrLen(TempString)-1] = CHAR_NULL;\r | |
700 | }\r | |
701 | InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);\r | |
702 | Info->CurrentValue += StrLen(TempString);\r | |
a405b86d | 703 | \r |
532691c8 | 704 | if (Info->CurrentValue[0] == L'\"') {\r |
705 | Info->CurrentValue++;\r | |
706 | }\r | |
707 | FreePool(TempString);\r | |
a405b86d | 708 | }\r |
a405b86d | 709 | } else {\r |
710 | CurrentScriptFile->CurrentCommand->Data = NULL;\r | |
711 | //\r | |
712 | // find the matching endfor (we're done with the loop)\r | |
713 | //\r | |
714 | if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {\r | |
ae724571 | 715 | ShellPrintHiiEx(\r |
716 | -1, \r | |
717 | -1, \r | |
718 | NULL, \r | |
719 | STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r | |
720 | gShellLevel1HiiHandle, \r | |
721 | L"EndFor", \r | |
722 | L"For", \r | |
723 | CurrentScriptFile!=NULL \r | |
724 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
725 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 726 | ShellStatus = SHELL_DEVICE_ERROR;\r |
727 | }\r | |
728 | if (Info->RemoveSubstAlias) {\r | |
729 | //\r | |
730 | // remove item from list\r | |
731 | //\r | |
732 | InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);\r | |
733 | }\r | |
734 | FreePool(Info);\r | |
735 | }\r | |
736 | }\r | |
737 | }\r | |
738 | if (ArgSet != NULL) {\r | |
739 | FreePool(ArgSet);\r | |
740 | }\r | |
741 | return (ShellStatus);\r | |
742 | }\r | |
743 | \r |