1 /*++ 2 3 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR> 4 This program and the accompanying materials 5 are licensed and made available under the terms and conditions of the BSD License 6 which accompanies this distribution. The full text of the license may be found at 7 http://opensource.org/licenses/bsd-license.php 8 9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 11 12 Module Name: 13 14 Sprint.c 15 16 Abstract: 17 18 Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very 19 simple implemenation of SPrint() and Print() to support debug. 20 21 You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a 22 time. This makes the implementation very simple. 23 24 VSPrint, Print, SPrint format specification has the follwoing form 25 26 %[flags][width]type 27 28 flags: 29 '-' - Left justify 30 '+' - Prefix a sign 31 ' ' - Prefix a blank 32 ',' - Place commas in numberss 33 '0' - Prefix for width with zeros 34 'l' - UINT64 35 'L' - UINT64 36 37 width: 38 '*' - Get width from a UINTN argumnet from the argument list 39 Decimal number that represents width of print 40 41 type: 42 'X' - argument is a UINTN hex number, prefix '0' 43 'x' - argument is a hex number 44 'd' - argument is a decimal number 45 'a' - argument is an ascii string 46 'S','s' - argument is an Unicode string 47 'g' - argument is a pointer to an EFI_GUID 48 't' - argument is a pointer to an EFI_TIME structure 49 'c' - argument is an ascii character 50 'r' - argument is EFI_STATUS 51 '%' - Print a % 52 53 --*/ 54 55 #include "TianoCommon.h" 56 #include "PrintWidth.h" 57 #include "EfiPrintLib.h" 58 #include "Print.h" 59 60 61 UINTN 62 ASPrint ( 63 OUT CHAR8 *Buffer, 64 IN UINTN BufferSize, 65 IN CONST CHAR8 *Format, 66 ... 67 ) 68 /*++ 69 70 Routine Description: 71 72 Process format and place the results in Buffer for narrow chars. 73 74 Arguments: 75 76 Buffer - Narrow char buffer to print the results of the parsing of Format into. 77 BufferSize - Maximum number of characters to put into buffer. 78 Format - Format string 79 ... - Vararg list consumed by processing Format. 80 81 Returns: 82 83 Number of characters printed. 84 85 --*/ 86 { 87 UINTN Return; 88 VA_LIST Marker; 89 90 VA_START (Marker, Format); 91 Return = AvSPrint (Buffer, BufferSize, Format, Marker); 92 VA_END (Marker); 93 94 return Return; 95 } 96 97 98 UINTN 99 AvSPrint ( 100 OUT CHAR8 *Buffer, 101 IN UINTN BufferSize, 102 IN CONST CHAR8 *FormatString, 103 IN VA_LIST Marker 104 ) 105 /*++ 106 107 Routine Description: 108 109 Internal implementation of ASPrint. 110 Process format and place the results in Buffer for narrow chars. 111 112 Arguments: 113 114 Buffer - Narrow char buffer to print the results of the parsing of Format into. 115 BufferSize - Maximum number of characters to put into buffer. 116 FormatString - Format string 117 Marker - Vararg list consumed by processing Format. 118 119 Returns: 120 121 Number of characters printed. 122 123 --*/ 124 { 125 UINTN Index; 126 CHAR16 UnicodeFormat[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1]; 127 CHAR16 UnicodeResult[EFI_DRIVER_LIB_MAX_PRINT_BUFFER+1]; 128 129 for (Index = 0; Index < EFI_DRIVER_LIB_MAX_PRINT_BUFFER && FormatString[Index] != '\0'; Index++) { 130 UnicodeFormat[Index] = (CHAR16) FormatString[Index]; 131 } 132 133 UnicodeFormat[Index] = '\0'; 134 135 Index = VSPrint (UnicodeResult, sizeof (UnicodeResult), UnicodeFormat, Marker); 136 137 for (Index = 0; (Index < (BufferSize - 1)) && UnicodeResult[Index] != '\0'; Index++) { 138 Buffer[Index] = (CHAR8) UnicodeResult[Index]; 139 } 140 141 Buffer[Index] = '\0'; 142 143 return Index++; 144 } 145