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 - 2017, Intel Corporation. All rights reserved.<BR>
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 BOOLEAN AsciiRedirection
= FALSE
;
24 Return the next parameter's end from a command line string.
26 @param[in] String the string to parse
30 IN CONST CHAR16
*String
34 CONST CHAR16
*CloseQuote
;
36 First
= FindFirstCharacter(String
, L
" \"", L
'^');
39 // nothing, all one parameter remaining
41 if (*First
== CHAR_NULL
) {
46 // If space before a quote (or neither found, i.e. both CHAR_NULL),
47 // then that's the end.
53 CloseQuote
= FindFirstCharacter (First
+1, L
"\"", L
'^');
56 // We did not find a terminator...
58 if (*CloseQuote
== CHAR_NULL
) {
62 return (FindEndOfParameter (CloseQuote
+1));
66 Return the next parameter from a command line string.
68 This function moves the next parameter from Walker into TempParameter and moves
69 Walker up past that parameter for recursive calling. When the final parameter
70 is moved *Walker will be set to NULL;
72 Temp Parameter must be large enough to hold the parameter before calling this
75 This will also remove all remaining ^ characters after processing.
77 @param[in, out] Walker pointer to string of command line. Adjusted to
78 reminaing command line on return
79 @param[in, out] TempParameter pointer to string of command line item extracted.
80 @param[in] Length buffer size of TempParameter.
81 @param[in] StripQuotation if TRUE then strip the quotation marks surrounding
84 @return EFI_INALID_PARAMETER A required parameter was NULL or pointed to a NULL or empty string.
85 @return EFI_NOT_FOUND A closing " could not be found on the specified string
89 IN OUT CHAR16
**Walker
,
90 IN OUT CHAR16
**TempParameter
,
91 IN CONST UINTN Length
,
92 IN BOOLEAN StripQuotation
95 CONST CHAR16
*NextDelim
;
99 ||TempParameter
== NULL
100 ||*TempParameter
== NULL
102 return (EFI_INVALID_PARAMETER
);
107 // make sure we dont have any leading spaces
109 while ((*Walker
)[0] == L
' ') {
114 // make sure we still have some params now...
116 if (StrLen(*Walker
) == 0) {
120 return (EFI_INVALID_PARAMETER
);
123 NextDelim
= FindEndOfParameter(*Walker
);
125 if (NextDelim
== NULL
){
129 return (EFI_NOT_FOUND
);
132 StrnCpyS(*TempParameter
, Length
/ sizeof(CHAR16
), (*Walker
), NextDelim
- *Walker
);
135 // Add a CHAR_NULL if we didnt get one via the copy
137 if (*NextDelim
!= CHAR_NULL
) {
138 (*TempParameter
)[NextDelim
- *Walker
] = CHAR_NULL
;
142 // Update Walker for the next iteration through the function
144 *Walker
= (CHAR16
*)NextDelim
;
147 // Remove any non-escaped quotes in the string
148 // Remove any remaining escape characters in the string
150 for (NextDelim
= FindFirstCharacter(*TempParameter
, L
"\"^", CHAR_NULL
)
151 ; *NextDelim
!= CHAR_NULL
152 ; NextDelim
= FindFirstCharacter(NextDelim
, L
"\"^", CHAR_NULL
)
154 if (*NextDelim
== L
'^') {
157 // eliminate the escape ^
159 CopyMem ((CHAR16
*)NextDelim
, NextDelim
+ 1, StrSize (NextDelim
+ 1));
161 } else if (*NextDelim
== L
'\"') {
164 // eliminate the unescaped quote
166 if (StripQuotation
) {
167 CopyMem ((CHAR16
*)NextDelim
, NextDelim
+ 1, StrSize (NextDelim
+ 1));
178 Function to populate Argc and Argv.
180 This function parses the CommandLine and divides it into standard C style Argc/Argv
181 parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space
182 delimited and quote surrounded parameter definition.
184 All special character processing (alias, environment variable, redirection,
185 etc... must be complete before calling this API.
187 @param[in] CommandLine String of command line to parse
188 @param[in] StripQuotation if TRUE then strip the quotation marks surrounding
190 @param[in, out] Argv pointer to array of strings; one for each parameter
191 @param[in, out] Argc pointer to number of strings in Argv array
193 @return EFI_SUCCESS the operation was sucessful
194 @return EFI_OUT_OF_RESOURCES a memory allocation failed.
197 ParseCommandLineToArgs(
198 IN CONST CHAR16
*CommandLine
,
199 IN BOOLEAN StripQuotation
,
200 IN OUT CHAR16
***Argv
,
205 CHAR16
*TempParameter
;
208 CHAR16
*NewCommandLine
;
212 ASSERT(Argc
!= NULL
);
213 ASSERT(Argv
!= NULL
);
215 if (CommandLine
== NULL
|| StrLen(CommandLine
)==0) {
218 return (EFI_SUCCESS
);
221 NewCommandLine
= AllocateCopyPool(StrSize(CommandLine
), CommandLine
);
222 if (NewCommandLine
== NULL
){
223 return (EFI_OUT_OF_RESOURCES
);
226 TrimSpaces(&NewCommandLine
);
227 Size
= StrSize(NewCommandLine
);
228 TempParameter
= AllocateZeroPool(Size
);
229 if (TempParameter
== NULL
) {
230 SHELL_FREE_NON_NULL(NewCommandLine
);
231 return (EFI_OUT_OF_RESOURCES
);
235 , Walker
= (CHAR16
*)NewCommandLine
236 ; Walker
!= NULL
&& *Walker
!= CHAR_NULL
239 if (EFI_ERROR(GetNextParameter(&Walker
, &TempParameter
, Size
, TRUE
))) {
245 // lets allocate the pointer array
247 (*Argv
) = AllocateZeroPool((Count
)*sizeof(CHAR16
*));
249 Status
= EFI_OUT_OF_RESOURCES
;
254 Walker
= (CHAR16
*)NewCommandLine
;
255 while(Walker
!= NULL
&& *Walker
!= CHAR_NULL
) {
256 SetMem16(TempParameter
, Size
, CHAR_NULL
);
257 if (EFI_ERROR(GetNextParameter(&Walker
, &TempParameter
, Size
, StripQuotation
))) {
258 Status
= EFI_INVALID_PARAMETER
;
262 NewParam
= AllocateCopyPool(StrSize(TempParameter
), TempParameter
);
263 if (NewParam
== NULL
){
264 Status
= EFI_OUT_OF_RESOURCES
;
267 ((CHAR16
**)(*Argv
))[(*Argc
)] = NewParam
;
270 ASSERT(Count
>= (*Argc
));
271 Status
= EFI_SUCCESS
;
274 SHELL_FREE_NON_NULL(TempParameter
);
275 SHELL_FREE_NON_NULL(NewCommandLine
);
280 creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then
281 installs it on our handle and if there is an existing version of the protocol
282 that one is cached for removal later.
284 @param[in, out] NewShellParameters on a successful return, a pointer to pointer
285 to the newly installed interface.
286 @param[in, out] RootShellInstance on a successful return, pointer to boolean.
287 TRUE if this is the root shell instance.
289 @retval EFI_SUCCESS the operation completed successfully.
290 @return other the operation failed.
291 @sa ReinstallProtocolInterface
292 @sa InstallProtocolInterface
293 @sa ParseCommandLineToArgs
296 CreatePopulateInstallShellParametersProtocol (
297 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
**NewShellParameters
,
298 IN OUT BOOLEAN
*RootShellInstance
302 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
303 CHAR16
*FullCommandLine
;
307 FullCommandLine
= NULL
;
311 // Assert for valid parameters
313 ASSERT(NewShellParameters
!= NULL
);
314 ASSERT(RootShellInstance
!= NULL
);
317 // See if we have a shell parameters placed on us
319 Status
= gBS
->OpenProtocol (
321 &gEfiShellParametersProtocolGuid
,
322 (VOID
**) &ShellInfoObject
.OldShellParameters
,
325 EFI_OPEN_PROTOCOL_GET_PROTOCOL
328 // if we don't then we must be the root shell (error is expected)
330 if (EFI_ERROR (Status
)) {
331 *RootShellInstance
= TRUE
;
335 // Allocate the new structure
337 *NewShellParameters
= AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL
));
338 if ((*NewShellParameters
) == NULL
) {
339 return (EFI_OUT_OF_RESOURCES
);
343 // get loaded image protocol
345 Status
= gBS
->OpenProtocol (
347 &gEfiLoadedImageProtocolGuid
,
348 (VOID
**) &LoadedImage
,
351 EFI_OPEN_PROTOCOL_GET_PROTOCOL
353 ASSERT_EFI_ERROR(Status
);
355 // Build the full command line
357 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
358 if (Status
== EFI_BUFFER_TOO_SMALL
) {
359 FullCommandLine
= AllocateZeroPool(Size
+ LoadedImage
->LoadOptionsSize
);
360 Status
= SHELL_GET_ENVIRONMENT_VARIABLE(L
"ShellOpt", &Size
, FullCommandLine
);
362 if (Status
== EFI_NOT_FOUND
) {
364 // no parameters via environment... ok
367 if (EFI_ERROR(Status
)) {
371 if (Size
== 0 && LoadedImage
->LoadOptionsSize
!= 0) {
372 ASSERT(FullCommandLine
== NULL
);
374 // Now we need to include a NULL terminator in the size.
376 Size
= LoadedImage
->LoadOptionsSize
+ sizeof(FullCommandLine
[0]);
377 FullCommandLine
= AllocateZeroPool(Size
);
379 if (FullCommandLine
!= NULL
) {
380 CopyMem (FullCommandLine
, LoadedImage
->LoadOptions
, LoadedImage
->LoadOptionsSize
);
382 // Populate Argc and Argv
384 Status
= ParseCommandLineToArgs(FullCommandLine
,
386 &(*NewShellParameters
)->Argv
,
387 &(*NewShellParameters
)->Argc
);
389 FreePool(FullCommandLine
);
391 ASSERT_EFI_ERROR(Status
);
393 (*NewShellParameters
)->Argv
= NULL
;
394 (*NewShellParameters
)->Argc
= 0;
398 // Populate the 3 faked file systems...
400 if (*RootShellInstance
) {
401 (*NewShellParameters
)->StdIn
= &FileInterfaceStdIn
;
402 (*NewShellParameters
)->StdOut
= &FileInterfaceStdOut
;
403 (*NewShellParameters
)->StdErr
= &FileInterfaceStdErr
;
404 Status
= gBS
->InstallProtocolInterface(&gImageHandle
,
405 &gEfiShellParametersProtocolGuid
,
406 EFI_NATIVE_INTERFACE
,
407 (VOID
*)(*NewShellParameters
));
410 // copy from the existing ones
412 (*NewShellParameters
)->StdIn
= ShellInfoObject
.OldShellParameters
->StdIn
;
413 (*NewShellParameters
)->StdOut
= ShellInfoObject
.OldShellParameters
->StdOut
;
414 (*NewShellParameters
)->StdErr
= ShellInfoObject
.OldShellParameters
->StdErr
;
415 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
416 &gEfiShellParametersProtocolGuid
,
417 (VOID
*)ShellInfoObject
.OldShellParameters
,
418 (VOID
*)(*NewShellParameters
));
425 frees all memory used by createion and installation of shell parameters protocol
426 and if there was an old version installed it will restore that one.
428 @param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is
431 @retval EFI_SUCCESS the cleanup was successful
432 @return other the cleanup failed
433 @sa ReinstallProtocolInterface
434 @sa UninstallProtocolInterface
437 CleanUpShellParametersProtocol (
438 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*NewShellParameters
445 // If the old exists we need to restore it
447 if (ShellInfoObject
.OldShellParameters
!= NULL
) {
448 Status
= gBS
->ReinstallProtocolInterface(gImageHandle
,
449 &gEfiShellParametersProtocolGuid
,
450 (VOID
*)NewShellParameters
,
451 (VOID
*)ShellInfoObject
.OldShellParameters
);
452 DEBUG_CODE(ShellInfoObject
.OldShellParameters
= NULL
;);
455 // No old one, just uninstall us...
457 Status
= gBS
->UninstallProtocolInterface(gImageHandle
,
458 &gEfiShellParametersProtocolGuid
,
459 (VOID
*)NewShellParameters
);
461 if (NewShellParameters
->Argv
!= NULL
) {
462 for ( LoopCounter
= 0
463 ; LoopCounter
< NewShellParameters
->Argc
466 FreePool(NewShellParameters
->Argv
[LoopCounter
]);
468 FreePool(NewShellParameters
->Argv
);
470 FreePool(NewShellParameters
);
475 Determin if a file name represents a unicode file.
477 @param[in] FileName Pointer to the filename to open.
479 @retval EFI_SUCCESS The file is a unicode file.
480 @return An error upon failure.
484 IN CONST CHAR16
*FileName
487 SHELL_FILE_HANDLE Handle
;
489 UINT64 OriginalFilePosition
;
493 Status
= gEfiShellProtocol
->OpenFileByName(FileName
, &Handle
, EFI_FILE_MODE_READ
);
494 if (EFI_ERROR(Status
)) {
497 gEfiShellProtocol
->GetFilePosition(Handle
, &OriginalFilePosition
);
498 gEfiShellProtocol
->SetFilePosition(Handle
, 0);
499 CharSize
= sizeof(CHAR16
);
500 Status
= gEfiShellProtocol
->ReadFile(Handle
, &CharSize
, &CharBuffer
);
501 if (EFI_ERROR(Status
) || CharBuffer
!= gUnicodeFileTag
) {
502 Status
= EFI_BUFFER_TOO_SMALL
;
504 gEfiShellProtocol
->SetFilePosition(Handle
, OriginalFilePosition
);
505 gEfiShellProtocol
->CloseFile(Handle
);
510 Strips out quotes sections of a string.
512 All of the characters between quotes is replaced with spaces.
514 @param[in, out] TheString A pointer to the string to update.
518 IN OUT CHAR16
*TheString
523 for (RemoveNow
= FALSE
; TheString
!= NULL
&& *TheString
!= CHAR_NULL
; TheString
++) {
524 if (*TheString
== L
'^' && *(TheString
+ 1) == L
'\"') {
526 } else if (*TheString
== L
'\"') {
527 RemoveNow
= (BOOLEAN
)!RemoveNow
;
528 } else if (RemoveNow
) {
535 Calcualte the 32-bit CRC in a EFI table using the service provided by the
538 @param Hdr Pointer to an EFI standard header
543 IN OUT EFI_TABLE_HEADER
*Hdr
551 // If gBS->CalculateCrce32 () == CoreEfiNotAvailableYet () then
552 // Crc will come back as zero if we set it to zero here
555 gBS
->CalculateCrc32 ((UINT8
*)Hdr
, Hdr
->HeaderSize
, &Crc
);
560 Fix a string to only have the file name, removing starting at the first space of whatever is quoted.
562 @param[in] FileName The filename to start with.
564 @retval NULL FileName was invalid.
565 @return The modified FileName.
573 CHAR16
*TempLocation
;
575 if (FileName
== NULL
) {
579 if (FileName
[0] == L
'\"') {
581 if ((TempLocation
= StrStr(Copy
, L
"\"")) != NULL
) {
582 TempLocation
[0] = CHAR_NULL
;
586 while(Copy
[0] == L
' ') {
589 if ((TempLocation
= StrStr(Copy
, L
" ")) != NULL
) {
590 TempLocation
[0] = CHAR_NULL
;
594 if (Copy
[0] == CHAR_NULL
) {
602 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 %.
604 @param[in] FileName The filename to start with.
606 @retval NULL FileName was invalid.
607 @return The modified FileName.
615 CHAR16
*TempLocation
;
619 if (FileName
[0] == L
'%') {
621 if ((TempLocation
= StrStr(Copy
, L
"%")) != NULL
) {
622 TempLocation
[0] = CHAR_NULL
;
626 return (FixFileName(Copy
));
630 Remove the unicode file tag from the begining of the file buffer since that will not be
633 @param[in] Handle Pointer to the handle of the file to be processed.
635 @retval EFI_SUCCESS The unicode file tag has been moved successfully.
639 IN SHELL_FILE_HANDLE
*Handle
645 CharSize
= sizeof(CHAR16
);
647 gEfiShellProtocol
->ReadFile(*Handle
, &CharSize
, &CharBuffer
);
648 if (CharBuffer
!= gUnicodeFileTag
) {
649 gEfiShellProtocol
->SetFilePosition(*Handle
, 0);
651 return (EFI_SUCCESS
);
655 Write the unicode file tag to the specified file.
657 It is the caller's responsibility to ensure that
658 ShellInfoObject.NewEfiShellProtocol has been initialized before calling this
661 @param[in] FileHandle The file to write the unicode file tag to.
663 @return Status code from ShellInfoObject.NewEfiShellProtocol->WriteFile.
667 IN SHELL_FILE_HANDLE FileHandle
674 FileTag
= gUnicodeFileTag
;
675 Size
= sizeof FileTag
;
676 Status
= ShellInfoObject
.NewEfiShellProtocol
->WriteFile (FileHandle
, &Size
,
678 ASSERT (EFI_ERROR (Status
) || Size
== sizeof FileTag
);
684 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
685 structure by parsing NewCommandLine. The current values are returned to the
688 This will also update the system table.
690 @param[in, out] ShellParameters Pointer to parameter structure to modify.
691 @param[in] NewCommandLine The new command line to parse and use.
692 @param[out] OldStdIn Pointer to old StdIn.
693 @param[out] OldStdOut Pointer to old StdOut.
694 @param[out] OldStdErr Pointer to old StdErr.
695 @param[out] SystemTableInfo Pointer to old system table information.
697 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
698 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
701 UpdateStdInStdOutStdErr(
702 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
703 IN CHAR16
*NewCommandLine
,
704 OUT SHELL_FILE_HANDLE
*OldStdIn
,
705 OUT SHELL_FILE_HANDLE
*OldStdOut
,
706 OUT SHELL_FILE_HANDLE
*OldStdErr
,
707 OUT SYSTEM_TABLE_INFO
*SystemTableInfo
710 CHAR16
*CommandLineCopy
;
711 CHAR16
*CommandLineWalker
;
712 CHAR16
*StdErrFileName
;
713 CHAR16
*StdOutFileName
;
714 CHAR16
*StdInFileName
;
715 CHAR16
*StdInVarName
;
716 CHAR16
*StdOutVarName
;
717 CHAR16
*StdErrVarName
;
719 SHELL_FILE_HANDLE TempHandle
;
728 CHAR16
*FirstLocation
;
733 AsciiRedirection
= FALSE
;
736 StdOutVarName
= NULL
;
737 StdErrVarName
= NULL
;
738 StdErrFileName
= NULL
;
739 StdInFileName
= NULL
;
740 StdOutFileName
= NULL
;
743 CommandLineCopy
= NULL
;
744 FirstLocation
= NULL
;
746 if (ShellParameters
== NULL
|| SystemTableInfo
== NULL
|| OldStdIn
== NULL
|| OldStdOut
== NULL
|| OldStdErr
== NULL
) {
747 return (EFI_INVALID_PARAMETER
);
750 SystemTableInfo
->ConIn
= gST
->ConIn
;
751 SystemTableInfo
->ConInHandle
= gST
->ConsoleInHandle
;
752 SystemTableInfo
->ConOut
= gST
->ConOut
;
753 SystemTableInfo
->ConOutHandle
= gST
->ConsoleOutHandle
;
754 SystemTableInfo
->ErrOut
= gST
->StdErr
;
755 SystemTableInfo
->ErrOutHandle
= gST
->StandardErrorHandle
;
756 *OldStdIn
= ShellParameters
->StdIn
;
757 *OldStdOut
= ShellParameters
->StdOut
;
758 *OldStdErr
= ShellParameters
->StdErr
;
760 if (NewCommandLine
== NULL
) {
761 return (EFI_SUCCESS
);
764 CommandLineCopy
= StrnCatGrow(&CommandLineCopy
, NULL
, NewCommandLine
, 0);
765 if (CommandLineCopy
== NULL
) {
766 return (EFI_OUT_OF_RESOURCES
);
768 Status
= EFI_SUCCESS
;
770 FirstLocation
= CommandLineCopy
+ StrLen(CommandLineCopy
);
772 StripQuotes(CommandLineCopy
);
774 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
775 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
776 if (Split
!= NULL
&& Split
->SplitStdIn
!= NULL
) {
777 ShellParameters
->StdIn
= Split
->SplitStdIn
;
779 if (Split
!= NULL
&& Split
->SplitStdOut
!= NULL
) {
780 ShellParameters
->StdOut
= Split
->SplitStdOut
;
784 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>>v ")) != NULL
) {
785 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
786 SetMem16(CommandLineWalker
, 12, L
' ');
787 StdErrVarName
= CommandLineWalker
+= 6;
789 if (StrStr(CommandLineWalker
, L
" 2>>v ") != NULL
) {
790 Status
= EFI_NOT_FOUND
;
793 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>v ")) != NULL
) {
794 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
795 SetMem16(CommandLineWalker
, 12, L
' ');
796 StdOutVarName
= CommandLineWalker
+= 6;
798 if (StrStr(CommandLineWalker
, L
" 1>>v ") != NULL
) {
799 Status
= EFI_NOT_FOUND
;
801 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>v ")) != NULL
) {
802 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
803 SetMem16(CommandLineWalker
, 10, L
' ');
804 StdOutVarName
= CommandLineWalker
+= 5;
806 if (StrStr(CommandLineWalker
, L
" >>v ") != NULL
) {
807 Status
= EFI_NOT_FOUND
;
809 } else if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >v ")) != NULL
) {
810 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
811 SetMem16(CommandLineWalker
, 8, L
' ');
812 StdOutVarName
= CommandLineWalker
+= 4;
814 if (StrStr(CommandLineWalker
, L
" >v ") != NULL
) {
815 Status
= EFI_NOT_FOUND
;
818 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>>a ")) != NULL
) {
819 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
820 SetMem16(CommandLineWalker
, 12, L
' ');
821 StdOutFileName
= CommandLineWalker
+= 6;
824 if (StrStr(CommandLineWalker
, L
" 1>>a ") != NULL
) {
825 Status
= EFI_NOT_FOUND
;
828 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>> ")) != NULL
) {
829 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
830 SetMem16(CommandLineWalker
, 10, L
' ');
831 if (StdOutFileName
!= NULL
) {
832 Status
= EFI_INVALID_PARAMETER
;
834 StdOutFileName
= CommandLineWalker
+= 5;
837 if (StrStr(CommandLineWalker
, L
" 1>> ") != NULL
) {
838 Status
= EFI_NOT_FOUND
;
841 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >> ")) != NULL
) {
842 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
843 SetMem16(CommandLineWalker
, 8, L
' ');
844 if (StdOutFileName
!= NULL
) {
845 Status
= EFI_INVALID_PARAMETER
;
847 StdOutFileName
= CommandLineWalker
+= 4;
850 if (StrStr(CommandLineWalker
, L
" >> ") != NULL
) {
851 Status
= EFI_NOT_FOUND
;
854 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >>a ")) != NULL
) {
855 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
856 SetMem16(CommandLineWalker
, 10, L
' ');
857 if (StdOutFileName
!= NULL
) {
858 Status
= EFI_INVALID_PARAMETER
;
860 StdOutFileName
= CommandLineWalker
+= 5;
864 if (StrStr(CommandLineWalker
, L
" >>a ") != NULL
) {
865 Status
= EFI_NOT_FOUND
;
868 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>a ")) != NULL
) {
869 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
870 SetMem16(CommandLineWalker
, 10, L
' ');
871 if (StdOutFileName
!= NULL
) {
872 Status
= EFI_INVALID_PARAMETER
;
874 StdOutFileName
= CommandLineWalker
+= 5;
878 if (StrStr(CommandLineWalker
, L
" 1>a ") != NULL
) {
879 Status
= EFI_NOT_FOUND
;
882 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" >a ")) != NULL
) {
883 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
884 SetMem16(CommandLineWalker
, 8, L
' ');
885 if (StdOutFileName
!= NULL
) {
886 Status
= EFI_INVALID_PARAMETER
;
888 StdOutFileName
= CommandLineWalker
+= 4;
892 if (StrStr(CommandLineWalker
, L
" >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
, 10, L
' ');
899 if (StdErrFileName
!= NULL
) {
900 Status
= EFI_INVALID_PARAMETER
;
902 StdErrFileName
= CommandLineWalker
+= 5;
905 if (StrStr(CommandLineWalker
, L
" 2>> ") != NULL
) {
906 Status
= EFI_NOT_FOUND
;
910 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>v ")) != NULL
) {
911 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
912 SetMem16(CommandLineWalker
, 10, L
' ');
913 if (StdErrVarName
!= NULL
) {
914 Status
= EFI_INVALID_PARAMETER
;
916 StdErrVarName
= CommandLineWalker
+= 5;
919 if (StrStr(CommandLineWalker
, L
" 2>v ") != NULL
) {
920 Status
= EFI_NOT_FOUND
;
923 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1>v ")) != NULL
) {
924 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
925 SetMem16(CommandLineWalker
, 10, L
' ');
926 if (StdOutVarName
!= NULL
) {
927 Status
= EFI_INVALID_PARAMETER
;
929 StdOutVarName
= CommandLineWalker
+= 5;
932 if (StrStr(CommandLineWalker
, L
" 1>v ") != NULL
) {
933 Status
= EFI_NOT_FOUND
;
936 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2>a ")) != NULL
) {
937 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
938 SetMem16(CommandLineWalker
, 10, L
' ');
939 if (StdErrFileName
!= NULL
) {
940 Status
= EFI_INVALID_PARAMETER
;
942 StdErrFileName
= CommandLineWalker
+= 5;
946 if (StrStr(CommandLineWalker
, L
" 2>a ") != NULL
) {
947 Status
= EFI_NOT_FOUND
;
950 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 2> ")) != NULL
) {
951 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
952 SetMem16(CommandLineWalker
, 8, L
' ');
953 if (StdErrFileName
!= NULL
) {
954 Status
= EFI_INVALID_PARAMETER
;
956 StdErrFileName
= CommandLineWalker
+= 4;
959 if (StrStr(CommandLineWalker
, L
" 2> ") != NULL
) {
960 Status
= EFI_NOT_FOUND
;
964 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" 1> ")) != NULL
) {
965 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
966 SetMem16(CommandLineWalker
, 8, L
' ');
967 if (StdOutFileName
!= NULL
) {
968 Status
= EFI_INVALID_PARAMETER
;
970 StdOutFileName
= CommandLineWalker
+= 4;
973 if (StrStr(CommandLineWalker
, L
" 1> ") != NULL
) {
974 Status
= EFI_NOT_FOUND
;
978 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" > ")) != NULL
) {
979 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
980 SetMem16(CommandLineWalker
, 6, L
' ');
981 if (StdOutFileName
!= NULL
) {
982 Status
= EFI_INVALID_PARAMETER
;
984 StdOutFileName
= CommandLineWalker
+= 3;
987 if (StrStr(CommandLineWalker
, L
" > ") != NULL
) {
988 Status
= EFI_NOT_FOUND
;
992 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" < ")) != NULL
) {
993 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
994 SetMem16(CommandLineWalker
, 6, L
' ');
995 if (StdInFileName
!= NULL
) {
996 Status
= EFI_INVALID_PARAMETER
;
998 StdInFileName
= CommandLineWalker
+= 3;
1000 if (StrStr(CommandLineWalker
, L
" < ") != NULL
) {
1001 Status
= EFI_NOT_FOUND
;
1004 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <a ")) != NULL
) {
1005 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
1006 SetMem16(CommandLineWalker
, 8, L
' ');
1007 if (StdInFileName
!= NULL
) {
1008 Status
= EFI_INVALID_PARAMETER
;
1010 StdInFileName
= CommandLineWalker
+= 4;
1012 AsciiRedirection
= TRUE
;
1014 if (StrStr(CommandLineWalker
, L
" <a ") != NULL
) {
1015 Status
= EFI_NOT_FOUND
;
1018 if (!EFI_ERROR(Status
) && (CommandLineWalker
= StrStr(CommandLineCopy
, L
" <v ")) != NULL
) {
1019 FirstLocation
= MIN(CommandLineWalker
, FirstLocation
);
1020 SetMem16(CommandLineWalker
, 8, L
' ');
1021 if (StdInVarName
!= NULL
) {
1022 Status
= EFI_INVALID_PARAMETER
;
1024 StdInVarName
= CommandLineWalker
+= 4;
1026 if (StrStr(CommandLineWalker
, L
" <v ") != NULL
) {
1027 Status
= EFI_NOT_FOUND
;
1032 // re-populate the string to support any filenames that were in quotes.
1034 StrnCpyS(CommandLineCopy
, StrSize(CommandLineCopy
)/sizeof(CHAR16
), NewCommandLine
, StrLen(NewCommandLine
));
1036 if (FirstLocation
!= CommandLineCopy
+ StrLen(CommandLineCopy
)
1037 && (((UINTN
)FirstLocation
- (UINTN
)CommandLineCopy
)/sizeof(CHAR16
) < StrLen(NewCommandLine
))
1039 *(NewCommandLine
+ ((UINTN
)FirstLocation
- (UINTN
)CommandLineCopy
)/sizeof(CHAR16
)) = CHAR_NULL
;
1042 if (!EFI_ERROR(Status
)) {
1044 if (StdErrFileName
!= NULL
) {
1045 if ((StdErrFileName
= FixFileName(StdErrFileName
)) == NULL
) {
1046 Status
= EFI_INVALID_PARAMETER
;
1049 if (StdOutFileName
!= NULL
) {
1050 if ((StdOutFileName
= FixFileName(StdOutFileName
)) == NULL
) {
1051 Status
= EFI_INVALID_PARAMETER
;
1054 if (StdInFileName
!= NULL
) {
1055 if ((StdInFileName
= FixFileName(StdInFileName
)) == NULL
) {
1056 Status
= EFI_INVALID_PARAMETER
;
1059 if (StdErrVarName
!= NULL
) {
1060 if ((StdErrVarName
= FixVarName(StdErrVarName
)) == NULL
) {
1061 Status
= EFI_INVALID_PARAMETER
;
1064 if (StdOutVarName
!= NULL
) {
1065 if ((StdOutVarName
= FixVarName(StdOutVarName
)) == NULL
) {
1066 Status
= EFI_INVALID_PARAMETER
;
1069 if (StdInVarName
!= NULL
) {
1070 if ((StdInVarName
= FixVarName(StdInVarName
)) == NULL
) {
1071 Status
= EFI_INVALID_PARAMETER
;
1076 // Verify not the same and not duplicating something from a split
1080 // Check that no 2 filenames are the same
1082 (StdErrFileName
!= NULL
&& StdOutFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdOutFileName
) == 0)
1083 ||(StdErrFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdErrFileName
, &StdInFileName
) == 0)
1084 ||(StdOutFileName
!= NULL
&& StdInFileName
!= NULL
&& StringNoCaseCompare(&StdOutFileName
, &StdInFileName
) == 0)
1086 // Check that no 2 variable names are the same
1088 ||(StdErrVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdInVarName
) == 0)
1089 ||(StdOutVarName
!= NULL
&& StdInVarName
!= NULL
&& StringNoCaseCompare(&StdOutVarName
, &StdInVarName
) == 0)
1090 ||(StdErrVarName
!= NULL
&& StdOutVarName
!= NULL
&& StringNoCaseCompare(&StdErrVarName
, &StdOutVarName
) == 0)
1092 // When a split (using | operator) is in place some are not allowed
1094 ||(Split
!= NULL
&& Split
->SplitStdIn
!= NULL
&& (StdInVarName
!= NULL
|| StdInFileName
!= NULL
))
1095 ||(Split
!= NULL
&& Split
->SplitStdOut
!= NULL
&& (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
))
1097 // Check that nothing is trying to be output to 2 locations.
1099 ||(StdErrFileName
!= NULL
&& StdErrVarName
!= NULL
)
1100 ||(StdOutFileName
!= NULL
&& StdOutVarName
!= NULL
)
1101 ||(StdInFileName
!= NULL
&& StdInVarName
!= NULL
)
1103 // Check for no volatile environment variables
1105 ||(StdErrVarName
!= NULL
&& !EFI_ERROR (IsVolatileEnv (StdErrVarName
, &Volatile
)) && !Volatile
)
1106 ||(StdOutVarName
!= NULL
&& !EFI_ERROR (IsVolatileEnv (StdOutVarName
, &Volatile
)) && !Volatile
)
1108 // Cant redirect during a reconnect operation.
1110 ||(StrStr(NewCommandLine
, L
"connect -r") != NULL
1111 && (StdOutVarName
!= NULL
|| StdOutFileName
!= NULL
|| StdErrFileName
!= NULL
|| StdErrVarName
!= NULL
))
1113 // Check that filetypes (Unicode/Ascii) do not change during an append
1115 ||(StdOutFileName
!= NULL
&& OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1116 ||(StdErrFileName
!= NULL
&& ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1117 ||(StdOutFileName
!= NULL
&& !OutUnicode
&& OutAppend
&& (!EFI_ERROR(ShellFileExists(StdOutFileName
)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName
))))
1118 ||(StdErrFileName
!= NULL
&& !ErrUnicode
&& ErrAppend
&& (!EFI_ERROR(ShellFileExists(StdErrFileName
)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName
))))
1120 Status
= EFI_INVALID_PARAMETER
;
1121 ShellParameters
->StdIn
= *OldStdIn
;
1122 ShellParameters
->StdOut
= *OldStdOut
;
1123 ShellParameters
->StdErr
= *OldStdErr
;
1124 } else if (!EFI_ERROR(Status
)){
1126 // Open the Std<Whatever> and we should not have conflicts here...
1132 if (StdErrFileName
!= NULL
) {
1135 // delete existing file.
1137 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdErrFileName
);
1139 Status
= ShellOpenFileByName(StdErrFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1140 if (!ErrAppend
&& ErrUnicode
&& !EFI_ERROR(Status
)) {
1141 Status
= WriteFileTag (TempHandle
);
1143 if (!ErrUnicode
&& !EFI_ERROR(Status
)) {
1144 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1145 ASSERT(TempHandle
!= NULL
);
1147 if (!EFI_ERROR(Status
)) {
1148 ShellParameters
->StdErr
= TempHandle
;
1149 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1156 if (!EFI_ERROR(Status
) && StdOutFileName
!= NULL
) {
1159 // delete existing file.
1161 ShellInfoObject
.NewEfiShellProtocol
->DeleteFileByName(StdOutFileName
);
1163 Status
= ShellOpenFileByName(StdOutFileName
, &TempHandle
, EFI_FILE_MODE_WRITE
|EFI_FILE_MODE_READ
|EFI_FILE_MODE_CREATE
,0);
1164 if (TempHandle
== NULL
) {
1165 Status
= EFI_INVALID_PARAMETER
;
1167 if (gUnicodeCollation
->MetaiMatch (gUnicodeCollation
, StdOutFileName
, L
"NUL")) {
1169 } else if (!OutAppend
&& OutUnicode
&& !EFI_ERROR(Status
)) {
1170 Status
= WriteFileTag (TempHandle
);
1171 } else if (OutAppend
) {
1172 Status
= ShellInfoObject
.NewEfiShellProtocol
->GetFileSize(TempHandle
, &FileSize
);
1173 if (!EFI_ERROR(Status
)) {
1175 // When appending to a new unicode file, write the file tag.
1176 // Otherwise (ie. when appending to a new ASCII file, or an
1177 // existent file with any encoding), just seek to the end.
1179 Status
= (FileSize
== 0 && OutUnicode
) ?
1180 WriteFileTag (TempHandle
) :
1181 ShellInfoObject
.NewEfiShellProtocol
->SetFilePosition (
1186 if (!OutUnicode
&& !EFI_ERROR(Status
)) {
1187 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1188 ASSERT(TempHandle
!= NULL
);
1190 if (!EFI_ERROR(Status
)) {
1191 ShellParameters
->StdOut
= TempHandle
;
1192 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1200 if (!EFI_ERROR(Status
) && StdOutVarName
!= NULL
) {
1203 // delete existing variable.
1205 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName
, 0, L
"");
1207 TempHandle
= CreateFileInterfaceEnv(StdOutVarName
);
1208 ASSERT(TempHandle
!= NULL
);
1209 ShellParameters
->StdOut
= TempHandle
;
1210 gST
->ConOut
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->ConsoleOutHandle
, gST
->ConOut
);
1216 if (!EFI_ERROR(Status
) && StdErrVarName
!= NULL
) {
1219 // delete existing variable.
1221 SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName
, 0, L
"");
1223 TempHandle
= CreateFileInterfaceEnv(StdErrVarName
);
1224 ASSERT(TempHandle
!= NULL
);
1225 ShellParameters
->StdErr
= TempHandle
;
1226 gST
->StdErr
= CreateSimpleTextOutOnFile(TempHandle
, &gST
->StandardErrorHandle
, gST
->StdErr
);
1232 if (!EFI_ERROR(Status
) && StdInVarName
!= NULL
) {
1233 TempHandle
= CreateFileInterfaceEnv(StdInVarName
);
1234 if (TempHandle
== NULL
) {
1235 Status
= EFI_OUT_OF_RESOURCES
;
1238 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1241 if (TempHandle
== NULL
|| ((EFI_FILE_PROTOCOL
*)TempHandle
)->Read(TempHandle
, &Size
, NULL
) != EFI_BUFFER_TOO_SMALL
) {
1242 Status
= EFI_INVALID_PARAMETER
;
1244 ShellParameters
->StdIn
= TempHandle
;
1245 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1251 // StdIn from a file
1253 if (!EFI_ERROR(Status
) && StdInFileName
!= NULL
) {
1254 Status
= ShellOpenFileByName(
1259 if (!EFI_ERROR(Status
)) {
1262 // Create the ASCII->Unicode conversion layer
1264 TempHandle
= CreateFileInterfaceFile(TempHandle
, FALSE
);
1266 ShellParameters
->StdIn
= TempHandle
;
1267 gST
->ConIn
= CreateSimpleTextInOnFile(TempHandle
, &gST
->ConsoleInHandle
);
1272 FreePool(CommandLineCopy
);
1274 CalculateEfiHdrCrc(&gST
->Hdr
);
1276 if (gST
->ConIn
== NULL
||gST
->ConOut
== NULL
) {
1277 Status
= EFI_OUT_OF_RESOURCES
;
1280 if (Status
== EFI_NOT_FOUND
) {
1281 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR
), ShellInfoObject
.HiiHandle
);
1282 } else if (EFI_ERROR(Status
)) {
1283 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_INVALID_REDIR
), ShellInfoObject
.HiiHandle
);
1290 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
1291 structure with StdIn and StdOut. The current values are de-allocated.
1293 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1294 @param[in] OldStdIn Pointer to old StdIn.
1295 @param[in] OldStdOut Pointer to old StdOut.
1296 @param[in] OldStdErr Pointer to old StdErr.
1297 @param[in] SystemTableInfo Pointer to old system table information.
1300 RestoreStdInStdOutStdErr (
1301 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1302 IN SHELL_FILE_HANDLE
*OldStdIn
,
1303 IN SHELL_FILE_HANDLE
*OldStdOut
,
1304 IN SHELL_FILE_HANDLE
*OldStdErr
,
1305 IN SYSTEM_TABLE_INFO
*SystemTableInfo
1310 if (ShellParameters
== NULL
1314 ||SystemTableInfo
== NULL
) {
1315 return (EFI_INVALID_PARAMETER
);
1317 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
1318 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
1322 if (ShellParameters
->StdIn
!= *OldStdIn
) {
1323 if ((Split
!= NULL
&& Split
->SplitStdIn
!= ShellParameters
->StdIn
) || Split
== NULL
) {
1324 gEfiShellProtocol
->CloseFile(ShellParameters
->StdIn
);
1326 ShellParameters
->StdIn
= *OldStdIn
;
1328 if (ShellParameters
->StdOut
!= *OldStdOut
) {
1329 if ((Split
!= NULL
&& Split
->SplitStdOut
!= ShellParameters
->StdOut
) || Split
== NULL
) {
1330 gEfiShellProtocol
->CloseFile(ShellParameters
->StdOut
);
1332 ShellParameters
->StdOut
= *OldStdOut
;
1334 if (ShellParameters
->StdErr
!= *OldStdErr
) {
1335 gEfiShellProtocol
->CloseFile(ShellParameters
->StdErr
);
1336 ShellParameters
->StdErr
= *OldStdErr
;
1339 if (gST
->ConIn
!= SystemTableInfo
->ConIn
) {
1340 CloseSimpleTextInOnFile(gST
->ConIn
);
1341 gST
->ConIn
= SystemTableInfo
->ConIn
;
1342 gST
->ConsoleInHandle
= SystemTableInfo
->ConInHandle
;
1344 if (gST
->ConOut
!= SystemTableInfo
->ConOut
) {
1345 CloseSimpleTextOutOnFile(gST
->ConOut
);
1346 gST
->ConOut
= SystemTableInfo
->ConOut
;
1347 gST
->ConsoleOutHandle
= SystemTableInfo
->ConOutHandle
;
1349 if (gST
->StdErr
!= SystemTableInfo
->ErrOut
) {
1350 CloseSimpleTextOutOnFile(gST
->StdErr
);
1351 gST
->StdErr
= SystemTableInfo
->ErrOut
;
1352 gST
->StandardErrorHandle
= SystemTableInfo
->ErrOutHandle
;
1355 CalculateEfiHdrCrc(&gST
->Hdr
);
1357 return (EFI_SUCCESS
);
1360 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1361 structure by parsing NewCommandLine. The current values are returned to the
1364 If OldArgv or OldArgc is NULL then that value is not returned.
1366 @param[in, out] ShellParameters Pointer to parameter structure to modify.
1367 @param[in] NewCommandLine The new command line to parse and use.
1368 @param[in] Type The type of operation.
1369 @param[out] OldArgv Pointer to old list of parameters.
1370 @param[out] OldArgc Pointer to old number of items in Argv list.
1372 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.
1373 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1377 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1378 IN CONST CHAR16
*NewCommandLine
,
1379 IN SHELL_OPERATION_TYPES Type
,
1380 OUT CHAR16
***OldArgv OPTIONAL
,
1381 OUT UINTN
*OldArgc OPTIONAL
1384 BOOLEAN StripParamQuotation
;
1386 ASSERT(ShellParameters
!= NULL
);
1387 StripParamQuotation
= TRUE
;
1389 if (OldArgc
!= NULL
) {
1390 *OldArgc
= ShellParameters
->Argc
;
1392 if (OldArgc
!= NULL
) {
1393 *OldArgv
= ShellParameters
->Argv
;
1396 if (Type
== Script_File_Name
) {
1397 StripParamQuotation
= FALSE
;
1400 return ParseCommandLineToArgs( NewCommandLine
,
1401 StripParamQuotation
,
1402 &(ShellParameters
->Argv
),
1403 &(ShellParameters
->Argc
)
1408 Funcion will replace the current Argc and Argv in the ShellParameters protocol
1409 structure with Argv and Argc. The current values are de-allocated and the
1410 OldArgv must not be deallocated by the caller.
1412 @param[in, out] ShellParameters pointer to parameter structure to modify
1413 @param[in] OldArgv pointer to old list of parameters
1414 @param[in] OldArgc pointer to old number of items in Argv list
1418 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL
*ShellParameters
,
1419 IN CHAR16
***OldArgv
,
1424 ASSERT(ShellParameters
!= NULL
);
1425 ASSERT(OldArgv
!= NULL
);
1426 ASSERT(OldArgc
!= NULL
);
1428 if (ShellParameters
->Argv
!= NULL
) {
1429 for ( LoopCounter
= 0
1430 ; LoopCounter
< ShellParameters
->Argc
1433 FreePool(ShellParameters
->Argv
[LoopCounter
]);
1435 FreePool(ShellParameters
->Argv
);
1437 ShellParameters
->Argv
= *OldArgv
;
1439 ShellParameters
->Argc
= *OldArgc
;