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.
614 IN SHELL_FILE_HANDLE FileHandle
621 FileTag
= gUnicodeFileTag
;
622 Size
= sizeof FileTag
;
623 Status
= ShellInfoObject
.NewEfiShellProtocol
->WriteFile (FileHandle
, &Size
,
625 ASSERT (EFI_ERROR (Status
) || Size
== sizeof FileTag
);
631 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
632 structure by parsing NewCommandLine. The current values are returned to the
635 This will also update the system table.
637 @param[in, out] ShellParameters Pointer to parameter structure to modify.
638 @param[in] NewCommandLine The new command line to parse and use.
639 @param[out] OldStdIn Pointer to old StdIn.
640 @param[out] OldStdOut Pointer to old StdOut.
641 @param[out] OldStdErr Pointer to old StdErr.
642 @param[out] SystemTableInfo Pointer to old system table information.
644 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
645 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
649 UpdateStdInStdOutStdErr(
650 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
651 IN CHAR16
*NewCommandLine
,
652 OUT SHELL_FILE_HANDLE
*OldStdIn
,
653 OUT SHELL_FILE_HANDLE
*OldStdOut
,
654 OUT SHELL_FILE_HANDLE
*OldStdErr
,
655 OUT SYSTEM_TABLE_INFO
*SystemTableInfo
658 CHAR16
*CommandLineCopy
;
659 CHAR16
*CommandLineWalker
;
660 CHAR16
*StdErrFileName
;
661 CHAR16
*StdOutFileName
;
662 CHAR16
*StdInFileName
;
663 CHAR16
*StdInVarName
;
664 CHAR16
*StdOutVarName
;
665 CHAR16
*StdErrVarName
;
667 SHELL_FILE_HANDLE TempHandle
;
676 CHAR16
*FirstLocation
;
682 StdOutVarName
= NULL
;
683 StdErrVarName
= NULL
;
684 StdErrFileName
= NULL
;
685 StdInFileName
= NULL
;
686 StdOutFileName
= NULL
;
689 CommandLineCopy
= NULL
;
690 FirstLocation
= NULL
;
692 if (ShellParameters
== NULL
|| SystemTableInfo
== NULL
|| OldStdIn
== NULL
|| OldStdOut
== NULL
|| OldStdErr
== NULL
) {
693 return (EFI_INVALID_PARAMETER
);
696 SystemTableInfo
->ConIn
= gST
->ConIn
;
697 SystemTableInfo
->ConInHandle
= gST
->ConsoleInHandle
;
698 SystemTableInfo
->ConOut
= gST
->ConOut
;
699 SystemTableInfo
->ConOutHandle
= gST
->ConsoleOutHandle
;
700 SystemTableInfo
->ErrOut
= gST
->StdErr
;
701 SystemTableInfo
->ErrOutHandle
= gST
->StandardErrorHandle
;
702 *OldStdIn
= ShellParameters
->StdIn
;
703 *OldStdOut
= ShellParameters
->StdOut
;
704 *OldStdErr
= ShellParameters
->StdErr
;
706 if (NewCommandLine
== NULL
) {
707 return (EFI_SUCCESS
);
710 CommandLineCopy
= StrnCatGrow(&CommandLineCopy
, NULL
, NewCommandLine
, 0);
711 if (CommandLineCopy
== NULL
) {
712 return (EFI_OUT_OF_RESOURCES
);
714 Status
= EFI_SUCCESS
;
716 FirstLocation
= CommandLineCopy
+ StrLen(CommandLineCopy
);
718 StripQuotes(CommandLineCopy
);
720 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
721 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
722 if (Split
!= NULL
&& Split
->SplitStdIn
!= NULL
) {
723 ShellParameters
->StdIn
= Split
->SplitStdIn
;
725 if (Split
!= NULL
&& Split
->SplitStdOut
!= NULL
) {
726 ShellParameters
->StdOut
= Split
->SplitStdOut
;
730 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>>v ")) != NULL
) {
731 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
732 SetMem16(CommandLineWalker
, 12, L
' ');
733 StdErrVarName
= CommandLineWalker
+= 6;
735 if (StrStr(CommandLineWalker
, L
" 2>>v ") != NULL
) {
736 Status
= EFI_NOT_FOUND
;
739 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>v ")) != NULL
) {
740 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
741 SetMem16(CommandLineWalker
, 12, L
' ');
742 StdOutVarName
= CommandLineWalker
+= 6;
744 if (StrStr(CommandLineWalker
, L
" 1>>v ") != NULL
) {
745 Status
= EFI_NOT_FOUND
;
747 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>v ")) != NULL
) {
748 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
749 SetMem16(CommandLineWalker
, 10, L
' ');
750 StdOutVarName
= CommandLineWalker
+= 5;
752 if (StrStr(CommandLineWalker
, L
" >>v ") != NULL
) {
753 Status
= EFI_NOT_FOUND
;
755 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >v ")) != NULL
) {
756 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
757 SetMem16(CommandLineWalker
, 8, L
' ');
758 StdOutVarName
= CommandLineWalker
+= 4;
760 if (StrStr(CommandLineWalker
, L
" >v ") != NULL
) {
761 Status
= EFI_NOT_FOUND
;
764 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>a ")) != NULL
) {
765 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
766 SetMem16(CommandLineWalker
, 12, L
' ');
767 StdOutFileName
= CommandLineWalker
+= 6;
770 if (StrStr(CommandLineWalker
, L
" 1>>a ") != NULL
) {
771 Status
= EFI_NOT_FOUND
;
774 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>> ")) != NULL
) {
775 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
776 SetMem16(CommandLineWalker
, 10, L
' ');
777 if (StdOutFileName
!= NULL
) {
778 Status
= EFI_INVALID_PARAMETER
;
780 StdOutFileName
= CommandLineWalker
+= 5;
783 if (StrStr(CommandLineWalker
, L
" 1>> ") != NULL
) {
784 Status
= EFI_NOT_FOUND
;
787 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >> ")) != NULL
) {
788 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
789 SetMem16(CommandLineWalker
, 8, L
' ');
790 if (StdOutFileName
!= NULL
) {
791 Status
= EFI_INVALID_PARAMETER
;
793 StdOutFileName
= CommandLineWalker
+= 4;
796 if (StrStr(CommandLineWalker
, L
" >> ") != NULL
) {
797 Status
= EFI_NOT_FOUND
;
800 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>a ")) != NULL
) {
801 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
802 SetMem16(CommandLineWalker
, 10, L
' ');
803 if (StdOutFileName
!= NULL
) {
804 Status
= EFI_INVALID_PARAMETER
;
806 StdOutFileName
= CommandLineWalker
+= 5;
810 if (StrStr(CommandLineWalker
, L
" >>a ") != NULL
) {
811 Status
= EFI_NOT_FOUND
;
814 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>a ")) != NULL
) {
815 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
816 SetMem16(CommandLineWalker
, 10, L
' ');
817 if (StdOutFileName
!= NULL
) {
818 Status
= EFI_INVALID_PARAMETER
;
820 StdOutFileName
= CommandLineWalker
+= 5;
824 if (StrStr(CommandLineWalker
, L
" 1>a ") != NULL
) {
825 Status
= EFI_NOT_FOUND
;
828 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >a ")) != NULL
) {
829 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
830 SetMem16(CommandLineWalker
, 8, L
' ');
831 if (StdOutFileName
!= NULL
) {
832 Status
= EFI_INVALID_PARAMETER
;
834 StdOutFileName
= CommandLineWalker
+= 4;
838 if (StrStr(CommandLineWalker
, L
" >a ") != NULL
) {
839 Status
= EFI_NOT_FOUND
;
842 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>> ")) != NULL
) {
843 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
844 SetMem16(CommandLineWalker
, 10, L
' ');
845 if (StdErrFileName
!= NULL
) {
846 Status
= EFI_INVALID_PARAMETER
;
848 StdErrFileName
= CommandLineWalker
+= 5;
851 if (StrStr(CommandLineWalker
, L
" 2>> ") != NULL
) {
852 Status
= EFI_NOT_FOUND
;
856 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>v ")) != NULL
) {
857 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
858 SetMem16(CommandLineWalker
, 10, L
' ');
859 if (StdErrVarName
!= NULL
) {
860 Status
= EFI_INVALID_PARAMETER
;
862 StdErrVarName
= CommandLineWalker
+= 5;
865 if (StrStr(CommandLineWalker
, L
" 2>v ") != NULL
) {
866 Status
= EFI_NOT_FOUND
;
869 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>v ")) != NULL
) {
870 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
871 SetMem16(CommandLineWalker
, 10, L
' ');
872 if (StdOutVarName
!= NULL
) {
873 Status
= EFI_INVALID_PARAMETER
;
875 StdOutVarName
= CommandLineWalker
+= 5;
878 if (StrStr(CommandLineWalker
, L
" 1>v ") != NULL
) {
879 Status
= EFI_NOT_FOUND
;
882 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>a ")) != NULL
) {
883 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
884 SetMem16(CommandLineWalker
, 10, L
' ');
885 if (StdErrFileName
!= NULL
) {
886 Status
= EFI_INVALID_PARAMETER
;
888 StdErrFileName
= CommandLineWalker
+= 5;
892 if (StrStr(CommandLineWalker
, L
" 2>a ") != NULL
) {
893 Status
= EFI_NOT_FOUND
;
896 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2> ")) != NULL
) {
897 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
898 SetMem16(CommandLineWalker
, 8, L
' ');
899 if (StdErrFileName
!= NULL
) {
900 Status
= EFI_INVALID_PARAMETER
;
902 StdErrFileName
= CommandLineWalker
+= 4;
905 if (StrStr(CommandLineWalker
, L
" 2> ") != NULL
) {
906 Status
= EFI_NOT_FOUND
;
910 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1> ")) != NULL
) {
911 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
912 SetMem16(CommandLineWalker
, 8, L
' ');
913 if (StdOutFileName
!= NULL
) {
914 Status
= EFI_INVALID_PARAMETER
;
916 StdOutFileName
= CommandLineWalker
+= 4;
919 if (StrStr(CommandLineWalker
, L
" 1> ") != NULL
) {
920 Status
= EFI_NOT_FOUND
;
924 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" > ")) != NULL
) {
925 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
926 SetMem16(CommandLineWalker
, 6, L
' ');
927 if (StdOutFileName
!= NULL
) {
928 Status
= EFI_INVALID_PARAMETER
;
930 StdOutFileName
= CommandLineWalker
+= 3;
933 if (StrStr(CommandLineWalker
, L
" > ") != NULL
) {
934 Status
= EFI_NOT_FOUND
;
938 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" < ")) != NULL
) {
939 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
940 SetMem16(CommandLineWalker
, 6, L
' ');
941 if (StdInFileName
!= NULL
) {
942 Status
= EFI_INVALID_PARAMETER
;
944 StdInFileName
= CommandLineWalker
+= 3;
946 if (StrStr(CommandLineWalker
, L
" < ") != NULL
) {
947 Status
= EFI_NOT_FOUND
;
950 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <a ")) != NULL
) {
951 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
952 SetMem16(CommandLineWalker
, 8, L
' ');
953 if (StdInFileName
!= NULL
) {
954 Status
= EFI_INVALID_PARAMETER
;
956 StdInFileName
= CommandLineWalker
+= 4;
959 if (StrStr(CommandLineWalker
, L
" <a ") != NULL
) {
960 Status
= EFI_NOT_FOUND
;
963 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <v ")) != NULL
) {
964 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
965 SetMem16(CommandLineWalker
, 8, L
' ');
966 if (StdInVarName
!= NULL
) {
967 Status
= EFI_INVALID_PARAMETER
;
969 StdInVarName
= CommandLineWalker
+= 4;
971 if (StrStr(CommandLineWalker
, L
" <v ") != NULL
) {
972 Status
= EFI_NOT_FOUND
;
977 // re-populate the string to support any filenames that were in quotes.
979 StrCpy(CommandLineCopy
, NewCommandLine
);
981 if (FirstLocation
!= CommandLineCopy
+ StrLen(CommandLineCopy
)
982 && ((UINTN
)(FirstLocation
- CommandLineCopy
) < StrLen(NewCommandLine
))
984 *(NewCommandLine
+ (UINTN
)(FirstLocation
- CommandLineCopy
)) = CHAR_NULL
;
987 if (!EFI_ERROR(Status
)) {
989 if (StdErrFileName
!= NULL
) {
990 if ((StdErrFileName
= FixFileName(StdErrFileName
)) == NULL
) {
991 Status
= EFI_INVALID_PARAMETER
;
994 if (StdOutFileName
!= NULL
) {
995 if ((StdOutFileName
= FixFileName(StdOutFileName
)) == NULL
) {
996 Status
= EFI_INVALID_PARAMETER
;
999 if (StdInFileName
!= NULL
) {
1000 if ((StdInFileName
= FixFileName(StdInFileName
)) == NULL
) {
1001 Status
= EFI_INVALID_PARAMETER
;
1004 if (StdErrVarName
!= NULL
) {
1005 if ((StdErrVarName
= FixVarName(StdErrVarName
)) == NULL
) {
1006 Status
= EFI_INVALID_PARAMETER
;
1009 if (StdOutVarName
!= NULL
) {
1010 if ((StdOutVarName
= FixVarName(StdOutVarName
)) == NULL
) {
1011 Status
= EFI_INVALID_PARAMETER
;
1014 if (StdInVarName
!= NULL
) {
1015 if ((StdInVarName
= FixVarName(StdInVarName
)) == NULL
) {
1016 Status
= EFI_INVALID_PARAMETER
;
1021 // Verify not the same and not duplicating something from a split
1025 // Check that no 2 filenames are the same
1027 (StdErrFileName
!= NULL
&& StdOutFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdOutFileName
) == 0)
1028 ||(StdErrFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdInFileName
) == 0)
1029 ||(StdOutFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdOutFileName
, &StdInFileName
) == 0)
1031 // Check that no 2 variable names are the same
1033 ||(StdErrVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdInVarName
) == 0)
1034 ||(StdOutVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdOutVarName
, &StdInVarName
) == 0)
1035 ||(StdErrVarName
!= NULL
&& StdOutVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdOutVarName
) == 0)
1037 // When a split (using | operator) is in place some are not allowed
1039 ||(Split
!= NULL
&& Split
->SplitStdIn
!= NULL
&& (StdInVarName
!= NULL
|| StdInFileName
!= NULL
))
1040 ||(Split
!= NULL
&& Split
->SplitStdOut
!= NULL
&& (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
))
1042 // Check that nothing is trying to be output to 2 locations.
1044 ||(StdErrFileName
!= NULL
&& StdErrVarName
!= NULL
)
1045 ||(StdOutFileName
!= NULL
&& StdOutVarName
!= NULL
)
1046 ||(StdInFileName
!= NULL
&& StdInVarName
!= NULL
)
1048 // Check for no volatile environment variables
1050 ||(StdErrVarName
!= NULL
&& !IsVolatileEnv(StdErrVarName
))
1051 ||(StdOutVarName
!= NULL
&& !IsVolatileEnv(StdOutVarName
))
1053 // Cant redirect during a reconnect operation.
1055 ||(StrStr(NewCommandLine
, L
"connect -r") != NULL
1056 && (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
|| StdErrFileName
!= NULL
|| StdErrVarName
!= NULL
))
1058 // Check that filetypes (Unicode/Ascii) do not change during an append
1060 ||(StdOutFileName
!= NULL
&& OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1061 ||(StdErrFileName
!= NULL
&& ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1062 ||(StdOutFileName
!= NULL
&& !OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1063 ||(StdErrFileName
!= NULL
&& !ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1065 Status
= EFI_INVALID_PARAMETER
;
1066 ShellParameters
->StdIn
= *OldStdIn
;
1067 ShellParameters
->StdOut
= *OldStdOut
;
1068 ShellParameters
->StdErr
= *OldStdErr
;
1069 } else if (!EFI_ERROR(Status
)){
1071 // Open the Std<Whatever> and we should not have conflicts here...
1077 if (StdErrFileName
!= NULL
) {
1080 // delete existing file.
1082 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdErrFileName
);
1084 Status
= ShellOpenFileByName(StdErrFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1085 if (!ErrAppend
&& ErrUnicode
&& !EFI_ERROR(Status
)) {
1086 Status
= WriteFileTag (TempHandle
);
1088 if (!ErrUnicode
&& !EFI_ERROR(Status
)) {
1089 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1090 ASSERT(TempHandle
!= NULL
);
1092 if (!EFI_ERROR(Status
)) {
1093 ShellParameters
->StdErr
= TempHandle
;
1094 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1101 if (!EFI_ERROR(Status
) && StdOutFileName
!= NULL
) {
1104 // delete existing file.
1106 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdOutFileName
);
1108 Status
= ShellOpenFileByName(StdOutFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1109 if (TempHandle
== NULL
) {
1110 Status
= EFI_INVALID_PARAMETER
;
1112 if (StrStr(StdOutFileName
, L
"NUL")==StdOutFileName
) {
1114 } else if (!OutAppend
&& OutUnicode
&& !EFI_ERROR(Status
)) {
1115 Status
= WriteFileTag (TempHandle
);
1116 } else if (OutAppend
) {
1117 Status
= ShellInfoObject
.NewEfiShellProtocol
->GetFileSize(TempHandle
, &FileSize
);
1118 if (!EFI_ERROR(Status
)) {
1120 // When appending to a new unicode file, write the file tag.
1121 // Otherwise (ie. when appending to a new ASCII file, or an
1122 // existent file with any encoding), just seek to the end.
1124 Status
= (FileSize
== 0 && OutUnicode
) ?
1125 WriteFileTag (TempHandle
) :
1126 ShellInfoObject
.NewEfiShellProtocol
->SetFilePosition (
1131 if (!OutUnicode
&& !EFI_ERROR(Status
)) {
1132 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1133 ASSERT(TempHandle
!= NULL
);
1135 if (!EFI_ERROR(Status
)) {
1136 ShellParameters
->StdOut
= TempHandle
;
1137 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1145 if (!EFI_ERROR(Status
) && StdOutVarName
!= NULL
) {
1148 // delete existing variable.
1150 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName
, 0, L
"");
1152 TempHandle
= CreateFileInterfaceEnv(StdOutVarName
);
1153 ASSERT(TempHandle
!= NULL
);
1154 ShellParameters
->StdOut
= TempHandle
;
1155 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1161 if (!EFI_ERROR(Status
) && StdErrVarName
!= NULL
) {
1164 // delete existing variable.
1166 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName
, 0, L
"");
1168 TempHandle
= CreateFileInterfaceEnv(StdErrVarName
);
1169 ASSERT(TempHandle
!= NULL
);
1170 ShellParameters
->StdErr
= TempHandle
;
1171 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1177 if (!EFI_ERROR(Status
) && StdInVarName
!= NULL
) {
1178 TempHandle
= CreateFileInterfaceEnv(StdInVarName
);
1179 if (TempHandle
== NULL
) {
1180 Status
= EFI_OUT_OF_RESOURCES
;
1183 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1186 if (TempHandle
== NULL
|| ((EFI_FILE_PROTOCOL
*)TempHandle
)->Read(TempHandle
, &Size
, NULL
) != EFI_BUFFER_TOO_SMALL
) {
1187 Status
= EFI_INVALID_PARAMETER
;
1189 ShellParameters
->StdIn
= TempHandle
;
1190 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1196 // StdIn from a file
1198 if (!EFI_ERROR(Status
) && StdInFileName
!= NULL
) {
1199 Status
= ShellOpenFileByName(
1206 // Chop off the 0xFEFF if it's there...
1208 RemoveFileTag(&TempHandle
);
1209 } else if (!EFI_ERROR(Status
)) {
1211 // Create the ASCII->Unicode conversion layer
1213 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1215 if (!EFI_ERROR(Status
)) {
1216 ShellParameters
->StdIn
= TempHandle
;
1217 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1222 FreePool(CommandLineCopy
);
1224 CalculateEfiHdrCrc(&gST
->Hdr
);
1226 if (gST
->ConIn
== NULL
||gST
->ConOut
== NULL
) {
1227 Status
= EFI_OUT_OF_RESOURCES
;
1230 if (Status
== EFI_NOT_FOUND
) {
1231 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR
), ShellInfoObject
.HiiHandle
);
1232 } else if (EFI_ERROR(Status
)) {
1233 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_INVALID_REDIR
), ShellInfoObject
.HiiHandle
);
1240 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
1241 structure with StdIn and StdOut. The current values are de-allocated.
1243 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1244 @param[in] OldStdIn Pointer to old StdIn.
1245 @param[in] OldStdOut Pointer to old StdOut.
1246 @param[in] OldStdErr Pointer to old StdErr.
1247 @param[in] SystemTableInfo Pointer to old system table information.
1251 RestoreStdInStdOutStdErr (
1252 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1253 IN SHELL_FILE_HANDLE
*OldStdIn
,
1254 IN SHELL_FILE_HANDLE
*OldStdOut
,
1255 IN SHELL_FILE_HANDLE
*OldStdErr
,
1256 IN SYSTEM_TABLE_INFO
*SystemTableInfo
1261 if (ShellParameters
== NULL
1265 ||SystemTableInfo
== NULL
) {
1266 return (EFI_INVALID_PARAMETER
);
1268 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
1269 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
1273 if (ShellParameters
->StdIn
!= *OldStdIn
) {
1274 if ((Split
!= NULL
&& Split
->SplitStdIn
!= ShellParameters
->StdIn
) || Split
== NULL
) {
1275 gEfiShellProtocol
->CloseFile(ShellParameters
->StdIn
);
1277 ShellParameters
->StdIn
= *OldStdIn
;
1279 if (ShellParameters
->StdOut
!= *OldStdOut
) {
1280 if ((Split
!= NULL
&& Split
->SplitStdOut
!= ShellParameters
->StdOut
) || Split
== NULL
) {
1281 gEfiShellProtocol
->CloseFile(ShellParameters
->StdOut
);
1283 ShellParameters
->StdOut
= *OldStdOut
;
1285 if (ShellParameters
->StdErr
!= *OldStdErr
) {
1286 gEfiShellProtocol
->CloseFile(ShellParameters
->StdErr
);
1287 ShellParameters
->StdErr
= *OldStdErr
;
1290 if (gST
->ConIn
!= SystemTableInfo
->ConIn
) {
1291 CloseSimpleTextInOnFile(gST
->ConIn
);
1292 gST
->ConIn
= SystemTableInfo
->ConIn
;
1293 gST
->ConsoleInHandle
= SystemTableInfo
->ConInHandle
;
1295 if (gST
->ConOut
!= SystemTableInfo
->ConOut
) {
1296 CloseSimpleTextOutOnFile(gST
->ConOut
);
1297 gST
->ConOut
= SystemTableInfo
->ConOut
;
1298 gST
->ConsoleOutHandle
= SystemTableInfo
->ConOutHandle
;
1300 if (gST
->StdErr
!= SystemTableInfo
->ErrOut
) {
1301 CloseSimpleTextOutOnFile(gST
->StdErr
);
1302 gST
->StdErr
= SystemTableInfo
->ErrOut
;
1303 gST
->StandardErrorHandle
= SystemTableInfo
->ErrOutHandle
;
1306 CalculateEfiHdrCrc(&gST
->Hdr
);
1308 return (EFI_SUCCESS
);
1311 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1312 structure by parsing NewCommandLine. The current values are returned to the
1315 If OldArgv or OldArgc is NULL then that value is not returned.
1317 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1318 @param[in] NewCommandLine The new command line to parse and use.
1319 @param[out] OldArgv Pointer to old list of parameters.
1320 @param[out] OldArgc Pointer to old number of items in Argv list.
1322 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
1323 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1328 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1329 IN CONST CHAR16
*NewCommandLine
,
1330 OUT CHAR16
***OldArgv OPTIONAL
,
1331 OUT UINTN
*OldArgc OPTIONAL
1334 ASSERT(ShellParameters
!= NULL
);
1336 if (OldArgc
!= NULL
) {
1337 *OldArgc
= ShellParameters
->Argc
;
1339 if (OldArgc
!= NULL
) {
1340 *OldArgv
= ShellParameters
->Argv
;
1343 return (ParseCommandLineToArgs(NewCommandLine
, &(ShellParameters
->Argv
), &(ShellParameters
->Argc
)));
1347 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1348 structure with Argv and Argc. The current values are de-allocated and the
1349 OldArgv must not be deallocated by the caller.
1351 @param[in, out] ShellParameters pointer to parameter structure to modify
1352 @param[in] OldArgv pointer to old list of parameters
1353 @param[in] OldArgc pointer to old number of items in Argv list
1358 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1359 IN CHAR16
***OldArgv
,
1364 ASSERT(ShellParameters
!= NULL
);
1365 ASSERT(OldArgv
!= NULL
);
1366 ASSERT(OldArgc
!= NULL
);
1368 if (ShellParameters
->Argv
!= NULL
) {
1369 for ( LoopCounter
= 0
1370 ; LoopCounter
< ShellParameters
->Argc
1373 FreePool(ShellParameters
->Argv
[LoopCounter
]);
1375 FreePool(ShellParameters
->Argv
);
1377 ShellParameters
->Argv
= *OldArgv
;
1379 ShellParameters
->Argc
= *OldArgc
;