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
;
21 Return the help text filename. Only used if no HII information found.
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) {
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
"stall", ShellCommandRunStall
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_STALL
) ));
68 ShellCommandRegisterCommandName(L
"for", ShellCommandRunFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_FOR
) ));
69 ShellCommandRegisterCommandName(L
"goto", ShellCommandRunGoto
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_GOTO
) ));
70 ShellCommandRegisterCommandName(L
"if", ShellCommandRunIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_IF
) ));
71 ShellCommandRegisterCommandName(L
"shift", ShellCommandRunShift
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_SHIFT
) ));
72 ShellCommandRegisterCommandName(L
"exit", ShellCommandRunExit
, ShellCommandGetManFileNameLevel1
, 1, L
"", TRUE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_EXIT
) ));
73 ShellCommandRegisterCommandName(L
"else", ShellCommandRunElse
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ELSE
) ));
74 ShellCommandRegisterCommandName(L
"endif", ShellCommandRunEndIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDIF
) ));
75 ShellCommandRegisterCommandName(L
"endfor", ShellCommandRunEndFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDFOR
)));
81 Destructor for the library. free any resources.
83 @param ImageHandle The image handle of the process.
84 @param SystemTable The EFI System Table pointer.
88 ShellLevel1CommandsLibDestructor (
89 IN EFI_HANDLE ImageHandle
,
90 IN EFI_SYSTEM_TABLE
*SystemTable
93 if (gShellLevel1HiiHandle
!= NULL
) {
94 HiiRemovePackages(gShellLevel1HiiHandle
);
100 Test a node to see if meets the criterion.
102 It functions so that count starts at 1 and it increases or decreases when it
103 hits the specified tags. when it hits zero the location has been found.
105 DecrementerTag and IncrementerTag are used to get around for/endfor and
106 similar paired types where the entire middle should be ignored.
108 If label is used it will be used instead of the count.
110 @param[in] Function The function to use to enumerate through the
111 list. Normally GetNextNode or GetPreviousNode.
112 @param[in] DecrementerTag The tag to decrement the count at.
113 @param[in] IncrementerTag The tag to increment the count at.
114 @param[in] Label A label to look for.
115 @param[in, out] ScriptFile The pointer to the current script file structure.
116 @param[in] MovePast TRUE makes function return 1 past the found
118 @param[in] FindOnly TRUE to not change the ScriptFile.
119 @param[in] CommandNode The pointer to the Node to test.
120 @param[in, out] TargetCount The pointer to the current count.
125 IN CONST LIST_MANIP_FUNC Function
,
126 IN CONST CHAR16
*DecrementerTag
,
127 IN CONST CHAR16
*IncrementerTag
,
128 IN CONST CHAR16
*Label OPTIONAL
,
129 IN OUT SCRIPT_FILE
*ScriptFile
,
130 IN CONST BOOLEAN MovePast
,
131 IN CONST BOOLEAN FindOnly
,
132 IN CONST SCRIPT_COMMAND_LIST
*CommandNode
,
133 IN OUT UINTN
*TargetCount
138 CHAR16
*CommandNameWalker
;
139 CHAR16
*TempLocation
;
144 // get just the first part of the command line...
147 CommandName
= StrnCatGrow(&CommandName
, NULL
, CommandNode
->Cl
, 0);
148 CommandNameWalker
= CommandName
;
149 while(CommandNameWalker
[0] == L
' ') {
152 TempLocation
= StrStr(CommandNameWalker
, L
" ");
154 if (TempLocation
!= NULL
) {
155 *TempLocation
= CHAR_NULL
;
159 // did we find a nested item ?
161 if (gUnicodeCollation
->StriColl(
163 (CHAR16
*)CommandNameWalker
,
164 (CHAR16
*)IncrementerTag
) == 0) {
166 } else if (gUnicodeCollation
->StriColl(
168 (CHAR16
*)CommandNameWalker
,
169 (CHAR16
*)DecrementerTag
) == 0) {
170 if (*TargetCount
> 0) {
176 // did we find the matching one...
179 if (*TargetCount
== 0) {
183 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
185 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
190 if (gUnicodeCollation
->StriColl(
192 (CHAR16
*)CommandNameWalker
,
194 && (*TargetCount
) == 0) {
198 // we found the target label without loops
201 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
203 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
210 // Free the memory for this loop...
212 FreePool(CommandName
);
217 Move the script pointer from 1 tag (line) to another.
219 It functions so that count starts at 1 and it increases or decreases when it
220 hits the specified tags. when it hits zero the location has been found.
222 DecrementerTag and IncrementerTag are used to get around for/endfor and
223 similar paired types where the entire middle should be ignored.
225 If label is used it will be used instead of the count.
227 @param[in] Function The function to use to enumerate through the
228 list. Normally GetNextNode or GetPreviousNode.
229 @param[in] DecrementerTag The tag to decrement the count at.
230 @param[in] IncrementerTag The tag to increment the count at.
231 @param[in] Label A label to look for.
232 @param[in, out] ScriptFile The pointer to the current script file structure.
233 @param[in] MovePast TRUE makes function return 1 past the found
235 @param[in] FindOnly TRUE to not change the ScriptFile.
236 @param[in] WrapAroundScript TRUE to wrap end-to-begining or vise versa in
242 IN CONST LIST_MANIP_FUNC Function
,
243 IN CONST CHAR16
*DecrementerTag
,
244 IN CONST CHAR16
*IncrementerTag
,
245 IN CONST CHAR16
*Label OPTIONAL
,
246 IN OUT SCRIPT_FILE
*ScriptFile
,
247 IN CONST BOOLEAN MovePast
,
248 IN CONST BOOLEAN FindOnly
,
249 IN CONST BOOLEAN WrapAroundScript
252 SCRIPT_COMMAND_LIST
*CommandNode
;
262 if (ScriptFile
== NULL
) {
266 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &ScriptFile
->CurrentCommand
->Link
), Found
= FALSE
267 ; !IsNull(&ScriptFile
->CommandList
, &CommandNode
->Link
)&& !Found
268 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
270 Found
= TestNodeForMove(
282 if (WrapAroundScript
&& !Found
) {
283 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)GetFirstNode(&ScriptFile
->CommandList
), Found
= FALSE
284 ; CommandNode
!= ScriptFile
->CurrentCommand
&& !Found
285 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
287 Found
= TestNodeForMove(