2 Main file for NULL named library for level 1 shell command functions.
4 Copyright (c) 2009 - 2011, 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 }
26 Return the help text filename. Only used if no HII information found.
32 ShellCommandGetManFileNameLevel1 (
40 Constructor for the Shell Level 1 Commands library.
42 Install the handlers for level 1 UEFI Shell 2.0 commands.
44 @param ImageHandle the image handle of the process
45 @param SystemTable the EFI System Table pointer
47 @retval EFI_SUCCESS the shell command handlers were installed sucessfully
48 @retval EFI_UNSUPPORTED the shell level required was not found.
52 ShellLevel1CommandsLibConstructor (
53 IN EFI_HANDLE ImageHandle
,
54 IN EFI_SYSTEM_TABLE
*SystemTable
58 // if shell level is less than 2 do nothing
60 if (PcdGet8(PcdShellSupportLevel
) < 1) {
61 return (EFI_UNSUPPORTED
);
64 gShellLevel1HiiHandle
= HiiAddPackages (&gShellLevel1HiiGuid
, gImageHandle
, UefiShellLevel1CommandsLibStrings
, NULL
);
65 if (gShellLevel1HiiHandle
== NULL
) {
66 return (EFI_DEVICE_ERROR
);
70 // install our shell command handlers that are always installed
72 ShellCommandRegisterCommandName(L
"stall", ShellCommandRunStall
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_STALL
) ));
73 ShellCommandRegisterCommandName(L
"for", ShellCommandRunFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_FOR
) ));
74 ShellCommandRegisterCommandName(L
"goto", ShellCommandRunGoto
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_GOTO
) ));
75 ShellCommandRegisterCommandName(L
"if", ShellCommandRunIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_IF
) ));
76 ShellCommandRegisterCommandName(L
"shift", ShellCommandRunShift
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_SHIFT
) ));
77 ShellCommandRegisterCommandName(L
"exit", ShellCommandRunExit
, ShellCommandGetManFileNameLevel1
, 1, L
"", TRUE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_EXIT
) ));
78 ShellCommandRegisterCommandName(L
"else", ShellCommandRunElse
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ELSE
) ));
79 ShellCommandRegisterCommandName(L
"endif", ShellCommandRunEndIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDIF
) ));
80 ShellCommandRegisterCommandName(L
"endfor", ShellCommandRunEndFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDFOR
)));
86 Destructor for the library. free any resources.
88 @param ImageHandle The image handle of the process.
89 @param SystemTable The EFI System Table pointer.
93 ShellLevel1CommandsLibDestructor (
94 IN EFI_HANDLE ImageHandle
,
95 IN EFI_SYSTEM_TABLE
*SystemTable
98 if (gShellLevel1HiiHandle
!= NULL
) {
99 HiiRemovePackages(gShellLevel1HiiHandle
);
101 return (EFI_SUCCESS
);
105 Test a node to see if meets the criterion.
107 It functions so that count starts at 1 and it increases or decreases when it
108 hits the specified tags. when it hits zero the location has been found.
110 DecrementerTag and IncrementerTag are used to get around for/endfor and
111 similar paired types where the entire middle should be ignored.
113 If label is used it will be used instead of the count.
115 @param[in] Function The function to use to enumerate through the
116 list. Normally GetNextNode or GetPreviousNode.
117 @param[in] DecrementerTag The tag to decrement the count at.
118 @param[in] IncrementerTag The tag to increment the count at.
119 @param[in] Label A label to look for.
120 @param[in,out] ScriptFile The pointer to the current script file structure.
121 @param[in] MovePast TRUE makes function return 1 past the found
123 @param[in] FindOnly TRUE to not change the ScriptFile.
124 @param[in] CommandNode The pointer to the Node to test.
125 @param[in,out] TargetCount The pointer to the current count.
130 IN CONST LIST_MANIP_FUNC Function
,
131 IN CONST CHAR16
*DecrementerTag
,
132 IN CONST CHAR16
*IncrementerTag
,
133 IN CONST CHAR16
*Label OPTIONAL
,
134 IN OUT SCRIPT_FILE
*ScriptFile
,
135 IN CONST BOOLEAN MovePast
,
136 IN CONST BOOLEAN FindOnly
,
137 IN CONST SCRIPT_COMMAND_LIST
*CommandNode
,
138 IN OUT UINTN
*TargetCount
143 CHAR16
*CommandNameWalker
;
144 CHAR16
*TempLocation
;
149 // get just the first part of the command line...
152 CommandName
= StrnCatGrow(&CommandName
, NULL
, CommandNode
->Cl
, 0);
153 CommandNameWalker
= CommandName
;
154 while(CommandNameWalker
[0] == L
' ') {
157 TempLocation
= StrStr(CommandNameWalker
, L
" ");
159 if (TempLocation
!= NULL
) {
160 *TempLocation
= CHAR_NULL
;
164 // did we find a nested item ?
166 if (gUnicodeCollation
->StriColl(
168 (CHAR16
*)CommandNameWalker
,
169 (CHAR16
*)IncrementerTag
) == 0) {
171 } else if (gUnicodeCollation
->StriColl(
173 (CHAR16
*)CommandNameWalker
,
174 (CHAR16
*)DecrementerTag
) == 0) {
175 if (*TargetCount
> 0) {
181 // did we find the matching one...
184 if (*TargetCount
== 0) {
188 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
190 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
195 if (gUnicodeCollation
->StriColl(
197 (CHAR16
*)CommandNameWalker
,
199 && (*TargetCount
) == 0) {
203 // we found the target label without loops
206 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
208 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
215 // Free the memory for this loop...
217 FreePool(CommandName
);
222 Move the script pointer from 1 tag (line) to another.
224 It functions so that count starts at 1 and it increases or decreases when it
225 hits the specified tags. when it hits zero the location has been found.
227 DecrementerTag and IncrementerTag are used to get around for/endfor and
228 similar paired types where the entire middle should be ignored.
230 If label is used it will be used instead of the count.
232 @param[in] Function The function to use to enumerate through the
233 list. Normally GetNextNode or GetPreviousNode.
234 @param[in] DecrementerTag The tag to decrement the count at.
235 @param[in] IncrementerTag The tag to increment the count at.
236 @param[in] Label A label to look for.
237 @param[in,out] ScriptFile The pointer to the current script file structure.
238 @param[in] MovePast TRUE makes function return 1 past the found
240 @param[in] FindOnly TRUE to not change the ScriptFile.
241 @param[in] WrapAroundScript TRUE to wrap end-to-begining or vise versa in
247 IN CONST LIST_MANIP_FUNC Function
,
248 IN CONST CHAR16
*DecrementerTag
,
249 IN CONST CHAR16
*IncrementerTag
,
250 IN CONST CHAR16
*Label OPTIONAL
,
251 IN OUT SCRIPT_FILE
*ScriptFile
,
252 IN CONST BOOLEAN MovePast
,
253 IN CONST BOOLEAN FindOnly
,
254 IN CONST BOOLEAN WrapAroundScript
257 SCRIPT_COMMAND_LIST
*CommandNode
;
267 if (ScriptFile
== NULL
) {
271 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &ScriptFile
->CurrentCommand
->Link
), Found
= FALSE
272 ; !IsNull(&ScriptFile
->CommandList
, &CommandNode
->Link
)&& !Found
273 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
275 Found
= TestNodeForMove(
287 if (WrapAroundScript
&& !Found
) {
288 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)GetFirstNode(&ScriptFile
->CommandList
), Found
= FALSE
289 ; CommandNode
!= ScriptFile
->CurrentCommand
&& !Found
290 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
292 Found
= TestNodeForMove(