2 This is THE shell (application)
4 Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 // Initialize the global structure
21 SHELL_INFO ShellInfoObject
= {
56 {{NULL
, NULL
}, NULL
, NULL
},
57 {{NULL
, NULL
}, NULL
, NULL
},
69 STATIC CONST CHAR16 mScriptExtension
[] = L
".NSH";
70 STATIC CONST CHAR16 mExecutableExtensions
[] = L
".NSH;.EFI";
71 STATIC CONST CHAR16 mStartupScript
[] = L
"startup.nsh";
74 Cleans off leading and trailing spaces and tabs.
76 @param[in] String pointer to the string to trim them off.
84 ASSERT(String
!= NULL
);
85 ASSERT(*String
!= NULL
);
87 // Remove any spaces and tabs at the beginning of the (*String).
89 while (((*String
)[0] == L
' ') || ((*String
)[0] == L
'\t')) {
90 CopyMem((*String
), (*String
)+1, StrSize((*String
)) - sizeof((*String
)[0]));
94 // Remove any spaces and tabs at the end of the (*String).
96 while ((StrLen (*String
) > 0) && (((*String
)[StrLen((*String
))-1] == L
' ') || ((*String
)[StrLen((*String
))-1] == L
'\t'))) {
97 (*String
)[StrLen((*String
))-1] = CHAR_NULL
;
100 return (EFI_SUCCESS
);
104 Check whether the string between a pair of % is a valid envifronment variable name.
106 @param[in] BeginPercent pointer to the first percent.
107 @param[in] EndPercent pointer to the last percent.
109 @retval TRUE is a valid environment variable name.
110 @retval FALSE is NOT a valid environment variable name.
113 IsValidEnvironmentVariableName(
114 IN CONST CHAR16
*BeginPercent
,
115 IN CONST CHAR16
*EndPercent
118 CONST CHAR16
*Walker
;
122 ASSERT (BeginPercent
!= NULL
);
123 ASSERT (EndPercent
!= NULL
);
124 ASSERT (BeginPercent
< EndPercent
);
126 if ((BeginPercent
+ 1) == EndPercent
) {
130 for (Walker
= BeginPercent
+ 1; Walker
< EndPercent
; Walker
++) {
132 (*Walker
>= L
'0' && *Walker
<= L
'9') ||
133 (*Walker
>= L
'A' && *Walker
<= L
'Z') ||
134 (*Walker
>= L
'a' && *Walker
<= L
'z') ||
137 if (Walker
== BeginPercent
+ 1 && (*Walker
>= L
'0' && *Walker
<= L
'9')) {
151 Determine if a command line contains a split operation
153 @param[in] CmdLine The command line to parse.
155 @retval TRUE CmdLine has a valid split.
156 @retval FALSE CmdLine does not have a valid split.
161 IN CONST CHAR16
*CmdLine
164 CONST CHAR16
*TempSpot
;
165 CONST CHAR16
*FirstQuote
;
166 CONST CHAR16
*SecondQuote
;
168 FirstQuote
= FindFirstCharacter (CmdLine
, L
"\"", L
'^');
170 TempSpot
= FindFirstCharacter(CmdLine
, L
"|", L
'^');
172 if (FirstQuote
== NULL
||
174 TempSpot
== CHAR_NULL
||
175 FirstQuote
> TempSpot
177 return (BOOLEAN
) ((TempSpot
!= NULL
) && (*TempSpot
!= CHAR_NULL
));
180 while ((TempSpot
!= NULL
) && (*TempSpot
!= CHAR_NULL
)) {
181 if (FirstQuote
== NULL
|| FirstQuote
> TempSpot
) {
184 SecondQuote
= FindFirstCharacter (FirstQuote
+ 1, L
"\"", L
'^');
185 if (SecondQuote
== NULL
) {
188 if (SecondQuote
< TempSpot
) {
189 FirstQuote
= FindFirstCharacter (SecondQuote
+ 1, L
"\"", L
'^');
192 FirstQuote
= FindFirstCharacter (SecondQuote
+ 1, L
"\"", L
'^');
193 TempSpot
= FindFirstCharacter(TempSpot
+ 1, L
"|", L
'^');
198 return (BOOLEAN
) ((TempSpot
!= NULL
) && (*TempSpot
!= CHAR_NULL
));
202 Function to start monitoring for CTRL-S using SimpleTextInputEx. This
203 feature's enabled state was not known when the shell initially launched.
205 @retval EFI_SUCCESS The feature is enabled.
206 @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.
210 InternalEfiShellStartCtrlSMonitor(
214 EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL
*SimpleEx
;
215 EFI_KEY_DATA KeyData
;
218 Status
= gBS
->OpenProtocol(
219 gST
->ConsoleInHandle
,
220 &gEfiSimpleTextInputExProtocolGuid
,
224 EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
225 if (EFI_ERROR(Status
)) {
230 STRING_TOKEN (STR_SHELL_NO_IN_EX
),
231 ShellInfoObject
.HiiHandle
);
232 return (EFI_SUCCESS
);
235 KeyData
.KeyState
.KeyToggleState
= 0;
236 KeyData
.Key
.ScanCode
= 0;
237 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
;
238 KeyData
.Key
.UnicodeChar
= L
's';
240 Status
= SimpleEx
->RegisterKeyNotify(
243 NotificationFunction
,
244 &ShellInfoObject
.CtrlSNotifyHandle1
);
246 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
;
247 if (!EFI_ERROR(Status
)) {
248 Status
= SimpleEx
->RegisterKeyNotify(
251 NotificationFunction
,
252 &ShellInfoObject
.CtrlSNotifyHandle2
);
254 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_LEFT_CONTROL_PRESSED
;
255 KeyData
.Key
.UnicodeChar
= 19;
257 if (!EFI_ERROR(Status
)) {
258 Status
= SimpleEx
->RegisterKeyNotify(
261 NotificationFunction
,
262 &ShellInfoObject
.CtrlSNotifyHandle3
);
264 KeyData
.KeyState
.KeyShiftState
= EFI_SHIFT_STATE_VALID
|EFI_RIGHT_CONTROL_PRESSED
;
265 if (!EFI_ERROR(Status
)) {
266 Status
= SimpleEx
->RegisterKeyNotify(
269 NotificationFunction
,
270 &ShellInfoObject
.CtrlSNotifyHandle4
);
278 The entry point for the application.
280 @param[in] ImageHandle The firmware allocated handle for the EFI image.
281 @param[in] SystemTable A pointer to the EFI System Table.
283 @retval EFI_SUCCESS The entry point is executed successfully.
284 @retval other Some error occurs when executing this entry point.
290 IN EFI_HANDLE ImageHandle
,
291 IN EFI_SYSTEM_TABLE
*SystemTable
297 EFI_HANDLE ConInHandle
;
298 EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*OldConIn
;
300 if (PcdGet8(PcdShellSupportLevel
) > 3) {
301 return (EFI_UNSUPPORTED
);
307 Status
= gST
->ConOut
->ClearScreen(gST
->ConOut
);
308 if (EFI_ERROR(Status
)) {
313 // Populate the global structure from PCDs
315 ShellInfoObject
.ImageDevPath
= NULL
;
316 ShellInfoObject
.FileDevPath
= NULL
;
317 ShellInfoObject
.PageBreakEnabled
= PcdGetBool(PcdShellPageBreakDefault
);
318 ShellInfoObject
.ViewingSettings
.InsertMode
= PcdGetBool(PcdShellInsertModeDefault
);
319 ShellInfoObject
.LogScreenCount
= PcdGet8 (PcdShellScreenLogCount
);
322 // verify we dont allow for spec violation
324 ASSERT(ShellInfoObject
.LogScreenCount
>= 3);
327 // Initialize the LIST ENTRY objects...
329 InitializeListHead(&ShellInfoObject
.BufferToFreeList
.Link
);
330 InitializeListHead(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
);
331 InitializeListHead(&ShellInfoObject
.SplitList
.Link
);
334 // Check PCDs for optional features that are not implemented yet.
336 if ( PcdGetBool(PcdShellSupportOldProtocols
)
337 || !FeaturePcdGet(PcdShellRequireHiiPlatform
)
338 || FeaturePcdGet(PcdShellSupportFrameworkHii
)
340 return (EFI_UNSUPPORTED
);
344 // turn off the watchdog timer
346 gBS
->SetWatchdogTimer (0, 0, 0, NULL
);
349 // install our console logger. This will keep a log of the output for back-browsing
351 Status
= ConsoleLoggerInstall(ShellInfoObject
.LogScreenCount
, &ShellInfoObject
.ConsoleInfo
);
352 if (!EFI_ERROR(Status
)) {
354 // Enable the cursor to be visible
356 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
359 // If supporting EFI 1.1 we need to install HII protocol
360 // only do this if PcdShellRequireHiiPlatform == FALSE
362 // remove EFI_UNSUPPORTED check above when complete.
363 ///@todo add support for Framework HII
366 // install our (solitary) HII package
368 ShellInfoObject
.HiiHandle
= HiiAddPackages (&gEfiCallerIdGuid
, gImageHandle
, ShellStrings
, NULL
);
369 if (ShellInfoObject
.HiiHandle
== NULL
) {
370 if (PcdGetBool(PcdShellSupportFrameworkHii
)) {
371 ///@todo Add our package into Framework HII
373 if (ShellInfoObject
.HiiHandle
== NULL
) {
374 Status
= EFI_NOT_STARTED
;
380 // create and install the EfiShellParametersProtocol
382 Status
= CreatePopulateInstallShellParametersProtocol(&ShellInfoObject
.NewShellParametersProtocol
, &ShellInfoObject
.RootShellInstance
);
383 ASSERT_EFI_ERROR(Status
);
384 ASSERT(ShellInfoObject
.NewShellParametersProtocol
!= NULL
);
387 // create and install the EfiShellProtocol
389 Status
= CreatePopulateInstallShellProtocol(&ShellInfoObject
.NewEfiShellProtocol
);
390 ASSERT_EFI_ERROR(Status
);
391 ASSERT(ShellInfoObject
.NewEfiShellProtocol
!= NULL
);
394 // Now initialize the shell library (it requires Shell Parameters protocol)
396 Status
= ShellInitialize();
397 ASSERT_EFI_ERROR(Status
);
399 Status
= CommandInit();
400 ASSERT_EFI_ERROR(Status
);
403 // Check the command line
405 Status
= ProcessCommandLine ();
406 if (EFI_ERROR (Status
)) {
411 // If shell support level is >= 1 create the mappings and paths
413 if (PcdGet8(PcdShellSupportLevel
) >= 1) {
414 Status
= ShellCommandCreateInitialMappingsAndPaths();
418 // save the device path for the loaded image and the device path for the filepath (under loaded image)
419 // These are where to look for the startup.nsh file
421 Status
= GetDevicePathsForImageAndFile(&ShellInfoObject
.ImageDevPath
, &ShellInfoObject
.FileDevPath
);
422 ASSERT_EFI_ERROR(Status
);
425 // Display the version
427 if (!ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoVersion
) {
430 gST
->ConOut
->Mode
->CursorRow
,
432 STRING_TOKEN (STR_VER_OUTPUT_MAIN_SHELL
),
433 ShellInfoObject
.HiiHandle
,
434 SupportLevel
[PcdGet8(PcdShellSupportLevel
)],
435 gEfiShellProtocol
->MajorVersion
,
436 gEfiShellProtocol
->MinorVersion
443 STRING_TOKEN (STR_VER_OUTPUT_MAIN_SUPPLIER
),
444 ShellInfoObject
.HiiHandle
,
445 (CHAR16
*) PcdGetPtr (PcdShellSupplier
)
452 STRING_TOKEN (STR_VER_OUTPUT_MAIN_UEFI
),
453 ShellInfoObject
.HiiHandle
,
454 (gST
->Hdr
.Revision
&0xffff0000)>>16,
455 (gST
->Hdr
.Revision
&0x0000ffff),
457 gST
->FirmwareRevision
462 // Display the mapping
464 if (PcdGet8(PcdShellSupportLevel
) >= 2 && !ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoMap
) {
465 Status
= RunCommand(L
"map");
466 ASSERT_EFI_ERROR(Status
);
470 // init all the built in alias'
472 Status
= SetBuiltInAlias();
473 ASSERT_EFI_ERROR(Status
);
476 // Initialize environment variables
478 if (ShellCommandGetProfileList() != NULL
) {
479 Status
= InternalEfiShellSetEnv(L
"profiles", ShellCommandGetProfileList(), TRUE
);
480 ASSERT_EFI_ERROR(Status
);
484 TempString
= AllocateZeroPool(Size
);
486 UnicodeSPrint(TempString
, Size
, L
"%d", PcdGet8(PcdShellSupportLevel
));
487 Status
= InternalEfiShellSetEnv(L
"uefishellsupport", TempString
, TRUE
);
488 ASSERT_EFI_ERROR(Status
);
490 UnicodeSPrint(TempString
, Size
, L
"%d.%d", ShellInfoObject
.NewEfiShellProtocol
->MajorVersion
, ShellInfoObject
.NewEfiShellProtocol
->MinorVersion
);
491 Status
= InternalEfiShellSetEnv(L
"uefishellversion", TempString
, TRUE
);
492 ASSERT_EFI_ERROR(Status
);
494 UnicodeSPrint(TempString
, Size
, L
"%d.%d", (gST
->Hdr
.Revision
& 0xFFFF0000) >> 16, gST
->Hdr
.Revision
& 0x0000FFFF);
495 Status
= InternalEfiShellSetEnv(L
"uefiversion", TempString
, TRUE
);
496 ASSERT_EFI_ERROR(Status
);
498 FreePool(TempString
);
500 if (!EFI_ERROR(Status
)) {
501 if (!ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoInterrupt
) {
503 // Set up the event for CTRL-C monitoring...
505 Status
= InernalEfiShellStartMonitor();
508 if (!EFI_ERROR(Status
) && !ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoConsoleIn
) {
510 // Set up the event for CTRL-S monitoring...
512 Status
= InternalEfiShellStartCtrlSMonitor();
515 if (!EFI_ERROR(Status
) && ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoConsoleIn
) {
517 // close off the gST->ConIn
519 OldConIn
= gST
->ConIn
;
520 ConInHandle
= gST
->ConsoleInHandle
;
521 gST
->ConIn
= CreateSimpleTextInOnFile((SHELL_FILE_HANDLE
)&FileInterfaceNulFile
, &gST
->ConsoleInHandle
);
527 if (!EFI_ERROR(Status
) && PcdGet8(PcdShellSupportLevel
) >= 1) {
529 // process the startup script or launch the called app.
531 Status
= DoStartupScript(ShellInfoObject
.ImageDevPath
, ShellInfoObject
.FileDevPath
);
534 if (!ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.Exit
&& !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel
) >= 3 || PcdGetBool(PcdShellForceConsole
)) && !EFI_ERROR(Status
) && !ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoConsoleIn
) {
536 // begin the UI waiting loop
540 // clean out all the memory allocated for CONST <something> * return values
541 // between each shell prompt presentation
543 if (!IsListEmpty(&ShellInfoObject
.BufferToFreeList
.Link
)){
544 FreeBufferList(&ShellInfoObject
.BufferToFreeList
);
548 // Reset page break back to default.
550 ShellInfoObject
.PageBreakEnabled
= PcdGetBool(PcdShellPageBreakDefault
);
551 ASSERT (ShellInfoObject
.ConsoleInfo
!= NULL
);
552 ShellInfoObject
.ConsoleInfo
->Enabled
= TRUE
;
553 ShellInfoObject
.ConsoleInfo
->RowCounter
= 0;
556 // Reset the CTRL-C event (yes we ignore the return values)
558 Status
= gBS
->CheckEvent (ShellInfoObject
.NewEfiShellProtocol
->ExecutionBreak
);
563 Status
= DoShellPrompt();
564 } while (!ShellCommandGetExit());
566 if (OldConIn
!= NULL
&& ConInHandle
!= NULL
) {
567 CloseSimpleTextInOnFile (gST
->ConIn
);
568 gST
->ConIn
= OldConIn
;
569 gST
->ConsoleInHandle
= ConInHandle
;
576 // uninstall protocols / free memory / etc...
578 if (ShellInfoObject
.UserBreakTimer
!= NULL
) {
579 gBS
->CloseEvent(ShellInfoObject
.UserBreakTimer
);
580 DEBUG_CODE(ShellInfoObject
.UserBreakTimer
= NULL
;);
582 if (ShellInfoObject
.ImageDevPath
!= NULL
) {
583 FreePool(ShellInfoObject
.ImageDevPath
);
584 DEBUG_CODE(ShellInfoObject
.ImageDevPath
= NULL
;);
586 if (ShellInfoObject
.FileDevPath
!= NULL
) {
587 FreePool(ShellInfoObject
.FileDevPath
);
588 DEBUG_CODE(ShellInfoObject
.FileDevPath
= NULL
;);
590 if (ShellInfoObject
.NewShellParametersProtocol
!= NULL
) {
591 CleanUpShellParametersProtocol(ShellInfoObject
.NewShellParametersProtocol
);
592 DEBUG_CODE(ShellInfoObject
.NewShellParametersProtocol
= NULL
;);
594 if (ShellInfoObject
.NewEfiShellProtocol
!= NULL
){
595 if (ShellInfoObject
.NewEfiShellProtocol
->IsRootShell()){
596 InternalEfiShellSetEnv(L
"cwd", NULL
, TRUE
);
598 CleanUpShellProtocol(ShellInfoObject
.NewEfiShellProtocol
);
599 DEBUG_CODE(ShellInfoObject
.NewEfiShellProtocol
= NULL
;);
602 if (!IsListEmpty(&ShellInfoObject
.BufferToFreeList
.Link
)){
603 FreeBufferList(&ShellInfoObject
.BufferToFreeList
);
606 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)){
607 ASSERT(FALSE
); ///@todo finish this de-allocation.
610 if (ShellInfoObject
.ShellInitSettings
.FileName
!= NULL
) {
611 FreePool(ShellInfoObject
.ShellInitSettings
.FileName
);
612 DEBUG_CODE(ShellInfoObject
.ShellInitSettings
.FileName
= NULL
;);
615 if (ShellInfoObject
.ShellInitSettings
.FileOptions
!= NULL
) {
616 FreePool(ShellInfoObject
.ShellInitSettings
.FileOptions
);
617 DEBUG_CODE(ShellInfoObject
.ShellInitSettings
.FileOptions
= NULL
;);
620 if (ShellInfoObject
.HiiHandle
!= NULL
) {
621 HiiRemovePackages(ShellInfoObject
.HiiHandle
);
622 DEBUG_CODE(ShellInfoObject
.HiiHandle
= NULL
;);
625 if (!IsListEmpty(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
)){
626 FreeBufferList(&ShellInfoObject
.ViewingSettings
.CommandHistory
);
629 ASSERT(ShellInfoObject
.ConsoleInfo
!= NULL
);
630 if (ShellInfoObject
.ConsoleInfo
!= NULL
) {
631 ConsoleLoggerUninstall(ShellInfoObject
.ConsoleInfo
);
632 FreePool(ShellInfoObject
.ConsoleInfo
);
633 DEBUG_CODE(ShellInfoObject
.ConsoleInfo
= NULL
;);
636 if (ShellCommandGetExit()) {
637 return ((EFI_STATUS
)ShellCommandGetExitCode());
643 Sets all the alias' that were registered with the ShellCommandLib library.
645 @retval EFI_SUCCESS all init commands were run sucessfully.
653 CONST ALIAS_LIST
*List
;
657 // Get all the commands we want to run
659 List
= ShellCommandGetInitAliasList();
662 // for each command in the List
664 for ( Node
= (ALIAS_LIST
*)GetFirstNode(&List
->Link
)
665 ; !IsNull (&List
->Link
, &Node
->Link
)
666 ; Node
= (ALIAS_LIST
*)GetNextNode(&List
->Link
, &Node
->Link
)
669 // install the alias'
671 Status
= InternalSetAlias(Node
->CommandString
, Node
->Alias
, TRUE
);
672 ASSERT_EFI_ERROR(Status
);
674 return (EFI_SUCCESS
);
678 Internal function to determine if 2 command names are really the same.
680 @param[in] Command1 The pointer to the first command name.
681 @param[in] Command2 The pointer to the second command name.
683 @retval TRUE The 2 command names are the same.
684 @retval FALSE The 2 command names are not the same.
689 IN CONST CHAR16
*Command1
,
690 IN CONST CHAR16
*Command2
693 if (StringNoCaseCompare(&Command1
, &Command2
) == 0) {
700 Internal function to determine if a command is a script only command.
702 @param[in] CommandName The pointer to the command name.
704 @retval TRUE The command is a script only command.
705 @retval FALSE The command is not a script only command.
710 IN CONST CHAR16
*CommandName
713 if (IsCommand(CommandName
, L
"for")
714 ||IsCommand(CommandName
, L
"endfor")
715 ||IsCommand(CommandName
, L
"if")
716 ||IsCommand(CommandName
, L
"else")
717 ||IsCommand(CommandName
, L
"endif")
718 ||IsCommand(CommandName
, L
"goto")) {
725 This function will populate the 2 device path protocol parameters based on the
726 global gImageHandle. The DevPath will point to the device path for the handle that has
727 loaded image protocol installed on it. The FilePath will point to the device path
728 for the file that was loaded.
730 @param[in, out] DevPath On a sucessful return the device path to the loaded image.
731 @param[in, out] FilePath On a sucessful return the device path to the file.
733 @retval EFI_SUCCESS The 2 device paths were sucessfully returned.
734 @retval other A error from gBS->HandleProtocol.
740 GetDevicePathsForImageAndFile (
741 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevPath
,
742 IN OUT EFI_DEVICE_PATH_PROTOCOL
**FilePath
746 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
747 EFI_DEVICE_PATH_PROTOCOL
*ImageDevicePath
;
749 ASSERT(DevPath
!= NULL
);
750 ASSERT(FilePath
!= NULL
);
752 Status
= gBS
->OpenProtocol (
754 &gEfiLoadedImageProtocolGuid
,
755 (VOID
**)&LoadedImage
,
758 EFI_OPEN_PROTOCOL_GET_PROTOCOL
760 if (!EFI_ERROR (Status
)) {
761 Status
= gBS
->OpenProtocol (
762 LoadedImage
->DeviceHandle
,
763 &gEfiDevicePathProtocolGuid
,
764 (VOID
**)&ImageDevicePath
,
767 EFI_OPEN_PROTOCOL_GET_PROTOCOL
769 if (!EFI_ERROR (Status
)) {
770 *DevPath
= DuplicateDevicePath (ImageDevicePath
);
771 *FilePath
= DuplicateDevicePath (LoadedImage
->FilePath
);
773 LoadedImage
->DeviceHandle
,
774 &gEfiDevicePathProtocolGuid
,
780 &gEfiLoadedImageProtocolGuid
,
788 Process all Uefi Shell 2.0 command line options.
790 see Uefi Shell 2.0 section 3.2 for full details.
792 the command line must resemble the following:
794 shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]
796 ShellOpt-options Options which control the initialization behavior of the shell.
797 These options are read from the EFI global variable "ShellOpt"
798 and are processed before options or file-name.
800 options Options which control the initialization behavior of the shell.
802 file-name The name of a UEFI shell application or script to be executed
803 after initialization is complete. By default, if file-name is
804 specified, then -nostartup is implied. Scripts are not supported
807 file-name-options The command-line options that are passed to file-name when it
810 This will initialize the ShellInfoObject.ShellInitSettings global variable.
812 @retval EFI_SUCCESS The variable is initialized.
823 CHAR16
*DelayValueStr
;
826 EFI_UNICODE_COLLATION_PROTOCOL
*UnicodeCollation
;
828 // `file-name-options` will contain arguments to `file-name` that we don't
829 // know about. This would cause ShellCommandLineParse to error, so we parse
830 // arguments manually, ignoring those after the first thing that doesn't look
831 // like a shell option (which is assumed to be `file-name`).
833 Status
= gBS
->LocateProtocol (
834 &gEfiUnicodeCollationProtocolGuid
,
836 (VOID
**) &UnicodeCollation
838 if (EFI_ERROR (Status
)) {
842 // Set default options
843 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.Startup
= FALSE
;
844 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoStartup
= FALSE
;
845 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoConsoleOut
= FALSE
;
846 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoConsoleIn
= FALSE
;
847 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoInterrupt
= FALSE
;
848 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoMap
= FALSE
;
849 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoVersion
= FALSE
;
850 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.Delay
= FALSE
;
851 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.Exit
= FALSE
;
852 ShellInfoObject
.ShellInitSettings
.Delay
= 5;
855 // Start LoopVar at 0 to parse only optional arguments at Argv[0]
856 // and parse other parameters from Argv[1]. This is for use case that
857 // UEFI Shell boot option is created, and OptionalData is provided
858 // that starts with shell command-line options.
860 for (LoopVar
= 0 ; LoopVar
< gEfiShellParametersProtocol
->Argc
; LoopVar
++) {
861 CurrentArg
= gEfiShellParametersProtocol
->Argv
[LoopVar
];
862 if (UnicodeCollation
->StriColl (
867 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.Startup
= TRUE
;
869 else if (UnicodeCollation
->StriColl (
874 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoStartup
= TRUE
;
876 else if (UnicodeCollation
->StriColl (
881 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoConsoleOut
= TRUE
;
883 else if (UnicodeCollation
->StriColl (
888 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoConsoleIn
= TRUE
;
890 else if (UnicodeCollation
->StriColl (
895 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoInterrupt
= TRUE
;
897 else if (UnicodeCollation
->StriColl (
902 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoMap
= TRUE
;
904 else if (UnicodeCollation
->StriColl (
909 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoVersion
= TRUE
;
911 else if (UnicodeCollation
->StriColl (
916 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.Delay
= TRUE
;
917 // Check for optional delay value following "-delay"
918 DelayValueStr
= gEfiShellParametersProtocol
->Argv
[LoopVar
+ 1];
919 if (DelayValueStr
!= NULL
){
920 if (*DelayValueStr
== L
':') {
923 if (!EFI_ERROR(ShellConvertStringToUint64 (
929 ShellInfoObject
.ShellInitSettings
.Delay
= (UINTN
)DelayValue
;
933 } else if (UnicodeCollation
->StriColl (
938 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.Exit
= TRUE
;
939 } else if (StrnCmp (L
"-", CurrentArg
, 1) == 0) {
940 // Unrecognised option
941 ShellPrintHiiEx(-1, -1, NULL
,
942 STRING_TOKEN (STR_GEN_PROBLEM
),
943 ShellInfoObject
.HiiHandle
,
946 return EFI_INVALID_PARAMETER
;
949 // First argument should be Shell.efi image name
955 ShellInfoObject
.ShellInitSettings
.FileName
= AllocateCopyPool(StrSize(CurrentArg
), CurrentArg
);
956 if (ShellInfoObject
.ShellInitSettings
.FileName
== NULL
) {
957 return (EFI_OUT_OF_RESOURCES
);
960 // We found `file-name`.
962 ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoStartup
= 1;
965 // Add `file-name-options`
966 for (Size
= 0 ; LoopVar
< gEfiShellParametersProtocol
->Argc
; LoopVar
++) {
967 ASSERT((ShellInfoObject
.ShellInitSettings
.FileOptions
== NULL
&& Size
== 0) || (ShellInfoObject
.ShellInitSettings
.FileOptions
!= NULL
));
968 StrnCatGrow(&ShellInfoObject
.ShellInitSettings
.FileOptions
,
972 if (ShellInfoObject
.ShellInitSettings
.FileOptions
== NULL
) {
973 SHELL_FREE_NON_NULL(ShellInfoObject
.ShellInitSettings
.FileName
);
974 return (EFI_OUT_OF_RESOURCES
);
976 StrnCatGrow(&ShellInfoObject
.ShellInitSettings
.FileOptions
,
978 gEfiShellParametersProtocol
->Argv
[LoopVar
],
980 if (ShellInfoObject
.ShellInitSettings
.FileOptions
== NULL
) {
981 SHELL_FREE_NON_NULL(ShellInfoObject
.ShellInitSettings
.FileName
);
982 return (EFI_OUT_OF_RESOURCES
);
988 // "-nointerrupt" overrides "-delay"
989 if (ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoInterrupt
) {
990 ShellInfoObject
.ShellInitSettings
.Delay
= 0;
997 Handles all interaction with the default startup script.
999 this will check that the correct command line parameters were passed, handle the delay, and then start running the script.
1001 @param ImagePath the path to the image for shell. first place to look for the startup script
1002 @param FilePath the path to the file for shell. second place to look for the startup script.
1004 @retval EFI_SUCCESS the variable is initialized.
1009 IN EFI_DEVICE_PATH_PROTOCOL
*ImagePath
,
1010 IN EFI_DEVICE_PATH_PROTOCOL
*FilePath
1016 SHELL_FILE_HANDLE FileHandle
;
1017 EFI_DEVICE_PATH_PROTOCOL
*NewPath
;
1018 EFI_DEVICE_PATH_PROTOCOL
*NamePath
;
1019 CHAR16
*FileStringPath
;
1022 CONST CHAR16
*MapName
;
1024 Key
.UnicodeChar
= CHAR_NULL
;
1028 if (!ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.Startup
&& ShellInfoObject
.ShellInitSettings
.FileName
!= NULL
) {
1030 // launch something else instead
1032 NewSize
= StrSize(ShellInfoObject
.ShellInitSettings
.FileName
);
1033 if (ShellInfoObject
.ShellInitSettings
.FileOptions
!= NULL
) {
1034 NewSize
+= StrSize(ShellInfoObject
.ShellInitSettings
.FileOptions
) + sizeof(CHAR16
);
1036 FileStringPath
= AllocateZeroPool(NewSize
);
1037 if (FileStringPath
== NULL
) {
1038 return (EFI_OUT_OF_RESOURCES
);
1040 StrnCpy(FileStringPath
, ShellInfoObject
.ShellInitSettings
.FileName
, NewSize
/sizeof(CHAR16
) -1);
1041 if (ShellInfoObject
.ShellInitSettings
.FileOptions
!= NULL
) {
1042 StrnCat(FileStringPath
, L
" ", NewSize
/sizeof(CHAR16
) - StrLen(FileStringPath
) -1);
1043 StrnCat(FileStringPath
, ShellInfoObject
.ShellInitSettings
.FileOptions
, NewSize
/sizeof(CHAR16
) - StrLen(FileStringPath
) -1);
1045 Status
= RunCommand(FileStringPath
);
1046 FreePool(FileStringPath
);
1052 // for shell level 0 we do no scripts
1053 // Without the Startup bit overriding we allow for nostartup to prevent scripts
1055 if ( (PcdGet8(PcdShellSupportLevel
) < 1)
1056 || (ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoStartup
&& !ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.Startup
)
1058 return (EFI_SUCCESS
);
1061 gST
->ConOut
->EnableCursor(gST
->ConOut
, FALSE
);
1063 // print out our warning and see if they press a key
1065 for ( Status
= EFI_UNSUPPORTED
, Delay
= ShellInfoObject
.ShellInitSettings
.Delay
1066 ; Delay
!= 0 && EFI_ERROR(Status
)
1069 ShellPrintHiiEx(0, gST
->ConOut
->Mode
->CursorRow
, NULL
, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION
), ShellInfoObject
.HiiHandle
, Delay
);
1070 gBS
->Stall (1000000);
1071 if (!ShellInfoObject
.ShellInitSettings
.BitUnion
.Bits
.NoConsoleIn
) {
1072 Status
= gST
->ConIn
->ReadKeyStroke (gST
->ConIn
, &Key
);
1075 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_CRLF
), ShellInfoObject
.HiiHandle
);
1076 gST
->ConOut
->EnableCursor(gST
->ConOut
, TRUE
);
1081 if (Status
== EFI_SUCCESS
&& Key
.UnicodeChar
== 0 && Key
.ScanCode
== SCAN_ESC
) {
1082 return (EFI_SUCCESS
);
1086 // Try the first location (must be file system)
1088 MapName
= ShellInfoObject
.NewEfiShellProtocol
->GetMapFromDevicePath(&ImagePath
);
1089 if (MapName
!= NULL
) {
1090 FileStringPath
= NULL
;
1092 FileStringPath
= StrnCatGrow(&FileStringPath
, &NewSize
, MapName
, 0);
1093 if (FileStringPath
== NULL
) {
1094 Status
= EFI_OUT_OF_RESOURCES
;
1096 TempSpot
= StrStr(FileStringPath
, L
";");
1097 if (TempSpot
!= NULL
) {
1098 *TempSpot
= CHAR_NULL
;
1100 FileStringPath
= StrnCatGrow(&FileStringPath
, &NewSize
, ((FILEPATH_DEVICE_PATH
*)FilePath
)->PathName
, 0);
1101 PathRemoveLastItem(FileStringPath
);
1102 FileStringPath
= StrnCatGrow(&FileStringPath
, &NewSize
, mStartupScript
, 0);
1103 Status
= ShellInfoObject
.NewEfiShellProtocol
->OpenFileByName(FileStringPath
, &FileHandle
, EFI_FILE_MODE_READ
);
1104 FreePool(FileStringPath
);
1107 if (EFI_ERROR(Status
)) {
1108 NamePath
= FileDevicePath (NULL
, mStartupScript
);
1109 NewPath
= AppendDevicePathNode (ImagePath
, NamePath
);
1115 Status
= InternalOpenFileDevicePath(NewPath
, &FileHandle
, EFI_FILE_MODE_READ
, 0);
1119 // If we got a file, run it
1121 if (!EFI_ERROR(Status
) && FileHandle
!= NULL
) {
1122 Status
= RunScriptFile (mStartupScript
, FileHandle
, L
"", ShellInfoObject
.NewShellParametersProtocol
);
1123 ShellInfoObject
.NewEfiShellProtocol
->CloseFile(FileHandle
);
1125 FileStringPath
= ShellFindFilePath(mStartupScript
);
1126 if (FileStringPath
== NULL
) {
1128 // we return success since we dont need to have a startup script
1130 Status
= EFI_SUCCESS
;
1131 ASSERT(FileHandle
== NULL
);
1133 Status
= RunScriptFile(FileStringPath
, NULL
, L
"", ShellInfoObject
.NewShellParametersProtocol
);
1134 FreePool(FileStringPath
);
1143 Function to perform the shell prompt looping. It will do a single prompt,
1144 dispatch the result, and then return. It is expected that the caller will
1145 call this function in a loop many times.
1148 @retval RETURN_ABORTED
1159 CONST CHAR16
*CurDir
;
1166 // Get screen setting to decide size of the command line buffer
1168 gST
->ConOut
->QueryMode (gST
->ConOut
, gST
->ConOut
->Mode
->Mode
, &Column
, &Row
);
1169 BufferSize
= Column
* Row
* sizeof (CHAR16
);
1170 CmdLine
= AllocateZeroPool (BufferSize
);
1171 if (CmdLine
== NULL
) {
1172 return EFI_OUT_OF_RESOURCES
;
1175 CurDir
= ShellInfoObject
.NewEfiShellProtocol
->GetEnv(L
"cwd");
1180 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, 0, gST
->ConOut
->Mode
->CursorRow
);
1182 if (CurDir
!= NULL
&& StrLen(CurDir
) > 1) {
1183 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_CURDIR
), ShellInfoObject
.HiiHandle
, CurDir
);
1185 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_SHELL
), ShellInfoObject
.HiiHandle
);
1189 // Read a line from the console
1191 Status
= ShellInfoObject
.NewEfiShellProtocol
->ReadFile(ShellInfoObject
.NewShellParametersProtocol
->StdIn
, &BufferSize
, CmdLine
);
1194 // Null terminate the string and parse it
1196 if (!EFI_ERROR (Status
)) {
1197 CmdLine
[BufferSize
/ sizeof (CHAR16
)] = CHAR_NULL
;
1198 Status
= RunCommand(CmdLine
);
1202 // Done with this command
1209 Add a buffer to the Buffer To Free List for safely returning buffers to other
1210 places without risking letting them modify internal shell information.
1212 @param Buffer Something to pass to FreePool when the shell is exiting.
1216 AddBufferToFreeList(
1220 BUFFER_LIST
*BufferListEntry
;
1222 if (Buffer
== NULL
) {
1226 BufferListEntry
= AllocateZeroPool(sizeof(BUFFER_LIST
));
1227 ASSERT(BufferListEntry
!= NULL
);
1228 BufferListEntry
->Buffer
= Buffer
;
1229 InsertTailList(&ShellInfoObject
.BufferToFreeList
.Link
, &BufferListEntry
->Link
);
1234 Add a buffer to the Line History List
1236 @param Buffer The line buffer to add.
1240 AddLineToCommandHistory(
1241 IN CONST CHAR16
*Buffer
1246 Node
= AllocateZeroPool(sizeof(BUFFER_LIST
));
1247 ASSERT(Node
!= NULL
);
1248 Node
->Buffer
= AllocateCopyPool(StrSize(Buffer
), Buffer
);
1249 ASSERT(Node
->Buffer
!= NULL
);
1251 InsertTailList(&ShellInfoObject
.ViewingSettings
.CommandHistory
.Link
, &Node
->Link
);
1255 Checks if a string is an alias for another command. If yes, then it replaces the alias name
1256 with the correct command name.
1258 @param[in, out] CommandString Upon entry the potential alias. Upon return the
1259 command name if it was an alias. If it was not
1260 an alias it will be unchanged. This function may
1261 change the buffer to fit the command name.
1263 @retval EFI_SUCCESS The name was changed.
1264 @retval EFI_SUCCESS The name was not an alias.
1265 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1270 IN OUT CHAR16
**CommandString
1273 CONST CHAR16
*NewString
;
1275 NewString
= ShellInfoObject
.NewEfiShellProtocol
->GetAlias(*CommandString
, NULL
);
1276 if (NewString
== NULL
) {
1277 return (EFI_SUCCESS
);
1279 FreePool(*CommandString
);
1280 *CommandString
= AllocateCopyPool(StrSize(NewString
), NewString
);
1281 if (*CommandString
== NULL
) {
1282 return (EFI_OUT_OF_RESOURCES
);
1284 return (EFI_SUCCESS
);
1288 This function will eliminate unreplaced (and therefore non-found) environment variables.
1290 @param[in,out] CmdLine The command line to update.
1294 StripUnreplacedEnvironmentVariables(
1295 IN OUT CHAR16
*CmdLine
1298 CHAR16
*FirstPercent
;
1300 CHAR16
*SecondPercent
;
1301 CHAR16
*SecondQuote
;
1302 CHAR16
*CurrentLocator
;
1304 for (CurrentLocator
= CmdLine
; CurrentLocator
!= NULL
; ) {
1305 FirstQuote
= (CHAR16
*)FindFirstCharacter(CurrentLocator
, L
"\"", L
'^');
1306 FirstPercent
= (CHAR16
*)FindFirstCharacter(CurrentLocator
, L
"%", L
'^');
1307 SecondPercent
= FirstPercent
!=NULL
?(CHAR16
*)FindFirstCharacter(FirstPercent
+1, L
"%", L
'^'):NULL
;
1308 if (FirstPercent
== NULL
|| SecondPercent
== NULL
) {
1310 // If we ever dont have 2 % we are done.
1315 if (FirstQuote
!= NULL
&& FirstQuote
< FirstPercent
) {
1316 SecondQuote
= (CHAR16
*)FindFirstCharacter(FirstQuote
+1, L
"\"", L
'^');
1318 // Quote is first found
1320 if (SecondQuote
< FirstPercent
) {
1322 // restart after the pair of "
1324 CurrentLocator
= SecondQuote
+ 1;
1325 } else /* FirstPercent < SecondQuote */{
1327 // Restart on the first percent
1329 CurrentLocator
= FirstPercent
;
1334 if (FirstQuote
== NULL
|| SecondPercent
< FirstQuote
) {
1335 if (IsValidEnvironmentVariableName(FirstPercent
, SecondPercent
)) {
1337 // We need to remove from FirstPercent to SecondPercent
1339 CopyMem(FirstPercent
, SecondPercent
+ 1, StrSize(SecondPercent
+ 1));
1341 // dont need to update the locator. both % characters are gone.
1344 CurrentLocator
= SecondPercent
+ 1;
1348 CurrentLocator
= FirstQuote
;
1350 return (EFI_SUCCESS
);
1354 Function allocates a new command line and replaces all instances of environment
1355 variable names that are correctly preset to their values.
1357 If the return value is not NULL the memory must be caller freed.
1359 @param[in] OriginalCommandLine The original command line
1361 @retval NULL An error ocurred.
1362 @return The new command line with no environment variables present.
1366 ShellConvertVariables (
1367 IN CONST CHAR16
*OriginalCommandLine
1370 CONST CHAR16
*MasterEnvList
;
1372 CHAR16
*NewCommandLine1
;
1373 CHAR16
*NewCommandLine2
;
1377 SCRIPT_FILE
*CurrentScriptFile
;
1378 ALIAS_LIST
*AliasListNode
;
1380 ASSERT(OriginalCommandLine
!= NULL
);
1383 NewSize
= StrSize(OriginalCommandLine
);
1384 CurrentScriptFile
= ShellCommandGetCurrentScriptFile();
1387 ///@todo update this to handle the %0 - %9 for scripting only (borrow from line 1256 area) ? ? ?
1390 // calculate the size required for the post-conversion string...
1392 if (CurrentScriptFile
!= NULL
) {
1393 for (AliasListNode
= (ALIAS_LIST
*)GetFirstNode(&CurrentScriptFile
->SubstList
)
1394 ; !IsNull(&CurrentScriptFile
->SubstList
, &AliasListNode
->Link
)
1395 ; AliasListNode
= (ALIAS_LIST
*)GetNextNode(&CurrentScriptFile
->SubstList
, &AliasListNode
->Link
)
1397 for (Temp
= StrStr(OriginalCommandLine
, AliasListNode
->Alias
)
1399 ; Temp
= StrStr(Temp
+1, AliasListNode
->Alias
)
1402 // we need a preceeding and if there is space no ^ preceeding (if no space ignore)
1404 if ((((Temp
-OriginalCommandLine
)>2) && *(Temp
-2) != L
'^') || ((Temp
-OriginalCommandLine
)<=2)) {
1405 NewSize
+= StrSize(AliasListNode
->CommandString
);
1411 for (MasterEnvList
= EfiShellGetEnv(NULL
)
1412 ; MasterEnvList
!= NULL
&& *MasterEnvList
!= CHAR_NULL
//&& *(MasterEnvList+1) != CHAR_NULL
1413 ; MasterEnvList
+= StrLen(MasterEnvList
) + 1
1415 if (StrSize(MasterEnvList
) > ItemSize
) {
1416 ItemSize
= StrSize(MasterEnvList
);
1418 for (Temp
= StrStr(OriginalCommandLine
, MasterEnvList
)
1420 ; Temp
= StrStr(Temp
+1, MasterEnvList
)
1423 // we need a preceeding and following % and if there is space no ^ preceeding (if no space ignore)
1425 if (*(Temp
-1) == L
'%' && *(Temp
+StrLen(MasterEnvList
)) == L
'%' &&
1426 ((((Temp
-OriginalCommandLine
)>2) && *(Temp
-2) != L
'^') || ((Temp
-OriginalCommandLine
)<=2))) {
1427 NewSize
+=StrSize(EfiShellGetEnv(MasterEnvList
));
1433 // now do the replacements...
1435 NewCommandLine1
= AllocateCopyPool(NewSize
, OriginalCommandLine
);
1436 NewCommandLine2
= AllocateZeroPool(NewSize
);
1437 ItemTemp
= AllocateZeroPool(ItemSize
+(2*sizeof(CHAR16
)));
1438 if (NewCommandLine1
== NULL
|| NewCommandLine2
== NULL
|| ItemTemp
== NULL
) {
1439 SHELL_FREE_NON_NULL(NewCommandLine1
);
1440 SHELL_FREE_NON_NULL(NewCommandLine2
);
1441 SHELL_FREE_NON_NULL(ItemTemp
);
1444 for (MasterEnvList
= EfiShellGetEnv(NULL
)
1445 ; MasterEnvList
!= NULL
&& *MasterEnvList
!= CHAR_NULL
1446 ; MasterEnvList
+= StrLen(MasterEnvList
) + 1
1448 StrnCpy(ItemTemp
, L
"%", ((ItemSize
+(2*sizeof(CHAR16
)))/sizeof(CHAR16
))-1);
1449 StrnCat(ItemTemp
, MasterEnvList
, ((ItemSize
+(2*sizeof(CHAR16
)))/sizeof(CHAR16
))-1 - StrLen(ItemTemp
));
1450 StrnCat(ItemTemp
, L
"%", ((ItemSize
+(2*sizeof(CHAR16
)))/sizeof(CHAR16
))-1 - StrLen(ItemTemp
));
1451 ShellCopySearchAndReplace(NewCommandLine1
, NewCommandLine2
, NewSize
, ItemTemp
, EfiShellGetEnv(MasterEnvList
), TRUE
, FALSE
);
1452 StrnCpy(NewCommandLine1
, NewCommandLine2
, NewSize
/sizeof(CHAR16
)-1);
1454 if (CurrentScriptFile
!= NULL
) {
1455 for (AliasListNode
= (ALIAS_LIST
*)GetFirstNode(&CurrentScriptFile
->SubstList
)
1456 ; !IsNull(&CurrentScriptFile
->SubstList
, &AliasListNode
->Link
)
1457 ; AliasListNode
= (ALIAS_LIST
*)GetNextNode(&CurrentScriptFile
->SubstList
, &AliasListNode
->Link
)
1459 ShellCopySearchAndReplace(NewCommandLine1
, NewCommandLine2
, NewSize
, AliasListNode
->Alias
, AliasListNode
->CommandString
, TRUE
, FALSE
);
1460 StrnCpy(NewCommandLine1
, NewCommandLine2
, NewSize
/sizeof(CHAR16
)-1);
1465 // Remove non-existant environment variables
1467 StripUnreplacedEnvironmentVariables(NewCommandLine1
);
1470 // Now cleanup any straggler intentionally ignored "%" characters
1472 ShellCopySearchAndReplace(NewCommandLine1
, NewCommandLine2
, NewSize
, L
"^%", L
"%", TRUE
, FALSE
);
1473 StrnCpy(NewCommandLine1
, NewCommandLine2
, NewSize
/sizeof(CHAR16
)-1);
1475 FreePool(NewCommandLine2
);
1478 return (NewCommandLine1
);
1482 Internal function to run a command line with pipe usage.
1484 @param[in] CmdLine The pointer to the command line.
1485 @param[in] StdIn The pointer to the Standard input.
1486 @param[in] StdOut The pointer to the Standard output.
1488 @retval EFI_SUCCESS The split command is executed successfully.
1489 @retval other Some error occurs when executing the split command.
1494 IN CONST CHAR16
*CmdLine
,
1495 IN SHELL_FILE_HANDLE
*StdIn
,
1496 IN SHELL_FILE_HANDLE
*StdOut
1500 CHAR16
*NextCommandLine
;
1501 CHAR16
*OurCommandLine
;
1505 SHELL_FILE_HANDLE
*TempFileHandle
;
1508 ASSERT(StdOut
== NULL
);
1510 ASSERT(StrStr(CmdLine
, L
"|") != NULL
);
1512 Status
= EFI_SUCCESS
;
1513 NextCommandLine
= NULL
;
1514 OurCommandLine
= NULL
;
1518 NextCommandLine
= StrnCatGrow(&NextCommandLine
, &Size1
, StrStr(CmdLine
, L
"|")+1, 0);
1519 OurCommandLine
= StrnCatGrow(&OurCommandLine
, &Size2
, CmdLine
, StrStr(CmdLine
, L
"|") - CmdLine
);
1521 if (NextCommandLine
== NULL
|| OurCommandLine
== NULL
) {
1522 SHELL_FREE_NON_NULL(OurCommandLine
);
1523 SHELL_FREE_NON_NULL(NextCommandLine
);
1524 return (EFI_OUT_OF_RESOURCES
);
1525 } else if (StrStr(OurCommandLine
, L
"|") != NULL
|| Size1
== 0 || Size2
== 0) {
1526 SHELL_FREE_NON_NULL(OurCommandLine
);
1527 SHELL_FREE_NON_NULL(NextCommandLine
);
1528 return (EFI_INVALID_PARAMETER
);
1529 } else if (NextCommandLine
[0] != CHAR_NULL
&&
1530 NextCommandLine
[0] == L
'a' &&
1531 NextCommandLine
[1] == L
' '
1533 CopyMem(NextCommandLine
, NextCommandLine
+1, StrSize(NextCommandLine
) - sizeof(NextCommandLine
[0]));
1541 // make a SPLIT_LIST item and add to list
1543 Split
= AllocateZeroPool(sizeof(SPLIT_LIST
));
1544 ASSERT(Split
!= NULL
);
1545 Split
->SplitStdIn
= StdIn
;
1546 Split
->SplitStdOut
= ConvertEfiFileProtocolToShellHandle(CreateFileInterfaceMem(Unicode
), NULL
);
1547 ASSERT(Split
->SplitStdOut
!= NULL
);
1548 InsertHeadList(&ShellInfoObject
.SplitList
.Link
, &Split
->Link
);
1550 Status
= RunCommand(OurCommandLine
);
1553 // move the output from the first to the in to the second.
1555 TempFileHandle
= Split
->SplitStdOut
;
1556 if (Split
->SplitStdIn
== StdIn
) {
1557 Split
->SplitStdOut
= NULL
;
1559 Split
->SplitStdOut
= Split
->SplitStdIn
;
1561 Split
->SplitStdIn
= TempFileHandle
;
1562 ShellInfoObject
.NewEfiShellProtocol
->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split
->SplitStdIn
), 0);
1564 if (!EFI_ERROR(Status
)) {
1565 Status
= RunCommand(NextCommandLine
);
1569 // remove the top level from the ScriptList
1571 ASSERT((SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
) == Split
);
1572 RemoveEntryList(&Split
->Link
);
1575 // Note that the original StdIn is now the StdOut...
1577 if (Split
->SplitStdOut
!= NULL
&& Split
->SplitStdOut
!= StdIn
) {
1578 ShellInfoObject
.NewEfiShellProtocol
->CloseFile(ConvertShellHandleToEfiFileProtocol(Split
->SplitStdOut
));
1580 if (Split
->SplitStdIn
!= NULL
) {
1581 ShellInfoObject
.NewEfiShellProtocol
->CloseFile(ConvertShellHandleToEfiFileProtocol(Split
->SplitStdIn
));
1585 FreePool(NextCommandLine
);
1586 FreePool(OurCommandLine
);
1592 Take the original command line, substitute any variables, free
1593 the original string, return the modified copy.
1595 @param[in] CmdLine pointer to the command line to update.
1597 @retval EFI_SUCCESS the function was successful.
1598 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.
1602 ShellSubstituteVariables(
1607 NewCmdLine
= ShellConvertVariables(*CmdLine
);
1608 SHELL_FREE_NON_NULL(*CmdLine
);
1609 if (NewCmdLine
== NULL
) {
1610 return (EFI_OUT_OF_RESOURCES
);
1612 *CmdLine
= NewCmdLine
;
1613 return (EFI_SUCCESS
);
1617 Take the original command line, substitute any alias in the first group of space delimited characters, free
1618 the original string, return the modified copy.
1620 @param[in] CmdLine pointer to the command line to update.
1622 @retval EFI_SUCCESS the function was successful.
1623 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.
1627 ShellSubstituteAliases(
1632 CHAR16
*CommandName
;
1634 UINTN PostAliasSize
;
1635 ASSERT(CmdLine
!= NULL
);
1636 ASSERT(*CmdLine
!= NULL
);
1640 if (StrStr((*CmdLine
), L
" ") == NULL
){
1641 StrnCatGrow(&CommandName
, NULL
, (*CmdLine
), 0);
1643 StrnCatGrow(&CommandName
, NULL
, (*CmdLine
), StrStr((*CmdLine
), L
" ") - (*CmdLine
));
1647 // This cannot happen 'inline' since the CmdLine can need extra space.
1650 if (!ShellCommandIsCommandOnList(CommandName
)) {
1652 // Convert via alias
1654 Status
= ShellConvertAlias(&CommandName
);
1655 if (EFI_ERROR(Status
)){
1659 NewCmdLine
= StrnCatGrow(&NewCmdLine
, &PostAliasSize
, CommandName
, 0);
1660 if (NewCmdLine
== NULL
) {
1661 SHELL_FREE_NON_NULL(CommandName
);
1662 SHELL_FREE_NON_NULL(*CmdLine
);
1663 return (EFI_OUT_OF_RESOURCES
);
1665 NewCmdLine
= StrnCatGrow(&NewCmdLine
, &PostAliasSize
, StrStr((*CmdLine
), L
" "), 0);
1666 if (NewCmdLine
== NULL
) {
1667 SHELL_FREE_NON_NULL(CommandName
);
1668 SHELL_FREE_NON_NULL(*CmdLine
);
1669 return (EFI_OUT_OF_RESOURCES
);
1672 NewCmdLine
= StrnCatGrow(&NewCmdLine
, NULL
, (*CmdLine
), 0);
1675 SHELL_FREE_NON_NULL(*CmdLine
);
1676 SHELL_FREE_NON_NULL(CommandName
);
1679 // re-assign the passed in double pointer to point to our newly allocated buffer
1681 *CmdLine
= NewCmdLine
;
1683 return (EFI_SUCCESS
);
1687 Takes the Argv[0] part of the command line and determine the meaning of it.
1689 @param[in] CmdName pointer to the command line to update.
1691 @retval Internal_Command The name is an internal command.
1692 @retval File_Sys_Change the name is a file system change.
1693 @retval Script_File_Name the name is a NSH script file.
1694 @retval Unknown_Invalid the name is unknown.
1695 @retval Efi_Application the name is an application (.EFI).
1697 SHELL_OPERATION_TYPES
1700 IN CONST CHAR16
*CmdName
1703 CHAR16
* FileWithPath
;
1704 CONST CHAR16
* TempLocation
;
1705 CONST CHAR16
* TempLocation2
;
1707 FileWithPath
= NULL
;
1709 // test for an internal command.
1711 if (ShellCommandIsCommandOnList(CmdName
)) {
1712 return (Internal_Command
);
1716 // Test for file system change request. anything ending with first : and cant have spaces.
1718 if (CmdName
[(StrLen(CmdName
)-1)] == L
':') {
1719 if ( StrStr(CmdName
, L
" ") != NULL
1720 || StrLen(StrStr(CmdName
, L
":")) > 1
1722 return (Unknown_Invalid
);
1724 return (File_Sys_Change
);
1730 if ((FileWithPath
= ShellFindFilePathEx(CmdName
, mExecutableExtensions
)) != NULL
) {
1732 // See if that file has a script file extension
1734 if (StrLen(FileWithPath
) > 4) {
1735 TempLocation
= FileWithPath
+StrLen(FileWithPath
)-4;
1736 TempLocation2
= mScriptExtension
;
1737 if (StringNoCaseCompare((VOID
*)(&TempLocation
), (VOID
*)(&TempLocation2
)) == 0) {
1738 SHELL_FREE_NON_NULL(FileWithPath
);
1739 return (Script_File_Name
);
1744 // Was a file, but not a script. we treat this as an application.
1746 SHELL_FREE_NON_NULL(FileWithPath
);
1747 return (Efi_Application
);
1750 SHELL_FREE_NON_NULL(FileWithPath
);
1752 // No clue what this is... return invalid flag...
1754 return (Unknown_Invalid
);
1758 Determine if the first item in a command line is valid.
1760 @param[in] CmdLine The command line to parse.
1762 @retval EFI_SUCCESS The item is valid.
1763 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
1764 @retval EFI_NOT_FOUND The operation type is unknown or invalid.
1769 IN CONST CHAR16
*CmdLine
1773 CHAR16
*FirstParameter
;
1779 Temp
= StrnCatGrow(&Temp
, NULL
, CmdLine
, 0);
1781 return (EFI_OUT_OF_RESOURCES
);
1784 FirstParameter
= StrStr(Temp
, L
"|");
1785 if (FirstParameter
!= NULL
) {
1786 *FirstParameter
= CHAR_NULL
;
1789 FirstParameter
= NULL
;
1792 // Process the command line
1794 Status
= ProcessCommandLineToFinal(&Temp
);
1796 if (!EFI_ERROR(Status
)) {
1797 FirstParameter
= AllocateZeroPool(StrSize(CmdLine
));
1798 if (FirstParameter
== NULL
) {
1799 SHELL_FREE_NON_NULL(Temp
);
1800 return (EFI_OUT_OF_RESOURCES
);
1802 TempWalker
= (CHAR16
*)Temp
;
1803 if (!EFI_ERROR(GetNextParameter(&TempWalker
, &FirstParameter
, StrSize(CmdLine
)))) {
1804 if (GetOperationType(FirstParameter
) == Unknown_Invalid
) {
1805 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_NOT_FOUND
), ShellInfoObject
.HiiHandle
, FirstParameter
);
1806 SetLastError(SHELL_NOT_FOUND
);
1807 Status
= EFI_NOT_FOUND
;
1812 SHELL_FREE_NON_NULL(Temp
);
1813 SHELL_FREE_NON_NULL(FirstParameter
);
1818 Determine if a command line contains with a split contains only valid commands.
1820 @param[in] CmdLine The command line to parse.
1822 @retval EFI_SUCCESS CmdLine has only valid commands, application, or has no split.
1823 @retval EFI_ABORTED CmdLine has at least one invalid command or application.
1828 IN CONST CHAR16
*CmdLine
1831 CONST CHAR16
*TempSpot
;
1835 // Verify up to the pipe or end character
1837 Status
= IsValidSplit(CmdLine
);
1838 if (EFI_ERROR(Status
)) {
1843 // If this was the only item, then get out
1845 if (!ContainsSplit(CmdLine
)) {
1846 return (EFI_SUCCESS
);
1850 // recurse to verify the next item
1852 TempSpot
= FindFirstCharacter(CmdLine
, L
"|", L
'^') + 1;
1853 return (VerifySplit(TempSpot
));
1857 Process a split based operation.
1859 @param[in] CmdLine pointer to the command line to process
1861 @retval EFI_SUCCESS The operation was successful
1862 @return an error occured.
1866 ProcessNewSplitCommandLine(
1867 IN CONST CHAR16
*CmdLine
1873 Status
= VerifySplit(CmdLine
);
1874 if (EFI_ERROR(Status
)) {
1881 // are we in an existing split???
1883 if (!IsListEmpty(&ShellInfoObject
.SplitList
.Link
)) {
1884 Split
= (SPLIT_LIST
*)GetFirstNode(&ShellInfoObject
.SplitList
.Link
);
1887 if (Split
== NULL
) {
1888 Status
= RunSplitCommand(CmdLine
, NULL
, NULL
);
1890 Status
= RunSplitCommand(CmdLine
, Split
->SplitStdIn
, Split
->SplitStdOut
);
1892 if (EFI_ERROR(Status
)) {
1893 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_INVALID_SPLIT
), ShellInfoObject
.HiiHandle
, CmdLine
);
1899 Handle a request to change the current file system.
1901 @param[in] CmdLine The passed in command line.
1903 @retval EFI_SUCCESS The operation was successful.
1908 IN CONST CHAR16
*CmdLine
1912 Status
= EFI_SUCCESS
;
1915 // make sure we are the right operation
1917 ASSERT(CmdLine
[(StrLen(CmdLine
)-1)] == L
':' && StrStr(CmdLine
, L
" ") == NULL
);
1920 // Call the protocol API to do the work
1922 Status
= ShellInfoObject
.NewEfiShellProtocol
->SetCurDir(NULL
, CmdLine
);
1925 // Report any errors
1927 if (EFI_ERROR(Status
)) {
1928 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_INVALID_MAPPING
), ShellInfoObject
.HiiHandle
, CmdLine
);
1935 Reprocess the command line to direct all -? to the help command.
1937 if found, will add "help" as argv[0], and move the rest later.
1939 @param[in,out] CmdLine pointer to the command line to update
1944 IN OUT CHAR16
**CmdLine
1947 CHAR16
*CurrentParameter
;
1950 CHAR16
*NewCommandLine
;
1953 Status
= EFI_SUCCESS
;
1955 CurrentParameter
= AllocateZeroPool(StrSize(*CmdLine
));
1956 if (CurrentParameter
== NULL
) {
1957 return (EFI_OUT_OF_RESOURCES
);
1961 while(Walker
!= NULL
&& *Walker
!= CHAR_NULL
) {
1962 LastWalker
= Walker
;
1963 if (!EFI_ERROR(GetNextParameter(&Walker
, &CurrentParameter
, StrSize(*CmdLine
)))) {
1964 if (StrStr(CurrentParameter
, L
"-?") == CurrentParameter
) {
1965 LastWalker
[0] = L
' ';
1966 LastWalker
[1] = L
' ';
1967 NewCommandLine
= AllocateZeroPool(StrSize(L
"help ") + StrSize(*CmdLine
));
1968 if (NewCommandLine
== NULL
) {
1969 Status
= EFI_OUT_OF_RESOURCES
;
1974 // We know the space is sufficient since we just calculated it.
1976 StrnCpy(NewCommandLine
, L
"help ", 5);
1977 StrnCat(NewCommandLine
, *CmdLine
, StrLen(*CmdLine
));
1978 SHELL_FREE_NON_NULL(*CmdLine
);
1979 *CmdLine
= NewCommandLine
;
1985 SHELL_FREE_NON_NULL(CurrentParameter
);
1991 Function to update the shell variable "lasterror".
1993 @param[in] ErrorCode the error code to put into lasterror.
1998 IN CONST SHELL_STATUS ErrorCode
2001 CHAR16 LeString
[19];
2002 if (sizeof(EFI_STATUS
) == sizeof(UINT64
)) {
2003 UnicodeSPrint(LeString
, sizeof(LeString
), L
"0x%Lx", ErrorCode
);
2005 UnicodeSPrint(LeString
, sizeof(LeString
), L
"0x%x", ErrorCode
);
2007 DEBUG_CODE(InternalEfiShellSetEnv(L
"debuglasterror", LeString
, TRUE
););
2008 InternalEfiShellSetEnv(L
"lasterror", LeString
, TRUE
);
2010 return (EFI_SUCCESS
);
2014 Converts the command line to it's post-processed form. this replaces variables and alias' per UEFI Shell spec.
2016 @param[in,out] CmdLine pointer to the command line to update
2018 @retval EFI_SUCCESS The operation was successful
2019 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
2020 @return some other error occured
2024 ProcessCommandLineToFinal(
2025 IN OUT CHAR16
**CmdLine
2029 TrimSpaces(CmdLine
);
2031 Status
= ShellSubstituteAliases(CmdLine
);
2032 if (EFI_ERROR(Status
)) {
2036 TrimSpaces(CmdLine
);
2038 Status
= ShellSubstituteVariables(CmdLine
);
2039 if (EFI_ERROR(Status
)) {
2042 ASSERT (*CmdLine
!= NULL
);
2044 TrimSpaces(CmdLine
);
2047 // update for help parsing
2049 if (StrStr(*CmdLine
, L
"?") != NULL
) {
2051 // This may do nothing if the ? does not indicate help.
2052 // Save all the details for in the API below.
2054 Status
= DoHelpUpdate(CmdLine
);
2057 TrimSpaces(CmdLine
);
2059 return (EFI_SUCCESS
);
2063 Run an internal shell command.
2065 This API will upadate the shell's environment since these commands are libraries.
2067 @param[in] CmdLine the command line to run.
2068 @param[in] FirstParameter the first parameter on the command line
2069 @param[in] ParamProtocol the shell parameters protocol pointer
2071 @retval EFI_SUCCESS The command was completed.
2072 @retval EFI_ABORTED The command's operation was aborted.
2077 IN CONST CHAR16
*CmdLine
,
2078 IN CHAR16
*FirstParameter
,
2079 IN EFI_SHELL_PARAMETERS_PROTOCOL
*ParamProtocol
2085 SHELL_STATUS CommandReturnedStatus
;
2090 NewCmdLine
= AllocateCopyPool (StrSize (CmdLine
), CmdLine
);
2091 if (NewCmdLine
== NULL
) {
2092 return EFI_OUT_OF_RESOURCES
;
2095 for (Walker
= NewCmdLine
; Walker
!= NULL
&& *Walker
!= CHAR_NULL
; Walker
++) {
2096 if (*Walker
== L
'^' && *(Walker
+1) == L
'#') {
2097 CopyMem(Walker
, Walker
+1, StrSize(Walker
) - sizeof(Walker
[0]));
2102 // get the argc and argv updated for internal commands
2104 Status
= UpdateArgcArgv(ParamProtocol
, NewCmdLine
, &Argv
, &Argc
);
2105 if (!EFI_ERROR(Status
)) {
2107 // Run the internal command.
2109 Status
= ShellCommandRunCommandHandler(FirstParameter
, &CommandReturnedStatus
, &LastError
);
2111 if (!EFI_ERROR(Status
)) {
2113 // Update last error status.
2114 // some commands do not update last error.
2117 SetLastError(CommandReturnedStatus
);
2121 // Pass thru the exitcode from the app.
2123 if (ShellCommandGetExit()) {
2125 // An Exit was requested ("exit" command), pass its value up.
2127 Status
= CommandReturnedStatus
;
2128 } else if (CommandReturnedStatus
!= SHELL_SUCCESS
&& IsScriptOnlyCommand(FirstParameter
)) {
2130 // Always abort when a script only command fails for any reason
2132 Status
= EFI_ABORTED
;
2133 } else if (ShellCommandGetCurrentScriptFile() != NULL
&& CommandReturnedStatus
== SHELL_ABORTED
) {
2135 // Abort when in a script and a command aborted
2137 Status
= EFI_ABORTED
;
2143 // This is guarenteed to be called after UpdateArgcArgv no matter what else happened.
2144 // This is safe even if the update API failed. In this case, it may be a no-op.
2146 RestoreArgcArgv(ParamProtocol
, &Argv
, &Argc
);
2149 // If a script is running and the command is not a scipt only command, then
2150 // change return value to success so the script won't halt (unless aborted).
2152 // Script only commands have to be able halt the script since the script will
2153 // not operate if they are failing.
2155 if ( ShellCommandGetCurrentScriptFile() != NULL
2156 && !IsScriptOnlyCommand(FirstParameter
)
2157 && Status
!= EFI_ABORTED
2159 Status
= EFI_SUCCESS
;
2162 FreePool (NewCmdLine
);
2167 Function to run the command or file.
2169 @param[in] Type the type of operation being run.
2170 @param[in] CmdLine the command line to run.
2171 @param[in] FirstParameter the first parameter on the command line
2172 @param[in] ParamProtocol the shell parameters protocol pointer
2174 @retval EFI_SUCCESS The command was completed.
2175 @retval EFI_ABORTED The command's operation was aborted.
2180 IN SHELL_OPERATION_TYPES Type
,
2181 IN CONST CHAR16
*CmdLine
,
2182 IN CHAR16
*FirstParameter
,
2183 IN EFI_SHELL_PARAMETERS_PROTOCOL
*ParamProtocol
2187 EFI_STATUS StartStatus
;
2188 CHAR16
*CommandWithPath
;
2189 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
2190 SHELL_STATUS CalleeExitStatus
;
2192 Status
= EFI_SUCCESS
;
2193 CommandWithPath
= NULL
;
2195 CalleeExitStatus
= SHELL_INVALID_PARAMETER
;
2198 case Internal_Command
:
2199 Status
= RunInternalCommand(CmdLine
, FirstParameter
, ParamProtocol
);
2201 case Script_File_Name
:
2202 case Efi_Application
:
2204 // Process a fully qualified path
2206 if (StrStr(FirstParameter
, L
":") != NULL
) {
2207 ASSERT (CommandWithPath
== NULL
);
2208 if (ShellIsFile(FirstParameter
) == EFI_SUCCESS
) {
2209 CommandWithPath
= StrnCatGrow(&CommandWithPath
, NULL
, FirstParameter
, 0);
2214 // Process a relative path and also check in the path environment variable
2216 if (CommandWithPath
== NULL
) {
2217 CommandWithPath
= ShellFindFilePathEx(FirstParameter
, mExecutableExtensions
);
2221 // This should be impossible now.
2223 ASSERT(CommandWithPath
!= NULL
);
2226 // Make sure that path is not just a directory (or not found)
2228 if (!EFI_ERROR(ShellIsDirectory(CommandWithPath
))) {
2229 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_NOT_FOUND
), ShellInfoObject
.HiiHandle
, FirstParameter
);
2230 SetLastError(SHELL_NOT_FOUND
);
2233 case Script_File_Name
:
2234 Status
= RunScriptFile (CommandWithPath
, NULL
, CmdLine
, ParamProtocol
);
2236 case Efi_Application
:
2238 // Get the device path of the application image
2240 DevPath
= ShellInfoObject
.NewEfiShellProtocol
->GetDevicePathFromFilePath(CommandWithPath
);
2241 if (DevPath
== NULL
){
2242 Status
= EFI_OUT_OF_RESOURCES
;
2247 // Execute the device path
2249 Status
= InternalShellExecuteDevicePath(
2257 SHELL_FREE_NON_NULL(DevPath
);
2259 if(EFI_ERROR (Status
)) {
2260 CalleeExitStatus
= (SHELL_STATUS
) (Status
& (~MAX_BIT
));
2262 CalleeExitStatus
= (SHELL_STATUS
) StartStatus
;
2266 // Update last error status.
2268 // Status is an EFI_STATUS. Clear top bit to convert to SHELL_STATUS
2269 SetLastError(CalleeExitStatus
);
2285 SHELL_FREE_NON_NULL(CommandWithPath
);
2291 Function to setup StdIn, StdErr, StdOut, and then run the command or file.
2293 @param[in] Type the type of operation being run.
2294 @param[in] CmdLine the command line to run.
2295 @param[in] FirstParameter the first parameter on the command line.
2296 @param[in] ParamProtocol the shell parameters protocol pointer
2298 @retval EFI_SUCCESS The command was completed.
2299 @retval EFI_ABORTED The command's operation was aborted.
2303 SetupAndRunCommandOrFile(
2304 IN SHELL_OPERATION_TYPES Type
,
2306 IN CHAR16
*FirstParameter
,
2307 IN EFI_SHELL_PARAMETERS_PROTOCOL
*ParamProtocol
2311 SHELL_FILE_HANDLE OriginalStdIn
;
2312 SHELL_FILE_HANDLE OriginalStdOut
;
2313 SHELL_FILE_HANDLE OriginalStdErr
;
2314 SYSTEM_TABLE_INFO OriginalSystemTableInfo
;
2317 // Update the StdIn, StdOut, and StdErr for redirection to environment variables, files, etc... unicode and ASCII
2319 Status
= UpdateStdInStdOutStdErr(ParamProtocol
, CmdLine
, &OriginalStdIn
, &OriginalStdOut
, &OriginalStdErr
, &OriginalSystemTableInfo
);
2322 // The StdIn, StdOut, and StdErr are set up.
2323 // Now run the command, script, or application
2325 if (!EFI_ERROR(Status
)) {
2326 TrimSpaces(&CmdLine
);
2327 Status
= RunCommandOrFile(Type
, CmdLine
, FirstParameter
, ParamProtocol
);
2333 if (EFI_ERROR(Status
)) {
2334 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_ERROR
), ShellInfoObject
.HiiHandle
, (VOID
*)(Status
));
2338 // put back the original StdIn, StdOut, and StdErr
2340 RestoreStdInStdOutStdErr(ParamProtocol
, &OriginalStdIn
, &OriginalStdOut
, &OriginalStdErr
, &OriginalSystemTableInfo
);
2346 Function will process and run a command line.
2348 This will determine if the command line represents an internal shell
2349 command or dispatch an external application.
2351 @param[in] CmdLine The command line to parse.
2353 @retval EFI_SUCCESS The command was completed.
2354 @retval EFI_ABORTED The command's operation was aborted.
2359 IN CONST CHAR16
*CmdLine
2363 CHAR16
*CleanOriginal
;
2364 CHAR16
*FirstParameter
;
2366 SHELL_OPERATION_TYPES Type
;
2368 ASSERT(CmdLine
!= NULL
);
2369 if (StrLen(CmdLine
) == 0) {
2370 return (EFI_SUCCESS
);
2373 Status
= EFI_SUCCESS
;
2374 CleanOriginal
= NULL
;
2376 CleanOriginal
= StrnCatGrow(&CleanOriginal
, NULL
, CmdLine
, 0);
2377 if (CleanOriginal
== NULL
) {
2378 return (EFI_OUT_OF_RESOURCES
);
2381 TrimSpaces(&CleanOriginal
);
2384 // NULL out comments (leveraged from RunScriptFileHandle() ).
2385 // The # character on a line is used to denote that all characters on the same line
2386 // and to the right of the # are to be ignored by the shell.
2387 // Afterward, again remove spaces, in case any were between the last command-parameter and '#'.
2389 for (TempWalker
= CleanOriginal
; TempWalker
!= NULL
&& *TempWalker
!= CHAR_NULL
; TempWalker
++) {
2390 if (*TempWalker
== L
'^') {
2391 if (*(TempWalker
+ 1) == L
'#') {
2394 } else if (*TempWalker
== L
'#') {
2395 *TempWalker
= CHAR_NULL
;
2399 TrimSpaces(&CleanOriginal
);
2402 // Handle case that passed in command line is just 1 or more " " characters.
2404 if (StrLen (CleanOriginal
) == 0) {
2405 SHELL_FREE_NON_NULL(CleanOriginal
);
2406 return (EFI_SUCCESS
);
2409 Status
= ProcessCommandLineToFinal(&CleanOriginal
);
2410 if (EFI_ERROR(Status
)) {
2411 SHELL_FREE_NON_NULL(CleanOriginal
);
2416 // We dont do normal processing with a split command line (output from one command input to another)
2418 if (ContainsSplit(CleanOriginal
)) {
2419 Status
= ProcessNewSplitCommandLine(CleanOriginal
);
2420 SHELL_FREE_NON_NULL(CleanOriginal
);
2425 // We need the first parameter information so we can determine the operation type
2427 FirstParameter
= AllocateZeroPool(StrSize(CleanOriginal
));
2428 if (FirstParameter
== NULL
) {
2429 SHELL_FREE_NON_NULL(CleanOriginal
);
2430 return (EFI_OUT_OF_RESOURCES
);
2432 TempWalker
= CleanOriginal
;
2433 if (!EFI_ERROR(GetNextParameter(&TempWalker
, &FirstParameter
, StrSize(CleanOriginal
)))) {
2435 // Depending on the first parameter we change the behavior
2437 switch (Type
= GetOperationType(FirstParameter
)) {
2438 case File_Sys_Change
:
2439 Status
= ChangeMappedDrive (FirstParameter
);
2441 case Internal_Command
:
2442 case Script_File_Name
:
2443 case Efi_Application
:
2444 Status
= SetupAndRunCommandOrFile(Type
, CleanOriginal
, FirstParameter
, ShellInfoObject
.NewShellParametersProtocol
);
2448 // Whatever was typed, it was invalid.
2450 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_NOT_FOUND
), ShellInfoObject
.HiiHandle
, FirstParameter
);
2451 SetLastError(SHELL_NOT_FOUND
);
2455 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_NOT_FOUND
), ShellInfoObject
.HiiHandle
, FirstParameter
);
2456 SetLastError(SHELL_NOT_FOUND
);
2459 SHELL_FREE_NON_NULL(CleanOriginal
);
2460 SHELL_FREE_NON_NULL(FirstParameter
);
2465 STATIC CONST UINT16 InvalidChars
[] = {L
'*', L
'?', L
'<', L
'>', L
'\\', L
'/', L
'\"', 0x0001, 0x0002};
2467 Function determins if the CommandName COULD be a valid command. It does not determine whether
2468 this is a valid command. It only checks for invalid characters.
2470 @param[in] CommandName The name to check
2472 @retval TRUE CommandName could be a command name
2473 @retval FALSE CommandName could not be a valid command name
2478 IN CONST CHAR16
*CommandName
2482 if (CommandName
== NULL
) {
2487 ; Count
< sizeof(InvalidChars
) / sizeof(InvalidChars
[0])
2490 if (ScanMem16(CommandName
, StrSize(CommandName
), InvalidChars
[Count
]) != NULL
) {
2498 Function to process a NSH script file via SHELL_FILE_HANDLE.
2500 @param[in] Handle The handle to the already opened file.
2501 @param[in] Name The name of the script file.
2503 @retval EFI_SUCCESS the script completed sucessfully
2507 RunScriptFileHandle (
2508 IN SHELL_FILE_HANDLE Handle
,
2509 IN CONST CHAR16
*Name
2513 SCRIPT_FILE
*NewScriptFile
;
2515 CHAR16
*CommandLine
;
2516 CHAR16
*CommandLine2
;
2517 CHAR16
*CommandLine3
;
2518 SCRIPT_COMMAND_LIST
*LastCommand
;
2520 BOOLEAN PreScriptEchoState
;
2521 BOOLEAN PreCommandEchoState
;
2522 CONST CHAR16
*CurDir
;
2524 CHAR16 LeString
[50];
2526 ASSERT(!ShellCommandGetScriptExit());
2528 PreScriptEchoState
= ShellCommandGetEchoState();
2530 NewScriptFile
= (SCRIPT_FILE
*)AllocateZeroPool(sizeof(SCRIPT_FILE
));
2531 if (NewScriptFile
== NULL
) {
2532 return (EFI_OUT_OF_RESOURCES
);
2538 ASSERT(NewScriptFile
->ScriptName
== NULL
);
2539 NewScriptFile
->ScriptName
= StrnCatGrow(&NewScriptFile
->ScriptName
, NULL
, Name
, 0);
2540 if (NewScriptFile
->ScriptName
== NULL
) {
2541 DeleteScriptFileStruct(NewScriptFile
);
2542 return (EFI_OUT_OF_RESOURCES
);
2546 // Save the parameters (used to replace %0 to %9 later on)
2548 NewScriptFile
->Argc
= ShellInfoObject
.NewShellParametersProtocol
->Argc
;
2549 if (NewScriptFile
->Argc
!= 0) {
2550 NewScriptFile
->Argv
= (CHAR16
**)AllocateZeroPool(NewScriptFile
->Argc
* sizeof(CHAR16
*));
2551 if (NewScriptFile
->Argv
== NULL
) {
2552 DeleteScriptFileStruct(NewScriptFile
);
2553 return (EFI_OUT_OF_RESOURCES
);
2555 for (LoopVar
= 0 ; LoopVar
< 10 && LoopVar
< NewScriptFile
->Argc
; LoopVar
++) {
2556 ASSERT(NewScriptFile
->Argv
[LoopVar
] == NULL
);
2557 NewScriptFile
->Argv
[LoopVar
] = StrnCatGrow(&NewScriptFile
->Argv
[LoopVar
], NULL
, ShellInfoObject
.NewShellParametersProtocol
->Argv
[LoopVar
], 0);
2558 if (NewScriptFile
->Argv
[LoopVar
] == NULL
) {
2559 DeleteScriptFileStruct(NewScriptFile
);
2560 return (EFI_OUT_OF_RESOURCES
);
2564 NewScriptFile
->Argv
= NULL
;
2567 InitializeListHead(&NewScriptFile
->CommandList
);
2568 InitializeListHead(&NewScriptFile
->SubstList
);
2571 // Now build the list of all script commands.
2574 while(!ShellFileHandleEof(Handle
)) {
2575 CommandLine
= ShellFileHandleReturnLine(Handle
, &Ascii
);
2577 if (CommandLine
== NULL
|| StrLen(CommandLine
) == 0 || CommandLine
[0] == '#') {
2578 SHELL_FREE_NON_NULL(CommandLine
);
2581 NewScriptFile
->CurrentCommand
= AllocateZeroPool(sizeof(SCRIPT_COMMAND_LIST
));
2582 if (NewScriptFile
->CurrentCommand
== NULL
) {
2583 SHELL_FREE_NON_NULL(CommandLine
);
2584 DeleteScriptFileStruct(NewScriptFile
);
2585 return (EFI_OUT_OF_RESOURCES
);
2588 NewScriptFile
->CurrentCommand
->Cl
= CommandLine
;
2589 NewScriptFile
->CurrentCommand
->Data
= NULL
;
2590 NewScriptFile
->CurrentCommand
->Line
= LineCount
;
2592 InsertTailList(&NewScriptFile
->CommandList
, &NewScriptFile
->CurrentCommand
->Link
);
2596 // Add this as the topmost script file
2598 ShellCommandSetNewScript (NewScriptFile
);
2601 // Now enumerate through the commands and run each one.
2603 CommandLine
= AllocateZeroPool(PcdGet16(PcdShellPrintBufferSize
));
2604 if (CommandLine
== NULL
) {
2605 DeleteScriptFileStruct(NewScriptFile
);
2606 return (EFI_OUT_OF_RESOURCES
);
2608 CommandLine2
= AllocateZeroPool(PcdGet16(PcdShellPrintBufferSize
));
2609 if (CommandLine2
== NULL
) {
2610 FreePool(CommandLine
);
2611 DeleteScriptFileStruct(NewScriptFile
);
2612 return (EFI_OUT_OF_RESOURCES
);
2615 for ( NewScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)GetFirstNode(&NewScriptFile
->CommandList
)
2616 ; !IsNull(&NewScriptFile
->CommandList
, &NewScriptFile
->CurrentCommand
->Link
)
2617 ; // conditional increment in the body of the loop
2619 ASSERT(CommandLine2
!= NULL
);
2620 StrnCpy(CommandLine2
, NewScriptFile
->CurrentCommand
->Cl
, PcdGet16(PcdShellPrintBufferSize
)/sizeof(CHAR16
)-1);
2623 // NULL out comments
2625 for (CommandLine3
= CommandLine2
; CommandLine3
!= NULL
&& *CommandLine3
!= CHAR_NULL
; CommandLine3
++) {
2626 if (*CommandLine3
== L
'^') {
2627 if ( *(CommandLine3
+1) == L
':') {
2628 CopyMem(CommandLine3
, CommandLine3
+1, StrSize(CommandLine3
) - sizeof(CommandLine3
[0]));
2629 } else if (*(CommandLine3
+1) == L
'#') {
2632 } else if (*CommandLine3
== L
'#') {
2633 *CommandLine3
= CHAR_NULL
;
2637 if (CommandLine2
!= NULL
&& StrLen(CommandLine2
) >= 1) {
2639 // Due to variability in starting the find and replace action we need to have both buffers the same.
2641 StrnCpy(CommandLine
, CommandLine2
, PcdGet16(PcdShellPrintBufferSize
)/sizeof(CHAR16
)-1);
2644 // Remove the %0 to %9 from the command line (if we have some arguments)
2646 if (NewScriptFile
->Argv
!= NULL
) {
2647 switch (NewScriptFile
->Argc
) {
2649 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%9", NewScriptFile
->Argv
[9], FALSE
, TRUE
);
2650 ASSERT_EFI_ERROR(Status
);
2652 Status
= ShellCopySearchAndReplace(CommandLine
, CommandLine2
, PcdGet16 (PcdShellPrintBufferSize
), L
"%8", NewScriptFile
->Argv
[8], FALSE
, TRUE
);
2653 ASSERT_EFI_ERROR(Status
);
2655 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%7", NewScriptFile
->Argv
[7], FALSE
, TRUE
);
2656 ASSERT_EFI_ERROR(Status
);
2658 Status
= ShellCopySearchAndReplace(CommandLine
, CommandLine2
, PcdGet16 (PcdShellPrintBufferSize
), L
"%6", NewScriptFile
->Argv
[6], FALSE
, TRUE
);
2659 ASSERT_EFI_ERROR(Status
);
2661 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%5", NewScriptFile
->Argv
[5], FALSE
, TRUE
);
2662 ASSERT_EFI_ERROR(Status
);
2664 Status
= ShellCopySearchAndReplace(CommandLine
, CommandLine2
, PcdGet16 (PcdShellPrintBufferSize
), L
"%4", NewScriptFile
->Argv
[4], FALSE
, TRUE
);
2665 ASSERT_EFI_ERROR(Status
);
2667 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%3", NewScriptFile
->Argv
[3], FALSE
, TRUE
);
2668 ASSERT_EFI_ERROR(Status
);
2670 Status
= ShellCopySearchAndReplace(CommandLine
, CommandLine2
, PcdGet16 (PcdShellPrintBufferSize
), L
"%2", NewScriptFile
->Argv
[2], FALSE
, TRUE
);
2671 ASSERT_EFI_ERROR(Status
);
2673 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%1", NewScriptFile
->Argv
[1], FALSE
, TRUE
);
2674 ASSERT_EFI_ERROR(Status
);
2676 Status
= ShellCopySearchAndReplace(CommandLine
, CommandLine2
, PcdGet16 (PcdShellPrintBufferSize
), L
"%0", NewScriptFile
->Argv
[0], FALSE
, TRUE
);
2677 ASSERT_EFI_ERROR(Status
);
2683 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%1", L
"\"\"", FALSE
, FALSE
);
2684 Status
= ShellCopySearchAndReplace(CommandLine
, CommandLine2
, PcdGet16 (PcdShellPrintBufferSize
), L
"%2", L
"\"\"", FALSE
, FALSE
);
2685 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%3", L
"\"\"", FALSE
, FALSE
);
2686 Status
= ShellCopySearchAndReplace(CommandLine
, CommandLine2
, PcdGet16 (PcdShellPrintBufferSize
), L
"%4", L
"\"\"", FALSE
, FALSE
);
2687 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%5", L
"\"\"", FALSE
, FALSE
);
2688 Status
= ShellCopySearchAndReplace(CommandLine
, CommandLine2
, PcdGet16 (PcdShellPrintBufferSize
), L
"%6", L
"\"\"", FALSE
, FALSE
);
2689 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%7", L
"\"\"", FALSE
, FALSE
);
2690 Status
= ShellCopySearchAndReplace(CommandLine
, CommandLine2
, PcdGet16 (PcdShellPrintBufferSize
), L
"%8", L
"\"\"", FALSE
, FALSE
);
2691 Status
= ShellCopySearchAndReplace(CommandLine2
, CommandLine
, PcdGet16 (PcdShellPrintBufferSize
), L
"%9", L
"\"\"", FALSE
, FALSE
);
2693 StrnCpy(CommandLine2
, CommandLine
, PcdGet16(PcdShellPrintBufferSize
)/sizeof(CHAR16
)-1);
2695 LastCommand
= NewScriptFile
->CurrentCommand
;
2697 for (CommandLine3
= CommandLine2
; CommandLine3
[0] == L
' ' ; CommandLine3
++);
2699 if (CommandLine3
!= NULL
&& CommandLine3
[0] == L
':' ) {
2701 // This line is a goto target / label
2704 if (CommandLine3
!= NULL
&& StrLen(CommandLine3
) > 0) {
2705 if (CommandLine3
[0] == L
'@') {
2707 // We need to save the current echo state
2708 // and disable echo for just this command.
2710 PreCommandEchoState
= ShellCommandGetEchoState();
2711 ShellCommandSetEchoState(FALSE
);
2712 Status
= RunCommand(CommandLine3
+1);
2715 // If command was "@echo -off" or "@echo -on" then don't restore echo state
2717 if (StrCmp (L
"@echo -off", CommandLine3
) != 0 &&
2718 StrCmp (L
"@echo -on", CommandLine3
) != 0) {
2720 // Now restore the pre-'@' echo state.
2722 ShellCommandSetEchoState(PreCommandEchoState
);
2725 if (ShellCommandGetEchoState()) {
2726 CurDir
= ShellInfoObject
.NewEfiShellProtocol
->GetEnv(L
"cwd");
2727 if (CurDir
!= NULL
&& StrLen(CurDir
) > 1) {
2728 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_CURDIR
), ShellInfoObject
.HiiHandle
, CurDir
);
2730 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SHELL_SHELL
), ShellInfoObject
.HiiHandle
);
2732 ShellPrintEx(-1, -1, L
"%s\r\n", CommandLine2
);
2734 Status
= RunCommand(CommandLine3
);
2738 if (ShellCommandGetScriptExit()) {
2740 // ShellCommandGetExitCode() always returns a UINT64
2742 UnicodeSPrint(LeString
, sizeof(LeString
), L
"0x%Lx", ShellCommandGetExitCode());
2743 DEBUG_CODE(InternalEfiShellSetEnv(L
"debuglasterror", LeString
, TRUE
););
2744 InternalEfiShellSetEnv(L
"lasterror", LeString
, TRUE
);
2746 ShellCommandRegisterExit(FALSE
, 0);
2747 Status
= EFI_SUCCESS
;
2750 if (ShellGetExecutionBreakFlag()) {
2753 if (EFI_ERROR(Status
)) {
2756 if (ShellCommandGetExit()) {
2761 // If that commend did not update the CurrentCommand then we need to advance it...
2763 if (LastCommand
== NewScriptFile
->CurrentCommand
) {
2764 NewScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)GetNextNode(&NewScriptFile
->CommandList
, &NewScriptFile
->CurrentCommand
->Link
);
2765 if (!IsNull(&NewScriptFile
->CommandList
, &NewScriptFile
->CurrentCommand
->Link
)) {
2766 NewScriptFile
->CurrentCommand
->Reset
= TRUE
;
2770 NewScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)GetNextNode(&NewScriptFile
->CommandList
, &NewScriptFile
->CurrentCommand
->Link
);
2771 if (!IsNull(&NewScriptFile
->CommandList
, &NewScriptFile
->CurrentCommand
->Link
)) {
2772 NewScriptFile
->CurrentCommand
->Reset
= TRUE
;
2778 FreePool(CommandLine
);
2779 FreePool(CommandLine2
);
2780 ShellCommandSetNewScript (NULL
);
2783 // Only if this was the last script reset the state.
2785 if (ShellCommandGetCurrentScriptFile()==NULL
) {
2786 ShellCommandSetEchoState(PreScriptEchoState
);
2788 return (EFI_SUCCESS
);
2792 Function to process a NSH script file.
2794 @param[in] ScriptPath Pointer to the script file name (including file system path).
2795 @param[in] Handle the handle of the script file already opened.
2796 @param[in] CmdLine the command line to run.
2797 @param[in] ParamProtocol the shell parameters protocol pointer
2799 @retval EFI_SUCCESS the script completed sucessfully
2804 IN CONST CHAR16
*ScriptPath
,
2805 IN SHELL_FILE_HANDLE Handle OPTIONAL
,
2806 IN CONST CHAR16
*CmdLine
,
2807 IN EFI_SHELL_PARAMETERS_PROTOCOL
*ParamProtocol
2811 SHELL_FILE_HANDLE FileHandle
;
2815 if (ShellIsFile(ScriptPath
) != EFI_SUCCESS
) {
2816 return (EFI_INVALID_PARAMETER
);
2820 // get the argc and argv updated for scripts
2822 Status
= UpdateArgcArgv(ParamProtocol
, CmdLine
, &Argv
, &Argc
);
2823 if (!EFI_ERROR(Status
)) {
2825 if (Handle
== NULL
) {
2829 Status
= ShellOpenFileByName(ScriptPath
, &FileHandle
, EFI_FILE_MODE_READ
, 0);
2830 if (!EFI_ERROR(Status
)) {
2834 Status
= RunScriptFileHandle(FileHandle
, ScriptPath
);
2837 // now close the file
2839 ShellCloseFile(&FileHandle
);
2842 Status
= RunScriptFileHandle(Handle
, ScriptPath
);
2847 // This is guarenteed to be called after UpdateArgcArgv no matter what else happened.
2848 // This is safe even if the update API failed. In this case, it may be a no-op.
2850 RestoreArgcArgv(ParamProtocol
, &Argv
, &Argc
);
2856 Return the pointer to the first occurance of any character from a list of characters.
2858 @param[in] String the string to parse
2859 @param[in] CharacterList the list of character to look for
2860 @param[in] EscapeCharacter An escape character to skip
2862 @return the location of the first character in the string
2863 @retval CHAR_NULL no instance of any character in CharacterList was found in String
2868 IN CONST CHAR16
*String
,
2869 IN CONST CHAR16
*CharacterList
,
2870 IN CONST CHAR16 EscapeCharacter
2876 for (WalkStr
= 0; WalkStr
< StrLen(String
); WalkStr
++) {
2877 if (String
[WalkStr
] == EscapeCharacter
) {
2881 for (WalkChar
= 0; WalkChar
< StrLen(CharacterList
); WalkChar
++) {
2882 if (String
[WalkStr
] == CharacterList
[WalkChar
]) {
2883 return (&String
[WalkStr
]);
2887 return (String
+ StrLen(String
));