]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ConsoleWrappers.c
ShellPkg: Standardized HP Copyright Message String
[mirror_edk2.git] / ShellPkg / Application / Shell / ConsoleWrappers.c
index d85d1acf4d713e937d897ea53cc5bc0f33e14f9c..feea6ef3a22e58d89038398cbc7d88a3a2ab5171 100644 (file)
@@ -1,7 +1,8 @@
 /** @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 - 2014, 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
@@ -18,12 +19,14 @@ typedef struct {
   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
@@ -41,19 +44,7 @@ ConInWaitForKey (
   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
@@ -90,10 +81,32 @@ FileBasedSimpleTextInReadKeyStroke(
   )\r
 {\r
   UINTN Size;\r
-  Size = sizeof(CHAR16);\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
+  //\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 > Size) {\r
+    ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= Size;\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
@@ -120,6 +133,8 @@ CreateSimpleTextInOnFile(
 {\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
@@ -129,7 +144,15 @@ CreateSimpleTextInOnFile(
   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
@@ -253,7 +276,16 @@ FileBasedSimpleTextOutQueryMode (
   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
@@ -386,8 +418,9 @@ FileBasedSimpleTextOutOutputString (
   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
@@ -395,8 +428,9 @@ FileBasedSimpleTextOutOutputString (
 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
@@ -411,6 +445,7 @@ CreateSimpleTextOutOnFile(
     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
@@ -425,12 +460,12 @@ CreateSimpleTextOutOnFile(
     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