2 Main file for NULL named library for level 1 shell command functions.
4 (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>
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.
16 #include "UefiShellLevel1CommandsLib.h"
18 STATIC CONST CHAR16 mFileName
[] = L
"ShellCommands";
19 EFI_HANDLE gShellLevel1HiiHandle
= NULL
;
22 Return the help text filename. Only used if no HII information found.
28 ShellCommandGetManFileNameLevel1 (
36 Constructor for the Shell Level 1 Commands library.
38 Install the handlers for level 1 UEFI Shell 2.0 commands.
40 @param ImageHandle the image handle of the process
41 @param SystemTable the EFI System Table pointer
43 @retval EFI_SUCCESS the shell command handlers were installed sucessfully
44 @retval EFI_UNSUPPORTED the shell level required was not found.
48 ShellLevel1CommandsLibConstructor (
49 IN EFI_HANDLE ImageHandle
,
50 IN EFI_SYSTEM_TABLE
*SystemTable
54 // if shell level is less than 2 do nothing
56 if (PcdGet8(PcdShellSupportLevel
) < 1) {
60 gShellLevel1HiiHandle
= HiiAddPackages (&gShellLevel1HiiGuid
, gImageHandle
, UefiShellLevel1CommandsLibStrings
, NULL
);
61 if (gShellLevel1HiiHandle
== NULL
) {
62 return (EFI_DEVICE_ERROR
);
66 // install our shell command handlers that are always installed
68 ShellCommandRegisterCommandName(L
"stall", ShellCommandRunStall
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_STALL
) ));
69 ShellCommandRegisterCommandName(L
"for", ShellCommandRunFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_FOR
) ));
70 ShellCommandRegisterCommandName(L
"goto", ShellCommandRunGoto
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_GOTO
) ));
71 ShellCommandRegisterCommandName(L
"if", ShellCommandRunIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_IF
) ));
72 ShellCommandRegisterCommandName(L
"shift", ShellCommandRunShift
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_SHIFT
) ));
73 ShellCommandRegisterCommandName(L
"exit", ShellCommandRunExit
, ShellCommandGetManFileNameLevel1
, 1, L
"", TRUE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_EXIT
) ));
74 ShellCommandRegisterCommandName(L
"else", ShellCommandRunElse
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ELSE
) ));
75 ShellCommandRegisterCommandName(L
"endif", ShellCommandRunEndIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDIF
) ));
76 ShellCommandRegisterCommandName(L
"endfor", ShellCommandRunEndFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDFOR
)));
82 Destructor for the library. free any resources.
84 @param ImageHandle The image handle of the process.
85 @param SystemTable The EFI System Table pointer.
89 ShellLevel1CommandsLibDestructor (
90 IN EFI_HANDLE ImageHandle
,
91 IN EFI_SYSTEM_TABLE
*SystemTable
94 if (gShellLevel1HiiHandle
!= NULL
) {
95 HiiRemovePackages(gShellLevel1HiiHandle
);
101 Test a node to see if meets the criterion.
103 It functions so that count starts at 1 and it increases or decreases when it
104 hits the specified tags. when it hits zero the location has been found.
106 DecrementerTag and IncrementerTag are used to get around for/endfor and
107 similar paired types where the entire middle should be ignored.
109 If label is used it will be used instead of the count.
111 @param[in] Function The function to use to enumerate through the
112 list. Normally GetNextNode or GetPreviousNode.
113 @param[in] DecrementerTag The tag to decrement the count at.
114 @param[in] IncrementerTag The tag to increment the count at.
115 @param[in] Label A label to look for.
116 @param[in, out] ScriptFile The pointer to the current script file structure.
117 @param[in] MovePast TRUE makes function return 1 past the found
119 @param[in] FindOnly TRUE to not change the ScriptFile.
120 @param[in] CommandNode The pointer to the Node to test.
121 @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
;
155 // Skip leading spaces and tabs.
157 while ((CommandNameWalker
[0] == L
' ') || (CommandNameWalker
[0] == L
'\t')) {
160 TempLocation
= StrStr(CommandNameWalker
, L
" ");
162 if (TempLocation
!= NULL
) {
163 *TempLocation
= CHAR_NULL
;
167 // did we find a nested item ?
169 if (gUnicodeCollation
->StriColl(
171 (CHAR16
*)CommandNameWalker
,
172 (CHAR16
*)IncrementerTag
) == 0) {
174 } else if (gUnicodeCollation
->StriColl(
176 (CHAR16
*)CommandNameWalker
,
177 (CHAR16
*)DecrementerTag
) == 0) {
178 if (*TargetCount
> 0) {
184 // did we find the matching one...
187 if (*TargetCount
== 0) {
191 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
193 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
198 if (gUnicodeCollation
->StriColl(
200 (CHAR16
*)CommandNameWalker
,
202 && (*TargetCount
) == 0) {
206 // we found the target label without loops
209 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
211 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
218 // Free the memory for this loop...
220 FreePool(CommandName
);
225 Move the script pointer from 1 tag (line) to another.
227 It functions so that count starts at 1 and it increases or decreases when it
228 hits the specified tags. when it hits zero the location has been found.
230 DecrementerTag and IncrementerTag are used to get around for/endfor and
231 similar paired types where the entire middle should be ignored.
233 If label is used it will be used instead of the count.
235 @param[in] Function The function to use to enumerate through the
236 list. Normally GetNextNode or GetPreviousNode.
237 @param[in] DecrementerTag The tag to decrement the count at.
238 @param[in] IncrementerTag The tag to increment the count at.
239 @param[in] Label A label to look for.
240 @param[in, out] ScriptFile The pointer to the current script file structure.
241 @param[in] MovePast TRUE makes function return 1 past the found
243 @param[in] FindOnly TRUE to not change the ScriptFile.
244 @param[in] WrapAroundScript TRUE to wrap end-to-begining or vise versa in
249 IN CONST LIST_MANIP_FUNC Function
,
250 IN CONST CHAR16
*DecrementerTag
,
251 IN CONST CHAR16
*IncrementerTag
,
252 IN CONST CHAR16
*Label OPTIONAL
,
253 IN OUT SCRIPT_FILE
*ScriptFile
,
254 IN CONST BOOLEAN MovePast
,
255 IN CONST BOOLEAN FindOnly
,
256 IN CONST BOOLEAN WrapAroundScript
259 SCRIPT_COMMAND_LIST
*CommandNode
;
269 if (ScriptFile
== NULL
) {
273 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &ScriptFile
->CurrentCommand
->Link
), Found
= FALSE
274 ; !IsNull(&ScriptFile
->CommandList
, &CommandNode
->Link
)&& !Found
275 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
277 Found
= TestNodeForMove(
289 if (WrapAroundScript
&& !Found
) {
290 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)GetFirstNode(&ScriptFile
->CommandList
), Found
= FALSE
291 ; CommandNode
!= ScriptFile
->CurrentCommand
&& !Found
292 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
294 Found
= TestNodeForMove(