]> git.proxmox.com Git - mirror_edk2.git/commitdiff
updates from code review, buffer length, and correct use of StdOut for printing
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 1 Dec 2009 05:40:24 +0000 (05:40 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 1 Dec 2009 05:40:24 +0000 (05:40 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9499 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg/Library/UefiShellLib/UefiShellLib.inf

index b1128ffc14ed2aef5376d2f3d8b0b4183483d6f6..ae76b4208075f94b824c63d9dea35b36b6419bb7 100644 (file)
@@ -54,6 +54,8 @@ STATIC EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol;
 STATIC EFI_HANDLE                    mEfiShellEnvironment2Handle;\r
 STATIC FILE_HANDLE_FUNCTION_MAP      FileFunctionMap;\r
 STATIC UINTN                         mTotalParameterCount;\r
+STATIC EFI_FILE_HANDLE               StdOut;\r
+STATIC EFI_FILE_HANDLE               StdErr;\r
 \r
 /**\r
   Check if a Unicode character is a hexadecimal character.\r
@@ -2244,6 +2246,34 @@ CopyReplace(
   return (EFI_SUCCESS);\r
 }\r
 \r
+/**\r
+  Internal worker function to output a string.\r
+\r
+  This function will output a string to the correct StdOut.\r
+\r
+  @param[in] String       The string to print out.\r
+\r
+  @retval EFI_SUCCESS     The operation was sucessful.\r
+  @retval !EFI_SUCCESS    The operation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalPrintTo (\r
+  IN CONST CHAR16 *String\r
+  )\r
+{\r
+  UINTN Size;\r
+  Size = StrSize(String) - sizeof(CHAR16);\r
+  if (mEfiShellParametersProtocol != NULL) {\r
+    return (mEfiShellParametersProtocol->StdOut->Write(mEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
+  }\r
+  if (mEfiShellInterface          != NULL) {\r
+    return (         mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut,          &Size, (VOID*)String));\r
+  }\r
+  ASSERT(FALSE);\r
+  return (EFI_UNSUPPORTED);\r
+}\r
+\r
 /**\r
   Print at a specific location on the screen.\r
 \r
@@ -2291,7 +2321,8 @@ InternalShellPrintWorker(
   CHAR16            *ResumeLocation;\r
   CHAR16            *FormatWalker;\r
   \r
-  BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
+  BufferSize = PcdGet16 (PcdShellLibMaxPrintBufferSize);\r
+  ASSERT(PcdGet16 (PcdShellLibMaxPrintBufferSize) < PcdGet32 (PcdMaximumUnicodeStringLength));\r
   PostReplaceFormat = AllocateZeroPool (BufferSize);\r
   ASSERT (PostReplaceFormat != NULL);\r
   PostReplaceFormat2 = AllocateZeroPool (BufferSize);\r
@@ -2336,7 +2367,7 @@ InternalShellPrintWorker(
     //\r
     // print the current FormatWalker string\r
     //\r
-    Status = gST->ConOut->OutputString(gST->ConOut, FormatWalker);\r
+    Status = InternalPrintTo(FormatWalker);\r
     ASSERT_EFI_ERROR(Status);\r
     //\r
     // update the attribute\r
@@ -2359,7 +2390,12 @@ InternalShellPrintWorker(
           gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((NormalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
           break;\r
         default:\r
-          ASSERT(FALSE);\r
+          //\r
+          // Print a simple '%' symbol\r
+          //\r
+          Status = InternalPrintTo(L"%");\r
+          ASSERT_EFI_ERROR(Status);\r
+          ResumeLocation = ResumeLocation - 1;\r
           break;\r
       }\r
     } else {\r
@@ -2384,13 +2420,13 @@ InternalShellPrintWorker(
 /**\r
   Print at a specific location on the screen.\r
 \r
-  This function will move the cursor to a given screen location and print the specified string\r
+  This function will move the cursor to a given screen location and print the specified string.\r
   \r
   If -1 is specified for either the Row or Col the current screen location for BOTH \r
   will be used.\r
 \r
-  if either Row or Col is out of range for the current console, then ASSERT\r
-  if Format is NULL, then ASSERT\r
+  If either Row or Col is out of range for the current console, then ASSERT.\r
+  If Format is NULL, then ASSERT.\r
 \r
   In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
   the following additional flags:\r
@@ -2419,21 +2455,23 @@ ShellPrintEx(
   ) \r
 {\r
   VA_LIST           Marker;\r
+  EFI_STATUS        Status;\r
   VA_START (Marker, Format);\r
-  return (InternalShellPrintWorker(Col, Row, Format, Marker));\r
+  Status = InternalShellPrintWorker(Col, Row, Format, Marker);\r
+  VA_END(Marker);\r
+  return(Status);\r
 }\r
 \r
 /**\r
   Print at a specific location on the screen.\r
 \r
-  This function will move the cursor to a given screen location, print the specified string, \r
-  and return the cursor to the original locaiton.  \r
+  This function will move the cursor to a given screen location and print the specified string.\r
   \r
   If -1 is specified for either the Row or Col the current screen location for BOTH \r
-  will be used and the cursor's position will not be moved back to an original location.\r
+  will be used.\r
 \r
-  if either Row or Col is out of range for the current console, then ASSERT\r
-  if Format is NULL, then ASSERT\r
+  If either Row or Col is out of range for the current console, then ASSERT.\r
+  If Format is NULL, then ASSERT.\r
 \r
   In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
   the following additional flags:\r
@@ -2473,6 +2511,7 @@ ShellPrintHiiEx(
   RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker);\r
 \r
   FreePool(HiiFormatString);\r
+  VA_END(Marker);\r
 \r
   return (RetVal);\r
 }\r
index 832028b73da4a9b630eb41c1e42f4d4cc6293f4f..28fe8930337d2f11a86ffbd84cb6a6a3a11fa12e 100644 (file)
@@ -64,5 +64,6 @@
   gEfiShellEnvironment2ExtGuid                  # ALWAYS_CONSUMED\r
 \r
 [Pcd.common]\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize  # ALWAYS_CONSUMED\r
-  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize # ALWAYS_CONSUMED\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize     # ALWAYS_CONSUMED\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellLibMaxPrintBufferSize # ALWAYS_CONSUMED\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength   # ALWAYS_CONSUMED
\ No newline at end of file