]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ConsoleWrappers.c
ShellPkg: Clean up source files
[mirror_edk2.git] / ShellPkg / Application / Shell / ConsoleWrappers.c
index fddf5c4ba07f0dd389337920dd92ec058b18efeb..a0861e6a1d2390be7ab345a11ead4814ab1015c3 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Function definitions for shell simple text in and out on top of file handles.\r
 \r
-  Copyright (c) 2013 Hewlett-Packard Development Company, L.P.\r
-  Copyright (c) 2010 - 2014, 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
@@ -15,6 +15,8 @@
 \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
@@ -81,6 +83,7 @@ FileBasedSimpleTextInReadKeyStroke(
   )\r
 {\r
   UINTN Size;\r
+  UINTN CharSize;\r
 \r
   //\r
   // Verify the parameters\r
@@ -98,11 +101,16 @@ FileBasedSimpleTextInReadKeyStroke(
 \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 > Size) {\r
-    ((SHELL_EFI_SIMPLE_TEXT_INPUT_PROTOCOL *)This)->RemainingBytesOfInputFile -= Size;\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
@@ -115,7 +123,7 @@ FileBasedSimpleTextInReadKeyStroke(
 }\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
@@ -125,7 +133,6 @@ FileBasedSimpleTextInReadKeyStroke(
   @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
@@ -155,7 +162,7 @@ CreateSimpleTextInOnFile(
   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
@@ -170,9 +177,9 @@ CreateSimpleTextInOnFile(
   }\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
@@ -184,7 +191,7 @@ CreateSimpleTextInOnFile(
 }\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
@@ -192,7 +199,6 @@ CreateSimpleTextInOnFile(
   @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
@@ -207,8 +213,8 @@ CloseSimpleTextInOnFile(
   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
@@ -277,9 +283,9 @@ FileBasedSimpleTextOutQueryMode (
   )\r
 {\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *PassThruProtocol;\r
-  \r
+\r
   PassThruProtocol = ((SHELL_EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *)This)->OriginalSimpleTextOut;\r
-  \r
+\r
   // Pass the QueryMode call thru to the original SimpleTextOutProtocol\r
   return (PassThruProtocol->QueryMode(\r
     PassThruProtocol,\r
@@ -415,7 +421,7 @@ FileBasedSimpleTextOutOutputString (
 }\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
@@ -426,7 +432,6 @@ FileBasedSimpleTextOutOutputString (
   @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
@@ -468,21 +473,22 @@ CreateSimpleTextOutOnFile(
   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
@@ -490,7 +496,6 @@ CreateSimpleTextOutOnFile(
   @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
@@ -500,9 +505,10 @@ CloseSimpleTextOutOnFile(
     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