2 Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,
3 manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 Copyright (C) 2014, Red Hat, Inc.
7 (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>
8 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
15 BOOLEAN AsciiRedirection
= FALSE
;
18 Return the next parameter's end from a command line string.
20 @param[in] String the string to parse
24 IN CONST CHAR16
*String
28 CONST CHAR16
*CloseQuote
;
30 First
= FindFirstCharacter(String
, L
" \"", L
'^');
33 // nothing, all one parameter remaining
35 if (*First
== CHAR_NULL
) {
40 // If space before a quote (or neither found, i.e. both CHAR_NULL),
41 // then that's the end.
47 CloseQuote
= FindFirstCharacter (First
+1, L
"\"", L
'^');
50 // We did not find a terminator...
52 if (*CloseQuote
== CHAR_NULL
) {
56 return (FindEndOfParameter (CloseQuote
+1));
60 Return the next parameter from a command line string.
62 This function moves the next parameter from Walker into TempParameter and moves
63 Walker up past that parameter for recursive calling. When the final parameter
64 is moved *Walker will be set to NULL;
66 Temp Parameter must be large enough to hold the parameter before calling this
69 This will also remove all remaining ^ characters after processing.
71 @param[in, out] Walker pointer to string of command line. Adjusted to
72 reminaing command line on return
73 @param[in, out] TempParameter pointer to string of command line item extracted.
74 @param[in] Length buffer size of TempParameter.
75 @param[in] StripQuotation if TRUE then strip the quotation marks surrounding
78 @return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.
79 @return EFI_NOT_FOUND A closing " could not be found on the specified string
83 IN OUT CHAR16
**Walker
,
84 IN OUT CHAR16
**TempParameter
,
85 IN CONST UINTN Length
,
86 IN BOOLEAN StripQuotation
89 CONST CHAR16
*NextDelim
;
93 ||TempParameter
== NULL
94 ||*TempParameter
== NULL
96 return (EFI_INVALID_PARAMETER
);
101 // make sure we dont have any leading spaces
103 while ((*Walker
)[0] == L
' ') {
108 // make sure we still have some params now...
110 if (StrLen(*Walker
) == 0) {
114 return (EFI_INVALID_PARAMETER
);
117 NextDelim
= FindEndOfParameter(*Walker
);
119 if (NextDelim
== NULL
){
123 return (EFI_NOT_FOUND
);
126 StrnCpyS(*TempParameter
, Length
/ sizeof(CHAR16
), (*Walker
), NextDelim
- *Walker
);
129 // Add a CHAR_NULL if we didnt get one via the copy
131 if (*NextDelim
!= CHAR_NULL
) {
132 (*TempParameter
)[NextDelim
- *Walker
] = CHAR_NULL
;
136 // Update Walker for the next iteration through the function
138 *Walker
= (CHAR16
*)NextDelim
;
141 // Remove any non-escaped quotes in the string
142 // Remove any remaining escape characters in the string
144 for (NextDelim
= FindFirstCharacter(*TempParameter
, L
"\"^", CHAR_NULL
)
145 ; *NextDelim
!= CHAR_NULL
146 ; NextDelim
= FindFirstCharacter(NextDelim
, L
"\"^", CHAR_NULL
)
148 if (*NextDelim
== L
'^') {
151 // eliminate the escape ^
153 CopyMem ((CHAR16
*)NextDelim
, NextDelim
+ 1, StrSize (NextDelim
+ 1));
155 } else if (*NextDelim
== L
'\"') {
158 // eliminate the unescaped quote
160 if (StripQuotation
) {
161 CopyMem ((CHAR16
*)NextDelim
, NextDelim
+ 1, StrSize (NextDelim
+ 1));
172 Function to populate Argc and Argv.
174 This function parses the CommandLine and divides it into standard C style Argc/Argv
175 parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space
176 delimited and quote surrounded parameter definition.
178 All special character processing (alias, environment variable, redirection,
179 etc... must be complete before calling this API.
181 @param[in] CommandLine String of command line to parse
182 @param[in] StripQuotation if TRUE then strip the quotation marks surrounding
184 @param[in, out] Argv pointer to array of strings; one for each parameter
185 @param[in, out] Argc pointer to number of strings in Argv array
187 @return EFI_SUCCESS the operation was sucessful
188 @return EFI_OUT_OF_RESOURCES a memory allocation failed.
191 ParseCommandLineToArgs(
192 IN CONST CHAR16
*CommandLine
,
193 IN BOOLEAN StripQuotation
,
194 IN OUT CHAR16
***Argv
,
199 CHAR16
*TempParameter
;
202 CHAR16
*NewCommandLine
;
206 ASSERT(Argc
!= NULL
);
207 ASSERT(Argv
!= NULL
);
209 if (CommandLine
== NULL
|| StrLen(CommandLine
)==0) {
212 return (EFI_SUCCESS
);
215 NewCommandLine
= AllocateCopyPool(StrSize(CommandLine
), CommandLine
);
216 if (NewCommandLine
== NULL
){
217 return (EFI_OUT_OF_RESOURCES
);
220 TrimSpaces(&NewCommandLine
);
221 Size
= StrSize(NewCommandLine
);
222 TempParameter
= AllocateZeroPool(Size
);
223 if (TempParameter
== NULL
) {
224 SHELL_FREE_NON_NULL(NewCommandLine
);
225 return (EFI_OUT_OF_RESOURCES
);
229 , Walker
= (CHAR16
*)NewCommandLine
230 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
233 if (EFI_ERROR(GetNextParameter(&Walker
, &TempParameter
, Size
, TRUE
))) {
239 // lets allocate the pointer array
241 (*Argv
) = AllocateZeroPool((Count
)*sizeof(CHAR16
*));
243 Status
= EFI_OUT_OF_RESOURCES
;
248 Walker
= (CHAR16
*)NewCommandLine
;
249 while(Walker
!= NULL
&& *Walker
!= CHAR_NULL
) {
250 SetMem16(TempParameter
, Size
, CHAR_NULL
);
251 if (EFI_ERROR(GetNextParameter(&Walker
, &TempParameter
, Size
, StripQuotation
))) {
252 Status
= EFI_INVALID_PARAMETER
;
256 NewParam
= AllocateCopyPool(StrSize(TempParameter
), TempParameter
);
257 if (NewParam
== NULL
){
258 Status
= EFI_OUT_OF_RESOURCES
;
261 ((CHAR16
**)(*Argv
))[(*Argc
)] = NewParam
;
264 ASSERT(Count
>= (*Argc
));
265 Status
= EFI_SUCCESS
;
268 SHELL_FREE_NON_NULL(TempParameter
);
269 SHELL_FREE_NON_NULL(NewCommandLine
);
274 creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then
275 installs it on our handle and if there is an existing version of the protocol
276 that one is cached for removal later.
278 @param[in, out] NewShellParameters on a successful return, a pointer to pointer
279 to the newly installed interface.
280 @param[in, out] RootShellInstance on a successful return, pointer to boolean.
281 TRUE if this is the root shell instance.
283 @retval EFI_SUCCESS the operation completed successfully.
284 @return other the operation failed.
285 @sa ReinstallProtocolInterface
286 @sa InstallProtocolInterface
287 @sa ParseCommandLineToArgs
290 CreatePopulateInstallShellParametersProtocol (
291 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
**NewShellParameters
,
292 IN OUT BOOLEAN
*RootShellInstance
296 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
297 CHAR16
*FullCommandLine
;
301 FullCommandLine
= NULL
;
305 // Assert for valid parameters
307 ASSERT(NewShellParameters
!= NULL
);
308 ASSERT(RootShellInstance
!= NULL
);
311 // See if we have a shell parameters placed on us
313 Status
= gBS
->OpenProtocol (
315 &gEfiShellParametersProtocolGuid
,
316 (VOID
**) &ShellInfoObject
.OldShellParameters
,
319 EFI_OPEN_PROTOCOL_GET_PROTOCOL
322 // if we don't then we must be the root shell (error is expected)
324 if (EFI_ERROR (Status
)) {
325 *RootShellInstance
= TRUE
;
329 // Allocate the new structure
331 *NewShellParameters
= AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL
));
332 if ((*NewShellParameters
) == NULL
) {
333 return (EFI_OUT_OF_RESOURCES
);
337 // get loaded image protocol
339 Status
= gBS
->OpenProtocol (
341 &gEfiLoadedImageProtocolGuid
,
342 (VOID
**) &LoadedImage
,
345 EFI_OPEN_PROTOCOL_GET_PROTOCOL
347 ASSERT_EFI_ERROR(Status
);
349 // Build the full command line
351 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
352 if (Status
== EFI_BUFFER_TOO_SMALL
) {
353 FullCommandLine
= AllocateZeroPool(Size
+ LoadedImage
->LoadOptionsSize
);
354 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
356 if (Status
== EFI_NOT_FOUND
) {
358 // no parameters via environment... ok
361 if (EFI_ERROR(Status
)) {
365 if (Size
== 0 && LoadedImage
->LoadOptionsSize
!= 0) {
366 ASSERT(FullCommandLine
== NULL
);
368 // Now we need to include a NULL terminator in the size.
370 Size
= LoadedImage
->LoadOptionsSize
+ sizeof(FullCommandLine
[0]);
371 FullCommandLine
= AllocateZeroPool(Size
);
373 if (FullCommandLine
!= NULL
) {
374 CopyMem (FullCommandLine
, LoadedImage
->LoadOptions
, LoadedImage
->LoadOptionsSize
);
376 // Populate Argc and Argv
378 Status
= ParseCommandLineToArgs(FullCommandLine
,
380 &(*NewShellParameters
)->Argv
,
381 &(*NewShellParameters
)->Argc
);
383 FreePool(FullCommandLine
);
385 ASSERT_EFI_ERROR(Status
);
387 (*NewShellParameters
)->Argv
= NULL
;
388 (*NewShellParameters
)->Argc
= 0;
392 // Populate the 3 faked file systems...
394 if (*RootShellInstance
) {
395 (*NewShellParameters
)->StdIn
= &FileInterfaceStdIn
;
396 (*NewShellParameters
)->StdOut
= &FileInterfaceStdOut
;
397 (*NewShellParameters
)->StdErr
= &FileInterfaceStdErr
;
398 Status
= gBS
->InstallProtocolInterface(&gImageHandle
,
399 &gEfiShellParametersProtocolGuid
,
400 EFI_NATIVE_INTERFACE
,
401 (VOID
*)(*NewShellParameters
));
404 // copy from the existing ones
406 (*NewShellParameters
)->StdIn
= ShellInfoObject
.OldShellParameters
->StdIn
;
407 (*NewShellParameters
)->StdOut
= ShellInfoObject
.OldShellParameters
->StdOut
;
408 (*NewShellParameters
)->StdErr
= ShellInfoObject
.OldShellParameters
->StdErr
;
409 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
410 &gEfiShellParametersProtocolGuid
,
411 (VOID
*)ShellInfoObject
.OldShellParameters
,
412 (VOID
*)(*NewShellParameters
));
419 frees all memory used by createion and installation of shell parameters protocol
420 and if there was an old version installed it will restore that one.
422 @param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
425 @retval EFI_SUCCESS the cleanup was successful
426 @return other the cleanup failed
427 @sa ReinstallProtocolInterface
428 @sa UninstallProtocolInterface
431 CleanUpShellParametersProtocol (
432 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*NewShellParameters
439 // If the old exists we need to restore it
441 if (ShellInfoObject
.OldShellParameters
!= NULL
) {
442 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
443 &gEfiShellParametersProtocolGuid
,
444 (VOID
*)NewShellParameters
,
445 (VOID
*)ShellInfoObject
.OldShellParameters
);
446 DEBUG_CODE(ShellInfoObject
.OldShellParameters
= NULL
;);
449 // No old one, just uninstall us...
451 Status
= gBS
->UninstallProtocolInterface(gImageHandle
,
452 &gEfiShellParametersProtocolGuid
,
453 (VOID
*)NewShellParameters
);
455 if (NewShellParameters
->Argv
!= NULL
) {
456 for ( LoopCounter
= 0
457 ; LoopCounter
< NewShellParameters
->Argc
460 FreePool(NewShellParameters
->Argv
[LoopCounter
]);
462 FreePool(NewShellParameters
->Argv
);
464 FreePool(NewShellParameters
);
469 Determin if a file name represents a unicode file.
471 @param[in] FileName Pointer to the filename to open.
473 @retval EFI_SUCCESS The file is a unicode file.
474 @return An error upon failure.
478 IN CONST CHAR16
*FileName
481 SHELL_FILE_HANDLE Handle
;
483 UINT64 OriginalFilePosition
;
487 Status
= gEfiShellProtocol
->OpenFileByName(FileName
, &Handle
, EFI_FILE_MODE_READ
);
488 if (EFI_ERROR(Status
)) {
491 gEfiShellProtocol
->GetFilePosition(Handle
, &OriginalFilePosition
);
492 gEfiShellProtocol
->SetFilePosition(Handle
, 0);
493 CharSize
= sizeof(CHAR16
);
494 Status
= gEfiShellProtocol
->ReadFile(Handle
, &CharSize
, &CharBuffer
);
495 if (EFI_ERROR(Status
) || CharBuffer
!= gUnicodeFileTag
) {
496 Status
= EFI_BUFFER_TOO_SMALL
;
498 gEfiShellProtocol
->SetFilePosition(Handle
, OriginalFilePosition
);
499 gEfiShellProtocol
->CloseFile(Handle
);
504 Strips out quotes sections of a string.
506 All of the characters between quotes is replaced with spaces.
508 @param[in, out] TheString A pointer to the string to update.
512 IN OUT CHAR16
*TheString
517 for (RemoveNow
= FALSE
; TheString
!= NULL
&& *TheString
!= CHAR_NULL
; TheString
++) {
518 if (*TheString
== L
'^' && *(TheString
+ 1) == L
'\"') {
520 } else if (*TheString
== L
'\"') {
521 RemoveNow
= (BOOLEAN
)!RemoveNow
;
522 } else if (RemoveNow
) {
529 Calcualte the 32-bit CRC in a EFI table using the service provided by the
532 @param Hdr Pointer to an EFI standard header
537 IN OUT EFI_TABLE_HEADER
*Hdr
545 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
546 // Crc will come back as zero if we set it to zero here
549 gBS
->CalculateCrc32 ((UINT8
*)Hdr
, Hdr
->HeaderSize
, &Crc
);
554 Fix a string to only have the file name, removing starting at the first space of whatever is quoted.
556 @param[in] FileName The filename to start with.
558 @retval NULL FileName was invalid.
559 @return The modified FileName.
567 CHAR16
*TempLocation
;
569 if (FileName
== NULL
) {
573 if (FileName
[0] == L
'\"') {
575 if ((TempLocation
= StrStr(Copy
, L
"\"")) != NULL
) {
576 TempLocation
[0] = CHAR_NULL
;
580 while(Copy
[0] == L
' ') {
583 if ((TempLocation
= StrStr(Copy
, L
" ")) != NULL
) {
584 TempLocation
[0] = CHAR_NULL
;
588 if (Copy
[0] == CHAR_NULL
) {
596 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 %.
598 @param[in] FileName The filename to start with.
600 @retval NULL FileName was invalid.
601 @return The modified FileName.
609 CHAR16
*TempLocation
;
613 if (FileName
[0] == L
'%') {
615 if ((TempLocation
= StrStr(Copy
, L
"%")) != NULL
) {
616 TempLocation
[0] = CHAR_NULL
;
620 return (FixFileName(Copy
));
625 Write the unicode file tag to the specified file.
627 It is the caller's responsibility to ensure that
628 ShellInfoObject.NewEfiShellProtocol has been initialized before calling this
631 @param[in] FileHandle The file to write the unicode file tag to.
633 @return Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.
637 IN SHELL_FILE_HANDLE FileHandle
644 FileTag
= gUnicodeFileTag
;
645 Size
= sizeof FileTag
;
646 Status
= ShellInfoObject
.NewEfiShellProtocol
->WriteFile (FileHandle
, &Size
,
648 ASSERT (EFI_ERROR (Status
) || Size
== sizeof FileTag
);
654 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
655 structure by parsing NewCommandLine. The current values are returned to the
658 This will also update the system table.
660 @param[in, out] ShellParameters Pointer to parameter structure to modify.
661 @param[in] NewCommandLine The new command line to parse and use.
662 @param[out] OldStdIn Pointer to old StdIn.
663 @param[out] OldStdOut Pointer to old StdOut.
664 @param[out] OldStdErr Pointer to old StdErr.
665 @param[out] SystemTableInfo Pointer to old system table information.
667 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
668 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
671 UpdateStdInStdOutStdErr(
672 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
673 IN CHAR16
*NewCommandLine
,
674 OUT SHELL_FILE_HANDLE
*OldStdIn
,
675 OUT SHELL_FILE_HANDLE
*OldStdOut
,
676 OUT SHELL_FILE_HANDLE
*OldStdErr
,
677 OUT SYSTEM_TABLE_INFO
*SystemTableInfo
680 CHAR16
*CommandLineCopy
;
681 CHAR16
*CommandLineWalker
;
682 CHAR16
*StdErrFileName
;
683 CHAR16
*StdOutFileName
;
684 CHAR16
*StdInFileName
;
685 CHAR16
*StdInVarName
;
686 CHAR16
*StdOutVarName
;
687 CHAR16
*StdErrVarName
;
689 SHELL_FILE_HANDLE TempHandle
;
698 CHAR16
*FirstLocation
;
703 AsciiRedirection
= FALSE
;
706 StdOutVarName
= NULL
;
707 StdErrVarName
= NULL
;
708 StdErrFileName
= NULL
;
709 StdInFileName
= NULL
;
710 StdOutFileName
= NULL
;
713 CommandLineCopy
= NULL
;
714 FirstLocation
= NULL
;
716 if (ShellParameters
== NULL
|| SystemTableInfo
== NULL
|| OldStdIn
== NULL
|| OldStdOut
== NULL
|| OldStdErr
== NULL
) {
717 return (EFI_INVALID_PARAMETER
);
720 SystemTableInfo
->ConIn
= gST
->ConIn
;
721 SystemTableInfo
->ConInHandle
= gST
->ConsoleInHandle
;
722 SystemTableInfo
->ConOut
= gST
->ConOut
;
723 SystemTableInfo
->ConOutHandle
= gST
->ConsoleOutHandle
;
724 SystemTableInfo
->ErrOut
= gST
->StdErr
;
725 SystemTableInfo
->ErrOutHandle
= gST
->StandardErrorHandle
;
726 *OldStdIn
= ShellParameters
->StdIn
;
727 *OldStdOut
= ShellParameters
->StdOut
;
728 *OldStdErr
= ShellParameters
->StdErr
;
730 if (NewCommandLine
== NULL
) {
731 return (EFI_SUCCESS
);
734 CommandLineCopy
= StrnCatGrow(&CommandLineCopy
, NULL
, NewCommandLine
, 0);
735 if (CommandLineCopy
== NULL
) {
736 return (EFI_OUT_OF_RESOURCES
);
738 Status
= EFI_SUCCESS
;
740 FirstLocation
= CommandLineCopy
+ StrLen(CommandLineCopy
);
742 StripQuotes(CommandLineCopy
);
744 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
745 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
746 if (Split
!= NULL
&& Split
->SplitStdIn
!= NULL
) {
747 ShellParameters
->StdIn
= Split
->SplitStdIn
;
749 if (Split
!= NULL
&& Split
->SplitStdOut
!= NULL
) {
750 ShellParameters
->StdOut
= Split
->SplitStdOut
;
754 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>>v ")) != NULL
) {
755 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
756 SetMem16(CommandLineWalker
, 12, L
' ');
757 StdErrVarName
= CommandLineWalker
+= 6;
759 if (StrStr(CommandLineWalker
, L
" 2>>v ") != NULL
) {
760 Status
= EFI_NOT_FOUND
;
763 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>v ")) != NULL
) {
764 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
765 SetMem16(CommandLineWalker
, 12, L
' ');
766 StdOutVarName
= CommandLineWalker
+= 6;
768 if (StrStr(CommandLineWalker
, L
" 1>>v ") != NULL
) {
769 Status
= EFI_NOT_FOUND
;
771 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>v ")) != NULL
) {
772 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
773 SetMem16(CommandLineWalker
, 10, L
' ');
774 StdOutVarName
= CommandLineWalker
+= 5;
776 if (StrStr(CommandLineWalker
, L
" >>v ") != NULL
) {
777 Status
= EFI_NOT_FOUND
;
779 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >v ")) != NULL
) {
780 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
781 SetMem16(CommandLineWalker
, 8, L
' ');
782 StdOutVarName
= CommandLineWalker
+= 4;
784 if (StrStr(CommandLineWalker
, L
" >v ") != NULL
) {
785 Status
= EFI_NOT_FOUND
;
788 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>a ")) != NULL
) {
789 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
790 SetMem16(CommandLineWalker
, 12, L
' ');
791 StdOutFileName
= CommandLineWalker
+= 6;
794 if (StrStr(CommandLineWalker
, L
" 1>>a ") != NULL
) {
795 Status
= EFI_NOT_FOUND
;
798 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>> ")) != NULL
) {
799 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
800 SetMem16(CommandLineWalker
, 10, L
' ');
801 if (StdOutFileName
!= NULL
) {
802 Status
= EFI_INVALID_PARAMETER
;
804 StdOutFileName
= CommandLineWalker
+= 5;
807 if (StrStr(CommandLineWalker
, L
" 1>> ") != NULL
) {
808 Status
= EFI_NOT_FOUND
;
811 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >> ")) != NULL
) {
812 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
813 SetMem16(CommandLineWalker
, 8, L
' ');
814 if (StdOutFileName
!= NULL
) {
815 Status
= EFI_INVALID_PARAMETER
;
817 StdOutFileName
= CommandLineWalker
+= 4;
820 if (StrStr(CommandLineWalker
, L
" >> ") != NULL
) {
821 Status
= EFI_NOT_FOUND
;
824 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>a ")) != NULL
) {
825 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
826 SetMem16(CommandLineWalker
, 10, L
' ');
827 if (StdOutFileName
!= NULL
) {
828 Status
= EFI_INVALID_PARAMETER
;
830 StdOutFileName
= CommandLineWalker
+= 5;
834 if (StrStr(CommandLineWalker
, L
" >>a ") != NULL
) {
835 Status
= EFI_NOT_FOUND
;
838 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>a ")) != NULL
) {
839 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
840 SetMem16(CommandLineWalker
, 10, L
' ');
841 if (StdOutFileName
!= NULL
) {
842 Status
= EFI_INVALID_PARAMETER
;
844 StdOutFileName
= CommandLineWalker
+= 5;
848 if (StrStr(CommandLineWalker
, L
" 1>a ") != NULL
) {
849 Status
= EFI_NOT_FOUND
;
852 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >a ")) != NULL
) {
853 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
854 SetMem16(CommandLineWalker
, 8, L
' ');
855 if (StdOutFileName
!= NULL
) {
856 Status
= EFI_INVALID_PARAMETER
;
858 StdOutFileName
= CommandLineWalker
+= 4;
862 if (StrStr(CommandLineWalker
, L
" >a ") != NULL
) {
863 Status
= EFI_NOT_FOUND
;
866 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>> ")) != NULL
) {
867 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
868 SetMem16(CommandLineWalker
, 10, L
' ');
869 if (StdErrFileName
!= NULL
) {
870 Status
= EFI_INVALID_PARAMETER
;
872 StdErrFileName
= CommandLineWalker
+= 5;
875 if (StrStr(CommandLineWalker
, L
" 2>> ") != NULL
) {
876 Status
= EFI_NOT_FOUND
;
880 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>v ")) != NULL
) {
881 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
882 SetMem16(CommandLineWalker
, 10, L
' ');
883 if (StdErrVarName
!= NULL
) {
884 Status
= EFI_INVALID_PARAMETER
;
886 StdErrVarName
= CommandLineWalker
+= 5;
889 if (StrStr(CommandLineWalker
, L
" 2>v ") != NULL
) {
890 Status
= EFI_NOT_FOUND
;
893 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>v ")) != NULL
) {
894 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
895 SetMem16(CommandLineWalker
, 10, L
' ');
896 if (StdOutVarName
!= NULL
) {
897 Status
= EFI_INVALID_PARAMETER
;
899 StdOutVarName
= CommandLineWalker
+= 5;
902 if (StrStr(CommandLineWalker
, L
" 1>v ") != NULL
) {
903 Status
= EFI_NOT_FOUND
;
906 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>a ")) != NULL
) {
907 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
908 SetMem16(CommandLineWalker
, 10, L
' ');
909 if (StdErrFileName
!= NULL
) {
910 Status
= EFI_INVALID_PARAMETER
;
912 StdErrFileName
= CommandLineWalker
+= 5;
916 if (StrStr(CommandLineWalker
, L
" 2>a ") != NULL
) {
917 Status
= EFI_NOT_FOUND
;
920 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2> ")) != NULL
) {
921 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
922 SetMem16(CommandLineWalker
, 8, L
' ');
923 if (StdErrFileName
!= NULL
) {
924 Status
= EFI_INVALID_PARAMETER
;
926 StdErrFileName
= CommandLineWalker
+= 4;
929 if (StrStr(CommandLineWalker
, L
" 2> ") != NULL
) {
930 Status
= EFI_NOT_FOUND
;
934 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1> ")) != NULL
) {
935 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
936 SetMem16(CommandLineWalker
, 8, L
' ');
937 if (StdOutFileName
!= NULL
) {
938 Status
= EFI_INVALID_PARAMETER
;
940 StdOutFileName
= CommandLineWalker
+= 4;
943 if (StrStr(CommandLineWalker
, L
" 1> ") != NULL
) {
944 Status
= EFI_NOT_FOUND
;
948 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" > ")) != NULL
) {
949 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
950 SetMem16(CommandLineWalker
, 6, L
' ');
951 if (StdOutFileName
!= NULL
) {
952 Status
= EFI_INVALID_PARAMETER
;
954 StdOutFileName
= CommandLineWalker
+= 3;
957 if (StrStr(CommandLineWalker
, L
" > ") != NULL
) {
958 Status
= EFI_NOT_FOUND
;
962 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" < ")) != NULL
) {
963 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
964 SetMem16(CommandLineWalker
, 6, L
' ');
965 if (StdInFileName
!= NULL
) {
966 Status
= EFI_INVALID_PARAMETER
;
968 StdInFileName
= CommandLineWalker
+= 3;
970 if (StrStr(CommandLineWalker
, L
" < ") != NULL
) {
971 Status
= EFI_NOT_FOUND
;
974 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <a ")) != NULL
) {
975 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
976 SetMem16(CommandLineWalker
, 8, L
' ');
977 if (StdInFileName
!= NULL
) {
978 Status
= EFI_INVALID_PARAMETER
;
980 StdInFileName
= CommandLineWalker
+= 4;
982 AsciiRedirection
= TRUE
;
984 if (StrStr(CommandLineWalker
, L
" <a ") != NULL
) {
985 Status
= EFI_NOT_FOUND
;
988 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <v ")) != NULL
) {
989 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
990 SetMem16(CommandLineWalker
, 8, L
' ');
991 if (StdInVarName
!= NULL
) {
992 Status
= EFI_INVALID_PARAMETER
;
994 StdInVarName
= CommandLineWalker
+= 4;
996 if (StrStr(CommandLineWalker
, L
" <v ") != NULL
) {
997 Status
= EFI_NOT_FOUND
;
1002 // re-populate the string to support any filenames that were in quotes.
1004 StrnCpyS(CommandLineCopy
, StrSize(CommandLineCopy
)/sizeof(CHAR16
), NewCommandLine
, StrLen(NewCommandLine
));
1006 if (FirstLocation
!= CommandLineCopy
+ StrLen(CommandLineCopy
)
1007 && (((UINTN
)FirstLocation
- (UINTN
)CommandLineCopy
)/sizeof(CHAR16
) < StrLen(NewCommandLine
))
1009 *(NewCommandLine
+ ((UINTN
)FirstLocation
- (UINTN
)CommandLineCopy
)/sizeof(CHAR16
)) = CHAR_NULL
;
1012 if (!EFI_ERROR(Status
)) {
1014 if (StdErrFileName
!= NULL
) {
1015 if ((StdErrFileName
= FixFileName(StdErrFileName
)) == NULL
) {
1016 Status
= EFI_INVALID_PARAMETER
;
1019 if (StdOutFileName
!= NULL
) {
1020 if ((StdOutFileName
= FixFileName(StdOutFileName
)) == NULL
) {
1021 Status
= EFI_INVALID_PARAMETER
;
1024 if (StdInFileName
!= NULL
) {
1025 if ((StdInFileName
= FixFileName(StdInFileName
)) == NULL
) {
1026 Status
= EFI_INVALID_PARAMETER
;
1029 if (StdErrVarName
!= NULL
) {
1030 if ((StdErrVarName
= FixVarName(StdErrVarName
)) == NULL
) {
1031 Status
= EFI_INVALID_PARAMETER
;
1034 if (StdOutVarName
!= NULL
) {
1035 if ((StdOutVarName
= FixVarName(StdOutVarName
)) == NULL
) {
1036 Status
= EFI_INVALID_PARAMETER
;
1039 if (StdInVarName
!= NULL
) {
1040 if ((StdInVarName
= FixVarName(StdInVarName
)) == NULL
) {
1041 Status
= EFI_INVALID_PARAMETER
;
1046 // Verify not the same and not duplicating something from a split
1050 // Check that no 2 filenames are the same
1052 (StdErrFileName
!= NULL
&& StdOutFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdOutFileName
) == 0)
1053 ||(StdErrFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdInFileName
) == 0)
1054 ||(StdOutFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdOutFileName
, &StdInFileName
) == 0)
1056 // Check that no 2 variable names are the same
1058 ||(StdErrVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdInVarName
) == 0)
1059 ||(StdOutVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdOutVarName
, &StdInVarName
) == 0)
1060 ||(StdErrVarName
!= NULL
&& StdOutVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdOutVarName
) == 0)
1062 // When a split (using | operator) is in place some are not allowed
1064 ||(Split
!= NULL
&& Split
->SplitStdIn
!= NULL
&& (StdInVarName
!= NULL
|| StdInFileName
!= NULL
))
1065 ||(Split
!= NULL
&& Split
->SplitStdOut
!= NULL
&& (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
))
1067 // Check that nothing is trying to be output to 2 locations.
1069 ||(StdErrFileName
!= NULL
&& StdErrVarName
!= NULL
)
1070 ||(StdOutFileName
!= NULL
&& StdOutVarName
!= NULL
)
1071 ||(StdInFileName
!= NULL
&& StdInVarName
!= NULL
)
1073 // Check for no volatile environment variables
1075 ||(StdErrVarName
!= NULL
&& !EFI_ERROR (IsVolatileEnv (StdErrVarName
, &Volatile
)) && !Volatile
)
1076 ||(StdOutVarName
!= NULL
&& !EFI_ERROR (IsVolatileEnv (StdOutVarName
, &Volatile
)) && !Volatile
)
1078 // Cant redirect during a reconnect operation.
1080 ||(StrStr(NewCommandLine
, L
"connect -r") != NULL
1081 && (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
|| StdErrFileName
!= NULL
|| StdErrVarName
!= NULL
))
1083 // Check that filetypes (Unicode/Ascii) do not change during an append
1085 ||(StdOutFileName
!= NULL
&& OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1086 ||(StdErrFileName
!= NULL
&& ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1087 ||(StdOutFileName
!= NULL
&& !OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1088 ||(StdErrFileName
!= NULL
&& !ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1090 Status
= EFI_INVALID_PARAMETER
;
1091 ShellParameters
->StdIn
= *OldStdIn
;
1092 ShellParameters
->StdOut
= *OldStdOut
;
1093 ShellParameters
->StdErr
= *OldStdErr
;
1094 } else if (!EFI_ERROR(Status
)){
1096 // Open the Std<Whatever> and we should not have conflicts here...
1102 if (StdErrFileName
!= NULL
) {
1105 // delete existing file.
1107 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdErrFileName
);
1109 Status
= ShellOpenFileByName(StdErrFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1110 if (!ErrAppend
&& ErrUnicode
&& !EFI_ERROR(Status
)) {
1111 Status
= WriteFileTag (TempHandle
);
1113 if (!ErrUnicode
&& !EFI_ERROR(Status
)) {
1114 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1115 ASSERT(TempHandle
!= NULL
);
1117 if (!EFI_ERROR(Status
)) {
1118 ShellParameters
->StdErr
= TempHandle
;
1119 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1126 if (!EFI_ERROR(Status
) && StdOutFileName
!= NULL
) {
1129 // delete existing file.
1131 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdOutFileName
);
1133 Status
= ShellOpenFileByName(StdOutFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1134 if (TempHandle
== NULL
) {
1135 Status
= EFI_INVALID_PARAMETER
;
1137 if (gUnicodeCollation
->MetaiMatch (gUnicodeCollation
, StdOutFileName
, L
"NUL")) {
1139 } else if (!OutAppend
&& OutUnicode
&& !EFI_ERROR(Status
)) {
1140 Status
= WriteFileTag (TempHandle
);
1141 } else if (OutAppend
) {
1142 Status
= ShellInfoObject
.NewEfiShellProtocol
->GetFileSize(TempHandle
, &FileSize
);
1143 if (!EFI_ERROR(Status
)) {
1145 // When appending to a new unicode file, write the file tag.
1146 // Otherwise (ie. when appending to a new ASCII file, or an
1147 // existent file with any encoding), just seek to the end.
1149 Status
= (FileSize
== 0 && OutUnicode
) ?
1150 WriteFileTag (TempHandle
) :
1151 ShellInfoObject
.NewEfiShellProtocol
->SetFilePosition (
1156 if (!OutUnicode
&& !EFI_ERROR(Status
)) {
1157 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1158 ASSERT(TempHandle
!= NULL
);
1160 if (!EFI_ERROR(Status
)) {
1161 ShellParameters
->StdOut
= TempHandle
;
1162 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1170 if (!EFI_ERROR(Status
) && StdOutVarName
!= NULL
) {
1173 // delete existing variable.
1175 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName
, 0, L
"");
1177 TempHandle
= CreateFileInterfaceEnv(StdOutVarName
);
1178 ASSERT(TempHandle
!= NULL
);
1179 ShellParameters
->StdOut
= TempHandle
;
1180 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1186 if (!EFI_ERROR(Status
) && StdErrVarName
!= NULL
) {
1189 // delete existing variable.
1191 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName
, 0, L
"");
1193 TempHandle
= CreateFileInterfaceEnv(StdErrVarName
);
1194 ASSERT(TempHandle
!= NULL
);
1195 ShellParameters
->StdErr
= TempHandle
;
1196 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1202 if (!EFI_ERROR(Status
) && StdInVarName
!= NULL
) {
1203 TempHandle
= CreateFileInterfaceEnv(StdInVarName
);
1204 if (TempHandle
== NULL
) {
1205 Status
= EFI_OUT_OF_RESOURCES
;
1208 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1211 if (TempHandle
== NULL
|| ((EFI_FILE_PROTOCOL
*)TempHandle
)->Read(TempHandle
, &Size
, NULL
) != EFI_BUFFER_TOO_SMALL
) {
1212 Status
= EFI_INVALID_PARAMETER
;
1214 ShellParameters
->StdIn
= TempHandle
;
1215 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1221 // StdIn from a file
1223 if (!EFI_ERROR(Status
) && StdInFileName
!= NULL
) {
1224 Status
= ShellOpenFileByName(
1229 if (!EFI_ERROR(Status
)) {
1232 // Create the ASCII->Unicode conversion layer
1234 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1236 ShellParameters
->StdIn
= TempHandle
;
1237 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1242 FreePool(CommandLineCopy
);
1244 CalculateEfiHdrCrc(&gST
->Hdr
);
1246 if (gST
->ConIn
== NULL
||gST
->ConOut
== NULL
) {
1247 Status
= EFI_OUT_OF_RESOURCES
;
1250 if (Status
== EFI_NOT_FOUND
) {
1251 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR
), ShellInfoObject
.HiiHandle
);
1252 } else if (EFI_ERROR(Status
)) {
1253 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_INVALID_REDIR
), ShellInfoObject
.HiiHandle
);
1260 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
1261 structure with StdIn and StdOut. The current values are de-allocated.
1263 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1264 @param[in] OldStdIn Pointer to old StdIn.
1265 @param[in] OldStdOut Pointer to old StdOut.
1266 @param[in] OldStdErr Pointer to old StdErr.
1267 @param[in] SystemTableInfo Pointer to old system table information.
1270 RestoreStdInStdOutStdErr (
1271 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1272 IN SHELL_FILE_HANDLE
*OldStdIn
,
1273 IN SHELL_FILE_HANDLE
*OldStdOut
,
1274 IN SHELL_FILE_HANDLE
*OldStdErr
,
1275 IN SYSTEM_TABLE_INFO
*SystemTableInfo
1280 if (ShellParameters
== NULL
1284 ||SystemTableInfo
== NULL
) {
1285 return (EFI_INVALID_PARAMETER
);
1287 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
1288 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
1292 if (ShellParameters
->StdIn
!= *OldStdIn
) {
1293 if ((Split
!= NULL
&& Split
->SplitStdIn
!= ShellParameters
->StdIn
) || Split
== NULL
) {
1294 gEfiShellProtocol
->CloseFile(ShellParameters
->StdIn
);
1296 ShellParameters
->StdIn
= *OldStdIn
;
1298 if (ShellParameters
->StdOut
!= *OldStdOut
) {
1299 if ((Split
!= NULL
&& Split
->SplitStdOut
!= ShellParameters
->StdOut
) || Split
== NULL
) {
1300 gEfiShellProtocol
->CloseFile(ShellParameters
->StdOut
);
1302 ShellParameters
->StdOut
= *OldStdOut
;
1304 if (ShellParameters
->StdErr
!= *OldStdErr
) {
1305 gEfiShellProtocol
->CloseFile(ShellParameters
->StdErr
);
1306 ShellParameters
->StdErr
= *OldStdErr
;
1309 if (gST
->ConIn
!= SystemTableInfo
->ConIn
) {
1310 CloseSimpleTextInOnFile(gST
->ConIn
);
1311 gST
->ConIn
= SystemTableInfo
->ConIn
;
1312 gST
->ConsoleInHandle
= SystemTableInfo
->ConInHandle
;
1314 if (gST
->ConOut
!= SystemTableInfo
->ConOut
) {
1315 CloseSimpleTextOutOnFile(gST
->ConOut
);
1316 gST
->ConOut
= SystemTableInfo
->ConOut
;
1317 gST
->ConsoleOutHandle
= SystemTableInfo
->ConOutHandle
;
1319 if (gST
->StdErr
!= SystemTableInfo
->ErrOut
) {
1320 CloseSimpleTextOutOnFile(gST
->StdErr
);
1321 gST
->StdErr
= SystemTableInfo
->ErrOut
;
1322 gST
->StandardErrorHandle
= SystemTableInfo
->ErrOutHandle
;
1325 CalculateEfiHdrCrc(&gST
->Hdr
);
1327 return (EFI_SUCCESS
);
1330 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1331 structure by parsing NewCommandLine. The current values are returned to the
1334 If OldArgv or OldArgc is NULL then that value is not returned.
1336 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1337 @param[in] NewCommandLine The new command line to parse and use.
1338 @param[in] Type The type of operation.
1339 @param[out] OldArgv Pointer to old list of parameters.
1340 @param[out] OldArgc Pointer to old number of items in Argv list.
1342 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
1343 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1347 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1348 IN CONST CHAR16
*NewCommandLine
,
1349 IN SHELL_OPERATION_TYPES Type
,
1350 OUT CHAR16
***OldArgv OPTIONAL
,
1351 OUT UINTN
*OldArgc OPTIONAL
1354 BOOLEAN StripParamQuotation
;
1356 ASSERT(ShellParameters
!= NULL
);
1357 StripParamQuotation
= TRUE
;
1359 if (OldArgc
!= NULL
) {
1360 *OldArgc
= ShellParameters
->Argc
;
1362 if (OldArgc
!= NULL
) {
1363 *OldArgv
= ShellParameters
->Argv
;
1366 if (Type
== Script_File_Name
) {
1367 StripParamQuotation
= FALSE
;
1370 return ParseCommandLineToArgs( NewCommandLine
,
1371 StripParamQuotation
,
1372 &(ShellParameters
->Argv
),
1373 &(ShellParameters
->Argc
)
1378 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1379 structure with Argv and Argc. The current values are de-allocated and the
1380 OldArgv must not be deallocated by the caller.
1382 @param[in, out] ShellParameters pointer to parameter structure to modify
1383 @param[in] OldArgv pointer to old list of parameters
1384 @param[in] OldArgc pointer to old number of items in Argv list
1388 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1389 IN CHAR16
***OldArgv
,
1394 ASSERT(ShellParameters
!= NULL
);
1395 ASSERT(OldArgv
!= NULL
);
1396 ASSERT(OldArgc
!= NULL
);
1398 if (ShellParameters
->Argv
!= NULL
) {
1399 for ( LoopCounter
= 0
1400 ; LoopCounter
< ShellParameters
->Argc
1403 FreePool(ShellParameters
->Argv
[LoopCounter
]);
1405 FreePool(ShellParameters
->Argv
);
1407 ShellParameters
->Argv
= *OldArgv
;
1409 ShellParameters
->Argc
= *OldArgc
;