]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLevel2CommandsLib/Parse.c
ShellPkg/parse: Handle Unicode stream from pipe correctly
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel2CommandsLib / Parse.c
index 4b1973a5050f6abdf42f04ae21e5ce92c60e11c2..85c39ba78fa13e379c6f26c286c41d5a8d654565 100644 (file)
@@ -2,7 +2,7 @@
   Main file for Parse shell level 2 function.\r
 \r
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
-  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2017, 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
@@ -55,137 +55,6 @@ IsStdInDataAvailable (
   }\r
 }\r
 \r
-/**\r
-  Function to read a single line (up to but not including the \n) using StdIn data from a SHELL_FILE_HANDLE.\r
-\r
-  If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
-  maintained and not changed for all operations with the same file.\r
-\r
-  @param[in]       Handle        SHELL_FILE_HANDLE to read from.\r
-  @param[in, out]  Buffer        The pointer to buffer to read into.\r
-  @param[in, out]  Size          The pointer to number of bytes in Buffer.\r
-  @param[in]       Truncate      If the buffer is large enough, this has no effect.\r
-                                 If the buffer is is too small and Truncate is TRUE,\r
-                                 the line will be truncated.\r
-                                 If the buffer is is too small and Truncate is FALSE,\r
-                                 then no read will occur.\r
-\r
-  @retval EFI_SUCCESS           The operation was successful.  The line is stored in\r
-                                Buffer.\r
-  @retval EFI_INVALID_PARAMETER Handle was NULL.\r
-  @retval EFI_INVALID_PARAMETER Size was NULL.\r
-  @retval EFI_BUFFER_TOO_SMALL  Size was not large enough to store the line.\r
-                                Size was updated to the minimum space required.\r
-**/\r
-EFI_STATUS\r
-ShellFileHandleReadStdInLine(\r
-  IN SHELL_FILE_HANDLE          Handle,\r
-  IN OUT CHAR16                 *Buffer,\r
-  IN OUT UINTN                  *Size,\r
-  IN BOOLEAN                    Truncate\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-  CHAR16      CharBuffer;\r
-  UINTN       CharSize;\r
-  UINTN       CountSoFar;\r
-  UINT64      OriginalFilePosition;\r
-\r
-\r
-  if (Handle == NULL\r
-    ||Size   == NULL\r
-   ){\r
-    return (EFI_INVALID_PARAMETER);\r
-  }\r
-  if (Buffer == NULL) {\r
-    ASSERT(*Size == 0);\r
-  } else {\r
-    *Buffer = CHAR_NULL;\r
-  }\r
-  gEfiShellProtocol->GetFilePosition (Handle, &OriginalFilePosition);\r
-\r
-  for (CountSoFar = 0;;CountSoFar++){\r
-    CharBuffer = 0;\r
-    CharSize = sizeof(CHAR16);\r
-    Status = gEfiShellProtocol->ReadFile (Handle, &CharSize, &CharBuffer);\r
-    if (  EFI_ERROR(Status)\r
-       || CharSize == 0\r
-       || (CharBuffer == L'\n')\r
-     ){\r
-      break;\r
-    }\r
-    //\r
-    // if we have space save it...\r
-    //\r
-    if ((CountSoFar+1)*sizeof(CHAR16) < *Size){\r
-      ASSERT(Buffer != NULL);\r
-      ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;\r
-      ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;\r
-    }\r
-  }\r
-\r
-  //\r
-  // if we ran out of space tell when...\r
-  //\r
-  if ((CountSoFar+1)*sizeof(CHAR16) > *Size){\r
-    *Size = (CountSoFar+1)*sizeof(CHAR16);\r
-    if (!Truncate) {\r
-      gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);\r
-    } else {\r
-      DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));\r
-    }\r
-    return (EFI_BUFFER_TOO_SMALL);\r
-  }\r
-  while(Buffer[StrLen(Buffer)-1] == L'\r') {\r
-    Buffer[StrLen(Buffer)-1] = CHAR_NULL;\r
-  }\r
-\r
-  return (Status);\r
-}\r
-\r
-\r
-/**\r
-  Function to read a single line using StdIn from a SHELL_FILE_HANDLE. The \n is not included in the returned\r
-  buffer.  The returned buffer must be callee freed.\r
-\r
-  If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
-  maintained and not changed for all operations with the same file.\r
-\r
-  @param[in]       Handle        SHELL_FILE_HANDLE to read from.\r
-\r
-  @return                        The line of text from the file.\r
-  @retval NULL                   There was not enough memory available.\r
-\r
-  @sa ShellFileHandleReadLine\r
-**/\r
-CHAR16*\r
-ParseReturnStdInLine (\r
-  IN SHELL_FILE_HANDLE Handle\r
-  )\r
-{\r
-  CHAR16          *RetVal;\r
-  UINTN           Size;\r
-  EFI_STATUS      Status;\r
-\r
-  Size   = 0;\r
-  RetVal = NULL;\r
-\r
-  Status = ShellFileHandleReadStdInLine (Handle, RetVal, &Size, FALSE);\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    RetVal = AllocateZeroPool(Size);\r
-    if (RetVal == NULL) {\r
-      return (NULL);\r
-    }\r
-    Status = ShellFileHandleReadStdInLine (Handle, RetVal, &Size, FALSE);\r
-\r
-  }\r
-  if (EFI_ERROR(Status) && (RetVal != NULL)) {\r
-    FreePool(RetVal);\r
-    RetVal = NULL;\r
-  }\r
-  return (RetVal);\r
-}\r
-\r
 /**\r
   Handle stings for SFO Output with escape character ^ in a string\r
   1. Quotation marks in the string must be escaped by using a ^ character (i.e. ^"). \r
@@ -281,11 +150,7 @@ PerformParsing(
     ShellStatus = SHELL_NOT_FOUND;\r
   } else {\r
     for (LoopVariable = 0 ; LoopVariable < ShellCommandInstance && !ShellFileHandleEof(FileHandle);) {\r
-     if (StreamingUnicode) {\r
-       TempLine = ParseReturnStdInLine (FileHandle);\r
-     } else {\r
-       TempLine = ShellFileHandleReturnLine (FileHandle, &Ascii); \r
-     }\r
+     TempLine = ShellFileHandleReturnLine (FileHandle, &Ascii); \r
 \r
       if ((TempLine == NULL) || (*TempLine == CHAR_NULL && StreamingUnicode)) {\r
          break;\r
@@ -304,11 +169,7 @@ PerformParsing(
     if (LoopVariable == ShellCommandInstance) {\r
       LoopVariable = 0;\r
       while(1) {\r
-        if (StreamingUnicode) {\r
-          TempLine = ParseReturnStdInLine (FileHandle);\r
-        } else {\r
-          TempLine = ShellFileHandleReturnLine (FileHandle, &Ascii); \r
-        }\r
+        TempLine = ShellFileHandleReturnLine (FileHandle, &Ascii); \r
         if (TempLine == NULL\r
             || *TempLine == CHAR_NULL\r
             || StrStr (TempLine, L"ShellCommand,") == TempLine) {\r