2 Main file for NULL named library for level 1 shell command functions.
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellLevel1CommandsLib.h"
17 STATIC CONST CHAR16 mFileName
[] = L
"ShellCommands";
18 EFI_HANDLE gShellLevel1HiiHandle
= NULL
;
19 CONST EFI_GUID gShellLevel1HiiGuid
= \
21 0xdec5daa4, 0x6781, 0x4820, { 0x9c, 0x63, 0xa7, 0xb0, 0xe4, 0xf1, 0xdb, 0x31 }
27 ShellCommandGetManFileNameLevel1 (
35 Constructor for the Shell Level 1 Commands library.
37 Install the handlers for level 1 UEFI Shell 2.0 commands.
39 @param ImageHandle the image handle of the process
40 @param SystemTable the EFI System Table pointer
42 @retval EFI_SUCCESS the shell command handlers were installed sucessfully
43 @retval EFI_UNSUPPORTED the shell level required was not found.
47 ShellLevel1CommandsLibConstructor (
48 IN EFI_HANDLE ImageHandle
,
49 IN EFI_SYSTEM_TABLE
*SystemTable
53 // if shell level is less than 2 do nothing
55 if (PcdGet8(PcdShellSupportLevel
) < 1) {
56 return (EFI_UNSUPPORTED
);
59 gShellLevel1HiiHandle
= HiiAddPackages (&gShellLevel1HiiGuid
, gImageHandle
, UefiShellLevel1CommandsLibStrings
, NULL
);
60 if (gShellLevel1HiiHandle
== NULL
) {
61 return (EFI_DEVICE_ERROR
);
65 // install our shell command handlers that are always installed
67 ShellCommandRegisterCommandName(L
"for", ShellCommandRunFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_FOR
) ));
68 ShellCommandRegisterCommandName(L
"goto", ShellCommandRunGoto
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_GOTO
) ));
69 ShellCommandRegisterCommandName(L
"if", ShellCommandRunIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_IF
) ));
70 ShellCommandRegisterCommandName(L
"shift", ShellCommandRunShift
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_SHIFT
) ));
71 ShellCommandRegisterCommandName(L
"exit", ShellCommandRunExit
, ShellCommandGetManFileNameLevel1
, 1, L
"", TRUE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_EXIT
) ));
72 ShellCommandRegisterCommandName(L
"else", ShellCommandRunElse
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ELSE
) ));
73 ShellCommandRegisterCommandName(L
"endif", ShellCommandRunEndIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDIF
) ));
74 ShellCommandRegisterCommandName(L
"endfor", ShellCommandRunEndFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDFOR
)));
80 Destructor for the library. free any resources.
84 ShellLevel1CommandsLibDestructor (
85 IN EFI_HANDLE ImageHandle
,
86 IN EFI_SYSTEM_TABLE
*SystemTable
89 if (gShellLevel1HiiHandle
!= NULL
) {
90 HiiRemovePackages(gShellLevel1HiiHandle
);
98 IN CONST LIST_MANIP_FUNC Function
,
99 IN CONST CHAR16
*DecrementerTag
,
100 IN CONST CHAR16
*IncrementerTag
,
101 IN CONST CHAR16
*Label OPTIONAL
,
102 IN SCRIPT_FILE
*ScriptFile
,
103 IN CONST BOOLEAN MovePast
,
104 IN CONST BOOLEAN FindOnly
,
105 IN CONST SCRIPT_COMMAND_LIST
*CommandNode
,
106 IN UINTN
*TargetCount
111 CHAR16
*CommandNameWalker
;
112 CHAR16
*TempLocation
;
117 // get just the first part of the command line...
120 CommandName
= StrnCatGrow(&CommandName
, NULL
, CommandNode
->Cl
, 0);
121 CommandNameWalker
= CommandName
;
122 while(CommandNameWalker
[0] == L
' ') {
125 TempLocation
= StrStr(CommandNameWalker
, L
" ");
127 if (TempLocation
!= NULL
) {
128 *TempLocation
= CHAR_NULL
;
132 // did we find a nested item ?
134 if (gUnicodeCollation
->StriColl(
136 (CHAR16
*)CommandNameWalker
,
137 (CHAR16
*)IncrementerTag
) == 0) {
139 } else if (gUnicodeCollation
->StriColl(
141 (CHAR16
*)CommandNameWalker
,
142 (CHAR16
*)DecrementerTag
) == 0) {
143 if (*TargetCount
> 0) {
149 // did we find the matching one...
152 if (*TargetCount
== 0) {
156 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
158 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
163 if (gUnicodeCollation
->StriColl(
165 (CHAR16
*)CommandNameWalker
,
167 && (*TargetCount
) == 0) {
171 // we found the target label without loops
174 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
176 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
183 // Free the memory for this loop...
185 FreePool(CommandName
);
192 IN CONST LIST_MANIP_FUNC Function
,
193 IN CONST CHAR16
*DecrementerTag
,
194 IN CONST CHAR16
*IncrementerTag
,
195 IN CONST CHAR16
*Label OPTIONAL
,
196 IN SCRIPT_FILE
*ScriptFile
,
197 IN CONST BOOLEAN MovePast
,
198 IN CONST BOOLEAN FindOnly
,
199 IN CONST BOOLEAN WrapAroundScript
202 SCRIPT_COMMAND_LIST
*CommandNode
;
212 if (ScriptFile
== NULL
) {
216 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &ScriptFile
->CurrentCommand
->Link
), Found
= FALSE
217 ; !IsNull(&ScriptFile
->CommandList
, &CommandNode
->Link
)&& !Found
218 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
220 Found
= TestNodeForMove(
232 if (WrapAroundScript
&& !Found
) {
233 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)GetFirstNode(&ScriptFile
->CommandList
), Found
= FALSE
234 ; CommandNode
!= ScriptFile
->CurrentCommand
&& !Found
235 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
237 Found
= TestNodeForMove(