/** @file\r
Function definitions for shell simple text in and out on top of file handles.\r
\r
- Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+ (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
**/\r
\r
-#include <Uefi.h>\r
-#include <ShellBase.h>\r
-\r
-#include "ConsoleWrappers.h"\r
#include "Shell.h"\r
\r
+extern BOOLEAN AsciiRedirection;\r
+\r
typedef struct {\r
EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;\r
SHELL_FILE_HANDLE FileHandle;\r
EFI_HANDLE TheHandle;\r
+ UINT64 RemainingBytesOfInputFile;\r
} SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL;\r
\r
typedef struct {\r
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut;\r
SHELL_FILE_HANDLE FileHandle;\r
EFI_HANDLE TheHandle;\r
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalSimpleTextOut;\r
} SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;\r
\r
/**\r
IN VOID *Context\r
)\r
{\r
- UINT64 Position;\r
- UINT64 Size;\r
- //\r
- // Someone is waiting on the keystroke event, if there's\r
- // a key pending, signal the event\r
- //\r
- // Context is the pointer to EFI_SIMPLE_TEXT_INPUT_PROTOCOL\r
- //\r
- ShellInfoObject.NewEfiShellProtocol->GetFilePosition(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Context)->FileHandle, &Position);\r
- ShellInfoObject.NewEfiShellProtocol->GetFileSize (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)Context)->FileHandle, &Size );\r
- if (Position < Size) {\r
- gBS->SignalEvent (Event);\r
- }\r
+ gBS->SignalEvent (Event);\r
}\r
\r
/**\r
/**\r
ReadKeyStroke function for the fake simple text input.\r
\r
- @param[in] This A pointer to the SimpleTextIn structure.\r
- @param[in,out] Key A pointer to the Key structure to fill.\r
+ @param[in] This A pointer to the SimpleTextIn structure.\r
+ @param[in, out] Key A pointer to the Key structure to fill.\r
\r
@retval EFI_SUCCESS The read was successful.\r
**/\r
)\r
{\r
UINTN Size;\r
- Size = sizeof(CHAR16);\r
+ UINTN CharSize;\r
+\r
+ //\r
+ // Verify the parameters\r
+ //\r
if (Key == NULL || This == NULL) {\r
return (EFI_INVALID_PARAMETER);\r
}\r
+\r
+ //\r
+ // Check if we have any characters left in the stream.\r
+ //\r
+ if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile == 0) {\r
+ return (EFI_NOT_READY);\r
+ }\r
+\r
+ Size = sizeof(CHAR16);\r
+\r
+ if(!AsciiRedirection) {\r
+ CharSize = sizeof(CHAR16);\r
+ } else {\r
+ CharSize = sizeof(CHAR8);\r
+ }\r
+ //\r
+ // Decrement the amount of free space by Size or set to zero (for odd length files)\r
+ //\r
+ if (((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile > CharSize) {\r
+ ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= CharSize;\r
+ } else {\r
+ ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile = 0;\r
+ }\r
+\r
Key->ScanCode = 0;\r
return (ShellInfoObject.NewEfiShellProtocol->ReadFile(\r
((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->FileHandle,\r
}\r
\r
/**\r
- Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a \r
+ Function to create a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a\r
SHELL_FILE_HANDLE to support redirecting input from a file.\r
\r
@param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.\r
@return A pointer to the allocated protocol structure;\r
**/\r
EFI_SIMPLE_TEXT_INPUT_PROTOCOL*\r
-EFIAPI\r
CreateSimpleTextInOnFile(\r
IN SHELL_FILE_HANDLE FileHandleToUse,\r
IN EFI_HANDLE *HandleLocation\r
{\r
SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ProtocolToReturn;\r
EFI_STATUS Status;\r
+ UINT64 CurrentPosition;\r
+ UINT64 FileSize;\r
\r
if (HandleLocation == NULL || FileHandleToUse == NULL) {\r
return (NULL);\r
if (ProtocolToReturn == NULL) {\r
return (NULL);\r
}\r
- ProtocolToReturn->FileHandle = FileHandleToUse;\r
+\r
+ ShellGetFileSize (FileHandleToUse, &FileSize);\r
+ ShellGetFilePosition(FileHandleToUse, &CurrentPosition);\r
+\r
+ //\r
+ // Initialize the protocol members\r
+ //\r
+ ProtocolToReturn->RemainingBytesOfInputFile = FileSize - CurrentPosition;\r
+ ProtocolToReturn->FileHandle = FileHandleToUse;\r
ProtocolToReturn->SimpleTextIn.Reset = FileBasedSimpleTextInReset;\r
ProtocolToReturn->SimpleTextIn.ReadKeyStroke = FileBasedSimpleTextInReadKeyStroke;\r
- \r
+\r
Status = gBS->CreateEvent (\r
EVT_NOTIFY_WAIT,\r
TPL_NOTIFY,\r
}\r
///@todo possibly also install SimpleTextInputEx on the handle at this point.\r
Status = gBS->InstallProtocolInterface(\r
- &(ProtocolToReturn->TheHandle), \r
- &gEfiSimpleTextInProtocolGuid, \r
- EFI_NATIVE_INTERFACE, \r
+ &(ProtocolToReturn->TheHandle),\r
+ &gEfiSimpleTextInProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
&(ProtocolToReturn->SimpleTextIn));\r
if (!EFI_ERROR(Status)) {\r
*HandleLocation = ProtocolToReturn->TheHandle;\r
}\r
\r
/**\r
- Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a \r
+ Function to close a EFI_SIMPLE_TEXT_INPUT_PROTOCOL on top of a\r
SHELL_FILE_HANDLE to support redirecting input from a file.\r
\r
@param[in] SimpleTextIn The pointer to the SimpleTextIn to close.\r
@retval EFI_SUCCESS The object was closed.\r
**/\r
EFI_STATUS\r
-EFIAPI\r
CloseSimpleTextInOnFile(\r
IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL *SimpleTextIn\r
)\r
Status = gBS->CloseEvent(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)SimpleTextIn)->SimpleTextIn.WaitForKey);\r
\r
Status1 = gBS->UninstallProtocolInterface(\r
- ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL*)SimpleTextIn)->TheHandle, \r
- &gEfiSimpleTextInProtocolGuid, \r
+ ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL*)SimpleTextIn)->TheHandle,\r
+ &gEfiSimpleTextInProtocolGuid,\r
&(((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL*)SimpleTextIn)->SimpleTextIn));\r
\r
FreePool(SimpleTextIn);\r
OUT UINTN *Rows\r
)\r
{\r
- return (EFI_UNSUPPORTED);\r
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *PassThruProtocol;\r
+\r
+ PassThruProtocol = ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->OriginalSimpleTextOut;\r
+\r
+ // Pass the QueryMode call thru to the original SimpleTextOutProtocol\r
+ return (PassThruProtocol->QueryMode(\r
+ PassThruProtocol,\r
+ ModeNumber,\r
+ Columns,\r
+ Rows));\r
}\r
\r
/**\r
}\r
\r
/**\r
- Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a \r
+ Function to create a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a\r
SHELL_FILE_HANDLE to support redirecting output from a file.\r
\r
- @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.\r
- @param[in] HandleLocation The pointer of a location to copy handle with protocol to.\r
+ @param[in] FileHandleToUse The pointer to the SHELL_FILE_HANDLE to use.\r
+ @param[in] HandleLocation The pointer of a location to copy handle with protocol to.\r
+ @param[in] OriginalProtocol The pointer to the original output protocol for pass thru of functions.\r
\r
@retval NULL There was insufficient memory available.\r
@return A pointer to the allocated protocol structure;\r
**/\r
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*\r
-EFIAPI\r
CreateSimpleTextOutOnFile(\r
- IN SHELL_FILE_HANDLE FileHandleToUse,\r
- IN EFI_HANDLE *HandleLocation\r
+ IN SHELL_FILE_HANDLE FileHandleToUse,\r
+ IN EFI_HANDLE *HandleLocation,\r
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *OriginalProtocol\r
)\r
{\r
SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ProtocolToReturn;\r
return (NULL);\r
}\r
ProtocolToReturn->FileHandle = FileHandleToUse;\r
+ ProtocolToReturn->OriginalSimpleTextOut = OriginalProtocol;\r
ProtocolToReturn->SimpleTextOut.Reset = FileBasedSimpleTextOutReset;\r
ProtocolToReturn->SimpleTextOut.TestString = FileBasedSimpleTextOutTestString;\r
ProtocolToReturn->SimpleTextOut.QueryMode = FileBasedSimpleTextOutQueryMode;\r
FreePool(ProtocolToReturn);\r
return (NULL);\r
}\r
- ProtocolToReturn->SimpleTextOut.Mode->MaxMode = 0;\r
- ProtocolToReturn->SimpleTextOut.Mode->Mode = 0;\r
- ProtocolToReturn->SimpleTextOut.Mode->Attribute = 0;\r
- ProtocolToReturn->SimpleTextOut.Mode->CursorColumn = 0;\r
- ProtocolToReturn->SimpleTextOut.Mode->CursorRow = 0;\r
- ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = FALSE;\r
+ ProtocolToReturn->SimpleTextOut.Mode->MaxMode = OriginalProtocol->Mode->MaxMode;\r
+ ProtocolToReturn->SimpleTextOut.Mode->Mode = OriginalProtocol->Mode->Mode;\r
+ ProtocolToReturn->SimpleTextOut.Mode->Attribute = OriginalProtocol->Mode->Attribute;\r
+ ProtocolToReturn->SimpleTextOut.Mode->CursorColumn = OriginalProtocol->Mode->CursorColumn;\r
+ ProtocolToReturn->SimpleTextOut.Mode->CursorRow = OriginalProtocol->Mode->CursorRow;\r
+ ProtocolToReturn->SimpleTextOut.Mode->CursorVisible = OriginalProtocol->Mode->CursorVisible;\r
\r
Status = gBS->InstallProtocolInterface(\r
- &(ProtocolToReturn->TheHandle), \r
- &gEfiSimpleTextOutProtocolGuid, \r
- EFI_NATIVE_INTERFACE, \r
+ &(ProtocolToReturn->TheHandle),\r
+ &gEfiSimpleTextOutProtocolGuid,\r
+ EFI_NATIVE_INTERFACE,\r
&(ProtocolToReturn->SimpleTextOut));\r
if (!EFI_ERROR(Status)) {\r
*HandleLocation = ProtocolToReturn->TheHandle;\r
return ((EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)ProtocolToReturn);\r
} else {\r
- FreePool(ProtocolToReturn);\r
+ SHELL_FREE_NON_NULL(ProtocolToReturn->SimpleTextOut.Mode);\r
+ SHELL_FREE_NON_NULL(ProtocolToReturn);\r
return (NULL);\r
}\r
}\r
\r
/**\r
- Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a \r
+ Function to close a EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL on top of a\r
SHELL_FILE_HANDLE to support redirecting output from a file.\r
\r
@param[in] SimpleTextOut The pointer to the SimpleTextOUT to close.\r
@retval EFI_SUCCESS The object was closed.\r
**/\r
EFI_STATUS\r
-EFIAPI\r
CloseSimpleTextOutOnFile(\r
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut\r
)\r
return (EFI_INVALID_PARAMETER);\r
}\r
Status = gBS->UninstallProtocolInterface(\r
- ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)SimpleTextOut)->TheHandle, \r
- &gEfiSimpleTextOutProtocolGuid, \r
+ ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)SimpleTextOut)->TheHandle,\r
+ &gEfiSimpleTextOutProtocolGuid,\r
&(((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL*)SimpleTextOut)->SimpleTextOut));\r
+ FreePool(SimpleTextOut->Mode);\r
FreePool(SimpleTextOut);\r
return (Status);\r
}\r