]>
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.
96 @return The number of Unicode characters in the produced output buffer not including the
103 OUT CHAR16
*StartOfBuffer
,
105 IN CONST CHAR16
*FormatString
,
111 VA_START (Marker
, FormatString
);
112 return UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
116 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
117 ASCII format string and a VA_LIST argument list
119 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
121 The Unicode string is produced by parsing the format string specified by FormatString.
122 Arguments are pulled from the variable argument list specified by Marker based on the
123 contents of the format string.
124 The number of Unicode characters in the produced output buffer is returned not including
126 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
128 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
129 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
130 If BufferSize > 1 and FormatString is NULL, then ASSERT().
131 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
132 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
134 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
135 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
136 Null-terminator, then ASSERT().
138 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
140 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
141 @param FormatString Null-terminated ASCII format string.
142 @param Marker VA_LIST marker for the variable argument list.
144 @return The number of Unicode characters in the produced output buffer not including the
150 UnicodeVSPrintAsciiFormat (
151 OUT CHAR16
*StartOfBuffer
,
153 IN CONST CHAR8
*FormatString
,
157 ASSERT_UNICODE_BUFFER(StartOfBuffer
);
158 return BasePrintLibVSPrint ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, OUTPUT_UNICODE
,FormatString
, Marker
);
162 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
163 ASCII format string and variable argument list.
165 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
167 The Unicode string is produced by parsing the format string specified by FormatString.
168 Arguments are pulled from the variable argument list based on the contents of the
170 The number of Unicode characters in the produced output buffer is returned not including
172 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
174 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
175 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
176 If BufferSize > 1 and FormatString is NULL, then ASSERT().
177 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
178 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
180 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
181 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
182 Null-terminator, then ASSERT().
184 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
186 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
187 @param FormatString Null-terminated ASCII format string.
188 @param ... Variable argument list whose contents are accessed based on the
189 format string specified by FormatString.
191 @return The number of Unicode characters in the produced output buffer not including the
197 UnicodeSPrintAsciiFormat (
198 OUT CHAR16
*StartOfBuffer
,
200 IN CONST CHAR8
*FormatString
,
206 VA_START (Marker
, FormatString
);
207 return UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
211 Converts a decimal value to a Null-terminated Unicode string.
213 Converts the decimal number specified by Value to a Null-terminated Unicode
214 string specified by Buffer containing at most Width characters. No padding of spaces
215 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
216 The number of Unicode characters in Buffer is returned not including the Null-terminator.
217 If the conversion contains more than Width characters, then only the first
218 Width characters are returned, and the total number of characters
219 required to perform the conversion is returned.
220 Additional conversion parameters are specified in Flags.
222 The Flags bit LEFT_JUSTIFY is always ignored.
223 All conversions are left justified in Buffer.
224 If Width is 0, PREFIX_ZERO is ignored in Flags.
225 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
226 are inserted every 3rd digit starting from the right.
227 If HEX_RADIX is set in Flags, then the output buffer will be
228 formatted in hexadecimal format.
229 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
230 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
231 then Buffer is padded with '0' characters so the combination of the optional '-'
232 sign character, '0' characters, digit characters for Value, and the Null-terminator
233 add up to Width characters.
234 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
235 If Buffer is NULL, then ASSERT().
236 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
237 If unsupported bits are set in Flags, then ASSERT().
238 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
239 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
241 @param Buffer Pointer to the output buffer for the produced Null-terminated
243 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
244 @param Value The 64-bit signed value to convert to a string.
245 @param Width The maximum number of Unicode characters to place in Buffer, not including
248 @return The number of Unicode characters in Buffer not including the Null-terminator.
253 UnicodeValueToString (
254 IN OUT CHAR16
*Buffer
,
260 ASSERT_UNICODE_BUFFER(Buffer
);
261 return BasePrintLibConvertValueToString ((CHAR8
*)Buffer
, Flags
, Value
, Width
, 2);
265 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
266 ASCII format string and a VA_LIST argument list.
268 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
270 The ASCII string is produced by parsing the format string specified by FormatString.
271 Arguments are pulled from the variable argument list specified by Marker based on
272 the contents of the format string.
273 The number of ASCII characters in the produced output buffer is returned not including
275 If BufferSize is 0, then no output buffer is produced and 0 is returned.
277 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
278 If BufferSize > 0 and FormatString is NULL, then ASSERT().
279 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
280 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
282 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
283 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
284 Null-terminator, then ASSERT().
286 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
288 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
289 @param FormatString Null-terminated ASCII format string.
290 @param Marker VA_LIST marker for the variable argument list.
292 @return The number of ASCII characters in the produced output buffer not including the
299 OUT CHAR8
*StartOfBuffer
,
301 IN CONST CHAR8
*FormatString
,
305 return BasePrintLibVSPrint (StartOfBuffer
, BufferSize
, 0, FormatString
, Marker
);
309 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
310 ASCII format string and variable argument list.
312 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
314 The ASCII string is produced by parsing the format string specified by FormatString.
315 Arguments are pulled from the variable argument list based on the contents of the
317 The number of ASCII characters in the produced output buffer is returned not including
319 If BufferSize is 0, then no output buffer is produced and 0 is returned.
321 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
322 If BufferSize > 0 and FormatString is NULL, then ASSERT().
323 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
324 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
326 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
327 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
328 Null-terminator, then ASSERT().
330 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
332 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
333 @param FormatString Null-terminated ASCII format string.
334 @param ... Variable argument list whose contents are accessed based on the
335 format string specified by FormatString.
337 @return The number of ASCII characters in the produced output buffer not including the
344 OUT CHAR8
*StartOfBuffer
,
346 IN CONST CHAR8
*FormatString
,
352 VA_START (Marker
, FormatString
);
353 return AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
357 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
358 Unicode format string and a VA_LIST argument list.
360 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
362 The ASCII string is produced by parsing the format string specified by FormatString.
363 Arguments are pulled from the variable argument list specified by Marker based on
364 the contents of the format string.
365 The number of ASCII characters in the produced output buffer is returned not including
367 If BufferSize is 0, then no output buffer is produced and 0 is returned.
369 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
370 If BufferSize > 0 and FormatString is NULL, then ASSERT().
371 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
372 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
373 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
375 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
376 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
377 Null-terminator, then ASSERT().
379 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
381 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
382 @param FormatString Null-terminated Unicode format string.
383 @param Marker VA_LIST marker for the variable argument list.
385 @return The number of ASCII characters in the produced output buffer not including the
391 AsciiVSPrintUnicodeFormat (
392 OUT CHAR8
*StartOfBuffer
,
394 IN CONST CHAR16
*FormatString
,
398 ASSERT_UNICODE_BUFFER (FormatString
);
399 return BasePrintLibVSPrint (StartOfBuffer
, BufferSize
, FORMAT_UNICODE
, (CHAR8
*)FormatString
, Marker
);
403 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
404 Unicode format string and variable argument list.
406 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
408 The ASCII string is produced by parsing the format string specified by FormatString.
409 Arguments are pulled from the variable argument list based on the contents of the
411 The number of ASCII characters in the produced output buffer is returned not including
413 If BufferSize is 0, then no output buffer is produced and 0 is returned.
415 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
416 If BufferSize > 0 and FormatString is NULL, then ASSERT().
417 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
418 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
419 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
421 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
422 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
423 Null-terminator, then ASSERT().
425 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
427 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
428 @param FormatString Null-terminated Unicode format string.
429 @param ... Variable argument list whose contents are accessed based on the
430 format string specified by FormatString.
432 @return The number of ASCII characters in the produced output buffer not including the
438 AsciiSPrintUnicodeFormat (
439 OUT CHAR8
*StartOfBuffer
,
441 IN CONST CHAR16
*FormatString
,
447 VA_START (Marker
, FormatString
);
448 return AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
453 Converts a decimal value to a Null-terminated ASCII string.
455 Converts the decimal number specified by Value to a Null-terminated ASCII string
456 specified by Buffer containing at most Width characters. No padding of spaces
458 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
459 The number of ASCII characters in Buffer is returned not including the Null-terminator.
460 If the conversion contains more than Width characters, then only the first Width
461 characters are returned, and the total number of characters required to perform
462 the conversion is returned.
463 Additional conversion parameters are specified in Flags.
464 The Flags bit LEFT_JUSTIFY is always ignored.
465 All conversions are left justified in Buffer.
466 If Width is 0, PREFIX_ZERO is ignored in Flags.
467 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
468 are inserted every 3rd digit starting from the right.
469 If HEX_RADIX is set in Flags, then the output buffer will be
470 formatted in hexadecimal format.
471 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
472 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
473 then Buffer is padded with '0' characters so the combination of the optional '-'
474 sign character, '0' characters, digit characters for Value, and the Null-terminator
475 add up to Width characters.
477 If Buffer is NULL, then ASSERT().
478 If unsupported bits are set in Flags, then ASSERT().
479 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
480 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
482 @param Buffer Pointer to the output buffer for the produced Null-terminated
484 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
485 @param Value The 64-bit signed value to convert to a string.
486 @param Width The maximum number of ASCII characters to place in Buffer, not including
489 @return The number of ASCII characters in Buffer not including the Null-terminator.
501 return BasePrintLibConvertValueToString (Buffer
, Flags
, Value
, Width
, 1);