TianoCore EDK2 master
Loading...
Searching...
No Matches
UefiShellLevel1CommandsLib.c
Go to the documentation of this file.
1
11
12STATIC CONST CHAR16 mFileName[] = L"ShellCommands";
13EFI_HII_HANDLE gShellLevel1HiiHandle = NULL;
14
20CONST CHAR16 *
21EFIAPI
23 VOID
24 )
25{
26 return (mFileName);
27}
28
41EFIAPI
43 IN EFI_HANDLE ImageHandle,
44 IN EFI_SYSTEM_TABLE *SystemTable
45 )
46{
47 //
48 // if shell level is less than 2 do nothing
49 //
50 if (PcdGet8 (PcdShellSupportLevel) < 1) {
51 return (EFI_SUCCESS);
52 }
53
54 gShellLevel1HiiHandle = HiiAddPackages (&gShellLevel1HiiGuid, gImageHandle, UefiShellLevel1CommandsLibStrings, NULL);
55 if (gShellLevel1HiiHandle == NULL) {
56 return (EFI_DEVICE_ERROR);
57 }
58
59 //
60 // install our shell command handlers that are always installed
61 //
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)));
71
72 return (EFI_SUCCESS);
73}
74
82EFIAPI
84 IN EFI_HANDLE ImageHandle,
85 IN EFI_SYSTEM_TABLE *SystemTable
86 )
87{
88 if (gShellLevel1HiiHandle != NULL) {
89 HiiRemovePackages (gShellLevel1HiiHandle);
90 }
91
92 return (EFI_SUCCESS);
93}
94
118BOOLEAN
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
129 )
130{
131 BOOLEAN Found;
132 CHAR16 *CommandName;
133 CHAR16 *CommandNameWalker;
134 CHAR16 *TempLocation;
135
136 Found = FALSE;
137
138 //
139 // get just the first part of the command line...
140 //
141 CommandName = NULL;
142 CommandName = StrnCatGrow (&CommandName, NULL, CommandNode->Cl, 0);
143 if (CommandName == NULL) {
144 return (FALSE);
145 }
146
147 CommandNameWalker = CommandName;
148
149 //
150 // Skip leading spaces and tabs.
151 //
152 while ((CommandNameWalker[0] == L' ') || (CommandNameWalker[0] == L'\t')) {
153 CommandNameWalker++;
154 }
155
156 TempLocation = StrStr (CommandNameWalker, L" ");
157
158 if (TempLocation != NULL) {
159 *TempLocation = CHAR_NULL;
160 }
161
162 //
163 // did we find a nested item ?
164 //
165 if (gUnicodeCollation->StriColl (
166 gUnicodeCollation,
167 (CHAR16 *)CommandNameWalker,
168 (CHAR16 *)IncrementerTag
169 ) == 0)
170 {
171 (*TargetCount)++;
172 } else if (gUnicodeCollation->StriColl (
173 gUnicodeCollation,
174 (CHAR16 *)CommandNameWalker,
175 (CHAR16 *)DecrementerTag
176 ) == 0)
177 {
178 if (*TargetCount > 0) {
179 (*TargetCount)--;
180 }
181 }
182
183 //
184 // did we find the matching one...
185 //
186 if (Label == NULL) {
187 if (*TargetCount == 0) {
188 Found = TRUE;
189 if (!FindOnly) {
190 if (MovePast) {
191 ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
192 } else {
193 ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
194 }
195 }
196 }
197 } else {
198 if ( (gUnicodeCollation->StriColl (
199 gUnicodeCollation,
200 (CHAR16 *)CommandNameWalker,
201 (CHAR16 *)Label
202 ) == 0)
203 && ((*TargetCount) == 0))
204 {
205 Found = TRUE;
206 if (!FindOnly) {
207 //
208 // we found the target label without loops
209 //
210 if (MovePast) {
211 ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)(*Function)(&ScriptFile->CommandList, &CommandNode->Link);
212 } else {
213 ScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)CommandNode;
214 }
215 }
216 }
217 }
218
219 //
220 // Free the memory for this loop...
221 //
222 FreePool (CommandName);
223 return (Found);
224}
225
249BOOLEAN
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
259 )
260{
261 SCRIPT_COMMAND_LIST *CommandNode;
262 BOOLEAN Found;
263 UINTN TargetCount;
264
265 if (Label == NULL) {
266 TargetCount = 1;
267 } else {
268 TargetCount = 0;
269 }
270
271 if (ScriptFile == NULL) {
272 return FALSE;
273 }
274
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)
278 )
279 {
280 Found = TestNodeForMove (
281 Function,
282 DecrementerTag,
283 IncrementerTag,
284 Label,
285 ScriptFile,
286 MovePast,
287 FindOnly,
288 CommandNode,
289 &TargetCount
290 );
291 }
292
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)
297 )
298 {
299 Found = TestNodeForMove (
300 Function,
301 DecrementerTag,
302 IncrementerTag,
303 Label,
304 ScriptFile,
305 MovePast,
306 FindOnly,
307 CommandNode,
308 &TargetCount
309 );
310 }
311 }
312
313 return (Found);
314}
UINT64 UINTN
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:443
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
VOID EFIAPI FreePool(IN VOID *Buffer)
SHELL_STATUS EFIAPI ShellCommandRunExit(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Exit.c:25
SHELL_STATUS EFIAPI ShellCommandRunEndFor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: For.c:59
SHELL_STATUS EFIAPI ShellCommandRunFor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: For.c:288
SHELL_STATUS EFIAPI ShellCommandRunGoto(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Goto.c:20
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
Definition: HiiLib.c:141
VOID EFIAPI HiiRemovePackages(IN EFI_HII_HANDLE HiiHandle)
Definition: HiiLib.c:253
SHELL_STATUS EFIAPI ShellCommandRunEndIf(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: If.c:1150
SHELL_STATUS EFIAPI ShellCommandRunElse(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: If.c:1065
SHELL_STATUS EFIAPI ShellCommandRunIf(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: If.c:869
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
RETURN_STATUS EFIAPI ShellCommandRegisterCommandName(IN CONST CHAR16 *CommandString, IN SHELL_RUN_COMMAND CommandHandler, IN SHELL_GET_MAN_FILENAME GetManFileName, IN UINT32 ShellMinSupportLevel, IN CONST CHAR16 *ProfileName, IN CONST BOOLEAN CanAffectLE, IN CONST EFI_HII_HANDLE HiiHandle, IN CONST EFI_STRING_ID ManFormatHelp)
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
SHELL_STATUS EFIAPI ShellCommandRunStall(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Stall.c:20
SHELL_STATUS EFIAPI ShellCommandRunShift(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Shift.c:20
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_HANDLE gImageHandle
#define STRING_TOKEN(t)
VOID * EFI_HII_HANDLE
EFI_STATUS EFIAPI ShellLevel1CommandsLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI ShellLevel1CommandsLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
BOOLEAN MoveToTag(IN CONST LIST_MANIP_FUNC Function, IN CONST CHAR16 *DecrementerTag, IN CONST CHAR16 *IncrementerTag, IN CONST CHAR16 *Label OPTIONAL, IN OUT SCRIPT_FILE *ScriptFile, IN CONST BOOLEAN MovePast, IN CONST BOOLEAN FindOnly, IN CONST BOOLEAN WrapAroundScript)
BOOLEAN TestNodeForMove(IN CONST LIST_MANIP_FUNC Function, IN CONST CHAR16 *DecrementerTag, IN CONST CHAR16 *IncrementerTag, IN CONST CHAR16 *Label OPTIONAL, IN OUT SCRIPT_FILE *ScriptFile, IN CONST BOOLEAN MovePast, IN CONST BOOLEAN FindOnly, IN CONST SCRIPT_COMMAND_LIST *CommandNode, IN OUT UINTN *TargetCount)
CONST CHAR16 *EFIAPI ShellCommandGetManFileNameLevel1(VOID)
LIST_ENTRY *(EFIAPI * LIST_MANIP_FUNC)(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
LIST_ENTRY Link
List enumerator items.