]>
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 ... The variable argument list.
95 @return The number of Unicode characters in the produced output buffer not including the
102 OUT CHAR16
*StartOfBuffer
,
104 IN CONST CHAR16
*FormatString
,
110 VA_START (Marker
, FormatString
);
111 return UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
115 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
116 ASCII format string and a VA_LIST argument list
118 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
120 The Unicode string is produced by parsing the format string specified by FormatString.
121 Arguments are pulled from the variable argument list specified by Marker based on the
122 contents of the format string.
123 The number of Unicode characters in the produced output buffer is returned not including
125 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
127 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
128 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
129 If BufferSize > 1 and FormatString is NULL, then ASSERT().
130 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
131 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
133 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
134 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
135 Null-terminator, then ASSERT().
137 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
139 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
140 @param FormatString Null-terminated ASCII format string.
141 @param Marker VA_LIST marker for the variable argument list.
143 @return The number of Unicode characters in the produced output buffer not including the
149 UnicodeVSPrintAsciiFormat (
150 OUT CHAR16
*StartOfBuffer
,
152 IN CONST CHAR8
*FormatString
,
156 ASSERT_UNICODE_BUFFER(StartOfBuffer
);
157 return BasePrintLibVSPrint ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, OUTPUT_UNICODE
,FormatString
, Marker
);
161 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
162 ASCII format string and variable argument list.
164 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
166 The Unicode string is produced by parsing the format string specified by FormatString.
167 Arguments are pulled from the variable argument list based on the contents of the
169 The number of Unicode characters in the produced output buffer is returned not including
171 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
173 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
174 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
175 If BufferSize > 1 and FormatString is NULL, then ASSERT().
176 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
177 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
179 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
180 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
181 Null-terminator, then ASSERT().
183 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
185 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
186 @param FormatString Null-terminated ASCII format string.
187 @param ... The variable argument list.
189 @return The number of Unicode characters in the produced output buffer not including the
195 UnicodeSPrintAsciiFormat (
196 OUT CHAR16
*StartOfBuffer
,
198 IN CONST CHAR8
*FormatString
,
204 VA_START (Marker
, FormatString
);
205 return UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
209 Converts a decimal value to a Null-terminated Unicode string.
211 Converts the decimal number specified by Value to a Null-terminated Unicode
212 string specified by Buffer containing at most Width characters. No padding of spaces
213 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
214 The number of Unicode characters in Buffer is returned not including the Null-terminator.
215 If the conversion contains more than Width characters, then only the first
216 Width characters are returned, and the total number of characters
217 required to perform the conversion is returned.
218 Additional conversion parameters are specified in Flags.
220 The Flags bit LEFT_JUSTIFY is always ignored.
221 All conversions are left justified in Buffer.
222 If Width is 0, PREFIX_ZERO is ignored in Flags.
223 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
224 are inserted every 3rd digit starting from the right.
225 If HEX_RADIX is set in Flags, then the output buffer will be
226 formatted in hexadecimal format.
227 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
228 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
229 then Buffer is padded with '0' characters so the combination of the optional '-'
230 sign character, '0' characters, digit characters for Value, and the Null-terminator
231 add up to Width characters.
232 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
233 If Buffer is NULL, then ASSERT().
234 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
235 If unsupported bits are set in Flags, then ASSERT().
236 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
237 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
239 @param Buffer Pointer to the output buffer for the produced Null-terminated
241 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
242 @param Value The 64-bit signed value to convert to a string.
243 @param Width The maximum number of Unicode characters to place in Buffer, not including
246 @return The number of Unicode characters in Buffer not including the Null-terminator.
251 UnicodeValueToString (
252 IN OUT CHAR16
*Buffer
,
258 ASSERT_UNICODE_BUFFER(Buffer
);
259 return BasePrintLibConvertValueToString ((CHAR8
*)Buffer
, Flags
, Value
, Width
, 2);
263 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
264 ASCII format string and a VA_LIST argument list.
266 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
268 The ASCII string is produced by parsing the format string specified by FormatString.
269 Arguments are pulled from the variable argument list specified by Marker based on
270 the contents of the format string.
271 The number of ASCII characters in the produced output buffer is returned not including
273 If BufferSize is 0, then no output buffer is produced and 0 is returned.
275 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
276 If BufferSize > 0 and FormatString is NULL, then ASSERT().
277 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
278 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
280 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
281 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
282 Null-terminator, then ASSERT().
284 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
286 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
287 @param FormatString Null-terminated ASCII format string.
288 @param Marker VA_LIST marker for the variable argument list.
290 @return The number of ASCII characters in the produced output buffer not including the
297 OUT CHAR8
*StartOfBuffer
,
299 IN CONST CHAR8
*FormatString
,
303 return BasePrintLibVSPrint (StartOfBuffer
, BufferSize
, 0, FormatString
, Marker
);
307 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
308 ASCII format string and variable argument list.
310 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
312 The ASCII string is produced by parsing the format string specified by FormatString.
313 Arguments are pulled from the variable argument list based on the contents of the
315 The number of ASCII characters in the produced output buffer is returned not including
317 If BufferSize is 0, then no output buffer is produced and 0 is returned.
319 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
320 If BufferSize > 0 and FormatString is NULL, then ASSERT().
321 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
322 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
324 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
325 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
326 Null-terminator, then ASSERT().
328 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
330 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
331 @param FormatString Null-terminated ASCII format string.
332 @param ... The variable argument list.
334 @return The number of ASCII characters in the produced output buffer not including the
341 OUT CHAR8
*StartOfBuffer
,
343 IN CONST CHAR8
*FormatString
,
349 VA_START (Marker
, FormatString
);
350 return AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
354 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
355 Unicode format string and a VA_LIST argument list.
357 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
359 The ASCII string is produced by parsing the format string specified by FormatString.
360 Arguments are pulled from the variable argument list specified by Marker based on
361 the contents of the format string.
362 The number of ASCII characters in the produced output buffer is returned not including
364 If BufferSize is 0, then no output buffer is produced and 0 is returned.
366 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
367 If BufferSize > 0 and FormatString is NULL, then ASSERT().
368 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
369 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
370 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
372 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
373 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
374 Null-terminator, then ASSERT().
376 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
378 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
379 @param FormatString Null-terminated Unicode format string.
380 @param Marker VA_LIST marker for the variable argument list.
382 @return The number of ASCII characters in the produced output buffer not including the
388 AsciiVSPrintUnicodeFormat (
389 OUT CHAR8
*StartOfBuffer
,
391 IN CONST CHAR16
*FormatString
,
395 ASSERT_UNICODE_BUFFER (FormatString
);
396 return BasePrintLibVSPrint (StartOfBuffer
, BufferSize
, FORMAT_UNICODE
, (CHAR8
*)FormatString
, Marker
);
400 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
401 Unicode format string and variable argument list.
403 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
405 The ASCII string is produced by parsing the format string specified by FormatString.
406 Arguments are pulled from the variable argument list based on the contents of the
408 The number of ASCII characters in the produced output buffer is returned not including
410 If BufferSize is 0, then no output buffer is produced and 0 is returned.
412 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
413 If BufferSize > 0 and FormatString is NULL, then ASSERT().
414 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
415 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
416 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
418 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
419 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
420 Null-terminator, then ASSERT().
422 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
424 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
425 @param FormatString Null-terminated Unicode format string.
426 @param ... The variable argument list.
428 @return The number of ASCII characters in the produced output buffer not including the
434 AsciiSPrintUnicodeFormat (
435 OUT CHAR8
*StartOfBuffer
,
437 IN CONST CHAR16
*FormatString
,
443 VA_START (Marker
, FormatString
);
444 return AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
449 Converts a decimal value to a Null-terminated ASCII string.
451 Converts the decimal number specified by Value to a Null-terminated ASCII string
452 specified by Buffer containing at most Width characters. No padding of spaces
454 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
455 The number of ASCII characters in Buffer is returned not including the Null-terminator.
456 If the conversion contains more than Width characters, then only the first Width
457 characters are returned, and the total number of characters required to perform
458 the conversion is returned.
459 Additional conversion parameters are specified in Flags.
460 The Flags bit LEFT_JUSTIFY is always ignored.
461 All conversions are left justified in Buffer.
462 If Width is 0, PREFIX_ZERO is ignored in Flags.
463 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
464 are inserted every 3rd digit starting from the right.
465 If HEX_RADIX is set in Flags, then the output buffer will be
466 formatted in hexadecimal format.
467 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.
468 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
469 then Buffer is padded with '0' characters so the combination of the optional '-'
470 sign character, '0' characters, digit characters for Value, and the Null-terminator
471 add up to Width characters.
473 If Buffer is NULL, then ASSERT().
474 If unsupported bits are set in Flags, then ASSERT().
475 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().
476 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
478 @param Buffer Pointer to the output buffer for the produced Null-terminated
480 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
481 @param Value The 64-bit signed value to convert to a string.
482 @param Width The maximum number of ASCII characters to place in Buffer, not including
485 @return The number of ASCII characters in Buffer not including the Null-terminator.
491 IN OUT CHAR8
*Buffer
,
497 return BasePrintLibConvertValueToString (Buffer
, Flags
, Value
, Width
, 1);