]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | This is THE shell (application)\r | |
3 | \r | |
dcbdb8bf | 4 | Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r |
c011b6c9 | 5 | (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P.<BR>\r |
a405b86d | 6 | This program and the accompanying materials\r |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "Shell.h"\r | |
17 | \r | |
18 | //\r | |
19 | // Initialize the global structure\r | |
20 | //\r | |
21 | SHELL_INFO ShellInfoObject = {\r | |
22 | NULL,\r | |
23 | NULL,\r | |
24 | FALSE,\r | |
25 | FALSE,\r | |
26 | {\r | |
ce68d3bc SZ |
27 | {{\r |
28 | 0,\r | |
29 | 0,\r | |
30 | 0,\r | |
31 | 0,\r | |
32 | 0,\r | |
33 | 0,\r | |
34 | 0,\r | |
35 | 0,\r | |
dcbdb8bf | 36 | 0,\r |
ce68d3bc SZ |
37 | 0\r |
38 | }},\r | |
a405b86d | 39 | 0,\r |
40 | NULL,\r | |
41 | NULL\r | |
42 | },\r | |
ce68d3bc | 43 | {{NULL, NULL}, NULL},\r |
a405b86d | 44 | {\r |
ce68d3bc | 45 | {{NULL, NULL}, NULL},\r |
a405b86d | 46 | 0,\r |
47 | 0,\r | |
48 | TRUE\r | |
49 | },\r | |
50 | NULL,\r | |
51 | 0,\r | |
52 | NULL,\r | |
53 | NULL,\r | |
54 | NULL,\r | |
55 | NULL,\r | |
56 | NULL,\r | |
ce68d3bc SZ |
57 | {{NULL, NULL}, NULL, NULL},\r |
58 | {{NULL, NULL}, NULL, NULL},\r | |
59 | NULL,\r | |
60 | NULL,\r | |
61 | NULL,\r | |
62 | NULL,\r | |
8be0ba36 | 63 | NULL,\r |
64 | NULL,\r | |
65 | NULL,\r | |
a49f6a2f | 66 | NULL,\r |
67 | FALSE\r | |
a405b86d | 68 | };\r |
69 | \r | |
70 | STATIC CONST CHAR16 mScriptExtension[] = L".NSH";\r | |
71 | STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI";\r | |
3c865f20 | 72 | STATIC CONST CHAR16 mStartupScript[] = L"startup.nsh";\r |
dcbdb8bf QS |
73 | CONST CHAR16 mNoNestingEnvVarName[] = L"nonesting";\r |
74 | CONST CHAR16 mNoNestingTrue[] = L"True";\r | |
75 | CONST CHAR16 mNoNestingFalse[] = L"False";\r | |
a405b86d | 76 | \r |
ad2bc854 | 77 | /**\r |
51429264 | 78 | Cleans off leading and trailing spaces and tabs.\r |
ad2bc854 | 79 | \r |
51429264 | 80 | @param[in] String pointer to the string to trim them off.\r |
ad2bc854 JC |
81 | **/\r |
82 | EFI_STATUS\r | |
83 | EFIAPI\r | |
84 | TrimSpaces(\r | |
85 | IN CHAR16 **String\r | |
86 | )\r | |
87 | {\r | |
88 | ASSERT(String != NULL);\r | |
89 | ASSERT(*String!= NULL);\r | |
90 | //\r | |
91 | // Remove any spaces and tabs at the beginning of the (*String).\r | |
92 | //\r | |
93 | while (((*String)[0] == L' ') || ((*String)[0] == L'\t')) {\r | |
94 | CopyMem((*String), (*String)+1, StrSize((*String)) - sizeof((*String)[0]));\r | |
95 | }\r | |
96 | \r | |
97 | //\r | |
404b3f43 | 98 | // Remove any spaces and tabs at the end of the (*String).\r |
ad2bc854 | 99 | //\r |
404b3f43 | 100 | while ((StrLen (*String) > 0) && (((*String)[StrLen((*String))-1] == L' ') || ((*String)[StrLen((*String))-1] == L'\t'))) {\r |
ad2bc854 JC |
101 | (*String)[StrLen((*String))-1] = CHAR_NULL;\r |
102 | }\r | |
103 | \r | |
104 | return (EFI_SUCCESS);\r | |
105 | }\r | |
106 | \r | |
a95cf8f0 JC |
107 | /**\r |
108 | Parse for the next instance of one string within another string. Can optionally make sure that \r | |
109 | the string was not escaped (^ character) per the shell specification.\r | |
110 | \r | |
111 | @param[in] SourceString The string to search within\r | |
112 | @param[in] FindString The string to look for\r | |
113 | @param[in] CheckForEscapeCharacter TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances\r | |
114 | **/\r | |
115 | CHAR16*\r | |
116 | EFIAPI\r | |
117 | FindNextInstance(\r | |
118 | IN CONST CHAR16 *SourceString,\r | |
119 | IN CONST CHAR16 *FindString,\r | |
120 | IN CONST BOOLEAN CheckForEscapeCharacter\r | |
121 | )\r | |
122 | {\r | |
123 | CHAR16 *Temp;\r | |
124 | if (SourceString == NULL) {\r | |
125 | return (NULL);\r | |
126 | }\r | |
127 | Temp = StrStr(SourceString, FindString);\r | |
128 | \r | |
129 | //\r | |
d08a5464 | 130 | // If nothing found, or we don't care about escape characters\r |
a95cf8f0 JC |
131 | //\r |
132 | if (Temp == NULL || !CheckForEscapeCharacter) {\r | |
133 | return (Temp);\r | |
134 | }\r | |
135 | \r | |
136 | //\r | |
137 | // If we found an escaped character, try again on the remainder of the string\r | |
138 | //\r | |
139 | if ((Temp > (SourceString)) && *(Temp-1) == L'^') {\r | |
140 | return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);\r | |
141 | }\r | |
142 | \r | |
143 | //\r | |
144 | // we found the right character\r | |
145 | //\r | |
146 | return (Temp);\r | |
147 | }\r | |
148 | \r | |
42435671 | 149 | /**\r |
d08a5464 | 150 | Check whether the string between a pair of % is a valid environment variable name.\r |
42435671 QS |
151 | \r |
152 | @param[in] BeginPercent pointer to the first percent.\r | |
153 | @param[in] EndPercent pointer to the last percent.\r | |
154 | \r | |
155 | @retval TRUE is a valid environment variable name.\r | |
156 | @retval FALSE is NOT a valid environment variable name.\r | |
157 | **/\r | |
158 | BOOLEAN\r | |
159 | IsValidEnvironmentVariableName(\r | |
160 | IN CONST CHAR16 *BeginPercent,\r | |
161 | IN CONST CHAR16 *EndPercent\r | |
162 | )\r | |
163 | {\r | |
164 | CONST CHAR16 *Walker;\r | |
165 | \r | |
166 | Walker = NULL;\r | |
167 | \r | |
168 | ASSERT (BeginPercent != NULL);\r | |
169 | ASSERT (EndPercent != NULL);\r | |
170 | ASSERT (BeginPercent < EndPercent);\r | |
171 | \r | |
172 | if ((BeginPercent + 1) == EndPercent) {\r | |
173 | return FALSE;\r | |
174 | }\r | |
175 | \r | |
176 | for (Walker = BeginPercent + 1; Walker < EndPercent; Walker++) {\r | |
177 | if (\r | |
178 | (*Walker >= L'0' && *Walker <= L'9') ||\r | |
179 | (*Walker >= L'A' && *Walker <= L'Z') ||\r | |
180 | (*Walker >= L'a' && *Walker <= L'z') ||\r | |
181 | (*Walker == L'_')\r | |
182 | ) {\r | |
183 | if (Walker == BeginPercent + 1 && (*Walker >= L'0' && *Walker <= L'9')) {\r | |
184 | return FALSE;\r | |
185 | } else {\r | |
186 | continue;\r | |
187 | }\r | |
188 | } else {\r | |
189 | return FALSE;\r | |
190 | }\r | |
191 | }\r | |
192 | \r | |
193 | return TRUE;\r | |
194 | }\r | |
195 | \r | |
518c8cdc JC |
196 | /**\r |
197 | Determine if a command line contains a split operation\r | |
198 | \r | |
199 | @param[in] CmdLine The command line to parse.\r | |
200 | \r | |
201 | @retval TRUE CmdLine has a valid split.\r | |
202 | @retval FALSE CmdLine does not have a valid split.\r | |
203 | **/\r | |
204 | BOOLEAN\r | |
205 | EFIAPI\r | |
206 | ContainsSplit(\r | |
207 | IN CONST CHAR16 *CmdLine\r | |
208 | )\r | |
209 | {\r | |
210 | CONST CHAR16 *TempSpot;\r | |
6f6792b8 QS |
211 | CONST CHAR16 *FirstQuote;\r |
212 | CONST CHAR16 *SecondQuote;\r | |
213 | \r | |
a95cf8f0 | 214 | FirstQuote = FindNextInstance (CmdLine, L"\"", TRUE);\r |
6f6792b8 | 215 | SecondQuote = NULL;\r |
00534bc3 | 216 | TempSpot = FindFirstCharacter(CmdLine, L"|", L'^');\r |
6f6792b8 | 217 | \r |
fe8ec3dd JC |
218 | if (FirstQuote == NULL || \r |
219 | TempSpot == NULL || \r | |
220 | TempSpot == CHAR_NULL || \r | |
6f6792b8 QS |
221 | FirstQuote > TempSpot\r |
222 | ) {\r | |
223 | return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r | |
224 | }\r | |
225 | \r | |
226 | while ((TempSpot != NULL) && (*TempSpot != CHAR_NULL)) {\r | |
fe8ec3dd | 227 | if (FirstQuote == NULL || FirstQuote > TempSpot) {\r |
6f6792b8 QS |
228 | break;\r |
229 | } \r | |
a95cf8f0 | 230 | SecondQuote = FindNextInstance (FirstQuote + 1, L"\"", TRUE);\r |
fe8ec3dd | 231 | if (SecondQuote == NULL) {\r |
6f6792b8 QS |
232 | break;\r |
233 | }\r | |
234 | if (SecondQuote < TempSpot) {\r | |
a95cf8f0 | 235 | FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r |
6f6792b8 QS |
236 | continue;\r |
237 | } else {\r | |
a95cf8f0 | 238 | FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r |
00534bc3 | 239 | TempSpot = FindFirstCharacter(TempSpot + 1, L"|", L'^');\r |
6f6792b8 QS |
240 | continue;\r |
241 | } \r | |
242 | }\r | |
243 | \r | |
8dcd84b9 | 244 | return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r |
19a44972 JC |
245 | }\r |
246 | \r | |
733f138d | 247 | /**\r |
248 | Function to start monitoring for CTRL-S using SimpleTextInputEx. This \r | |
249 | feature's enabled state was not known when the shell initially launched.\r | |
250 | \r | |
251 | @retval EFI_SUCCESS The feature is enabled.\r | |
d08a5464 | 252 | @retval EFI_OUT_OF_RESOURCES There is not enough memory available.\r |
733f138d | 253 | **/\r |
254 | EFI_STATUS\r | |
255 | EFIAPI\r | |
256 | InternalEfiShellStartCtrlSMonitor(\r | |
257 | VOID\r | |
258 | )\r | |
259 | {\r | |
260 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r | |
261 | EFI_KEY_DATA KeyData;\r | |
262 | EFI_STATUS Status;\r | |
263 | \r | |
264 | Status = gBS->OpenProtocol(\r | |
265 | gST->ConsoleInHandle,\r | |
266 | &gEfiSimpleTextInputExProtocolGuid,\r | |
267 | (VOID**)&SimpleEx,\r | |
268 | gImageHandle,\r | |
269 | NULL,\r | |
270 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
271 | if (EFI_ERROR(Status)) {\r | |
272 | ShellPrintHiiEx(\r | |
273 | -1, \r | |
274 | -1, \r | |
275 | NULL,\r | |
276 | STRING_TOKEN (STR_SHELL_NO_IN_EX),\r | |
277 | ShellInfoObject.HiiHandle);\r | |
278 | return (EFI_SUCCESS);\r | |
279 | }\r | |
280 | \r | |
281 | KeyData.KeyState.KeyToggleState = 0;\r | |
282 | KeyData.Key.ScanCode = 0;\r | |
283 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r | |
284 | KeyData.Key.UnicodeChar = L's';\r | |
285 | \r | |
286 | Status = SimpleEx->RegisterKeyNotify(\r | |
287 | SimpleEx,\r | |
288 | &KeyData,\r | |
289 | NotificationFunction,\r | |
290 | &ShellInfoObject.CtrlSNotifyHandle1);\r | |
291 | \r | |
292 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r | |
293 | if (!EFI_ERROR(Status)) {\r | |
294 | Status = SimpleEx->RegisterKeyNotify(\r | |
295 | SimpleEx,\r | |
296 | &KeyData,\r | |
297 | NotificationFunction,\r | |
298 | &ShellInfoObject.CtrlSNotifyHandle2);\r | |
299 | }\r | |
300 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r | |
301 | KeyData.Key.UnicodeChar = 19;\r | |
302 | \r | |
303 | if (!EFI_ERROR(Status)) {\r | |
304 | Status = SimpleEx->RegisterKeyNotify(\r | |
305 | SimpleEx,\r | |
306 | &KeyData,\r | |
307 | NotificationFunction,\r | |
ed8b5297 | 308 | &ShellInfoObject.CtrlSNotifyHandle3);\r |
733f138d | 309 | } \r |
310 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r | |
311 | if (!EFI_ERROR(Status)) {\r | |
312 | Status = SimpleEx->RegisterKeyNotify(\r | |
313 | SimpleEx,\r | |
314 | &KeyData,\r | |
315 | NotificationFunction,\r | |
ed8b5297 | 316 | &ShellInfoObject.CtrlSNotifyHandle4);\r |
733f138d | 317 | }\r |
318 | return (Status);\r | |
319 | }\r | |
320 | \r | |
321 | \r | |
322 | \r | |
a405b86d | 323 | /**\r |
324 | The entry point for the application.\r | |
325 | \r | |
326 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
327 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
328 | \r | |
329 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
330 | @retval other Some error occurs when executing this entry point.\r | |
331 | \r | |
332 | **/\r | |
333 | EFI_STATUS\r | |
334 | EFIAPI\r | |
335 | UefiMain (\r | |
336 | IN EFI_HANDLE ImageHandle,\r | |
337 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
338 | )\r | |
339 | {\r | |
a49f6a2f | 340 | EFI_STATUS Status;\r |
341 | CHAR16 *TempString;\r | |
342 | UINTN Size;\r | |
343 | EFI_HANDLE ConInHandle;\r | |
344 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL *OldConIn;\r | |
a405b86d | 345 | \r |
346 | if (PcdGet8(PcdShellSupportLevel) > 3) {\r | |
347 | return (EFI_UNSUPPORTED);\r | |
348 | }\r | |
349 | \r | |
350 | //\r | |
351 | // Clear the screen\r | |
352 | //\r | |
353 | Status = gST->ConOut->ClearScreen(gST->ConOut);\r | |
3c865f20 | 354 | if (EFI_ERROR(Status)) {\r |
355 | return (Status);\r | |
356 | }\r | |
a405b86d | 357 | \r |
358 | //\r | |
359 | // Populate the global structure from PCDs\r | |
360 | //\r | |
361 | ShellInfoObject.ImageDevPath = NULL;\r | |
362 | ShellInfoObject.FileDevPath = NULL;\r | |
363 | ShellInfoObject.PageBreakEnabled = PcdGetBool(PcdShellPageBreakDefault);\r | |
364 | ShellInfoObject.ViewingSettings.InsertMode = PcdGetBool(PcdShellInsertModeDefault);\r | |
365 | ShellInfoObject.LogScreenCount = PcdGet8 (PcdShellScreenLogCount );\r | |
366 | \r | |
367 | //\r | |
368 | // verify we dont allow for spec violation\r | |
369 | //\r | |
370 | ASSERT(ShellInfoObject.LogScreenCount >= 3);\r | |
371 | \r | |
372 | //\r | |
373 | // Initialize the LIST ENTRY objects...\r | |
374 | //\r | |
375 | InitializeListHead(&ShellInfoObject.BufferToFreeList.Link);\r | |
376 | InitializeListHead(&ShellInfoObject.ViewingSettings.CommandHistory.Link);\r | |
377 | InitializeListHead(&ShellInfoObject.SplitList.Link);\r | |
378 | \r | |
379 | //\r | |
380 | // Check PCDs for optional features that are not implemented yet.\r | |
381 | //\r | |
382 | if ( PcdGetBool(PcdShellSupportOldProtocols)\r | |
383 | || !FeaturePcdGet(PcdShellRequireHiiPlatform)\r | |
384 | || FeaturePcdGet(PcdShellSupportFrameworkHii)\r | |
385 | ) {\r | |
386 | return (EFI_UNSUPPORTED);\r | |
387 | }\r | |
388 | \r | |
389 | //\r | |
390 | // turn off the watchdog timer\r | |
391 | //\r | |
392 | gBS->SetWatchdogTimer (0, 0, 0, NULL);\r | |
393 | \r | |
394 | //\r | |
395 | // install our console logger. This will keep a log of the output for back-browsing\r | |
396 | //\r | |
397 | Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);\r | |
3c865f20 | 398 | if (!EFI_ERROR(Status)) {\r |
399 | //\r | |
400 | // Enable the cursor to be visible\r | |
401 | //\r | |
402 | gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r | |
a405b86d | 403 | \r |
3c865f20 | 404 | //\r |
405 | // If supporting EFI 1.1 we need to install HII protocol\r | |
406 | // only do this if PcdShellRequireHiiPlatform == FALSE\r | |
407 | //\r | |
408 | // remove EFI_UNSUPPORTED check above when complete.\r | |
409 | ///@todo add support for Framework HII\r | |
a405b86d | 410 | \r |
3c865f20 | 411 | //\r |
412 | // install our (solitary) HII package\r | |
413 | //\r | |
414 | ShellInfoObject.HiiHandle = HiiAddPackages (&gEfiCallerIdGuid, gImageHandle, ShellStrings, NULL);\r | |
a405b86d | 415 | if (ShellInfoObject.HiiHandle == NULL) {\r |
3c865f20 | 416 | if (PcdGetBool(PcdShellSupportFrameworkHii)) {\r |
417 | ///@todo Add our package into Framework HII\r | |
418 | }\r | |
419 | if (ShellInfoObject.HiiHandle == NULL) {\r | |
0477054b BJ |
420 | Status = EFI_NOT_STARTED;\r |
421 | goto FreeResources;\r | |
3c865f20 | 422 | }\r |
a405b86d | 423 | }\r |
a405b86d | 424 | \r |
3c865f20 | 425 | //\r |
426 | // create and install the EfiShellParametersProtocol\r | |
427 | //\r | |
428 | Status = CreatePopulateInstallShellParametersProtocol(&ShellInfoObject.NewShellParametersProtocol, &ShellInfoObject.RootShellInstance);\r | |
429 | ASSERT_EFI_ERROR(Status);\r | |
430 | ASSERT(ShellInfoObject.NewShellParametersProtocol != NULL);\r | |
a405b86d | 431 | \r |
3c865f20 | 432 | //\r |
433 | // create and install the EfiShellProtocol\r | |
434 | //\r | |
435 | Status = CreatePopulateInstallShellProtocol(&ShellInfoObject.NewEfiShellProtocol);\r | |
436 | ASSERT_EFI_ERROR(Status);\r | |
437 | ASSERT(ShellInfoObject.NewEfiShellProtocol != NULL);\r | |
a405b86d | 438 | \r |
3c865f20 | 439 | //\r |
440 | // Now initialize the shell library (it requires Shell Parameters protocol)\r | |
441 | //\r | |
442 | Status = ShellInitialize();\r | |
443 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 444 | \r |
3c865f20 | 445 | Status = CommandInit();\r |
446 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 447 | \r |
3c865f20 | 448 | //\r |
449 | // Check the command line\r | |
450 | //\r | |
da92bf85 BJ |
451 | Status = ProcessCommandLine ();\r |
452 | if (EFI_ERROR (Status)) {\r | |
453 | goto FreeResources;\r | |
454 | }\r | |
a405b86d | 455 | \r |
3c865f20 | 456 | //\r |
457 | // If shell support level is >= 1 create the mappings and paths\r | |
458 | //\r | |
459 | if (PcdGet8(PcdShellSupportLevel) >= 1) {\r | |
460 | Status = ShellCommandCreateInitialMappingsAndPaths();\r | |
461 | }\r | |
a405b86d | 462 | \r |
dcbdb8bf QS |
463 | //\r |
464 | // Set the environment variable for nesting support\r | |
465 | //\r | |
466 | Size = 0;\r | |
467 | TempString = NULL;\r | |
468 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest) {\r | |
469 | //\r | |
470 | // No change. require nesting in Shell Protocol Execute()\r | |
471 | //\r | |
472 | StrnCatGrow(&TempString,\r | |
473 | &Size,\r | |
474 | L"False",\r | |
475 | 0);\r | |
476 | } else {\r | |
477 | StrnCatGrow(&TempString,\r | |
478 | &Size,\r | |
479 | mNoNestingTrue,\r | |
480 | 0);\r | |
481 | }\r | |
482 | Status = InternalEfiShellSetEnv(mNoNestingEnvVarName, TempString, TRUE);\r | |
483 | SHELL_FREE_NON_NULL(TempString);\r | |
484 | Size = 0;\r | |
485 | \r | |
3c865f20 | 486 | //\r |
487 | // save the device path for the loaded image and the device path for the filepath (under loaded image)\r | |
488 | // These are where to look for the startup.nsh file\r | |
489 | //\r | |
490 | Status = GetDevicePathsForImageAndFile(&ShellInfoObject.ImageDevPath, &ShellInfoObject.FileDevPath);\r | |
a405b86d | 491 | ASSERT_EFI_ERROR(Status);\r |
a405b86d | 492 | \r |
3c865f20 | 493 | //\r |
494 | // Display the version\r | |
495 | //\r | |
496 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion) {\r | |
497 | ShellPrintHiiEx (\r | |
498 | 0,\r | |
499 | gST->ConOut->Mode->CursorRow,\r | |
500 | NULL,\r | |
284e034f | 501 | STRING_TOKEN (STR_VER_OUTPUT_MAIN_SHELL),\r |
3c865f20 | 502 | ShellInfoObject.HiiHandle,\r |
503 | SupportLevel[PcdGet8(PcdShellSupportLevel)],\r | |
504 | gEfiShellProtocol->MajorVersion,\r | |
284e034f CP |
505 | gEfiShellProtocol->MinorVersion\r |
506 | );\r | |
507 | \r | |
508 | ShellPrintHiiEx (\r | |
509 | -1,\r | |
510 | -1,\r | |
511 | NULL,\r | |
512 | STRING_TOKEN (STR_VER_OUTPUT_MAIN_SUPPLIER),\r | |
513 | ShellInfoObject.HiiHandle,\r | |
514 | (CHAR16 *) PcdGetPtr (PcdShellSupplier)\r | |
515 | );\r | |
516 | \r | |
517 | ShellPrintHiiEx (\r | |
518 | -1,\r | |
519 | -1,\r | |
520 | NULL,\r | |
521 | STRING_TOKEN (STR_VER_OUTPUT_MAIN_UEFI),\r | |
522 | ShellInfoObject.HiiHandle,\r | |
3c865f20 | 523 | (gST->Hdr.Revision&0xffff0000)>>16,\r |
524 | (gST->Hdr.Revision&0x0000ffff),\r | |
525 | gST->FirmwareVendor,\r | |
526 | gST->FirmwareRevision\r | |
527 | );\r | |
528 | }\r | |
a405b86d | 529 | \r |
3c865f20 | 530 | //\r |
531 | // Display the mapping\r | |
532 | //\r | |
533 | if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {\r | |
a308e058 | 534 | Status = RunCommand(L"map");\r |
3c865f20 | 535 | ASSERT_EFI_ERROR(Status);\r |
536 | }\r | |
a405b86d | 537 | \r |
3c865f20 | 538 | //\r |
539 | // init all the built in alias'\r | |
540 | //\r | |
541 | Status = SetBuiltInAlias();\r | |
542 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 543 | \r |
3c865f20 | 544 | //\r |
545 | // Initialize environment variables\r | |
546 | //\r | |
547 | if (ShellCommandGetProfileList() != NULL) {\r | |
548 | Status = InternalEfiShellSetEnv(L"profiles", ShellCommandGetProfileList(), TRUE);\r | |
549 | ASSERT_EFI_ERROR(Status);\r | |
550 | }\r | |
a405b86d | 551 | \r |
3c865f20 | 552 | Size = 100;\r |
553 | TempString = AllocateZeroPool(Size);\r | |
a405b86d | 554 | \r |
3c865f20 | 555 | UnicodeSPrint(TempString, Size, L"%d", PcdGet8(PcdShellSupportLevel));\r |
556 | Status = InternalEfiShellSetEnv(L"uefishellsupport", TempString, TRUE);\r | |
557 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 558 | \r |
3c865f20 | 559 | UnicodeSPrint(TempString, Size, L"%d.%d", ShellInfoObject.NewEfiShellProtocol->MajorVersion, ShellInfoObject.NewEfiShellProtocol->MinorVersion);\r |
560 | Status = InternalEfiShellSetEnv(L"uefishellversion", TempString, TRUE);\r | |
561 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 562 | \r |
3c865f20 | 563 | UnicodeSPrint(TempString, Size, L"%d.%d", (gST->Hdr.Revision & 0xFFFF0000) >> 16, gST->Hdr.Revision & 0x0000FFFF);\r |
564 | Status = InternalEfiShellSetEnv(L"uefiversion", TempString, TRUE);\r | |
565 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 566 | \r |
3c865f20 | 567 | FreePool(TempString);\r |
a405b86d | 568 | \r |
3c865f20 | 569 | if (!EFI_ERROR(Status)) {\r |
570 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {\r | |
a405b86d | 571 | //\r |
3c865f20 | 572 | // Set up the event for CTRL-C monitoring...\r |
a405b86d | 573 | //\r |
8be0ba36 | 574 | Status = InernalEfiShellStartMonitor();\r |
3c865f20 | 575 | }\r |
576 | \r | |
733f138d | 577 | if (!EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r |
578 | //\r | |
579 | // Set up the event for CTRL-S monitoring...\r | |
580 | //\r | |
581 | Status = InternalEfiShellStartCtrlSMonitor();\r | |
582 | }\r | |
583 | \r | |
a49f6a2f | 584 | if (!EFI_ERROR(Status) && ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r |
585 | //\r | |
586 | // close off the gST->ConIn\r | |
587 | //\r | |
588 | OldConIn = gST->ConIn;\r | |
589 | ConInHandle = gST->ConsoleInHandle;\r | |
590 | gST->ConIn = CreateSimpleTextInOnFile((SHELL_FILE_HANDLE)&FileInterfaceNulFile, &gST->ConsoleInHandle);\r | |
591 | } else {\r | |
592 | OldConIn = NULL;\r | |
593 | ConInHandle = NULL;\r | |
594 | }\r | |
595 | \r | |
3c865f20 | 596 | if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {\r |
a405b86d | 597 | //\r |
3c865f20 | 598 | // process the startup script or launch the called app.\r |
a405b86d | 599 | //\r |
a308e058 | 600 | Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);\r |
3c865f20 | 601 | }\r |
a405b86d | 602 | \r |
ca79c798 | 603 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r |
a405b86d | 604 | //\r |
3c865f20 | 605 | // begin the UI waiting loop\r |
a405b86d | 606 | //\r |
3c865f20 | 607 | do {\r |
608 | //\r | |
609 | // clean out all the memory allocated for CONST <something> * return values\r | |
610 | // between each shell prompt presentation\r | |
611 | //\r | |
612 | if (!IsListEmpty(&ShellInfoObject.BufferToFreeList.Link)){\r | |
613 | FreeBufferList(&ShellInfoObject.BufferToFreeList);\r | |
614 | }\r | |
615 | \r | |
616 | //\r | |
617 | // Reset page break back to default.\r | |
618 | //\r | |
619 | ShellInfoObject.PageBreakEnabled = PcdGetBool(PcdShellPageBreakDefault);\r | |
81cd2f53 | 620 | ASSERT (ShellInfoObject.ConsoleInfo != NULL);\r |
3c865f20 | 621 | ShellInfoObject.ConsoleInfo->Enabled = TRUE;\r |
622 | ShellInfoObject.ConsoleInfo->RowCounter = 0;\r | |
623 | \r | |
8be0ba36 | 624 | //\r |
625 | // Reset the CTRL-C event (yes we ignore the return values)\r | |
626 | //\r | |
627 | Status = gBS->CheckEvent (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak);\r | |
628 | \r | |
3c865f20 | 629 | //\r |
630 | // Display Prompt\r | |
631 | //\r | |
632 | Status = DoShellPrompt();\r | |
633 | } while (!ShellCommandGetExit());\r | |
634 | }\r | |
a49f6a2f | 635 | if (OldConIn != NULL && ConInHandle != NULL) {\r |
636 | CloseSimpleTextInOnFile (gST->ConIn);\r | |
637 | gST->ConIn = OldConIn;\r | |
638 | gST->ConsoleInHandle = ConInHandle;\r | |
639 | }\r | |
a405b86d | 640 | }\r |
641 | }\r | |
3c865f20 | 642 | \r |
0477054b | 643 | FreeResources:\r |
a405b86d | 644 | //\r |
645 | // uninstall protocols / free memory / etc...\r | |
646 | //\r | |
647 | if (ShellInfoObject.UserBreakTimer != NULL) {\r | |
648 | gBS->CloseEvent(ShellInfoObject.UserBreakTimer);\r | |
649 | DEBUG_CODE(ShellInfoObject.UserBreakTimer = NULL;);\r | |
650 | }\r | |
a405b86d | 651 | if (ShellInfoObject.ImageDevPath != NULL) {\r |
652 | FreePool(ShellInfoObject.ImageDevPath);\r | |
653 | DEBUG_CODE(ShellInfoObject.ImageDevPath = NULL;);\r | |
654 | }\r | |
655 | if (ShellInfoObject.FileDevPath != NULL) {\r | |
656 | FreePool(ShellInfoObject.FileDevPath);\r | |
657 | DEBUG_CODE(ShellInfoObject.FileDevPath = NULL;);\r | |
658 | }\r | |
659 | if (ShellInfoObject.NewShellParametersProtocol != NULL) {\r | |
660 | CleanUpShellParametersProtocol(ShellInfoObject.NewShellParametersProtocol);\r | |
661 | DEBUG_CODE(ShellInfoObject.NewShellParametersProtocol = NULL;);\r | |
662 | }\r | |
663 | if (ShellInfoObject.NewEfiShellProtocol != NULL){\r | |
8be0ba36 | 664 | if (ShellInfoObject.NewEfiShellProtocol->IsRootShell()){\r |
92670471 | 665 | InternalEfiShellSetEnv(L"cwd", NULL, TRUE);\r |
8be0ba36 | 666 | }\r |
a405b86d | 667 | CleanUpShellProtocol(ShellInfoObject.NewEfiShellProtocol);\r |
668 | DEBUG_CODE(ShellInfoObject.NewEfiShellProtocol = NULL;);\r | |
669 | }\r | |
670 | \r | |
671 | if (!IsListEmpty(&ShellInfoObject.BufferToFreeList.Link)){\r | |
672 | FreeBufferList(&ShellInfoObject.BufferToFreeList);\r | |
673 | }\r | |
674 | \r | |
675 | if (!IsListEmpty(&ShellInfoObject.SplitList.Link)){\r | |
3c865f20 | 676 | ASSERT(FALSE); ///@todo finish this de-allocation.\r |
a405b86d | 677 | }\r |
678 | \r | |
679 | if (ShellInfoObject.ShellInitSettings.FileName != NULL) {\r | |
680 | FreePool(ShellInfoObject.ShellInitSettings.FileName);\r | |
681 | DEBUG_CODE(ShellInfoObject.ShellInitSettings.FileName = NULL;);\r | |
682 | }\r | |
683 | \r | |
684 | if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r | |
685 | FreePool(ShellInfoObject.ShellInitSettings.FileOptions);\r | |
686 | DEBUG_CODE(ShellInfoObject.ShellInitSettings.FileOptions = NULL;);\r | |
687 | }\r | |
688 | \r | |
689 | if (ShellInfoObject.HiiHandle != NULL) {\r | |
690 | HiiRemovePackages(ShellInfoObject.HiiHandle);\r | |
691 | DEBUG_CODE(ShellInfoObject.HiiHandle = NULL;);\r | |
692 | }\r | |
693 | \r | |
694 | if (!IsListEmpty(&ShellInfoObject.ViewingSettings.CommandHistory.Link)){\r | |
695 | FreeBufferList(&ShellInfoObject.ViewingSettings.CommandHistory);\r | |
696 | }\r | |
697 | \r | |
698 | ASSERT(ShellInfoObject.ConsoleInfo != NULL);\r | |
699 | if (ShellInfoObject.ConsoleInfo != NULL) {\r | |
700 | ConsoleLoggerUninstall(ShellInfoObject.ConsoleInfo);\r | |
701 | FreePool(ShellInfoObject.ConsoleInfo);\r | |
702 | DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;);\r | |
703 | }\r | |
704 | \r | |
a308e058 RN |
705 | if (ShellCommandGetExit()) {\r |
706 | return ((EFI_STATUS)ShellCommandGetExitCode());\r | |
b6b22b13 | 707 | }\r |
a308e058 | 708 | return (Status);\r |
a405b86d | 709 | }\r |
710 | \r | |
711 | /**\r | |
712 | Sets all the alias' that were registered with the ShellCommandLib library.\r | |
713 | \r | |
d08a5464 | 714 | @retval EFI_SUCCESS all init commands were run successfully.\r |
a405b86d | 715 | **/\r |
716 | EFI_STATUS\r | |
717 | EFIAPI\r | |
718 | SetBuiltInAlias(\r | |
719 | )\r | |
720 | {\r | |
721 | EFI_STATUS Status;\r | |
722 | CONST ALIAS_LIST *List;\r | |
723 | ALIAS_LIST *Node;\r | |
724 | \r | |
725 | //\r | |
726 | // Get all the commands we want to run\r | |
727 | //\r | |
728 | List = ShellCommandGetInitAliasList();\r | |
729 | \r | |
730 | //\r | |
731 | // for each command in the List\r | |
732 | //\r | |
733 | for ( Node = (ALIAS_LIST*)GetFirstNode(&List->Link)\r | |
734 | ; !IsNull (&List->Link, &Node->Link)\r | |
735 | ; Node = (ALIAS_LIST *)GetNextNode(&List->Link, &Node->Link)\r | |
736 | ){\r | |
737 | //\r | |
738 | // install the alias'\r | |
739 | //\r | |
740 | Status = InternalSetAlias(Node->CommandString, Node->Alias, TRUE);\r | |
741 | ASSERT_EFI_ERROR(Status);\r | |
742 | }\r | |
743 | return (EFI_SUCCESS);\r | |
744 | }\r | |
745 | \r | |
746 | /**\r | |
747 | Internal function to determine if 2 command names are really the same.\r | |
748 | \r | |
749 | @param[in] Command1 The pointer to the first command name.\r | |
750 | @param[in] Command2 The pointer to the second command name.\r | |
751 | \r | |
752 | @retval TRUE The 2 command names are the same.\r | |
753 | @retval FALSE The 2 command names are not the same.\r | |
754 | **/\r | |
755 | BOOLEAN\r | |
756 | EFIAPI\r | |
757 | IsCommand(\r | |
758 | IN CONST CHAR16 *Command1,\r | |
759 | IN CONST CHAR16 *Command2\r | |
760 | )\r | |
761 | {\r | |
762 | if (StringNoCaseCompare(&Command1, &Command2) == 0) {\r | |
763 | return (TRUE);\r | |
764 | }\r | |
765 | return (FALSE);\r | |
766 | }\r | |
767 | \r | |
768 | /**\r | |
769 | Internal function to determine if a command is a script only command.\r | |
770 | \r | |
771 | @param[in] CommandName The pointer to the command name.\r | |
772 | \r | |
773 | @retval TRUE The command is a script only command.\r | |
774 | @retval FALSE The command is not a script only command.\r | |
775 | **/\r | |
776 | BOOLEAN\r | |
777 | EFIAPI\r | |
778 | IsScriptOnlyCommand(\r | |
779 | IN CONST CHAR16 *CommandName\r | |
780 | )\r | |
781 | {\r | |
782 | if (IsCommand(CommandName, L"for")\r | |
783 | ||IsCommand(CommandName, L"endfor")\r | |
784 | ||IsCommand(CommandName, L"if")\r | |
785 | ||IsCommand(CommandName, L"else")\r | |
786 | ||IsCommand(CommandName, L"endif")\r | |
787 | ||IsCommand(CommandName, L"goto")) {\r | |
788 | return (TRUE);\r | |
789 | }\r | |
790 | return (FALSE);\r | |
791 | }\r | |
792 | \r | |
a405b86d | 793 | /**\r |
794 | This function will populate the 2 device path protocol parameters based on the\r | |
795 | global gImageHandle. The DevPath will point to the device path for the handle that has\r | |
796 | loaded image protocol installed on it. The FilePath will point to the device path\r | |
797 | for the file that was loaded.\r | |
798 | \r | |
d08a5464 JP |
799 | @param[in, out] DevPath On a successful return the device path to the loaded image.\r |
800 | @param[in, out] FilePath On a successful return the device path to the file.\r | |
a405b86d | 801 | \r |
d08a5464 | 802 | @retval EFI_SUCCESS The 2 device paths were successfully returned.\r |
a405b86d | 803 | @retval other A error from gBS->HandleProtocol.\r |
804 | \r | |
805 | @sa HandleProtocol\r | |
806 | **/\r | |
807 | EFI_STATUS\r | |
808 | EFIAPI\r | |
809 | GetDevicePathsForImageAndFile (\r | |
810 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,\r | |
811 | IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath\r | |
812 | )\r | |
813 | {\r | |
814 | EFI_STATUS Status;\r | |
815 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
816 | EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath;\r | |
817 | \r | |
818 | ASSERT(DevPath != NULL);\r | |
819 | ASSERT(FilePath != NULL);\r | |
820 | \r | |
821 | Status = gBS->OpenProtocol (\r | |
822 | gImageHandle,\r | |
823 | &gEfiLoadedImageProtocolGuid,\r | |
824 | (VOID**)&LoadedImage,\r | |
825 | gImageHandle,\r | |
826 | NULL,\r | |
827 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
828 | );\r | |
829 | if (!EFI_ERROR (Status)) {\r | |
830 | Status = gBS->OpenProtocol (\r | |
831 | LoadedImage->DeviceHandle,\r | |
832 | &gEfiDevicePathProtocolGuid,\r | |
833 | (VOID**)&ImageDevicePath,\r | |
834 | gImageHandle,\r | |
835 | NULL,\r | |
836 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
837 | );\r | |
838 | if (!EFI_ERROR (Status)) {\r | |
839 | *DevPath = DuplicateDevicePath (ImageDevicePath);\r | |
840 | *FilePath = DuplicateDevicePath (LoadedImage->FilePath);\r | |
a49f6a2f | 841 | gBS->CloseProtocol(\r |
842 | LoadedImage->DeviceHandle,\r | |
843 | &gEfiDevicePathProtocolGuid,\r | |
844 | gImageHandle,\r | |
845 | NULL);\r | |
a405b86d | 846 | }\r |
847 | gBS->CloseProtocol(\r | |
848 | gImageHandle,\r | |
849 | &gEfiLoadedImageProtocolGuid,\r | |
850 | gImageHandle,\r | |
851 | NULL);\r | |
852 | }\r | |
853 | return (Status);\r | |
854 | }\r | |
855 | \r | |
a405b86d | 856 | /**\r |
857 | Process all Uefi Shell 2.0 command line options.\r | |
858 | \r | |
859 | see Uefi Shell 2.0 section 3.2 for full details.\r | |
860 | \r | |
861 | the command line must resemble the following:\r | |
862 | \r | |
863 | shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]\r | |
864 | \r | |
865 | ShellOpt-options Options which control the initialization behavior of the shell.\r | |
866 | These options are read from the EFI global variable "ShellOpt"\r | |
867 | and are processed before options or file-name.\r | |
868 | \r | |
869 | options Options which control the initialization behavior of the shell.\r | |
870 | \r | |
871 | file-name The name of a UEFI shell application or script to be executed\r | |
872 | after initialization is complete. By default, if file-name is\r | |
873 | specified, then -nostartup is implied. Scripts are not supported\r | |
874 | by level 0.\r | |
875 | \r | |
876 | file-name-options The command-line options that are passed to file-name when it\r | |
877 | is invoked.\r | |
878 | \r | |
879 | This will initialize the ShellInfoObject.ShellInitSettings global variable.\r | |
880 | \r | |
881 | @retval EFI_SUCCESS The variable is initialized.\r | |
882 | **/\r | |
883 | EFI_STATUS\r | |
884 | EFIAPI\r | |
885 | ProcessCommandLine(\r | |
886 | VOID\r | |
887 | )\r | |
888 | {\r | |
23385d63 BJ |
889 | UINTN Size;\r |
890 | UINTN LoopVar;\r | |
891 | CHAR16 *CurrentArg;\r | |
892 | CHAR16 *DelayValueStr;\r | |
893 | UINT64 DelayValue;\r | |
894 | EFI_STATUS Status;\r | |
895 | EFI_UNICODE_COLLATION_PROTOCOL *UnicodeCollation;\r | |
896 | \r | |
897 | // `file-name-options` will contain arguments to `file-name` that we don't\r | |
898 | // know about. This would cause ShellCommandLineParse to error, so we parse\r | |
899 | // arguments manually, ignoring those after the first thing that doesn't look\r | |
900 | // like a shell option (which is assumed to be `file-name`).\r | |
901 | \r | |
902 | Status = gBS->LocateProtocol (\r | |
903 | &gEfiUnicodeCollationProtocolGuid,\r | |
904 | NULL,\r | |
905 | (VOID **) &UnicodeCollation\r | |
906 | );\r | |
907 | if (EFI_ERROR (Status)) {\r | |
908 | return Status;\r | |
909 | }\r | |
910 | \r | |
911 | // Set default options\r | |
912 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup = FALSE;\r | |
913 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = FALSE;\r | |
914 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut = FALSE;\r | |
915 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn = FALSE;\r | |
916 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt = FALSE;\r | |
917 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap = FALSE;\r | |
918 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion = FALSE;\r | |
919 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay = FALSE;\r | |
920 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit = FALSE;\r | |
dcbdb8bf | 921 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest = FALSE;\r |
23385d63 BJ |
922 | ShellInfoObject.ShellInitSettings.Delay = 5;\r |
923 | \r | |
e9d19a80 CP |
924 | //\r |
925 | // Start LoopVar at 0 to parse only optional arguments at Argv[0]\r | |
926 | // and parse other parameters from Argv[1]. This is for use case that\r | |
927 | // UEFI Shell boot option is created, and OptionalData is provided\r | |
928 | // that starts with shell command-line options.\r | |
929 | //\r | |
930 | for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r | |
23385d63 BJ |
931 | CurrentArg = gEfiShellParametersProtocol->Argv[LoopVar];\r |
932 | if (UnicodeCollation->StriColl (\r | |
933 | UnicodeCollation,\r | |
934 | L"-startup",\r | |
935 | CurrentArg\r | |
936 | ) == 0) {\r | |
937 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup = TRUE;\r | |
3c865f20 | 938 | }\r |
23385d63 BJ |
939 | else if (UnicodeCollation->StriColl (\r |
940 | UnicodeCollation,\r | |
941 | L"-nostartup",\r | |
942 | CurrentArg\r | |
943 | ) == 0) {\r | |
944 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = TRUE;\r | |
945 | }\r | |
946 | else if (UnicodeCollation->StriColl (\r | |
947 | UnicodeCollation,\r | |
948 | L"-noconsoleout",\r | |
949 | CurrentArg\r | |
950 | ) == 0) {\r | |
951 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut = TRUE;\r | |
952 | }\r | |
953 | else if (UnicodeCollation->StriColl (\r | |
954 | UnicodeCollation,\r | |
955 | L"-noconsolein",\r | |
956 | CurrentArg\r | |
957 | ) == 0) {\r | |
958 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn = TRUE;\r | |
959 | }\r | |
960 | else if (UnicodeCollation->StriColl (\r | |
961 | UnicodeCollation,\r | |
962 | L"-nointerrupt",\r | |
963 | CurrentArg\r | |
964 | ) == 0) {\r | |
965 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt = TRUE;\r | |
966 | }\r | |
967 | else if (UnicodeCollation->StriColl (\r | |
968 | UnicodeCollation,\r | |
969 | L"-nomap",\r | |
970 | CurrentArg\r | |
971 | ) == 0) {\r | |
972 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap = TRUE;\r | |
973 | }\r | |
974 | else if (UnicodeCollation->StriColl (\r | |
975 | UnicodeCollation,\r | |
976 | L"-noversion",\r | |
977 | CurrentArg\r | |
978 | ) == 0) {\r | |
979 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion = TRUE;\r | |
980 | }\r | |
dcbdb8bf QS |
981 | else if (UnicodeCollation->StriColl (\r |
982 | UnicodeCollation,\r | |
983 | L"-nonest",\r | |
984 | CurrentArg\r | |
985 | ) == 0) {\r | |
986 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest = TRUE;\r | |
987 | }\r | |
23385d63 BJ |
988 | else if (UnicodeCollation->StriColl (\r |
989 | UnicodeCollation,\r | |
990 | L"-delay",\r | |
991 | CurrentArg\r | |
992 | ) == 0) {\r | |
993 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay = TRUE;\r | |
994 | // Check for optional delay value following "-delay"\r | |
995 | DelayValueStr = gEfiShellParametersProtocol->Argv[LoopVar + 1];\r | |
996 | if (DelayValueStr != NULL){\r | |
997 | if (*DelayValueStr == L':') {\r | |
998 | DelayValueStr++;\r | |
999 | }\r | |
1000 | if (!EFI_ERROR(ShellConvertStringToUint64 (\r | |
1001 | DelayValueStr,\r | |
1002 | &DelayValue,\r | |
1003 | FALSE,\r | |
1004 | FALSE\r | |
1005 | ))) {\r | |
1006 | ShellInfoObject.ShellInitSettings.Delay = (UINTN)DelayValue;\r | |
1007 | LoopVar++;\r | |
1008 | }\r | |
1009 | }\r | |
1010 | } else if (UnicodeCollation->StriColl (\r | |
1011 | UnicodeCollation,\r | |
1012 | L"-_exit",\r | |
1013 | CurrentArg\r | |
1014 | ) == 0) {\r | |
1015 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit = TRUE;\r | |
1016 | } else if (StrnCmp (L"-", CurrentArg, 1) == 0) {\r | |
d08a5464 | 1017 | // Unrecognized option\r |
23385d63 BJ |
1018 | ShellPrintHiiEx(-1, -1, NULL,\r |
1019 | STRING_TOKEN (STR_GEN_PROBLEM),\r | |
1020 | ShellInfoObject.HiiHandle,\r | |
1021 | CurrentArg\r | |
1022 | );\r | |
1023 | return EFI_INVALID_PARAMETER;\r | |
1024 | } else {\r | |
e9d19a80 CP |
1025 | //\r |
1026 | // First argument should be Shell.efi image name\r | |
1027 | //\r | |
1028 | if (LoopVar == 0) {\r | |
1029 | continue;\r | |
1030 | }\r | |
1031 | \r | |
7f79b01e | 1032 | ShellInfoObject.ShellInitSettings.FileName = AllocateCopyPool(StrSize(CurrentArg), CurrentArg);\r |
23385d63 BJ |
1033 | if (ShellInfoObject.ShellInitSettings.FileName == NULL) {\r |
1034 | return (EFI_OUT_OF_RESOURCES);\r | |
1035 | }\r | |
1036 | //\r | |
1037 | // We found `file-name`.\r | |
1038 | //\r | |
1039 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1;\r | |
23385d63 BJ |
1040 | LoopVar++;\r |
1041 | \r | |
1042 | // Add `file-name-options`\r | |
ba71f790 | 1043 | for (Size = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r |
23385d63 BJ |
1044 | ASSERT((ShellInfoObject.ShellInitSettings.FileOptions == NULL && Size == 0) || (ShellInfoObject.ShellInitSettings.FileOptions != NULL));\r |
1045 | StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,\r | |
1046 | &Size,\r | |
1047 | L" ",\r | |
1048 | 0);\r | |
1049 | if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r | |
1050 | SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);\r | |
1051 | return (EFI_OUT_OF_RESOURCES);\r | |
1052 | }\r | |
1053 | StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,\r | |
1054 | &Size,\r | |
1055 | gEfiShellParametersProtocol->Argv[LoopVar],\r | |
1056 | 0);\r | |
1057 | if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r | |
1058 | SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);\r | |
1059 | return (EFI_OUT_OF_RESOURCES);\r | |
a405b86d | 1060 | }\r |
1061 | }\r | |
a405b86d | 1062 | }\r |
1063 | }\r | |
1064 | \r | |
23385d63 | 1065 | // "-nointerrupt" overrides "-delay"\r |
733f138d | 1066 | if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {\r |
1067 | ShellInfoObject.ShellInitSettings.Delay = 0;\r | |
a405b86d | 1068 | }\r |
a405b86d | 1069 | \r |
23385d63 | 1070 | return EFI_SUCCESS;\r |
a405b86d | 1071 | }\r |
1072 | \r | |
1073 | /**\r | |
1074 | Handles all interaction with the default startup script.\r | |
1075 | \r | |
1076 | this will check that the correct command line parameters were passed, handle the delay, and then start running the script.\r | |
1077 | \r | |
1078 | @param ImagePath the path to the image for shell. first place to look for the startup script\r | |
1079 | @param FilePath the path to the file for shell. second place to look for the startup script.\r | |
1080 | \r | |
1081 | @retval EFI_SUCCESS the variable is initialized.\r | |
1082 | **/\r | |
1083 | EFI_STATUS\r | |
1084 | EFIAPI\r | |
1085 | DoStartupScript(\r | |
a308e058 RN |
1086 | IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r |
1087 | IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r | |
a405b86d | 1088 | )\r |
1089 | {\r | |
1090 | EFI_STATUS Status;\r | |
490ce43d | 1091 | EFI_STATUS CalleeStatus;\r |
a405b86d | 1092 | UINTN Delay;\r |
1093 | EFI_INPUT_KEY Key;\r | |
1094 | SHELL_FILE_HANDLE FileHandle;\r | |
1095 | EFI_DEVICE_PATH_PROTOCOL *NewPath;\r | |
1096 | EFI_DEVICE_PATH_PROTOCOL *NamePath;\r | |
1097 | CHAR16 *FileStringPath;\r | |
733f138d | 1098 | CHAR16 *TempSpot;\r |
a405b86d | 1099 | UINTN NewSize;\r |
733f138d | 1100 | CONST CHAR16 *MapName;\r |
a405b86d | 1101 | \r |
1102 | Key.UnicodeChar = CHAR_NULL;\r | |
1103 | Key.ScanCode = 0;\r | |
1104 | FileHandle = NULL;\r | |
1105 | \r | |
1106 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup && ShellInfoObject.ShellInitSettings.FileName != NULL) {\r | |
1107 | //\r | |
1108 | // launch something else instead\r | |
1109 | //\r | |
1110 | NewSize = StrSize(ShellInfoObject.ShellInitSettings.FileName);\r | |
1111 | if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r | |
1112 | NewSize += StrSize(ShellInfoObject.ShellInitSettings.FileOptions) + sizeof(CHAR16);\r | |
1113 | }\r | |
1114 | FileStringPath = AllocateZeroPool(NewSize);\r | |
3c865f20 | 1115 | if (FileStringPath == NULL) {\r |
1116 | return (EFI_OUT_OF_RESOURCES);\r | |
1117 | }\r | |
e75390f0 | 1118 | StrCpyS(FileStringPath, NewSize/sizeof(CHAR16), ShellInfoObject.ShellInitSettings.FileName);\r |
a405b86d | 1119 | if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r |
e75390f0 QS |
1120 | StrnCatS(FileStringPath, NewSize/sizeof(CHAR16), L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r |
1121 | StrnCatS(FileStringPath, NewSize/sizeof(CHAR16), ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r | |
a405b86d | 1122 | }\r |
490ce43d QS |
1123 | Status = RunShellCommand(FileStringPath, &CalleeStatus);\r |
1124 | if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit == TRUE) {\r | |
01e3a976 | 1125 | ShellCommandRegisterExit(gEfiShellProtocol->BatchIsActive(), (UINT64)CalleeStatus);\r |
490ce43d | 1126 | }\r |
a405b86d | 1127 | FreePool(FileStringPath);\r |
1128 | return (Status);\r | |
1129 | \r | |
1130 | }\r | |
1131 | \r | |
1132 | //\r | |
1133 | // for shell level 0 we do no scripts\r | |
1134 | // Without the Startup bit overriding we allow for nostartup to prevent scripts\r | |
1135 | //\r | |
1136 | if ( (PcdGet8(PcdShellSupportLevel) < 1)\r | |
1137 | || (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup)\r | |
1138 | ){\r | |
1139 | return (EFI_SUCCESS);\r | |
1140 | }\r | |
1141 | \r | |
5559a41a | 1142 | gST->ConOut->EnableCursor(gST->ConOut, FALSE);\r |
a405b86d | 1143 | //\r |
1144 | // print out our warning and see if they press a key\r | |
1145 | //\r | |
284e034f | 1146 | for ( Status = EFI_UNSUPPORTED, Delay = ShellInfoObject.ShellInitSettings.Delay\r |
733f138d | 1147 | ; Delay != 0 && EFI_ERROR(Status)\r |
a405b86d | 1148 | ; Delay--\r |
1149 | ){\r | |
284e034f CP |
1150 | ShellPrintHiiEx(0, gST->ConOut->Mode->CursorRow, NULL, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION), ShellInfoObject.HiiHandle, Delay);\r |
1151 | gBS->Stall (1000000);\r | |
733f138d | 1152 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r |
1153 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
1154 | }\r | |
a405b86d | 1155 | }\r |
1156 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle);\r | |
5559a41a | 1157 | gST->ConOut->EnableCursor(gST->ConOut, TRUE);\r |
a405b86d | 1158 | \r |
1159 | //\r | |
1160 | // ESC was pressed\r | |
1161 | //\r | |
1162 | if (Status == EFI_SUCCESS && Key.UnicodeChar == 0 && Key.ScanCode == SCAN_ESC) {\r | |
1163 | return (EFI_SUCCESS);\r | |
1164 | }\r | |
1165 | \r | |
a405b86d | 1166 | //\r |
733f138d | 1167 | // Try the first location (must be file system)\r |
a405b86d | 1168 | //\r |
733f138d | 1169 | MapName = ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath(&ImagePath);\r |
1170 | if (MapName != NULL) {\r | |
1171 | FileStringPath = NULL;\r | |
1172 | NewSize = 0;\r | |
1173 | FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, MapName, 0);\r | |
532691c8 | 1174 | if (FileStringPath == NULL) {\r |
1175 | Status = EFI_OUT_OF_RESOURCES;\r | |
1176 | } else {\r | |
1177 | TempSpot = StrStr(FileStringPath, L";");\r | |
1178 | if (TempSpot != NULL) {\r | |
1179 | *TempSpot = CHAR_NULL;\r | |
1180 | }\r | |
1181 | FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);\r | |
1182 | PathRemoveLastItem(FileStringPath);\r | |
1183 | FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);\r | |
1184 | Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);\r | |
1185 | FreePool(FileStringPath);\r | |
733f138d | 1186 | }\r |
733f138d | 1187 | }\r |
a405b86d | 1188 | if (EFI_ERROR(Status)) {\r |
733f138d | 1189 | NamePath = FileDevicePath (NULL, mStartupScript);\r |
1190 | NewPath = AppendDevicePathNode (ImagePath, NamePath);\r | |
1191 | FreePool(NamePath);\r | |
1192 | \r | |
a405b86d | 1193 | //\r |
733f138d | 1194 | // Try the location\r |
a405b86d | 1195 | //\r |
a405b86d | 1196 | Status = InternalOpenFileDevicePath(NewPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r |
733f138d | 1197 | FreePool(NewPath);\r |
a405b86d | 1198 | }\r |
a405b86d | 1199 | //\r |
1200 | // If we got a file, run it\r | |
1201 | //\r | |
733f138d | 1202 | if (!EFI_ERROR(Status) && FileHandle != NULL) {\r |
a308e058 | 1203 | Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol);\r |
a405b86d | 1204 | ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);\r |
1205 | } else {\r | |
3c865f20 | 1206 | FileStringPath = ShellFindFilePath(mStartupScript);\r |
1207 | if (FileStringPath == NULL) {\r | |
1208 | //\r | |
d08a5464 | 1209 | // we return success since we don't need to have a startup script\r |
3c865f20 | 1210 | //\r |
1211 | Status = EFI_SUCCESS;\r | |
1212 | ASSERT(FileHandle == NULL);\r | |
1213 | } else {\r | |
a308e058 | 1214 | Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);\r |
3c865f20 | 1215 | FreePool(FileStringPath);\r |
1216 | }\r | |
a405b86d | 1217 | }\r |
1218 | \r | |
a405b86d | 1219 | \r |
1220 | return (Status);\r | |
1221 | }\r | |
1222 | \r | |
1223 | /**\r | |
1224 | Function to perform the shell prompt looping. It will do a single prompt,\r | |
1225 | dispatch the result, and then return. It is expected that the caller will\r | |
1226 | call this function in a loop many times.\r | |
1227 | \r | |
1228 | @retval EFI_SUCCESS\r | |
1229 | @retval RETURN_ABORTED\r | |
1230 | **/\r | |
1231 | EFI_STATUS\r | |
1232 | EFIAPI\r | |
1233 | DoShellPrompt (\r | |
1234 | VOID\r | |
1235 | )\r | |
1236 | {\r | |
1237 | UINTN Column;\r | |
1238 | UINTN Row;\r | |
1239 | CHAR16 *CmdLine;\r | |
1240 | CONST CHAR16 *CurDir;\r | |
1241 | UINTN BufferSize;\r | |
1242 | EFI_STATUS Status;\r | |
594e780b | 1243 | LIST_ENTRY OldBufferList;\r |
a405b86d | 1244 | \r |
1245 | CurDir = NULL;\r | |
1246 | \r | |
1247 | //\r | |
1248 | // Get screen setting to decide size of the command line buffer\r | |
1249 | //\r | |
1250 | gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Column, &Row);\r | |
1251 | BufferSize = Column * Row * sizeof (CHAR16);\r | |
1252 | CmdLine = AllocateZeroPool (BufferSize);\r | |
1253 | if (CmdLine == NULL) {\r | |
1254 | return EFI_OUT_OF_RESOURCES;\r | |
1255 | }\r | |
1256 | \r | |
594e780b | 1257 | SaveBufferList(&OldBufferList);\r |
a405b86d | 1258 | CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd");\r |
1259 | \r | |
1260 | //\r | |
1261 | // Prompt for input\r | |
1262 | //\r | |
1263 | gST->ConOut->SetCursorPosition (gST->ConOut, 0, gST->ConOut->Mode->CursorRow);\r | |
1264 | \r | |
1265 | if (CurDir != NULL && StrLen(CurDir) > 1) {\r | |
1266 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);\r | |
1267 | } else {\r | |
1268 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);\r | |
1269 | }\r | |
1270 | \r | |
1271 | //\r | |
1272 | // Read a line from the console\r | |
1273 | //\r | |
1274 | Status = ShellInfoObject.NewEfiShellProtocol->ReadFile(ShellInfoObject.NewShellParametersProtocol->StdIn, &BufferSize, CmdLine);\r | |
1275 | \r | |
1276 | //\r | |
1277 | // Null terminate the string and parse it\r | |
1278 | //\r | |
1279 | if (!EFI_ERROR (Status)) {\r | |
1280 | CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;\r | |
a308e058 | 1281 | Status = RunCommand(CmdLine);\r |
4922715d | 1282 | }\r |
a405b86d | 1283 | \r |
1284 | //\r | |
1285 | // Done with this command\r | |
1286 | //\r | |
594e780b | 1287 | RestoreBufferList(&OldBufferList);\r |
a405b86d | 1288 | FreePool (CmdLine);\r |
1289 | return Status;\r | |
1290 | }\r | |
1291 | \r | |
1292 | /**\r | |
1293 | Add a buffer to the Buffer To Free List for safely returning buffers to other\r | |
1294 | places without risking letting them modify internal shell information.\r | |
1295 | \r | |
1296 | @param Buffer Something to pass to FreePool when the shell is exiting.\r | |
1297 | **/\r | |
1298 | VOID*\r | |
1299 | EFIAPI\r | |
1300 | AddBufferToFreeList(\r | |
1301 | VOID *Buffer\r | |
1302 | )\r | |
1303 | {\r | |
1304 | BUFFER_LIST *BufferListEntry;\r | |
1305 | \r | |
1306 | if (Buffer == NULL) {\r | |
1307 | return (NULL);\r | |
1308 | }\r | |
1309 | \r | |
1310 | BufferListEntry = AllocateZeroPool(sizeof(BUFFER_LIST));\r | |
1311 | ASSERT(BufferListEntry != NULL);\r | |
1312 | BufferListEntry->Buffer = Buffer;\r | |
1313 | InsertTailList(&ShellInfoObject.BufferToFreeList.Link, &BufferListEntry->Link);\r | |
1314 | return (Buffer);\r | |
1315 | }\r | |
1316 | \r | |
14810d6b QS |
1317 | \r |
1318 | /**\r | |
1319 | Create a new buffer list and stores the old one to OldBufferList \r | |
1320 | \r | |
1321 | @param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.\r | |
1322 | **/\r | |
1323 | VOID\r | |
1324 | SaveBufferList (\r | |
1325 | OUT LIST_ENTRY *OldBufferList\r | |
1326 | )\r | |
1327 | {\r | |
1328 | CopyMem (OldBufferList, &ShellInfoObject.BufferToFreeList.Link, sizeof (LIST_ENTRY));\r | |
1329 | InitializeListHead (&ShellInfoObject.BufferToFreeList.Link);\r | |
1330 | }\r | |
1331 | \r | |
1332 | /**\r | |
1333 | Restore previous nodes into BufferToFreeList .\r | |
1334 | \r | |
1335 | @param OldBufferList The temporary list head used to store the nodes in BufferToFreeList.\r | |
1336 | **/\r | |
1337 | VOID\r | |
1338 | RestoreBufferList (\r | |
1339 | IN OUT LIST_ENTRY *OldBufferList\r | |
1340 | )\r | |
1341 | {\r | |
1342 | FreeBufferList (&ShellInfoObject.BufferToFreeList);\r | |
1343 | CopyMem (&ShellInfoObject.BufferToFreeList.Link, OldBufferList, sizeof (LIST_ENTRY));\r | |
1344 | }\r | |
1345 | \r | |
1346 | \r | |
a405b86d | 1347 | /**\r |
1348 | Add a buffer to the Line History List\r | |
1349 | \r | |
1350 | @param Buffer The line buffer to add.\r | |
1351 | **/\r | |
1352 | VOID\r | |
1353 | EFIAPI\r | |
1354 | AddLineToCommandHistory(\r | |
1355 | IN CONST CHAR16 *Buffer\r | |
1356 | )\r | |
1357 | {\r | |
1358 | BUFFER_LIST *Node;\r | |
a4f138a4 QS |
1359 | BUFFER_LIST *Walker;\r |
1360 | UINT16 MaxHistoryCmdCount;\r | |
1361 | UINT16 Count;\r | |
dcbdb8bf | 1362 | \r |
a4f138a4 QS |
1363 | Count = 0;\r |
1364 | MaxHistoryCmdCount = PcdGet16(PcdShellMaxHistoryCommandCount);\r | |
1365 | \r | |
1366 | if (MaxHistoryCmdCount == 0) {\r | |
1367 | return ;\r | |
1368 | }\r | |
1369 | \r | |
a405b86d | 1370 | \r |
1371 | Node = AllocateZeroPool(sizeof(BUFFER_LIST));\r | |
1372 | ASSERT(Node != NULL);\r | |
7f79b01e | 1373 | Node->Buffer = AllocateCopyPool(StrSize(Buffer), Buffer);\r |
a405b86d | 1374 | ASSERT(Node->Buffer != NULL);\r |
a405b86d | 1375 | \r |
a4f138a4 QS |
1376 | for ( Walker = (BUFFER_LIST*)GetFirstNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link)\r |
1377 | ; !IsNull(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Walker->Link)\r | |
1378 | ; Walker = (BUFFER_LIST*)GetNextNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Walker->Link)\r | |
1379 | ){\r | |
1380 | Count++;\r | |
1381 | }\r | |
1382 | if (Count < MaxHistoryCmdCount){\r | |
1383 | InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r | |
1384 | } else {\r | |
1385 | Walker = (BUFFER_LIST*)GetFirstNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link);\r | |
1386 | RemoveEntryList(&Walker->Link);\r | |
1387 | if (Walker->Buffer != NULL) {\r | |
1388 | FreePool(Walker->Buffer);\r | |
1389 | }\r | |
1390 | FreePool(Walker);\r | |
1391 | InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r | |
1392 | }\r | |
a405b86d | 1393 | }\r |
1394 | \r | |
1395 | /**\r | |
1396 | Checks if a string is an alias for another command. If yes, then it replaces the alias name\r | |
1397 | with the correct command name.\r | |
1398 | \r | |
4ff7e37b ED |
1399 | @param[in, out] CommandString Upon entry the potential alias. Upon return the\r |
1400 | command name if it was an alias. If it was not\r | |
1401 | an alias it will be unchanged. This function may\r | |
1402 | change the buffer to fit the command name.\r | |
a405b86d | 1403 | \r |
1404 | @retval EFI_SUCCESS The name was changed.\r | |
1405 | @retval EFI_SUCCESS The name was not an alias.\r | |
1406 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
1407 | **/\r | |
1408 | EFI_STATUS\r | |
1409 | EFIAPI\r | |
1410 | ShellConvertAlias(\r | |
1411 | IN OUT CHAR16 **CommandString\r | |
1412 | )\r | |
1413 | {\r | |
1414 | CONST CHAR16 *NewString;\r | |
1415 | \r | |
1416 | NewString = ShellInfoObject.NewEfiShellProtocol->GetAlias(*CommandString, NULL);\r | |
1417 | if (NewString == NULL) {\r | |
1418 | return (EFI_SUCCESS);\r | |
1419 | }\r | |
1420 | FreePool(*CommandString);\r | |
7f79b01e | 1421 | *CommandString = AllocateCopyPool(StrSize(NewString), NewString);\r |
a405b86d | 1422 | if (*CommandString == NULL) {\r |
1423 | return (EFI_OUT_OF_RESOURCES);\r | |
1424 | }\r | |
a405b86d | 1425 | return (EFI_SUCCESS);\r |
1426 | }\r | |
1427 | \r | |
d5b5440b JC |
1428 | /**\r |
1429 | This function will eliminate unreplaced (and therefore non-found) environment variables.\r | |
1430 | \r | |
1431 | @param[in,out] CmdLine The command line to update.\r | |
1432 | **/\r | |
1433 | EFI_STATUS\r | |
1434 | EFIAPI\r | |
1435 | StripUnreplacedEnvironmentVariables(\r | |
1436 | IN OUT CHAR16 *CmdLine\r | |
1437 | )\r | |
1438 | {\r | |
1439 | CHAR16 *FirstPercent;\r | |
1440 | CHAR16 *FirstQuote;\r | |
1441 | CHAR16 *SecondPercent;\r | |
1442 | CHAR16 *SecondQuote;\r | |
1443 | CHAR16 *CurrentLocator;\r | |
1444 | \r | |
1445 | for (CurrentLocator = CmdLine ; CurrentLocator != NULL ; ) {\r | |
a95cf8f0 JC |
1446 | FirstQuote = FindNextInstance(CurrentLocator, L"\"", TRUE);\r |
1447 | FirstPercent = FindNextInstance(CurrentLocator, L"%", TRUE);\r | |
1448 | SecondPercent = FirstPercent!=NULL?FindNextInstance(FirstPercent+1, L"%", TRUE):NULL;\r | |
d5b5440b JC |
1449 | if (FirstPercent == NULL || SecondPercent == NULL) {\r |
1450 | //\r | |
d08a5464 | 1451 | // If we ever don't have 2 % we are done.\r |
d5b5440b JC |
1452 | //\r |
1453 | break;\r | |
1454 | }\r | |
1455 | \r | |
fdd52bde | 1456 | if (FirstQuote!= NULL && FirstQuote < FirstPercent) {\r |
a95cf8f0 | 1457 | SecondQuote = FindNextInstance(FirstQuote+1, L"\"", TRUE);\r |
d5b5440b JC |
1458 | //\r |
1459 | // Quote is first found\r | |
1460 | //\r | |
a95cf8f0 | 1461 | \r |
d5b5440b JC |
1462 | if (SecondQuote < FirstPercent) {\r |
1463 | //\r | |
1464 | // restart after the pair of "\r | |
1465 | //\r | |
1466 | CurrentLocator = SecondQuote + 1;\r | |
1467 | } else /* FirstPercent < SecondQuote */{\r | |
1468 | //\r | |
1469 | // Restart on the first percent\r | |
1470 | //\r | |
1471 | CurrentLocator = FirstPercent;\r | |
1472 | }\r | |
1473 | continue;\r | |
1474 | }\r | |
fdd52bde | 1475 | \r |
fe8ec3dd | 1476 | if (FirstQuote == NULL || SecondPercent < FirstQuote) {\r |
42435671 QS |
1477 | if (IsValidEnvironmentVariableName(FirstPercent, SecondPercent)) {\r |
1478 | //\r | |
1479 | // We need to remove from FirstPercent to SecondPercent\r | |
1480 | //\r | |
1481 | CopyMem(FirstPercent, SecondPercent + 1, StrSize(SecondPercent + 1));\r | |
1482 | //\r | |
d08a5464 | 1483 | // don't need to update the locator. both % characters are gone.\r |
42435671 QS |
1484 | //\r |
1485 | } else {\r | |
1486 | CurrentLocator = SecondPercent + 1;\r | |
1487 | }\r | |
d5b5440b JC |
1488 | continue;\r |
1489 | }\r | |
d5b5440b JC |
1490 | CurrentLocator = FirstQuote;\r |
1491 | }\r | |
1492 | return (EFI_SUCCESS);\r | |
1493 | }\r | |
1494 | \r | |
a405b86d | 1495 | /**\r |
1496 | Function allocates a new command line and replaces all instances of environment\r | |
1497 | variable names that are correctly preset to their values.\r | |
1498 | \r | |
1499 | If the return value is not NULL the memory must be caller freed.\r | |
1500 | \r | |
1501 | @param[in] OriginalCommandLine The original command line\r | |
1502 | \r | |
d08a5464 | 1503 | @retval NULL An error occurred.\r |
a405b86d | 1504 | @return The new command line with no environment variables present.\r |
1505 | **/\r | |
1506 | CHAR16*\r | |
1507 | EFIAPI\r | |
1508 | ShellConvertVariables (\r | |
1509 | IN CONST CHAR16 *OriginalCommandLine\r | |
1510 | )\r | |
1511 | {\r | |
1512 | CONST CHAR16 *MasterEnvList;\r | |
1513 | UINTN NewSize;\r | |
1514 | CHAR16 *NewCommandLine1;\r | |
1515 | CHAR16 *NewCommandLine2;\r | |
1516 | CHAR16 *Temp;\r | |
1517 | UINTN ItemSize;\r | |
1518 | CHAR16 *ItemTemp;\r | |
1519 | SCRIPT_FILE *CurrentScriptFile;\r | |
1520 | ALIAS_LIST *AliasListNode;\r | |
1521 | \r | |
1522 | ASSERT(OriginalCommandLine != NULL);\r | |
1523 | \r | |
1524 | ItemSize = 0;\r | |
1525 | NewSize = StrSize(OriginalCommandLine);\r | |
1526 | CurrentScriptFile = ShellCommandGetCurrentScriptFile();\r | |
1527 | Temp = NULL;\r | |
1528 | \r | |
1529 | ///@todo update this to handle the %0 - %9 for scripting only (borrow from line 1256 area) ? ? ?\r | |
1530 | \r | |
1531 | //\r | |
1532 | // calculate the size required for the post-conversion string...\r | |
1533 | //\r | |
1534 | if (CurrentScriptFile != NULL) {\r | |
1535 | for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)\r | |
1536 | ; !IsNull(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r | |
1537 | ; AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r | |
1538 | ){\r | |
1539 | for (Temp = StrStr(OriginalCommandLine, AliasListNode->Alias)\r | |
1540 | ; Temp != NULL\r | |
1541 | ; Temp = StrStr(Temp+1, AliasListNode->Alias)\r | |
1542 | ){\r | |
1543 | //\r | |
d08a5464 | 1544 | // we need a preceding and if there is space no ^ preceding (if no space ignore)\r |
a405b86d | 1545 | //\r |
1546 | if ((((Temp-OriginalCommandLine)>2) && *(Temp-2) != L'^') || ((Temp-OriginalCommandLine)<=2)) {\r | |
1547 | NewSize += StrSize(AliasListNode->CommandString);\r | |
1548 | }\r | |
1549 | }\r | |
1550 | }\r | |
1551 | }\r | |
1552 | \r | |
1553 | for (MasterEnvList = EfiShellGetEnv(NULL)\r | |
1554 | ; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL\r | |
1555 | ; MasterEnvList += StrLen(MasterEnvList) + 1\r | |
1556 | ){\r | |
1557 | if (StrSize(MasterEnvList) > ItemSize) {\r | |
1558 | ItemSize = StrSize(MasterEnvList);\r | |
1559 | }\r | |
1560 | for (Temp = StrStr(OriginalCommandLine, MasterEnvList)\r | |
1561 | ; Temp != NULL\r | |
1562 | ; Temp = StrStr(Temp+1, MasterEnvList)\r | |
1563 | ){\r | |
1564 | //\r | |
d08a5464 | 1565 | // we need a preceding and following % and if there is space no ^ preceding (if no space ignore)\r |
a405b86d | 1566 | //\r |
1567 | if (*(Temp-1) == L'%' && *(Temp+StrLen(MasterEnvList)) == L'%' &&\r | |
1568 | ((((Temp-OriginalCommandLine)>2) && *(Temp-2) != L'^') || ((Temp-OriginalCommandLine)<=2))) {\r | |
1569 | NewSize+=StrSize(EfiShellGetEnv(MasterEnvList));\r | |
1570 | }\r | |
1571 | }\r | |
1572 | }\r | |
1573 | \r | |
a405b86d | 1574 | //\r |
1575 | // now do the replacements...\r | |
1576 | //\r | |
7f79b01e | 1577 | NewCommandLine1 = AllocateCopyPool(NewSize, OriginalCommandLine);\r |
a405b86d | 1578 | NewCommandLine2 = AllocateZeroPool(NewSize);\r |
1579 | ItemTemp = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));\r | |
3c865f20 | 1580 | if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) {\r |
1581 | SHELL_FREE_NON_NULL(NewCommandLine1);\r | |
1582 | SHELL_FREE_NON_NULL(NewCommandLine2);\r | |
1583 | SHELL_FREE_NON_NULL(ItemTemp);\r | |
1584 | return (NULL);\r | |
1585 | }\r | |
a405b86d | 1586 | for (MasterEnvList = EfiShellGetEnv(NULL)\r |
7f79b01e | 1587 | ; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL\r |
a405b86d | 1588 | ; MasterEnvList += StrLen(MasterEnvList) + 1\r |
1589 | ){\r | |
e75390f0 QS |
1590 | StrCpyS( ItemTemp, \r |
1591 | ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)), \r | |
1592 | L"%"\r | |
1593 | );\r | |
1594 | StrCatS( ItemTemp, \r | |
1595 | ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)), \r | |
1596 | MasterEnvList\r | |
1597 | );\r | |
1598 | StrCatS( ItemTemp, \r | |
1599 | ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)), \r | |
1600 | L"%"\r | |
1601 | );\r | |
a405b86d | 1602 | ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);\r |
e75390f0 | 1603 | StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);\r |
a405b86d | 1604 | }\r |
1605 | if (CurrentScriptFile != NULL) {\r | |
1606 | for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)\r | |
1607 | ; !IsNull(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r | |
1608 | ; AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r | |
1609 | ){\r | |
1610 | ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);\r | |
e75390f0 | 1611 | StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);\r |
a405b86d | 1612 | }\r |
1613 | }\r | |
1614 | \r | |
fdd52bde | 1615 | //\r |
d08a5464 | 1616 | // Remove non-existent environment variables\r |
fdd52bde JC |
1617 | //\r |
1618 | StripUnreplacedEnvironmentVariables(NewCommandLine1);\r | |
1619 | \r | |
df07baea JC |
1620 | //\r |
1621 | // Now cleanup any straggler intentionally ignored "%" characters\r | |
1622 | //\r | |
1623 | ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);\r | |
e75390f0 | 1624 | StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);\r |
df07baea | 1625 | \r |
a405b86d | 1626 | FreePool(NewCommandLine2);\r |
1627 | FreePool(ItemTemp);\r | |
1628 | \r | |
1629 | return (NewCommandLine1);\r | |
1630 | }\r | |
1631 | \r | |
1632 | /**\r | |
1633 | Internal function to run a command line with pipe usage.\r | |
1634 | \r | |
1635 | @param[in] CmdLine The pointer to the command line.\r | |
1636 | @param[in] StdIn The pointer to the Standard input.\r | |
1637 | @param[in] StdOut The pointer to the Standard output.\r | |
1638 | \r | |
1639 | @retval EFI_SUCCESS The split command is executed successfully.\r | |
1640 | @retval other Some error occurs when executing the split command.\r | |
1641 | **/\r | |
1642 | EFI_STATUS\r | |
1643 | EFIAPI\r | |
1644 | RunSplitCommand(\r | |
1645 | IN CONST CHAR16 *CmdLine,\r | |
1646 | IN SHELL_FILE_HANDLE *StdIn,\r | |
a308e058 | 1647 | IN SHELL_FILE_HANDLE *StdOut\r |
a405b86d | 1648 | )\r |
1649 | {\r | |
1650 | EFI_STATUS Status;\r | |
1651 | CHAR16 *NextCommandLine;\r | |
1652 | CHAR16 *OurCommandLine;\r | |
1653 | UINTN Size1;\r | |
1654 | UINTN Size2;\r | |
1655 | SPLIT_LIST *Split;\r | |
1656 | SHELL_FILE_HANDLE *TempFileHandle;\r | |
1657 | BOOLEAN Unicode;\r | |
1658 | \r | |
1659 | ASSERT(StdOut == NULL);\r | |
1660 | \r | |
1661 | ASSERT(StrStr(CmdLine, L"|") != NULL);\r | |
1662 | \r | |
1663 | Status = EFI_SUCCESS;\r | |
1664 | NextCommandLine = NULL;\r | |
1665 | OurCommandLine = NULL;\r | |
1666 | Size1 = 0;\r | |
1667 | Size2 = 0;\r | |
1668 | \r | |
1669 | NextCommandLine = StrnCatGrow(&NextCommandLine, &Size1, StrStr(CmdLine, L"|")+1, 0);\r | |
1670 | OurCommandLine = StrnCatGrow(&OurCommandLine , &Size2, CmdLine , StrStr(CmdLine, L"|") - CmdLine);\r | |
532691c8 | 1671 | \r |
1672 | if (NextCommandLine == NULL || OurCommandLine == NULL) {\r | |
1673 | SHELL_FREE_NON_NULL(OurCommandLine);\r | |
1674 | SHELL_FREE_NON_NULL(NextCommandLine);\r | |
1675 | return (EFI_OUT_OF_RESOURCES);\r | |
19216573 | 1676 | } else if (StrStr(OurCommandLine, L"|") != NULL || Size1 == 0 || Size2 == 0) {\r |
1677 | SHELL_FREE_NON_NULL(OurCommandLine);\r | |
1678 | SHELL_FREE_NON_NULL(NextCommandLine);\r | |
1679 | return (EFI_INVALID_PARAMETER);\r | |
a5382ce0 QS |
1680 | } else if (NextCommandLine[0] == L'a' &&\r |
1681 | (NextCommandLine[1] == L' ' || NextCommandLine[1] == CHAR_NULL)\r | |
1682 | ){\r | |
a405b86d | 1683 | CopyMem(NextCommandLine, NextCommandLine+1, StrSize(NextCommandLine) - sizeof(NextCommandLine[0]));\r |
a5382ce0 QS |
1684 | while (NextCommandLine[0] == L' ') {\r |
1685 | CopyMem(NextCommandLine, NextCommandLine+1, StrSize(NextCommandLine) - sizeof(NextCommandLine[0]));\r | |
1686 | }\r | |
1687 | if (NextCommandLine[0] == CHAR_NULL) {\r | |
1688 | SHELL_FREE_NON_NULL(OurCommandLine);\r | |
1689 | SHELL_FREE_NON_NULL(NextCommandLine);\r | |
1690 | return (EFI_INVALID_PARAMETER);\r | |
1691 | }\r | |
a405b86d | 1692 | Unicode = FALSE;\r |
1693 | } else {\r | |
1694 | Unicode = TRUE;\r | |
1695 | }\r | |
1696 | \r | |
1697 | \r | |
1698 | //\r | |
1699 | // make a SPLIT_LIST item and add to list\r | |
1700 | //\r | |
1701 | Split = AllocateZeroPool(sizeof(SPLIT_LIST));\r | |
1702 | ASSERT(Split != NULL);\r | |
1703 | Split->SplitStdIn = StdIn;\r | |
1704 | Split->SplitStdOut = ConvertEfiFileProtocolToShellHandle(CreateFileInterfaceMem(Unicode), NULL);\r | |
1705 | ASSERT(Split->SplitStdOut != NULL);\r | |
1706 | InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link);\r | |
1707 | \r | |
a308e058 | 1708 | Status = RunCommand(OurCommandLine);\r |
a405b86d | 1709 | \r |
1710 | //\r | |
1711 | // move the output from the first to the in to the second.\r | |
1712 | //\r | |
1713 | TempFileHandle = Split->SplitStdOut;\r | |
1714 | if (Split->SplitStdIn == StdIn) {\r | |
1715 | Split->SplitStdOut = NULL;\r | |
1716 | } else {\r | |
1717 | Split->SplitStdOut = Split->SplitStdIn;\r | |
1718 | }\r | |
1719 | Split->SplitStdIn = TempFileHandle;\r | |
1720 | ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0);\r | |
1721 | \r | |
1722 | if (!EFI_ERROR(Status)) {\r | |
a308e058 | 1723 | Status = RunCommand(NextCommandLine);\r |
a405b86d | 1724 | }\r |
1725 | \r | |
1726 | //\r | |
1727 | // remove the top level from the ScriptList\r | |
1728 | //\r | |
1729 | ASSERT((SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link) == Split);\r | |
1730 | RemoveEntryList(&Split->Link);\r | |
1731 | \r | |
1732 | //\r | |
1733 | // Note that the original StdIn is now the StdOut...\r | |
1734 | //\r | |
1735 | if (Split->SplitStdOut != NULL && Split->SplitStdOut != StdIn) {\r | |
1736 | ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdOut));\r | |
1737 | }\r | |
1738 | if (Split->SplitStdIn != NULL) {\r | |
1739 | ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn));\r | |
1740 | }\r | |
1741 | \r | |
1742 | FreePool(Split);\r | |
1743 | FreePool(NextCommandLine);\r | |
1744 | FreePool(OurCommandLine);\r | |
1745 | \r | |
1746 | return (Status);\r | |
1747 | }\r | |
1748 | \r | |
1ef61d03 JC |
1749 | /**\r |
1750 | Take the original command line, substitute any variables, free \r | |
51429264 | 1751 | the original string, return the modified copy.\r |
1ef61d03 | 1752 | \r |
51429264 | 1753 | @param[in] CmdLine pointer to the command line to update.\r |
1ef61d03 | 1754 | \r |
51429264 SQ |
1755 | @retval EFI_SUCCESS the function was successful.\r |
1756 | @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r | |
1ef61d03 JC |
1757 | **/\r |
1758 | EFI_STATUS\r | |
1759 | EFIAPI\r | |
1760 | ShellSubstituteVariables(\r | |
1761 | IN CHAR16 **CmdLine\r | |
1762 | )\r | |
1763 | {\r | |
1764 | CHAR16 *NewCmdLine;\r | |
1765 | NewCmdLine = ShellConvertVariables(*CmdLine);\r | |
1766 | SHELL_FREE_NON_NULL(*CmdLine);\r | |
1767 | if (NewCmdLine == NULL) {\r | |
1768 | return (EFI_OUT_OF_RESOURCES);\r | |
1769 | }\r | |
1770 | *CmdLine = NewCmdLine;\r | |
1771 | return (EFI_SUCCESS);\r | |
1772 | }\r | |
1773 | \r | |
ca53c0af JC |
1774 | /**\r |
1775 | Take the original command line, substitute any alias in the first group of space delimited characters, free \r | |
51429264 | 1776 | the original string, return the modified copy.\r |
ca53c0af | 1777 | \r |
51429264 | 1778 | @param[in] CmdLine pointer to the command line to update.\r |
ca53c0af | 1779 | \r |
51429264 SQ |
1780 | @retval EFI_SUCCESS the function was successful.\r |
1781 | @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r | |
ca53c0af JC |
1782 | **/\r |
1783 | EFI_STATUS\r | |
1784 | EFIAPI\r | |
1785 | ShellSubstituteAliases(\r | |
1786 | IN CHAR16 **CmdLine\r | |
1787 | )\r | |
1788 | {\r | |
1789 | CHAR16 *NewCmdLine;\r | |
1790 | CHAR16 *CommandName;\r | |
1791 | EFI_STATUS Status;\r | |
1792 | UINTN PostAliasSize;\r | |
1793 | ASSERT(CmdLine != NULL);\r | |
1794 | ASSERT(*CmdLine!= NULL);\r | |
1795 | \r | |
1796 | \r | |
1797 | CommandName = NULL;\r | |
1798 | if (StrStr((*CmdLine), L" ") == NULL){\r | |
1799 | StrnCatGrow(&CommandName, NULL, (*CmdLine), 0);\r | |
1800 | } else {\r | |
1801 | StrnCatGrow(&CommandName, NULL, (*CmdLine), StrStr((*CmdLine), L" ") - (*CmdLine));\r | |
1802 | }\r | |
1803 | \r | |
1804 | //\r | |
1805 | // This cannot happen 'inline' since the CmdLine can need extra space.\r | |
1806 | //\r | |
1807 | NewCmdLine = NULL;\r | |
1808 | if (!ShellCommandIsCommandOnList(CommandName)) {\r | |
1809 | //\r | |
1810 | // Convert via alias\r | |
1811 | //\r | |
1812 | Status = ShellConvertAlias(&CommandName);\r | |
1813 | if (EFI_ERROR(Status)){\r | |
1814 | return (Status);\r | |
1815 | }\r | |
1816 | PostAliasSize = 0;\r | |
1817 | NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, CommandName, 0);\r | |
1818 | if (NewCmdLine == NULL) {\r | |
1819 | SHELL_FREE_NON_NULL(CommandName);\r | |
1820 | SHELL_FREE_NON_NULL(*CmdLine);\r | |
1821 | return (EFI_OUT_OF_RESOURCES);\r | |
1822 | }\r | |
1823 | NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, StrStr((*CmdLine), L" "), 0);\r | |
1824 | if (NewCmdLine == NULL) {\r | |
1825 | SHELL_FREE_NON_NULL(CommandName);\r | |
1826 | SHELL_FREE_NON_NULL(*CmdLine);\r | |
1827 | return (EFI_OUT_OF_RESOURCES);\r | |
1828 | }\r | |
1829 | } else {\r | |
1830 | NewCmdLine = StrnCatGrow(&NewCmdLine, NULL, (*CmdLine), 0);\r | |
1831 | }\r | |
1832 | \r | |
1833 | SHELL_FREE_NON_NULL(*CmdLine);\r | |
1834 | SHELL_FREE_NON_NULL(CommandName);\r | |
1835 | \r | |
1836 | //\r | |
1837 | // re-assign the passed in double pointer to point to our newly allocated buffer\r | |
1838 | //\r | |
1839 | *CmdLine = NewCmdLine;\r | |
1840 | \r | |
1841 | return (EFI_SUCCESS);\r | |
1842 | }\r | |
1843 | \r | |
6ba2921d JC |
1844 | /**\r |
1845 | Takes the Argv[0] part of the command line and determine the meaning of it.\r | |
e7831c90 | 1846 | \r |
51429264 | 1847 | @param[in] CmdName pointer to the command line to update.\r |
e7831c90 | 1848 | \r |
51429264 SQ |
1849 | @retval Internal_Command The name is an internal command.\r |
1850 | @retval File_Sys_Change the name is a file system change.\r | |
1851 | @retval Script_File_Name the name is a NSH script file.\r | |
1852 | @retval Unknown_Invalid the name is unknown.\r | |
1853 | @retval Efi_Application the name is an application (.EFI).\r | |
6ba2921d JC |
1854 | **/\r |
1855 | SHELL_OPERATION_TYPES\r | |
1856 | EFIAPI\r | |
1857 | GetOperationType(\r | |
1858 | IN CONST CHAR16 *CmdName\r | |
1859 | )\r | |
1860 | {\r | |
1861 | CHAR16* FileWithPath;\r | |
1862 | CONST CHAR16* TempLocation;\r | |
1863 | CONST CHAR16* TempLocation2;\r | |
1864 | \r | |
1865 | FileWithPath = NULL;\r | |
1866 | //\r | |
1867 | // test for an internal command.\r | |
1868 | //\r | |
1869 | if (ShellCommandIsCommandOnList(CmdName)) {\r | |
51429264 | 1870 | return (Internal_Command);\r |
6ba2921d JC |
1871 | }\r |
1872 | \r | |
1873 | //\r | |
fc4c7b30 | 1874 | // Test for file system change request. anything ending with first : and cant have spaces.\r |
6ba2921d JC |
1875 | //\r |
1876 | if (CmdName[(StrLen(CmdName)-1)] == L':') {\r | |
fc4c7b30 JC |
1877 | if ( StrStr(CmdName, L" ") != NULL \r |
1878 | || StrLen(StrStr(CmdName, L":")) > 1\r | |
1879 | ) {\r | |
51429264 | 1880 | return (Unknown_Invalid);\r |
6ba2921d | 1881 | }\r |
51429264 | 1882 | return (File_Sys_Change);\r |
6ba2921d JC |
1883 | }\r |
1884 | \r | |
1885 | //\r | |
1886 | // Test for a file\r | |
1887 | //\r | |
1888 | if ((FileWithPath = ShellFindFilePathEx(CmdName, mExecutableExtensions)) != NULL) {\r | |
1889 | //\r | |
1890 | // See if that file has a script file extension\r | |
1891 | //\r | |
1892 | if (StrLen(FileWithPath) > 4) {\r | |
1893 | TempLocation = FileWithPath+StrLen(FileWithPath)-4;\r | |
1894 | TempLocation2 = mScriptExtension;\r | |
1895 | if (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0) {\r | |
1896 | SHELL_FREE_NON_NULL(FileWithPath);\r | |
51429264 | 1897 | return (Script_File_Name);\r |
6ba2921d JC |
1898 | }\r |
1899 | }\r | |
1900 | \r | |
1901 | //\r | |
1902 | // Was a file, but not a script. we treat this as an application.\r | |
1903 | //\r | |
1904 | SHELL_FREE_NON_NULL(FileWithPath);\r | |
51429264 | 1905 | return (Efi_Application);\r |
6ba2921d JC |
1906 | }\r |
1907 | \r | |
1908 | SHELL_FREE_NON_NULL(FileWithPath);\r | |
1909 | //\r | |
1910 | // No clue what this is... return invalid flag...\r | |
1911 | //\r | |
51429264 | 1912 | return (Unknown_Invalid);\r |
6ba2921d JC |
1913 | }\r |
1914 | \r | |
de4ebdcf SQ |
1915 | /**\r |
1916 | Determine if the first item in a command line is valid.\r | |
1917 | \r | |
1918 | @param[in] CmdLine The command line to parse.\r | |
1919 | \r | |
1920 | @retval EFI_SUCCESS The item is valid.\r | |
1921 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
1922 | @retval EFI_NOT_FOUND The operation type is unknown or invalid.\r | |
1923 | **/\r | |
6bd64463 JC |
1924 | EFI_STATUS \r |
1925 | EFIAPI\r | |
1926 | IsValidSplit(\r | |
1927 | IN CONST CHAR16 *CmdLine\r | |
1928 | )\r | |
1929 | {\r | |
1930 | CHAR16 *Temp;\r | |
1931 | CHAR16 *FirstParameter;\r | |
1932 | CHAR16 *TempWalker;\r | |
1933 | EFI_STATUS Status;\r | |
1934 | \r | |
1935 | Temp = NULL;\r | |
1936 | \r | |
1937 | Temp = StrnCatGrow(&Temp, NULL, CmdLine, 0);\r | |
1938 | if (Temp == NULL) {\r | |
1939 | return (EFI_OUT_OF_RESOURCES);\r | |
1940 | }\r | |
1941 | \r | |
1942 | FirstParameter = StrStr(Temp, L"|");\r | |
1943 | if (FirstParameter != NULL) {\r | |
1944 | *FirstParameter = CHAR_NULL;\r | |
1945 | }\r | |
1946 | \r | |
1947 | FirstParameter = NULL;\r | |
1948 | \r | |
1949 | //\r | |
1950 | // Process the command line\r | |
1951 | //\r | |
1952 | Status = ProcessCommandLineToFinal(&Temp);\r | |
1953 | \r | |
1954 | if (!EFI_ERROR(Status)) {\r | |
1955 | FirstParameter = AllocateZeroPool(StrSize(CmdLine));\r | |
1956 | if (FirstParameter == NULL) {\r | |
1957 | SHELL_FREE_NON_NULL(Temp);\r | |
1958 | return (EFI_OUT_OF_RESOURCES);\r | |
1959 | }\r | |
1960 | TempWalker = (CHAR16*)Temp;\r | |
d1c275c6 | 1961 | if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CmdLine), TRUE))) {\r |
14030c5c JC |
1962 | if (GetOperationType(FirstParameter) == Unknown_Invalid) {\r |
1963 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r | |
1964 | SetLastError(SHELL_NOT_FOUND);\r | |
1965 | Status = EFI_NOT_FOUND;\r | |
1966 | }\r | |
6bd64463 JC |
1967 | }\r |
1968 | }\r | |
1969 | \r | |
1970 | SHELL_FREE_NON_NULL(Temp);\r | |
1971 | SHELL_FREE_NON_NULL(FirstParameter);\r | |
1972 | return Status;\r | |
1973 | }\r | |
1974 | \r | |
1975 | /**\r | |
51429264 | 1976 | Determine if a command line contains with a split contains only valid commands.\r |
6bd64463 JC |
1977 | \r |
1978 | @param[in] CmdLine The command line to parse.\r | |
1979 | \r | |
1980 | @retval EFI_SUCCESS CmdLine has only valid commands, application, or has no split.\r | |
1981 | @retval EFI_ABORTED CmdLine has at least one invalid command or application.\r | |
1982 | **/\r | |
1983 | EFI_STATUS\r | |
1984 | EFIAPI\r | |
1985 | VerifySplit(\r | |
1986 | IN CONST CHAR16 *CmdLine\r | |
1987 | )\r | |
1988 | {\r | |
1989 | CONST CHAR16 *TempSpot;\r | |
1990 | EFI_STATUS Status;\r | |
1991 | \r | |
1992 | //\r | |
a5382ce0 | 1993 | // If this was the only item, then get out\r |
6bd64463 | 1994 | //\r |
a5382ce0 QS |
1995 | if (!ContainsSplit(CmdLine)) {\r |
1996 | return (EFI_SUCCESS);\r | |
6bd64463 JC |
1997 | }\r |
1998 | \r | |
1999 | //\r | |
a5382ce0 | 2000 | // Verify up to the pipe or end character\r |
6bd64463 | 2001 | //\r |
a5382ce0 QS |
2002 | Status = IsValidSplit(CmdLine);\r |
2003 | if (EFI_ERROR(Status)) {\r | |
2004 | return (Status);\r | |
6bd64463 JC |
2005 | }\r |
2006 | \r | |
2007 | //\r | |
2008 | // recurse to verify the next item\r | |
2009 | //\r | |
00534bc3 | 2010 | TempSpot = FindFirstCharacter(CmdLine, L"|", L'^') + 1;\r |
a5382ce0 QS |
2011 | if (*TempSpot == L'a' && \r |
2012 | (*(TempSpot + 1) == L' ' || *(TempSpot + 1) == CHAR_NULL)\r | |
2013 | ) {\r | |
2014 | // If it's an ASCII pipe '|a'\r | |
2015 | TempSpot += 1;\r | |
2016 | }\r | |
2017 | \r | |
6bd64463 JC |
2018 | return (VerifySplit(TempSpot));\r |
2019 | }\r | |
2020 | \r | |
680db511 | 2021 | /**\r |
e7831c90 JC |
2022 | Process a split based operation.\r |
2023 | \r | |
a308e058 | 2024 | @param[in] CmdLine pointer to the command line to process\r |
e7831c90 JC |
2025 | \r |
2026 | @retval EFI_SUCCESS The operation was successful\r | |
d08a5464 | 2027 | @return an error occurred.\r |
680db511 JC |
2028 | **/\r |
2029 | EFI_STATUS\r | |
2030 | EFIAPI\r | |
2031 | ProcessNewSplitCommandLine(\r | |
a308e058 | 2032 | IN CONST CHAR16 *CmdLine\r |
680db511 JC |
2033 | )\r |
2034 | {\r | |
2035 | SPLIT_LIST *Split;\r | |
2036 | EFI_STATUS Status;\r | |
2037 | \r | |
6bd64463 JC |
2038 | Status = VerifySplit(CmdLine);\r |
2039 | if (EFI_ERROR(Status)) {\r | |
2040 | return (Status);\r | |
2041 | }\r | |
2042 | \r | |
680db511 JC |
2043 | Split = NULL;\r |
2044 | \r | |
2045 | //\r | |
2046 | // are we in an existing split???\r | |
2047 | //\r | |
2048 | if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {\r | |
2049 | Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);\r | |
2050 | }\r | |
2051 | \r | |
2052 | if (Split == NULL) {\r | |
a308e058 | 2053 | Status = RunSplitCommand(CmdLine, NULL, NULL);\r |
680db511 | 2054 | } else {\r |
a308e058 | 2055 | Status = RunSplitCommand(CmdLine, Split->SplitStdIn, Split->SplitStdOut);\r |
680db511 JC |
2056 | }\r |
2057 | if (EFI_ERROR(Status)) {\r | |
2058 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine);\r | |
2059 | }\r | |
2060 | return (Status);\r | |
2061 | }\r | |
daf70584 JC |
2062 | \r |
2063 | /**\r | |
51429264 | 2064 | Handle a request to change the current file system.\r |
daf70584 | 2065 | \r |
51429264 | 2066 | @param[in] CmdLine The passed in command line.\r |
daf70584 | 2067 | \r |
51429264 | 2068 | @retval EFI_SUCCESS The operation was successful.\r |
daf70584 JC |
2069 | **/\r |
2070 | EFI_STATUS\r | |
2071 | EFIAPI\r | |
2072 | ChangeMappedDrive(\r | |
2073 | IN CONST CHAR16 *CmdLine\r | |
2074 | )\r | |
2075 | {\r | |
2076 | EFI_STATUS Status;\r | |
2077 | Status = EFI_SUCCESS;\r | |
2078 | \r | |
2079 | //\r | |
2080 | // make sure we are the right operation\r | |
2081 | //\r | |
2082 | ASSERT(CmdLine[(StrLen(CmdLine)-1)] == L':' && StrStr(CmdLine, L" ") == NULL);\r | |
2083 | \r | |
2084 | //\r | |
2085 | // Call the protocol API to do the work\r | |
2086 | //\r | |
2087 | Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, CmdLine);\r | |
2088 | \r | |
2089 | //\r | |
2090 | // Report any errors\r | |
2091 | //\r | |
2092 | if (EFI_ERROR(Status)) {\r | |
2093 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_MAPPING), ShellInfoObject.HiiHandle, CmdLine);\r | |
2094 | }\r | |
2095 | \r | |
2096 | return (Status);\r | |
2097 | }\r | |
2098 | \r | |
5a5eb806 JC |
2099 | /**\r |
2100 | Reprocess the command line to direct all -? to the help command.\r | |
2101 | \r | |
2102 | if found, will add "help" as argv[0], and move the rest later.\r | |
2103 | \r | |
806c49db | 2104 | @param[in,out] CmdLine pointer to the command line to update\r |
5a5eb806 JC |
2105 | **/\r |
2106 | EFI_STATUS\r | |
2107 | EFIAPI\r | |
806c49db JC |
2108 | DoHelpUpdate(\r |
2109 | IN OUT CHAR16 **CmdLine\r | |
5a5eb806 JC |
2110 | )\r |
2111 | {\r | |
806c49db JC |
2112 | CHAR16 *CurrentParameter;\r |
2113 | CHAR16 *Walker;\r | |
806c49db JC |
2114 | CHAR16 *NewCommandLine;\r |
2115 | EFI_STATUS Status;\r | |
e75390f0 | 2116 | UINTN NewCmdLineSize;\r |
806c49db JC |
2117 | \r |
2118 | Status = EFI_SUCCESS;\r | |
2119 | \r | |
2120 | CurrentParameter = AllocateZeroPool(StrSize(*CmdLine));\r | |
2121 | if (CurrentParameter == NULL) {\r | |
2122 | return (EFI_OUT_OF_RESOURCES);\r | |
2123 | }\r | |
2124 | \r | |
2125 | Walker = *CmdLine;\r | |
2126 | while(Walker != NULL && *Walker != CHAR_NULL) {\r | |
d1c275c6 | 2127 | if (!EFI_ERROR(GetNextParameter(&Walker, &CurrentParameter, StrSize(*CmdLine), TRUE))) {\r |
14030c5c | 2128 | if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {\r |
a8f98806 JC |
2129 | CurrentParameter[0] = L' ';\r |
2130 | CurrentParameter[1] = L' ';\r | |
e75390f0 QS |
2131 | NewCmdLineSize = StrSize(L"help ") + StrSize(*CmdLine);\r |
2132 | NewCommandLine = AllocateZeroPool(NewCmdLineSize);\r | |
14030c5c JC |
2133 | if (NewCommandLine == NULL) {\r |
2134 | Status = EFI_OUT_OF_RESOURCES;\r | |
2135 | break;\r | |
2136 | }\r | |
2137 | \r | |
2138 | //\r | |
2139 | // We know the space is sufficient since we just calculated it.\r | |
2140 | //\r | |
e75390f0 QS |
2141 | StrnCpyS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), L"help ", 5);\r |
2142 | StrnCatS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), *CmdLine, StrLen(*CmdLine));\r | |
14030c5c JC |
2143 | SHELL_FREE_NON_NULL(*CmdLine);\r |
2144 | *CmdLine = NewCommandLine;\r | |
806c49db JC |
2145 | break;\r |
2146 | }\r | |
806c49db JC |
2147 | }\r |
2148 | }\r | |
2149 | \r | |
2150 | SHELL_FREE_NON_NULL(CurrentParameter);\r | |
2151 | \r | |
2152 | return (Status);\r | |
2153 | }\r | |
2154 | \r | |
2155 | /**\r | |
51429264 | 2156 | Function to update the shell variable "lasterror".\r |
806c49db | 2157 | \r |
51429264 | 2158 | @param[in] ErrorCode the error code to put into lasterror.\r |
806c49db JC |
2159 | **/\r |
2160 | EFI_STATUS\r | |
2161 | EFIAPI\r | |
2162 | SetLastError(\r | |
6bd64463 | 2163 | IN CONST SHELL_STATUS ErrorCode\r |
806c49db JC |
2164 | )\r |
2165 | {\r | |
2166 | CHAR16 LeString[19];\r | |
2167 | if (sizeof(EFI_STATUS) == sizeof(UINT64)) {\r | |
2168 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ErrorCode);\r | |
2169 | } else {\r | |
2170 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ErrorCode);\r | |
2171 | }\r | |
2172 | DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r | |
2173 | InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r | |
2174 | \r | |
2175 | return (EFI_SUCCESS);\r | |
2176 | }\r | |
2177 | \r | |
2178 | /**\r | |
2179 | Converts the command line to it's post-processed form. this replaces variables and alias' per UEFI Shell spec.\r | |
2180 | \r | |
2181 | @param[in,out] CmdLine pointer to the command line to update\r | |
2182 | \r | |
2183 | @retval EFI_SUCCESS The operation was successful\r | |
2184 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
d08a5464 | 2185 | @return some other error occurred\r |
806c49db JC |
2186 | **/\r |
2187 | EFI_STATUS\r | |
2188 | EFIAPI\r | |
12a27a6d | 2189 | ProcessCommandLineToFinal(\r |
806c49db JC |
2190 | IN OUT CHAR16 **CmdLine\r |
2191 | )\r | |
2192 | {\r | |
2193 | EFI_STATUS Status;\r | |
2194 | TrimSpaces(CmdLine);\r | |
2195 | \r | |
2196 | Status = ShellSubstituteAliases(CmdLine);\r | |
2197 | if (EFI_ERROR(Status)) {\r | |
2198 | return (Status);\r | |
2199 | }\r | |
2200 | \r | |
2201 | TrimSpaces(CmdLine);\r | |
2202 | \r | |
2203 | Status = ShellSubstituteVariables(CmdLine);\r | |
2204 | if (EFI_ERROR(Status)) {\r | |
2205 | return (Status);\r | |
2206 | }\r | |
81cd2f53 | 2207 | ASSERT (*CmdLine != NULL);\r |
806c49db JC |
2208 | \r |
2209 | TrimSpaces(CmdLine);\r | |
2210 | \r | |
2211 | //\r | |
2212 | // update for help parsing\r | |
2213 | //\r | |
2214 | if (StrStr(*CmdLine, L"?") != NULL) {\r | |
2215 | //\r | |
2216 | // This may do nothing if the ? does not indicate help.\r | |
2217 | // Save all the details for in the API below.\r | |
2218 | //\r | |
2219 | Status = DoHelpUpdate(CmdLine);\r | |
2220 | }\r | |
2221 | \r | |
2222 | TrimSpaces(CmdLine);\r | |
2223 | \r | |
2224 | return (EFI_SUCCESS);\r | |
2225 | }\r | |
2226 | \r | |
2227 | /**\r | |
2228 | Run an internal shell command.\r | |
2229 | \r | |
d08a5464 | 2230 | This API will update the shell's environment since these commands are libraries.\r |
806c49db JC |
2231 | \r |
2232 | @param[in] CmdLine the command line to run.\r | |
2233 | @param[in] FirstParameter the first parameter on the command line\r | |
2234 | @param[in] ParamProtocol the shell parameters protocol pointer\r | |
490ce43d | 2235 | @param[out] CommandStatus the status from the command line.\r |
806c49db JC |
2236 | \r |
2237 | @retval EFI_SUCCESS The command was completed.\r | |
2238 | @retval EFI_ABORTED The command's operation was aborted.\r | |
2239 | **/\r | |
2240 | EFI_STATUS\r | |
2241 | EFIAPI\r | |
2242 | RunInternalCommand(\r | |
2243 | IN CONST CHAR16 *CmdLine,\r | |
2244 | IN CHAR16 *FirstParameter,\r | |
490ce43d QS |
2245 | IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r |
2246 | OUT EFI_STATUS *CommandStatus\r | |
806c49db JC |
2247 | )\r |
2248 | {\r | |
2249 | EFI_STATUS Status;\r | |
2250 | UINTN Argc;\r | |
2251 | CHAR16 **Argv;\r | |
2252 | SHELL_STATUS CommandReturnedStatus;\r | |
2253 | BOOLEAN LastError;\r | |
4b6b543e QS |
2254 | CHAR16 *Walker;\r |
2255 | CHAR16 *NewCmdLine; \r | |
2256 | \r | |
2257 | NewCmdLine = AllocateCopyPool (StrSize (CmdLine), CmdLine);\r | |
2258 | if (NewCmdLine == NULL) {\r | |
2259 | return EFI_OUT_OF_RESOURCES;\r | |
2260 | }\r | |
2261 | \r | |
2262 | for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {\r | |
2263 | if (*Walker == L'^' && *(Walker+1) == L'#') {\r | |
2264 | CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));\r | |
2265 | }\r | |
2266 | }\r | |
806c49db | 2267 | \r |
5a5eb806 | 2268 | //\r |
806c49db | 2269 | // get the argc and argv updated for internal commands\r |
5a5eb806 | 2270 | //\r |
d1c275c6 | 2271 | Status = UpdateArgcArgv(ParamProtocol, NewCmdLine, Internal_Command, &Argv, &Argc);\r |
806c49db | 2272 | if (!EFI_ERROR(Status)) {\r |
5a5eb806 | 2273 | //\r |
806c49db | 2274 | // Run the internal command.\r |
5a5eb806 | 2275 | //\r |
806c49db JC |
2276 | Status = ShellCommandRunCommandHandler(FirstParameter, &CommandReturnedStatus, &LastError);\r |
2277 | \r | |
2278 | if (!EFI_ERROR(Status)) {\r | |
490ce43d QS |
2279 | if (CommandStatus != NULL) {\r |
2280 | if (CommandReturnedStatus != SHELL_SUCCESS) {\r | |
2281 | *CommandStatus = (EFI_STATUS)(CommandReturnedStatus | MAX_BIT);\r | |
2282 | } else {\r | |
2283 | *CommandStatus = EFI_SUCCESS;\r | |
2284 | }\r | |
2285 | }\r | |
2286 | \r | |
5a5eb806 | 2287 | //\r |
806c49db JC |
2288 | // Update last error status.\r |
2289 | // some commands do not update last error.\r | |
5a5eb806 | 2290 | //\r |
806c49db JC |
2291 | if (LastError) {\r |
2292 | SetLastError(CommandReturnedStatus);\r | |
5a5eb806 | 2293 | }\r |
806c49db JC |
2294 | \r |
2295 | //\r | |
2296 | // Pass thru the exitcode from the app.\r | |
2297 | //\r | |
2298 | if (ShellCommandGetExit()) {\r | |
e3eb7d82 JC |
2299 | //\r |
2300 | // An Exit was requested ("exit" command), pass its value up.\r | |
2301 | //\r | |
806c49db | 2302 | Status = CommandReturnedStatus;\r |
e3eb7d82 JC |
2303 | } else if (CommandReturnedStatus != SHELL_SUCCESS && IsScriptOnlyCommand(FirstParameter)) {\r |
2304 | //\r | |
2305 | // Always abort when a script only command fails for any reason\r | |
2306 | //\r | |
2307 | Status = EFI_ABORTED;\r | |
2308 | } else if (ShellCommandGetCurrentScriptFile() != NULL && CommandReturnedStatus == SHELL_ABORTED) {\r | |
2309 | //\r | |
2310 | // Abort when in a script and a command aborted\r | |
2311 | //\r | |
806c49db | 2312 | Status = EFI_ABORTED;\r |
5a5eb806 | 2313 | }\r |
806c49db JC |
2314 | }\r |
2315 | }\r | |
2316 | \r | |
2317 | //\r | |
d08a5464 | 2318 | // This is guaranteed to be called after UpdateArgcArgv no matter what else happened.\r |
806c49db JC |
2319 | // This is safe even if the update API failed. In this case, it may be a no-op.\r |
2320 | //\r | |
2321 | RestoreArgcArgv(ParamProtocol, &Argv, &Argc);\r | |
2322 | \r | |
e3eb7d82 | 2323 | //\r |
d08a5464 | 2324 | // If a script is running and the command is not a script only command, then\r |
e3eb7d82 JC |
2325 | // change return value to success so the script won't halt (unless aborted).\r |
2326 | //\r | |
2327 | // Script only commands have to be able halt the script since the script will\r | |
2328 | // not operate if they are failing.\r | |
2329 | //\r | |
2330 | if ( ShellCommandGetCurrentScriptFile() != NULL\r | |
2331 | && !IsScriptOnlyCommand(FirstParameter)\r | |
2332 | && Status != EFI_ABORTED\r | |
2333 | ) {\r | |
806c49db JC |
2334 | Status = EFI_SUCCESS;\r |
2335 | }\r | |
2336 | \r | |
4b6b543e | 2337 | FreePool (NewCmdLine);\r |
806c49db JC |
2338 | return (Status);\r |
2339 | }\r | |
2340 | \r | |
2341 | /**\r | |
2342 | Function to run the command or file.\r | |
2343 | \r | |
2344 | @param[in] Type the type of operation being run.\r | |
2345 | @param[in] CmdLine the command line to run.\r | |
2346 | @param[in] FirstParameter the first parameter on the command line\r | |
2347 | @param[in] ParamProtocol the shell parameters protocol pointer\r | |
490ce43d | 2348 | @param[out] CommandStatus the status from the command line.\r |
806c49db JC |
2349 | \r |
2350 | @retval EFI_SUCCESS The command was completed.\r | |
2351 | @retval EFI_ABORTED The command's operation was aborted.\r | |
2352 | **/\r | |
2353 | EFI_STATUS\r | |
2354 | EFIAPI\r | |
2355 | RunCommandOrFile(\r | |
2356 | IN SHELL_OPERATION_TYPES Type,\r | |
2357 | IN CONST CHAR16 *CmdLine,\r | |
2358 | IN CHAR16 *FirstParameter,\r | |
490ce43d QS |
2359 | IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r |
2360 | OUT EFI_STATUS *CommandStatus\r | |
806c49db JC |
2361 | )\r |
2362 | {\r | |
2363 | EFI_STATUS Status;\r | |
cd39fe08 | 2364 | EFI_STATUS StartStatus;\r |
806c49db JC |
2365 | CHAR16 *CommandWithPath;\r |
2366 | EFI_DEVICE_PATH_PROTOCOL *DevPath;\r | |
5223c121 | 2367 | SHELL_STATUS CalleeExitStatus;\r |
806c49db JC |
2368 | \r |
2369 | Status = EFI_SUCCESS;\r | |
2370 | CommandWithPath = NULL;\r | |
2371 | DevPath = NULL;\r | |
71c49eaf | 2372 | CalleeExitStatus = SHELL_INVALID_PARAMETER;\r |
806c49db JC |
2373 | \r |
2374 | switch (Type) {\r | |
51429264 | 2375 | case Internal_Command:\r |
490ce43d | 2376 | Status = RunInternalCommand(CmdLine, FirstParameter, ParamProtocol, CommandStatus);\r |
806c49db | 2377 | break;\r |
51429264 SQ |
2378 | case Script_File_Name:\r |
2379 | case Efi_Application:\r | |
806c49db JC |
2380 | //\r |
2381 | // Process a fully qualified path\r | |
2382 | //\r | |
2383 | if (StrStr(FirstParameter, L":") != NULL) {\r | |
2384 | ASSERT (CommandWithPath == NULL);\r | |
2385 | if (ShellIsFile(FirstParameter) == EFI_SUCCESS) {\r | |
2386 | CommandWithPath = StrnCatGrow(&CommandWithPath, NULL, FirstParameter, 0);\r | |
2387 | }\r | |
2388 | }\r | |
2389 | \r | |
2390 | //\r | |
2391 | // Process a relative path and also check in the path environment variable\r | |
2392 | //\r | |
2393 | if (CommandWithPath == NULL) {\r | |
2394 | CommandWithPath = ShellFindFilePathEx(FirstParameter, mExecutableExtensions);\r | |
2395 | }\r | |
2396 | \r | |
2397 | //\r | |
2398 | // This should be impossible now.\r | |
2399 | //\r | |
2400 | ASSERT(CommandWithPath != NULL);\r | |
2401 | \r | |
2402 | //\r | |
2403 | // Make sure that path is not just a directory (or not found)\r | |
2404 | //\r | |
2405 | if (!EFI_ERROR(ShellIsDirectory(CommandWithPath))) {\r | |
2406 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r | |
6bd64463 | 2407 | SetLastError(SHELL_NOT_FOUND);\r |
806c49db JC |
2408 | }\r |
2409 | switch (Type) {\r | |
51429264 | 2410 | case Script_File_Name:\r |
a308e058 | 2411 | Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);\r |
806c49db | 2412 | break;\r |
51429264 | 2413 | case Efi_Application:\r |
806c49db JC |
2414 | //\r |
2415 | // Get the device path of the application image\r | |
2416 | //\r | |
2417 | DevPath = ShellInfoObject.NewEfiShellProtocol->GetDevicePathFromFilePath(CommandWithPath);\r | |
2418 | if (DevPath == NULL){\r | |
2419 | Status = EFI_OUT_OF_RESOURCES;\r | |
2420 | break;\r | |
2421 | }\r | |
2422 | \r | |
2423 | //\r | |
2424 | // Execute the device path\r | |
2425 | //\r | |
2426 | Status = InternalShellExecuteDevicePath(\r | |
2427 | &gImageHandle,\r | |
2428 | DevPath,\r | |
2429 | CmdLine,\r | |
2430 | NULL,\r | |
a308e058 | 2431 | &StartStatus\r |
806c49db JC |
2432 | );\r |
2433 | \r | |
2434 | SHELL_FREE_NON_NULL(DevPath);\r | |
2435 | \r | |
71c49eaf SQ |
2436 | if(EFI_ERROR (Status)) {\r |
2437 | CalleeExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r | |
2438 | } else {\r | |
cd39fe08 | 2439 | CalleeExitStatus = (SHELL_STATUS) StartStatus;\r |
71c49eaf SQ |
2440 | }\r |
2441 | \r | |
490ce43d QS |
2442 | if (CommandStatus != NULL) {\r |
2443 | *CommandStatus = CalleeExitStatus;\r | |
2444 | }\r | |
2445 | \r | |
806c49db JC |
2446 | //\r |
2447 | // Update last error status.\r | |
2448 | //\r | |
5223c121 | 2449 | // Status is an EFI_STATUS. Clear top bit to convert to SHELL_STATUS\r |
71c49eaf | 2450 | SetLastError(CalleeExitStatus);\r |
806c49db | 2451 | break;\r |
6fa0da7d LE |
2452 | default:\r |
2453 | //\r | |
2454 | // Do nothing.\r | |
2455 | //\r | |
2456 | break;\r | |
5a5eb806 JC |
2457 | }\r |
2458 | break;\r | |
6fa0da7d LE |
2459 | default:\r |
2460 | //\r | |
2461 | // Do nothing.\r | |
2462 | //\r | |
2463 | break;\r | |
5a5eb806 | 2464 | }\r |
806c49db JC |
2465 | \r |
2466 | SHELL_FREE_NON_NULL(CommandWithPath);\r | |
2467 | \r | |
2468 | return (Status);\r | |
2469 | }\r | |
2470 | \r | |
2471 | /**\r | |
2472 | Function to setup StdIn, StdErr, StdOut, and then run the command or file.\r | |
2473 | \r | |
2474 | @param[in] Type the type of operation being run.\r | |
2475 | @param[in] CmdLine the command line to run.\r | |
2476 | @param[in] FirstParameter the first parameter on the command line.\r | |
2477 | @param[in] ParamProtocol the shell parameters protocol pointer\r | |
490ce43d | 2478 | @param[out] CommandStatus the status from the command line.\r |
806c49db JC |
2479 | \r |
2480 | @retval EFI_SUCCESS The command was completed.\r | |
2481 | @retval EFI_ABORTED The command's operation was aborted.\r | |
2482 | **/\r | |
2483 | EFI_STATUS\r | |
2484 | EFIAPI\r | |
2485 | SetupAndRunCommandOrFile(\r | |
490ce43d QS |
2486 | IN SHELL_OPERATION_TYPES Type,\r |
2487 | IN CHAR16 *CmdLine,\r | |
2488 | IN CHAR16 *FirstParameter,\r | |
2489 | IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol,\r | |
dcbdb8bf | 2490 | OUT EFI_STATUS *CommandStatus\r |
806c49db JC |
2491 | )\r |
2492 | {\r | |
2493 | EFI_STATUS Status;\r | |
2494 | SHELL_FILE_HANDLE OriginalStdIn;\r | |
2495 | SHELL_FILE_HANDLE OriginalStdOut;\r | |
2496 | SHELL_FILE_HANDLE OriginalStdErr;\r | |
2497 | SYSTEM_TABLE_INFO OriginalSystemTableInfo;\r | |
2498 | \r | |
2499 | //\r | |
2500 | // Update the StdIn, StdOut, and StdErr for redirection to environment variables, files, etc... unicode and ASCII\r | |
2501 | //\r | |
2502 | Status = UpdateStdInStdOutStdErr(ParamProtocol, CmdLine, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r | |
2503 | \r | |
2504 | //\r | |
2505 | // The StdIn, StdOut, and StdErr are set up.\r | |
2506 | // Now run the command, script, or application\r | |
2507 | //\r | |
2508 | if (!EFI_ERROR(Status)) {\r | |
75eb337f | 2509 | TrimSpaces(&CmdLine);\r |
490ce43d | 2510 | Status = RunCommandOrFile(Type, CmdLine, FirstParameter, ParamProtocol, CommandStatus);\r |
806c49db JC |
2511 | }\r |
2512 | \r | |
2513 | //\r | |
2514 | // Now print errors\r | |
2515 | //\r | |
2516 | if (EFI_ERROR(Status)) {\r | |
2517 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR), ShellInfoObject.HiiHandle, (VOID*)(Status));\r | |
2518 | }\r | |
2519 | \r | |
2520 | //\r | |
2521 | // put back the original StdIn, StdOut, and StdErr\r | |
2522 | //\r | |
2523 | RestoreStdInStdOutStdErr(ParamProtocol, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r | |
2524 | \r | |
2525 | return (Status);\r | |
5a5eb806 JC |
2526 | }\r |
2527 | \r | |
a405b86d | 2528 | /**\r |
2529 | Function will process and run a command line.\r | |
2530 | \r | |
2531 | This will determine if the command line represents an internal shell \r | |
2532 | command or dispatch an external application.\r | |
2533 | \r | |
2534 | @param[in] CmdLine The command line to parse.\r | |
490ce43d | 2535 | @param[out] CommandStatus The status from the command line.\r |
a405b86d | 2536 | \r |
2537 | @retval EFI_SUCCESS The command was completed.\r | |
2538 | @retval EFI_ABORTED The command's operation was aborted.\r | |
2539 | **/\r | |
2540 | EFI_STATUS\r | |
2541 | EFIAPI\r | |
490ce43d QS |
2542 | RunShellCommand(\r |
2543 | IN CONST CHAR16 *CmdLine,\r | |
2544 | OUT EFI_STATUS *CommandStatus\r | |
a405b86d | 2545 | )\r |
2546 | {\r | |
2547 | EFI_STATUS Status;\r | |
a405b86d | 2548 | CHAR16 *CleanOriginal;\r |
806c49db JC |
2549 | CHAR16 *FirstParameter;\r |
2550 | CHAR16 *TempWalker;\r | |
2551 | SHELL_OPERATION_TYPES Type;\r | |
a405b86d | 2552 | \r |
2553 | ASSERT(CmdLine != NULL);\r | |
2554 | if (StrLen(CmdLine) == 0) {\r | |
2555 | return (EFI_SUCCESS);\r | |
2556 | }\r | |
2557 | \r | |
a405b86d | 2558 | Status = EFI_SUCCESS;\r |
2559 | CleanOriginal = NULL;\r | |
a405b86d | 2560 | \r |
2561 | CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);\r | |
532691c8 | 2562 | if (CleanOriginal == NULL) {\r |
2563 | return (EFI_OUT_OF_RESOURCES);\r | |
2564 | }\r | |
284e034f | 2565 | \r |
ad2bc854 | 2566 | TrimSpaces(&CleanOriginal);\r |
a405b86d | 2567 | \r |
284e034f | 2568 | //\r |
d41a79a0 CP |
2569 | // NULL out comments (leveraged from RunScriptFileHandle() ).\r |
2570 | // The # character on a line is used to denote that all characters on the same line\r | |
2571 | // and to the right of the # are to be ignored by the shell.\r | |
d08a5464 | 2572 | // Afterwards, again remove spaces, in case any were between the last command-parameter and '#'.\r |
d41a79a0 CP |
2573 | //\r |
2574 | for (TempWalker = CleanOriginal; TempWalker != NULL && *TempWalker != CHAR_NULL; TempWalker++) {\r | |
2575 | if (*TempWalker == L'^') {\r | |
2576 | if (*(TempWalker + 1) == L'#') {\r | |
4b6b543e | 2577 | TempWalker++;\r |
d41a79a0 CP |
2578 | }\r |
2579 | } else if (*TempWalker == L'#') {\r | |
2580 | *TempWalker = CHAR_NULL;\r | |
2581 | }\r | |
2582 | }\r | |
2583 | \r | |
2584 | TrimSpaces(&CleanOriginal);\r | |
2585 | \r | |
2586 | //\r | |
284e034f CP |
2587 | // Handle case that passed in command line is just 1 or more " " characters.\r |
2588 | //\r | |
2589 | if (StrLen (CleanOriginal) == 0) {\r | |
806c49db | 2590 | SHELL_FREE_NON_NULL(CleanOriginal);\r |
284e034f CP |
2591 | return (EFI_SUCCESS);\r |
2592 | }\r | |
2593 | \r | |
12a27a6d | 2594 | Status = ProcessCommandLineToFinal(&CleanOriginal);\r |
ca53c0af | 2595 | if (EFI_ERROR(Status)) {\r |
806c49db | 2596 | SHELL_FREE_NON_NULL(CleanOriginal);\r |
ca53c0af | 2597 | return (Status);\r |
a405b86d | 2598 | }\r |
2599 | \r | |
a405b86d | 2600 | //\r |
d08a5464 | 2601 | // We don't do normal processing with a split command line (output from one command input to another)\r |
a405b86d | 2602 | //\r |
1ef61d03 | 2603 | if (ContainsSplit(CleanOriginal)) {\r |
a308e058 | 2604 | Status = ProcessNewSplitCommandLine(CleanOriginal);\r |
806c49db JC |
2605 | SHELL_FREE_NON_NULL(CleanOriginal);\r |
2606 | return (Status);\r | |
2607 | } \r | |
5b5cd144 | 2608 | \r |
806c49db JC |
2609 | //\r |
2610 | // We need the first parameter information so we can determine the operation type\r | |
2611 | //\r | |
2612 | FirstParameter = AllocateZeroPool(StrSize(CleanOriginal));\r | |
2613 | if (FirstParameter == NULL) {\r | |
2614 | SHELL_FREE_NON_NULL(CleanOriginal);\r | |
2615 | return (EFI_OUT_OF_RESOURCES);\r | |
2616 | }\r | |
2617 | TempWalker = CleanOriginal;\r | |
d1c275c6 | 2618 | if (!EFI_ERROR(GetNextParameter(&TempWalker, &FirstParameter, StrSize(CleanOriginal), TRUE))) {\r |
14030c5c JC |
2619 | //\r |
2620 | // Depending on the first parameter we change the behavior\r | |
2621 | //\r | |
2622 | switch (Type = GetOperationType(FirstParameter)) {\r | |
2623 | case File_Sys_Change:\r | |
2624 | Status = ChangeMappedDrive (FirstParameter);\r | |
2625 | break;\r | |
2626 | case Internal_Command:\r | |
2627 | case Script_File_Name:\r | |
2628 | case Efi_Application:\r | |
490ce43d | 2629 | Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol, CommandStatus);\r |
14030c5c JC |
2630 | break;\r |
2631 | default:\r | |
2632 | //\r | |
2633 | // Whatever was typed, it was invalid.\r | |
2634 | //\r | |
2635 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r | |
2636 | SetLastError(SHELL_NOT_FOUND);\r | |
2637 | break;\r | |
2638 | }\r | |
2639 | } else {\r | |
2640 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r | |
2641 | SetLastError(SHELL_NOT_FOUND);\r | |
a405b86d | 2642 | }\r |
806c49db | 2643 | \r |
ca53c0af | 2644 | SHELL_FREE_NON_NULL(CleanOriginal);\r |
806c49db | 2645 | SHELL_FREE_NON_NULL(FirstParameter);\r |
a405b86d | 2646 | \r |
2647 | return (Status);\r | |
2648 | }\r | |
2649 | \r | |
490ce43d QS |
2650 | /**\r |
2651 | Function will process and run a command line.\r | |
2652 | \r | |
2653 | This will determine if the command line represents an internal shell \r | |
2654 | command or dispatch an external application.\r | |
2655 | \r | |
2656 | @param[in] CmdLine The command line to parse.\r | |
2657 | \r | |
2658 | @retval EFI_SUCCESS The command was completed.\r | |
2659 | @retval EFI_ABORTED The command's operation was aborted.\r | |
2660 | **/\r | |
2661 | EFI_STATUS\r | |
2662 | EFIAPI\r | |
2663 | RunCommand(\r | |
2664 | IN CONST CHAR16 *CmdLine\r | |
2665 | )\r | |
2666 | {\r | |
2667 | return (RunShellCommand(CmdLine, NULL));\r | |
2668 | }\r | |
2669 | \r | |
2670 | \r | |
a405b86d | 2671 | STATIC CONST UINT16 InvalidChars[] = {L'*', L'?', L'<', L'>', L'\\', L'/', L'\"', 0x0001, 0x0002};\r |
2672 | /**\r | |
d08a5464 | 2673 | Function determines if the CommandName COULD be a valid command. It does not determine whether\r |
a405b86d | 2674 | this is a valid command. It only checks for invalid characters.\r |
2675 | \r | |
2676 | @param[in] CommandName The name to check\r | |
2677 | \r | |
2678 | @retval TRUE CommandName could be a command name\r | |
2679 | @retval FALSE CommandName could not be a valid command name\r | |
2680 | **/\r | |
2681 | BOOLEAN\r | |
2682 | EFIAPI\r | |
2683 | IsValidCommandName(\r | |
2684 | IN CONST CHAR16 *CommandName\r | |
2685 | )\r | |
2686 | {\r | |
2687 | UINTN Count;\r | |
2688 | if (CommandName == NULL) {\r | |
2689 | ASSERT(FALSE);\r | |
2690 | return (FALSE);\r | |
2691 | }\r | |
2692 | for ( Count = 0\r | |
2693 | ; Count < sizeof(InvalidChars) / sizeof(InvalidChars[0])\r | |
2694 | ; Count++\r | |
2695 | ){\r | |
2696 | if (ScanMem16(CommandName, StrSize(CommandName), InvalidChars[Count]) != NULL) {\r | |
2697 | return (FALSE);\r | |
2698 | }\r | |
2699 | }\r | |
2700 | return (TRUE);\r | |
2701 | }\r | |
2702 | \r | |
2703 | /**\r | |
2704 | Function to process a NSH script file via SHELL_FILE_HANDLE.\r | |
2705 | \r | |
2706 | @param[in] Handle The handle to the already opened file.\r | |
2707 | @param[in] Name The name of the script file.\r | |
2708 | \r | |
d08a5464 | 2709 | @retval EFI_SUCCESS the script completed successfully\r |
a405b86d | 2710 | **/\r |
2711 | EFI_STATUS\r | |
2712 | EFIAPI\r | |
2713 | RunScriptFileHandle (\r | |
a308e058 RN |
2714 | IN SHELL_FILE_HANDLE Handle,\r |
2715 | IN CONST CHAR16 *Name\r | |
a405b86d | 2716 | )\r |
2717 | {\r | |
2718 | EFI_STATUS Status;\r | |
2719 | SCRIPT_FILE *NewScriptFile;\r | |
2720 | UINTN LoopVar;\r | |
4dc0d578 | 2721 | UINTN PrintBuffSize;\r |
a405b86d | 2722 | CHAR16 *CommandLine;\r |
2723 | CHAR16 *CommandLine2;\r | |
2724 | CHAR16 *CommandLine3;\r | |
2725 | SCRIPT_COMMAND_LIST *LastCommand;\r | |
2726 | BOOLEAN Ascii;\r | |
2727 | BOOLEAN PreScriptEchoState;\r | |
848997b5 | 2728 | BOOLEAN PreCommandEchoState;\r |
a405b86d | 2729 | CONST CHAR16 *CurDir;\r |
2730 | UINTN LineCount;\r | |
b6b22b13 | 2731 | CHAR16 LeString[50];\r |
14810d6b | 2732 | LIST_ENTRY OldBufferList;\r |
a405b86d | 2733 | \r |
2734 | ASSERT(!ShellCommandGetScriptExit());\r | |
2735 | \r | |
2736 | PreScriptEchoState = ShellCommandGetEchoState();\r | |
4dc0d578 | 2737 | PrintBuffSize = PcdGet16(PcdShellPrintBufferSize);\r |
a405b86d | 2738 | \r |
2739 | NewScriptFile = (SCRIPT_FILE*)AllocateZeroPool(sizeof(SCRIPT_FILE));\r | |
3c865f20 | 2740 | if (NewScriptFile == NULL) {\r |
2741 | return (EFI_OUT_OF_RESOURCES);\r | |
2742 | }\r | |
a405b86d | 2743 | \r |
2744 | //\r | |
2745 | // Set up the name\r | |
2746 | //\r | |
2747 | ASSERT(NewScriptFile->ScriptName == NULL);\r | |
2748 | NewScriptFile->ScriptName = StrnCatGrow(&NewScriptFile->ScriptName, NULL, Name, 0);\r | |
3c865f20 | 2749 | if (NewScriptFile->ScriptName == NULL) {\r |
2750 | DeleteScriptFileStruct(NewScriptFile);\r | |
2751 | return (EFI_OUT_OF_RESOURCES);\r | |
2752 | }\r | |
a405b86d | 2753 | \r |
2754 | //\r | |
2755 | // Save the parameters (used to replace %0 to %9 later on)\r | |
2756 | //\r | |
2757 | NewScriptFile->Argc = ShellInfoObject.NewShellParametersProtocol->Argc;\r | |
2758 | if (NewScriptFile->Argc != 0) {\r | |
2759 | NewScriptFile->Argv = (CHAR16**)AllocateZeroPool(NewScriptFile->Argc * sizeof(CHAR16*));\r | |
3c865f20 | 2760 | if (NewScriptFile->Argv == NULL) {\r |
2761 | DeleteScriptFileStruct(NewScriptFile);\r | |
2762 | return (EFI_OUT_OF_RESOURCES);\r | |
2763 | }\r | |
a405b86d | 2764 | for (LoopVar = 0 ; LoopVar < 10 && LoopVar < NewScriptFile->Argc; LoopVar++) {\r |
2765 | ASSERT(NewScriptFile->Argv[LoopVar] == NULL);\r | |
2766 | NewScriptFile->Argv[LoopVar] = StrnCatGrow(&NewScriptFile->Argv[LoopVar], NULL, ShellInfoObject.NewShellParametersProtocol->Argv[LoopVar], 0);\r | |
3c865f20 | 2767 | if (NewScriptFile->Argv[LoopVar] == NULL) {\r |
2768 | DeleteScriptFileStruct(NewScriptFile);\r | |
2769 | return (EFI_OUT_OF_RESOURCES);\r | |
2770 | }\r | |
a405b86d | 2771 | }\r |
2772 | } else {\r | |
2773 | NewScriptFile->Argv = NULL;\r | |
2774 | }\r | |
2775 | \r | |
2776 | InitializeListHead(&NewScriptFile->CommandList);\r | |
2777 | InitializeListHead(&NewScriptFile->SubstList);\r | |
2778 | \r | |
2779 | //\r | |
2780 | // Now build the list of all script commands.\r | |
2781 | //\r | |
2782 | LineCount = 0;\r | |
2783 | while(!ShellFileHandleEof(Handle)) {\r | |
2784 | CommandLine = ShellFileHandleReturnLine(Handle, &Ascii);\r | |
2785 | LineCount++;\r | |
4922715d JC |
2786 | if (CommandLine == NULL || StrLen(CommandLine) == 0 || CommandLine[0] == '#') {\r |
2787 | SHELL_FREE_NON_NULL(CommandLine);\r | |
a405b86d | 2788 | continue;\r |
2789 | }\r | |
2790 | NewScriptFile->CurrentCommand = AllocateZeroPool(sizeof(SCRIPT_COMMAND_LIST));\r | |
3c865f20 | 2791 | if (NewScriptFile->CurrentCommand == NULL) {\r |
4922715d | 2792 | SHELL_FREE_NON_NULL(CommandLine);\r |
3c865f20 | 2793 | DeleteScriptFileStruct(NewScriptFile);\r |
2794 | return (EFI_OUT_OF_RESOURCES);\r | |
2795 | }\r | |
a405b86d | 2796 | \r |
2797 | NewScriptFile->CurrentCommand->Cl = CommandLine;\r | |
2798 | NewScriptFile->CurrentCommand->Data = NULL;\r | |
2799 | NewScriptFile->CurrentCommand->Line = LineCount;\r | |
2800 | \r | |
2801 | InsertTailList(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r | |
2802 | }\r | |
2803 | \r | |
2804 | //\r | |
2805 | // Add this as the topmost script file\r | |
2806 | //\r | |
2807 | ShellCommandSetNewScript (NewScriptFile);\r | |
2808 | \r | |
2809 | //\r | |
2810 | // Now enumerate through the commands and run each one.\r | |
2811 | //\r | |
4dc0d578 | 2812 | CommandLine = AllocateZeroPool(PrintBuffSize);\r |
3c865f20 | 2813 | if (CommandLine == NULL) {\r |
2814 | DeleteScriptFileStruct(NewScriptFile);\r | |
2815 | return (EFI_OUT_OF_RESOURCES);\r | |
2816 | }\r | |
4dc0d578 | 2817 | CommandLine2 = AllocateZeroPool(PrintBuffSize);\r |
3c865f20 | 2818 | if (CommandLine2 == NULL) {\r |
2819 | FreePool(CommandLine);\r | |
2820 | DeleteScriptFileStruct(NewScriptFile);\r | |
2821 | return (EFI_OUT_OF_RESOURCES);\r | |
2822 | }\r | |
a405b86d | 2823 | \r |
2824 | for ( NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetFirstNode(&NewScriptFile->CommandList)\r | |
2825 | ; !IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)\r | |
2826 | ; // conditional increment in the body of the loop\r | |
2827 | ){\r | |
3c865f20 | 2828 | ASSERT(CommandLine2 != NULL);\r |
4dc0d578 QS |
2829 | StrnCpyS( CommandLine2, \r |
2830 | PrintBuffSize/sizeof(CHAR16), \r | |
2831 | NewScriptFile->CurrentCommand->Cl,\r | |
2832 | PrintBuffSize/sizeof(CHAR16) - 1\r | |
e75390f0 | 2833 | );\r |
a405b86d | 2834 | \r |
14810d6b QS |
2835 | SaveBufferList(&OldBufferList);\r |
2836 | \r | |
a405b86d | 2837 | //\r |
2838 | // NULL out comments\r | |
2839 | //\r | |
2840 | for (CommandLine3 = CommandLine2 ; CommandLine3 != NULL && *CommandLine3 != CHAR_NULL ; CommandLine3++) {\r | |
2841 | if (*CommandLine3 == L'^') {\r | |
4b6b543e | 2842 | if ( *(CommandLine3+1) == L':') {\r |
a405b86d | 2843 | CopyMem(CommandLine3, CommandLine3+1, StrSize(CommandLine3) - sizeof(CommandLine3[0]));\r |
4b6b543e QS |
2844 | } else if (*(CommandLine3+1) == L'#') {\r |
2845 | CommandLine3++;\r | |
a405b86d | 2846 | }\r |
2847 | } else if (*CommandLine3 == L'#') {\r | |
2848 | *CommandLine3 = CHAR_NULL;\r | |
2849 | }\r | |
2850 | }\r | |
2851 | \r | |
2852 | if (CommandLine2 != NULL && StrLen(CommandLine2) >= 1) {\r | |
2853 | //\r | |
2854 | // Due to variability in starting the find and replace action we need to have both buffers the same.\r | |
2855 | //\r | |
4dc0d578 QS |
2856 | StrnCpyS( CommandLine, \r |
2857 | PrintBuffSize/sizeof(CHAR16), \r | |
2858 | CommandLine2,\r | |
2859 | PrintBuffSize/sizeof(CHAR16) - 1\r | |
e75390f0 | 2860 | );\r |
a405b86d | 2861 | \r |
2862 | //\r | |
2863 | // Remove the %0 to %9 from the command line (if we have some arguments)\r | |
2864 | //\r | |
2865 | if (NewScriptFile->Argv != NULL) {\r | |
2866 | switch (NewScriptFile->Argc) {\r | |
2867 | default:\r | |
d1c275c6 | 2868 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%9", NewScriptFile->Argv[9], FALSE, FALSE);\r |
a405b86d | 2869 | ASSERT_EFI_ERROR(Status);\r |
2870 | case 9:\r | |
d1c275c6 | 2871 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PrintBuffSize, L"%8", NewScriptFile->Argv[8], FALSE, FALSE);\r |
a405b86d | 2872 | ASSERT_EFI_ERROR(Status);\r |
2873 | case 8:\r | |
d1c275c6 | 2874 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%7", NewScriptFile->Argv[7], FALSE, FALSE);\r |
a405b86d | 2875 | ASSERT_EFI_ERROR(Status);\r |
2876 | case 7:\r | |
d1c275c6 | 2877 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PrintBuffSize, L"%6", NewScriptFile->Argv[6], FALSE, FALSE);\r |
a405b86d | 2878 | ASSERT_EFI_ERROR(Status);\r |
2879 | case 6:\r | |
d1c275c6 | 2880 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%5", NewScriptFile->Argv[5], FALSE, FALSE);\r |
a405b86d | 2881 | ASSERT_EFI_ERROR(Status);\r |
2882 | case 5:\r | |
d1c275c6 | 2883 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PrintBuffSize, L"%4", NewScriptFile->Argv[4], FALSE, FALSE);\r |
a405b86d | 2884 | ASSERT_EFI_ERROR(Status);\r |
2885 | case 4:\r | |
d1c275c6 | 2886 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%3", NewScriptFile->Argv[3], FALSE, FALSE);\r |
a405b86d | 2887 | ASSERT_EFI_ERROR(Status);\r |
2888 | case 3:\r | |
d1c275c6 | 2889 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PrintBuffSize, L"%2", NewScriptFile->Argv[2], FALSE, FALSE);\r |
a405b86d | 2890 | ASSERT_EFI_ERROR(Status);\r |
2891 | case 2:\r | |
d1c275c6 | 2892 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%1", NewScriptFile->Argv[1], FALSE, FALSE);\r |
a405b86d | 2893 | ASSERT_EFI_ERROR(Status);\r |
2894 | case 1:\r | |
d1c275c6 | 2895 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PrintBuffSize, L"%0", NewScriptFile->Argv[0], FALSE, FALSE);\r |
a405b86d | 2896 | ASSERT_EFI_ERROR(Status);\r |
2897 | break;\r | |
2898 | case 0:\r | |
2899 | break;\r | |
2900 | }\r | |
2901 | }\r | |
4dc0d578 QS |
2902 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%1", L"\"\"", FALSE, FALSE);\r |
2903 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PrintBuffSize, L"%2", L"\"\"", FALSE, FALSE);\r | |
2904 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%3", L"\"\"", FALSE, FALSE);\r | |
2905 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PrintBuffSize, L"%4", L"\"\"", FALSE, FALSE);\r | |
2906 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%5", L"\"\"", FALSE, FALSE);\r | |
2907 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PrintBuffSize, L"%6", L"\"\"", FALSE, FALSE);\r | |
2908 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%7", L"\"\"", FALSE, FALSE);\r | |
2909 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PrintBuffSize, L"%8", L"\"\"", FALSE, FALSE);\r | |
2910 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PrintBuffSize, L"%9", L"\"\"", FALSE, FALSE);\r | |
2911 | \r | |
2912 | StrnCpyS( CommandLine2, \r | |
2913 | PrintBuffSize/sizeof(CHAR16), \r | |
2914 | CommandLine,\r | |
2915 | PrintBuffSize/sizeof(CHAR16) - 1\r | |
e75390f0 | 2916 | );\r |
a405b86d | 2917 | \r |
2918 | LastCommand = NewScriptFile->CurrentCommand;\r | |
2919 | \r | |
2920 | for (CommandLine3 = CommandLine2 ; CommandLine3[0] == L' ' ; CommandLine3++);\r | |
2921 | \r | |
3c865f20 | 2922 | if (CommandLine3 != NULL && CommandLine3[0] == L':' ) {\r |
a405b86d | 2923 | //\r |
2924 | // This line is a goto target / label\r | |
2925 | //\r | |
2926 | } else {\r | |
2927 | if (CommandLine3 != NULL && StrLen(CommandLine3) > 0) {\r | |
848997b5 | 2928 | if (CommandLine3[0] == L'@') {\r |
2929 | //\r | |
2930 | // We need to save the current echo state\r | |
2931 | // and disable echo for just this command.\r | |
2932 | //\r | |
2933 | PreCommandEchoState = ShellCommandGetEchoState();\r | |
2934 | ShellCommandSetEchoState(FALSE);\r | |
a308e058 | 2935 | Status = RunCommand(CommandLine3+1);\r |
848997b5 | 2936 | \r |
2937 | //\r | |
284e034f | 2938 | // If command was "@echo -off" or "@echo -on" then don't restore echo state\r |
848997b5 | 2939 | //\r |
284e034f CP |
2940 | if (StrCmp (L"@echo -off", CommandLine3) != 0 &&\r |
2941 | StrCmp (L"@echo -on", CommandLine3) != 0) {\r | |
2942 | //\r | |
2943 | // Now restore the pre-'@' echo state.\r | |
2944 | //\r | |
2945 | ShellCommandSetEchoState(PreCommandEchoState);\r | |
2946 | }\r | |
848997b5 | 2947 | } else {\r |
0d11446d | 2948 | if (ShellCommandGetEchoState()) {\r |
2949 | CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd");\r | |
2950 | if (CurDir != NULL && StrLen(CurDir) > 1) {\r | |
2951 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);\r | |
2952 | } else {\r | |
2953 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);\r | |
2954 | }\r | |
2955 | ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2);\r | |
2956 | }\r | |
a308e058 | 2957 | Status = RunCommand(CommandLine3);\r |
848997b5 | 2958 | }\r |
a405b86d | 2959 | }\r |
2960 | \r | |
2961 | if (ShellCommandGetScriptExit()) {\r | |
5b5cd144 CP |
2962 | //\r |
2963 | // ShellCommandGetExitCode() always returns a UINT64\r | |
2964 | //\r | |
a308e058 | 2965 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());\r |
5b5cd144 CP |
2966 | DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r |
2967 | InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r | |
b6b22b13 | 2968 | \r |
2969 | ShellCommandRegisterExit(FALSE, 0);\r | |
a405b86d | 2970 | Status = EFI_SUCCESS;\r |
14810d6b | 2971 | RestoreBufferList(&OldBufferList);\r |
a405b86d | 2972 | break;\r |
2973 | }\r | |
c6a7fef8 | 2974 | if (ShellGetExecutionBreakFlag()) {\r |
14810d6b | 2975 | RestoreBufferList(&OldBufferList);\r |
c6a7fef8 ED |
2976 | break;\r |
2977 | }\r | |
a405b86d | 2978 | if (EFI_ERROR(Status)) {\r |
14810d6b | 2979 | RestoreBufferList(&OldBufferList);\r |
a405b86d | 2980 | break;\r |
2981 | }\r | |
2982 | if (ShellCommandGetExit()) {\r | |
14810d6b | 2983 | RestoreBufferList(&OldBufferList);\r |
a405b86d | 2984 | break;\r |
2985 | }\r | |
2986 | }\r | |
2987 | //\r | |
2988 | // If that commend did not update the CurrentCommand then we need to advance it...\r | |
2989 | //\r | |
2990 | if (LastCommand == NewScriptFile->CurrentCommand) {\r | |
2991 | NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r | |
2992 | if (!IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)) {\r | |
2993 | NewScriptFile->CurrentCommand->Reset = TRUE;\r | |
2994 | }\r | |
2995 | }\r | |
2996 | } else {\r | |
2997 | NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r | |
2998 | if (!IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)) {\r | |
2999 | NewScriptFile->CurrentCommand->Reset = TRUE;\r | |
3000 | }\r | |
3001 | }\r | |
14810d6b | 3002 | RestoreBufferList(&OldBufferList);\r |
a405b86d | 3003 | }\r |
3004 | \r | |
a405b86d | 3005 | \r |
3006 | FreePool(CommandLine);\r | |
3007 | FreePool(CommandLine2);\r | |
3008 | ShellCommandSetNewScript (NULL);\r | |
733f138d | 3009 | \r |
3010 | //\r | |
3011 | // Only if this was the last script reset the state.\r | |
3012 | //\r | |
3013 | if (ShellCommandGetCurrentScriptFile()==NULL) {\r | |
3014 | ShellCommandSetEchoState(PreScriptEchoState);\r | |
3015 | }\r | |
a405b86d | 3016 | return (EFI_SUCCESS);\r |
3017 | }\r | |
3018 | \r | |
3019 | /**\r | |
3020 | Function to process a NSH script file.\r | |
3021 | \r | |
3022 | @param[in] ScriptPath Pointer to the script file name (including file system path).\r | |
e958b946 JC |
3023 | @param[in] Handle the handle of the script file already opened.\r |
3024 | @param[in] CmdLine the command line to run.\r | |
3025 | @param[in] ParamProtocol the shell parameters protocol pointer\r | |
a405b86d | 3026 | \r |
d08a5464 | 3027 | @retval EFI_SUCCESS the script completed successfully\r |
a405b86d | 3028 | **/\r |
3029 | EFI_STATUS\r | |
3030 | EFIAPI\r | |
3031 | RunScriptFile (\r | |
a308e058 RN |
3032 | IN CONST CHAR16 *ScriptPath,\r |
3033 | IN SHELL_FILE_HANDLE Handle OPTIONAL,\r | |
3034 | IN CONST CHAR16 *CmdLine,\r | |
3035 | IN EFI_SHELL_PARAMETERS_PROTOCOL *ParamProtocol\r | |
a405b86d | 3036 | )\r |
3037 | {\r | |
3038 | EFI_STATUS Status;\r | |
3039 | SHELL_FILE_HANDLE FileHandle;\r | |
e958b946 JC |
3040 | UINTN Argc;\r |
3041 | CHAR16 **Argv;\r | |
a405b86d | 3042 | \r |
3043 | if (ShellIsFile(ScriptPath) != EFI_SUCCESS) {\r | |
3044 | return (EFI_INVALID_PARAMETER);\r | |
3045 | }\r | |
3046 | \r | |
e958b946 JC |
3047 | //\r |
3048 | // get the argc and argv updated for scripts\r | |
3049 | //\r | |
d1c275c6 | 3050 | Status = UpdateArgcArgv(ParamProtocol, CmdLine, Script_File_Name, &Argv, &Argc);\r |
e958b946 | 3051 | if (!EFI_ERROR(Status)) {\r |
a405b86d | 3052 | \r |
e958b946 JC |
3053 | if (Handle == NULL) {\r |
3054 | //\r | |
3055 | // open the file\r | |
3056 | //\r | |
3057 | Status = ShellOpenFileByName(ScriptPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r | |
3058 | if (!EFI_ERROR(Status)) {\r | |
3059 | //\r | |
3060 | // run it\r | |
3061 | //\r | |
a308e058 | 3062 | Status = RunScriptFileHandle(FileHandle, ScriptPath);\r |
a405b86d | 3063 | \r |
e958b946 JC |
3064 | //\r |
3065 | // now close the file\r | |
3066 | //\r | |
3067 | ShellCloseFile(&FileHandle);\r | |
3068 | }\r | |
3069 | } else {\r | |
a308e058 | 3070 | Status = RunScriptFileHandle(Handle, ScriptPath);\r |
e958b946 JC |
3071 | }\r |
3072 | }\r | |
3073 | \r | |
3074 | //\r | |
d08a5464 | 3075 | // This is guaranteed to be called after UpdateArgcArgv no matter what else happened.\r |
e958b946 JC |
3076 | // This is safe even if the update API failed. In this case, it may be a no-op.\r |
3077 | //\r | |
3078 | RestoreArgcArgv(ParamProtocol, &Argv, &Argc);\r | |
a405b86d | 3079 | \r |
3080 | return (Status);\r | |
3081 | }\r | |
00534bc3 JC |
3082 | \r |
3083 | /**\r | |
d08a5464 | 3084 | Return the pointer to the first occurrence of any character from a list of characters.\r |
00534bc3 JC |
3085 | \r |
3086 | @param[in] String the string to parse\r | |
3087 | @param[in] CharacterList the list of character to look for\r | |
3088 | @param[in] EscapeCharacter An escape character to skip\r | |
3089 | \r | |
3090 | @return the location of the first character in the string\r | |
3091 | @retval CHAR_NULL no instance of any character in CharacterList was found in String\r | |
3092 | **/\r | |
3093 | CONST CHAR16*\r | |
3094 | EFIAPI\r | |
3095 | FindFirstCharacter(\r | |
3096 | IN CONST CHAR16 *String,\r | |
3097 | IN CONST CHAR16 *CharacterList,\r | |
3098 | IN CONST CHAR16 EscapeCharacter\r | |
3099 | )\r | |
3100 | {\r | |
3101 | UINT32 WalkChar;\r | |
3102 | UINT32 WalkStr;\r | |
3103 | \r | |
3104 | for (WalkStr = 0; WalkStr < StrLen(String); WalkStr++) {\r | |
3105 | if (String[WalkStr] == EscapeCharacter) {\r | |
3106 | WalkStr++;\r | |
3107 | continue;\r | |
3108 | }\r | |
3109 | for (WalkChar = 0; WalkChar < StrLen(CharacterList); WalkChar++) {\r | |
3110 | if (String[WalkStr] == CharacterList[WalkChar]) {\r | |
3111 | return (&String[WalkStr]);\r | |
3112 | }\r | |
3113 | }\r | |
3114 | }\r | |
3115 | return (String + StrLen(String));\r | |
88ff5ba7 | 3116 | }\r |