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
);
96 Test a node to see if meets the criterion.
98 It functions so that count starts at 1 and it increases or decreases when it
99 hits the specified tags. when it hits zero the location has been found.
101 DecrementerTag and IncrementerTag are used to get around for/endfor and
102 similar paired types where the entire middle should be ignored.
104 If label is used it will be used instead of the count.
106 @param[in] Function The function to use to enumerate through the
107 list. Normally GetNextNode or GetPreviousNode.
108 @param[in] DecrementerTag The tag to decrement the count at.
109 @param[in] IncrementerTag The tag to increment the count at.
110 @param[in] Label A label to look for.
111 @param[in, out] ScriptFile The pointer to the current script file structure.
112 @param[in] MovePast TRUE makes function return 1 past the found
114 @param[in] FindOnly TRUE to not change the ScriptFile.
115 @param[in] CommandNode The pointer to the Node to test.
116 @param[in, out] TargetCount The pointer to the current count.
120 IN CONST LIST_MANIP_FUNC Function
,
121 IN CONST CHAR16
*DecrementerTag
,
122 IN CONST CHAR16
*IncrementerTag
,
123 IN CONST CHAR16
*Label OPTIONAL
,
124 IN OUT SCRIPT_FILE
*ScriptFile
,
125 IN CONST BOOLEAN MovePast
,
126 IN CONST BOOLEAN FindOnly
,
127 IN CONST SCRIPT_COMMAND_LIST
*CommandNode
,
128 IN OUT UINTN
*TargetCount
133 CHAR16
*CommandNameWalker
;
134 CHAR16
*TempLocation
;
139 // get just the first part of the command line...
142 CommandName
= StrnCatGrow (&CommandName
, NULL
, CommandNode
->Cl
, 0);
143 if (CommandName
== NULL
) {
147 CommandNameWalker
= CommandName
;
150 // Skip leading spaces and tabs.
152 while ((CommandNameWalker
[0] == L
' ') || (CommandNameWalker
[0] == L
'\t')) {
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
172 } else if (gUnicodeCollation
->StriColl (
174 (CHAR16
*)CommandNameWalker
,
175 (CHAR16
*)DecrementerTag
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
,
203 && ((*TargetCount
) == 0))
208 // we found the target label without loops
211 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
);
213 ScriptFile
->CurrentCommand
= (SCRIPT_COMMAND_LIST
*)CommandNode
;
220 // Free the memory for this loop...
222 FreePool (CommandName
);
227 Move the script pointer from 1 tag (line) to another.
229 It functions so that count starts at 1 and it increases or decreases when it
230 hits the specified tags. when it hits zero the location has been found.
232 DecrementerTag and IncrementerTag are used to get around for/endfor and
233 similar paired types where the entire middle should be ignored.
235 If label is used it will be used instead of the count.
237 @param[in] Function The function to use to enumerate through the
238 list. Normally GetNextNode or GetPreviousNode.
239 @param[in] DecrementerTag The tag to decrement the count at.
240 @param[in] IncrementerTag The tag to increment the count at.
241 @param[in] Label A label to look for.
242 @param[in, out] ScriptFile The pointer to the current script file structure.
243 @param[in] MovePast TRUE makes function return 1 past the found
245 @param[in] FindOnly TRUE to not change the ScriptFile.
246 @param[in] WrapAroundScript TRUE to wrap end-to-begining or vise versa in
251 IN CONST LIST_MANIP_FUNC Function
,
252 IN CONST CHAR16
*DecrementerTag
,
253 IN CONST CHAR16
*IncrementerTag
,
254 IN CONST CHAR16
*Label OPTIONAL
,
255 IN OUT SCRIPT_FILE
*ScriptFile
,
256 IN CONST BOOLEAN MovePast
,
257 IN CONST BOOLEAN FindOnly
,
258 IN CONST BOOLEAN WrapAroundScript
261 SCRIPT_COMMAND_LIST
*CommandNode
;
271 if (ScriptFile
== NULL
) {
275 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &ScriptFile
->CurrentCommand
->Link
), Found
= FALSE
276 ; !IsNull (&ScriptFile
->CommandList
, &CommandNode
->Link
) && !Found
277 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
280 Found
= TestNodeForMove (
293 if (WrapAroundScript
&& !Found
) {
294 for (CommandNode
= (SCRIPT_COMMAND_LIST
*)GetFirstNode (&ScriptFile
->CommandList
), Found
= FALSE
295 ; CommandNode
!= ScriptFile
->CurrentCommand
&& !Found
296 ; CommandNode
= (SCRIPT_COMMAND_LIST
*)(*Function
)(&ScriptFile
->CommandList
, &CommandNode
->Link
)
299 Found
= TestNodeForMove (