]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ConsoleWrappers.c
ShellPkg: Apply uncrustify changes
[mirror_edk2.git] / ShellPkg / Application / Shell / ConsoleWrappers.c
CommitLineData
8be0ba36 1/** @file\r
2 Function definitions for shell simple text in and out on top of file handles.\r
3\r
c011b6c9 4 (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r
ba0014b9 5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
56ba3746 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8be0ba36 7\r
8**/\r
9\r
8be0ba36 10#include "Shell.h"\r
11\r
47d20b54 12extern BOOLEAN AsciiRedirection;\r
48cb33ec 13\r
8be0ba36 14typedef struct {\r
47d20b54
MK
15 EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;\r
16 SHELL_FILE_HANDLE FileHandle;\r
17 EFI_HANDLE TheHandle;\r
18 UINT64 RemainingBytesOfInputFile;\r
8be0ba36 19} SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL;\r
20\r
21typedef struct {\r
47d20b54
MK
22 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut;\r
23 SHELL_FILE_HANDLE FileHandle;\r
24 EFI_HANDLE TheHandle;\r
25 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalSimpleTextOut;\r
8be0ba36 26} SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;\r
27\r
28/**\r
29 Event notification function for EFI_SIMPLE_TEXT_INPUT_PROTOCOL.WaitForKey event\r
30 Signal the event if there is key available\r
31\r
32 @param Event Indicates the event that invoke this function.\r
33 @param Context Indicates the calling context.\r
34\r
35**/\r
36VOID\r
37EFIAPI\r
38ConInWaitForKey (\r
47d20b54
MK
39 IN EFI_EVENT Event,\r
40 IN VOID *Context\r
8be0ba36 41 )\r
42{\r
2c86b6b7 43 gBS->SignalEvent (Event);\r
8be0ba36 44}\r
45\r
46/**\r
47 Reset function for the fake simple text input.\r
48\r
49 @param[in] This A pointer to the SimpleTextIn structure.\r
50 @param[in] ExtendedVerification TRUE for extra validation, FALSE otherwise.\r
51\r
52 @retval EFI_SUCCESS The reset was successful.\r
53**/\r
54EFI_STATUS\r
55EFIAPI\r
47d20b54
MK
56FileBasedSimpleTextInReset (\r
57 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
58 IN BOOLEAN ExtendedVerification\r
8be0ba36 59 )\r
60{\r
61 return (EFI_SUCCESS);\r
62}\r
63\r
64/**\r
65 ReadKeyStroke function for the fake simple text input.\r
66\r
4ff7e37b
ED
67 @param[in] This A pointer to the SimpleTextIn structure.\r
68 @param[in, out] Key A pointer to the Key structure to fill.\r
8be0ba36 69\r
70 @retval EFI_SUCCESS The read was successful.\r
71**/\r
72EFI_STATUS\r
73EFIAPI\r
47d20b54
MK
74FileBasedSimpleTextInReadKeyStroke (\r
75 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,\r
76 IN OUT EFI_INPUT_KEY *Key\r
8be0ba36 77 )\r
78{\r
47d20b54
MK
79 UINTN Size;\r
80 UINTN CharSize;\r
2c86b6b7
JC
81\r
82 //\r
83 // Verify the parameters\r
84 //\r
47d20b54 85 if ((Key == NULL) || (This == NULL)) {\r
8be0ba36 86 return (EFI_INVALID_PARAMETER);\r
87 }\r
2c86b6b7
JC
88\r
89 //\r
90 // Check if we have any characters left in the stream.\r
91 //\r
92 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile == 0) {\r
93 return (EFI_NOT_READY);\r
94 }\r
95\r
47d20b54 96 Size = sizeof (CHAR16);\r
2c86b6b7 97\r
47d20b54
MK
98 if (!AsciiRedirection) {\r
99 CharSize = sizeof (CHAR16);\r
48cb33ec 100 } else {\r
47d20b54 101 CharSize = sizeof (CHAR8);\r
ba0014b9 102 }\r
47d20b54 103\r
2c86b6b7
JC
104 //\r
105 // Decrement the amount of free space by Size or set to zero (for odd length files)\r
106 //\r
48cb33ec
QS
107 if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile > CharSize) {\r
108 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= CharSize;\r
2c86b6b7
JC
109 } else {\r
110 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile = 0;\r
111 }\r
112\r
8be0ba36 113 Key->ScanCode = 0;\r
47d20b54
MK
114 return (ShellInfoObject.NewEfiShellProtocol->ReadFile (\r
115 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->FileHandle,\r
116 &Size,\r
117 &Key->UnicodeChar\r
118 ));\r
8be0ba36 119}\r
120\r
121/**\r
ba0014b9 122 Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a\r
8be0ba36 123 SHELL_FILE_HANDLE to support redirecting input from a file.\r
124\r
125 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.\r
126 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.\r
127\r
128 @retval NULL There was insufficient memory available.\r
129 @return A pointer to the allocated protocol structure;\r
130**/\r
47d20b54
MK
131EFI_SIMPLE_TEXT_INPUT_PROTOCOL *\r
132CreateSimpleTextInOnFile (\r
8be0ba36 133 IN SHELL_FILE_HANDLE FileHandleToUse,\r
134 IN EFI_HANDLE *HandleLocation\r
135 )\r
136{\r
137 SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ProtocolToReturn;\r
138 EFI_STATUS Status;\r
2c86b6b7
JC
139 UINT64 CurrentPosition;\r
140 UINT64 FileSize;\r
8be0ba36 141\r
47d20b54 142 if ((HandleLocation == NULL) || (FileHandleToUse == NULL)) {\r
8be0ba36 143 return (NULL);\r
144 }\r
145\r
47d20b54 146 ProtocolToReturn = AllocateZeroPool (sizeof (SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL));\r
8be0ba36 147 if (ProtocolToReturn == NULL) {\r
148 return (NULL);\r
149 }\r
2c86b6b7 150\r
47d20b54
MK
151 ShellGetFileSize (FileHandleToUse, &FileSize);\r
152 ShellGetFilePosition (FileHandleToUse, &CurrentPosition);\r
2c86b6b7
JC
153\r
154 //\r
155 // Initialize the protocol members\r
156 //\r
157 ProtocolToReturn->RemainingBytesOfInputFile = FileSize - CurrentPosition;\r
158 ProtocolToReturn->FileHandle = FileHandleToUse;\r
8be0ba36 159 ProtocolToReturn->SimpleTextIn.Reset = FileBasedSimpleTextInReset;\r
160 ProtocolToReturn->SimpleTextIn.ReadKeyStroke = FileBasedSimpleTextInReadKeyStroke;\r
ba0014b9 161\r
8be0ba36 162 Status = gBS->CreateEvent (\r
163 EVT_NOTIFY_WAIT,\r
164 TPL_NOTIFY,\r
165 ConInWaitForKey,\r
166 &ProtocolToReturn->SimpleTextIn,\r
167 &ProtocolToReturn->SimpleTextIn.WaitForKey\r
168 );\r
169\r
47d20b54
MK
170 if (EFI_ERROR (Status)) {\r
171 FreePool (ProtocolToReturn);\r
8be0ba36 172 return (NULL);\r
173 }\r
47d20b54
MK
174\r
175 /// @todo possibly also install SimpleTextInputEx on the handle at this point.\r
176 Status = gBS->InstallProtocolInterface (\r
177 &(ProtocolToReturn->TheHandle),\r
178 &gEfiSimpleTextInProtocolGuid,\r
179 EFI_NATIVE_INTERFACE,\r
180 &(ProtocolToReturn->SimpleTextIn)\r
181 );\r
182 if (!EFI_ERROR (Status)) {\r
8be0ba36 183 *HandleLocation = ProtocolToReturn->TheHandle;\r
47d20b54 184 return ((EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)ProtocolToReturn);\r
8be0ba36 185 } else {\r
47d20b54 186 FreePool (ProtocolToReturn);\r
8be0ba36 187 return (NULL);\r
188 }\r
189}\r
190\r
191/**\r
ba0014b9 192 Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a\r
8be0ba36 193 SHELL_FILE_HANDLE to support redirecting input from a file.\r
194\r
195 @param[in] SimpleTextIn The pointer to the SimpleTextIn to close.\r
196\r
197 @retval EFI_SUCCESS The object was closed.\r
198**/\r
199EFI_STATUS\r
47d20b54 200CloseSimpleTextInOnFile (\r
8be0ba36 201 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleTextIn\r
202 )\r
203{\r
47d20b54
MK
204 EFI_STATUS Status;\r
205 EFI_STATUS Status1;\r
8be0ba36 206\r
207 if (SimpleTextIn == NULL) {\r
208 return (EFI_INVALID_PARAMETER);\r
209 }\r
210\r
47d20b54 211 Status = gBS->CloseEvent (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)SimpleTextIn)->SimpleTextIn.WaitForKey);\r
8be0ba36 212\r
47d20b54
MK
213 Status1 = gBS->UninstallProtocolInterface (\r
214 ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)SimpleTextIn)->TheHandle,\r
215 &gEfiSimpleTextInProtocolGuid,\r
216 &(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)SimpleTextIn)->SimpleTextIn)\r
217 );\r
8be0ba36 218\r
47d20b54
MK
219 FreePool (SimpleTextIn);\r
220 if (!EFI_ERROR (Status)) {\r
8be0ba36 221 return (Status1);\r
222 } else {\r
223 return (Status);\r
224 }\r
225}\r
226\r
227/**\r
6a5033ca 228 Reset the text output device hardware and optionally run diagnostics.\r
8be0ba36 229\r
230 @param This pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r
231 @param ExtendedVerification Indicates that a more extensive test may be performed\r
232\r
233 @retval EFI_SUCCESS The text output device was reset.\r
234**/\r
235EFI_STATUS\r
236EFIAPI\r
237FileBasedSimpleTextOutReset (\r
47d20b54
MK
238 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
239 IN BOOLEAN ExtendedVerification\r
8be0ba36 240 )\r
241{\r
242 return (EFI_SUCCESS);\r
243}\r
244\r
245/**\r
246 Verifies that all characters in a Unicode string can be output to the\r
247 target device.\r
248\r
249 @param[in] This Protocol instance pointer.\r
250 @param[in] WString The NULL-terminated Unicode string to be examined.\r
251\r
252 @retval EFI_SUCCESS The device(s) are capable of rendering the output string.\r
253**/\r
254EFI_STATUS\r
255EFIAPI\r
256FileBasedSimpleTextOutTestString (\r
47d20b54
MK
257 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
258 IN CHAR16 *WString\r
8be0ba36 259 )\r
260{\r
261 return (EFI_SUCCESS);\r
262}\r
263\r
264/**\r
265 Returns information for an available text mode that the output device(s)\r
266 supports.\r
267\r
268 @param[in] This Protocol instance pointer.\r
269 @param[in] ModeNumber The mode number to return information on.\r
270 @param[out] Columns Upon return, the number of columns in the selected geometry\r
271 @param[out] Rows Upon return, the number of rows in the selected geometry\r
272\r
273 @retval EFI_UNSUPPORTED The mode number was not valid.\r
274**/\r
275EFI_STATUS\r
276EFIAPI\r
277FileBasedSimpleTextOutQueryMode (\r
47d20b54
MK
278 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
279 IN UINTN ModeNumber,\r
280 OUT UINTN *Columns,\r
281 OUT UINTN *Rows\r
8be0ba36 282 )\r
283{\r
47d20b54 284 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *PassThruProtocol;\r
ba0014b9 285\r
6f05676d 286 PassThruProtocol = ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->OriginalSimpleTextOut;\r
ba0014b9 287\r
dcf9b428 288 // Pass the QueryMode call thru to the original SimpleTextOutProtocol\r
47d20b54
MK
289 return (PassThruProtocol->QueryMode (\r
290 PassThruProtocol,\r
291 ModeNumber,\r
292 Columns,\r
293 Rows\r
294 ));\r
8be0ba36 295}\r
296\r
297/**\r
298 Sets the output device(s) to a specified mode.\r
299\r
300 @param[in] This Protocol instance pointer.\r
301 @param[in] ModeNumber The mode number to set.\r
302\r
303 @retval EFI_UNSUPPORTED The mode number was not valid.\r
304**/\r
305EFI_STATUS\r
306EFIAPI\r
307FileBasedSimpleTextOutSetMode (\r
308 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
47d20b54 309 IN UINTN ModeNumber\r
8be0ba36 310 )\r
311{\r
312 return (EFI_UNSUPPORTED);\r
313}\r
314\r
315/**\r
316 Sets the background and foreground colors for the OutputString () and\r
317 ClearScreen () functions.\r
318\r
319 @param[in] This Protocol instance pointer.\r
320 @param[in] Attribute The attribute to set. Bits 0..3 are the foreground color, and\r
321 bits 4..6 are the background color. All other bits are undefined\r
322 and must be zero. The valid Attributes are defined in this file.\r
323\r
324 @retval EFI_SUCCESS The attribute was set.\r
325**/\r
326EFI_STATUS\r
327EFIAPI\r
328FileBasedSimpleTextOutSetAttribute (\r
47d20b54
MK
329 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
330 IN UINTN Attribute\r
8be0ba36 331 )\r
332{\r
333 return (EFI_SUCCESS);\r
334}\r
335\r
336/**\r
337 Clears the output device(s) display to the currently selected background\r
338 color.\r
339\r
340 @param[in] This Protocol instance pointer.\r
341\r
342 @retval EFI_UNSUPPORTED The output device is not in a valid text mode.\r
343**/\r
344EFI_STATUS\r
345EFIAPI\r
346FileBasedSimpleTextOutClearScreen (\r
347 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This\r
348 )\r
349{\r
350 return (EFI_SUCCESS);\r
351}\r
352\r
353/**\r
354 Sets the current coordinates of the cursor position\r
355\r
356 @param[in] This Protocol instance pointer.\r
357 @param[in] Column Column to put the cursor in. Must be between zero and Column returned from QueryMode\r
358 @param[in] Row Row to put the cursor in. Must be between zero and Row returned from QueryMode\r
359\r
360 @retval EFI_SUCCESS The operation completed successfully.\r
361**/\r
362EFI_STATUS\r
363EFIAPI\r
364FileBasedSimpleTextOutSetCursorPosition (\r
365 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
47d20b54
MK
366 IN UINTN Column,\r
367 IN UINTN Row\r
8be0ba36 368 )\r
369{\r
370 return (EFI_SUCCESS);\r
371}\r
372\r
373/**\r
374 Makes the cursor visible or invisible\r
375\r
376 @param[in] This Protocol instance pointer.\r
377 @param[in] Visible If TRUE, the cursor is set to be visible. If FALSE, the cursor is\r
378 set to be invisible.\r
379\r
380 @retval EFI_SUCCESS The operation completed successfully.\r
381**/\r
382EFI_STATUS\r
383EFIAPI\r
384FileBasedSimpleTextOutEnableCursor (\r
385 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
47d20b54 386 IN BOOLEAN Visible\r
8be0ba36 387 )\r
388{\r
389 return (EFI_SUCCESS);\r
390}\r
391\r
392/**\r
393 Write a Unicode string to the output device.\r
394\r
395 @param[in] This Protocol instance pointer.\r
396 @param[in] WString The NULL-terminated Unicode string to be displayed on the output\r
397 device(s). All output devices must also support the Unicode\r
398 drawing defined in this file.\r
399 @retval EFI_SUCCESS The string was output to the device.\r
400 @retval EFI_DEVICE_ERROR The device reported an error while attempting to output\r
401 the text.\r
402 @retval EFI_UNSUPPORTED The output device's mode is not currently in a\r
403 defined text mode.\r
404 @retval EFI_WARN_UNKNOWN_GLYPH This warning code indicates that some of the\r
405 characters in the Unicode string could not be\r
406 rendered and were skipped.\r
407**/\r
408EFI_STATUS\r
409EFIAPI\r
410FileBasedSimpleTextOutOutputString (\r
47d20b54
MK
411 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,\r
412 IN CHAR16 *WString\r
8be0ba36 413 )\r
414{\r
47d20b54
MK
415 UINTN Size;\r
416\r
417 Size = StrLen (WString) * sizeof (CHAR16);\r
418 return (ShellInfoObject.NewEfiShellProtocol->WriteFile (\r
419 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->FileHandle,\r
420 &Size,\r
421 WString\r
422 ));\r
8be0ba36 423}\r
424\r
425/**\r
ba0014b9 426 Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a\r
8be0ba36 427 SHELL_FILE_HANDLE to support redirecting output from a file.\r
428\r
dcf9b428
CP
429 @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.\r
430 @param[in] HandleLocation The pointer of a location to copy handle with protocol to.\r
431 @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.\r
8be0ba36 432\r
433 @retval NULL There was insufficient memory available.\r
434 @return A pointer to the allocated protocol structure;\r
435**/\r
47d20b54
MK
436EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *\r
437CreateSimpleTextOutOnFile (\r
438 IN SHELL_FILE_HANDLE FileHandleToUse,\r
439 IN EFI_HANDLE *HandleLocation,\r
440 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol\r
8be0ba36 441 )\r
442{\r
47d20b54
MK
443 SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ProtocolToReturn;\r
444 EFI_STATUS Status;\r
8be0ba36 445\r
47d20b54 446 if ((HandleLocation == NULL) || (FileHandleToUse == NULL)) {\r
8be0ba36 447 return (NULL);\r
448 }\r
449\r
47d20b54 450 ProtocolToReturn = AllocateZeroPool (sizeof (SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL));\r
8be0ba36 451 if (ProtocolToReturn == NULL) {\r
452 return (NULL);\r
453 }\r
47d20b54 454\r
8be0ba36 455 ProtocolToReturn->FileHandle = FileHandleToUse;\r
dcf9b428 456 ProtocolToReturn->OriginalSimpleTextOut = OriginalProtocol;\r
8be0ba36 457 ProtocolToReturn->SimpleTextOut.Reset = FileBasedSimpleTextOutReset;\r
458 ProtocolToReturn->SimpleTextOut.TestString = FileBasedSimpleTextOutTestString;\r
459 ProtocolToReturn->SimpleTextOut.QueryMode = FileBasedSimpleTextOutQueryMode;\r
460 ProtocolToReturn->SimpleTextOut.SetMode = FileBasedSimpleTextOutSetMode;\r
461 ProtocolToReturn->SimpleTextOut.SetAttribute = FileBasedSimpleTextOutSetAttribute;\r
462 ProtocolToReturn->SimpleTextOut.ClearScreen = FileBasedSimpleTextOutClearScreen;\r
463 ProtocolToReturn->SimpleTextOut.SetCursorPosition = FileBasedSimpleTextOutSetCursorPosition;\r
464 ProtocolToReturn->SimpleTextOut.EnableCursor = FileBasedSimpleTextOutEnableCursor;\r
465 ProtocolToReturn->SimpleTextOut.OutputString = FileBasedSimpleTextOutOutputString;\r
47d20b54 466 ProtocolToReturn->SimpleTextOut.Mode = AllocateZeroPool (sizeof (EFI_SIMPLE_TEXT_OUTPUT_MODE));\r
8be0ba36 467 if (ProtocolToReturn->SimpleTextOut.Mode == NULL) {\r
47d20b54 468 FreePool (ProtocolToReturn);\r
8be0ba36 469 return (NULL);\r
470 }\r
47d20b54 471\r
dcf9b428
CP
472 ProtocolToReturn->SimpleTextOut.Mode->MaxMode = OriginalProtocol->Mode->MaxMode;\r
473 ProtocolToReturn->SimpleTextOut.Mode->Mode = OriginalProtocol->Mode->Mode;\r
474 ProtocolToReturn->SimpleTextOut.Mode->Attribute = OriginalProtocol->Mode->Attribute;\r
475 ProtocolToReturn->SimpleTextOut.Mode->CursorColumn = OriginalProtocol->Mode->CursorColumn;\r
476 ProtocolToReturn->SimpleTextOut.Mode->CursorRow = OriginalProtocol->Mode->CursorRow;\r
477 ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = OriginalProtocol->Mode->CursorVisible;\r
8be0ba36 478\r
47d20b54
MK
479 Status = gBS->InstallProtocolInterface (\r
480 &(ProtocolToReturn->TheHandle),\r
481 &gEfiSimpleTextOutProtocolGuid,\r
482 EFI_NATIVE_INTERFACE,\r
483 &(ProtocolToReturn->SimpleTextOut)\r
484 );\r
485 if (!EFI_ERROR (Status)) {\r
8be0ba36 486 *HandleLocation = ProtocolToReturn->TheHandle;\r
47d20b54 487 return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)ProtocolToReturn);\r
8be0ba36 488 } else {\r
47d20b54
MK
489 SHELL_FREE_NON_NULL (ProtocolToReturn->SimpleTextOut.Mode);\r
490 SHELL_FREE_NON_NULL (ProtocolToReturn);\r
8be0ba36 491 return (NULL);\r
492 }\r
493}\r
494\r
495/**\r
ba0014b9 496 Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a\r
8be0ba36 497 SHELL_FILE_HANDLE to support redirecting output from a file.\r
498\r
733f138d 499 @param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.\r
8be0ba36 500\r
501 @retval EFI_SUCCESS The object was closed.\r
502**/\r
503EFI_STATUS\r
47d20b54 504CloseSimpleTextOutOnFile (\r
733f138d 505 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut\r
8be0ba36 506 )\r
507{\r
508 EFI_STATUS Status;\r
47d20b54 509\r
8be0ba36 510 if (SimpleTextOut == NULL) {\r
511 return (EFI_INVALID_PARAMETER);\r
512 }\r
47d20b54
MK
513\r
514 Status = gBS->UninstallProtocolInterface (\r
515 ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)SimpleTextOut)->TheHandle,\r
516 &gEfiSimpleTextOutProtocolGuid,\r
517 &(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)SimpleTextOut)->SimpleTextOut)\r
518 );\r
519 FreePool (SimpleTextOut->Mode);\r
520 FreePool (SimpleTextOut);\r
8be0ba36 521 return (Status);\r
522}\r