2 Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,
3 manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
5 Copyright (C) 2014, Red Hat, Inc.
6 Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
7 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 return the next parameter from a command line string;
23 This function moves the next parameter from Walker into TempParameter and moves
24 Walker up past that parameter for recursive calling. When the final parameter
25 is moved *Walker will be set to NULL;
27 Temp Parameter must be large enough to hold the parameter before calling this
30 @param[in, out] Walker pointer to string of command line. Adjusted to
31 reminaing command line on return
32 @param[in, out] TempParameter pointer to string of command line item extracted.
39 CHAR16
**TempParameter
45 ASSERT(Walker
!= NULL
);
46 ASSERT(*Walker
!= NULL
);
47 ASSERT(TempParameter
!= NULL
);
48 ASSERT(*TempParameter
!= NULL
);
51 // make sure we dont have any leading spaces
53 while ((*Walker
)[0] == L
' ') {
58 // make sure we still have some params now...
60 if (StrLen(*Walker
) == 0) {
61 ASSERT((*Walker
)[0] == CHAR_NULL
);
67 // we have a quoted parameter
68 // could be the last parameter, but SHOULD have a trailing quote
70 if ((*Walker
)[0] == L
'\"') {
72 for (TempLoc
= *Walker
+ 1 ; TempLoc
!= NULL
&& *TempLoc
!= CHAR_NULL
; TempLoc
++) {
73 if (*TempLoc
== L
'^' && *(TempLoc
+1) == L
'\"') {
75 } else if (*TempLoc
== L
'\"') {
81 if (NextDelim
- ((*Walker
)+1) == 0) {
85 StrCpy(*TempParameter
, L
"");
86 *Walker
= NextDelim
+ 1;
87 } else if (NextDelim
!= NULL
) {
90 // Copy ensuring that both quotes are left in place.
92 StrnCpy(*TempParameter
, (*Walker
), NextDelim
- *Walker
+ 1);
93 *Walker
= NextDelim
+ 1;
96 // last one... someone forgot the training quote!
98 StrCpy(*TempParameter
, *Walker
);
101 for (TempLoc
= *TempParameter
; TempLoc
!= NULL
&& *TempLoc
!= CHAR_NULL
; TempLoc
++) {
102 if (*TempLoc
== L
'^' && *(TempLoc
+1) == L
'\"') {
103 CopyMem(TempLoc
, TempLoc
+1, StrSize(TempLoc
) - sizeof(TempLoc
[0]));
108 // we have a regular parameter (no quote) OR
109 // we have the final parameter (no trailing space)
111 NextDelim
= StrStr((*Walker
), L
" ");
112 if (NextDelim
!= NULL
) {
113 StrnCpy(*TempParameter
, *Walker
, NextDelim
- (*Walker
));
114 (*TempParameter
)[NextDelim
- (*Walker
)] = CHAR_NULL
;
115 *Walker
= NextDelim
+1;
120 StrCpy(*TempParameter
, *Walker
);
123 for (NextDelim
= *TempParameter
; NextDelim
!= NULL
&& *NextDelim
!= CHAR_NULL
; NextDelim
++) {
124 if (*NextDelim
== L
'^' && *(NextDelim
+1) == L
'^') {
125 CopyMem(NextDelim
, NextDelim
+1, StrSize(NextDelim
) - sizeof(NextDelim
[0]));
128 while ((*TempParameter
)[StrLen(*TempParameter
)-1] == L
' ') {
129 (*TempParameter
)[StrLen(*TempParameter
)-1] = CHAR_NULL
;
131 while ((*TempParameter
)[0] == L
' ') {
132 CopyMem(*TempParameter
, (*TempParameter
)+1, StrSize(*TempParameter
) - sizeof((*TempParameter
)[0]));
139 Function to populate Argc and Argv.
141 This function parses the CommandLine and divides it into standard C style Argc/Argv
142 parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space
143 delimited and quote surrounded parameter definition.
145 @param[in] CommandLine String of command line to parse
146 @param[in, out] Argv pointer to array of strings; one for each parameter
147 @param[in, out] Argc pointer to number of strings in Argv array
149 @return EFI_SUCCESS the operation was sucessful
150 @return EFI_OUT_OF_RESOURCES a memory allocation failed.
154 ParseCommandLineToArgs(
155 IN CONST CHAR16
*CommandLine
,
156 IN OUT CHAR16
***Argv
,
161 CHAR16
*TempParameter
;
166 ASSERT(Argc
!= NULL
);
167 ASSERT(Argv
!= NULL
);
169 if (CommandLine
== NULL
|| StrLen(CommandLine
)==0) {
172 return (EFI_SUCCESS
);
175 Size
= StrSize(CommandLine
);
176 TempParameter
= AllocateZeroPool(Size
);
177 if (TempParameter
== NULL
) {
178 return (EFI_OUT_OF_RESOURCES
);
182 , Walker
= (CHAR16
*)CommandLine
183 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
184 ; GetNextParameter(&Walker
, &TempParameter
)
189 Walker = (CHAR16*)CommandLine;
190 while(Walker != NULL) {
191 GetNextParameter(&Walker, &TempParameter);
196 // lets allocate the pointer array
198 (*Argv
) = AllocateZeroPool((Count
)*sizeof(CHAR16
*));
200 SHELL_FREE_NON_NULL(TempParameter
);
201 return (EFI_OUT_OF_RESOURCES
);
205 Walker
= (CHAR16
*)CommandLine
;
206 while(Walker
!= NULL
&& *Walker
!= CHAR_NULL
) {
207 SetMem16(TempParameter
, Size
, CHAR_NULL
);
208 GetNextParameter(&Walker
, &TempParameter
);
209 NewParam
= AllocateZeroPool(StrSize(TempParameter
));
210 ASSERT(NewParam
!= NULL
);
211 StrCpy(NewParam
, TempParameter
);
212 ((CHAR16
**)(*Argv
))[(*Argc
)] = NewParam
;
215 ASSERT(Count
>= (*Argc
));
216 SHELL_FREE_NON_NULL(TempParameter
);
217 return (EFI_SUCCESS
);
221 creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then
222 installs it on our handle and if there is an existing version of the protocol
223 that one is cached for removal later.
225 @param[in, out] NewShellParameters on a successful return, a pointer to pointer
226 to the newly installed interface.
227 @param[in, out] RootShellInstance on a successful return, pointer to boolean.
228 TRUE if this is the root shell instance.
230 @retval EFI_SUCCESS the operation completed successfully.
231 @return other the operation failed.
232 @sa ReinstallProtocolInterface
233 @sa InstallProtocolInterface
234 @sa ParseCommandLineToArgs
238 CreatePopulateInstallShellParametersProtocol (
239 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
**NewShellParameters
,
240 IN OUT BOOLEAN
*RootShellInstance
244 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
245 CHAR16
*FullCommandLine
;
249 FullCommandLine
= NULL
;
253 // Assert for valid parameters
255 ASSERT(NewShellParameters
!= NULL
);
256 ASSERT(RootShellInstance
!= NULL
);
259 // See if we have a shell parameters placed on us
261 Status
= gBS
->OpenProtocol (
263 &gEfiShellParametersProtocolGuid
,
264 (VOID
**) &ShellInfoObject
.OldShellParameters
,
267 EFI_OPEN_PROTOCOL_GET_PROTOCOL
270 // if we don't then we must be the root shell (error is expected)
272 if (EFI_ERROR (Status
)) {
273 *RootShellInstance
= TRUE
;
277 // Allocate the new structure
279 *NewShellParameters
= AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL
));
280 if ((*NewShellParameters
) == NULL
) {
281 return (EFI_OUT_OF_RESOURCES
);
285 // get loaded image protocol
287 Status
= gBS
->OpenProtocol (
289 &gEfiLoadedImageProtocolGuid
,
290 (VOID
**) &LoadedImage
,
293 EFI_OPEN_PROTOCOL_GET_PROTOCOL
295 ASSERT_EFI_ERROR(Status
);
297 // Build the full command line
299 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
300 if (Status
== EFI_BUFFER_TOO_SMALL
) {
301 FullCommandLine
= AllocateZeroPool(Size
+ LoadedImage
->LoadOptionsSize
);
302 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
304 if (Status
== EFI_NOT_FOUND
) {
306 // no parameters via environment... ok
309 if (EFI_ERROR(Status
)) {
313 if (Size
== 0 && LoadedImage
->LoadOptionsSize
!= 0) {
314 ASSERT(FullCommandLine
== NULL
);
316 // Now we need to include a NULL terminator in the size.
318 Size
= LoadedImage
->LoadOptionsSize
+ sizeof(FullCommandLine
[0]);
319 FullCommandLine
= AllocateZeroPool(Size
);
321 if (FullCommandLine
!= NULL
) {
322 CopyMem (FullCommandLine
, LoadedImage
->LoadOptions
, LoadedImage
->LoadOptionsSize
);
324 // Populate Argc and Argv
326 Status
= ParseCommandLineToArgs(FullCommandLine
,
327 &(*NewShellParameters
)->Argv
,
328 &(*NewShellParameters
)->Argc
);
330 FreePool(FullCommandLine
);
332 ASSERT_EFI_ERROR(Status
);
334 (*NewShellParameters
)->Argv
= NULL
;
335 (*NewShellParameters
)->Argc
= 0;
339 // Populate the 3 faked file systems...
341 if (*RootShellInstance
) {
342 (*NewShellParameters
)->StdIn
= &FileInterfaceStdIn
;
343 (*NewShellParameters
)->StdOut
= &FileInterfaceStdOut
;
344 (*NewShellParameters
)->StdErr
= &FileInterfaceStdErr
;
345 Status
= gBS
->InstallProtocolInterface(&gImageHandle
,
346 &gEfiShellParametersProtocolGuid
,
347 EFI_NATIVE_INTERFACE
,
348 (VOID
*)(*NewShellParameters
));
351 // copy from the existing ones
353 (*NewShellParameters
)->StdIn
= ShellInfoObject
.OldShellParameters
->StdIn
;
354 (*NewShellParameters
)->StdOut
= ShellInfoObject
.OldShellParameters
->StdOut
;
355 (*NewShellParameters
)->StdErr
= ShellInfoObject
.OldShellParameters
->StdErr
;
356 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
357 &gEfiShellParametersProtocolGuid
,
358 (VOID
*)ShellInfoObject
.OldShellParameters
,
359 (VOID
*)(*NewShellParameters
));
366 frees all memory used by createion and installation of shell parameters protocol
367 and if there was an old version installed it will restore that one.
369 @param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
372 @retval EFI_SUCCESS the cleanup was successful
373 @return other the cleanup failed
374 @sa ReinstallProtocolInterface
375 @sa UninstallProtocolInterface
379 CleanUpShellParametersProtocol (
380 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*NewShellParameters
387 // If the old exists we need to restore it
389 if (ShellInfoObject
.OldShellParameters
!= NULL
) {
390 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
391 &gEfiShellParametersProtocolGuid
,
392 (VOID
*)NewShellParameters
,
393 (VOID
*)ShellInfoObject
.OldShellParameters
);
394 DEBUG_CODE(ShellInfoObject
.OldShellParameters
= NULL
;);
397 // No old one, just uninstall us...
399 Status
= gBS
->UninstallProtocolInterface(gImageHandle
,
400 &gEfiShellParametersProtocolGuid
,
401 (VOID
*)NewShellParameters
);
403 if (NewShellParameters
->Argv
!= NULL
) {
404 for ( LoopCounter
= 0
405 ; LoopCounter
< NewShellParameters
->Argc
408 FreePool(NewShellParameters
->Argv
[LoopCounter
]);
410 FreePool(NewShellParameters
->Argv
);
412 FreePool(NewShellParameters
);
417 Determin if a file name represents a unicode file.
419 @param[in] FileName Pointer to the filename to open.
421 @retval EFI_SUCCESS The file is a unicode file.
422 @return An error upon failure.
427 IN CONST CHAR16
*FileName
430 SHELL_FILE_HANDLE Handle
;
432 UINT64 OriginalFilePosition
;
436 Status
= gEfiShellProtocol
->OpenFileByName(FileName
, &Handle
, EFI_FILE_MODE_READ
);
437 if (EFI_ERROR(Status
)) {
440 gEfiShellProtocol
->GetFilePosition(Handle
, &OriginalFilePosition
);
441 gEfiShellProtocol
->SetFilePosition(Handle
, 0);
442 CharSize
= sizeof(CHAR16
);
443 Status
= gEfiShellProtocol
->ReadFile(Handle
, &CharSize
, &CharBuffer
);
444 if (EFI_ERROR(Status
) || CharBuffer
!= gUnicodeFileTag
) {
445 Status
= EFI_BUFFER_TOO_SMALL
;
447 gEfiShellProtocol
->SetFilePosition(Handle
, OriginalFilePosition
);
448 gEfiShellProtocol
->CloseFile(Handle
);
453 Strips out quotes sections of a string.
455 All of the characters between quotes is replaced with spaces.
457 @param[in, out] TheString A pointer to the string to update.
462 IN OUT CHAR16
*TheString
467 for (RemoveNow
= FALSE
; TheString
!= NULL
&& *TheString
!= CHAR_NULL
; TheString
++) {
468 if (*TheString
== L
'^' && *(TheString
+ 1) == L
'\"') {
470 } else if (*TheString
== L
'\"') {
471 RemoveNow
= (BOOLEAN
)!RemoveNow
;
472 } else if (RemoveNow
) {
479 Calcualte the 32-bit CRC in a EFI table using the service provided by the
482 @param Hdr Pointer to an EFI standard header
487 IN OUT EFI_TABLE_HEADER
*Hdr
495 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
496 // Crc will come back as zero if we set it to zero here
499 gBS
->CalculateCrc32 ((UINT8
*)Hdr
, Hdr
->HeaderSize
, &Crc
);
504 Fix a string to only have the file name, removing starting at the first space of whatever is quoted.
506 @param[in] FileName The filename to start with.
508 @retval NULL FileName was invalid.
509 @return The modified FileName.
518 CHAR16
*TempLocation
;
520 if (FileName
== NULL
) {
524 if (FileName
[0] == L
'\"') {
526 if ((TempLocation
= StrStr(Copy
, L
"\"")) != NULL
) {
527 TempLocation
[0] = CHAR_NULL
;
531 while(Copy
[0] == L
' ') {
534 if ((TempLocation
= StrStr(Copy
, L
" ")) != NULL
) {
535 TempLocation
[0] = CHAR_NULL
;
539 if (Copy
[0] == CHAR_NULL
) {
547 Fix a string to only have the environment variable name, removing starting at the first space of whatever is quoted and removing the leading and trailing %.
549 @param[in] FileName The filename to start with.
551 @retval NULL FileName was invalid.
552 @return The modified FileName.
561 CHAR16
*TempLocation
;
565 if (FileName
[0] == L
'%') {
567 if ((TempLocation
= StrStr(Copy
, L
"%")) != NULL
) {
568 TempLocation
[0] = CHAR_NULL
;
572 return (FixFileName(Copy
));
576 Remove the unicode file tag from the begining of the file buffer since that will not be
579 @param[in] Handle Pointer to the handle of the file to be processed.
581 @retval EFI_SUCCESS The unicode file tag has been moved successfully.
586 IN SHELL_FILE_HANDLE
*Handle
592 CharSize
= sizeof(CHAR16
);
594 gEfiShellProtocol
->ReadFile(*Handle
, &CharSize
, &CharBuffer
);
595 if (CharBuffer
!= gUnicodeFileTag
) {
596 gEfiShellProtocol
->SetFilePosition(*Handle
, 0);
598 return (EFI_SUCCESS
);
602 Write the unicode file tag to the specified file.
604 It is the caller's responsibility to ensure that
605 ShellInfoObject.NewEfiShellProtocol has been initialized before calling this
608 @param[in] FileHandle The file to write the unicode file tag to.
610 @return Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.
615 IN SHELL_FILE_HANDLE FileHandle
622 FileTag
= gUnicodeFileTag
;
623 Size
= sizeof FileTag
;
624 Status
= ShellInfoObject
.NewEfiShellProtocol
->WriteFile (FileHandle
, &Size
,
626 ASSERT (EFI_ERROR (Status
) || Size
== sizeof FileTag
);
632 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
633 structure by parsing NewCommandLine. The current values are returned to the
636 This will also update the system table.
638 @param[in, out] ShellParameters Pointer to parameter structure to modify.
639 @param[in] NewCommandLine The new command line to parse and use.
640 @param[out] OldStdIn Pointer to old StdIn.
641 @param[out] OldStdOut Pointer to old StdOut.
642 @param[out] OldStdErr Pointer to old StdErr.
643 @param[out] SystemTableInfo Pointer to old system table information.
645 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
646 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
650 UpdateStdInStdOutStdErr(
651 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
652 IN CHAR16
*NewCommandLine
,
653 OUT SHELL_FILE_HANDLE
*OldStdIn
,
654 OUT SHELL_FILE_HANDLE
*OldStdOut
,
655 OUT SHELL_FILE_HANDLE
*OldStdErr
,
656 OUT SYSTEM_TABLE_INFO
*SystemTableInfo
659 CHAR16
*CommandLineCopy
;
660 CHAR16
*CommandLineWalker
;
661 CHAR16
*StdErrFileName
;
662 CHAR16
*StdOutFileName
;
663 CHAR16
*StdInFileName
;
664 CHAR16
*StdInVarName
;
665 CHAR16
*StdOutVarName
;
666 CHAR16
*StdErrVarName
;
668 SHELL_FILE_HANDLE TempHandle
;
677 CHAR16
*FirstLocation
;
683 StdOutVarName
= NULL
;
684 StdErrVarName
= NULL
;
685 StdErrFileName
= NULL
;
686 StdInFileName
= NULL
;
687 StdOutFileName
= NULL
;
690 CommandLineCopy
= NULL
;
691 FirstLocation
= NULL
;
693 if (ShellParameters
== NULL
|| SystemTableInfo
== NULL
|| OldStdIn
== NULL
|| OldStdOut
== NULL
|| OldStdErr
== NULL
) {
694 return (EFI_INVALID_PARAMETER
);
697 SystemTableInfo
->ConIn
= gST
->ConIn
;
698 SystemTableInfo
->ConInHandle
= gST
->ConsoleInHandle
;
699 SystemTableInfo
->ConOut
= gST
->ConOut
;
700 SystemTableInfo
->ConOutHandle
= gST
->ConsoleOutHandle
;
701 SystemTableInfo
->ErrOut
= gST
->StdErr
;
702 SystemTableInfo
->ErrOutHandle
= gST
->StandardErrorHandle
;
703 *OldStdIn
= ShellParameters
->StdIn
;
704 *OldStdOut
= ShellParameters
->StdOut
;
705 *OldStdErr
= ShellParameters
->StdErr
;
707 if (NewCommandLine
== NULL
) {
708 return (EFI_SUCCESS
);
711 CommandLineCopy
= StrnCatGrow(&CommandLineCopy
, NULL
, NewCommandLine
, 0);
712 if (CommandLineCopy
== NULL
) {
713 return (EFI_OUT_OF_RESOURCES
);
715 Status
= EFI_SUCCESS
;
717 FirstLocation
= CommandLineCopy
+ StrLen(CommandLineCopy
);
719 StripQuotes(CommandLineCopy
);
721 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
722 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
723 if (Split
!= NULL
&& Split
->SplitStdIn
!= NULL
) {
724 ShellParameters
->StdIn
= Split
->SplitStdIn
;
726 if (Split
!= NULL
&& Split
->SplitStdOut
!= NULL
) {
727 ShellParameters
->StdOut
= Split
->SplitStdOut
;
731 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>>v ")) != NULL
) {
732 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
733 SetMem16(CommandLineWalker
, 12, L
' ');
734 StdErrVarName
= CommandLineWalker
+= 6;
736 if (StrStr(CommandLineWalker
, L
" 2>>v ") != NULL
) {
737 Status
= EFI_NOT_FOUND
;
740 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>v ")) != NULL
) {
741 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
742 SetMem16(CommandLineWalker
, 12, L
' ');
743 StdOutVarName
= CommandLineWalker
+= 6;
745 if (StrStr(CommandLineWalker
, L
" 1>>v ") != NULL
) {
746 Status
= EFI_NOT_FOUND
;
748 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>v ")) != NULL
) {
749 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
750 SetMem16(CommandLineWalker
, 10, L
' ');
751 StdOutVarName
= CommandLineWalker
+= 5;
753 if (StrStr(CommandLineWalker
, L
" >>v ") != NULL
) {
754 Status
= EFI_NOT_FOUND
;
756 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >v ")) != NULL
) {
757 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
758 SetMem16(CommandLineWalker
, 8, L
' ');
759 StdOutVarName
= CommandLineWalker
+= 4;
761 if (StrStr(CommandLineWalker
, L
" >v ") != NULL
) {
762 Status
= EFI_NOT_FOUND
;
765 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>a ")) != NULL
) {
766 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
767 SetMem16(CommandLineWalker
, 12, L
' ');
768 StdOutFileName
= CommandLineWalker
+= 6;
771 if (StrStr(CommandLineWalker
, L
" 1>>a ") != NULL
) {
772 Status
= EFI_NOT_FOUND
;
775 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>> ")) != NULL
) {
776 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
777 SetMem16(CommandLineWalker
, 10, L
' ');
778 if (StdOutFileName
!= NULL
) {
779 Status
= EFI_INVALID_PARAMETER
;
781 StdOutFileName
= CommandLineWalker
+= 5;
784 if (StrStr(CommandLineWalker
, L
" 1>> ") != NULL
) {
785 Status
= EFI_NOT_FOUND
;
788 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >> ")) != NULL
) {
789 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
790 SetMem16(CommandLineWalker
, 8, L
' ');
791 if (StdOutFileName
!= NULL
) {
792 Status
= EFI_INVALID_PARAMETER
;
794 StdOutFileName
= CommandLineWalker
+= 4;
797 if (StrStr(CommandLineWalker
, L
" >> ") != NULL
) {
798 Status
= EFI_NOT_FOUND
;
801 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>a ")) != NULL
) {
802 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
803 SetMem16(CommandLineWalker
, 10, L
' ');
804 if (StdOutFileName
!= NULL
) {
805 Status
= EFI_INVALID_PARAMETER
;
807 StdOutFileName
= CommandLineWalker
+= 5;
811 if (StrStr(CommandLineWalker
, L
" >>a ") != NULL
) {
812 Status
= EFI_NOT_FOUND
;
815 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>a ")) != NULL
) {
816 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
817 SetMem16(CommandLineWalker
, 10, L
' ');
818 if (StdOutFileName
!= NULL
) {
819 Status
= EFI_INVALID_PARAMETER
;
821 StdOutFileName
= CommandLineWalker
+= 5;
825 if (StrStr(CommandLineWalker
, L
" 1>a ") != NULL
) {
826 Status
= EFI_NOT_FOUND
;
829 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >a ")) != NULL
) {
830 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
831 SetMem16(CommandLineWalker
, 8, L
' ');
832 if (StdOutFileName
!= NULL
) {
833 Status
= EFI_INVALID_PARAMETER
;
835 StdOutFileName
= CommandLineWalker
+= 4;
839 if (StrStr(CommandLineWalker
, L
" >a ") != NULL
) {
840 Status
= EFI_NOT_FOUND
;
843 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>> ")) != NULL
) {
844 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
845 SetMem16(CommandLineWalker
, 10, L
' ');
846 if (StdErrFileName
!= NULL
) {
847 Status
= EFI_INVALID_PARAMETER
;
849 StdErrFileName
= CommandLineWalker
+= 5;
852 if (StrStr(CommandLineWalker
, L
" 2>> ") != NULL
) {
853 Status
= EFI_NOT_FOUND
;
857 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>v ")) != NULL
) {
858 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
859 SetMem16(CommandLineWalker
, 10, L
' ');
860 if (StdErrVarName
!= NULL
) {
861 Status
= EFI_INVALID_PARAMETER
;
863 StdErrVarName
= CommandLineWalker
+= 5;
866 if (StrStr(CommandLineWalker
, L
" 2>v ") != NULL
) {
867 Status
= EFI_NOT_FOUND
;
870 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>v ")) != NULL
) {
871 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
872 SetMem16(CommandLineWalker
, 10, L
' ');
873 if (StdOutVarName
!= NULL
) {
874 Status
= EFI_INVALID_PARAMETER
;
876 StdOutVarName
= CommandLineWalker
+= 5;
879 if (StrStr(CommandLineWalker
, L
" 1>v ") != NULL
) {
880 Status
= EFI_NOT_FOUND
;
883 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>a ")) != NULL
) {
884 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
885 SetMem16(CommandLineWalker
, 10, L
' ');
886 if (StdErrFileName
!= NULL
) {
887 Status
= EFI_INVALID_PARAMETER
;
889 StdErrFileName
= CommandLineWalker
+= 5;
893 if (StrStr(CommandLineWalker
, L
" 2>a ") != NULL
) {
894 Status
= EFI_NOT_FOUND
;
897 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2> ")) != NULL
) {
898 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
899 SetMem16(CommandLineWalker
, 8, L
' ');
900 if (StdErrFileName
!= NULL
) {
901 Status
= EFI_INVALID_PARAMETER
;
903 StdErrFileName
= CommandLineWalker
+= 4;
906 if (StrStr(CommandLineWalker
, L
" 2> ") != NULL
) {
907 Status
= EFI_NOT_FOUND
;
911 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1> ")) != NULL
) {
912 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
913 SetMem16(CommandLineWalker
, 8, L
' ');
914 if (StdOutFileName
!= NULL
) {
915 Status
= EFI_INVALID_PARAMETER
;
917 StdOutFileName
= CommandLineWalker
+= 4;
920 if (StrStr(CommandLineWalker
, L
" 1> ") != NULL
) {
921 Status
= EFI_NOT_FOUND
;
925 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" > ")) != NULL
) {
926 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
927 SetMem16(CommandLineWalker
, 6, L
' ');
928 if (StdOutFileName
!= NULL
) {
929 Status
= EFI_INVALID_PARAMETER
;
931 StdOutFileName
= CommandLineWalker
+= 3;
934 if (StrStr(CommandLineWalker
, L
" > ") != NULL
) {
935 Status
= EFI_NOT_FOUND
;
939 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" < ")) != NULL
) {
940 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
941 SetMem16(CommandLineWalker
, 6, L
' ');
942 if (StdInFileName
!= NULL
) {
943 Status
= EFI_INVALID_PARAMETER
;
945 StdInFileName
= CommandLineWalker
+= 3;
947 if (StrStr(CommandLineWalker
, L
" < ") != NULL
) {
948 Status
= EFI_NOT_FOUND
;
951 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <a ")) != NULL
) {
952 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
953 SetMem16(CommandLineWalker
, 8, L
' ');
954 if (StdInFileName
!= NULL
) {
955 Status
= EFI_INVALID_PARAMETER
;
957 StdInFileName
= CommandLineWalker
+= 4;
960 if (StrStr(CommandLineWalker
, L
" <a ") != NULL
) {
961 Status
= EFI_NOT_FOUND
;
964 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <v ")) != NULL
) {
965 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
966 SetMem16(CommandLineWalker
, 8, L
' ');
967 if (StdInVarName
!= NULL
) {
968 Status
= EFI_INVALID_PARAMETER
;
970 StdInVarName
= CommandLineWalker
+= 4;
972 if (StrStr(CommandLineWalker
, L
" <v ") != NULL
) {
973 Status
= EFI_NOT_FOUND
;
978 // re-populate the string to support any filenames that were in quotes.
980 StrCpy(CommandLineCopy
, NewCommandLine
);
982 if (FirstLocation
!= CommandLineCopy
+ StrLen(CommandLineCopy
)
983 && ((UINTN
)(FirstLocation
- CommandLineCopy
) < StrLen(NewCommandLine
))
985 *(NewCommandLine
+ (UINTN
)(FirstLocation
- CommandLineCopy
)) = CHAR_NULL
;
988 if (!EFI_ERROR(Status
)) {
990 if (StdErrFileName
!= NULL
) {
991 if ((StdErrFileName
= FixFileName(StdErrFileName
)) == NULL
) {
992 Status
= EFI_INVALID_PARAMETER
;
995 if (StdOutFileName
!= NULL
) {
996 if ((StdOutFileName
= FixFileName(StdOutFileName
)) == NULL
) {
997 Status
= EFI_INVALID_PARAMETER
;
1000 if (StdInFileName
!= NULL
) {
1001 if ((StdInFileName
= FixFileName(StdInFileName
)) == NULL
) {
1002 Status
= EFI_INVALID_PARAMETER
;
1005 if (StdErrVarName
!= NULL
) {
1006 if ((StdErrVarName
= FixVarName(StdErrVarName
)) == NULL
) {
1007 Status
= EFI_INVALID_PARAMETER
;
1010 if (StdOutVarName
!= NULL
) {
1011 if ((StdOutVarName
= FixVarName(StdOutVarName
)) == NULL
) {
1012 Status
= EFI_INVALID_PARAMETER
;
1015 if (StdInVarName
!= NULL
) {
1016 if ((StdInVarName
= FixVarName(StdInVarName
)) == NULL
) {
1017 Status
= EFI_INVALID_PARAMETER
;
1022 // Verify not the same and not duplicating something from a split
1026 // Check that no 2 filenames are the same
1028 (StdErrFileName
!= NULL
&& StdOutFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdOutFileName
) == 0)
1029 ||(StdErrFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdInFileName
) == 0)
1030 ||(StdOutFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdOutFileName
, &StdInFileName
) == 0)
1032 // Check that no 2 variable names are the same
1034 ||(StdErrVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdInVarName
) == 0)
1035 ||(StdOutVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdOutVarName
, &StdInVarName
) == 0)
1036 ||(StdErrVarName
!= NULL
&& StdOutVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdOutVarName
) == 0)
1038 // When a split (using | operator) is in place some are not allowed
1040 ||(Split
!= NULL
&& Split
->SplitStdIn
!= NULL
&& (StdInVarName
!= NULL
|| StdInFileName
!= NULL
))
1041 ||(Split
!= NULL
&& Split
->SplitStdOut
!= NULL
&& (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
))
1043 // Check that nothing is trying to be output to 2 locations.
1045 ||(StdErrFileName
!= NULL
&& StdErrVarName
!= NULL
)
1046 ||(StdOutFileName
!= NULL
&& StdOutVarName
!= NULL
)
1047 ||(StdInFileName
!= NULL
&& StdInVarName
!= NULL
)
1049 // Check for no volatile environment variables
1051 ||(StdErrVarName
!= NULL
&& !IsVolatileEnv(StdErrVarName
))
1052 ||(StdOutVarName
!= NULL
&& !IsVolatileEnv(StdOutVarName
))
1054 // Cant redirect during a reconnect operation.
1056 ||(StrStr(NewCommandLine
, L
"connect -r") != NULL
1057 && (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
|| StdErrFileName
!= NULL
|| StdErrVarName
!= NULL
))
1059 // Check that filetypes (Unicode/Ascii) do not change during an append
1061 ||(StdOutFileName
!= NULL
&& OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1062 ||(StdErrFileName
!= NULL
&& ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1063 ||(StdOutFileName
!= NULL
&& !OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1064 ||(StdErrFileName
!= NULL
&& !ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1066 Status
= EFI_INVALID_PARAMETER
;
1067 ShellParameters
->StdIn
= *OldStdIn
;
1068 ShellParameters
->StdOut
= *OldStdOut
;
1069 ShellParameters
->StdErr
= *OldStdErr
;
1070 } else if (!EFI_ERROR(Status
)){
1072 // Open the Std<Whatever> and we should not have conflicts here...
1078 if (StdErrFileName
!= NULL
) {
1081 // delete existing file.
1083 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdErrFileName
);
1085 Status
= ShellOpenFileByName(StdErrFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1086 if (!ErrAppend
&& ErrUnicode
&& !EFI_ERROR(Status
)) {
1087 Status
= WriteFileTag (TempHandle
);
1089 if (!ErrUnicode
&& !EFI_ERROR(Status
)) {
1090 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1091 ASSERT(TempHandle
!= NULL
);
1093 if (!EFI_ERROR(Status
)) {
1094 ShellParameters
->StdErr
= TempHandle
;
1095 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1102 if (!EFI_ERROR(Status
) && StdOutFileName
!= NULL
) {
1105 // delete existing file.
1107 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdOutFileName
);
1109 Status
= ShellOpenFileByName(StdOutFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1110 if (TempHandle
== NULL
) {
1111 Status
= EFI_INVALID_PARAMETER
;
1113 if (StrStr(StdOutFileName
, L
"NUL")==StdOutFileName
) {
1115 } else if (!OutAppend
&& OutUnicode
&& !EFI_ERROR(Status
)) {
1116 Status
= WriteFileTag (TempHandle
);
1117 } else if (OutAppend
) {
1118 Status
= ShellInfoObject
.NewEfiShellProtocol
->GetFileSize(TempHandle
, &FileSize
);
1119 if (!EFI_ERROR(Status
)) {
1121 // When appending to a new unicode file, write the file tag.
1122 // Otherwise (ie. when appending to a new ASCII file, or an
1123 // existent file with any encoding), just seek to the end.
1125 Status
= (FileSize
== 0 && OutUnicode
) ?
1126 WriteFileTag (TempHandle
) :
1127 ShellInfoObject
.NewEfiShellProtocol
->SetFilePosition (
1132 if (!OutUnicode
&& !EFI_ERROR(Status
)) {
1133 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1134 ASSERT(TempHandle
!= NULL
);
1136 if (!EFI_ERROR(Status
)) {
1137 ShellParameters
->StdOut
= TempHandle
;
1138 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1146 if (!EFI_ERROR(Status
) && StdOutVarName
!= NULL
) {
1149 // delete existing variable.
1151 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName
, 0, L
"");
1153 TempHandle
= CreateFileInterfaceEnv(StdOutVarName
);
1154 ASSERT(TempHandle
!= NULL
);
1155 ShellParameters
->StdOut
= TempHandle
;
1156 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1162 if (!EFI_ERROR(Status
) && StdErrVarName
!= NULL
) {
1165 // delete existing variable.
1167 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName
, 0, L
"");
1169 TempHandle
= CreateFileInterfaceEnv(StdErrVarName
);
1170 ASSERT(TempHandle
!= NULL
);
1171 ShellParameters
->StdErr
= TempHandle
;
1172 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1178 if (!EFI_ERROR(Status
) && StdInVarName
!= NULL
) {
1179 TempHandle
= CreateFileInterfaceEnv(StdInVarName
);
1180 if (TempHandle
== NULL
) {
1181 Status
= EFI_OUT_OF_RESOURCES
;
1184 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1187 if (TempHandle
== NULL
|| ((EFI_FILE_PROTOCOL
*)TempHandle
)->Read(TempHandle
, &Size
, NULL
) != EFI_BUFFER_TOO_SMALL
) {
1188 Status
= EFI_INVALID_PARAMETER
;
1190 ShellParameters
->StdIn
= TempHandle
;
1191 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1197 // StdIn from a file
1199 if (!EFI_ERROR(Status
) && StdInFileName
!= NULL
) {
1200 Status
= ShellOpenFileByName(
1207 // Chop off the 0xFEFF if it's there...
1209 RemoveFileTag(&TempHandle
);
1210 } else if (!EFI_ERROR(Status
)) {
1212 // Create the ASCII->Unicode conversion layer
1214 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1216 if (!EFI_ERROR(Status
)) {
1217 ShellParameters
->StdIn
= TempHandle
;
1218 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1223 FreePool(CommandLineCopy
);
1225 CalculateEfiHdrCrc(&gST
->Hdr
);
1227 if (gST
->ConIn
== NULL
||gST
->ConOut
== NULL
) {
1228 Status
= EFI_OUT_OF_RESOURCES
;
1231 if (Status
== EFI_NOT_FOUND
) {
1232 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR
), ShellInfoObject
.HiiHandle
);
1233 } else if (EFI_ERROR(Status
)) {
1234 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_INVALID_REDIR
), ShellInfoObject
.HiiHandle
);
1241 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
1242 structure with StdIn and StdOut. The current values are de-allocated.
1244 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1245 @param[in] OldStdIn Pointer to old StdIn.
1246 @param[in] OldStdOut Pointer to old StdOut.
1247 @param[in] OldStdErr Pointer to old StdErr.
1248 @param[in] SystemTableInfo Pointer to old system table information.
1252 RestoreStdInStdOutStdErr (
1253 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1254 IN SHELL_FILE_HANDLE
*OldStdIn
,
1255 IN SHELL_FILE_HANDLE
*OldStdOut
,
1256 IN SHELL_FILE_HANDLE
*OldStdErr
,
1257 IN SYSTEM_TABLE_INFO
*SystemTableInfo
1262 if (ShellParameters
== NULL
1266 ||SystemTableInfo
== NULL
) {
1267 return (EFI_INVALID_PARAMETER
);
1269 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
1270 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
1274 if (ShellParameters
->StdIn
!= *OldStdIn
) {
1275 if ((Split
!= NULL
&& Split
->SplitStdIn
!= ShellParameters
->StdIn
) || Split
== NULL
) {
1276 gEfiShellProtocol
->CloseFile(ShellParameters
->StdIn
);
1278 ShellParameters
->StdIn
= *OldStdIn
;
1280 if (ShellParameters
->StdOut
!= *OldStdOut
) {
1281 if ((Split
!= NULL
&& Split
->SplitStdOut
!= ShellParameters
->StdOut
) || Split
== NULL
) {
1282 gEfiShellProtocol
->CloseFile(ShellParameters
->StdOut
);
1284 ShellParameters
->StdOut
= *OldStdOut
;
1286 if (ShellParameters
->StdErr
!= *OldStdErr
) {
1287 gEfiShellProtocol
->CloseFile(ShellParameters
->StdErr
);
1288 ShellParameters
->StdErr
= *OldStdErr
;
1291 if (gST
->ConIn
!= SystemTableInfo
->ConIn
) {
1292 CloseSimpleTextInOnFile(gST
->ConIn
);
1293 gST
->ConIn
= SystemTableInfo
->ConIn
;
1294 gST
->ConsoleInHandle
= SystemTableInfo
->ConInHandle
;
1296 if (gST
->ConOut
!= SystemTableInfo
->ConOut
) {
1297 CloseSimpleTextOutOnFile(gST
->ConOut
);
1298 gST
->ConOut
= SystemTableInfo
->ConOut
;
1299 gST
->ConsoleOutHandle
= SystemTableInfo
->ConOutHandle
;
1301 if (gST
->StdErr
!= SystemTableInfo
->ErrOut
) {
1302 CloseSimpleTextOutOnFile(gST
->StdErr
);
1303 gST
->StdErr
= SystemTableInfo
->ErrOut
;
1304 gST
->StandardErrorHandle
= SystemTableInfo
->ErrOutHandle
;
1307 CalculateEfiHdrCrc(&gST
->Hdr
);
1309 return (EFI_SUCCESS
);
1312 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1313 structure by parsing NewCommandLine. The current values are returned to the
1316 If OldArgv or OldArgc is NULL then that value is not returned.
1318 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1319 @param[in] NewCommandLine The new command line to parse and use.
1320 @param[out] OldArgv Pointer to old list of parameters.
1321 @param[out] OldArgc Pointer to old number of items in Argv list.
1323 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
1324 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1329 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1330 IN CONST CHAR16
*NewCommandLine
,
1331 OUT CHAR16
***OldArgv OPTIONAL
,
1332 OUT UINTN
*OldArgc OPTIONAL
1335 ASSERT(ShellParameters
!= NULL
);
1337 if (OldArgc
!= NULL
) {
1338 *OldArgc
= ShellParameters
->Argc
;
1340 if (OldArgc
!= NULL
) {
1341 *OldArgv
= ShellParameters
->Argv
;
1344 return (ParseCommandLineToArgs(NewCommandLine
, &(ShellParameters
->Argv
), &(ShellParameters
->Argc
)));
1348 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1349 structure with Argv and Argc. The current values are de-allocated and the
1350 OldArgv must not be deallocated by the caller.
1352 @param[in, out] ShellParameters pointer to parameter structure to modify
1353 @param[in] OldArgv pointer to old list of parameters
1354 @param[in] OldArgc pointer to old number of items in Argv list
1359 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1360 IN CHAR16
***OldArgv
,
1365 ASSERT(ShellParameters
!= NULL
);
1366 ASSERT(OldArgv
!= NULL
);
1367 ASSERT(OldArgc
!= NULL
);
1369 if (ShellParameters
->Argv
!= NULL
) {
1370 for ( LoopCounter
= 0
1371 ; LoopCounter
< ShellParameters
->Argc
1374 FreePool(ShellParameters
->Argv
[LoopCounter
]);
1376 FreePool(ShellParameters
->Argv
);
1378 ShellParameters
->Argv
= *OldArgv
;
1380 ShellParameters
->Argc
= *OldArgc
;