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 - 2015, 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's end from a command line string.
23 @param[in] String the string to parse
28 IN CONST CHAR16
*String
32 CONST CHAR16
*CloseQuote
;
34 First
= FindFirstCharacter(String
, L
" \"", L
'^');
37 // nothing, all one parameter remaining
39 if (*First
== CHAR_NULL
) {
44 // If space before a quote (or neither found, i.e. both CHAR_NULL),
45 // then that's the end.
51 CloseQuote
= FindFirstCharacter (First
+1, L
"\"", L
'^');
54 // We did not find a terminator...
56 if (*CloseQuote
== CHAR_NULL
) {
60 return (FindEndOfParameter (CloseQuote
+1));
64 Return the next parameter from a command line string.
66 This function moves the next parameter from Walker into TempParameter and moves
67 Walker up past that parameter for recursive calling. When the final parameter
68 is moved *Walker will be set to NULL;
70 Temp Parameter must be large enough to hold the parameter before calling this
73 This will also remove all remaining ^ characters after processing.
75 @param[in, out] Walker pointer to string of command line. Adjusted to
76 reminaing command line on return
77 @param[in, out] TempParameter pointer to string of command line item extracted.
78 @param[in] Length buffer size of TempParameter.
80 @return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.
81 @return EFI_NOT_FOUND A closing " could not be found on the specified string
86 IN OUT CHAR16
**Walker
,
87 IN OUT CHAR16
**TempParameter
,
91 CONST CHAR16
*NextDelim
;
95 ||TempParameter
== NULL
96 ||*TempParameter
== NULL
98 return (EFI_INVALID_PARAMETER
);
103 // make sure we dont have any leading spaces
105 while ((*Walker
)[0] == L
' ') {
110 // make sure we still have some params now...
112 if (StrLen(*Walker
) == 0) {
116 return (EFI_INVALID_PARAMETER
);
119 NextDelim
= FindEndOfParameter(*Walker
);
121 if (NextDelim
== NULL
){
125 return (EFI_NOT_FOUND
);
128 StrnCpy(*TempParameter
, (*Walker
), NextDelim
- *Walker
);
131 // Add a CHAR_NULL if we didnt get one via the copy
133 if (*NextDelim
!= CHAR_NULL
) {
134 (*TempParameter
)[NextDelim
- *Walker
] = CHAR_NULL
;
138 // Update Walker for the next iteration through the function
140 *Walker
= (CHAR16
*)NextDelim
;
143 // Remove any non-escaped quotes in the string
144 // Remove any remaining escape characters in the string
146 for (NextDelim
= FindFirstCharacter(*TempParameter
, L
"\"^", CHAR_NULL
)
147 ; *NextDelim
!= CHAR_NULL
148 ; NextDelim
= FindFirstCharacter(NextDelim
, L
"\"^", CHAR_NULL
)
150 if (*NextDelim
== L
'^') {
153 // eliminate the escape ^
155 CopyMem ((CHAR16
*)NextDelim
, NextDelim
+ 1, StrSize (NextDelim
+ 1));
157 } else if (*NextDelim
== L
'\"') {
160 // eliminate the unescaped quote
162 CopyMem ((CHAR16
*)NextDelim
, NextDelim
+ 1, StrSize (NextDelim
+ 1));
170 Function to populate Argc and Argv.
172 This function parses the CommandLine and divides it into standard C style Argc/Argv
173 parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space
174 delimited and quote surrounded parameter definition.
176 All special character processing (alias, environment variable, redirection,
177 etc... must be complete before calling this API.
179 @param[in] CommandLine String of command line to parse
180 @param[in, out] Argv pointer to array of strings; one for each parameter
181 @param[in, out] Argc pointer to number of strings in Argv array
183 @return EFI_SUCCESS the operation was sucessful
184 @return EFI_OUT_OF_RESOURCES a memory allocation failed.
188 ParseCommandLineToArgs(
189 IN CONST CHAR16
*CommandLine
,
190 IN OUT CHAR16
***Argv
,
195 CHAR16
*TempParameter
;
200 ASSERT(Argc
!= NULL
);
201 ASSERT(Argv
!= NULL
);
203 if (CommandLine
== NULL
|| StrLen(CommandLine
)==0) {
206 return (EFI_SUCCESS
);
209 Size
= StrSize(CommandLine
);
210 TempParameter
= AllocateZeroPool(Size
);
211 if (TempParameter
== NULL
) {
212 return (EFI_OUT_OF_RESOURCES
);
216 , Walker
= (CHAR16
*)CommandLine
217 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
220 if (EFI_ERROR(GetNextParameter(&Walker
, &TempParameter
, Size
))) {
226 // lets allocate the pointer array
228 (*Argv
) = AllocateZeroPool((Count
)*sizeof(CHAR16
*));
230 SHELL_FREE_NON_NULL(TempParameter
);
231 return (EFI_OUT_OF_RESOURCES
);
235 Walker
= (CHAR16
*)CommandLine
;
236 while(Walker
!= NULL
&& *Walker
!= CHAR_NULL
) {
237 SetMem16(TempParameter
, Size
, CHAR_NULL
);
238 if (EFI_ERROR(GetNextParameter(&Walker
, &TempParameter
, Size
))) {
239 SHELL_FREE_NON_NULL(TempParameter
);
240 return (EFI_INVALID_PARAMETER
);
243 NewParam
= AllocateCopyPool(StrSize(TempParameter
), TempParameter
);
244 if (NewParam
== NULL
){
245 SHELL_FREE_NON_NULL(TempParameter
);
246 return (EFI_OUT_OF_RESOURCES
);
248 ((CHAR16
**)(*Argv
))[(*Argc
)] = NewParam
;
251 ASSERT(Count
>= (*Argc
));
252 SHELL_FREE_NON_NULL(TempParameter
);
253 return (EFI_SUCCESS
);
257 creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then
258 installs it on our handle and if there is an existing version of the protocol
259 that one is cached for removal later.
261 @param[in, out] NewShellParameters on a successful return, a pointer to pointer
262 to the newly installed interface.
263 @param[in, out] RootShellInstance on a successful return, pointer to boolean.
264 TRUE if this is the root shell instance.
266 @retval EFI_SUCCESS the operation completed successfully.
267 @return other the operation failed.
268 @sa ReinstallProtocolInterface
269 @sa InstallProtocolInterface
270 @sa ParseCommandLineToArgs
274 CreatePopulateInstallShellParametersProtocol (
275 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
**NewShellParameters
,
276 IN OUT BOOLEAN
*RootShellInstance
280 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
281 CHAR16
*FullCommandLine
;
285 FullCommandLine
= NULL
;
289 // Assert for valid parameters
291 ASSERT(NewShellParameters
!= NULL
);
292 ASSERT(RootShellInstance
!= NULL
);
295 // See if we have a shell parameters placed on us
297 Status
= gBS
->OpenProtocol (
299 &gEfiShellParametersProtocolGuid
,
300 (VOID
**) &ShellInfoObject
.OldShellParameters
,
303 EFI_OPEN_PROTOCOL_GET_PROTOCOL
306 // if we don't then we must be the root shell (error is expected)
308 if (EFI_ERROR (Status
)) {
309 *RootShellInstance
= TRUE
;
313 // Allocate the new structure
315 *NewShellParameters
= AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL
));
316 if ((*NewShellParameters
) == NULL
) {
317 return (EFI_OUT_OF_RESOURCES
);
321 // get loaded image protocol
323 Status
= gBS
->OpenProtocol (
325 &gEfiLoadedImageProtocolGuid
,
326 (VOID
**) &LoadedImage
,
329 EFI_OPEN_PROTOCOL_GET_PROTOCOL
331 ASSERT_EFI_ERROR(Status
);
333 // Build the full command line
335 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
336 if (Status
== EFI_BUFFER_TOO_SMALL
) {
337 FullCommandLine
= AllocateZeroPool(Size
+ LoadedImage
->LoadOptionsSize
);
338 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
340 if (Status
== EFI_NOT_FOUND
) {
342 // no parameters via environment... ok
345 if (EFI_ERROR(Status
)) {
349 if (Size
== 0 && LoadedImage
->LoadOptionsSize
!= 0) {
350 ASSERT(FullCommandLine
== NULL
);
352 // Now we need to include a NULL terminator in the size.
354 Size
= LoadedImage
->LoadOptionsSize
+ sizeof(FullCommandLine
[0]);
355 FullCommandLine
= AllocateZeroPool(Size
);
357 if (FullCommandLine
!= NULL
) {
358 CopyMem (FullCommandLine
, LoadedImage
->LoadOptions
, LoadedImage
->LoadOptionsSize
);
360 // Populate Argc and Argv
362 Status
= ParseCommandLineToArgs(FullCommandLine
,
363 &(*NewShellParameters
)->Argv
,
364 &(*NewShellParameters
)->Argc
);
366 FreePool(FullCommandLine
);
368 ASSERT_EFI_ERROR(Status
);
370 (*NewShellParameters
)->Argv
= NULL
;
371 (*NewShellParameters
)->Argc
= 0;
375 // Populate the 3 faked file systems...
377 if (*RootShellInstance
) {
378 (*NewShellParameters
)->StdIn
= &FileInterfaceStdIn
;
379 (*NewShellParameters
)->StdOut
= &FileInterfaceStdOut
;
380 (*NewShellParameters
)->StdErr
= &FileInterfaceStdErr
;
381 Status
= gBS
->InstallProtocolInterface(&gImageHandle
,
382 &gEfiShellParametersProtocolGuid
,
383 EFI_NATIVE_INTERFACE
,
384 (VOID
*)(*NewShellParameters
));
387 // copy from the existing ones
389 (*NewShellParameters
)->StdIn
= ShellInfoObject
.OldShellParameters
->StdIn
;
390 (*NewShellParameters
)->StdOut
= ShellInfoObject
.OldShellParameters
->StdOut
;
391 (*NewShellParameters
)->StdErr
= ShellInfoObject
.OldShellParameters
->StdErr
;
392 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
393 &gEfiShellParametersProtocolGuid
,
394 (VOID
*)ShellInfoObject
.OldShellParameters
,
395 (VOID
*)(*NewShellParameters
));
402 frees all memory used by createion and installation of shell parameters protocol
403 and if there was an old version installed it will restore that one.
405 @param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
408 @retval EFI_SUCCESS the cleanup was successful
409 @return other the cleanup failed
410 @sa ReinstallProtocolInterface
411 @sa UninstallProtocolInterface
415 CleanUpShellParametersProtocol (
416 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*NewShellParameters
423 // If the old exists we need to restore it
425 if (ShellInfoObject
.OldShellParameters
!= NULL
) {
426 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
427 &gEfiShellParametersProtocolGuid
,
428 (VOID
*)NewShellParameters
,
429 (VOID
*)ShellInfoObject
.OldShellParameters
);
430 DEBUG_CODE(ShellInfoObject
.OldShellParameters
= NULL
;);
433 // No old one, just uninstall us...
435 Status
= gBS
->UninstallProtocolInterface(gImageHandle
,
436 &gEfiShellParametersProtocolGuid
,
437 (VOID
*)NewShellParameters
);
439 if (NewShellParameters
->Argv
!= NULL
) {
440 for ( LoopCounter
= 0
441 ; LoopCounter
< NewShellParameters
->Argc
444 FreePool(NewShellParameters
->Argv
[LoopCounter
]);
446 FreePool(NewShellParameters
->Argv
);
448 FreePool(NewShellParameters
);
453 Determin if a file name represents a unicode file.
455 @param[in] FileName Pointer to the filename to open.
457 @retval EFI_SUCCESS The file is a unicode file.
458 @return An error upon failure.
463 IN CONST CHAR16
*FileName
466 SHELL_FILE_HANDLE Handle
;
468 UINT64 OriginalFilePosition
;
472 Status
= gEfiShellProtocol
->OpenFileByName(FileName
, &Handle
, EFI_FILE_MODE_READ
);
473 if (EFI_ERROR(Status
)) {
476 gEfiShellProtocol
->GetFilePosition(Handle
, &OriginalFilePosition
);
477 gEfiShellProtocol
->SetFilePosition(Handle
, 0);
478 CharSize
= sizeof(CHAR16
);
479 Status
= gEfiShellProtocol
->ReadFile(Handle
, &CharSize
, &CharBuffer
);
480 if (EFI_ERROR(Status
) || CharBuffer
!= gUnicodeFileTag
) {
481 Status
= EFI_BUFFER_TOO_SMALL
;
483 gEfiShellProtocol
->SetFilePosition(Handle
, OriginalFilePosition
);
484 gEfiShellProtocol
->CloseFile(Handle
);
489 Strips out quotes sections of a string.
491 All of the characters between quotes is replaced with spaces.
493 @param[in, out] TheString A pointer to the string to update.
498 IN OUT CHAR16
*TheString
503 for (RemoveNow
= FALSE
; TheString
!= NULL
&& *TheString
!= CHAR_NULL
; TheString
++) {
504 if (*TheString
== L
'^' && *(TheString
+ 1) == L
'\"') {
506 } else if (*TheString
== L
'\"') {
507 RemoveNow
= (BOOLEAN
)!RemoveNow
;
508 } else if (RemoveNow
) {
515 Calcualte the 32-bit CRC in a EFI table using the service provided by the
518 @param Hdr Pointer to an EFI standard header
523 IN OUT EFI_TABLE_HEADER
*Hdr
531 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
532 // Crc will come back as zero if we set it to zero here
535 gBS
->CalculateCrc32 ((UINT8
*)Hdr
, Hdr
->HeaderSize
, &Crc
);
540 Fix a string to only have the file name, removing starting at the first space of whatever is quoted.
542 @param[in] FileName The filename to start with.
544 @retval NULL FileName was invalid.
545 @return The modified FileName.
554 CHAR16
*TempLocation
;
556 if (FileName
== NULL
) {
560 if (FileName
[0] == L
'\"') {
562 if ((TempLocation
= StrStr(Copy
, L
"\"")) != NULL
) {
563 TempLocation
[0] = CHAR_NULL
;
567 while(Copy
[0] == L
' ') {
570 if ((TempLocation
= StrStr(Copy
, L
" ")) != NULL
) {
571 TempLocation
[0] = CHAR_NULL
;
575 if (Copy
[0] == CHAR_NULL
) {
583 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 %.
585 @param[in] FileName The filename to start with.
587 @retval NULL FileName was invalid.
588 @return The modified FileName.
597 CHAR16
*TempLocation
;
601 if (FileName
[0] == L
'%') {
603 if ((TempLocation
= StrStr(Copy
, L
"%")) != NULL
) {
604 TempLocation
[0] = CHAR_NULL
;
608 return (FixFileName(Copy
));
612 Remove the unicode file tag from the begining of the file buffer since that will not be
615 @param[in] Handle Pointer to the handle of the file to be processed.
617 @retval EFI_SUCCESS The unicode file tag has been moved successfully.
622 IN SHELL_FILE_HANDLE
*Handle
628 CharSize
= sizeof(CHAR16
);
630 gEfiShellProtocol
->ReadFile(*Handle
, &CharSize
, &CharBuffer
);
631 if (CharBuffer
!= gUnicodeFileTag
) {
632 gEfiShellProtocol
->SetFilePosition(*Handle
, 0);
634 return (EFI_SUCCESS
);
638 Write the unicode file tag to the specified file.
640 It is the caller's responsibility to ensure that
641 ShellInfoObject.NewEfiShellProtocol has been initialized before calling this
644 @param[in] FileHandle The file to write the unicode file tag to.
646 @return Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.
650 IN SHELL_FILE_HANDLE FileHandle
657 FileTag
= gUnicodeFileTag
;
658 Size
= sizeof FileTag
;
659 Status
= ShellInfoObject
.NewEfiShellProtocol
->WriteFile (FileHandle
, &Size
,
661 ASSERT (EFI_ERROR (Status
) || Size
== sizeof FileTag
);
667 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
668 structure by parsing NewCommandLine. The current values are returned to the
671 This will also update the system table.
673 @param[in, out] ShellParameters Pointer to parameter structure to modify.
674 @param[in] NewCommandLine The new command line to parse and use.
675 @param[out] OldStdIn Pointer to old StdIn.
676 @param[out] OldStdOut Pointer to old StdOut.
677 @param[out] OldStdErr Pointer to old StdErr.
678 @param[out] SystemTableInfo Pointer to old system table information.
680 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
681 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
685 UpdateStdInStdOutStdErr(
686 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
687 IN CHAR16
*NewCommandLine
,
688 OUT SHELL_FILE_HANDLE
*OldStdIn
,
689 OUT SHELL_FILE_HANDLE
*OldStdOut
,
690 OUT SHELL_FILE_HANDLE
*OldStdErr
,
691 OUT SYSTEM_TABLE_INFO
*SystemTableInfo
694 CHAR16
*CommandLineCopy
;
695 CHAR16
*CommandLineWalker
;
696 CHAR16
*StdErrFileName
;
697 CHAR16
*StdOutFileName
;
698 CHAR16
*StdInFileName
;
699 CHAR16
*StdInVarName
;
700 CHAR16
*StdOutVarName
;
701 CHAR16
*StdErrVarName
;
703 SHELL_FILE_HANDLE TempHandle
;
712 CHAR16
*FirstLocation
;
718 StdOutVarName
= NULL
;
719 StdErrVarName
= NULL
;
720 StdErrFileName
= NULL
;
721 StdInFileName
= NULL
;
722 StdOutFileName
= NULL
;
725 CommandLineCopy
= NULL
;
726 FirstLocation
= NULL
;
728 if (ShellParameters
== NULL
|| SystemTableInfo
== NULL
|| OldStdIn
== NULL
|| OldStdOut
== NULL
|| OldStdErr
== NULL
) {
729 return (EFI_INVALID_PARAMETER
);
732 SystemTableInfo
->ConIn
= gST
->ConIn
;
733 SystemTableInfo
->ConInHandle
= gST
->ConsoleInHandle
;
734 SystemTableInfo
->ConOut
= gST
->ConOut
;
735 SystemTableInfo
->ConOutHandle
= gST
->ConsoleOutHandle
;
736 SystemTableInfo
->ErrOut
= gST
->StdErr
;
737 SystemTableInfo
->ErrOutHandle
= gST
->StandardErrorHandle
;
738 *OldStdIn
= ShellParameters
->StdIn
;
739 *OldStdOut
= ShellParameters
->StdOut
;
740 *OldStdErr
= ShellParameters
->StdErr
;
742 if (NewCommandLine
== NULL
) {
743 return (EFI_SUCCESS
);
746 CommandLineCopy
= StrnCatGrow(&CommandLineCopy
, NULL
, NewCommandLine
, 0);
747 if (CommandLineCopy
== NULL
) {
748 return (EFI_OUT_OF_RESOURCES
);
750 Status
= EFI_SUCCESS
;
752 FirstLocation
= CommandLineCopy
+ StrLen(CommandLineCopy
);
754 StripQuotes(CommandLineCopy
);
756 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
757 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
758 if (Split
!= NULL
&& Split
->SplitStdIn
!= NULL
) {
759 ShellParameters
->StdIn
= Split
->SplitStdIn
;
761 if (Split
!= NULL
&& Split
->SplitStdOut
!= NULL
) {
762 ShellParameters
->StdOut
= Split
->SplitStdOut
;
766 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>>v ")) != NULL
) {
767 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
768 SetMem16(CommandLineWalker
, 12, L
' ');
769 StdErrVarName
= CommandLineWalker
+= 6;
771 if (StrStr(CommandLineWalker
, L
" 2>>v ") != NULL
) {
772 Status
= EFI_NOT_FOUND
;
775 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>v ")) != NULL
) {
776 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
777 SetMem16(CommandLineWalker
, 12, L
' ');
778 StdOutVarName
= CommandLineWalker
+= 6;
780 if (StrStr(CommandLineWalker
, L
" 1>>v ") != NULL
) {
781 Status
= EFI_NOT_FOUND
;
783 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>v ")) != NULL
) {
784 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
785 SetMem16(CommandLineWalker
, 10, L
' ');
786 StdOutVarName
= CommandLineWalker
+= 5;
788 if (StrStr(CommandLineWalker
, L
" >>v ") != NULL
) {
789 Status
= EFI_NOT_FOUND
;
791 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >v ")) != NULL
) {
792 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
793 SetMem16(CommandLineWalker
, 8, L
' ');
794 StdOutVarName
= CommandLineWalker
+= 4;
796 if (StrStr(CommandLineWalker
, L
" >v ") != NULL
) {
797 Status
= EFI_NOT_FOUND
;
800 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>a ")) != NULL
) {
801 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
802 SetMem16(CommandLineWalker
, 12, L
' ');
803 StdOutFileName
= CommandLineWalker
+= 6;
806 if (StrStr(CommandLineWalker
, L
" 1>>a ") != NULL
) {
807 Status
= EFI_NOT_FOUND
;
810 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>> ")) != NULL
) {
811 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
812 SetMem16(CommandLineWalker
, 10, L
' ');
813 if (StdOutFileName
!= NULL
) {
814 Status
= EFI_INVALID_PARAMETER
;
816 StdOutFileName
= CommandLineWalker
+= 5;
819 if (StrStr(CommandLineWalker
, L
" 1>> ") != NULL
) {
820 Status
= EFI_NOT_FOUND
;
823 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >> ")) != NULL
) {
824 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
825 SetMem16(CommandLineWalker
, 8, L
' ');
826 if (StdOutFileName
!= NULL
) {
827 Status
= EFI_INVALID_PARAMETER
;
829 StdOutFileName
= CommandLineWalker
+= 4;
832 if (StrStr(CommandLineWalker
, L
" >> ") != NULL
) {
833 Status
= EFI_NOT_FOUND
;
836 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>a ")) != NULL
) {
837 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
838 SetMem16(CommandLineWalker
, 10, L
' ');
839 if (StdOutFileName
!= NULL
) {
840 Status
= EFI_INVALID_PARAMETER
;
842 StdOutFileName
= CommandLineWalker
+= 5;
846 if (StrStr(CommandLineWalker
, L
" >>a ") != NULL
) {
847 Status
= EFI_NOT_FOUND
;
850 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>a ")) != NULL
) {
851 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
852 SetMem16(CommandLineWalker
, 10, L
' ');
853 if (StdOutFileName
!= NULL
) {
854 Status
= EFI_INVALID_PARAMETER
;
856 StdOutFileName
= CommandLineWalker
+= 5;
860 if (StrStr(CommandLineWalker
, L
" 1>a ") != NULL
) {
861 Status
= EFI_NOT_FOUND
;
864 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >a ")) != NULL
) {
865 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
866 SetMem16(CommandLineWalker
, 8, L
' ');
867 if (StdOutFileName
!= NULL
) {
868 Status
= EFI_INVALID_PARAMETER
;
870 StdOutFileName
= CommandLineWalker
+= 4;
874 if (StrStr(CommandLineWalker
, L
" >a ") != NULL
) {
875 Status
= EFI_NOT_FOUND
;
878 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>> ")) != NULL
) {
879 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
880 SetMem16(CommandLineWalker
, 10, L
' ');
881 if (StdErrFileName
!= NULL
) {
882 Status
= EFI_INVALID_PARAMETER
;
884 StdErrFileName
= CommandLineWalker
+= 5;
887 if (StrStr(CommandLineWalker
, L
" 2>> ") != NULL
) {
888 Status
= EFI_NOT_FOUND
;
892 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>v ")) != NULL
) {
893 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
894 SetMem16(CommandLineWalker
, 10, L
' ');
895 if (StdErrVarName
!= NULL
) {
896 Status
= EFI_INVALID_PARAMETER
;
898 StdErrVarName
= CommandLineWalker
+= 5;
901 if (StrStr(CommandLineWalker
, L
" 2>v ") != NULL
) {
902 Status
= EFI_NOT_FOUND
;
905 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>v ")) != NULL
) {
906 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
907 SetMem16(CommandLineWalker
, 10, L
' ');
908 if (StdOutVarName
!= NULL
) {
909 Status
= EFI_INVALID_PARAMETER
;
911 StdOutVarName
= CommandLineWalker
+= 5;
914 if (StrStr(CommandLineWalker
, L
" 1>v ") != NULL
) {
915 Status
= EFI_NOT_FOUND
;
918 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>a ")) != NULL
) {
919 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
920 SetMem16(CommandLineWalker
, 10, L
' ');
921 if (StdErrFileName
!= NULL
) {
922 Status
= EFI_INVALID_PARAMETER
;
924 StdErrFileName
= CommandLineWalker
+= 5;
928 if (StrStr(CommandLineWalker
, L
" 2>a ") != NULL
) {
929 Status
= EFI_NOT_FOUND
;
932 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2> ")) != NULL
) {
933 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
934 SetMem16(CommandLineWalker
, 8, L
' ');
935 if (StdErrFileName
!= NULL
) {
936 Status
= EFI_INVALID_PARAMETER
;
938 StdErrFileName
= CommandLineWalker
+= 4;
941 if (StrStr(CommandLineWalker
, L
" 2> ") != NULL
) {
942 Status
= EFI_NOT_FOUND
;
946 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1> ")) != NULL
) {
947 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
948 SetMem16(CommandLineWalker
, 8, L
' ');
949 if (StdOutFileName
!= NULL
) {
950 Status
= EFI_INVALID_PARAMETER
;
952 StdOutFileName
= CommandLineWalker
+= 4;
955 if (StrStr(CommandLineWalker
, L
" 1> ") != NULL
) {
956 Status
= EFI_NOT_FOUND
;
960 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" > ")) != NULL
) {
961 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
962 SetMem16(CommandLineWalker
, 6, L
' ');
963 if (StdOutFileName
!= NULL
) {
964 Status
= EFI_INVALID_PARAMETER
;
966 StdOutFileName
= CommandLineWalker
+= 3;
969 if (StrStr(CommandLineWalker
, L
" > ") != NULL
) {
970 Status
= EFI_NOT_FOUND
;
974 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" < ")) != NULL
) {
975 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
976 SetMem16(CommandLineWalker
, 6, L
' ');
977 if (StdInFileName
!= NULL
) {
978 Status
= EFI_INVALID_PARAMETER
;
980 StdInFileName
= CommandLineWalker
+= 3;
982 if (StrStr(CommandLineWalker
, L
" < ") != NULL
) {
983 Status
= EFI_NOT_FOUND
;
986 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <a ")) != NULL
) {
987 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
988 SetMem16(CommandLineWalker
, 8, L
' ');
989 if (StdInFileName
!= NULL
) {
990 Status
= EFI_INVALID_PARAMETER
;
992 StdInFileName
= CommandLineWalker
+= 4;
995 if (StrStr(CommandLineWalker
, L
" <a ") != NULL
) {
996 Status
= EFI_NOT_FOUND
;
999 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <v ")) != NULL
) {
1000 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
1001 SetMem16(CommandLineWalker
, 8, L
' ');
1002 if (StdInVarName
!= NULL
) {
1003 Status
= EFI_INVALID_PARAMETER
;
1005 StdInVarName
= CommandLineWalker
+= 4;
1007 if (StrStr(CommandLineWalker
, L
" <v ") != NULL
) {
1008 Status
= EFI_NOT_FOUND
;
1013 // re-populate the string to support any filenames that were in quotes.
1015 StrnCpy(CommandLineCopy
, NewCommandLine
, StrLen(NewCommandLine
));
1017 if (FirstLocation
!= CommandLineCopy
+ StrLen(CommandLineCopy
)
1018 && ((UINTN
)(FirstLocation
- CommandLineCopy
) < StrLen(NewCommandLine
))
1020 *(NewCommandLine
+ (UINTN
)(FirstLocation
- CommandLineCopy
)) = CHAR_NULL
;
1023 if (!EFI_ERROR(Status
)) {
1025 if (StdErrFileName
!= NULL
) {
1026 if ((StdErrFileName
= FixFileName(StdErrFileName
)) == NULL
) {
1027 Status
= EFI_INVALID_PARAMETER
;
1030 if (StdOutFileName
!= NULL
) {
1031 if ((StdOutFileName
= FixFileName(StdOutFileName
)) == NULL
) {
1032 Status
= EFI_INVALID_PARAMETER
;
1035 if (StdInFileName
!= NULL
) {
1036 if ((StdInFileName
= FixFileName(StdInFileName
)) == NULL
) {
1037 Status
= EFI_INVALID_PARAMETER
;
1040 if (StdErrVarName
!= NULL
) {
1041 if ((StdErrVarName
= FixVarName(StdErrVarName
)) == NULL
) {
1042 Status
= EFI_INVALID_PARAMETER
;
1045 if (StdOutVarName
!= NULL
) {
1046 if ((StdOutVarName
= FixVarName(StdOutVarName
)) == NULL
) {
1047 Status
= EFI_INVALID_PARAMETER
;
1050 if (StdInVarName
!= NULL
) {
1051 if ((StdInVarName
= FixVarName(StdInVarName
)) == NULL
) {
1052 Status
= EFI_INVALID_PARAMETER
;
1057 // Verify not the same and not duplicating something from a split
1061 // Check that no 2 filenames are the same
1063 (StdErrFileName
!= NULL
&& StdOutFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdOutFileName
) == 0)
1064 ||(StdErrFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdInFileName
) == 0)
1065 ||(StdOutFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdOutFileName
, &StdInFileName
) == 0)
1067 // Check that no 2 variable names are the same
1069 ||(StdErrVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdInVarName
) == 0)
1070 ||(StdOutVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdOutVarName
, &StdInVarName
) == 0)
1071 ||(StdErrVarName
!= NULL
&& StdOutVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdOutVarName
) == 0)
1073 // When a split (using | operator) is in place some are not allowed
1075 ||(Split
!= NULL
&& Split
->SplitStdIn
!= NULL
&& (StdInVarName
!= NULL
|| StdInFileName
!= NULL
))
1076 ||(Split
!= NULL
&& Split
->SplitStdOut
!= NULL
&& (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
))
1078 // Check that nothing is trying to be output to 2 locations.
1080 ||(StdErrFileName
!= NULL
&& StdErrVarName
!= NULL
)
1081 ||(StdOutFileName
!= NULL
&& StdOutVarName
!= NULL
)
1082 ||(StdInFileName
!= NULL
&& StdInVarName
!= NULL
)
1084 // Check for no volatile environment variables
1086 ||(StdErrVarName
!= NULL
&& !IsVolatileEnv(StdErrVarName
))
1087 ||(StdOutVarName
!= NULL
&& !IsVolatileEnv(StdOutVarName
))
1089 // Cant redirect during a reconnect operation.
1091 ||(StrStr(NewCommandLine
, L
"connect -r") != NULL
1092 && (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
|| StdErrFileName
!= NULL
|| StdErrVarName
!= NULL
))
1094 // Check that filetypes (Unicode/Ascii) do not change during an append
1096 ||(StdOutFileName
!= NULL
&& OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1097 ||(StdErrFileName
!= NULL
&& ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1098 ||(StdOutFileName
!= NULL
&& !OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1099 ||(StdErrFileName
!= NULL
&& !ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1101 Status
= EFI_INVALID_PARAMETER
;
1102 ShellParameters
->StdIn
= *OldStdIn
;
1103 ShellParameters
->StdOut
= *OldStdOut
;
1104 ShellParameters
->StdErr
= *OldStdErr
;
1105 } else if (!EFI_ERROR(Status
)){
1107 // Open the Std<Whatever> and we should not have conflicts here...
1113 if (StdErrFileName
!= NULL
) {
1116 // delete existing file.
1118 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdErrFileName
);
1120 Status
= ShellOpenFileByName(StdErrFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1121 if (!ErrAppend
&& ErrUnicode
&& !EFI_ERROR(Status
)) {
1122 Status
= WriteFileTag (TempHandle
);
1124 if (!ErrUnicode
&& !EFI_ERROR(Status
)) {
1125 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1126 ASSERT(TempHandle
!= NULL
);
1128 if (!EFI_ERROR(Status
)) {
1129 ShellParameters
->StdErr
= TempHandle
;
1130 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1137 if (!EFI_ERROR(Status
) && StdOutFileName
!= NULL
) {
1140 // delete existing file.
1142 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdOutFileName
);
1144 Status
= ShellOpenFileByName(StdOutFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1145 if (TempHandle
== NULL
) {
1146 Status
= EFI_INVALID_PARAMETER
;
1148 if (StrStr(StdOutFileName
, L
"NUL")==StdOutFileName
) {
1150 } else if (!OutAppend
&& OutUnicode
&& !EFI_ERROR(Status
)) {
1151 Status
= WriteFileTag (TempHandle
);
1152 } else if (OutAppend
) {
1153 Status
= ShellInfoObject
.NewEfiShellProtocol
->GetFileSize(TempHandle
, &FileSize
);
1154 if (!EFI_ERROR(Status
)) {
1156 // When appending to a new unicode file, write the file tag.
1157 // Otherwise (ie. when appending to a new ASCII file, or an
1158 // existent file with any encoding), just seek to the end.
1160 Status
= (FileSize
== 0 && OutUnicode
) ?
1161 WriteFileTag (TempHandle
) :
1162 ShellInfoObject
.NewEfiShellProtocol
->SetFilePosition (
1167 if (!OutUnicode
&& !EFI_ERROR(Status
)) {
1168 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1169 ASSERT(TempHandle
!= NULL
);
1171 if (!EFI_ERROR(Status
)) {
1172 ShellParameters
->StdOut
= TempHandle
;
1173 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1181 if (!EFI_ERROR(Status
) && StdOutVarName
!= NULL
) {
1184 // delete existing variable.
1186 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName
, 0, L
"");
1188 TempHandle
= CreateFileInterfaceEnv(StdOutVarName
);
1189 ASSERT(TempHandle
!= NULL
);
1190 ShellParameters
->StdOut
= TempHandle
;
1191 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1197 if (!EFI_ERROR(Status
) && StdErrVarName
!= NULL
) {
1200 // delete existing variable.
1202 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName
, 0, L
"");
1204 TempHandle
= CreateFileInterfaceEnv(StdErrVarName
);
1205 ASSERT(TempHandle
!= NULL
);
1206 ShellParameters
->StdErr
= TempHandle
;
1207 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1213 if (!EFI_ERROR(Status
) && StdInVarName
!= NULL
) {
1214 TempHandle
= CreateFileInterfaceEnv(StdInVarName
);
1215 if (TempHandle
== NULL
) {
1216 Status
= EFI_OUT_OF_RESOURCES
;
1219 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1222 if (TempHandle
== NULL
|| ((EFI_FILE_PROTOCOL
*)TempHandle
)->Read(TempHandle
, &Size
, NULL
) != EFI_BUFFER_TOO_SMALL
) {
1223 Status
= EFI_INVALID_PARAMETER
;
1225 ShellParameters
->StdIn
= TempHandle
;
1226 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1232 // StdIn from a file
1234 if (!EFI_ERROR(Status
) && StdInFileName
!= NULL
) {
1235 Status
= ShellOpenFileByName(
1242 // Chop off the 0xFEFF if it's there...
1244 RemoveFileTag(&TempHandle
);
1245 } else if (!EFI_ERROR(Status
)) {
1247 // Create the ASCII->Unicode conversion layer
1249 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1251 if (!EFI_ERROR(Status
)) {
1252 ShellParameters
->StdIn
= TempHandle
;
1253 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1258 FreePool(CommandLineCopy
);
1260 CalculateEfiHdrCrc(&gST
->Hdr
);
1262 if (gST
->ConIn
== NULL
||gST
->ConOut
== NULL
) {
1263 Status
= EFI_OUT_OF_RESOURCES
;
1266 if (Status
== EFI_NOT_FOUND
) {
1267 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR
), ShellInfoObject
.HiiHandle
);
1268 } else if (EFI_ERROR(Status
)) {
1269 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_INVALID_REDIR
), ShellInfoObject
.HiiHandle
);
1276 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
1277 structure with StdIn and StdOut. The current values are de-allocated.
1279 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1280 @param[in] OldStdIn Pointer to old StdIn.
1281 @param[in] OldStdOut Pointer to old StdOut.
1282 @param[in] OldStdErr Pointer to old StdErr.
1283 @param[in] SystemTableInfo Pointer to old system table information.
1287 RestoreStdInStdOutStdErr (
1288 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1289 IN SHELL_FILE_HANDLE
*OldStdIn
,
1290 IN SHELL_FILE_HANDLE
*OldStdOut
,
1291 IN SHELL_FILE_HANDLE
*OldStdErr
,
1292 IN SYSTEM_TABLE_INFO
*SystemTableInfo
1297 if (ShellParameters
== NULL
1301 ||SystemTableInfo
== NULL
) {
1302 return (EFI_INVALID_PARAMETER
);
1304 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
1305 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
1309 if (ShellParameters
->StdIn
!= *OldStdIn
) {
1310 if ((Split
!= NULL
&& Split
->SplitStdIn
!= ShellParameters
->StdIn
) || Split
== NULL
) {
1311 gEfiShellProtocol
->CloseFile(ShellParameters
->StdIn
);
1313 ShellParameters
->StdIn
= *OldStdIn
;
1315 if (ShellParameters
->StdOut
!= *OldStdOut
) {
1316 if ((Split
!= NULL
&& Split
->SplitStdOut
!= ShellParameters
->StdOut
) || Split
== NULL
) {
1317 gEfiShellProtocol
->CloseFile(ShellParameters
->StdOut
);
1319 ShellParameters
->StdOut
= *OldStdOut
;
1321 if (ShellParameters
->StdErr
!= *OldStdErr
) {
1322 gEfiShellProtocol
->CloseFile(ShellParameters
->StdErr
);
1323 ShellParameters
->StdErr
= *OldStdErr
;
1326 if (gST
->ConIn
!= SystemTableInfo
->ConIn
) {
1327 CloseSimpleTextInOnFile(gST
->ConIn
);
1328 gST
->ConIn
= SystemTableInfo
->ConIn
;
1329 gST
->ConsoleInHandle
= SystemTableInfo
->ConInHandle
;
1331 if (gST
->ConOut
!= SystemTableInfo
->ConOut
) {
1332 CloseSimpleTextOutOnFile(gST
->ConOut
);
1333 gST
->ConOut
= SystemTableInfo
->ConOut
;
1334 gST
->ConsoleOutHandle
= SystemTableInfo
->ConOutHandle
;
1336 if (gST
->StdErr
!= SystemTableInfo
->ErrOut
) {
1337 CloseSimpleTextOutOnFile(gST
->StdErr
);
1338 gST
->StdErr
= SystemTableInfo
->ErrOut
;
1339 gST
->StandardErrorHandle
= SystemTableInfo
->ErrOutHandle
;
1342 CalculateEfiHdrCrc(&gST
->Hdr
);
1344 return (EFI_SUCCESS
);
1347 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1348 structure by parsing NewCommandLine. The current values are returned to the
1351 If OldArgv or OldArgc is NULL then that value is not returned.
1353 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1354 @param[in] NewCommandLine The new command line to parse and use.
1355 @param[out] OldArgv Pointer to old list of parameters.
1356 @param[out] OldArgc Pointer to old number of items in Argv list.
1358 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
1359 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1364 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1365 IN CONST CHAR16
*NewCommandLine
,
1366 OUT CHAR16
***OldArgv OPTIONAL
,
1367 OUT UINTN
*OldArgc OPTIONAL
1370 ASSERT(ShellParameters
!= NULL
);
1372 if (OldArgc
!= NULL
) {
1373 *OldArgc
= ShellParameters
->Argc
;
1375 if (OldArgc
!= NULL
) {
1376 *OldArgv
= ShellParameters
->Argv
;
1379 return (ParseCommandLineToArgs(NewCommandLine
, &(ShellParameters
->Argv
), &(ShellParameters
->Argc
)));
1383 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1384 structure with Argv and Argc. The current values are de-allocated and the
1385 OldArgv must not be deallocated by the caller.
1387 @param[in, out] ShellParameters pointer to parameter structure to modify
1388 @param[in] OldArgv pointer to old list of parameters
1389 @param[in] OldArgc pointer to old number of items in Argv list
1394 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1395 IN CHAR16
***OldArgv
,
1400 ASSERT(ShellParameters
!= NULL
);
1401 ASSERT(OldArgv
!= NULL
);
1402 ASSERT(OldArgc
!= NULL
);
1404 if (ShellParameters
->Argv
!= NULL
) {
1405 for ( LoopCounter
= 0
1406 ; LoopCounter
< ShellParameters
->Argc
1409 FreePool(ShellParameters
->Argv
[LoopCounter
]);
1411 FreePool(ShellParameters
->Argv
);
1413 ShellParameters
->Argv
= *OldArgv
;
1415 ShellParameters
->Argc
= *OldArgc
;