Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | This is THE shell (application)\r | |
3 | \r | |
ca79c798 | 4 | Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r |
ed34da40 | 5 | Copyright (c) 2013, Hewlett-Packard Development Company, L.P.\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 | |
36 | 0\r | |
37 | }},\r | |
a405b86d | 38 | 0,\r |
39 | NULL,\r | |
40 | NULL\r | |
41 | },\r | |
ce68d3bc | 42 | {{NULL, NULL}, NULL},\r |
a405b86d | 43 | {\r |
ce68d3bc | 44 | {{NULL, NULL}, NULL},\r |
a405b86d | 45 | 0,\r |
46 | 0,\r | |
47 | TRUE\r | |
48 | },\r | |
49 | NULL,\r | |
50 | 0,\r | |
51 | NULL,\r | |
52 | NULL,\r | |
53 | NULL,\r | |
54 | NULL,\r | |
55 | NULL,\r | |
ce68d3bc SZ |
56 | {{NULL, NULL}, NULL, NULL},\r |
57 | {{NULL, NULL}, NULL, NULL},\r | |
58 | NULL,\r | |
59 | NULL,\r | |
60 | NULL,\r | |
61 | NULL,\r | |
8be0ba36 | 62 | NULL,\r |
63 | NULL,\r | |
64 | NULL,\r | |
a49f6a2f | 65 | NULL,\r |
66 | FALSE\r | |
a405b86d | 67 | };\r |
68 | \r | |
69 | STATIC CONST CHAR16 mScriptExtension[] = L".NSH";\r | |
70 | STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI";\r | |
3c865f20 | 71 | STATIC CONST CHAR16 mStartupScript[] = L"startup.nsh";\r |
a405b86d | 72 | \r |
ad2bc854 JC |
73 | /**\r |
74 | Cleans off leading and trailing spaces and tabs\r | |
75 | \r | |
76 | @param[in] String pointer to the string to trim them off\r | |
77 | **/\r | |
78 | EFI_STATUS\r | |
79 | EFIAPI\r | |
80 | TrimSpaces(\r | |
81 | IN CHAR16 **String\r | |
82 | )\r | |
83 | {\r | |
84 | ASSERT(String != NULL);\r | |
85 | ASSERT(*String!= NULL);\r | |
86 | //\r | |
87 | // Remove any spaces and tabs at the beginning of the (*String).\r | |
88 | //\r | |
89 | while (((*String)[0] == L' ') || ((*String)[0] == L'\t')) {\r | |
90 | CopyMem((*String), (*String)+1, StrSize((*String)) - sizeof((*String)[0]));\r | |
91 | }\r | |
92 | \r | |
93 | //\r | |
94 | // Remove any spaces at the end of the (*String).\r | |
95 | //\r | |
96 | while ((*String)[StrLen((*String))-1] == L' ') {\r | |
97 | (*String)[StrLen((*String))-1] = CHAR_NULL;\r | |
98 | }\r | |
99 | \r | |
100 | return (EFI_SUCCESS);\r | |
101 | }\r | |
102 | \r | |
19a44972 | 103 | /**\r |
518c8cdc | 104 | Find a command line contains a split operation\r |
19a44972 JC |
105 | \r |
106 | @param[in] CmdLine The command line to parse.\r | |
107 | \r | |
518c8cdc | 108 | @retval A pointer to the | character in CmdLine or NULL if not present.\r |
19a44972 | 109 | **/\r |
321a8d49 JC |
110 | CONST\r |
111 | CHAR16*\r | |
19a44972 | 112 | EFIAPI\r |
518c8cdc | 113 | FindSplit(\r |
19a44972 JC |
114 | IN CONST CHAR16 *CmdLine\r |
115 | )\r | |
116 | {\r | |
117 | CONST CHAR16 *TempSpot;\r | |
118 | TempSpot = NULL;\r | |
119 | if (StrStr(CmdLine, L"|") != NULL) {\r | |
120 | for (TempSpot = CmdLine ; TempSpot != NULL && *TempSpot != CHAR_NULL ; TempSpot++) {\r | |
121 | if (*TempSpot == L'^' && *(TempSpot+1) == L'|') {\r | |
122 | TempSpot++;\r | |
123 | } else if (*TempSpot == L'|') {\r | |
124 | break;\r | |
125 | }\r | |
126 | }\r | |
127 | }\r | |
518c8cdc JC |
128 | return (TempSpot);\r |
129 | }\r | |
130 | \r | |
131 | /**\r | |
132 | Determine if a command line contains a split operation\r | |
133 | \r | |
134 | @param[in] CmdLine The command line to parse.\r | |
135 | \r | |
136 | @retval TRUE CmdLine has a valid split.\r | |
137 | @retval FALSE CmdLine does not have a valid split.\r | |
138 | **/\r | |
139 | BOOLEAN\r | |
140 | EFIAPI\r | |
141 | ContainsSplit(\r | |
142 | IN CONST CHAR16 *CmdLine\r | |
143 | )\r | |
144 | {\r | |
145 | CONST CHAR16 *TempSpot;\r | |
146 | TempSpot = FindSplit(CmdLine);\r | |
19a44972 JC |
147 | return (TempSpot != NULL && *TempSpot != CHAR_NULL);\r |
148 | }\r | |
149 | \r | |
733f138d | 150 | /**\r |
151 | Function to start monitoring for CTRL-S using SimpleTextInputEx. This \r | |
152 | feature's enabled state was not known when the shell initially launched.\r | |
153 | \r | |
154 | @retval EFI_SUCCESS The feature is enabled.\r | |
155 | @retval EFI_OUT_OF_RESOURCES There is not enough mnemory available.\r | |
156 | **/\r | |
157 | EFI_STATUS\r | |
158 | EFIAPI\r | |
159 | InternalEfiShellStartCtrlSMonitor(\r | |
160 | VOID\r | |
161 | )\r | |
162 | {\r | |
163 | EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r | |
164 | EFI_KEY_DATA KeyData;\r | |
165 | EFI_STATUS Status;\r | |
166 | \r | |
167 | Status = gBS->OpenProtocol(\r | |
168 | gST->ConsoleInHandle,\r | |
169 | &gEfiSimpleTextInputExProtocolGuid,\r | |
170 | (VOID**)&SimpleEx,\r | |
171 | gImageHandle,\r | |
172 | NULL,\r | |
173 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
174 | if (EFI_ERROR(Status)) {\r | |
175 | ShellPrintHiiEx(\r | |
176 | -1, \r | |
177 | -1, \r | |
178 | NULL,\r | |
179 | STRING_TOKEN (STR_SHELL_NO_IN_EX),\r | |
180 | ShellInfoObject.HiiHandle);\r | |
181 | return (EFI_SUCCESS);\r | |
182 | }\r | |
183 | \r | |
184 | KeyData.KeyState.KeyToggleState = 0;\r | |
185 | KeyData.Key.ScanCode = 0;\r | |
186 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r | |
187 | KeyData.Key.UnicodeChar = L's';\r | |
188 | \r | |
189 | Status = SimpleEx->RegisterKeyNotify(\r | |
190 | SimpleEx,\r | |
191 | &KeyData,\r | |
192 | NotificationFunction,\r | |
193 | &ShellInfoObject.CtrlSNotifyHandle1);\r | |
194 | \r | |
195 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r | |
196 | if (!EFI_ERROR(Status)) {\r | |
197 | Status = SimpleEx->RegisterKeyNotify(\r | |
198 | SimpleEx,\r | |
199 | &KeyData,\r | |
200 | NotificationFunction,\r | |
201 | &ShellInfoObject.CtrlSNotifyHandle2);\r | |
202 | }\r | |
203 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r | |
204 | KeyData.Key.UnicodeChar = 19;\r | |
205 | \r | |
206 | if (!EFI_ERROR(Status)) {\r | |
207 | Status = SimpleEx->RegisterKeyNotify(\r | |
208 | SimpleEx,\r | |
209 | &KeyData,\r | |
210 | NotificationFunction,\r | |
ed8b5297 | 211 | &ShellInfoObject.CtrlSNotifyHandle3);\r |
733f138d | 212 | } \r |
213 | KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r | |
214 | if (!EFI_ERROR(Status)) {\r | |
215 | Status = SimpleEx->RegisterKeyNotify(\r | |
216 | SimpleEx,\r | |
217 | &KeyData,\r | |
218 | NotificationFunction,\r | |
ed8b5297 | 219 | &ShellInfoObject.CtrlSNotifyHandle4);\r |
733f138d | 220 | }\r |
221 | return (Status);\r | |
222 | }\r | |
223 | \r | |
224 | \r | |
225 | \r | |
a405b86d | 226 | /**\r |
227 | The entry point for the application.\r | |
228 | \r | |
229 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
230 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
231 | \r | |
232 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
233 | @retval other Some error occurs when executing this entry point.\r | |
234 | \r | |
235 | **/\r | |
236 | EFI_STATUS\r | |
237 | EFIAPI\r | |
238 | UefiMain (\r | |
239 | IN EFI_HANDLE ImageHandle,\r | |
240 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
241 | )\r | |
242 | {\r | |
a49f6a2f | 243 | EFI_STATUS Status;\r |
244 | CHAR16 *TempString;\r | |
245 | UINTN Size;\r | |
246 | EFI_HANDLE ConInHandle;\r | |
247 | EFI_SIMPLE_TEXT_INPUT_PROTOCOL *OldConIn;\r | |
a405b86d | 248 | \r |
249 | if (PcdGet8(PcdShellSupportLevel) > 3) {\r | |
250 | return (EFI_UNSUPPORTED);\r | |
251 | }\r | |
252 | \r | |
253 | //\r | |
254 | // Clear the screen\r | |
255 | //\r | |
256 | Status = gST->ConOut->ClearScreen(gST->ConOut);\r | |
3c865f20 | 257 | if (EFI_ERROR(Status)) {\r |
258 | return (Status);\r | |
259 | }\r | |
a405b86d | 260 | \r |
261 | //\r | |
262 | // Populate the global structure from PCDs\r | |
263 | //\r | |
264 | ShellInfoObject.ImageDevPath = NULL;\r | |
265 | ShellInfoObject.FileDevPath = NULL;\r | |
266 | ShellInfoObject.PageBreakEnabled = PcdGetBool(PcdShellPageBreakDefault);\r | |
267 | ShellInfoObject.ViewingSettings.InsertMode = PcdGetBool(PcdShellInsertModeDefault);\r | |
268 | ShellInfoObject.LogScreenCount = PcdGet8 (PcdShellScreenLogCount );\r | |
269 | \r | |
270 | //\r | |
271 | // verify we dont allow for spec violation\r | |
272 | //\r | |
273 | ASSERT(ShellInfoObject.LogScreenCount >= 3);\r | |
274 | \r | |
275 | //\r | |
276 | // Initialize the LIST ENTRY objects...\r | |
277 | //\r | |
278 | InitializeListHead(&ShellInfoObject.BufferToFreeList.Link);\r | |
279 | InitializeListHead(&ShellInfoObject.ViewingSettings.CommandHistory.Link);\r | |
280 | InitializeListHead(&ShellInfoObject.SplitList.Link);\r | |
281 | \r | |
282 | //\r | |
283 | // Check PCDs for optional features that are not implemented yet.\r | |
284 | //\r | |
285 | if ( PcdGetBool(PcdShellSupportOldProtocols)\r | |
286 | || !FeaturePcdGet(PcdShellRequireHiiPlatform)\r | |
287 | || FeaturePcdGet(PcdShellSupportFrameworkHii)\r | |
288 | ) {\r | |
289 | return (EFI_UNSUPPORTED);\r | |
290 | }\r | |
291 | \r | |
292 | //\r | |
293 | // turn off the watchdog timer\r | |
294 | //\r | |
295 | gBS->SetWatchdogTimer (0, 0, 0, NULL);\r | |
296 | \r | |
297 | //\r | |
298 | // install our console logger. This will keep a log of the output for back-browsing\r | |
299 | //\r | |
300 | Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);\r | |
3c865f20 | 301 | if (!EFI_ERROR(Status)) {\r |
302 | //\r | |
303 | // Enable the cursor to be visible\r | |
304 | //\r | |
305 | gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r | |
a405b86d | 306 | \r |
3c865f20 | 307 | //\r |
308 | // If supporting EFI 1.1 we need to install HII protocol\r | |
309 | // only do this if PcdShellRequireHiiPlatform == FALSE\r | |
310 | //\r | |
311 | // remove EFI_UNSUPPORTED check above when complete.\r | |
312 | ///@todo add support for Framework HII\r | |
a405b86d | 313 | \r |
3c865f20 | 314 | //\r |
315 | // install our (solitary) HII package\r | |
316 | //\r | |
317 | ShellInfoObject.HiiHandle = HiiAddPackages (&gEfiCallerIdGuid, gImageHandle, ShellStrings, NULL);\r | |
a405b86d | 318 | if (ShellInfoObject.HiiHandle == NULL) {\r |
3c865f20 | 319 | if (PcdGetBool(PcdShellSupportFrameworkHii)) {\r |
320 | ///@todo Add our package into Framework HII\r | |
321 | }\r | |
322 | if (ShellInfoObject.HiiHandle == NULL) {\r | |
323 | return (EFI_NOT_STARTED);\r | |
324 | }\r | |
a405b86d | 325 | }\r |
a405b86d | 326 | \r |
3c865f20 | 327 | //\r |
328 | // create and install the EfiShellParametersProtocol\r | |
329 | //\r | |
330 | Status = CreatePopulateInstallShellParametersProtocol(&ShellInfoObject.NewShellParametersProtocol, &ShellInfoObject.RootShellInstance);\r | |
331 | ASSERT_EFI_ERROR(Status);\r | |
332 | ASSERT(ShellInfoObject.NewShellParametersProtocol != NULL);\r | |
a405b86d | 333 | \r |
3c865f20 | 334 | //\r |
335 | // create and install the EfiShellProtocol\r | |
336 | //\r | |
337 | Status = CreatePopulateInstallShellProtocol(&ShellInfoObject.NewEfiShellProtocol);\r | |
338 | ASSERT_EFI_ERROR(Status);\r | |
339 | ASSERT(ShellInfoObject.NewEfiShellProtocol != NULL);\r | |
a405b86d | 340 | \r |
3c865f20 | 341 | //\r |
342 | // Now initialize the shell library (it requires Shell Parameters protocol)\r | |
343 | //\r | |
344 | Status = ShellInitialize();\r | |
345 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 346 | \r |
3c865f20 | 347 | Status = CommandInit();\r |
348 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 349 | \r |
3c865f20 | 350 | //\r |
351 | // Check the command line\r | |
352 | //\r | |
353 | Status = ProcessCommandLine();\r | |
a405b86d | 354 | \r |
3c865f20 | 355 | //\r |
356 | // If shell support level is >= 1 create the mappings and paths\r | |
357 | //\r | |
358 | if (PcdGet8(PcdShellSupportLevel) >= 1) {\r | |
359 | Status = ShellCommandCreateInitialMappingsAndPaths();\r | |
360 | }\r | |
a405b86d | 361 | \r |
3c865f20 | 362 | //\r |
363 | // save the device path for the loaded image and the device path for the filepath (under loaded image)\r | |
364 | // These are where to look for the startup.nsh file\r | |
365 | //\r | |
366 | Status = GetDevicePathsForImageAndFile(&ShellInfoObject.ImageDevPath, &ShellInfoObject.FileDevPath);\r | |
a405b86d | 367 | ASSERT_EFI_ERROR(Status);\r |
a405b86d | 368 | \r |
3c865f20 | 369 | //\r |
370 | // Display the version\r | |
371 | //\r | |
372 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion) {\r | |
373 | ShellPrintHiiEx (\r | |
374 | 0,\r | |
375 | gST->ConOut->Mode->CursorRow,\r | |
376 | NULL,\r | |
284e034f | 377 | STRING_TOKEN (STR_VER_OUTPUT_MAIN_SHELL),\r |
3c865f20 | 378 | ShellInfoObject.HiiHandle,\r |
379 | SupportLevel[PcdGet8(PcdShellSupportLevel)],\r | |
380 | gEfiShellProtocol->MajorVersion,\r | |
284e034f CP |
381 | gEfiShellProtocol->MinorVersion\r |
382 | );\r | |
383 | \r | |
384 | ShellPrintHiiEx (\r | |
385 | -1,\r | |
386 | -1,\r | |
387 | NULL,\r | |
388 | STRING_TOKEN (STR_VER_OUTPUT_MAIN_SUPPLIER),\r | |
389 | ShellInfoObject.HiiHandle,\r | |
390 | (CHAR16 *) PcdGetPtr (PcdShellSupplier)\r | |
391 | );\r | |
392 | \r | |
393 | ShellPrintHiiEx (\r | |
394 | -1,\r | |
395 | -1,\r | |
396 | NULL,\r | |
397 | STRING_TOKEN (STR_VER_OUTPUT_MAIN_UEFI),\r | |
398 | ShellInfoObject.HiiHandle,\r | |
3c865f20 | 399 | (gST->Hdr.Revision&0xffff0000)>>16,\r |
400 | (gST->Hdr.Revision&0x0000ffff),\r | |
401 | gST->FirmwareVendor,\r | |
402 | gST->FirmwareRevision\r | |
403 | );\r | |
404 | }\r | |
a405b86d | 405 | \r |
3c865f20 | 406 | //\r |
407 | // Display the mapping\r | |
408 | //\r | |
409 | if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {\r | |
410 | Status = RunCommand(L"map");\r | |
411 | ASSERT_EFI_ERROR(Status);\r | |
412 | }\r | |
a405b86d | 413 | \r |
3c865f20 | 414 | //\r |
415 | // init all the built in alias'\r | |
416 | //\r | |
417 | Status = SetBuiltInAlias();\r | |
418 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 419 | \r |
3c865f20 | 420 | //\r |
421 | // Initialize environment variables\r | |
422 | //\r | |
423 | if (ShellCommandGetProfileList() != NULL) {\r | |
424 | Status = InternalEfiShellSetEnv(L"profiles", ShellCommandGetProfileList(), TRUE);\r | |
425 | ASSERT_EFI_ERROR(Status);\r | |
426 | }\r | |
a405b86d | 427 | \r |
3c865f20 | 428 | Size = 100;\r |
429 | TempString = AllocateZeroPool(Size);\r | |
a405b86d | 430 | \r |
3c865f20 | 431 | UnicodeSPrint(TempString, Size, L"%d", PcdGet8(PcdShellSupportLevel));\r |
432 | Status = InternalEfiShellSetEnv(L"uefishellsupport", TempString, TRUE);\r | |
433 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 434 | \r |
3c865f20 | 435 | UnicodeSPrint(TempString, Size, L"%d.%d", ShellInfoObject.NewEfiShellProtocol->MajorVersion, ShellInfoObject.NewEfiShellProtocol->MinorVersion);\r |
436 | Status = InternalEfiShellSetEnv(L"uefishellversion", TempString, TRUE);\r | |
437 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 438 | \r |
3c865f20 | 439 | UnicodeSPrint(TempString, Size, L"%d.%d", (gST->Hdr.Revision & 0xFFFF0000) >> 16, gST->Hdr.Revision & 0x0000FFFF);\r |
440 | Status = InternalEfiShellSetEnv(L"uefiversion", TempString, TRUE);\r | |
441 | ASSERT_EFI_ERROR(Status);\r | |
a405b86d | 442 | \r |
3c865f20 | 443 | FreePool(TempString);\r |
a405b86d | 444 | \r |
3c865f20 | 445 | if (!EFI_ERROR(Status)) {\r |
446 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {\r | |
a405b86d | 447 | //\r |
3c865f20 | 448 | // Set up the event for CTRL-C monitoring...\r |
a405b86d | 449 | //\r |
8be0ba36 | 450 | Status = InernalEfiShellStartMonitor();\r |
3c865f20 | 451 | }\r |
452 | \r | |
733f138d | 453 | if (!EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r |
454 | //\r | |
455 | // Set up the event for CTRL-S monitoring...\r | |
456 | //\r | |
457 | Status = InternalEfiShellStartCtrlSMonitor();\r | |
458 | }\r | |
459 | \r | |
a49f6a2f | 460 | if (!EFI_ERROR(Status) && ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r |
461 | //\r | |
462 | // close off the gST->ConIn\r | |
463 | //\r | |
464 | OldConIn = gST->ConIn;\r | |
465 | ConInHandle = gST->ConsoleInHandle;\r | |
466 | gST->ConIn = CreateSimpleTextInOnFile((SHELL_FILE_HANDLE)&FileInterfaceNulFile, &gST->ConsoleInHandle);\r | |
467 | } else {\r | |
468 | OldConIn = NULL;\r | |
469 | ConInHandle = NULL;\r | |
470 | }\r | |
471 | \r | |
3c865f20 | 472 | if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {\r |
a405b86d | 473 | //\r |
3c865f20 | 474 | // process the startup script or launch the called app.\r |
a405b86d | 475 | //\r |
3c865f20 | 476 | Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);\r |
477 | }\r | |
a405b86d | 478 | \r |
ca79c798 | 479 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r |
a405b86d | 480 | //\r |
3c865f20 | 481 | // begin the UI waiting loop\r |
a405b86d | 482 | //\r |
3c865f20 | 483 | do {\r |
484 | //\r | |
485 | // clean out all the memory allocated for CONST <something> * return values\r | |
486 | // between each shell prompt presentation\r | |
487 | //\r | |
488 | if (!IsListEmpty(&ShellInfoObject.BufferToFreeList.Link)){\r | |
489 | FreeBufferList(&ShellInfoObject.BufferToFreeList);\r | |
490 | }\r | |
491 | \r | |
492 | //\r | |
493 | // Reset page break back to default.\r | |
494 | //\r | |
495 | ShellInfoObject.PageBreakEnabled = PcdGetBool(PcdShellPageBreakDefault);\r | |
496 | ShellInfoObject.ConsoleInfo->Enabled = TRUE;\r | |
497 | ShellInfoObject.ConsoleInfo->RowCounter = 0;\r | |
498 | \r | |
8be0ba36 | 499 | //\r |
500 | // Reset the CTRL-C event (yes we ignore the return values)\r | |
501 | //\r | |
502 | Status = gBS->CheckEvent (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak);\r | |
503 | \r | |
3c865f20 | 504 | //\r |
505 | // Display Prompt\r | |
506 | //\r | |
507 | Status = DoShellPrompt();\r | |
508 | } while (!ShellCommandGetExit());\r | |
509 | }\r | |
a49f6a2f | 510 | if (OldConIn != NULL && ConInHandle != NULL) {\r |
511 | CloseSimpleTextInOnFile (gST->ConIn);\r | |
512 | gST->ConIn = OldConIn;\r | |
513 | gST->ConsoleInHandle = ConInHandle;\r | |
514 | }\r | |
a405b86d | 515 | }\r |
516 | }\r | |
3c865f20 | 517 | \r |
a405b86d | 518 | //\r |
519 | // uninstall protocols / free memory / etc...\r | |
520 | //\r | |
521 | if (ShellInfoObject.UserBreakTimer != NULL) {\r | |
522 | gBS->CloseEvent(ShellInfoObject.UserBreakTimer);\r | |
523 | DEBUG_CODE(ShellInfoObject.UserBreakTimer = NULL;);\r | |
524 | }\r | |
a405b86d | 525 | if (ShellInfoObject.ImageDevPath != NULL) {\r |
526 | FreePool(ShellInfoObject.ImageDevPath);\r | |
527 | DEBUG_CODE(ShellInfoObject.ImageDevPath = NULL;);\r | |
528 | }\r | |
529 | if (ShellInfoObject.FileDevPath != NULL) {\r | |
530 | FreePool(ShellInfoObject.FileDevPath);\r | |
531 | DEBUG_CODE(ShellInfoObject.FileDevPath = NULL;);\r | |
532 | }\r | |
533 | if (ShellInfoObject.NewShellParametersProtocol != NULL) {\r | |
534 | CleanUpShellParametersProtocol(ShellInfoObject.NewShellParametersProtocol);\r | |
535 | DEBUG_CODE(ShellInfoObject.NewShellParametersProtocol = NULL;);\r | |
536 | }\r | |
537 | if (ShellInfoObject.NewEfiShellProtocol != NULL){\r | |
8be0ba36 | 538 | if (ShellInfoObject.NewEfiShellProtocol->IsRootShell()){\r |
92670471 | 539 | InternalEfiShellSetEnv(L"cwd", NULL, TRUE);\r |
8be0ba36 | 540 | }\r |
a405b86d | 541 | CleanUpShellProtocol(ShellInfoObject.NewEfiShellProtocol);\r |
542 | DEBUG_CODE(ShellInfoObject.NewEfiShellProtocol = NULL;);\r | |
543 | }\r | |
544 | \r | |
545 | if (!IsListEmpty(&ShellInfoObject.BufferToFreeList.Link)){\r | |
546 | FreeBufferList(&ShellInfoObject.BufferToFreeList);\r | |
547 | }\r | |
548 | \r | |
549 | if (!IsListEmpty(&ShellInfoObject.SplitList.Link)){\r | |
3c865f20 | 550 | ASSERT(FALSE); ///@todo finish this de-allocation.\r |
a405b86d | 551 | }\r |
552 | \r | |
553 | if (ShellInfoObject.ShellInitSettings.FileName != NULL) {\r | |
554 | FreePool(ShellInfoObject.ShellInitSettings.FileName);\r | |
555 | DEBUG_CODE(ShellInfoObject.ShellInitSettings.FileName = NULL;);\r | |
556 | }\r | |
557 | \r | |
558 | if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r | |
559 | FreePool(ShellInfoObject.ShellInitSettings.FileOptions);\r | |
560 | DEBUG_CODE(ShellInfoObject.ShellInitSettings.FileOptions = NULL;);\r | |
561 | }\r | |
562 | \r | |
563 | if (ShellInfoObject.HiiHandle != NULL) {\r | |
564 | HiiRemovePackages(ShellInfoObject.HiiHandle);\r | |
565 | DEBUG_CODE(ShellInfoObject.HiiHandle = NULL;);\r | |
566 | }\r | |
567 | \r | |
568 | if (!IsListEmpty(&ShellInfoObject.ViewingSettings.CommandHistory.Link)){\r | |
569 | FreeBufferList(&ShellInfoObject.ViewingSettings.CommandHistory);\r | |
570 | }\r | |
571 | \r | |
572 | ASSERT(ShellInfoObject.ConsoleInfo != NULL);\r | |
573 | if (ShellInfoObject.ConsoleInfo != NULL) {\r | |
574 | ConsoleLoggerUninstall(ShellInfoObject.ConsoleInfo);\r | |
575 | FreePool(ShellInfoObject.ConsoleInfo);\r | |
576 | DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;);\r | |
577 | }\r | |
578 | \r | |
b6b22b13 | 579 | if (ShellCommandGetExit()) {\r |
580 | return ((EFI_STATUS)ShellCommandGetExitCode());\r | |
581 | }\r | |
a405b86d | 582 | return (Status);\r |
583 | }\r | |
584 | \r | |
585 | /**\r | |
586 | Sets all the alias' that were registered with the ShellCommandLib library.\r | |
587 | \r | |
588 | @retval EFI_SUCCESS all init commands were run sucessfully.\r | |
589 | **/\r | |
590 | EFI_STATUS\r | |
591 | EFIAPI\r | |
592 | SetBuiltInAlias(\r | |
593 | )\r | |
594 | {\r | |
595 | EFI_STATUS Status;\r | |
596 | CONST ALIAS_LIST *List;\r | |
597 | ALIAS_LIST *Node;\r | |
598 | \r | |
599 | //\r | |
600 | // Get all the commands we want to run\r | |
601 | //\r | |
602 | List = ShellCommandGetInitAliasList();\r | |
603 | \r | |
604 | //\r | |
605 | // for each command in the List\r | |
606 | //\r | |
607 | for ( Node = (ALIAS_LIST*)GetFirstNode(&List->Link)\r | |
608 | ; !IsNull (&List->Link, &Node->Link)\r | |
609 | ; Node = (ALIAS_LIST *)GetNextNode(&List->Link, &Node->Link)\r | |
610 | ){\r | |
611 | //\r | |
612 | // install the alias'\r | |
613 | //\r | |
614 | Status = InternalSetAlias(Node->CommandString, Node->Alias, TRUE);\r | |
615 | ASSERT_EFI_ERROR(Status);\r | |
616 | }\r | |
617 | return (EFI_SUCCESS);\r | |
618 | }\r | |
619 | \r | |
620 | /**\r | |
621 | Internal function to determine if 2 command names are really the same.\r | |
622 | \r | |
623 | @param[in] Command1 The pointer to the first command name.\r | |
624 | @param[in] Command2 The pointer to the second command name.\r | |
625 | \r | |
626 | @retval TRUE The 2 command names are the same.\r | |
627 | @retval FALSE The 2 command names are not the same.\r | |
628 | **/\r | |
629 | BOOLEAN\r | |
630 | EFIAPI\r | |
631 | IsCommand(\r | |
632 | IN CONST CHAR16 *Command1,\r | |
633 | IN CONST CHAR16 *Command2\r | |
634 | )\r | |
635 | {\r | |
636 | if (StringNoCaseCompare(&Command1, &Command2) == 0) {\r | |
637 | return (TRUE);\r | |
638 | }\r | |
639 | return (FALSE);\r | |
640 | }\r | |
641 | \r | |
642 | /**\r | |
643 | Internal function to determine if a command is a script only command.\r | |
644 | \r | |
645 | @param[in] CommandName The pointer to the command name.\r | |
646 | \r | |
647 | @retval TRUE The command is a script only command.\r | |
648 | @retval FALSE The command is not a script only command.\r | |
649 | **/\r | |
650 | BOOLEAN\r | |
651 | EFIAPI\r | |
652 | IsScriptOnlyCommand(\r | |
653 | IN CONST CHAR16 *CommandName\r | |
654 | )\r | |
655 | {\r | |
656 | if (IsCommand(CommandName, L"for")\r | |
657 | ||IsCommand(CommandName, L"endfor")\r | |
658 | ||IsCommand(CommandName, L"if")\r | |
659 | ||IsCommand(CommandName, L"else")\r | |
660 | ||IsCommand(CommandName, L"endif")\r | |
661 | ||IsCommand(CommandName, L"goto")) {\r | |
662 | return (TRUE);\r | |
663 | }\r | |
664 | return (FALSE);\r | |
665 | }\r | |
666 | \r | |
a405b86d | 667 | /**\r |
668 | This function will populate the 2 device path protocol parameters based on the\r | |
669 | global gImageHandle. The DevPath will point to the device path for the handle that has\r | |
670 | loaded image protocol installed on it. The FilePath will point to the device path\r | |
671 | for the file that was loaded.\r | |
672 | \r | |
4ff7e37b ED |
673 | @param[in, out] DevPath On a sucessful return the device path to the loaded image.\r |
674 | @param[in, out] FilePath On a sucessful return the device path to the file.\r | |
a405b86d | 675 | \r |
676 | @retval EFI_SUCCESS The 2 device paths were sucessfully returned.\r | |
677 | @retval other A error from gBS->HandleProtocol.\r | |
678 | \r | |
679 | @sa HandleProtocol\r | |
680 | **/\r | |
681 | EFI_STATUS\r | |
682 | EFIAPI\r | |
683 | GetDevicePathsForImageAndFile (\r | |
684 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,\r | |
685 | IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath\r | |
686 | )\r | |
687 | {\r | |
688 | EFI_STATUS Status;\r | |
689 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
690 | EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath;\r | |
691 | \r | |
692 | ASSERT(DevPath != NULL);\r | |
693 | ASSERT(FilePath != NULL);\r | |
694 | \r | |
695 | Status = gBS->OpenProtocol (\r | |
696 | gImageHandle,\r | |
697 | &gEfiLoadedImageProtocolGuid,\r | |
698 | (VOID**)&LoadedImage,\r | |
699 | gImageHandle,\r | |
700 | NULL,\r | |
701 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
702 | );\r | |
703 | if (!EFI_ERROR (Status)) {\r | |
704 | Status = gBS->OpenProtocol (\r | |
705 | LoadedImage->DeviceHandle,\r | |
706 | &gEfiDevicePathProtocolGuid,\r | |
707 | (VOID**)&ImageDevicePath,\r | |
708 | gImageHandle,\r | |
709 | NULL,\r | |
710 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
711 | );\r | |
712 | if (!EFI_ERROR (Status)) {\r | |
713 | *DevPath = DuplicateDevicePath (ImageDevicePath);\r | |
714 | *FilePath = DuplicateDevicePath (LoadedImage->FilePath);\r | |
a49f6a2f | 715 | gBS->CloseProtocol(\r |
716 | LoadedImage->DeviceHandle,\r | |
717 | &gEfiDevicePathProtocolGuid,\r | |
718 | gImageHandle,\r | |
719 | NULL);\r | |
a405b86d | 720 | }\r |
721 | gBS->CloseProtocol(\r | |
722 | gImageHandle,\r | |
723 | &gEfiLoadedImageProtocolGuid,\r | |
724 | gImageHandle,\r | |
725 | NULL);\r | |
726 | }\r | |
727 | return (Status);\r | |
728 | }\r | |
729 | \r | |
730 | STATIC CONST SHELL_PARAM_ITEM mShellParamList[] = {\r | |
731 | {L"-nostartup", TypeFlag},\r | |
732 | {L"-startup", TypeFlag},\r | |
733 | {L"-noconsoleout", TypeFlag},\r | |
734 | {L"-noconsolein", TypeFlag},\r | |
735 | {L"-nointerrupt", TypeFlag},\r | |
736 | {L"-nomap", TypeFlag},\r | |
737 | {L"-noversion", TypeFlag},\r | |
738 | {L"-startup", TypeFlag},\r | |
739 | {L"-delay", TypeValue},\r | |
ca79c798 | 740 | {L"-_exit", TypeFlag},\r |
a405b86d | 741 | {NULL, TypeMax}\r |
742 | };\r | |
a49f6a2f | 743 | \r |
a405b86d | 744 | /**\r |
745 | Process all Uefi Shell 2.0 command line options.\r | |
746 | \r | |
747 | see Uefi Shell 2.0 section 3.2 for full details.\r | |
748 | \r | |
749 | the command line must resemble the following:\r | |
750 | \r | |
751 | shell.efi [ShellOpt-options] [options] [file-name [file-name-options]]\r | |
752 | \r | |
753 | ShellOpt-options Options which control the initialization behavior of the shell.\r | |
754 | These options are read from the EFI global variable "ShellOpt"\r | |
755 | and are processed before options or file-name.\r | |
756 | \r | |
757 | options Options which control the initialization behavior of the shell.\r | |
758 | \r | |
759 | file-name The name of a UEFI shell application or script to be executed\r | |
760 | after initialization is complete. By default, if file-name is\r | |
761 | specified, then -nostartup is implied. Scripts are not supported\r | |
762 | by level 0.\r | |
763 | \r | |
764 | file-name-options The command-line options that are passed to file-name when it\r | |
765 | is invoked.\r | |
766 | \r | |
767 | This will initialize the ShellInfoObject.ShellInitSettings global variable.\r | |
768 | \r | |
769 | @retval EFI_SUCCESS The variable is initialized.\r | |
770 | **/\r | |
771 | EFI_STATUS\r | |
772 | EFIAPI\r | |
773 | ProcessCommandLine(\r | |
774 | VOID\r | |
775 | )\r | |
776 | {\r | |
777 | EFI_STATUS Status;\r | |
778 | LIST_ENTRY *Package;\r | |
779 | UINTN Size;\r | |
780 | CONST CHAR16 *TempConst;\r | |
781 | UINTN Count;\r | |
782 | UINTN LoopVar;\r | |
783 | CHAR16 *ProblemParam;\r | |
733f138d | 784 | UINT64 Intermediate;\r |
a405b86d | 785 | \r |
786 | Package = NULL;\r | |
787 | ProblemParam = NULL;\r | |
788 | \r | |
789 | Status = ShellCommandLineParse (mShellParamList, &Package, NULL, FALSE);\r | |
790 | \r | |
791 | Count = 1;\r | |
792 | Size = 0;\r | |
793 | TempConst = ShellCommandLineGetRawValue(Package, Count++);\r | |
794 | if (TempConst != NULL && StrLen(TempConst)) {\r | |
733f138d | 795 | ShellInfoObject.ShellInitSettings.FileName = AllocateZeroPool(StrSize(TempConst));\r |
3c865f20 | 796 | if (ShellInfoObject.ShellInitSettings.FileName == NULL) {\r |
797 | return (EFI_OUT_OF_RESOURCES);\r | |
798 | }\r | |
a405b86d | 799 | StrCpy(ShellInfoObject.ShellInitSettings.FileName, TempConst);\r |
800 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = 1;\r | |
801 | for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r | |
802 | if (StrCmp(gEfiShellParametersProtocol->Argv[LoopVar], ShellInfoObject.ShellInitSettings.FileName)==0) {\r | |
803 | LoopVar++;\r | |
804 | //\r | |
805 | // We found the file... add the rest of the params...\r | |
806 | //\r | |
807 | for ( ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r | |
808 | ASSERT((ShellInfoObject.ShellInitSettings.FileOptions == NULL && Size == 0) || (ShellInfoObject.ShellInitSettings.FileOptions != NULL));\r | |
809 | StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,\r | |
810 | &Size,\r | |
811 | L" ",\r | |
812 | 0);\r | |
3c865f20 | 813 | if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r |
814 | SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);\r | |
815 | return (EFI_OUT_OF_RESOURCES);\r | |
816 | }\r | |
a405b86d | 817 | StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,\r |
818 | &Size,\r | |
819 | gEfiShellParametersProtocol->Argv[LoopVar],\r | |
820 | 0);\r | |
3c865f20 | 821 | if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r |
822 | SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);\r | |
823 | return (EFI_OUT_OF_RESOURCES);\r | |
824 | }\r | |
a405b86d | 825 | }\r |
826 | }\r | |
827 | }\r | |
828 | } else {\r | |
829 | ShellCommandLineFreeVarList(Package);\r | |
830 | Package = NULL;\r | |
831 | Status = ShellCommandLineParse (mShellParamList, &Package, &ProblemParam, FALSE);\r | |
832 | if (EFI_ERROR(Status)) {\r | |
833 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), ShellInfoObject.HiiHandle, ProblemParam);\r | |
834 | FreePool(ProblemParam);\r | |
835 | ShellCommandLineFreeVarList(Package);\r | |
836 | return (EFI_INVALID_PARAMETER);\r | |
837 | }\r | |
838 | }\r | |
839 | \r | |
840 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup = ShellCommandLineGetFlag(Package, L"-startup");\r | |
841 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = ShellCommandLineGetFlag(Package, L"-nostartup");\r | |
842 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut = ShellCommandLineGetFlag(Package, L"-noconsoleout");\r | |
843 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn = ShellCommandLineGetFlag(Package, L"-noconsolein");\r | |
844 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt = ShellCommandLineGetFlag(Package, L"-nointerrupt");\r | |
845 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap = ShellCommandLineGetFlag(Package, L"-nomap");\r | |
846 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion = ShellCommandLineGetFlag(Package, L"-noversion");\r | |
847 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay = ShellCommandLineGetFlag(Package, L"-delay");\r | |
ca79c798 | 848 | ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit = ShellCommandLineGetFlag(Package, L"-_exit");\r |
a405b86d | 849 | \r |
733f138d | 850 | ShellInfoObject.ShellInitSettings.Delay = 5;\r |
851 | \r | |
852 | if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {\r | |
853 | ShellInfoObject.ShellInitSettings.Delay = 0;\r | |
854 | } else if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay) {\r | |
a405b86d | 855 | TempConst = ShellCommandLineGetValue(Package, L"-delay");\r |
33c031ee | 856 | if (TempConst != NULL && *TempConst == L':') {\r |
733f138d | 857 | TempConst++;\r |
858 | }\r | |
859 | if (TempConst != NULL && !EFI_ERROR(ShellConvertStringToUint64(TempConst, &Intermediate, FALSE, FALSE))) {\r | |
860 | ShellInfoObject.ShellInitSettings.Delay = (UINTN)Intermediate;\r | |
a405b86d | 861 | }\r |
a405b86d | 862 | }\r |
a405b86d | 863 | ShellCommandLineFreeVarList(Package);\r |
864 | \r | |
865 | return (Status);\r | |
866 | }\r | |
867 | \r | |
868 | /**\r | |
869 | Handles all interaction with the default startup script.\r | |
870 | \r | |
871 | this will check that the correct command line parameters were passed, handle the delay, and then start running the script.\r | |
872 | \r | |
873 | @param ImagePath the path to the image for shell. first place to look for the startup script\r | |
874 | @param FilePath the path to the file for shell. second place to look for the startup script.\r | |
875 | \r | |
876 | @retval EFI_SUCCESS the variable is initialized.\r | |
877 | **/\r | |
878 | EFI_STATUS\r | |
879 | EFIAPI\r | |
880 | DoStartupScript(\r | |
881 | EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r | |
882 | EFI_DEVICE_PATH_PROTOCOL *FilePath\r | |
883 | )\r | |
884 | {\r | |
885 | EFI_STATUS Status;\r | |
886 | UINTN Delay;\r | |
887 | EFI_INPUT_KEY Key;\r | |
888 | SHELL_FILE_HANDLE FileHandle;\r | |
889 | EFI_DEVICE_PATH_PROTOCOL *NewPath;\r | |
890 | EFI_DEVICE_PATH_PROTOCOL *NamePath;\r | |
891 | CHAR16 *FileStringPath;\r | |
733f138d | 892 | CHAR16 *TempSpot;\r |
a405b86d | 893 | UINTN NewSize;\r |
733f138d | 894 | CONST CHAR16 *MapName;\r |
a405b86d | 895 | \r |
896 | Key.UnicodeChar = CHAR_NULL;\r | |
897 | Key.ScanCode = 0;\r | |
898 | FileHandle = NULL;\r | |
899 | \r | |
900 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup && ShellInfoObject.ShellInitSettings.FileName != NULL) {\r | |
901 | //\r | |
902 | // launch something else instead\r | |
903 | //\r | |
904 | NewSize = StrSize(ShellInfoObject.ShellInitSettings.FileName);\r | |
905 | if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r | |
906 | NewSize += StrSize(ShellInfoObject.ShellInitSettings.FileOptions) + sizeof(CHAR16);\r | |
907 | }\r | |
908 | FileStringPath = AllocateZeroPool(NewSize);\r | |
3c865f20 | 909 | if (FileStringPath == NULL) {\r |
910 | return (EFI_OUT_OF_RESOURCES);\r | |
911 | }\r | |
a405b86d | 912 | StrCpy(FileStringPath, ShellInfoObject.ShellInitSettings.FileName);\r |
913 | if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r | |
3c865f20 | 914 | StrCat(FileStringPath, L" ");\r |
a405b86d | 915 | StrCat(FileStringPath, ShellInfoObject.ShellInitSettings.FileOptions);\r |
916 | }\r | |
917 | Status = RunCommand(FileStringPath);\r | |
918 | FreePool(FileStringPath);\r | |
919 | return (Status);\r | |
920 | \r | |
921 | }\r | |
922 | \r | |
923 | //\r | |
924 | // for shell level 0 we do no scripts\r | |
925 | // Without the Startup bit overriding we allow for nostartup to prevent scripts\r | |
926 | //\r | |
927 | if ( (PcdGet8(PcdShellSupportLevel) < 1)\r | |
928 | || (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup)\r | |
929 | ){\r | |
930 | return (EFI_SUCCESS);\r | |
931 | }\r | |
932 | \r | |
5559a41a | 933 | gST->ConOut->EnableCursor(gST->ConOut, FALSE);\r |
a405b86d | 934 | //\r |
935 | // print out our warning and see if they press a key\r | |
936 | //\r | |
284e034f | 937 | for ( Status = EFI_UNSUPPORTED, Delay = ShellInfoObject.ShellInitSettings.Delay\r |
733f138d | 938 | ; Delay != 0 && EFI_ERROR(Status)\r |
a405b86d | 939 | ; Delay--\r |
940 | ){\r | |
284e034f CP |
941 | ShellPrintHiiEx(0, gST->ConOut->Mode->CursorRow, NULL, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION), ShellInfoObject.HiiHandle, Delay);\r |
942 | gBS->Stall (1000000);\r | |
733f138d | 943 | if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r |
944 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
945 | }\r | |
a405b86d | 946 | }\r |
947 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle);\r | |
5559a41a | 948 | gST->ConOut->EnableCursor(gST->ConOut, TRUE);\r |
a405b86d | 949 | \r |
950 | //\r | |
951 | // ESC was pressed\r | |
952 | //\r | |
953 | if (Status == EFI_SUCCESS && Key.UnicodeChar == 0 && Key.ScanCode == SCAN_ESC) {\r | |
954 | return (EFI_SUCCESS);\r | |
955 | }\r | |
956 | \r | |
a405b86d | 957 | //\r |
733f138d | 958 | // Try the first location (must be file system)\r |
a405b86d | 959 | //\r |
733f138d | 960 | MapName = ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath(&ImagePath);\r |
961 | if (MapName != NULL) {\r | |
962 | FileStringPath = NULL;\r | |
963 | NewSize = 0;\r | |
964 | FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, MapName, 0);\r | |
532691c8 | 965 | if (FileStringPath == NULL) {\r |
966 | Status = EFI_OUT_OF_RESOURCES;\r | |
967 | } else {\r | |
968 | TempSpot = StrStr(FileStringPath, L";");\r | |
969 | if (TempSpot != NULL) {\r | |
970 | *TempSpot = CHAR_NULL;\r | |
971 | }\r | |
972 | FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);\r | |
973 | PathRemoveLastItem(FileStringPath);\r | |
974 | FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);\r | |
975 | Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);\r | |
976 | FreePool(FileStringPath);\r | |
733f138d | 977 | }\r |
733f138d | 978 | }\r |
a405b86d | 979 | if (EFI_ERROR(Status)) {\r |
733f138d | 980 | NamePath = FileDevicePath (NULL, mStartupScript);\r |
981 | NewPath = AppendDevicePathNode (ImagePath, NamePath);\r | |
982 | FreePool(NamePath);\r | |
983 | \r | |
a405b86d | 984 | //\r |
733f138d | 985 | // Try the location\r |
a405b86d | 986 | //\r |
a405b86d | 987 | Status = InternalOpenFileDevicePath(NewPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r |
733f138d | 988 | FreePool(NewPath);\r |
a405b86d | 989 | }\r |
a405b86d | 990 | //\r |
991 | // If we got a file, run it\r | |
992 | //\r | |
733f138d | 993 | if (!EFI_ERROR(Status) && FileHandle != NULL) {\r |
3c865f20 | 994 | Status = RunScriptFileHandle (FileHandle, mStartupScript);\r |
a405b86d | 995 | ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);\r |
996 | } else {\r | |
3c865f20 | 997 | FileStringPath = ShellFindFilePath(mStartupScript);\r |
998 | if (FileStringPath == NULL) {\r | |
999 | //\r | |
1000 | // we return success since we dont need to have a startup script\r | |
1001 | //\r | |
1002 | Status = EFI_SUCCESS;\r | |
1003 | ASSERT(FileHandle == NULL);\r | |
1004 | } else {\r | |
1005 | Status = RunScriptFile(FileStringPath);\r | |
1006 | FreePool(FileStringPath);\r | |
1007 | }\r | |
a405b86d | 1008 | }\r |
1009 | \r | |
a405b86d | 1010 | \r |
1011 | return (Status);\r | |
1012 | }\r | |
1013 | \r | |
1014 | /**\r | |
1015 | Function to perform the shell prompt looping. It will do a single prompt,\r | |
1016 | dispatch the result, and then return. It is expected that the caller will\r | |
1017 | call this function in a loop many times.\r | |
1018 | \r | |
1019 | @retval EFI_SUCCESS\r | |
1020 | @retval RETURN_ABORTED\r | |
1021 | **/\r | |
1022 | EFI_STATUS\r | |
1023 | EFIAPI\r | |
1024 | DoShellPrompt (\r | |
1025 | VOID\r | |
1026 | )\r | |
1027 | {\r | |
1028 | UINTN Column;\r | |
1029 | UINTN Row;\r | |
1030 | CHAR16 *CmdLine;\r | |
1031 | CONST CHAR16 *CurDir;\r | |
1032 | UINTN BufferSize;\r | |
1033 | EFI_STATUS Status;\r | |
1034 | \r | |
1035 | CurDir = NULL;\r | |
1036 | \r | |
1037 | //\r | |
1038 | // Get screen setting to decide size of the command line buffer\r | |
1039 | //\r | |
1040 | gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Column, &Row);\r | |
1041 | BufferSize = Column * Row * sizeof (CHAR16);\r | |
1042 | CmdLine = AllocateZeroPool (BufferSize);\r | |
1043 | if (CmdLine == NULL) {\r | |
1044 | return EFI_OUT_OF_RESOURCES;\r | |
1045 | }\r | |
1046 | \r | |
1047 | CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd");\r | |
1048 | \r | |
1049 | //\r | |
1050 | // Prompt for input\r | |
1051 | //\r | |
1052 | gST->ConOut->SetCursorPosition (gST->ConOut, 0, gST->ConOut->Mode->CursorRow);\r | |
1053 | \r | |
1054 | if (CurDir != NULL && StrLen(CurDir) > 1) {\r | |
1055 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);\r | |
1056 | } else {\r | |
1057 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);\r | |
1058 | }\r | |
1059 | \r | |
1060 | //\r | |
1061 | // Read a line from the console\r | |
1062 | //\r | |
1063 | Status = ShellInfoObject.NewEfiShellProtocol->ReadFile(ShellInfoObject.NewShellParametersProtocol->StdIn, &BufferSize, CmdLine);\r | |
1064 | \r | |
1065 | //\r | |
1066 | // Null terminate the string and parse it\r | |
1067 | //\r | |
1068 | if (!EFI_ERROR (Status)) {\r | |
1069 | CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;\r | |
1070 | Status = RunCommand(CmdLine);\r | |
1071 | }\r | |
1072 | \r | |
1073 | //\r | |
1074 | // Done with this command\r | |
1075 | //\r | |
1076 | FreePool (CmdLine);\r | |
1077 | return Status;\r | |
1078 | }\r | |
1079 | \r | |
1080 | /**\r | |
1081 | Add a buffer to the Buffer To Free List for safely returning buffers to other\r | |
1082 | places without risking letting them modify internal shell information.\r | |
1083 | \r | |
1084 | @param Buffer Something to pass to FreePool when the shell is exiting.\r | |
1085 | **/\r | |
1086 | VOID*\r | |
1087 | EFIAPI\r | |
1088 | AddBufferToFreeList(\r | |
1089 | VOID *Buffer\r | |
1090 | )\r | |
1091 | {\r | |
1092 | BUFFER_LIST *BufferListEntry;\r | |
1093 | \r | |
1094 | if (Buffer == NULL) {\r | |
1095 | return (NULL);\r | |
1096 | }\r | |
1097 | \r | |
1098 | BufferListEntry = AllocateZeroPool(sizeof(BUFFER_LIST));\r | |
1099 | ASSERT(BufferListEntry != NULL);\r | |
1100 | BufferListEntry->Buffer = Buffer;\r | |
1101 | InsertTailList(&ShellInfoObject.BufferToFreeList.Link, &BufferListEntry->Link);\r | |
1102 | return (Buffer);\r | |
1103 | }\r | |
1104 | \r | |
1105 | /**\r | |
1106 | Add a buffer to the Line History List\r | |
1107 | \r | |
1108 | @param Buffer The line buffer to add.\r | |
1109 | **/\r | |
1110 | VOID\r | |
1111 | EFIAPI\r | |
1112 | AddLineToCommandHistory(\r | |
1113 | IN CONST CHAR16 *Buffer\r | |
1114 | )\r | |
1115 | {\r | |
1116 | BUFFER_LIST *Node;\r | |
1117 | \r | |
1118 | Node = AllocateZeroPool(sizeof(BUFFER_LIST));\r | |
1119 | ASSERT(Node != NULL);\r | |
1120 | Node->Buffer = AllocateZeroPool(StrSize(Buffer));\r | |
1121 | ASSERT(Node->Buffer != NULL);\r | |
1122 | StrCpy(Node->Buffer, Buffer);\r | |
1123 | \r | |
1124 | InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r | |
1125 | }\r | |
1126 | \r | |
1127 | /**\r | |
1128 | Checks if a string is an alias for another command. If yes, then it replaces the alias name\r | |
1129 | with the correct command name.\r | |
1130 | \r | |
4ff7e37b ED |
1131 | @param[in, out] CommandString Upon entry the potential alias. Upon return the\r |
1132 | command name if it was an alias. If it was not\r | |
1133 | an alias it will be unchanged. This function may\r | |
1134 | change the buffer to fit the command name.\r | |
a405b86d | 1135 | \r |
1136 | @retval EFI_SUCCESS The name was changed.\r | |
1137 | @retval EFI_SUCCESS The name was not an alias.\r | |
1138 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r | |
1139 | **/\r | |
1140 | EFI_STATUS\r | |
1141 | EFIAPI\r | |
1142 | ShellConvertAlias(\r | |
1143 | IN OUT CHAR16 **CommandString\r | |
1144 | )\r | |
1145 | {\r | |
1146 | CONST CHAR16 *NewString;\r | |
1147 | \r | |
1148 | NewString = ShellInfoObject.NewEfiShellProtocol->GetAlias(*CommandString, NULL);\r | |
1149 | if (NewString == NULL) {\r | |
1150 | return (EFI_SUCCESS);\r | |
1151 | }\r | |
1152 | FreePool(*CommandString);\r | |
733f138d | 1153 | *CommandString = AllocateZeroPool(StrSize(NewString));\r |
a405b86d | 1154 | if (*CommandString == NULL) {\r |
1155 | return (EFI_OUT_OF_RESOURCES);\r | |
1156 | }\r | |
1157 | StrCpy(*CommandString, NewString);\r | |
1158 | return (EFI_SUCCESS);\r | |
1159 | }\r | |
1160 | \r | |
1161 | /**\r | |
1162 | Function allocates a new command line and replaces all instances of environment\r | |
1163 | variable names that are correctly preset to their values.\r | |
1164 | \r | |
1165 | If the return value is not NULL the memory must be caller freed.\r | |
1166 | \r | |
1167 | @param[in] OriginalCommandLine The original command line\r | |
1168 | \r | |
1169 | @retval NULL An error ocurred.\r | |
1170 | @return The new command line with no environment variables present.\r | |
1171 | **/\r | |
1172 | CHAR16*\r | |
1173 | EFIAPI\r | |
1174 | ShellConvertVariables (\r | |
1175 | IN CONST CHAR16 *OriginalCommandLine\r | |
1176 | )\r | |
1177 | {\r | |
1178 | CONST CHAR16 *MasterEnvList;\r | |
1179 | UINTN NewSize;\r | |
1180 | CHAR16 *NewCommandLine1;\r | |
1181 | CHAR16 *NewCommandLine2;\r | |
1182 | CHAR16 *Temp;\r | |
df07baea | 1183 | CHAR16 *Temp2;\r |
a405b86d | 1184 | UINTN ItemSize;\r |
1185 | CHAR16 *ItemTemp;\r | |
1186 | SCRIPT_FILE *CurrentScriptFile;\r | |
1187 | ALIAS_LIST *AliasListNode;\r | |
1188 | \r | |
1189 | ASSERT(OriginalCommandLine != NULL);\r | |
1190 | \r | |
1191 | ItemSize = 0;\r | |
1192 | NewSize = StrSize(OriginalCommandLine);\r | |
1193 | CurrentScriptFile = ShellCommandGetCurrentScriptFile();\r | |
1194 | Temp = NULL;\r | |
1195 | \r | |
1196 | ///@todo update this to handle the %0 - %9 for scripting only (borrow from line 1256 area) ? ? ?\r | |
1197 | \r | |
1198 | //\r | |
1199 | // calculate the size required for the post-conversion string...\r | |
1200 | //\r | |
1201 | if (CurrentScriptFile != NULL) {\r | |
1202 | for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)\r | |
1203 | ; !IsNull(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r | |
1204 | ; AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r | |
1205 | ){\r | |
1206 | for (Temp = StrStr(OriginalCommandLine, AliasListNode->Alias)\r | |
1207 | ; Temp != NULL\r | |
1208 | ; Temp = StrStr(Temp+1, AliasListNode->Alias)\r | |
1209 | ){\r | |
1210 | //\r | |
1211 | // we need a preceeding and if there is space no ^ preceeding (if no space ignore)\r | |
1212 | //\r | |
1213 | if ((((Temp-OriginalCommandLine)>2) && *(Temp-2) != L'^') || ((Temp-OriginalCommandLine)<=2)) {\r | |
1214 | NewSize += StrSize(AliasListNode->CommandString);\r | |
1215 | }\r | |
1216 | }\r | |
1217 | }\r | |
1218 | }\r | |
1219 | \r | |
1220 | for (MasterEnvList = EfiShellGetEnv(NULL)\r | |
1221 | ; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL\r | |
1222 | ; MasterEnvList += StrLen(MasterEnvList) + 1\r | |
1223 | ){\r | |
1224 | if (StrSize(MasterEnvList) > ItemSize) {\r | |
1225 | ItemSize = StrSize(MasterEnvList);\r | |
1226 | }\r | |
1227 | for (Temp = StrStr(OriginalCommandLine, MasterEnvList)\r | |
1228 | ; Temp != NULL\r | |
1229 | ; Temp = StrStr(Temp+1, MasterEnvList)\r | |
1230 | ){\r | |
1231 | //\r | |
1232 | // we need a preceeding and following % and if there is space no ^ preceeding (if no space ignore)\r | |
1233 | //\r | |
1234 | if (*(Temp-1) == L'%' && *(Temp+StrLen(MasterEnvList)) == L'%' &&\r | |
1235 | ((((Temp-OriginalCommandLine)>2) && *(Temp-2) != L'^') || ((Temp-OriginalCommandLine)<=2))) {\r | |
1236 | NewSize+=StrSize(EfiShellGetEnv(MasterEnvList));\r | |
1237 | }\r | |
1238 | }\r | |
1239 | }\r | |
1240 | \r | |
a405b86d | 1241 | //\r |
1242 | // now do the replacements...\r | |
1243 | //\r | |
1244 | NewCommandLine1 = AllocateZeroPool(NewSize);\r | |
1245 | NewCommandLine2 = AllocateZeroPool(NewSize);\r | |
1246 | ItemTemp = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));\r | |
3c865f20 | 1247 | if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) {\r |
1248 | SHELL_FREE_NON_NULL(NewCommandLine1);\r | |
1249 | SHELL_FREE_NON_NULL(NewCommandLine2);\r | |
1250 | SHELL_FREE_NON_NULL(ItemTemp);\r | |
1251 | return (NULL);\r | |
1252 | }\r | |
a405b86d | 1253 | StrCpy(NewCommandLine1, OriginalCommandLine);\r |
1254 | for (MasterEnvList = EfiShellGetEnv(NULL)\r | |
1255 | ; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL\r | |
1256 | ; MasterEnvList += StrLen(MasterEnvList) + 1\r | |
1257 | ){\r | |
1258 | StrCpy(ItemTemp, L"%");\r | |
1259 | StrCat(ItemTemp, MasterEnvList);\r | |
1260 | StrCat(ItemTemp, L"%");\r | |
1261 | ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);\r | |
1262 | StrCpy(NewCommandLine1, NewCommandLine2);\r | |
1263 | }\r | |
1264 | if (CurrentScriptFile != NULL) {\r | |
1265 | for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)\r | |
1266 | ; !IsNull(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r | |
1267 | ; AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r | |
1268 | ){\r | |
1269 | ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);\r | |
1270 | StrCpy(NewCommandLine1, NewCommandLine2);\r | |
1271 | }\r | |
df07baea JC |
1272 | \r |
1273 | //\r | |
1274 | // Remove non-existant environment variables in scripts only\r | |
1275 | //\r | |
1276 | for (Temp = NewCommandLine1 ; Temp != NULL ; ) {\r | |
1277 | Temp = StrStr(Temp, L"%");\r | |
1278 | if (Temp == NULL) {\r | |
1279 | break;\r | |
1280 | }\r | |
1281 | while (*(Temp - 1) == L'^') {\r | |
1282 | Temp = StrStr(Temp + 1, L"%");\r | |
1283 | if (Temp == NULL) {\r | |
1284 | break;\r | |
1285 | }\r | |
1286 | }\r | |
1287 | if (Temp == NULL) {\r | |
1288 | break;\r | |
1289 | }\r | |
1290 | \r | |
1291 | Temp2 = StrStr(Temp + 1, L"%");\r | |
1292 | if (Temp2 == NULL) {\r | |
1293 | break;\r | |
1294 | }\r | |
1295 | while (*(Temp2 - 1) == L'^') {\r | |
1296 | Temp2 = StrStr(Temp2 + 1, L"%");\r | |
1297 | if (Temp2 == NULL) {\r | |
1298 | break;\r | |
1299 | }\r | |
1300 | }\r | |
1301 | if (Temp2 == NULL) {\r | |
1302 | break;\r | |
1303 | }\r | |
1304 | \r | |
1305 | Temp2++;\r | |
1306 | CopyMem(Temp, Temp2, StrSize(Temp2));\r | |
1307 | }\r | |
1308 | \r | |
a405b86d | 1309 | }\r |
1310 | \r | |
df07baea JC |
1311 | //\r |
1312 | // Now cleanup any straggler intentionally ignored "%" characters\r | |
1313 | //\r | |
1314 | ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);\r | |
1315 | StrCpy(NewCommandLine1, NewCommandLine2);\r | |
1316 | \r | |
a405b86d | 1317 | FreePool(NewCommandLine2);\r |
1318 | FreePool(ItemTemp);\r | |
1319 | \r | |
1320 | return (NewCommandLine1);\r | |
1321 | }\r | |
1322 | \r | |
1323 | /**\r | |
1324 | Internal function to run a command line with pipe usage.\r | |
1325 | \r | |
1326 | @param[in] CmdLine The pointer to the command line.\r | |
1327 | @param[in] StdIn The pointer to the Standard input.\r | |
1328 | @param[in] StdOut The pointer to the Standard output.\r | |
1329 | \r | |
1330 | @retval EFI_SUCCESS The split command is executed successfully.\r | |
1331 | @retval other Some error occurs when executing the split command.\r | |
1332 | **/\r | |
1333 | EFI_STATUS\r | |
1334 | EFIAPI\r | |
1335 | RunSplitCommand(\r | |
1336 | IN CONST CHAR16 *CmdLine,\r | |
1337 | IN SHELL_FILE_HANDLE *StdIn,\r | |
1338 | IN SHELL_FILE_HANDLE *StdOut\r | |
1339 | )\r | |
1340 | {\r | |
1341 | EFI_STATUS Status;\r | |
1342 | CHAR16 *NextCommandLine;\r | |
1343 | CHAR16 *OurCommandLine;\r | |
1344 | UINTN Size1;\r | |
1345 | UINTN Size2;\r | |
1346 | SPLIT_LIST *Split;\r | |
1347 | SHELL_FILE_HANDLE *TempFileHandle;\r | |
1348 | BOOLEAN Unicode;\r | |
1349 | \r | |
1350 | ASSERT(StdOut == NULL);\r | |
1351 | \r | |
1352 | ASSERT(StrStr(CmdLine, L"|") != NULL);\r | |
1353 | \r | |
1354 | Status = EFI_SUCCESS;\r | |
1355 | NextCommandLine = NULL;\r | |
1356 | OurCommandLine = NULL;\r | |
1357 | Size1 = 0;\r | |
1358 | Size2 = 0;\r | |
1359 | \r | |
1360 | NextCommandLine = StrnCatGrow(&NextCommandLine, &Size1, StrStr(CmdLine, L"|")+1, 0);\r | |
1361 | OurCommandLine = StrnCatGrow(&OurCommandLine , &Size2, CmdLine , StrStr(CmdLine, L"|") - CmdLine);\r | |
532691c8 | 1362 | \r |
1363 | if (NextCommandLine == NULL || OurCommandLine == NULL) {\r | |
1364 | SHELL_FREE_NON_NULL(OurCommandLine);\r | |
1365 | SHELL_FREE_NON_NULL(NextCommandLine);\r | |
1366 | return (EFI_OUT_OF_RESOURCES);\r | |
19216573 | 1367 | } else if (StrStr(OurCommandLine, L"|") != NULL || Size1 == 0 || Size2 == 0) {\r |
1368 | SHELL_FREE_NON_NULL(OurCommandLine);\r | |
1369 | SHELL_FREE_NON_NULL(NextCommandLine);\r | |
1370 | return (EFI_INVALID_PARAMETER);\r | |
1371 | } else if (NextCommandLine[0] != CHAR_NULL &&\r | |
a405b86d | 1372 | NextCommandLine[0] == L'a' &&\r |
1373 | NextCommandLine[1] == L' '\r | |
1374 | ){\r | |
1375 | CopyMem(NextCommandLine, NextCommandLine+1, StrSize(NextCommandLine) - sizeof(NextCommandLine[0]));\r | |
1376 | Unicode = FALSE;\r | |
1377 | } else {\r | |
1378 | Unicode = TRUE;\r | |
1379 | }\r | |
1380 | \r | |
1381 | \r | |
1382 | //\r | |
1383 | // make a SPLIT_LIST item and add to list\r | |
1384 | //\r | |
1385 | Split = AllocateZeroPool(sizeof(SPLIT_LIST));\r | |
1386 | ASSERT(Split != NULL);\r | |
1387 | Split->SplitStdIn = StdIn;\r | |
1388 | Split->SplitStdOut = ConvertEfiFileProtocolToShellHandle(CreateFileInterfaceMem(Unicode), NULL);\r | |
1389 | ASSERT(Split->SplitStdOut != NULL);\r | |
1390 | InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link);\r | |
1391 | \r | |
a405b86d | 1392 | Status = RunCommand(OurCommandLine);\r |
1393 | \r | |
1394 | //\r | |
1395 | // move the output from the first to the in to the second.\r | |
1396 | //\r | |
1397 | TempFileHandle = Split->SplitStdOut;\r | |
1398 | if (Split->SplitStdIn == StdIn) {\r | |
1399 | Split->SplitStdOut = NULL;\r | |
1400 | } else {\r | |
1401 | Split->SplitStdOut = Split->SplitStdIn;\r | |
1402 | }\r | |
1403 | Split->SplitStdIn = TempFileHandle;\r | |
1404 | ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0);\r | |
1405 | \r | |
1406 | if (!EFI_ERROR(Status)) {\r | |
1407 | Status = RunCommand(NextCommandLine);\r | |
1408 | }\r | |
1409 | \r | |
1410 | //\r | |
1411 | // remove the top level from the ScriptList\r | |
1412 | //\r | |
1413 | ASSERT((SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link) == Split);\r | |
1414 | RemoveEntryList(&Split->Link);\r | |
1415 | \r | |
1416 | //\r | |
1417 | // Note that the original StdIn is now the StdOut...\r | |
1418 | //\r | |
1419 | if (Split->SplitStdOut != NULL && Split->SplitStdOut != StdIn) {\r | |
1420 | ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdOut));\r | |
1421 | }\r | |
1422 | if (Split->SplitStdIn != NULL) {\r | |
1423 | ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn));\r | |
1424 | }\r | |
1425 | \r | |
1426 | FreePool(Split);\r | |
1427 | FreePool(NextCommandLine);\r | |
1428 | FreePool(OurCommandLine);\r | |
1429 | \r | |
1430 | return (Status);\r | |
1431 | }\r | |
1432 | \r | |
1ef61d03 JC |
1433 | /**\r |
1434 | Take the original command line, substitute any variables, free \r | |
1435 | the original string, return the modified copy\r | |
1436 | \r | |
1437 | @param[in] CmdLine pointer to the command line to update\r | |
1438 | @param[out]CmdName upon successful return the name of the command to be run\r | |
1439 | \r | |
1440 | @retval EFI_SUCCESS the function was successful\r | |
1441 | @retval EFI_OUT_OF_RESOURCES a memory allocation failed\r | |
1442 | **/\r | |
1443 | EFI_STATUS\r | |
1444 | EFIAPI\r | |
1445 | ShellSubstituteVariables(\r | |
1446 | IN CHAR16 **CmdLine\r | |
1447 | )\r | |
1448 | {\r | |
1449 | CHAR16 *NewCmdLine;\r | |
1450 | NewCmdLine = ShellConvertVariables(*CmdLine);\r | |
1451 | SHELL_FREE_NON_NULL(*CmdLine);\r | |
1452 | if (NewCmdLine == NULL) {\r | |
1453 | return (EFI_OUT_OF_RESOURCES);\r | |
1454 | }\r | |
1455 | *CmdLine = NewCmdLine;\r | |
1456 | return (EFI_SUCCESS);\r | |
1457 | }\r | |
1458 | \r | |
ca53c0af JC |
1459 | /**\r |
1460 | Take the original command line, substitute any alias in the first group of space delimited characters, free \r | |
1461 | the original string, return the modified copy\r | |
1462 | \r | |
1463 | @param[in] CmdLine pointer to the command line to update\r | |
1464 | @param[out]CmdName upon successful return the name of the command to be run\r | |
1465 | \r | |
1466 | @retval EFI_SUCCESS the function was successful\r | |
1467 | @retval EFI_OUT_OF_RESOURCES a memory allocation failed\r | |
1468 | **/\r | |
1469 | EFI_STATUS\r | |
1470 | EFIAPI\r | |
1471 | ShellSubstituteAliases(\r | |
1472 | IN CHAR16 **CmdLine\r | |
1473 | )\r | |
1474 | {\r | |
1475 | CHAR16 *NewCmdLine;\r | |
1476 | CHAR16 *CommandName;\r | |
1477 | EFI_STATUS Status;\r | |
1478 | UINTN PostAliasSize;\r | |
1479 | ASSERT(CmdLine != NULL);\r | |
1480 | ASSERT(*CmdLine!= NULL);\r | |
1481 | \r | |
1482 | \r | |
1483 | CommandName = NULL;\r | |
1484 | if (StrStr((*CmdLine), L" ") == NULL){\r | |
1485 | StrnCatGrow(&CommandName, NULL, (*CmdLine), 0);\r | |
1486 | } else {\r | |
1487 | StrnCatGrow(&CommandName, NULL, (*CmdLine), StrStr((*CmdLine), L" ") - (*CmdLine));\r | |
1488 | }\r | |
1489 | \r | |
1490 | //\r | |
1491 | // This cannot happen 'inline' since the CmdLine can need extra space.\r | |
1492 | //\r | |
1493 | NewCmdLine = NULL;\r | |
1494 | if (!ShellCommandIsCommandOnList(CommandName)) {\r | |
1495 | //\r | |
1496 | // Convert via alias\r | |
1497 | //\r | |
1498 | Status = ShellConvertAlias(&CommandName);\r | |
1499 | if (EFI_ERROR(Status)){\r | |
1500 | return (Status);\r | |
1501 | }\r | |
1502 | PostAliasSize = 0;\r | |
1503 | NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, CommandName, 0);\r | |
1504 | if (NewCmdLine == NULL) {\r | |
1505 | SHELL_FREE_NON_NULL(CommandName);\r | |
1506 | SHELL_FREE_NON_NULL(*CmdLine);\r | |
1507 | return (EFI_OUT_OF_RESOURCES);\r | |
1508 | }\r | |
1509 | NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, StrStr((*CmdLine), L" "), 0);\r | |
1510 | if (NewCmdLine == NULL) {\r | |
1511 | SHELL_FREE_NON_NULL(CommandName);\r | |
1512 | SHELL_FREE_NON_NULL(*CmdLine);\r | |
1513 | return (EFI_OUT_OF_RESOURCES);\r | |
1514 | }\r | |
1515 | } else {\r | |
1516 | NewCmdLine = StrnCatGrow(&NewCmdLine, NULL, (*CmdLine), 0);\r | |
1517 | }\r | |
1518 | \r | |
1519 | SHELL_FREE_NON_NULL(*CmdLine);\r | |
1520 | SHELL_FREE_NON_NULL(CommandName);\r | |
1521 | \r | |
1522 | //\r | |
1523 | // re-assign the passed in double pointer to point to our newly allocated buffer\r | |
1524 | //\r | |
1525 | *CmdLine = NewCmdLine;\r | |
1526 | \r | |
1527 | return (EFI_SUCCESS);\r | |
1528 | }\r | |
1529 | \r | |
6ba2921d JC |
1530 | /**\r |
1531 | Takes the Argv[0] part of the command line and determine the meaning of it.\r | |
1532 | **/\r | |
1533 | SHELL_OPERATION_TYPES\r | |
1534 | EFIAPI\r | |
1535 | GetOperationType(\r | |
1536 | IN CONST CHAR16 *CmdName\r | |
1537 | )\r | |
1538 | {\r | |
1539 | CHAR16* FileWithPath;\r | |
1540 | CONST CHAR16* TempLocation;\r | |
1541 | CONST CHAR16* TempLocation2;\r | |
1542 | \r | |
1543 | FileWithPath = NULL;\r | |
1544 | //\r | |
1545 | // test for an internal command.\r | |
1546 | //\r | |
1547 | if (ShellCommandIsCommandOnList(CmdName)) {\r | |
1548 | return (INTERNAL_COMMAND);\r | |
1549 | }\r | |
1550 | \r | |
1551 | //\r | |
1552 | // Test for file system change request. anything ending with : and cant have spaces.\r | |
1553 | //\r | |
1554 | if (CmdName[(StrLen(CmdName)-1)] == L':') {\r | |
1555 | if (StrStr(CmdName, L" ") != NULL) {\r | |
1556 | return (UNKNOWN_INVALID);\r | |
1557 | }\r | |
1558 | return (FILE_SYS_CHANGE);\r | |
1559 | }\r | |
1560 | \r | |
1561 | //\r | |
1562 | // Test for a file\r | |
1563 | //\r | |
1564 | if ((FileWithPath = ShellFindFilePathEx(CmdName, mExecutableExtensions)) != NULL) {\r | |
1565 | //\r | |
1566 | // See if that file has a script file extension\r | |
1567 | //\r | |
1568 | if (StrLen(FileWithPath) > 4) {\r | |
1569 | TempLocation = FileWithPath+StrLen(FileWithPath)-4;\r | |
1570 | TempLocation2 = mScriptExtension;\r | |
1571 | if (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0) {\r | |
1572 | SHELL_FREE_NON_NULL(FileWithPath);\r | |
1573 | return (SCRIPT_FILE_NAME);\r | |
1574 | }\r | |
1575 | }\r | |
1576 | \r | |
1577 | //\r | |
1578 | // Was a file, but not a script. we treat this as an application.\r | |
1579 | //\r | |
1580 | SHELL_FREE_NON_NULL(FileWithPath);\r | |
1581 | return (EFI_APPLICATION);\r | |
1582 | }\r | |
1583 | \r | |
1584 | SHELL_FREE_NON_NULL(FileWithPath);\r | |
1585 | //\r | |
1586 | // No clue what this is... return invalid flag...\r | |
1587 | //\r | |
1588 | return (UNKNOWN_INVALID);\r | |
1589 | }\r | |
1590 | \r | |
680db511 JC |
1591 | /**\r |
1592 | **/\r | |
1593 | EFI_STATUS\r | |
1594 | EFIAPI\r | |
1595 | ProcessNewSplitCommandLine(\r | |
1596 | IN CONST CHAR16 *CmdLine\r | |
1597 | )\r | |
1598 | {\r | |
1599 | SPLIT_LIST *Split;\r | |
1600 | EFI_STATUS Status;\r | |
1601 | \r | |
1602 | Split = NULL;\r | |
1603 | \r | |
1604 | //\r | |
1605 | // are we in an existing split???\r | |
1606 | //\r | |
1607 | if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {\r | |
1608 | Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);\r | |
1609 | }\r | |
1610 | \r | |
1611 | if (Split == NULL) {\r | |
1612 | Status = RunSplitCommand(CmdLine, NULL, NULL);\r | |
1613 | } else {\r | |
1614 | Status = RunSplitCommand(CmdLine, Split->SplitStdIn, Split->SplitStdOut);\r | |
1615 | }\r | |
1616 | if (EFI_ERROR(Status)) {\r | |
1617 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine);\r | |
1618 | }\r | |
1619 | return (Status);\r | |
1620 | }\r | |
daf70584 JC |
1621 | \r |
1622 | /**\r | |
1623 | Handle a request to change the current file system\r | |
1624 | \r | |
1625 | @param[in] CmdLine The passed in command line\r | |
1626 | \r | |
1627 | @retval EFI_SUCCESS The operation was successful\r | |
1628 | **/\r | |
1629 | EFI_STATUS\r | |
1630 | EFIAPI\r | |
1631 | ChangeMappedDrive(\r | |
1632 | IN CONST CHAR16 *CmdLine\r | |
1633 | )\r | |
1634 | {\r | |
1635 | EFI_STATUS Status;\r | |
1636 | Status = EFI_SUCCESS;\r | |
1637 | \r | |
1638 | //\r | |
1639 | // make sure we are the right operation\r | |
1640 | //\r | |
1641 | ASSERT(CmdLine[(StrLen(CmdLine)-1)] == L':' && StrStr(CmdLine, L" ") == NULL);\r | |
1642 | \r | |
1643 | //\r | |
1644 | // Call the protocol API to do the work\r | |
1645 | //\r | |
1646 | Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, CmdLine);\r | |
1647 | \r | |
1648 | //\r | |
1649 | // Report any errors\r | |
1650 | //\r | |
1651 | if (EFI_ERROR(Status)) {\r | |
1652 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_MAPPING), ShellInfoObject.HiiHandle, CmdLine);\r | |
1653 | }\r | |
1654 | \r | |
1655 | return (Status);\r | |
1656 | }\r | |
1657 | \r | |
a405b86d | 1658 | /**\r |
1659 | Function will process and run a command line.\r | |
1660 | \r | |
1661 | This will determine if the command line represents an internal shell \r | |
1662 | command or dispatch an external application.\r | |
1663 | \r | |
1664 | @param[in] CmdLine The command line to parse.\r | |
1665 | \r | |
1666 | @retval EFI_SUCCESS The command was completed.\r | |
1667 | @retval EFI_ABORTED The command's operation was aborted.\r | |
1668 | **/\r | |
1669 | EFI_STATUS\r | |
1670 | EFIAPI\r | |
1671 | RunCommand(\r | |
1672 | IN CONST CHAR16 *CmdLine\r | |
1673 | )\r | |
1674 | {\r | |
1675 | EFI_STATUS Status;\r | |
64c7a749 | 1676 | EFI_STATUS StatusCode;\r |
a405b86d | 1677 | CHAR16 *CommandName;\r |
1678 | SHELL_STATUS ShellStatus;\r | |
1679 | UINTN Argc;\r | |
1680 | CHAR16 **Argv;\r | |
1681 | BOOLEAN LastError;\r | |
ed34da40 | 1682 | CHAR16 LeString[19];\r |
a405b86d | 1683 | CHAR16 *CommandWithPath;\r |
733f138d | 1684 | CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;\r |
a405b86d | 1685 | CONST CHAR16 *TempLocation;\r |
1686 | CONST CHAR16 *TempLocation2;\r | |
1687 | SHELL_FILE_HANDLE OriginalStdIn;\r | |
1688 | SHELL_FILE_HANDLE OriginalStdOut;\r | |
1689 | SHELL_FILE_HANDLE OriginalStdErr;\r | |
8be0ba36 | 1690 | SYSTEM_TABLE_INFO OriginalSystemTableInfo;\r |
a405b86d | 1691 | UINTN Count;\r |
1692 | UINTN Count2;\r | |
1693 | CHAR16 *CleanOriginal;\r | |
a405b86d | 1694 | \r |
1695 | ASSERT(CmdLine != NULL);\r | |
1696 | if (StrLen(CmdLine) == 0) {\r | |
1697 | return (EFI_SUCCESS);\r | |
1698 | }\r | |
1699 | \r | |
1700 | CommandName = NULL;\r | |
a405b86d | 1701 | CommandWithPath = NULL;\r |
1702 | DevPath = NULL;\r | |
1703 | Status = EFI_SUCCESS;\r | |
1704 | CleanOriginal = NULL;\r | |
a405b86d | 1705 | \r |
1706 | CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);\r | |
532691c8 | 1707 | if (CleanOriginal == NULL) {\r |
1708 | return (EFI_OUT_OF_RESOURCES);\r | |
1709 | }\r | |
284e034f | 1710 | \r |
ad2bc854 | 1711 | TrimSpaces(&CleanOriginal);\r |
a405b86d | 1712 | \r |
284e034f CP |
1713 | //\r |
1714 | // Handle case that passed in command line is just 1 or more " " characters.\r | |
1715 | //\r | |
1716 | if (StrLen (CleanOriginal) == 0) {\r | |
1717 | if (CleanOriginal != NULL) {\r | |
1718 | FreePool(CleanOriginal);\r | |
1719 | CleanOriginal = NULL;\r | |
1720 | }\r | |
1721 | return (EFI_SUCCESS);\r | |
1722 | }\r | |
1723 | \r | |
ca53c0af JC |
1724 | Status = ShellSubstituteAliases(&CleanOriginal);\r |
1725 | if (EFI_ERROR(Status)) {\r | |
1726 | return (Status);\r | |
a405b86d | 1727 | }\r |
1728 | \r | |
1ef61d03 JC |
1729 | Status = ShellSubstituteVariables(&CleanOriginal);\r |
1730 | if (EFI_ERROR(Status)) {\r | |
1731 | return (Status);\r | |
3c865f20 | 1732 | }\r |
1733 | \r | |
1ef61d03 | 1734 | TrimSpaces(&CleanOriginal);\r |
a405b86d | 1735 | \r |
1736 | //\r | |
1737 | // We dont do normal processing with a split command line (output from one command input to another)\r | |
1738 | //\r | |
1ef61d03 | 1739 | if (ContainsSplit(CleanOriginal)) {\r |
680db511 | 1740 | Status = ProcessNewSplitCommandLine(CleanOriginal);\r |
a405b86d | 1741 | } else {\r |
a405b86d | 1742 | //\r |
1743 | // If this is a mapped drive change handle that...\r | |
1744 | //\r | |
1ef61d03 | 1745 | if (CleanOriginal[(StrLen(CleanOriginal)-1)] == L':' && StrStr(CleanOriginal, L" ") == NULL) {\r |
daf70584 JC |
1746 | Status = ChangeMappedDrive(CleanOriginal);\r |
1747 | SHELL_FREE_NON_NULL(CleanOriginal);\r | |
a405b86d | 1748 | return (Status);\r |
1749 | }\r | |
1750 | \r | |
daf70584 | 1751 | \r |
a405b86d | 1752 | ///@todo update this section to divide into 3 ways - run internal command, run split (above), and run an external file...\r |
1753 | /// We waste a lot of time doing processing like StdIn,StdOut,Argv,Argc for things that are external files...\r | |
1754 | \r | |
1755 | \r | |
1756 | \r | |
1ef61d03 | 1757 | Status = UpdateStdInStdOutStdErr(ShellInfoObject.NewShellParametersProtocol, CleanOriginal, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r |
a405b86d | 1758 | if (EFI_ERROR(Status)) {\r |
733f138d | 1759 | if (Status == EFI_NOT_FOUND) {\r |
1760 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle);\r | |
1761 | } else {\r | |
1762 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);\r | |
1763 | }\r | |
a405b86d | 1764 | } else {\r |
1ef61d03 | 1765 | TrimSpaces(&CleanOriginal);\r |
ad2bc854 | 1766 | \r |
a405b86d | 1767 | //\r |
1768 | // get the argc and argv updated for internal commands\r | |
1769 | //\r | |
1ef61d03 | 1770 | Status = UpdateArgcArgv(ShellInfoObject.NewShellParametersProtocol, CleanOriginal, &Argv, &Argc);\r |
a405b86d | 1771 | ASSERT_EFI_ERROR(Status);\r |
1772 | \r | |
1773 | for (Count = 0 ; Count < ShellInfoObject.NewShellParametersProtocol->Argc ; Count++) {\r | |
1774 | if (StrStr(ShellInfoObject.NewShellParametersProtocol->Argv[Count], L"-?") == ShellInfoObject.NewShellParametersProtocol->Argv[Count]\r | |
1775 | || (ShellInfoObject.NewShellParametersProtocol->Argv[0][0] == L'?' && ShellInfoObject.NewShellParametersProtocol->Argv[0][1] == CHAR_NULL)\r | |
1776 | ) {\r | |
1777 | //\r | |
1778 | // We need to redo the arguments since a parameter was -?\r | |
1779 | // move them all down 1 to the end, then up one then replace the first with help\r | |
1780 | //\r | |
1781 | FreePool(ShellInfoObject.NewShellParametersProtocol->Argv[Count]);\r | |
1782 | ShellInfoObject.NewShellParametersProtocol->Argv[Count] = NULL;\r | |
1783 | for (Count2 = Count ; (Count2 + 1) < ShellInfoObject.NewShellParametersProtocol->Argc ; Count2++) {\r | |
1784 | ShellInfoObject.NewShellParametersProtocol->Argv[Count2] = ShellInfoObject.NewShellParametersProtocol->Argv[Count2+1];\r | |
1785 | }\r | |
1786 | ShellInfoObject.NewShellParametersProtocol->Argv[Count2] = NULL;\r | |
1787 | for (Count2 = ShellInfoObject.NewShellParametersProtocol->Argc -1 ; Count2 > 0 ; Count2--) {\r | |
1788 | ShellInfoObject.NewShellParametersProtocol->Argv[Count2] = ShellInfoObject.NewShellParametersProtocol->Argv[Count2-1];\r | |
1789 | }\r | |
1790 | ShellInfoObject.NewShellParametersProtocol->Argv[0] = NULL;\r | |
1791 | ShellInfoObject.NewShellParametersProtocol->Argv[0] = StrnCatGrow(&ShellInfoObject.NewShellParametersProtocol->Argv[0], NULL, L"help", 0);\r | |
1792 | break;\r | |
1793 | }\r | |
1794 | }\r | |
1795 | \r | |
1796 | //\r | |
1797 | // command or file?\r | |
1798 | //\r | |
1799 | if (ShellCommandIsCommandOnList(ShellInfoObject.NewShellParametersProtocol->Argv[0])) {\r | |
1800 | //\r | |
1801 | // Run the command (which was converted if it was an alias)\r | |
1802 | //\r | |
1803 | if (!EFI_ERROR(Status)) {\r | |
1804 | Status = ShellCommandRunCommandHandler(ShellInfoObject.NewShellParametersProtocol->Argv[0], &ShellStatus, &LastError);\r | |
1805 | ASSERT_EFI_ERROR(Status);\r | |
5b5cd144 CP |
1806 | \r |
1807 | if (sizeof(EFI_STATUS) == sizeof(UINT64)) {\r | |
1808 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellStatus);\r | |
1809 | } else {\r | |
1810 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ShellStatus);\r | |
1811 | }\r | |
1812 | DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r | |
a405b86d | 1813 | if (LastError) {\r |
5b5cd144 | 1814 | InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r |
a405b86d | 1815 | }\r |
1816 | //\r | |
1817 | // Pass thru the exitcode from the app.\r | |
1818 | //\r | |
1819 | if (ShellCommandGetExit()) {\r | |
1820 | Status = ShellStatus;\r | |
1821 | } else if (ShellStatus != 0 && IsScriptOnlyCommand(ShellInfoObject.NewShellParametersProtocol->Argv[0])) {\r | |
1822 | Status = EFI_ABORTED;\r | |
1823 | }\r | |
1824 | }\r | |
1825 | } else {\r | |
1826 | //\r | |
1827 | // run an external file (or script)\r | |
1828 | //\r | |
1829 | if (StrStr(ShellInfoObject.NewShellParametersProtocol->Argv[0], L":") != NULL) {\r | |
1830 | ASSERT (CommandWithPath == NULL);\r | |
1831 | if (ShellIsFile(ShellInfoObject.NewShellParametersProtocol->Argv[0]) == EFI_SUCCESS) {\r | |
1832 | CommandWithPath = StrnCatGrow(&CommandWithPath, NULL, ShellInfoObject.NewShellParametersProtocol->Argv[0], 0);\r | |
1833 | }\r | |
1834 | }\r | |
1835 | if (CommandWithPath == NULL) {\r | |
1836 | CommandWithPath = ShellFindFilePathEx(ShellInfoObject.NewShellParametersProtocol->Argv[0], mExecutableExtensions);\r | |
1837 | }\r | |
1838 | if (CommandWithPath == NULL || ShellIsDirectory(CommandWithPath) == EFI_SUCCESS) {\r | |
1839 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, ShellInfoObject.NewShellParametersProtocol->Argv[0]);\r | |
5b5cd144 CP |
1840 | \r |
1841 | if (sizeof(EFI_STATUS) == sizeof(UINT64)) {\r | |
1842 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", EFI_NOT_FOUND);\r | |
1843 | } else {\r | |
1844 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", EFI_NOT_FOUND);\r | |
1845 | }\r | |
1846 | DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r | |
1847 | InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r | |
a405b86d | 1848 | } else {\r |
1849 | //\r | |
1850 | // Check if it's a NSH (script) file.\r | |
1851 | //\r | |
1852 | TempLocation = CommandWithPath+StrLen(CommandWithPath)-4;\r | |
1853 | TempLocation2 = mScriptExtension;\r | |
1854 | if ((StrLen(CommandWithPath) > 4) && (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0)) {\r | |
1855 | Status = RunScriptFile (CommandWithPath);\r | |
1856 | } else {\r | |
1857 | DevPath = ShellInfoObject.NewEfiShellProtocol->GetDevicePathFromFilePath(CommandWithPath);\r | |
1858 | ASSERT(DevPath != NULL);\r | |
1859 | Status = InternalShellExecuteDevicePath(\r | |
1860 | &gImageHandle,\r | |
1861 | DevPath,\r | |
1ef61d03 | 1862 | CleanOriginal,\r |
a405b86d | 1863 | NULL,\r |
64c7a749 | 1864 | &StatusCode\r |
a405b86d | 1865 | );\r |
64c7a749 ED |
1866 | \r |
1867 | //\r | |
5b5cd144 | 1868 | // Update last error status.\r |
64c7a749 | 1869 | //\r |
5b5cd144 CP |
1870 | if (sizeof(EFI_STATUS) == sizeof(UINT64)) {\r |
1871 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", StatusCode);\r | |
1872 | } else {\r | |
1873 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", StatusCode);\r | |
1874 | }\r | |
1875 | DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r | |
1876 | InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r | |
a405b86d | 1877 | }\r |
1878 | }\r | |
1879 | }\r | |
64c7a749 ED |
1880 | \r |
1881 | //\r | |
1882 | // Print some error info.\r | |
1883 | //\r | |
1884 | if (EFI_ERROR(Status)) {\r | |
1885 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR), ShellInfoObject.HiiHandle, (VOID*)(Status));\r | |
1886 | }\r | |
1887 | \r | |
a405b86d | 1888 | CommandName = StrnCatGrow(&CommandName, NULL, ShellInfoObject.NewShellParametersProtocol->Argv[0], 0);\r |
1889 | \r | |
1890 | RestoreArgcArgv(ShellInfoObject.NewShellParametersProtocol, &Argv, &Argc);\r | |
1891 | \r | |
8be0ba36 | 1892 | RestoreStdInStdOutStdErr(ShellInfoObject.NewShellParametersProtocol, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r |
a405b86d | 1893 | }\r |
1894 | if (CommandName != NULL) {\r | |
1895 | if (ShellCommandGetCurrentScriptFile() != NULL && !IsScriptOnlyCommand(CommandName)) {\r | |
1896 | //\r | |
1897 | // if this is NOT a scipt only command return success so the script won't quit.\r | |
1898 | // prevent killing the script - this is the only place where we know the actual command name (after alias and variable replacement...)\r | |
1899 | //\r | |
1900 | Status = EFI_SUCCESS;\r | |
1901 | }\r | |
1902 | }\r | |
1903 | }\r | |
1904 | \r | |
1905 | SHELL_FREE_NON_NULL(CommandName);\r | |
1906 | SHELL_FREE_NON_NULL(CommandWithPath);\r | |
ca53c0af | 1907 | SHELL_FREE_NON_NULL(CleanOriginal);\r |
a405b86d | 1908 | \r |
1909 | return (Status);\r | |
1910 | }\r | |
1911 | \r | |
1912 | STATIC CONST UINT16 InvalidChars[] = {L'*', L'?', L'<', L'>', L'\\', L'/', L'\"', 0x0001, 0x0002};\r | |
1913 | /**\r | |
1914 | Function determins if the CommandName COULD be a valid command. It does not determine whether\r | |
1915 | this is a valid command. It only checks for invalid characters.\r | |
1916 | \r | |
1917 | @param[in] CommandName The name to check\r | |
1918 | \r | |
1919 | @retval TRUE CommandName could be a command name\r | |
1920 | @retval FALSE CommandName could not be a valid command name\r | |
1921 | **/\r | |
1922 | BOOLEAN\r | |
1923 | EFIAPI\r | |
1924 | IsValidCommandName(\r | |
1925 | IN CONST CHAR16 *CommandName\r | |
1926 | )\r | |
1927 | {\r | |
1928 | UINTN Count;\r | |
1929 | if (CommandName == NULL) {\r | |
1930 | ASSERT(FALSE);\r | |
1931 | return (FALSE);\r | |
1932 | }\r | |
1933 | for ( Count = 0\r | |
1934 | ; Count < sizeof(InvalidChars) / sizeof(InvalidChars[0])\r | |
1935 | ; Count++\r | |
1936 | ){\r | |
1937 | if (ScanMem16(CommandName, StrSize(CommandName), InvalidChars[Count]) != NULL) {\r | |
1938 | return (FALSE);\r | |
1939 | }\r | |
1940 | }\r | |
1941 | return (TRUE);\r | |
1942 | }\r | |
1943 | \r | |
1944 | /**\r | |
1945 | Function to process a NSH script file via SHELL_FILE_HANDLE.\r | |
1946 | \r | |
1947 | @param[in] Handle The handle to the already opened file.\r | |
1948 | @param[in] Name The name of the script file.\r | |
1949 | \r | |
1950 | @retval EFI_SUCCESS the script completed sucessfully\r | |
1951 | **/\r | |
1952 | EFI_STATUS\r | |
1953 | EFIAPI\r | |
1954 | RunScriptFileHandle (\r | |
1955 | IN SHELL_FILE_HANDLE Handle,\r | |
1956 | IN CONST CHAR16 *Name\r | |
1957 | )\r | |
1958 | {\r | |
1959 | EFI_STATUS Status;\r | |
1960 | SCRIPT_FILE *NewScriptFile;\r | |
1961 | UINTN LoopVar;\r | |
1962 | CHAR16 *CommandLine;\r | |
1963 | CHAR16 *CommandLine2;\r | |
1964 | CHAR16 *CommandLine3;\r | |
1965 | SCRIPT_COMMAND_LIST *LastCommand;\r | |
1966 | BOOLEAN Ascii;\r | |
1967 | BOOLEAN PreScriptEchoState;\r | |
848997b5 | 1968 | BOOLEAN PreCommandEchoState;\r |
a405b86d | 1969 | CONST CHAR16 *CurDir;\r |
1970 | UINTN LineCount;\r | |
b6b22b13 | 1971 | CHAR16 LeString[50];\r |
a405b86d | 1972 | \r |
1973 | ASSERT(!ShellCommandGetScriptExit());\r | |
1974 | \r | |
1975 | PreScriptEchoState = ShellCommandGetEchoState();\r | |
1976 | \r | |
1977 | NewScriptFile = (SCRIPT_FILE*)AllocateZeroPool(sizeof(SCRIPT_FILE));\r | |
3c865f20 | 1978 | if (NewScriptFile == NULL) {\r |
1979 | return (EFI_OUT_OF_RESOURCES);\r | |
1980 | }\r | |
a405b86d | 1981 | \r |
1982 | //\r | |
1983 | // Set up the name\r | |
1984 | //\r | |
1985 | ASSERT(NewScriptFile->ScriptName == NULL);\r | |
1986 | NewScriptFile->ScriptName = StrnCatGrow(&NewScriptFile->ScriptName, NULL, Name, 0);\r | |
3c865f20 | 1987 | if (NewScriptFile->ScriptName == NULL) {\r |
1988 | DeleteScriptFileStruct(NewScriptFile);\r | |
1989 | return (EFI_OUT_OF_RESOURCES);\r | |
1990 | }\r | |
a405b86d | 1991 | \r |
1992 | //\r | |
1993 | // Save the parameters (used to replace %0 to %9 later on)\r | |
1994 | //\r | |
1995 | NewScriptFile->Argc = ShellInfoObject.NewShellParametersProtocol->Argc;\r | |
1996 | if (NewScriptFile->Argc != 0) {\r | |
1997 | NewScriptFile->Argv = (CHAR16**)AllocateZeroPool(NewScriptFile->Argc * sizeof(CHAR16*));\r | |
3c865f20 | 1998 | if (NewScriptFile->Argv == NULL) {\r |
1999 | DeleteScriptFileStruct(NewScriptFile);\r | |
2000 | return (EFI_OUT_OF_RESOURCES);\r | |
2001 | }\r | |
a405b86d | 2002 | for (LoopVar = 0 ; LoopVar < 10 && LoopVar < NewScriptFile->Argc; LoopVar++) {\r |
2003 | ASSERT(NewScriptFile->Argv[LoopVar] == NULL);\r | |
2004 | NewScriptFile->Argv[LoopVar] = StrnCatGrow(&NewScriptFile->Argv[LoopVar], NULL, ShellInfoObject.NewShellParametersProtocol->Argv[LoopVar], 0);\r | |
3c865f20 | 2005 | if (NewScriptFile->Argv[LoopVar] == NULL) {\r |
2006 | DeleteScriptFileStruct(NewScriptFile);\r | |
2007 | return (EFI_OUT_OF_RESOURCES);\r | |
2008 | }\r | |
a405b86d | 2009 | }\r |
2010 | } else {\r | |
2011 | NewScriptFile->Argv = NULL;\r | |
2012 | }\r | |
2013 | \r | |
2014 | InitializeListHead(&NewScriptFile->CommandList);\r | |
2015 | InitializeListHead(&NewScriptFile->SubstList);\r | |
2016 | \r | |
2017 | //\r | |
2018 | // Now build the list of all script commands.\r | |
2019 | //\r | |
2020 | LineCount = 0;\r | |
2021 | while(!ShellFileHandleEof(Handle)) {\r | |
2022 | CommandLine = ShellFileHandleReturnLine(Handle, &Ascii);\r | |
2023 | LineCount++;\r | |
2024 | if (CommandLine == NULL || StrLen(CommandLine) == 0) {\r | |
2025 | continue;\r | |
2026 | }\r | |
2027 | NewScriptFile->CurrentCommand = AllocateZeroPool(sizeof(SCRIPT_COMMAND_LIST));\r | |
3c865f20 | 2028 | if (NewScriptFile->CurrentCommand == NULL) {\r |
2029 | DeleteScriptFileStruct(NewScriptFile);\r | |
2030 | return (EFI_OUT_OF_RESOURCES);\r | |
2031 | }\r | |
a405b86d | 2032 | \r |
2033 | NewScriptFile->CurrentCommand->Cl = CommandLine;\r | |
2034 | NewScriptFile->CurrentCommand->Data = NULL;\r | |
2035 | NewScriptFile->CurrentCommand->Line = LineCount;\r | |
2036 | \r | |
2037 | InsertTailList(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r | |
2038 | }\r | |
2039 | \r | |
2040 | //\r | |
2041 | // Add this as the topmost script file\r | |
2042 | //\r | |
2043 | ShellCommandSetNewScript (NewScriptFile);\r | |
2044 | \r | |
2045 | //\r | |
2046 | // Now enumerate through the commands and run each one.\r | |
2047 | //\r | |
733f138d | 2048 | CommandLine = AllocateZeroPool(PcdGet16(PcdShellPrintBufferSize));\r |
3c865f20 | 2049 | if (CommandLine == NULL) {\r |
2050 | DeleteScriptFileStruct(NewScriptFile);\r | |
2051 | return (EFI_OUT_OF_RESOURCES);\r | |
2052 | }\r | |
733f138d | 2053 | CommandLine2 = AllocateZeroPool(PcdGet16(PcdShellPrintBufferSize));\r |
3c865f20 | 2054 | if (CommandLine2 == NULL) {\r |
2055 | FreePool(CommandLine);\r | |
2056 | DeleteScriptFileStruct(NewScriptFile);\r | |
2057 | return (EFI_OUT_OF_RESOURCES);\r | |
2058 | }\r | |
a405b86d | 2059 | \r |
2060 | for ( NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetFirstNode(&NewScriptFile->CommandList)\r | |
2061 | ; !IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)\r | |
2062 | ; // conditional increment in the body of the loop\r | |
2063 | ){\r | |
3c865f20 | 2064 | ASSERT(CommandLine2 != NULL);\r |
a405b86d | 2065 | StrCpy(CommandLine2, NewScriptFile->CurrentCommand->Cl);\r |
2066 | \r | |
2067 | //\r | |
2068 | // NULL out comments\r | |
2069 | //\r | |
2070 | for (CommandLine3 = CommandLine2 ; CommandLine3 != NULL && *CommandLine3 != CHAR_NULL ; CommandLine3++) {\r | |
2071 | if (*CommandLine3 == L'^') {\r | |
2072 | if (*(CommandLine3+1) == L'#' || *(CommandLine3+1) == L':') {\r | |
2073 | CopyMem(CommandLine3, CommandLine3+1, StrSize(CommandLine3) - sizeof(CommandLine3[0]));\r | |
2074 | }\r | |
2075 | } else if (*CommandLine3 == L'#') {\r | |
2076 | *CommandLine3 = CHAR_NULL;\r | |
2077 | }\r | |
2078 | }\r | |
2079 | \r | |
2080 | if (CommandLine2 != NULL && StrLen(CommandLine2) >= 1) {\r | |
2081 | //\r | |
2082 | // Due to variability in starting the find and replace action we need to have both buffers the same.\r | |
2083 | //\r | |
2084 | StrCpy(CommandLine, CommandLine2);\r | |
2085 | \r | |
2086 | //\r | |
2087 | // Remove the %0 to %9 from the command line (if we have some arguments)\r | |
2088 | //\r | |
2089 | if (NewScriptFile->Argv != NULL) {\r | |
2090 | switch (NewScriptFile->Argc) {\r | |
2091 | default:\r | |
2092 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", NewScriptFile->Argv[9], FALSE, TRUE);\r | |
2093 | ASSERT_EFI_ERROR(Status);\r | |
2094 | case 9:\r | |
2095 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%8", NewScriptFile->Argv[8], FALSE, TRUE);\r | |
2096 | ASSERT_EFI_ERROR(Status);\r | |
2097 | case 8:\r | |
2098 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%7", NewScriptFile->Argv[7], FALSE, TRUE);\r | |
2099 | ASSERT_EFI_ERROR(Status);\r | |
2100 | case 7:\r | |
2101 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%6", NewScriptFile->Argv[6], FALSE, TRUE);\r | |
2102 | ASSERT_EFI_ERROR(Status);\r | |
2103 | case 6:\r | |
2104 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%5", NewScriptFile->Argv[5], FALSE, TRUE);\r | |
2105 | ASSERT_EFI_ERROR(Status);\r | |
2106 | case 5:\r | |
2107 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%4", NewScriptFile->Argv[4], FALSE, TRUE);\r | |
2108 | ASSERT_EFI_ERROR(Status);\r | |
2109 | case 4:\r | |
2110 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%3", NewScriptFile->Argv[3], FALSE, TRUE);\r | |
2111 | ASSERT_EFI_ERROR(Status);\r | |
2112 | case 3:\r | |
2113 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%2", NewScriptFile->Argv[2], FALSE, TRUE);\r | |
2114 | ASSERT_EFI_ERROR(Status);\r | |
2115 | case 2:\r | |
2116 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%1", NewScriptFile->Argv[1], FALSE, TRUE);\r | |
2117 | ASSERT_EFI_ERROR(Status);\r | |
2118 | case 1:\r | |
2119 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%0", NewScriptFile->Argv[0], FALSE, TRUE);\r | |
2120 | ASSERT_EFI_ERROR(Status);\r | |
2121 | break;\r | |
2122 | case 0:\r | |
2123 | break;\r | |
2124 | }\r | |
2125 | }\r | |
2126 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%1", L"\"\"", FALSE, FALSE);\r | |
2127 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%2", L"\"\"", FALSE, FALSE);\r | |
2128 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%3", L"\"\"", FALSE, FALSE);\r | |
2129 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%4", L"\"\"", FALSE, FALSE);\r | |
2130 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%5", L"\"\"", FALSE, FALSE);\r | |
2131 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%6", L"\"\"", FALSE, FALSE);\r | |
2132 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%7", L"\"\"", FALSE, FALSE);\r | |
2133 | Status = ShellCopySearchAndReplace(CommandLine, CommandLine2, PcdGet16 (PcdShellPrintBufferSize), L"%8", L"\"\"", FALSE, FALSE);\r | |
2134 | Status = ShellCopySearchAndReplace(CommandLine2, CommandLine, PcdGet16 (PcdShellPrintBufferSize), L"%9", L"\"\"", FALSE, FALSE);\r | |
2135 | \r | |
2136 | StrCpy(CommandLine2, CommandLine);\r | |
2137 | \r | |
2138 | LastCommand = NewScriptFile->CurrentCommand;\r | |
2139 | \r | |
2140 | for (CommandLine3 = CommandLine2 ; CommandLine3[0] == L' ' ; CommandLine3++);\r | |
2141 | \r | |
3c865f20 | 2142 | if (CommandLine3 != NULL && CommandLine3[0] == L':' ) {\r |
a405b86d | 2143 | //\r |
2144 | // This line is a goto target / label\r | |
2145 | //\r | |
2146 | } else {\r | |
2147 | if (CommandLine3 != NULL && StrLen(CommandLine3) > 0) {\r | |
848997b5 | 2148 | if (CommandLine3[0] == L'@') {\r |
2149 | //\r | |
2150 | // We need to save the current echo state\r | |
2151 | // and disable echo for just this command.\r | |
2152 | //\r | |
2153 | PreCommandEchoState = ShellCommandGetEchoState();\r | |
2154 | ShellCommandSetEchoState(FALSE);\r | |
2155 | Status = RunCommand(CommandLine3+1);\r | |
2156 | \r | |
2157 | //\r | |
284e034f | 2158 | // If command was "@echo -off" or "@echo -on" then don't restore echo state\r |
848997b5 | 2159 | //\r |
284e034f CP |
2160 | if (StrCmp (L"@echo -off", CommandLine3) != 0 &&\r |
2161 | StrCmp (L"@echo -on", CommandLine3) != 0) {\r | |
2162 | //\r | |
2163 | // Now restore the pre-'@' echo state.\r | |
2164 | //\r | |
2165 | ShellCommandSetEchoState(PreCommandEchoState);\r | |
2166 | }\r | |
848997b5 | 2167 | } else {\r |
0d11446d | 2168 | if (ShellCommandGetEchoState()) {\r |
2169 | CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd");\r | |
2170 | if (CurDir != NULL && StrLen(CurDir) > 1) {\r | |
2171 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);\r | |
2172 | } else {\r | |
2173 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);\r | |
2174 | }\r | |
2175 | ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2);\r | |
2176 | }\r | |
848997b5 | 2177 | Status = RunCommand(CommandLine3);\r |
2178 | }\r | |
a405b86d | 2179 | }\r |
2180 | \r | |
2181 | if (ShellCommandGetScriptExit()) {\r | |
5b5cd144 CP |
2182 | //\r |
2183 | // ShellCommandGetExitCode() always returns a UINT64\r | |
2184 | //\r | |
ed34da40 | 2185 | UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());\r |
5b5cd144 CP |
2186 | DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r |
2187 | InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r | |
b6b22b13 | 2188 | \r |
2189 | ShellCommandRegisterExit(FALSE, 0);\r | |
a405b86d | 2190 | Status = EFI_SUCCESS;\r |
2191 | break;\r | |
2192 | }\r | |
c6a7fef8 ED |
2193 | if (ShellGetExecutionBreakFlag()) {\r |
2194 | break;\r | |
2195 | }\r | |
a405b86d | 2196 | if (EFI_ERROR(Status)) {\r |
2197 | break;\r | |
2198 | }\r | |
2199 | if (ShellCommandGetExit()) {\r | |
2200 | break;\r | |
2201 | }\r | |
2202 | }\r | |
2203 | //\r | |
2204 | // If that commend did not update the CurrentCommand then we need to advance it...\r | |
2205 | //\r | |
2206 | if (LastCommand == NewScriptFile->CurrentCommand) {\r | |
2207 | NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r | |
2208 | if (!IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)) {\r | |
2209 | NewScriptFile->CurrentCommand->Reset = TRUE;\r | |
2210 | }\r | |
2211 | }\r | |
2212 | } else {\r | |
2213 | NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r | |
2214 | if (!IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)) {\r | |
2215 | NewScriptFile->CurrentCommand->Reset = TRUE;\r | |
2216 | }\r | |
2217 | }\r | |
2218 | }\r | |
2219 | \r | |
a405b86d | 2220 | \r |
2221 | FreePool(CommandLine);\r | |
2222 | FreePool(CommandLine2);\r | |
2223 | ShellCommandSetNewScript (NULL);\r | |
733f138d | 2224 | \r |
2225 | //\r | |
2226 | // Only if this was the last script reset the state.\r | |
2227 | //\r | |
2228 | if (ShellCommandGetCurrentScriptFile()==NULL) {\r | |
2229 | ShellCommandSetEchoState(PreScriptEchoState);\r | |
2230 | }\r | |
a405b86d | 2231 | return (EFI_SUCCESS);\r |
2232 | }\r | |
2233 | \r | |
2234 | /**\r | |
2235 | Function to process a NSH script file.\r | |
2236 | \r | |
2237 | @param[in] ScriptPath Pointer to the script file name (including file system path).\r | |
2238 | \r | |
2239 | @retval EFI_SUCCESS the script completed sucessfully\r | |
2240 | **/\r | |
2241 | EFI_STATUS\r | |
2242 | EFIAPI\r | |
2243 | RunScriptFile (\r | |
2244 | IN CONST CHAR16 *ScriptPath\r | |
2245 | )\r | |
2246 | {\r | |
2247 | EFI_STATUS Status;\r | |
2248 | SHELL_FILE_HANDLE FileHandle;\r | |
2249 | \r | |
2250 | if (ShellIsFile(ScriptPath) != EFI_SUCCESS) {\r | |
2251 | return (EFI_INVALID_PARAMETER);\r | |
2252 | }\r | |
2253 | \r | |
2254 | Status = ShellOpenFileByName(ScriptPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r | |
2255 | if (EFI_ERROR(Status)) {\r | |
2256 | return (Status);\r | |
2257 | }\r | |
2258 | \r | |
2259 | Status = RunScriptFileHandle(FileHandle, ScriptPath);\r | |
2260 | \r | |
2261 | ShellCloseFile(&FileHandle);\r | |
2262 | \r | |
2263 | return (Status);\r | |
2264 | }\r |