3 Copyright (c) 2004 - 2012, 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
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.
18 Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very
19 simple implemenation of SPrint() and Print() to support debug.
21 You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a
22 time. This makes the implementation very simple.
24 VSPrint, Print, SPrint format specification has the follwoing form
32 ',' - Place commas in numberss
33 '0' - Prefix for width with zeros
38 '*' - Get width from a UINTN argumnet from the argument list
39 Decimal number that represents width of print
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
56 #include "EfiDriverLib.h"
57 #include "EfiCommonLib.h"
58 #include "EfiPrintLib.h"
64 IN CONST CHAR16
*ErrorString
,
65 IN CONST CHAR8
*Format
,
72 Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
77 ErrorString - String of error infomation.
79 Format - Ascii format string see file header for more details.
81 ... - Vararg list consumed by processing Format.
85 Number of characters printed.
93 CHAR16 Buffer
[EFI_DRIVER_LIB_MAX_PRINT_BUFFER
];
94 CHAR16 UnicodeFormat
[EFI_DRIVER_LIB_MAX_PRINT_BUFFER
];
96 MaxIndex
= EfiAsciiStrLen ((CHAR8
*) Format
);
97 if (MaxIndex
>= EFI_DRIVER_LIB_MAX_PRINT_BUFFER
) {
99 // Format string was too long for use to process.
104 if (ErrorString
!= NULL
) {
105 if (gST
->StdErr
!= NULL
) {
107 // To be extra safe make sure StdErr has been initialized
109 gST
->StdErr
->SetAttribute (gST
->StdErr
, EFI_TEXT_ATTR (EFI_RED
, EFI_BLACK
));
110 gST
->StdErr
->OutputString (gST
->StdErr
, (CHAR16
*) ErrorString
);
111 gST
->StdErr
->SetAttribute (gST
->StdErr
, EFI_TEXT_ATTR (EFI_WHITE
, EFI_BLACK
));
115 for (Index
= 0; Index
< MaxIndex
; Index
++) {
116 UnicodeFormat
[Index
] = (CHAR16
) Format
[Index
];
119 UnicodeFormat
[Index
] = 0;
121 VA_START (Marker
, Format
);
122 Return
= VSPrint (Buffer
, sizeof (Buffer
), UnicodeFormat
, Marker
);
126 // Need to convert to Unicode to do an OutputString
129 if (gST
->StdErr
!= NULL
) {
131 // To be extra safe make sure StdErr has been initialized
133 gST
->StdErr
->OutputString (gST
->StdErr
, Buffer
);
142 IN CONST CHAR8
*Format
,
149 Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
154 Format - Ascii format string see file header for more details.
156 ... - Vararg list consumed by processing Format.
160 Number of characters printed.
168 CHAR16 Buffer
[EFI_DRIVER_LIB_MAX_PRINT_BUFFER
];
169 CHAR16 UnicodeFormat
[EFI_DRIVER_LIB_MAX_PRINT_BUFFER
];
171 MaxIndex
= EfiAsciiStrLen ((CHAR8
*) Format
);
172 if (MaxIndex
>= EFI_DRIVER_LIB_MAX_PRINT_BUFFER
) {
174 // Format string was too long for use to process.
179 for (Index
= 0; Index
<= MaxIndex
; Index
++) {
180 UnicodeFormat
[Index
] = (CHAR16
) Format
[Index
];
183 VA_START (Marker
, Format
);
184 Return
= VSPrint (Buffer
, sizeof (Buffer
), UnicodeFormat
, Marker
);
188 // Need to convert to Unicode to do an OutputString
191 if (gST
->ConOut
!= NULL
) {
193 // To be extra safe make sure ConOut has been initialized
195 gST
->ConOut
->OutputString (gST
->ConOut
, Buffer
);
204 IN CONST CHAR16
*Format
,
211 Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
216 Format - Ascii format string see file header for more details.
218 ... - Vararg list consumed by processing Format.
222 Number of characters printed.
228 CHAR16 Buffer
[EFI_DRIVER_LIB_MAX_PRINT_BUFFER
];
230 VA_START (Marker
, Format
);
231 Return
= VSPrint (Buffer
, sizeof (Buffer
), Format
, Marker
);
234 if (gST
->ConOut
!= NULL
) {
236 // To be extra safe make sure ConOut has been initialized
238 gST
->ConOut
->OutputString (gST
->ConOut
, Buffer
);
246 IN CONST CHAR16
*Format
,
253 Print function for a maximum of EFI_DRIVER_LIB_MAX_PRINT_BUFFER ascii
258 Format - Ascii format string see file header for more details.
260 ... - Vararg list consumed by processing Format.
264 Number of characters printed.
270 CHAR16 Buffer
[EFI_DRIVER_LIB_MAX_PRINT_BUFFER
];
272 VA_START (Marker
, Format
);
273 Return
= VSPrint (Buffer
, sizeof (Buffer
), Format
, Marker
);
276 if (gST
->ConOut
!= NULL
) {
278 // To be extra safe make sure ConOut has been initialized
280 gST
->ConOut
->OutputString (gST
->ConOut
, Buffer
);