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 if (CommandName
== NULL
) {
152 CommandNameWalker
= CommandName
;
153 while(CommandNameWalker
[0] == L
' ') {
156 TempLocation
= StrStr(CommandNameWalker
, L
" ");
158 if (TempLocation
!= NULL
) {
159 *TempLocation
= CHAR_NULL
;
163 // did we find a nested item ?
165 if (gUnicodeCollation
->StriColl(
167 (CHAR16
*)CommandNameWalker
,
168 (CHAR16
*)IncrementerTag
) == 0) {
170 } else if (gUnicodeCollation
->StriColl(
172 (CHAR16
*)CommandNameWalker
,
173 (CHAR16
*)DecrementerTag
) == 0) {
174 if (*TargetCount
> 0) {
180 // did we find the matching one...
183 if (*TargetCount
== 0) {
187 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
189 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
194 if (gUnicodeCollation
->StriColl(
196 (CHAR16
*)CommandNameWalker
,
198 && (*TargetCount
) == 0) {
202 // we found the target label without loops
205 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
207 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
214 // Free the memory for this loop...
216 FreePool(CommandName
);
221 Move the script pointer from 1 tag (line) to another.
223 It functions so that count starts at 1 and it increases or decreases when it
224 hits the specified tags. when it hits zero the location has been found.
226 DecrementerTag and IncrementerTag are used to get around for/endfor and
227 similar paired types where the entire middle should be ignored.
229 If label is used it will be used instead of the count.
231 @param[in] Function The function to use to enumerate through the
232 list. Normally GetNextNode or GetPreviousNode.
233 @param[in] DecrementerTag The tag to decrement the count at.
234 @param[in] IncrementerTag The tag to increment the count at.
235 @param[in] Label A label to look for.
236 @param[in, out] ScriptFile The pointer to the current script file structure.
237 @param[in] MovePast TRUE makes function return 1 past the found
239 @param[in] FindOnly TRUE to not change the ScriptFile.
240 @param[in] WrapAroundScript TRUE to wrap end-to-begining or vise versa in
246 IN CONST LIST_MANIP_FUNC Function
,
247 IN CONST CHAR16
*DecrementerTag
,
248 IN CONST CHAR16
*IncrementerTag
,
249 IN CONST CHAR16
*Label OPTIONAL
,
250 IN OUT SCRIPT_FILE
*ScriptFile
,
251 IN CONST BOOLEAN MovePast
,
252 IN CONST BOOLEAN FindOnly
,
253 IN CONST BOOLEAN WrapAroundScript
256 SCRIPT_COMMAND_LIST
*CommandNode
;
266 if (ScriptFile
== NULL
) {
270 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &ScriptFile
->CurrentCommand
->Link
), Found
= FALSE
271 ; !IsNull(&ScriptFile
->CommandList
, &CommandNode
->Link
)&& !Found
272 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
274 Found
= TestNodeForMove(
286 if (WrapAroundScript
&& !Found
) {
287 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)GetFirstNode(&ScriptFile
->CommandList
), Found
= FALSE
288 ; CommandNode
!= ScriptFile
->CurrentCommand
&& !Found
289 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
291 Found
= TestNodeForMove(