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.
23 #include "PrintLibInternal.h"
25 #define WARNING_STATUS_NUMBER 4
26 #define ERROR_STATUS_NUMBER 24
27 #define ASSERT_UNICODE_BUFFER(Buffer) ASSERT ((((UINTN) (Buffer)) & 0x01) == 0)
29 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8
*StatusString
[] = {
30 "Success", // RETURN_SUCCESS = 0
31 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1
32 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2
33 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3
34 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4
35 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
36 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
37 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
38 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
39 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
40 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
41 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
42 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
43 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
44 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
45 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
46 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
47 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
48 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
49 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
50 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
51 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
52 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
53 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
54 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
55 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
56 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
57 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
58 "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
62 Worker function that produces a Null-terminated string in an output buffer
63 based on a Null-terminated format string and a VA_LIST argument list.
65 VSPrint function to process format and place the results in Buffer. Since a
66 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
67 this is the main print working routine.
69 @param Buffer Character buffer to print the results of the parsing
71 @param BufferSize Maximum number of characters to put into buffer.
72 @param Flags Intial flags value.
73 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set.
74 @param Format Null-terminated format string.
75 @param Marker Vararg list consumed by processing Format.
77 @return Number of characters printed not including the Null-terminator.
85 IN CONST CHAR8
*Format
,
89 CHAR8
*OriginalBuffer
;
91 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
92 UINTN BytesPerOutputCharacter
;
93 UINTN BytesPerFormatCharacter
;
95 UINTN FormatCharacter
;
99 CONST CHAR8
*ArgumentString
;
105 INTN BytesPerArgumentCharacter
;
106 UINTN ArgumentCharacter
;
114 RETURN_STATUS Status
;
116 if (BufferSize
== 0) {
119 ASSERT (Buffer
!= NULL
);
121 if ((Flags
& OUTPUT_UNICODE
) != 0) {
122 BytesPerOutputCharacter
= 2;
124 BytesPerOutputCharacter
= 1;
128 // Reserve space for the Null terminator.
131 OriginalBuffer
= Buffer
;
133 // Set the tag for the end of the input Buffer.
135 EndBuffer
= Buffer
+ BufferSize
* BytesPerOutputCharacter
;
137 if ((Flags
& FORMAT_UNICODE
) != 0) {
139 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
140 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
142 ASSERT (StrSize ((CHAR16
*) Format
) != 0);
143 BytesPerFormatCharacter
= 2;
147 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
148 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
150 ASSERT (AsciiStrSize (Format
) != 0);
151 BytesPerFormatCharacter
= 1;
158 // Get the first character from the format string
160 FormatCharacter
= (*Format
| (*(Format
+ 1) << 8)) & FormatMask
;
163 // Loop until the end of the format string is reached or the output buffer is full
165 while (FormatCharacter
!= 0 && Buffer
< EndBuffer
) {
167 // Clear all the flag bits except those that may have been passed in
169 Flags
&= (OUTPUT_UNICODE
| FORMAT_UNICODE
);
172 // Set the default width to zero, and the default precision to 1
182 switch (FormatCharacter
) {
185 // Parse Flags and Width
187 for (Done
= FALSE
; !Done
; ) {
188 Format
+= BytesPerFormatCharacter
;
189 FormatCharacter
= (*Format
| (*(Format
+ 1) << 8)) & FormatMask
;
190 switch (FormatCharacter
) {
195 Flags
|= LEFT_JUSTIFY
;
198 Flags
|= PREFIX_SIGN
;
201 Flags
|= PREFIX_BLANK
;
211 if ((Flags
& PRECISION
) == 0) {
212 Flags
|= PAD_TO_WIDTH
;
213 Width
= VA_ARG (Marker
, UINTN
);
215 Precision
= VA_ARG (Marker
, UINTN
);
219 if ((Flags
& PRECISION
) == 0) {
220 Flags
|= PREFIX_ZERO
;
231 for (Count
= 0; ((FormatCharacter
>= '0') && (FormatCharacter
<= '9')); ){
232 Count
= (Count
* 10) + FormatCharacter
- '0';
233 Format
+= BytesPerFormatCharacter
;
234 FormatCharacter
= (*Format
| (*(Format
+ 1) << 8)) & FormatMask
;
236 Format
-= BytesPerFormatCharacter
;
237 if ((Flags
& PRECISION
) == 0) {
238 Flags
|= PAD_TO_WIDTH
;
247 // Make no output if Format string terminates unexpectedly when
248 // looking up for flag, width, precision and type.
250 Format
-= BytesPerFormatCharacter
;
253 // break skipped on purpose.
262 // Handle each argument type
264 switch (FormatCharacter
) {
267 // Flag space, +, 0, L & l are invalid for type p.
269 Flags
&= ~(PREFIX_BLANK
| PREFIX_SIGN
| PREFIX_ZERO
| LONG_TYPE
);
270 if (sizeof (VOID
*) > 4) {
274 Flags
|= PREFIX_ZERO
;
276 // break skipped on purpose
281 // break skipped on purpose
284 if ((Flags
& LONG_TYPE
) == 0) {
285 Value
= (VA_ARG (Marker
, int));
287 Value
= VA_ARG (Marker
, INT64
);
289 if ((Flags
& PREFIX_BLANK
) != 0) {
292 if ((Flags
& PREFIX_SIGN
) != 0) {
295 if ((Flags
& COMMA_TYPE
) != 0) {
298 if ((Flags
& RADIX_HEX
) == 0) {
301 Flags
&= (~PREFIX_ZERO
);
305 Flags
|= PREFIX_SIGN
;
312 if ((Flags
& LONG_TYPE
) == 0 && Value
< 0) {
313 Value
= (unsigned int)Value
;
317 // Convert Value to a reversed string
319 Count
= BasePrintLibValueToString (ValueBuffer
, Value
, Radix
);
320 if (Value
== 0 && Precision
== 0) {
323 ArgumentString
= (CHAR8
*)ValueBuffer
+ Count
;
329 if (Comma
&& Count
!= 0) {
330 Count
+= ((Count
- 1) / 3);
336 Flags
|= ARGUMENT_REVERSED
;
338 if ((Flags
& PREFIX_ZERO
) != 0) {
339 if ((Flags
& LEFT_JUSTIFY
) == 0) {
340 if ((Flags
& PAD_TO_WIDTH
) != 0) {
341 if ((Flags
& PRECISION
) == 0) {
351 Flags
|= ARGUMENT_UNICODE
;
353 // break skipped on purpose
356 ArgumentString
= (CHAR8
*)VA_ARG (Marker
, CHAR8
*);
357 if (ArgumentString
== NULL
) {
358 Flags
&= (~ARGUMENT_UNICODE
);
359 ArgumentString
= "<null string>";
364 Character
= VA_ARG (Marker
, UINTN
) & 0xffff;
365 ArgumentString
= (CHAR8
*)&Character
;
366 Flags
|= ARGUMENT_UNICODE
;
370 TmpGuid
= VA_ARG (Marker
, GUID
*);
371 if (TmpGuid
== NULL
) {
372 ArgumentString
= "<null guid>";
376 MAXIMUM_VALUE_CHARACTERS
,
378 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
391 ArgumentString
= ValueBuffer
;
396 TmpTime
= VA_ARG (Marker
, TIME
*);
397 if (TmpTime
== NULL
) {
398 ArgumentString
= "<null time>";
402 MAXIMUM_VALUE_CHARACTERS
,
404 "%02d/%02d/%04d %02d:%02d",
411 ArgumentString
= ValueBuffer
;
416 Status
= VA_ARG (Marker
, RETURN_STATUS
);
417 ArgumentString
= ValueBuffer
;
418 if (RETURN_ERROR (Status
)) {
422 Index
= Status
& ~MAX_BIT
;
423 if (Index
> 0 && Index
<= ERROR_STATUS_NUMBER
) {
424 ArgumentString
= StatusString
[Index
+ WARNING_STATUS_NUMBER
];
427 Index
= (UINTN
) Status
;
428 if (Index
<= WARNING_STATUS_NUMBER
) {
429 ArgumentString
= StatusString
[Index
];
432 if (ArgumentString
== ValueBuffer
) {
433 BasePrintLibSPrint ((CHAR8
*) ValueBuffer
, MAXIMUM_VALUE_CHARACTERS
, 0, "%08X", Status
);
438 ArgumentString
= "\n\r";
444 // if the type is '%' or unknown, then print it to the screen
446 ArgumentString
= (CHAR8
*)&FormatCharacter
;
447 Flags
|= ARGUMENT_UNICODE
;
453 ArgumentString
= "\n\r";
457 ArgumentString
= (CHAR8
*)&FormatCharacter
;
458 Flags
|= ARGUMENT_UNICODE
;
463 // Retrieve the ArgumentString attriubutes
465 if ((Flags
& ARGUMENT_UNICODE
) != 0) {
466 ArgumentMask
= 0xffff;
467 BytesPerArgumentCharacter
= 2;
470 BytesPerArgumentCharacter
= 1;
472 if ((Flags
& ARGUMENT_REVERSED
) != 0) {
473 BytesPerArgumentCharacter
= -BytesPerArgumentCharacter
;
476 // Compute the number of characters in ArgumentString and store it in Count
477 // ArgumentString is either null-terminated, or it contains Precision characters
479 for (Count
= 0; Count
< Precision
|| ((Flags
& PRECISION
) == 0); Count
++) {
480 ArgumentCharacter
= ((ArgumentString
[Count
* BytesPerArgumentCharacter
] & 0xff) | ((ArgumentString
[Count
* BytesPerArgumentCharacter
+ 1]) << 8)) & ArgumentMask
;
481 if (ArgumentCharacter
== 0) {
487 if (Precision
< Count
) {
492 // Pad before the string
494 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
)) {
495 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, Width
- Precision
, ' ', BytesPerOutputCharacter
);
500 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, Prefix
, BytesPerOutputCharacter
);
502 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, Precision
- Count
, '0', BytesPerOutputCharacter
);
504 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, Precision
- Count
, ' ', BytesPerOutputCharacter
);
506 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, Prefix
, BytesPerOutputCharacter
);
511 // Output the Prefix character if it is present
519 // Copy the string into the output buffer performing the required type conversions
521 while (Index
< Count
) {
522 ArgumentCharacter
= ((*ArgumentString
& 0xff) | (*(ArgumentString
+ 1) << 8)) & ArgumentMask
;
524 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, ArgumentCharacter
, BytesPerOutputCharacter
);
525 ArgumentString
+= BytesPerArgumentCharacter
;
533 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, ',', BytesPerOutputCharacter
);
540 // Pad after the string
542 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) {
543 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, Width
- Precision
, ' ', BytesPerOutputCharacter
);
547 // Get the next character from the format string
549 Format
+= BytesPerFormatCharacter
;
552 // Get the next character from the format string
554 FormatCharacter
= (*Format
| (*(Format
+ 1) << 8)) & FormatMask
;
558 // Null terminate the Unicode or ASCII string
560 BasePrintLibFillBuffer (Buffer
, EndBuffer
+ BytesPerOutputCharacter
, 1, 0, BytesPerOutputCharacter
);
562 // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
563 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
565 ASSERT ((((Flags
& OUTPUT_UNICODE
) == 0)) || (StrSize ((CHAR16
*) OriginalBuffer
) != 0));
567 // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength
568 // ASCII characters if PcdMaximumAsciiStringLength is not zero.
570 ASSERT ((((Flags
& OUTPUT_UNICODE
) != 0)) || (AsciiStrSize (OriginalBuffer
) != 0));
572 return ((Buffer
- OriginalBuffer
) / BytesPerOutputCharacter
);
576 Worker function that produces a Null-terminated string in an output buffer
577 based on a Null-terminated format string and variable argument list.
579 VSPrint function to process format and place the results in Buffer. Since a
580 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
581 this is the main print working routine.
583 @param Buffer Character buffer to print the results of the parsing
585 @param BufferSize Maximum number of characters to put into buffer.
587 @param Flags Intial flags value.
588 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
589 @param FormatString Null-terminated format string.
591 @return Number of characters printed not including the Null-terminator.
596 OUT CHAR8
*StartOfBuffer
,
599 IN CONST CHAR8
*FormatString
,
604 UINTN NumberOfPrinted
;
606 VA_START (Marker
, FormatString
);
607 NumberOfPrinted
= BasePrintLibVSPrint (StartOfBuffer
, BufferSize
, Flags
, FormatString
, Marker
);
609 return NumberOfPrinted
;
613 Produces a Null-terminated Unicode string in an output buffer based on
614 a Null-terminated Unicode format string and a VA_LIST argument list
616 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
618 The Unicode string is produced by parsing the format string specified by FormatString.
619 Arguments are pulled from the variable argument list specified by Marker based on the
620 contents of the format string.
621 The number of Unicode characters in the produced output buffer is returned not including
623 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
625 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
626 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
627 If BufferSize > 1 and FormatString is NULL, then ASSERT().
628 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
629 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
630 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
632 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
633 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
634 Null-terminator, then ASSERT().
636 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
638 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
639 @param FormatString Null-terminated Unicode format string.
640 @param Marker VA_LIST marker for the variable argument list.
642 @return The number of Unicode characters in the produced output buffer not including the
649 OUT CHAR16
*StartOfBuffer
,
651 IN CONST CHAR16
*FormatString
,
655 ASSERT_UNICODE_BUFFER(StartOfBuffer
);
656 ASSERT_UNICODE_BUFFER(FormatString
);
657 return BasePrintLibVSPrint ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, FORMAT_UNICODE
| OUTPUT_UNICODE
, (CHAR8
*)FormatString
, Marker
);
661 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
662 Unicode format string and variable argument list.
664 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
666 The Unicode string is produced by parsing the format string specified by FormatString.
667 Arguments are pulled from the variable argument list based on the contents of the format string.
668 The number of Unicode characters in the produced output buffer is returned not including
670 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
672 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
673 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
674 If BufferSize > 1 and FormatString is NULL, then ASSERT().
675 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
676 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
677 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
679 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
680 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
681 Null-terminator, then ASSERT().
683 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
685 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
686 @param FormatString Null-terminated Unicode format string.
688 @return The number of Unicode characters in the produced output buffer not including the
695 OUT CHAR16
*StartOfBuffer
,
697 IN CONST CHAR16
*FormatString
,
702 UINTN NumberOfPrinted
;
704 VA_START (Marker
, FormatString
);
705 NumberOfPrinted
= UnicodeVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
707 return NumberOfPrinted
;
711 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
712 ASCII format string and a VA_LIST argument list
714 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
716 The Unicode string is produced by parsing the format string specified by FormatString.
717 Arguments are pulled from the variable argument list specified by Marker based on the
718 contents of the format string.
719 The number of Unicode characters in the produced output buffer is returned not including
721 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
723 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
724 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
725 If BufferSize > 1 and FormatString is NULL, then ASSERT().
726 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
727 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
729 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
730 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
731 Null-terminator, then ASSERT().
733 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
735 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
736 @param FormatString Null-terminated Unicode format string.
737 @param Marker VA_LIST marker for the variable argument list.
739 @return The number of Unicode characters in the produced output buffer not including the
745 UnicodeVSPrintAsciiFormat (
746 OUT CHAR16
*StartOfBuffer
,
748 IN CONST CHAR8
*FormatString
,
752 ASSERT_UNICODE_BUFFER(StartOfBuffer
);
753 return BasePrintLibVSPrint ((CHAR8
*)StartOfBuffer
, BufferSize
>> 1, OUTPUT_UNICODE
,FormatString
, Marker
);
757 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
758 ASCII format string and variable argument list.
760 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
762 The Unicode string is produced by parsing the format string specified by FormatString.
763 Arguments are pulled from the variable argument list based on the contents of the
765 The number of Unicode characters in the produced output buffer is returned not including
767 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
769 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
770 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
771 If BufferSize > 1 and FormatString is NULL, then ASSERT().
772 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
773 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
775 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
776 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
777 Null-terminator, then ASSERT().
779 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
781 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
782 @param FormatString Null-terminated Unicode format string.
784 @return The number of Unicode characters in the produced output buffer not including the
790 UnicodeSPrintAsciiFormat (
791 OUT CHAR16
*StartOfBuffer
,
793 IN CONST CHAR8
*FormatString
,
798 UINTN NumberOfPrinted
;
800 VA_START (Marker
, FormatString
);
801 NumberOfPrinted
= UnicodeVSPrintAsciiFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
803 return NumberOfPrinted
;
807 Converts a decimal value to a Null-terminated Unicode string.
809 Converts the decimal number specified by Value to a Null-terminated Unicode
810 string specified by Buffer containing at most Width characters. No padding of spaces
811 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
812 The number of Unicode characters in Buffer is returned not including the Null-terminator.
813 If the conversion contains more than Width characters, then only the first
814 Width characters are returned, and the total number of characters
815 required to perform the conversion is returned.
816 Additional conversion parameters are specified in Flags.
818 The Flags bit LEFT_JUSTIFY is always ignored.
819 All conversions are left justified in Buffer.
820 If Width is 0, PREFIX_ZERO is ignored in Flags.
821 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
822 are inserted every 3rd digit starting from the right.
823 If RADIX_HEX is set in Flags, then the output buffer will be
824 formatted in hexadecimal format.
825 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
826 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
827 then Buffer is padded with '0' characters so the combination of the optional '-'
828 sign character, '0' characters, digit characters for Value, and the Null-terminator
829 add up to Width characters.
830 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
831 If Buffer is NULL, then ASSERT().
832 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
833 If unsupported bits are set in Flags, then ASSERT().
834 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
835 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
837 @param Buffer Pointer to the output buffer for the produced Null-terminated
839 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
840 @param Value The 64-bit signed value to convert to a string.
841 @param Width The maximum number of Unicode characters to place in Buffer, not including
844 @return The number of Unicode characters in Buffer not including the Null-terminator.
849 UnicodeValueToString (
850 IN OUT CHAR16
*Buffer
,
856 ASSERT_UNICODE_BUFFER(Buffer
);
857 return BasePrintLibConvertValueToString ((CHAR8
*)Buffer
, Flags
, Value
, Width
, 2);
861 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
862 ASCII format string and a VA_LIST argument list.
864 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
866 The ASCII string is produced by parsing the format string specified by FormatString.
867 Arguments are pulled from the variable argument list specified by Marker based on
868 the contents of the format string.
869 The number of ASCII characters in the produced output buffer is returned not including
871 If BufferSize is 0, then no output buffer is produced and 0 is returned.
873 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
874 If BufferSize > 0 and FormatString is NULL, then ASSERT().
875 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
876 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
878 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
879 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
880 Null-terminator, then ASSERT().
882 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
884 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
885 @param FormatString Null-terminated Unicode format string.
886 @param Marker VA_LIST marker for the variable argument list.
888 @return The number of ASCII characters in the produced output buffer not including the
895 OUT CHAR8
*StartOfBuffer
,
897 IN CONST CHAR8
*FormatString
,
901 return BasePrintLibVSPrint (StartOfBuffer
, BufferSize
, 0, FormatString
, Marker
);
905 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
906 ASCII format string and variable argument list.
908 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
910 The ASCII string is produced by parsing the format string specified by FormatString.
911 Arguments are pulled from the variable argument list based on the contents of the
913 The number of ASCII characters in the produced output buffer is returned not including
915 If BufferSize is 0, then no output buffer is produced and 0 is returned.
917 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
918 If BufferSize > 0 and FormatString is NULL, then ASSERT().
919 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
920 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
922 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
923 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
924 Null-terminator, then ASSERT().
926 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
928 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
929 @param FormatString Null-terminated Unicode format string.
931 @return The number of ASCII characters in the produced output buffer not including the
938 OUT CHAR8
*StartOfBuffer
,
940 IN CONST CHAR8
*FormatString
,
945 UINTN NumberOfPrinted
;
947 VA_START (Marker
, FormatString
);
948 NumberOfPrinted
= AsciiVSPrint (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
950 return NumberOfPrinted
;
954 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
955 ASCII format string and a VA_LIST argument list.
957 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
959 The ASCII string is produced by parsing the format string specified by FormatString.
960 Arguments are pulled from the variable argument list specified by Marker based on
961 the contents of the format string.
962 The number of ASCII characters in the produced output buffer is returned not including
964 If BufferSize is 0, then no output buffer is produced and 0 is returned.
966 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
967 If BufferSize > 0 and FormatString is NULL, then ASSERT().
968 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
969 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
970 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
972 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
973 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
974 Null-terminator, then ASSERT().
976 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
978 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
979 @param FormatString Null-terminated Unicode format string.
980 @param Marker VA_LIST marker for the variable argument list.
982 @return The number of ASCII characters in the produced output buffer not including the
988 AsciiVSPrintUnicodeFormat (
989 OUT CHAR8
*StartOfBuffer
,
991 IN CONST CHAR16
*FormatString
,
995 ASSERT_UNICODE_BUFFER (FormatString
);
996 return BasePrintLibVSPrint (StartOfBuffer
, BufferSize
, FORMAT_UNICODE
, (CHAR8
*)FormatString
, Marker
);
1000 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
1001 ASCII format string and variable argument list.
1003 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
1005 The ASCII string is produced by parsing the format string specified by FormatString.
1006 Arguments are pulled from the variable argument list based on the contents of the
1008 The number of ASCII characters in the produced output buffer is returned not including
1009 the Null-terminator.
1010 If BufferSize is 0, then no output buffer is produced and 0 is returned.
1012 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
1013 If BufferSize > 0 and FormatString is NULL, then ASSERT().
1014 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
1015 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
1016 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
1018 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
1019 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
1020 Null-terminator, then ASSERT().
1022 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
1024 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
1025 @param FormatString Null-terminated Unicode format string.
1027 @return The number of ASCII characters in the produced output buffer not including the
1033 AsciiSPrintUnicodeFormat (
1034 OUT CHAR8
*StartOfBuffer
,
1035 IN UINTN BufferSize
,
1036 IN CONST CHAR16
*FormatString
,
1041 UINTN NumberOfPrinted
;
1043 VA_START (Marker
, FormatString
);
1044 NumberOfPrinted
= AsciiVSPrintUnicodeFormat (StartOfBuffer
, BufferSize
, FormatString
, Marker
);
1046 return NumberOfPrinted
;
1051 Converts a decimal value to a Null-terminated ASCII string.
1053 Converts the decimal number specified by Value to a Null-terminated ASCII string
1054 specified by Buffer containing at most Width characters. No padding of spaces
1056 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
1057 The number of ASCII characters in Buffer is returned not including the Null-terminator.
1058 If the conversion contains more than Width characters, then only the first Width
1059 characters are returned, and the total number of characters required to perform
1060 the conversion is returned.
1061 Additional conversion parameters are specified in Flags.
1062 The Flags bit LEFT_JUSTIFY is always ignored.
1063 All conversions are left justified in Buffer.
1064 If Width is 0, PREFIX_ZERO is ignored in Flags.
1065 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
1066 are inserted every 3rd digit starting from the right.
1067 If RADIX_HEX is set in Flags, then the output buffer will be
1068 formatted in hexadecimal format.
1069 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
1070 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
1071 then Buffer is padded with '0' characters so the combination of the optional '-'
1072 sign character, '0' characters, digit characters for Value, and the Null-terminator
1073 add up to Width characters.
1075 If Buffer is NULL, then ASSERT().
1076 If unsupported bits are set in Flags, then ASSERT().
1077 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
1078 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
1080 @param Buffer Pointer to the output buffer for the produced Null-terminated
1082 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
1083 @param Value The 64-bit signed value to convert to a string.
1084 @param Width The maximum number of ASCII characters to place in Buffer, not including
1085 the Null-terminator.
1087 @return The number of ASCII characters in Buffer not including the Null-terminator.
1092 AsciiValueToString (
1093 IN OUT CHAR8
*Buffer
,
1099 return BasePrintLibConvertValueToString (Buffer
, Flags
, Value
, Width
, 1);