]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Foundation/Library/Dxe/GraphicsLite/Ascii/Sprint.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / Dxe / GraphicsLite / Ascii / Sprint.c
diff --git a/EdkCompatibilityPkg/Foundation/Library/Dxe/GraphicsLite/Ascii/Sprint.c b/EdkCompatibilityPkg/Foundation/Library/Dxe/GraphicsLite/Ascii/Sprint.c
new file mode 100644 (file)
index 0000000..7c44ad5
--- /dev/null
@@ -0,0 +1,144 @@
+/*++\r
+\r
+Copyright (c) 2004, Intel Corporation                                                         \r
+All rights reserved. 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
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+\r
+  Sprint.c\r
+\r
+Abstract:\r
+\r
+  Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very\r
+  simple implemenation of SPrint() and Print() to support debug. \r
+\r
+  You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a \r
+  time. This makes the implementation very simple.\r
+\r
+  VSPrint, Print, SPrint format specification has the follwoing form\r
+\r
+  %[flags][width]type\r
+\r
+  flags:\r
+    '-' - Left justify\r
+    '+' - Prefix a sign\r
+    ' ' - Prefix a blank\r
+    ',' - Place commas in numberss\r
+    '0' - Prefix for width with zeros\r
+    'l' - UINT64\r
+    'L' - UINT64\r
+\r
+  width:\r
+    '*' - Get width from a UINTN argumnet from the argument list\r
+    Decimal number that represents width of print\r
+\r
+  type:\r
+    'X' - argument is a UINTN hex number, prefix '0'\r
+    'x' - argument is a hex number\r
+    'd' - argument is a decimal number\r
+    'a' - argument is an ascii string \r
+    'S','s' - argument is an Unicode string\r
+    'g' - argument is a pointer to an EFI_GUID\r
+    't' - argument is a pointer to an EFI_TIME structure\r
+    'c' - argument is an ascii character\r
+    'r' - argument is EFI_STATUS\r
+    '%' - Print a %\r
+\r
+--*/\r
+\r
+#include "TianoCommon.h"\r
+#include "PrintWidth.h"\r
+#include "EfiPrintLib.h"\r
+#include "Print.h"\r
+\r
+\r
+UINTN\r
+USPrint (\r
+  OUT CHAR16        *Buffer,\r
+  IN  UINTN         BufferSize,\r
+  IN  CONST CHAR16  *Format,\r
+  ...\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Process format and place the results in Buffer for wide chars.\r
+\r
+Arguments:\r
+\r
+  Buffer      - Wide char buffer to print the results of the parsing of Format into.\r
+  BufferSize  - Maximum number of characters to put into buffer.\r
+  Format      - Format string\r
+  ...         - Vararg list consumed by processing Format.\r
+\r
+Returns:\r
+\r
+  Number of characters printed.\r
+\r
+--*/\r
+{\r
+  UINTN   Return;\r
+  VA_LIST Marker;\r
+\r
+  VA_START (Marker, Format);\r
+  Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r
+  VA_END (Marker);\r
+\r
+  return Return;\r
+}\r
+\r
+\r
+UINTN\r
+UvSPrint (\r
+  OUT CHAR16        *Buffer,\r
+  IN  UINTN         BufferSize,\r
+  IN  CONST CHAR16  *FormatString,\r
+  IN  VA_LIST       Marker\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Internal implementation of USPrint. \r
+  Process format and place the results in Buffer for wide chars.\r
+\r
+Arguments:\r
+\r
+  Buffer        - Wide char buffer to print the results of the parsing of Format into.\r
+  BufferSize    - Maximum number of characters to put into buffer.\r
+  FormatString  - Format string\r
+  Marker        - Vararg list consumed by processing Format.\r
+\r
+Returns:\r
+\r
+  Number of characters printed.\r
+\r
+--*/\r
+{\r
+  UINTN Index;\r
+  CHAR8 AsciiFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
+  CHAR8 AsciiResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER];\r
+\r
+  for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) {\r
+    AsciiFormat[Index] = (CHAR8) FormatString[Index];\r
+  }\r
+\r
+  AsciiFormat[Index]  = '\0';\r
+\r
+  Index               = VSPrint (AsciiResult, EFI_DRIVER_LIB_MAX_PRINT_BUFFER, AsciiFormat, Marker);\r
+\r
+  for (Index = 0; (Index < (BufferSize - 1)) && AsciiResult[Index] != '\0'; Index++) {\r
+    Buffer[Index] = (CHAR16) AsciiResult[Index];\r
+  }\r
+\r
+  Buffer[Index] = '\0';\r
+\r
+  return Index++;\r
+}\r