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