TianoCore EDK2 master
Loading...
Searching...
No Matches
For.c
Go to the documentation of this file.
1
11#include <Library/PrintLib.h>
12
21BOOLEAN
23 IN CONST CHAR16 *Number
24 )
25{
26 if ((Number == NULL) || (*Number == CHAR_NULL)) {
27 return (FALSE);
28 }
29
30 if (*Number == L'-') {
31 Number++;
32 }
33
34 if (StrLen (Number) == 0) {
35 return (FALSE);
36 }
37
38 if (StrLen (Number) >= 7) {
39 if ((StrStr (Number, L" ") == NULL) || (((StrStr (Number, L" ") != NULL) && ((StrStr (Number, L" ") - Number) >= 7)))) {
40 return (FALSE);
41 }
42 }
43
44 if (!ShellIsDecimalDigitCharacter (*Number)) {
45 return (FALSE);
46 }
47
48 return (TRUE);
49}
50
58EFIAPI
60 IN EFI_HANDLE ImageHandle,
61 IN EFI_SYSTEM_TABLE *SystemTable
62 )
63{
64 EFI_STATUS Status;
65 BOOLEAN Found;
66 SCRIPT_FILE *CurrentScriptFile;
67
68 Status = CommandInit ();
69 ASSERT_EFI_ERROR (Status);
70
71 if (!gEfiShellProtocol->BatchIsActive ()) {
72 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"endfor");
73 return (SHELL_UNSUPPORTED);
74 }
75
76 if (gEfiShellParametersProtocol->Argc > 1) {
77 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"endfor");
79 }
80
82
83 if (!Found) {
84 CurrentScriptFile = ShellCommandGetCurrentScriptFile ();
86 -1,
87 -1,
88 NULL,
89 STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
90 gShellLevel1HiiHandle,
91 L"For",
92 L"EndFor",
93 CurrentScriptFile != NULL
94 && CurrentScriptFile->CurrentCommand != NULL
95 ? CurrentScriptFile->CurrentCommand->Line : 0
96 );
97 return (SHELL_NOT_FOUND);
98 }
99
100 return (SHELL_SUCCESS);
101}
102
103typedef struct {
104 UINT32 Signature;
105 INTN Current;
106 INTN End;
107 INTN Step;
108 CHAR16 *ReplacementName;
109 CHAR16 *CurrentValue;
110 BOOLEAN RemoveSubstAlias;
111 CHAR16 Set[1];
113#define SIZE_OF_SHELL_FOR_INFO OFFSET_OF (SHELL_FOR_INFO, Set)
114#define SHELL_FOR_INFO_SIGNATURE SIGNATURE_32 ('S', 'F', 'I', 's')
115
128 IN CONST CHAR16 *Alias,
129 IN CONST CHAR16 *CommandString,
130 IN OUT LIST_ENTRY *List
131 )
132{
133 ALIAS_LIST *Node;
134 BOOLEAN Found;
135
136 //
137 // assert for NULL parameter
138 //
139 ASSERT (Alias != NULL);
140
141 //
142 // check for the Alias
143 //
144 for ( Node = (ALIAS_LIST *)GetFirstNode (List), Found = FALSE
145 ; !IsNull (List, &Node->Link)
146 ; Node = (ALIAS_LIST *)GetNextNode (List, &Node->Link)
147 )
148 {
149 ASSERT (Node->CommandString != NULL);
150 ASSERT (Node->Alias != NULL);
151 if (StrCmp (Node->Alias, Alias) == 0) {
152 FreePool (Node->CommandString);
153 Node->CommandString = NULL;
154 Node->CommandString = StrnCatGrow (&Node->CommandString, NULL, CommandString, 0);
155 Found = TRUE;
156 break;
157 }
158 }
159
160 if (!Found) {
161 Node = AllocateZeroPool (sizeof (ALIAS_LIST));
162 if (Node == NULL) {
163 return (EFI_OUT_OF_RESOURCES);
164 }
165
166 ASSERT (Node->Alias == NULL);
167 Node->Alias = StrnCatGrow (&Node->Alias, NULL, Alias, 0);
168 ASSERT (Node->CommandString == NULL);
169 Node->CommandString = StrnCatGrow (&Node->CommandString, NULL, CommandString, 0);
170 InsertTailList (List, &Node->Link);
171 }
172
173 return (EFI_SUCCESS);
174}
175
185BOOLEAN
187 IN CONST CHAR16 *Alias,
188 IN CONST LIST_ENTRY *List
189 )
190{
191 ALIAS_LIST *Node;
192
193 //
194 // assert for NULL parameter
195 //
196 ASSERT (Alias != NULL);
197
198 //
199 // check for the Alias
200 //
201 for ( Node = (ALIAS_LIST *)GetFirstNode (List)
202 ; !IsNull (List, &Node->Link)
203 ; Node = (ALIAS_LIST *)GetNextNode (List, &Node->Link)
204 )
205 {
206 ASSERT (Node->CommandString != NULL);
207 ASSERT (Node->Alias != NULL);
208 if (StrCmp (Node->Alias, Alias) == 0) {
209 return (TRUE);
210 }
211 }
212
213 return (FALSE);
214}
215
222BOOLEAN
224 IN CONST CHAR16 *Alias,
225 IN OUT LIST_ENTRY *List
226 )
227{
228 ALIAS_LIST *Node;
229
230 //
231 // assert for NULL parameter
232 //
233 ASSERT (Alias != NULL);
234
235 //
236 // check for the Alias
237 //
238 for ( Node = (ALIAS_LIST *)GetFirstNode (List)
239 ; !IsNull (List, &Node->Link)
240 ; Node = (ALIAS_LIST *)GetNextNode (List, &Node->Link)
241 )
242 {
243 ASSERT (Node->CommandString != NULL);
244 ASSERT (Node->Alias != NULL);
245 if (StrCmp (Node->Alias, Alias) == 0) {
246 RemoveEntryList (&Node->Link);
247 FreePool (Node->Alias);
248 FreePool (Node->CommandString);
249 FreePool (Node);
250 return (TRUE);
251 }
252 }
253
254 return (FALSE);
255}
256
266UINTN
268 IN CONST CHAR16 *String
269 )
270{
271 UINT64 RetVal;
272
273 if (!EFI_ERROR (ShellConvertStringToUint64 (String, &RetVal, FALSE, TRUE))) {
274 return ((UINTN)RetVal);
275 }
276
277 return ((UINTN)(-1));
278}
279
287EFIAPI
289 IN EFI_HANDLE ImageHandle,
290 IN EFI_SYSTEM_TABLE *SystemTable
291 )
292{
293 EFI_STATUS Status;
294 SHELL_STATUS ShellStatus;
295 SCRIPT_FILE *CurrentScriptFile;
296 CHAR16 *ArgSet;
297 CHAR16 *ArgSetWalker;
298 CHAR16 *Parameter;
299 UINTN ArgSize;
300 UINTN LoopVar;
301 SHELL_FOR_INFO *Info;
302 CHAR16 *TempString;
303 CHAR16 *TempSpot;
304 BOOLEAN FirstPass;
306 EFI_SHELL_FILE_INFO *FileList;
307 UINTN NewSize;
308
309 ArgSet = NULL;
310 ArgSize = 0;
311 ShellStatus = SHELL_SUCCESS;
312 ArgSetWalker = NULL;
313 TempString = NULL;
314 Parameter = NULL;
315 FirstPass = FALSE;
316
317 //
318 // initialize the shell lib (we must be in non-auto-init...)
319 //
320 Status = ShellInitialize ();
321 ASSERT_EFI_ERROR (Status);
322
323 Status = CommandInit ();
324 ASSERT_EFI_ERROR (Status);
325
326 if (!gEfiShellProtocol->BatchIsActive ()) {
327 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"for");
328 return (SHELL_UNSUPPORTED);
329 }
330
331 if (gEfiShellParametersProtocol->Argc < 4) {
332 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"for");
334 }
335
336 CurrentScriptFile = ShellCommandGetCurrentScriptFile ();
337 if (CurrentScriptFile == NULL) {
338 ASSERT (CurrentScriptFile != NULL);
340 }
341
342 if ((CurrentScriptFile->CurrentCommand != NULL) && (CurrentScriptFile->CurrentCommand->Data == NULL)) {
343 FirstPass = TRUE;
344
345 //
346 // Make sure that an End exists.
347 //
348 if (!MoveToTag (GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) {
350 -1,
351 -1,
352 NULL,
353 STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
354 gShellLevel1HiiHandle,
355 L"EndFor",
356 L"For",
357 CurrentScriptFile->CurrentCommand->Line
358 );
359 return (SHELL_DEVICE_ERROR);
360 }
361
362 //
363 // Process the line.
364 //
365 if ( (gEfiShellParametersProtocol->Argv[1][0] != L'%') || (gEfiShellParametersProtocol->Argv[1][2] != CHAR_NULL)
366 || !( ((gEfiShellParametersProtocol->Argv[1][1] >= L'a') && (gEfiShellParametersProtocol->Argv[1][1] <= L'z'))
367 || ((gEfiShellParametersProtocol->Argv[1][1] >= L'A') && (gEfiShellParametersProtocol->Argv[1][1] <= L'Z')))
368 )
369 {
370 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_VAR), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[1]);
372 }
373
374 if (gUnicodeCollation->StriColl (
375 gUnicodeCollation,
376 L"in",
377 gEfiShellParametersProtocol->Argv[2]
378 ) == 0)
379 {
380 for (LoopVar = 0x3; LoopVar < gEfiShellParametersProtocol->Argc; LoopVar++) {
381 ASSERT ((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
382 if ( (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L"*") != NULL)
383 || (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L"?") != NULL)
384 || (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L"[") != NULL)
385 || (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L"]") != NULL))
386 {
387 FileList = NULL;
388 Status = ShellOpenFileMetaArg ((CHAR16 *)gEfiShellParametersProtocol->Argv[LoopVar], EFI_FILE_MODE_READ, &FileList);
389 if (EFI_ERROR (Status) || (FileList == NULL) || IsListEmpty (&FileList->Link)) {
390 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, L" \"", 0);
391 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
392 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, L"\"", 0);
393 } else {
394 for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
395 ; !IsNull (&FileList->Link, &Node->Link)
396 ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link)
397 )
398 {
399 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, L" \"", 0);
400 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, Node->FullName, 0);
401 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, L"\"", 0);
402 }
403
404 ShellCloseFileMetaArg (&FileList);
405 }
406 } else {
407 Parameter = gEfiShellParametersProtocol->Argv[LoopVar];
408 if ((Parameter[0] == L'\"') && (Parameter[StrLen (Parameter)-1] == L'\"')) {
409 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, L" ", 0);
410 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, Parameter, 0);
411 } else {
412 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, L" \"", 0);
413 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, Parameter, 0);
414 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, L"\"", 0);
415 }
416 }
417 }
418
419 if (ArgSet == NULL) {
420 ShellStatus = SHELL_OUT_OF_RESOURCES;
421 } else {
422 //
423 // set up for an 'in' for loop
424 //
425 NewSize = StrSize (ArgSet);
426 NewSize += sizeof (SHELL_FOR_INFO)+StrSize (gEfiShellParametersProtocol->Argv[1]);
427 Info = AllocateZeroPool (NewSize);
428 if (Info == NULL) {
429 FreePool (ArgSet);
431 }
432
433 Info->Signature = SHELL_FOR_INFO_SIGNATURE;
434 CopyMem (Info->Set, ArgSet, StrSize (ArgSet));
435 NewSize = StrSize (gEfiShellParametersProtocol->Argv[1]);
436 CopyMem (Info->Set+(StrSize (ArgSet)/sizeof (Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);
437 Info->ReplacementName = Info->Set+StrSize (ArgSet)/sizeof (Info->Set[0]);
438 Info->CurrentValue = (CHAR16 *)Info->Set;
439 Info->Step = 0;
440 Info->Current = 0;
441 Info->End = 0;
442
443 if (InternalIsAliasOnList (Info->ReplacementName, &CurrentScriptFile->SubstList)) {
444 Info->RemoveSubstAlias = FALSE;
445 } else {
446 Info->RemoveSubstAlias = TRUE;
447 }
448
449 CurrentScriptFile->CurrentCommand->Data = Info;
450 }
451 } else if (gUnicodeCollation->StriColl (
452 gUnicodeCollation,
453 L"run",
454 gEfiShellParametersProtocol->Argv[2]
455 ) == 0)
456 {
457 for (LoopVar = 0x3; LoopVar < gEfiShellParametersProtocol->Argc; LoopVar++) {
458 ASSERT ((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
459 if ((StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L")") != NULL) &&
460 ((LoopVar + 1) < gEfiShellParametersProtocol->Argc)
461 )
462 {
464 }
465
466 if (ArgSet == NULL) {
467 // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
468 } else {
469 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, L" ", 0);
470 }
471
472 ArgSet = StrnCatGrow (&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
473 // ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
474 }
475
476 if (ArgSet == NULL) {
477 ShellStatus = SHELL_OUT_OF_RESOURCES;
478 } else {
479 //
480 // set up for a 'run' for loop
481 //
482 Info = AllocateZeroPool (sizeof (SHELL_FOR_INFO)+StrSize (gEfiShellParametersProtocol->Argv[1]));
483 if (Info == NULL) {
484 FreePool (ArgSet);
486 }
487
488 Info->Signature = SHELL_FOR_INFO_SIGNATURE;
489 CopyMem (Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize (gEfiShellParametersProtocol->Argv[1]));
490 Info->ReplacementName = Info->Set;
491 Info->CurrentValue = NULL;
492 ArgSetWalker = ArgSet;
493 if (ArgSetWalker[0] != L'(') {
495 -1,
496 -1,
497 NULL,
498 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
499 gShellLevel1HiiHandle,
500 ArgSet,
501 CurrentScriptFile->CurrentCommand->Line
502 );
503 ShellStatus = SHELL_INVALID_PARAMETER;
504 } else {
505 TempSpot = StrStr (ArgSetWalker, L")");
506 if (TempSpot != NULL) {
507 TempString = TempSpot+1;
508 if (*(TempString) != CHAR_NULL) {
509 while (TempString != NULL && *TempString == L' ') {
510 TempString++;
511 }
512
513 if (StrLen (TempString) > 0) {
514 TempSpot = NULL;
515 }
516 }
517 }
518
519 if (TempSpot == NULL) {
521 -1,
522 -1,
523 NULL,
524 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
525 gShellLevel1HiiHandle,
526 CurrentScriptFile->CurrentCommand->Line
527 );
528 ShellStatus = SHELL_INVALID_PARAMETER;
529 } else {
530 *TempSpot = CHAR_NULL;
531 ArgSetWalker++;
532 while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
533 ArgSetWalker++;
534 }
535
536 if (!ShellIsValidForNumber (ArgSetWalker)) {
538 -1,
539 -1,
540 NULL,
541 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
542 gShellLevel1HiiHandle,
543 ArgSet,
544 CurrentScriptFile->CurrentCommand->Line
545 );
546 ShellStatus = SHELL_INVALID_PARAMETER;
547 } else {
548 if (ArgSetWalker[0] == L'-') {
549 Info->Current = 0 - (INTN)ReturnUintn (ArgSetWalker+1);
550 } else {
551 Info->Current = (INTN)ReturnUintn (ArgSetWalker);
552 }
553
554 ArgSetWalker = StrStr (ArgSetWalker, L" ");
555 while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
556 ArgSetWalker++;
557 }
558
559 if ((ArgSetWalker == NULL) || (*ArgSetWalker == CHAR_NULL) || !ShellIsValidForNumber (ArgSetWalker)) {
561 -1,
562 -1,
563 NULL,
564 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
565 gShellLevel1HiiHandle,
566 ArgSet,
567 CurrentScriptFile->CurrentCommand->Line
568 );
569 ShellStatus = SHELL_INVALID_PARAMETER;
570 } else {
571 if (ArgSetWalker[0] == L'-') {
572 Info->End = 0 - (INTN)ReturnUintn (ArgSetWalker+1);
573 } else {
574 Info->End = (INTN)ReturnUintn (ArgSetWalker);
575 }
576
577 if (Info->Current < Info->End) {
578 Info->Step = 1;
579 } else {
580 Info->Step = -1;
581 }
582
583 ArgSetWalker = StrStr (ArgSetWalker, L" ");
584 while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
585 ArgSetWalker++;
586 }
587
588 if ((ArgSetWalker != NULL) && (*ArgSetWalker != CHAR_NULL)) {
589 if ((ArgSetWalker == NULL) || (*ArgSetWalker == CHAR_NULL) || !ShellIsValidForNumber (ArgSetWalker)) {
591 -1,
592 -1,
593 NULL,
594 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
595 gShellLevel1HiiHandle,
596 ArgSet,
597 CurrentScriptFile->CurrentCommand->Line
598 );
599 ShellStatus = SHELL_INVALID_PARAMETER;
600 } else {
601 if (*ArgSetWalker == L')') {
602 ASSERT (Info->Step == 1 || Info->Step == -1);
603 } else {
604 if (ArgSetWalker[0] == L'-') {
605 Info->Step = 0 - (INTN)ReturnUintn (ArgSetWalker+1);
606 } else {
607 Info->Step = (INTN)ReturnUintn (ArgSetWalker);
608 }
609
610 if (StrStr (ArgSetWalker, L" ") != NULL) {
612 -1,
613 -1,
614 NULL,
615 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
616 gShellLevel1HiiHandle,
617 ArgSet,
618 CurrentScriptFile->CurrentCommand->Line
619 );
620 ShellStatus = SHELL_INVALID_PARAMETER;
621 }
622 }
623 }
624 }
625 }
626 }
627 }
628 }
629
630 if (ShellStatus == SHELL_SUCCESS) {
631 if (InternalIsAliasOnList (Info->ReplacementName, &CurrentScriptFile->SubstList)) {
632 Info->RemoveSubstAlias = FALSE;
633 } else {
634 Info->RemoveSubstAlias = TRUE;
635 }
636 }
637
638 if (CurrentScriptFile->CurrentCommand != NULL) {
639 CurrentScriptFile->CurrentCommand->Data = Info;
640 }
641 }
642 } else {
644 -1,
645 -1,
646 NULL,
647 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT),
648 gShellLevel1HiiHandle,
649 ArgSet,
650 CurrentScriptFile != NULL
651 && CurrentScriptFile->CurrentCommand != NULL
652 ? CurrentScriptFile->CurrentCommand->Line : 0
653 );
654 ShellStatus = SHELL_INVALID_PARAMETER;
655 }
656 } else {
657 //
658 // These need to be NULL since they are used to determine if this is the first pass later on...
659 //
660 ASSERT (ArgSetWalker == NULL);
661 ASSERT (ArgSet == NULL);
662 }
663
664 if ((CurrentScriptFile != NULL) && (CurrentScriptFile->CurrentCommand != NULL)) {
665 Info = (SHELL_FOR_INFO *)CurrentScriptFile->CurrentCommand->Data;
666 if (CurrentScriptFile->CurrentCommand->Reset) {
667 if (Info != NULL) {
668 Info->CurrentValue = (CHAR16 *)Info->Set;
669 }
670
671 FirstPass = TRUE;
672 CurrentScriptFile->CurrentCommand->Reset = FALSE;
673 }
674 } else {
675 ShellStatus = SHELL_UNSUPPORTED;
676 Info = NULL;
677 }
678
679 if (ShellStatus == SHELL_SUCCESS) {
680 ASSERT (Info != NULL);
681 if (Info->Step != 0) {
682 //
683 // only advance if not the first pass
684 //
685 if (!FirstPass) {
686 //
687 // sequence version of for loop...
688 //
689 Info->Current += Info->Step;
690 }
691
692 TempString = AllocateZeroPool (50*sizeof (CHAR16));
693 if (TempString == NULL) {
694 SHELL_FREE_NON_NULL (ArgSet);
695 SHELL_FREE_NON_NULL (Info);
696 return (SHELL_OUT_OF_RESOURCES);
697 }
698
699 UnicodeSPrint (TempString, 50*sizeof (CHAR16), L"%d", Info->Current);
700 InternalUpdateAliasOnList (Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
701 FreePool (TempString);
702
703 if (((Info->Step > 0) && (Info->Current > Info->End)) || ((Info->Step < 0) && (Info->Current < Info->End))) {
704 CurrentScriptFile->CurrentCommand->Data = NULL;
705 //
706 // find the matching endfor (we're done with the loop)
707 //
708 if (!MoveToTag (GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
710 -1,
711 -1,
712 NULL,
713 STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
714 gShellLevel1HiiHandle,
715 L"EndFor",
716 L"For",
717 CurrentScriptFile != NULL
718 && CurrentScriptFile->CurrentCommand != NULL
719 ? CurrentScriptFile->CurrentCommand->Line : 0
720 );
721 ShellStatus = SHELL_DEVICE_ERROR;
722 }
723
724 if (Info->RemoveSubstAlias) {
725 //
726 // remove item from list
727 //
728 InternalRemoveAliasFromList (Info->ReplacementName, &CurrentScriptFile->SubstList);
729 }
730
731 FreePool (Info);
732 }
733 } else {
734 //
735 // Must be in 'in' version of for loop...
736 //
737 ASSERT (Info->Set != NULL);
738 if ((Info->CurrentValue != NULL) && (*Info->CurrentValue != CHAR_NULL)) {
739 if (Info->CurrentValue[0] == L' ') {
740 Info->CurrentValue++;
741 }
742
743 if (Info->CurrentValue[0] == L'\"') {
744 Info->CurrentValue++;
745 }
746
747 //
748 // do the next one of the set
749 //
750 ASSERT (TempString == NULL);
751 TempString = StrnCatGrow (&TempString, NULL, Info->CurrentValue, 0);
752 if (TempString == NULL) {
753 ShellStatus = SHELL_OUT_OF_RESOURCES;
754 } else {
755 TempSpot = StrStr (TempString, L"\" \"");
756 if (TempSpot != NULL) {
757 *TempSpot = CHAR_NULL;
758 }
759
760 while (TempString[StrLen (TempString)-1] == L'\"') {
761 TempString[StrLen (TempString)-1] = CHAR_NULL;
762 }
763
764 InternalUpdateAliasOnList (Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
765 Info->CurrentValue += StrLen (TempString);
766
767 if (Info->CurrentValue[0] == L'\"') {
768 Info->CurrentValue++;
769 }
770
771 FreePool (TempString);
772 }
773 } else {
774 CurrentScriptFile->CurrentCommand->Data = NULL;
775 //
776 // find the matching endfor (we're done with the loop)
777 //
778 if (!MoveToTag (GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
780 -1,
781 -1,
782 NULL,
783 STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
784 gShellLevel1HiiHandle,
785 L"EndFor",
786 L"For",
787 CurrentScriptFile != NULL
788 && CurrentScriptFile->CurrentCommand != NULL
789 ? CurrentScriptFile->CurrentCommand->Line : 0
790 );
791 ShellStatus = SHELL_DEVICE_ERROR;
792 }
793
794 if (Info->RemoveSubstAlias) {
795 //
796 // remove item from list
797 //
798 InternalRemoveAliasFromList (Info->ReplacementName, &CurrentScriptFile->SubstList);
799 }
800
801 FreePool (Info);
802 }
803 }
804 }
805
806 if (ArgSet != NULL) {
807 FreePool (ArgSet);
808 }
809
810 return (ShellStatus);
811}
UINT64 UINTN
INT64 INTN
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:443
LIST_ENTRY *EFIAPI GetPreviousNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:369
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:333
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
BOOLEAN ShellIsValidForNumber(IN CONST CHAR16 *Number)
Definition: For.c:22
UINTN ReturnUintn(IN CONST CHAR16 *String)
Definition: For.c:267
BOOLEAN InternalIsAliasOnList(IN CONST CHAR16 *Alias, IN CONST LIST_ENTRY *List)
Definition: For.c:186
SHELL_STATUS EFIAPI ShellCommandRunEndFor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: For.c:59
EFI_STATUS InternalUpdateAliasOnList(IN CONST CHAR16 *Alias, IN CONST CHAR16 *CommandString, IN OUT LIST_ENTRY *List)
Definition: For.c:127
SHELL_STATUS EFIAPI ShellCommandRunFor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: For.c:288
BOOLEAN InternalRemoveAliasFromList(IN CONST CHAR16 *Alias, IN OUT LIST_ENTRY *List)
Definition: For.c:223
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_OUT_OF_RESOURCES
Definition: Shell.h:73
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_UNSUPPORTED
Definition: Shell.h:40
@ SHELL_DEVICE_ERROR
Definition: Shell.h:63
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_STATUS EFIAPI Set(IN EMBEDDED_GPIO *This, IN EMBEDDED_GPIO_PIN Gpio, IN EMBEDDED_GPIO_MODE Mode)
Definition: PL061Gpio.c:219
EFI_STATUS EFIAPI CommandInit(VOID)
SCRIPT_FILE *EFIAPI ShellCommandGetCurrentScriptFile(VOID)
EFI_STATUS EFIAPI ShellCloseFileMetaArg(IN OUT EFI_SHELL_FILE_INFO **ListHead)
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellIsDecimalDigitCharacter(IN CHAR16 Char)
Definition: UefiShellLib.c:194
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
EFI_STATUS EFIAPI ShellOpenFileMetaArg(IN CHAR16 *Arg, IN UINT64 OpenMode, IN OUT EFI_SHELL_FILE_INFO **ListHead)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
EFI_STATUS EFIAPI ShellConvertStringToUint64(IN CONST CHAR16 *String, OUT UINT64 *Value, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define STRING_TOKEN(t)
BOOLEAN MoveToTag(IN CONST LIST_MANIP_FUNC Function, IN CONST CHAR16 *DecrementerTag, IN CONST CHAR16 *IncrementerTag, IN CONST CHAR16 *Label OPTIONAL, IN OUT SCRIPT_FILE *ScriptFile, IN CONST BOOLEAN MovePast, IN CONST BOOLEAN FindOnly, IN CONST BOOLEAN WrapAroundScript)
LIST_ENTRY Link
Linked list members.
Definition: Shell.h:153
CONST CHAR16 * FullName
Fully qualified filename.
Definition: Shell.h:155
VOID * Data
The data structure format dependant upon Command. (not always used)
UINTN Line
What line of the script file this was on.
BOOLEAN Reset
Reset the command (it must be treated like a initial run (but it may have data already))
SCRIPT_COMMAND_LIST * CurrentCommand
The command currently being operated. If !=NULL must be a member of CommandList.
LIST_ENTRY SubstList
A list of current script loop alias' (ALIAS_LIST objects) (Used for the for %-based replacement).