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 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellLevel1CommandsLib.h"
12 STATIC CONST CHAR16 mFileName
[] = L
"ShellCommands";
13 EFI_HII_HANDLE gShellLevel1HiiHandle
= NULL
;
16 Return the help text filename. Only used if no HII information found.
22 ShellCommandGetManFileNameLevel1 (
30 Constructor for the Shell Level 1 Commands library.
32 Install the handlers for level 1 UEFI Shell 2.0 commands.
34 @param ImageHandle the image handle of the process
35 @param SystemTable the EFI System Table pointer
37 @retval EFI_SUCCESS the shell command handlers were installed sucessfully
38 @retval EFI_UNSUPPORTED the shell level required was not found.
42 ShellLevel1CommandsLibConstructor (
43 IN EFI_HANDLE ImageHandle
,
44 IN EFI_SYSTEM_TABLE
*SystemTable
48 // if shell level is less than 2 do nothing
50 if (PcdGet8(PcdShellSupportLevel
) < 1) {
54 gShellLevel1HiiHandle
= HiiAddPackages (&gShellLevel1HiiGuid
, gImageHandle
, UefiShellLevel1CommandsLibStrings
, NULL
);
55 if (gShellLevel1HiiHandle
== NULL
) {
56 return (EFI_DEVICE_ERROR
);
60 // install our shell command handlers that are always installed
62 ShellCommandRegisterCommandName(L
"stall", ShellCommandRunStall
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_STALL
) ));
63 ShellCommandRegisterCommandName(L
"for", ShellCommandRunFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_FOR
) ));
64 ShellCommandRegisterCommandName(L
"goto", ShellCommandRunGoto
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_GOTO
) ));
65 ShellCommandRegisterCommandName(L
"if", ShellCommandRunIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_IF
) ));
66 ShellCommandRegisterCommandName(L
"shift", ShellCommandRunShift
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_SHIFT
) ));
67 ShellCommandRegisterCommandName(L
"exit", ShellCommandRunExit
, ShellCommandGetManFileNameLevel1
, 1, L
"", TRUE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_EXIT
) ));
68 ShellCommandRegisterCommandName(L
"else", ShellCommandRunElse
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ELSE
) ));
69 ShellCommandRegisterCommandName(L
"endif", ShellCommandRunEndIf
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDIF
) ));
70 ShellCommandRegisterCommandName(L
"endfor", ShellCommandRunEndFor
, ShellCommandGetManFileNameLevel1
, 1, L
"", FALSE
, gShellLevel1HiiHandle
, (EFI_STRING_ID
)(PcdGet8(PcdShellSupportLevel
) < 3 ? 0 : STRING_TOKEN(STR_GET_HELP_ENDFOR
)));
76 Destructor for the library. free any resources.
78 @param ImageHandle The image handle of the process.
79 @param SystemTable The EFI System Table pointer.
83 ShellLevel1CommandsLibDestructor (
84 IN EFI_HANDLE ImageHandle
,
85 IN EFI_SYSTEM_TABLE
*SystemTable
88 if (gShellLevel1HiiHandle
!= NULL
) {
89 HiiRemovePackages(gShellLevel1HiiHandle
);
95 Test a node to see if meets the criterion.
97 It functions so that count starts at 1 and it increases or decreases when it
98 hits the specified tags. when it hits zero the location has been found.
100 DecrementerTag and IncrementerTag are used to get around for/endfor and
101 similar paired types where the entire middle should be ignored.
103 If label is used it will be used instead of the count.
105 @param[in] Function The function to use to enumerate through the
106 list. Normally GetNextNode or GetPreviousNode.
107 @param[in] DecrementerTag The tag to decrement the count at.
108 @param[in] IncrementerTag The tag to increment the count at.
109 @param[in] Label A label to look for.
110 @param[in, out] ScriptFile The pointer to the current script file structure.
111 @param[in] MovePast TRUE makes function return 1 past the found
113 @param[in] FindOnly TRUE to not change the ScriptFile.
114 @param[in] CommandNode The pointer to the Node to test.
115 @param[in, out] TargetCount The pointer to the current count.
119 IN CONST LIST_MANIP_FUNC Function
,
120 IN CONST CHAR16
*DecrementerTag
,
121 IN CONST CHAR16
*IncrementerTag
,
122 IN CONST CHAR16
*Label OPTIONAL
,
123 IN OUT SCRIPT_FILE
*ScriptFile
,
124 IN CONST BOOLEAN MovePast
,
125 IN CONST BOOLEAN FindOnly
,
126 IN CONST SCRIPT_COMMAND_LIST
*CommandNode
,
127 IN OUT UINTN
*TargetCount
132 CHAR16
*CommandNameWalker
;
133 CHAR16
*TempLocation
;
138 // get just the first part of the command line...
141 CommandName
= StrnCatGrow(&CommandName
, NULL
, CommandNode
->Cl
, 0);
142 if (CommandName
== NULL
) {
146 CommandNameWalker
= CommandName
;
149 // Skip leading spaces and tabs.
151 while ((CommandNameWalker
[0] == L
' ') || (CommandNameWalker
[0] == L
'\t')) {
154 TempLocation
= StrStr(CommandNameWalker
, L
" ");
156 if (TempLocation
!= NULL
) {
157 *TempLocation
= CHAR_NULL
;
161 // did we find a nested item ?
163 if (gUnicodeCollation
->StriColl(
165 (CHAR16
*)CommandNameWalker
,
166 (CHAR16
*)IncrementerTag
) == 0) {
168 } else if (gUnicodeCollation
->StriColl(
170 (CHAR16
*)CommandNameWalker
,
171 (CHAR16
*)DecrementerTag
) == 0) {
172 if (*TargetCount
> 0) {
178 // did we find the matching one...
181 if (*TargetCount
== 0) {
185 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
187 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
192 if (gUnicodeCollation
->StriColl(
194 (CHAR16
*)CommandNameWalker
,
196 && (*TargetCount
) == 0) {
200 // we found the target label without loops
203 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
205 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
212 // Free the memory for this loop...
214 FreePool(CommandName
);
219 Move the script pointer from 1 tag (line) to another.
221 It functions so that count starts at 1 and it increases or decreases when it
222 hits the specified tags. when it hits zero the location has been found.
224 DecrementerTag and IncrementerTag are used to get around for/endfor and
225 similar paired types where the entire middle should be ignored.
227 If label is used it will be used instead of the count.
229 @param[in] Function The function to use to enumerate through the
230 list. Normally GetNextNode or GetPreviousNode.
231 @param[in] DecrementerTag The tag to decrement the count at.
232 @param[in] IncrementerTag The tag to increment the count at.
233 @param[in] Label A label to look for.
234 @param[in, out] ScriptFile The pointer to the current script file structure.
235 @param[in] MovePast TRUE makes function return 1 past the found
237 @param[in] FindOnly TRUE to not change the ScriptFile.
238 @param[in] WrapAroundScript TRUE to wrap end-to-begining or vise versa in
243 IN CONST LIST_MANIP_FUNC Function
,
244 IN CONST CHAR16
*DecrementerTag
,
245 IN CONST CHAR16
*IncrementerTag
,
246 IN CONST CHAR16
*Label OPTIONAL
,
247 IN OUT SCRIPT_FILE
*ScriptFile
,
248 IN CONST BOOLEAN MovePast
,
249 IN CONST BOOLEAN FindOnly
,
250 IN CONST BOOLEAN WrapAroundScript
253 SCRIPT_COMMAND_LIST
*CommandNode
;
263 if (ScriptFile
== NULL
) {
267 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &ScriptFile
->CurrentCommand
->Link
), Found
= FALSE
268 ; !IsNull(&ScriptFile
->CommandList
, &CommandNode
->Link
)&& !Found
269 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
271 Found
= TestNodeForMove(
283 if (WrapAroundScript
&& !Found
) {
284 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)GetFirstNode(&ScriptFile
->CommandList
), Found
= FALSE
285 ; CommandNode
!= ScriptFile
->CurrentCommand
&& !Found
286 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
288 Found
= TestNodeForMove(