]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Main file for endfor and for shell level 1 functions.\r | |
3 | \r | |
b471606b | 4 | Copyright (c) 2009 - 2012, 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 | |
2d3759d8 | 45 | if ((StrStr(Number, L" ") == NULL) || (((StrStr(Number, L" ") != NULL) && (StrStr(Number, L" ") - Number) >= 7))) {\r |
a405b86d | 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 | |
e82edcf9 JC |
256 | /**\r |
257 | Function to determine whether a string is decimal or hex representation of a number\r | |
258 | and return the number converted from the string.\r | |
259 | \r | |
260 | @param[in] String String representation of a number\r | |
261 | \r | |
262 | @return the number\r | |
263 | @retval (UINTN)(-1) An error ocurred.\r | |
264 | **/\r | |
265 | UINTN\r | |
266 | EFIAPI\r | |
267 | ReturnUintn(\r | |
268 | IN CONST CHAR16 *String\r | |
269 | )\r | |
270 | {\r | |
271 | UINT64 RetVal;\r | |
272 | \r | |
c8186395 | 273 | if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, FALSE, TRUE))) {\r |
e82edcf9 JC |
274 | return ((UINTN)RetVal);\r |
275 | }\r | |
276 | return ((UINTN)(-1));\r | |
277 | }\r | |
278 | \r | |
a405b86d | 279 | /**\r |
280 | Function for 'for' command.\r | |
281 | \r | |
282 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
283 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
284 | **/\r | |
285 | SHELL_STATUS\r | |
286 | EFIAPI\r | |
287 | ShellCommandRunFor (\r | |
288 | IN EFI_HANDLE ImageHandle,\r | |
289 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
290 | )\r | |
291 | {\r | |
292 | EFI_STATUS Status;\r | |
293 | SHELL_STATUS ShellStatus;\r | |
294 | SCRIPT_FILE *CurrentScriptFile;\r | |
295 | CHAR16 *ArgSet;\r | |
296 | CHAR16 *ArgSetWalker;\r | |
297 | UINTN ArgSize;\r | |
298 | UINTN LoopVar;\r | |
299 | SHELL_FOR_INFO *Info;\r | |
300 | CHAR16 *TempString;\r | |
301 | CHAR16 *TempSpot;\r | |
302 | BOOLEAN FirstPass;\r | |
303 | EFI_SHELL_FILE_INFO *Node;\r | |
304 | EFI_SHELL_FILE_INFO *FileList;\r | |
305 | UINTN NewSize;\r | |
306 | \r | |
307 | ArgSet = NULL;\r | |
308 | ArgSize = 0;\r | |
309 | ShellStatus = SHELL_SUCCESS;\r | |
310 | ArgSetWalker = NULL;\r | |
311 | TempString = NULL;\r | |
312 | FirstPass = FALSE;\r | |
313 | \r | |
314 | //\r | |
315 | // initialize the shell lib (we must be in non-auto-init...)\r | |
316 | //\r | |
317 | Status = ShellInitialize();\r | |
318 | ASSERT_EFI_ERROR(Status);\r | |
319 | \r | |
320 | Status = CommandInit();\r | |
321 | ASSERT_EFI_ERROR(Status);\r | |
322 | \r | |
323 | if (!gEfiShellProtocol->BatchIsActive()) {\r | |
324 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"For");\r | |
325 | return (SHELL_UNSUPPORTED);\r | |
326 | }\r | |
327 | \r | |
328 | if (gEfiShellParametersProtocol->Argc < 4) {\r | |
329 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);\r | |
330 | return (SHELL_INVALID_PARAMETER);\r | |
331 | }\r | |
332 | \r | |
333 | CurrentScriptFile = ShellCommandGetCurrentScriptFile();\r | |
334 | ASSERT(CurrentScriptFile != NULL);\r | |
335 | \r | |
336 | if (CurrentScriptFile->CurrentCommand->Data == NULL) {\r | |
337 | FirstPass = TRUE;\r | |
338 | \r | |
339 | //\r | |
340 | // Make sure that an End exists.\r | |
341 | //\r | |
342 | if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) {\r | |
33c031ee | 343 | ShellPrintHiiEx(\r |
344 | -1, \r | |
345 | -1, \r | |
346 | NULL, \r | |
347 | STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r | |
348 | gShellLevel1HiiHandle, \r | |
349 | L"EndFor", \r | |
350 | L"For", \r | |
351 | CurrentScriptFile->CurrentCommand!=NULL\r | |
352 | ?CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 353 | return (SHELL_DEVICE_ERROR);\r |
354 | }\r | |
355 | \r | |
356 | //\r | |
357 | // Process the line.\r | |
358 | //\r | |
359 | if (gEfiShellParametersProtocol->Argv[1][0] != L'%' || gEfiShellParametersProtocol->Argv[1][2] != CHAR_NULL\r | |
360 | ||!((gEfiShellParametersProtocol->Argv[1][1] >= L'a' && gEfiShellParametersProtocol->Argv[1][1] <= L'z')\r | |
361 | ||(gEfiShellParametersProtocol->Argv[1][1] >= L'A' && gEfiShellParametersProtocol->Argv[1][1] <= L'Z'))\r | |
362 | ) {\r | |
77dcec12 | 363 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_VAR), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[1]);\r |
a405b86d | 364 | return (SHELL_INVALID_PARAMETER);\r |
365 | }\r | |
366 | \r | |
367 | if (gUnicodeCollation->StriColl(\r | |
368 | gUnicodeCollation,\r | |
369 | L"in",\r | |
370 | gEfiShellParametersProtocol->Argv[2]) == 0) {\r | |
371 | for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r | |
372 | ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));\r | |
c8186395 | 373 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);\r |
a405b86d | 374 | if (StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"*") != NULL\r |
375 | ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"?") != NULL\r | |
376 | ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"[") != NULL\r | |
377 | ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"]") != NULL) {\r | |
378 | FileList = NULL;\r | |
379 | Status = ShellOpenFileMetaArg ((CHAR16*)gEfiShellParametersProtocol->Argv[LoopVar], EFI_FILE_MODE_READ, &FileList);\r | |
380 | if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {\r | |
381 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);\r | |
382 | } else {\r | |
383 | for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)\r | |
384 | ; !IsNull(&FileList->Link, &Node->Link)\r | |
385 | ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)\r | |
386 | ){\r | |
387 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);\r | |
388 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Node->FullName, 0);\r | |
389 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);\r | |
390 | }\r | |
391 | ShellCloseFileMetaArg(&FileList);\r | |
392 | }\r | |
393 | } else {\r | |
394 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);\r | |
395 | }\r | |
396 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);\r | |
397 | }\r | |
532691c8 | 398 | if (ArgSet == NULL) {\r |
399 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
a405b86d | 400 | } else {\r |
532691c8 | 401 | //\r |
402 | // set up for an 'in' for loop\r | |
403 | //\r | |
404 | NewSize = StrSize(ArgSet);\r | |
405 | NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);\r | |
406 | Info = AllocateZeroPool(NewSize);\r | |
407 | ASSERT(Info != NULL);\r | |
408 | Info->Signature = SHELL_FOR_INFO_SIGNATURE;\r | |
409 | CopyMem(Info->Set, ArgSet, StrSize(ArgSet));\r | |
410 | NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);\r | |
411 | CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);\r | |
412 | Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);\r | |
413 | Info->CurrentValue = (CHAR16*)Info->Set;\r | |
414 | Info->Step = 0;\r | |
415 | Info->Current = 0;\r | |
416 | Info->End = 0;\r | |
417 | \r | |
418 | if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {\r | |
419 | Info->RemoveSubstAlias = FALSE;\r | |
420 | } else {\r | |
421 | Info->RemoveSubstAlias = TRUE;\r | |
422 | }\r | |
423 | CurrentScriptFile->CurrentCommand->Data = Info;\r | |
a405b86d | 424 | }\r |
a405b86d | 425 | } else if (gUnicodeCollation->StriColl(\r |
426 | gUnicodeCollation,\r | |
427 | L"run",\r | |
428 | gEfiShellParametersProtocol->Argv[2]) == 0) {\r | |
429 | for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r | |
430 | ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));\r | |
431 | if (ArgSet == NULL) {\r | |
432 | // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);\r | |
433 | } else {\r | |
77dcec12 | 434 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);\r |
a405b86d | 435 | }\r |
436 | ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);\r | |
437 | // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);\r | |
438 | }\r | |
532691c8 | 439 | if (ArgSet == NULL) {\r |
440 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
a405b86d | 441 | } else {\r |
532691c8 | 442 | //\r |
443 | // set up for a 'run' for loop\r | |
444 | //\r | |
445 | Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));\r | |
446 | ASSERT(Info != NULL);\r | |
b471606b | 447 | Info->Signature = SHELL_FOR_INFO_SIGNATURE;\r |
532691c8 | 448 | CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));\r |
449 | Info->ReplacementName = Info->Set;\r | |
450 | Info->CurrentValue = NULL;\r | |
451 | ArgSetWalker = ArgSet;\r | |
452 | if (ArgSetWalker[0] != L'(') {\r | |
ae724571 | 453 | ShellPrintHiiEx(\r |
454 | -1, \r | |
455 | -1, \r | |
456 | NULL, \r | |
457 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
458 | gShellLevel1HiiHandle, \r | |
532691c8 | 459 | ArgSet, \r |
ae724571 | 460 | CurrentScriptFile!=NULL \r |
461 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
462 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 463 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
464 | } else {\r | |
532691c8 | 465 | TempSpot = StrStr(ArgSetWalker, L")");\r |
466 | if (TempSpot != NULL) {\r | |
467 | TempString = TempSpot+1;\r | |
468 | if (*(TempString) != CHAR_NULL) {\r | |
469 | while(TempString != NULL && *TempString == L' ') {\r | |
470 | TempString++;\r | |
471 | }\r | |
472 | if (StrLen(TempString) > 0) {\r | |
473 | TempSpot = NULL;\r | |
474 | }\r | |
475 | }\r | |
a405b86d | 476 | }\r |
532691c8 | 477 | if (TempSpot == NULL) {\r |
ae724571 | 478 | ShellPrintHiiEx(\r |
479 | -1, \r | |
480 | -1, \r | |
481 | NULL, \r | |
482 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
483 | gShellLevel1HiiHandle, \r | |
ae724571 | 484 | CurrentScriptFile!=NULL \r |
485 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
486 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 487 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
488 | } else {\r | |
532691c8 | 489 | *TempSpot = CHAR_NULL;\r |
490 | ArgSetWalker++;\r | |
a405b86d | 491 | while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r |
492 | ArgSetWalker++;\r | |
493 | }\r | |
532691c8 | 494 | if (!ShellIsValidForNumber(ArgSetWalker)) {\r |
ae724571 | 495 | ShellPrintHiiEx(\r |
496 | -1, \r | |
497 | -1, \r | |
498 | NULL, \r | |
499 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
500 | gShellLevel1HiiHandle, \r | |
501 | ArgSet, \r | |
502 | CurrentScriptFile!=NULL \r | |
503 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
504 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
77dcec12 | 505 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
506 | } else {\r | |
507 | if (ArgSetWalker[0] == L'-') {\r | |
e82edcf9 | 508 | Info->Current = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r |
77dcec12 | 509 | } else {\r |
e82edcf9 | 510 | Info->Current = (INTN)ReturnUintn(ArgSetWalker);\r |
77dcec12 | 511 | }\r |
77dcec12 | 512 | ArgSetWalker = StrStr(ArgSetWalker, L" ");\r |
513 | while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r | |
514 | ArgSetWalker++;\r | |
515 | }\r | |
532691c8 | 516 | if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){\r |
517 | ShellPrintHiiEx(\r | |
518 | -1, \r | |
519 | -1, \r | |
520 | NULL, \r | |
521 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
522 | gShellLevel1HiiHandle, \r | |
523 | ArgSet, \r | |
524 | CurrentScriptFile!=NULL \r | |
525 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
526 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
527 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
528 | } else {\r | |
529 | if (ArgSetWalker[0] == L'-') {\r | |
e82edcf9 | 530 | Info->End = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r |
a405b86d | 531 | } else {\r |
e82edcf9 | 532 | Info->End = (INTN)ReturnUintn(ArgSetWalker);\r |
532691c8 | 533 | }\r |
534 | if (Info->Current < Info->End) {\r | |
535 | Info->Step = 1;\r | |
536 | } else {\r | |
537 | Info->Step = -1;\r | |
538 | }\r | |
539 | \r | |
540 | ArgSetWalker = StrStr(ArgSetWalker, L" ");\r | |
541 | while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r | |
542 | ArgSetWalker++;\r | |
543 | }\r | |
544 | if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) {\r | |
545 | if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){\r | |
546 | ShellPrintHiiEx(\r | |
547 | -1, \r | |
548 | -1, \r | |
549 | NULL, \r | |
550 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
551 | gShellLevel1HiiHandle, \r | |
552 | ArgSet, \r | |
553 | CurrentScriptFile!=NULL \r | |
554 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
555 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
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 | |
575 | CurrentScriptFile!=NULL \r | |
576 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
577 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
578 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
579 | }\r | |
77dcec12 | 580 | }\r |
a405b86d | 581 | }\r |
532691c8 | 582 | \r |
a405b86d | 583 | }\r |
584 | }\r | |
585 | }\r | |
586 | }\r | |
587 | }\r | |
532691c8 | 588 | if (ShellStatus == SHELL_SUCCESS) {\r |
589 | if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {\r | |
590 | Info->RemoveSubstAlias = FALSE;\r | |
591 | } else {\r | |
592 | Info->RemoveSubstAlias = TRUE;\r | |
593 | }\r | |
594 | }\r | |
595 | if (CurrentScriptFile->CurrentCommand != NULL) {\r | |
596 | CurrentScriptFile->CurrentCommand->Data = Info;\r | |
a405b86d | 597 | }\r |
cbdd109b | 598 | }\r |
a405b86d | 599 | } else {\r |
ae724571 | 600 | ShellPrintHiiEx(\r |
601 | -1, \r | |
602 | -1, \r | |
603 | NULL, \r | |
604 | STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), \r | |
605 | gShellLevel1HiiHandle, \r | |
606 | ArgSet, \r | |
607 | CurrentScriptFile!=NULL \r | |
608 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
609 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 610 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
611 | }\r | |
612 | } else {\r | |
613 | //\r | |
614 | // These need to be NULL since they are used to determine if this is the first pass later on...\r | |
615 | //\r | |
616 | ASSERT(ArgSetWalker == NULL);\r | |
617 | ASSERT(ArgSet == NULL);\r | |
618 | }\r | |
619 | \r | |
d8f8021c | 620 | if (CurrentScriptFile != NULL && CurrentScriptFile->CurrentCommand != NULL) {\r |
621 | Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data;\r | |
622 | if (CurrentScriptFile->CurrentCommand->Reset) {\r | |
623 | Info->CurrentValue = (CHAR16*)Info->Set;\r | |
624 | FirstPass = TRUE;\r | |
625 | CurrentScriptFile->CurrentCommand->Reset = FALSE;\r | |
626 | }\r | |
627 | } else {\r | |
628 | ShellStatus = SHELL_UNSUPPORTED;\r | |
629 | Info = NULL;\r | |
a405b86d | 630 | }\r |
631 | if (ShellStatus == SHELL_SUCCESS) {\r | |
632 | ASSERT(Info != NULL);\r | |
633 | if (Info->Step != 0) {\r | |
634 | //\r | |
635 | // only advance if not the first pass\r | |
636 | //\r | |
637 | if (!FirstPass) {\r | |
638 | //\r | |
639 | // sequence version of for loop...\r | |
640 | //\r | |
641 | Info->Current += Info->Step;\r | |
642 | }\r | |
643 | \r | |
644 | TempString = AllocateZeroPool(50*sizeof(CHAR16));\r | |
645 | UnicodeSPrint(TempString, 50*sizeof(CHAR16), L"%d", Info->Current);\r | |
646 | InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);\r | |
647 | FreePool(TempString);\r | |
648 | \r | |
649 | if ((Info->Step > 0 && Info->Current > Info->End) || (Info->Step < 0 && Info->Current < Info->End)) {\r | |
650 | CurrentScriptFile->CurrentCommand->Data = NULL;\r | |
651 | //\r | |
652 | // find the matching endfor (we're done with the loop)\r | |
653 | //\r | |
654 | if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {\r | |
ae724571 | 655 | ShellPrintHiiEx(\r |
656 | -1, \r | |
657 | -1, \r | |
658 | NULL, \r | |
659 | STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r | |
660 | gShellLevel1HiiHandle, \r | |
661 | L"EndFor", \r | |
662 | L"For", \r | |
663 | CurrentScriptFile!=NULL \r | |
664 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
665 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 666 | ShellStatus = SHELL_DEVICE_ERROR;\r |
667 | }\r | |
668 | if (Info->RemoveSubstAlias) {\r | |
669 | //\r | |
670 | // remove item from list\r | |
671 | //\r | |
672 | InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);\r | |
673 | }\r | |
674 | FreePool(Info);\r | |
675 | }\r | |
676 | } else {\r | |
677 | //\r | |
678 | // Must be in 'in' version of for loop...\r | |
679 | //\r | |
680 | ASSERT(Info->Set != NULL);\r | |
681 | if (Info->CurrentValue != NULL && *Info->CurrentValue != CHAR_NULL) {\r | |
b471606b | 682 | if (Info->CurrentValue[0] == L' ') {\r |
a405b86d | 683 | Info->CurrentValue++;\r |
684 | }\r | |
a405b86d | 685 | if (Info->CurrentValue[0] == L'\"') {\r |
686 | Info->CurrentValue++;\r | |
687 | }\r | |
688 | //\r | |
689 | // do the next one of the set\r | |
690 | //\r | |
691 | ASSERT(TempString == NULL);\r | |
692 | TempString = StrnCatGrow(&TempString, NULL, Info->CurrentValue, 0);\r | |
532691c8 | 693 | if (TempString == NULL) {\r |
694 | ShellStatus = SHELL_OUT_OF_RESOURCES;\r | |
695 | } else {\r | |
696 | TempSpot = StrStr(TempString, L"\" \"");\r | |
697 | if (TempSpot != NULL) {\r | |
698 | *TempSpot = CHAR_NULL;\r | |
699 | }\r | |
700 | while (TempString[StrLen(TempString)-1] == L'\"') {\r | |
701 | TempString[StrLen(TempString)-1] = CHAR_NULL;\r | |
702 | }\r | |
703 | InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);\r | |
704 | Info->CurrentValue += StrLen(TempString);\r | |
a405b86d | 705 | \r |
532691c8 | 706 | if (Info->CurrentValue[0] == L'\"') {\r |
707 | Info->CurrentValue++;\r | |
708 | }\r | |
709 | while (Info->CurrentValue[0] == L' ') {\r | |
710 | Info->CurrentValue++;\r | |
711 | }\r | |
712 | if (Info->CurrentValue[0] == L'\"') {\r | |
713 | Info->CurrentValue++;\r | |
714 | }\r | |
715 | FreePool(TempString);\r | |
a405b86d | 716 | }\r |
a405b86d | 717 | } else {\r |
718 | CurrentScriptFile->CurrentCommand->Data = NULL;\r | |
719 | //\r | |
720 | // find the matching endfor (we're done with the loop)\r | |
721 | //\r | |
722 | if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {\r | |
ae724571 | 723 | ShellPrintHiiEx(\r |
724 | -1, \r | |
725 | -1, \r | |
726 | NULL, \r | |
727 | STRING_TOKEN (STR_SYNTAX_NO_MATCHING), \r | |
728 | gShellLevel1HiiHandle, \r | |
729 | L"EndFor", \r | |
730 | L"For", \r | |
731 | CurrentScriptFile!=NULL \r | |
732 | && CurrentScriptFile->CurrentCommand!=NULL\r | |
733 | ? CurrentScriptFile->CurrentCommand->Line:0);\r | |
a405b86d | 734 | ShellStatus = SHELL_DEVICE_ERROR;\r |
735 | }\r | |
736 | if (Info->RemoveSubstAlias) {\r | |
737 | //\r | |
738 | // remove item from list\r | |
739 | //\r | |
740 | InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);\r | |
741 | }\r | |
742 | FreePool(Info);\r | |
743 | }\r | |
744 | }\r | |
745 | }\r | |
746 | if (ArgSet != NULL) {\r | |
747 | FreePool(ArgSet);\r | |
748 | }\r | |
749 | return (ShellStatus);\r | |
750 | }\r | |
751 | \r |