]>
git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BasePrintLib/PrintLib.c
2 Base Print Library instance implementation.
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "PrintLibInternal.h"
17 #define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) == 0)
20 Produces a Null-terminated Unicode string in an output buffer based on
21 a Null-terminated Unicode format string and a VA_LIST argument list
23 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
25 The Unicode string is produced by parsing the format string specified by FormatString.
26 Arguments are pulled from the variable argument list specified by Marker based on the
27 contents of the format string.
28 The number of Unicode characters in the produced output buffer is returned not including
30 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
32 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
33 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
34 If BufferSize > 1 and FormatString is NULL, then ASSERT().
35 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
36 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
37 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
39 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
40 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
41 Null-terminator, then ASSERT().
43 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
45 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
46 @param FormatString Null-terminated Unicode format string.
47 @param Marker VA_LIST marker for the variable argument list.
49 @return The number of Unicode characters in the produced output buffer not including the
56 OUT CHAR16
*StartOfBuffer
,
58 IN CONST CHAR16
*FormatString
,
62 ASSERT_UNICODE_BUFFER(StartOfBuffer
);
63 ASSERT_UNICODE_BUFFER(FormatString
);
64 return BasePrintLibVSPrint ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, FORMAT_UNICODE
| OUTPUT_UNICODE
, (CHAR8
*)FormatString
, Marker
);
68 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
69 Unicode format string and variable argument list.
71 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
73 The Unicode string is produced by parsing the format string specified by FormatString.
74 Arguments are pulled from the variable argument list based on the contents of the format string.
75 The number of Unicode characters in the produced output buffer is returned not including
77 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
79 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
80 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
81 If BufferSize > 1 and FormatString is NULL, then ASSERT().
82 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
83 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
84 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
86 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
87 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
88 Null-terminator, then ASSERT().
90 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
92 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
93 @param FormatString Null-terminated Unicode format string.
94 @param ... Variable argument list whose contents are accessed based on the
95 format string specified by FormatString.
97 @return The number of Unicode characters in the produced output buffer not including the
104 OUT CHAR16
*StartOfBuffer
,
106 IN CONST CHAR16
*FormatString
,
112 VA_START (Marker
, FormatString
);
113 return UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
117 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
118 ASCII format string and a VA_LIST argument list
120 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
122 The Unicode string is produced by parsing the format string specified by FormatString.
123 Arguments are pulled from the variable argument list specified by Marker based on the
124 contents of the format string.
125 The number of Unicode characters in the produced output buffer is returned not including
127 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
129 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
130 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
131 If BufferSize > 1 and FormatString is NULL, then ASSERT().
132 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
133 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
135 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
136 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
137 Null-terminator, then ASSERT().
139 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
141 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
142 @param FormatString Null-terminated ASCII format string.
143 @param Marker VA_LIST marker for the variable argument list.
145 @return The number of Unicode characters in the produced output buffer not including the
151 UnicodeVSPrintAsciiFormat (
152 OUT CHAR16
*StartOfBuffer
,
154 IN CONST CHAR8
*FormatString
,
158 ASSERT_UNICODE_BUFFER(StartOfBuffer
);
159 return BasePrintLibVSPrint ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, OUTPUT_UNICODE
,FormatString
, Marker
);
163 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
164 ASCII format string and variable argument list.
166 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
168 The Unicode string is produced by parsing the format string specified by FormatString.
169 Arguments are pulled from the variable argument list based on the contents of the
171 The number of Unicode characters in the produced output buffer is returned not including
173 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
175 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
176 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
177 If BufferSize > 1 and FormatString is NULL, then ASSERT().
178 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
179 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
181 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
182 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
183 Null-terminator, then ASSERT().
185 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
187 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
188 @param FormatString Null-terminated ASCII format string.
189 @param ... Variable argument list whose contents are accessed based on the
190 format string specified by FormatString.
192 @return The number of Unicode characters in the produced output buffer not including the
198 UnicodeSPrintAsciiFormat (
199 OUT CHAR16
*StartOfBuffer
,
201 IN CONST CHAR8
*FormatString
,
207 VA_START (Marker
, FormatString
);
208 return UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
212 Converts a decimal value to a Null-terminated Unicode string.
214 Converts the decimal number specified by Value to a Null-terminated Unicode
215 string specified by Buffer containing at most Width characters. No padding of spaces
216 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
217 The number of Unicode characters in Buffer is returned not including the Null-terminator.
218 If the conversion contains more than Width characters, then only the first
219 Width characters are returned, and the total number of characters
220 required to perform the conversion is returned.
221 Additional conversion parameters are specified in Flags.
223 The Flags bit LEFT_JUSTIFY is always ignored.
224 All conversions are left justified in Buffer.
225 If Width is 0, PREFIX_ZERO is ignored in Flags.
226 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
227 are inserted every 3rd digit starting from the right.
228 If HEX_RADIX is set in Flags, then the output buffer will be
229 formatted in hexadecimal format.
230 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
231 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
232 then Buffer is padded with '0' characters so the combination of the optional '-'
233 sign character, '0' characters, digit characters for Value, and the Null-terminator
234 add up to Width characters.
235 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
236 If Buffer is NULL, then ASSERT().
237 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
238 If unsupported bits are set in Flags, then ASSERT().
239 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
240 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
242 @param Buffer Pointer to the output buffer for the produced Null-terminated
244 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
245 @param Value The 64-bit signed value to convert to a string.
246 @param Width The maximum number of Unicode characters to place in Buffer, not including
249 @return The number of Unicode characters in Buffer not including the Null-terminator.
254 UnicodeValueToString (
255 IN OUT CHAR16
*Buffer
,
261 ASSERT_UNICODE_BUFFER(Buffer
);
262 return BasePrintLibConvertValueToString ((CHAR8
*)Buffer
, Flags
, Value
, Width
, 2);
266 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
267 ASCII format string and a VA_LIST argument list.
269 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
271 The ASCII string is produced by parsing the format string specified by FormatString.
272 Arguments are pulled from the variable argument list specified by Marker based on
273 the contents of the format string.
274 The number of ASCII characters in the produced output buffer is returned not including
276 If BufferSize is 0, then no output buffer is produced and 0 is returned.
278 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
279 If BufferSize > 0 and FormatString is NULL, then ASSERT().
280 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
281 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
283 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
284 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
285 Null-terminator, then ASSERT().
287 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
289 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
290 @param FormatString Null-terminated ASCII format string.
291 @param Marker VA_LIST marker for the variable argument list.
293 @return The number of ASCII characters in the produced output buffer not including the
300 OUT CHAR8
*StartOfBuffer
,
302 IN CONST CHAR8
*FormatString
,
306 return BasePrintLibVSPrint (StartOfBuffer
, BufferSize
, 0, FormatString
, Marker
);
310 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
311 ASCII format string and variable argument list.
313 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
315 The ASCII string is produced by parsing the format string specified by FormatString.
316 Arguments are pulled from the variable argument list based on the contents of the
318 The number of ASCII characters in the produced output buffer is returned not including
320 If BufferSize is 0, then no output buffer is produced and 0 is returned.
322 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
323 If BufferSize > 0 and FormatString is NULL, then ASSERT().
324 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
325 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
327 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
328 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
329 Null-terminator, then ASSERT().
331 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
333 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
334 @param FormatString Null-terminated ASCII format string.
335 @param ... Variable argument list whose contents are accessed based on the
336 format string specified by FormatString.
338 @return The number of ASCII characters in the produced output buffer not including the
345 OUT CHAR8
*StartOfBuffer
,
347 IN CONST CHAR8
*FormatString
,
353 VA_START (Marker
, FormatString
);
354 return AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
358 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
359 Unicode format string and a VA_LIST argument list.
361 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
363 The ASCII string is produced by parsing the format string specified by FormatString.
364 Arguments are pulled from the variable argument list specified by Marker based on
365 the contents of the format string.
366 The number of ASCII characters in the produced output buffer is returned not including
368 If BufferSize is 0, then no output buffer is produced and 0 is returned.
370 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
371 If BufferSize > 0 and FormatString is NULL, then ASSERT().
372 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
373 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
374 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
376 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
377 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
378 Null-terminator, then ASSERT().
380 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
382 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
383 @param FormatString Null-terminated Unicode format string.
384 @param Marker VA_LIST marker for the variable argument list.
386 @return The number of ASCII characters in the produced output buffer not including the
392 AsciiVSPrintUnicodeFormat (
393 OUT CHAR8
*StartOfBuffer
,
395 IN CONST CHAR16
*FormatString
,
399 ASSERT_UNICODE_BUFFER (FormatString
);
400 return BasePrintLibVSPrint (StartOfBuffer
, BufferSize
, FORMAT_UNICODE
, (CHAR8
*)FormatString
, Marker
);
404 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
405 Unicode format string and variable argument list.
407 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
409 The ASCII string is produced by parsing the format string specified by FormatString.
410 Arguments are pulled from the variable argument list based on the contents of the
412 The number of ASCII characters in the produced output buffer is returned not including
414 If BufferSize is 0, then no output buffer is produced and 0 is returned.
416 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
417 If BufferSize > 0 and FormatString is NULL, then ASSERT().
418 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
419 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
420 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
422 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
423 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
424 Null-terminator, then ASSERT().
426 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
428 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
429 @param FormatString Null-terminated Unicode format string.
430 @param ... Variable argument list whose contents are accessed based on the
431 format string specified by FormatString.
433 @return The number of ASCII characters in the produced output buffer not including the
439 AsciiSPrintUnicodeFormat (
440 OUT CHAR8
*StartOfBuffer
,
442 IN CONST CHAR16
*FormatString
,
448 VA_START (Marker
, FormatString
);
449 return AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
454 Converts a decimal value to a Null-terminated ASCII string.
456 Converts the decimal number specified by Value to a Null-terminated ASCII string
457 specified by Buffer containing at most Width characters. No padding of spaces
459 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
460 The number of ASCII characters in Buffer is returned not including the Null-terminator.
461 If the conversion contains more than Width characters, then only the first Width
462 characters are returned, and the total number of characters required to perform
463 the conversion is returned.
464 Additional conversion parameters are specified in Flags.
465 The Flags bit LEFT_JUSTIFY is always ignored.
466 All conversions are left justified in Buffer.
467 If Width is 0, PREFIX_ZERO is ignored in Flags.
468 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
469 are inserted every 3rd digit starting from the right.
470 If HEX_RADIX is set in Flags, then the output buffer will be
471 formatted in hexadecimal format.
472 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
473 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
474 then Buffer is padded with '0' characters so the combination of the optional '-'
475 sign character, '0' characters, digit characters for Value, and the Null-terminator
476 add up to Width characters.
478 If Buffer is NULL, then ASSERT().
479 If unsupported bits are set in Flags, then ASSERT().
480 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
481 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
483 @param Buffer Pointer to the output buffer for the produced Null-terminated
485 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
486 @param Value The 64-bit signed value to convert to a string.
487 @param Width The maximum number of ASCII characters to place in Buffer, not including
490 @return The number of ASCII characters in Buffer not including the Null-terminator.
502 return BasePrintLibConvertValueToString (Buffer
, Flags
, Value
, Width
, 1);