2 Print Library internal worker functions.
4 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
5 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 WARNING_STATUS_NUMBER 5
18 #define ERROR_STATUS_NUMBER 33
20 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr
[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
22 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8
*mStatusString
[] = {
23 "Success", // RETURN_SUCCESS = 0
24 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1
25 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2
26 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3
27 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4
28 "Warning Stale Data", // RETURN_WARN_STALE_DATA = 5
29 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
30 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
31 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
32 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
33 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
34 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
35 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
36 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
37 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
38 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
39 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
40 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
41 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
42 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
43 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
44 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
45 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
46 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
47 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
48 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
49 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
50 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
51 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
52 "Protocol Error", // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
53 "Incompatible Version", // RETURN_INCOMPATIBLE_VERSION = 25 | MAX_BIT
54 "Security Violation", // RETURN_SECURITY_VIOLATION = 26 | MAX_BIT
55 "CRC Error", // RETURN_CRC_ERROR = 27 | MAX_BIT
56 "End of Media", // RETURN_END_OF_MEDIA = 28 | MAX_BIT
57 "Reserved (29)", // RESERVED = 29 | MAX_BIT
58 "Reserved (30)", // RESERVED = 30 | MAX_BIT
59 "End of File", // RETURN_END_OF_FILE = 31 | MAX_BIT
60 "Invalid Language", // RETURN_INVALID_LANGUAGE = 32 | MAX_BIT
61 "Compromised Data" // RETURN_COMPROMISED_DATA = 33 | MAX_BIT
66 Internal function that places the character into the Buffer.
68 Internal function that places ASCII or Unicode character into the Buffer.
70 @param Buffer The buffer to place the Unicode or ASCII string.
71 @param EndBuffer The end of the input Buffer. No characters will be
73 @param Length The count of character to be placed into Buffer.
74 (Negative value indicates no buffer fill.)
75 @param Character The character to be placed into Buffer.
76 @param Increment The character increment in Buffer.
82 BasePrintLibFillBuffer (
92 for (Index
= 0; Index
< Length
&& Buffer
< EndBuffer
; Index
++) {
93 *Buffer
= (CHAR8
) Character
;
95 *(Buffer
+ 1) = (CHAR8
)(Character
>> 8);
104 Internal function that convert a number to a string in Buffer.
106 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.
108 @param Buffer Location to place the ASCII string of Value.
109 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.
110 @param Radix Radix of the value
112 @return A pointer to the end of buffer filled with ASCII string.
116 BasePrintLibValueToString (
117 IN OUT CHAR8
*Buffer
,
125 // Loop to convert one digit at a time in reverse order
129 Value
= (INT64
)DivU64x32Remainder ((UINT64
)Value
, (UINT32
)Radix
, &Remainder
);
130 *(++Buffer
) = mHexStr
[Remainder
];
131 } while (Value
!= 0);
134 // Return pointer of the end of filled buffer.
140 Internal function that converts a decimal value to a Null-terminated string.
142 Converts the decimal number specified by Value to a Null-terminated
143 string specified by Buffer containing at most Width characters.
144 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
145 The total number of characters placed in Buffer is returned.
146 If the conversion contains more than Width characters, then only the first
147 Width characters are returned, and the total number of characters
148 required to perform the conversion is returned.
149 Additional conversion parameters are specified in Flags.
150 The Flags bit LEFT_JUSTIFY is always ignored.
151 All conversions are left justified in Buffer.
152 If Width is 0, PREFIX_ZERO is ignored in Flags.
153 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
154 are inserted every 3rd digit starting from the right.
155 If Value is < 0, then the fist character in Buffer is a '-'.
156 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
157 then Buffer is padded with '0' characters so the combination of the optional '-'
158 sign character, '0' characters, digit characters for Value, and the Null-terminator
159 add up to Width characters.
161 If Buffer is NULL, then ASSERT().
162 If unsupported bits are set in Flags, then ASSERT().
163 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
165 @param Buffer The pointer to the output buffer for the produced Null-terminated
167 @param Flags The bitmask of flags that specify left justification, zero pad,
169 @param Value The 64-bit signed value to convert to a string.
170 @param Width The maximum number of characters to place in Buffer, not including
172 @param Increment The character increment in Buffer.
174 @return Total number of characters required to perform the conversion.
178 BasePrintLibConvertValueToString (
179 IN OUT CHAR8
*Buffer
,
186 CHAR8
*OriginalBuffer
;
188 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
189 CHAR8
*ValueBufferPtr
;
196 // Make sure Buffer is not NULL and Width < MAXIMUM
198 ASSERT (Buffer
!= NULL
);
199 ASSERT (Width
< MAXIMUM_VALUE_CHARACTERS
);
201 // Make sure Flags can only contain supported bits.
203 ASSERT ((Flags
& ~(LEFT_JUSTIFY
| COMMA_TYPE
| PREFIX_ZERO
| RADIX_HEX
)) == 0);
206 // If both COMMA_TYPE and RADIX_HEX are set, then ASSERT ()
208 ASSERT (((Flags
& COMMA_TYPE
) == 0) || ((Flags
& RADIX_HEX
) == 0));
210 OriginalBuffer
= Buffer
;
213 // Width is 0 or COMMA_TYPE is set, PREFIX_ZERO is ignored.
215 if (Width
== 0 || (Flags
& COMMA_TYPE
) != 0) {
216 Flags
&= (~PREFIX_ZERO
);
219 // If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
222 Width
= MAXIMUM_VALUE_CHARACTERS
- 1;
225 // Set the tag for the end of the input Buffer.
227 EndBuffer
= Buffer
+ Width
* Increment
;
230 // Convert decimal negative
232 if ((Value
< 0) && ((Flags
& RADIX_HEX
) == 0)) {
234 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, '-', Increment
);
239 // Count the length of the value string.
241 Radix
= ((Flags
& RADIX_HEX
) == 0)? 10 : 16;
242 ValueBufferPtr
= BasePrintLibValueToString (ValueBuffer
, Value
, Radix
);
243 Count
= ValueBufferPtr
- ValueBuffer
;
248 if ((Flags
& PREFIX_ZERO
) != 0) {
249 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, Width
- Count
, '0', Increment
);
253 // Print Comma type for every 3 characters
259 for (Index
= 0; Index
< Count
; Index
++) {
260 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, *ValueBufferPtr
--, Increment
);
261 if ((Flags
& COMMA_TYPE
) != 0) {
265 if ((Index
+ 1) < Count
) {
266 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, ',', Increment
);
273 // Print Null-terminator
275 BasePrintLibFillBuffer (Buffer
, EndBuffer
+ Increment
, 1, 0, Increment
);
277 return ((Buffer
- OriginalBuffer
) / Increment
);
281 Worker function that produces a Null-terminated string in an output buffer
282 based on a Null-terminated format string and a VA_LIST argument list.
284 VSPrint function to process format and place the results in Buffer. Since a
285 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
286 this is the main print working routine.
288 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
290 @param[out] Buffer The character buffer to print the results of the
291 parsing of Format into.
292 @param[in] BufferSize The maximum number of characters to put into
294 @param[in] Flags Initial flags value.
295 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
296 and COUNT_ONLY_NO_PRINT set.
297 @param[in] Format A Null-terminated format string.
298 @param[in] VaListMarker VA_LIST style variable argument list consumed by
300 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
301 by processing Format.
303 @return The number of characters printed not including the Null-terminator.
304 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
305 modification to Buffer.
309 BasePrintLibSPrintMarker (
313 IN CONST CHAR8
*Format
,
314 IN VA_LIST VaListMarker
, OPTIONAL
315 IN BASE_LIST BaseListMarker OPTIONAL
318 CHAR8
*OriginalBuffer
;
320 CHAR8 ValueBuffer
[MAXIMUM_VALUE_CHARACTERS
];
321 UINT32 BytesPerOutputCharacter
;
322 UINTN BytesPerFormatCharacter
;
324 UINTN FormatCharacter
;
328 CONST CHAR8
*ArgumentString
;
334 INTN BytesPerArgumentCharacter
;
335 UINTN ArgumentCharacter
;
343 RETURN_STATUS Status
;
347 UINTN LengthToReturn
;
350 // If you change this code be sure to match the 2 versions of this function.
351 // Nearly identical logic is found in the BasePrintLib and
352 // DxePrintLibPrint2Protocol (both PrintLib instances).
355 if ((Flags
& COUNT_ONLY_NO_PRINT
) != 0) {
356 if (BufferSize
== 0) {
361 // We can run without a Buffer for counting only.
363 if (BufferSize
== 0) {
366 ASSERT (Buffer
!= NULL
);
369 if ((Flags
& OUTPUT_UNICODE
) != 0) {
370 BytesPerOutputCharacter
= 2;
372 BytesPerOutputCharacter
= 1;
378 // Reserve space for the Null terminator.
381 OriginalBuffer
= Buffer
;
384 // Set the tag for the end of the input Buffer.
386 EndBuffer
= Buffer
+ BufferSize
* BytesPerOutputCharacter
;
388 if ((Flags
& FORMAT_UNICODE
) != 0) {
390 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
391 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
393 ASSERT (StrSize ((CHAR16
*) Format
) != 0);
394 BytesPerFormatCharacter
= 2;
398 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
399 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
401 ASSERT (AsciiStrSize (Format
) != 0);
402 BytesPerFormatCharacter
= 1;
407 // Get the first character from the format string
409 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
412 // Loop until the end of the format string is reached or the output buffer is full
414 while (FormatCharacter
!= 0 && Buffer
< EndBuffer
) {
416 // Clear all the flag bits except those that may have been passed in
418 Flags
&= (OUTPUT_UNICODE
| FORMAT_UNICODE
| COUNT_ONLY_NO_PRINT
);
421 // Set the default width to zero, and the default precision to 1
431 switch (FormatCharacter
) {
434 // Parse Flags and Width
436 for (Done
= FALSE
; !Done
; ) {
437 Format
+= BytesPerFormatCharacter
;
438 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
439 switch (FormatCharacter
) {
444 Flags
|= LEFT_JUSTIFY
;
447 Flags
|= PREFIX_SIGN
;
450 Flags
|= PREFIX_BLANK
;
460 if ((Flags
& PRECISION
) == 0) {
461 Flags
|= PAD_TO_WIDTH
;
462 if (BaseListMarker
== NULL
) {
463 Width
= VA_ARG (VaListMarker
, UINTN
);
465 Width
= BASE_ARG (BaseListMarker
, UINTN
);
468 if (BaseListMarker
== NULL
) {
469 Precision
= VA_ARG (VaListMarker
, UINTN
);
471 Precision
= BASE_ARG (BaseListMarker
, UINTN
);
476 if ((Flags
& PRECISION
) == 0) {
477 Flags
|= PREFIX_ZERO
;
488 for (Count
= 0; ((FormatCharacter
>= '0') && (FormatCharacter
<= '9')); ){
489 Count
= (Count
* 10) + FormatCharacter
- '0';
490 Format
+= BytesPerFormatCharacter
;
491 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
493 Format
-= BytesPerFormatCharacter
;
494 if ((Flags
& PRECISION
) == 0) {
495 Flags
|= PAD_TO_WIDTH
;
504 // Make no output if Format string terminates unexpectedly when
505 // looking up for flag, width, precision and type.
507 Format
-= BytesPerFormatCharacter
;
510 // break skipped on purpose.
519 // Handle each argument type
521 switch (FormatCharacter
) {
524 // Flag space, +, 0, L & l are invalid for type p.
526 Flags
&= ~(PREFIX_BLANK
| PREFIX_SIGN
| PREFIX_ZERO
| LONG_TYPE
);
527 if (sizeof (VOID
*) > 4) {
531 // break skipped on purpose
534 Flags
|= PREFIX_ZERO
;
536 // break skipped on purpose
541 // break skipped on purpose
544 if ((Flags
& LONG_TYPE
) == 0) {
546 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
547 // This assumption is made so the format string definition is compatible with the ANSI C
548 // Specification for formatted strings. It is recommended that the Base Types be used
549 // everywhere, but in this one case, compliance with ANSI C is more important, and
550 // provides an implementation that is compatible with that largest possible set of CPU
551 // architectures. This is why the type "int" is used in this one case.
553 if (BaseListMarker
== NULL
) {
554 Value
= VA_ARG (VaListMarker
, int);
556 Value
= BASE_ARG (BaseListMarker
, int);
559 if (BaseListMarker
== NULL
) {
560 Value
= VA_ARG (VaListMarker
, INT64
);
562 Value
= BASE_ARG (BaseListMarker
, INT64
);
565 if ((Flags
& PREFIX_BLANK
) != 0) {
568 if ((Flags
& PREFIX_SIGN
) != 0) {
571 if ((Flags
& COMMA_TYPE
) != 0) {
574 if ((Flags
& RADIX_HEX
) == 0) {
577 Flags
&= (~PREFIX_ZERO
);
581 Flags
|= PREFIX_SIGN
;
588 if ((Flags
& LONG_TYPE
) == 0 && Value
< 0) {
590 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".
591 // This assumption is made so the format string definition is compatible with the ANSI C
592 // Specification for formatted strings. It is recommended that the Base Types be used
593 // everywhere, but in this one case, compliance with ANSI C is more important, and
594 // provides an implementation that is compatible with that largest possible set of CPU
595 // architectures. This is why the type "unsigned int" is used in this one case.
597 Value
= (unsigned int)Value
;
601 // Convert Value to a reversed string
603 Count
= BasePrintLibValueToString (ValueBuffer
, Value
, Radix
) - ValueBuffer
;
604 if (Value
== 0 && Precision
== 0) {
607 ArgumentString
= (CHAR8
*)ValueBuffer
+ Count
;
613 if (Comma
&& Count
!= 0) {
614 Count
+= ((Count
- 1) / 3);
620 Flags
|= ARGUMENT_REVERSED
;
622 if ((Flags
& PREFIX_ZERO
) != 0) {
623 if ((Flags
& LEFT_JUSTIFY
) == 0) {
624 if ((Flags
& PAD_TO_WIDTH
) != 0) {
625 if ((Flags
& PRECISION
) == 0) {
635 Flags
|= ARGUMENT_UNICODE
;
637 // break skipped on purpose
640 if (BaseListMarker
== NULL
) {
641 ArgumentString
= VA_ARG (VaListMarker
, CHAR8
*);
643 ArgumentString
= BASE_ARG (BaseListMarker
, CHAR8
*);
645 if (ArgumentString
== NULL
) {
646 Flags
&= (~ARGUMENT_UNICODE
);
647 ArgumentString
= "<null string>";
650 // Set the default precision for string to be zero if not specified.
652 if ((Flags
& PRECISION
) == 0) {
658 if (BaseListMarker
== NULL
) {
659 Character
= VA_ARG (VaListMarker
, UINTN
) & 0xffff;
661 Character
= BASE_ARG (BaseListMarker
, UINTN
) & 0xffff;
663 ArgumentString
= (CHAR8
*)&Character
;
664 Flags
|= ARGUMENT_UNICODE
;
668 if (BaseListMarker
== NULL
) {
669 TmpGuid
= VA_ARG (VaListMarker
, GUID
*);
671 TmpGuid
= BASE_ARG (BaseListMarker
, GUID
*);
673 if (TmpGuid
== NULL
) {
674 ArgumentString
= "<null guid>";
676 GuidData1
= ReadUnaligned32 (&(TmpGuid
->Data1
));
677 GuidData2
= ReadUnaligned16 (&(TmpGuid
->Data2
));
678 GuidData3
= ReadUnaligned16 (&(TmpGuid
->Data3
));
681 MAXIMUM_VALUE_CHARACTERS
,
683 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
696 ArgumentString
= ValueBuffer
;
701 if (BaseListMarker
== NULL
) {
702 TmpTime
= VA_ARG (VaListMarker
, TIME
*);
704 TmpTime
= BASE_ARG (BaseListMarker
, TIME
*);
706 if (TmpTime
== NULL
) {
707 ArgumentString
= "<null time>";
711 MAXIMUM_VALUE_CHARACTERS
,
713 "%02d/%02d/%04d %02d:%02d",
720 ArgumentString
= ValueBuffer
;
725 if (BaseListMarker
== NULL
) {
726 Status
= VA_ARG (VaListMarker
, RETURN_STATUS
);
728 Status
= BASE_ARG (BaseListMarker
, RETURN_STATUS
);
730 ArgumentString
= ValueBuffer
;
731 if (RETURN_ERROR (Status
)) {
735 Index
= Status
& ~MAX_BIT
;
736 if (Index
> 0 && Index
<= ERROR_STATUS_NUMBER
) {
737 ArgumentString
= mStatusString
[Index
+ WARNING_STATUS_NUMBER
];
741 if (Index
<= WARNING_STATUS_NUMBER
) {
742 ArgumentString
= mStatusString
[Index
];
745 if (ArgumentString
== ValueBuffer
) {
746 BasePrintLibSPrint ((CHAR8
*) ValueBuffer
, MAXIMUM_VALUE_CHARACTERS
, 0, "%08X", Status
);
751 Format
+= BytesPerFormatCharacter
;
752 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
753 if (FormatCharacter
== '\n') {
755 // Translate '\r\n' to '\r\n'
757 ArgumentString
= "\r\n";
760 // Translate '\r' to '\r'
762 ArgumentString
= "\r";
763 Format
-= BytesPerFormatCharacter
;
769 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
771 ArgumentString
= "\r\n";
772 Format
+= BytesPerFormatCharacter
;
773 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
774 if (FormatCharacter
!= '\r') {
775 Format
-= BytesPerFormatCharacter
;
782 // if the type is '%' or unknown, then print it to the screen
784 ArgumentString
= (CHAR8
*)&FormatCharacter
;
785 Flags
|= ARGUMENT_UNICODE
;
791 Format
+= BytesPerFormatCharacter
;
792 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
793 if (FormatCharacter
== '\n') {
795 // Translate '\r\n' to '\r\n'
797 ArgumentString
= "\r\n";
800 // Translate '\r' to '\r'
802 ArgumentString
= "\r";
803 Format
-= BytesPerFormatCharacter
;
809 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'
811 ArgumentString
= "\r\n";
812 Format
+= BytesPerFormatCharacter
;
813 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
814 if (FormatCharacter
!= '\r') {
815 Format
-= BytesPerFormatCharacter
;
820 ArgumentString
= (CHAR8
*)&FormatCharacter
;
821 Flags
|= ARGUMENT_UNICODE
;
826 // Retrieve the ArgumentString attriubutes
828 if ((Flags
& ARGUMENT_UNICODE
) != 0) {
829 ArgumentMask
= 0xffff;
830 BytesPerArgumentCharacter
= 2;
833 BytesPerArgumentCharacter
= 1;
835 if ((Flags
& ARGUMENT_REVERSED
) != 0) {
836 BytesPerArgumentCharacter
= -BytesPerArgumentCharacter
;
839 // Compute the number of characters in ArgumentString and store it in Count
840 // ArgumentString is either null-terminated, or it contains Precision characters
842 for (Count
= 0; Count
< Precision
|| ((Flags
& PRECISION
) == 0); Count
++) {
843 ArgumentCharacter
= ((ArgumentString
[Count
* BytesPerArgumentCharacter
] & 0xff) | ((ArgumentString
[Count
* BytesPerArgumentCharacter
+ 1]) << 8)) & ArgumentMask
;
844 if (ArgumentCharacter
== 0) {
850 if (Precision
< Count
) {
855 // Pad before the string
857 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
)) {
858 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
859 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
860 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, Width
- Precision
, ' ', BytesPerOutputCharacter
);
866 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
867 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
868 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, Prefix
, BytesPerOutputCharacter
);
871 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
872 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
873 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, Precision
- Count
, '0', BytesPerOutputCharacter
);
876 LengthToReturn
+= ((Precision
- Count
) * BytesPerOutputCharacter
);
877 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
878 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, Precision
- Count
, ' ', BytesPerOutputCharacter
);
881 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
882 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
883 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, Prefix
, BytesPerOutputCharacter
);
889 // Output the Prefix character if it is present
897 // Copy the string into the output buffer performing the required type conversions
899 while (Index
< Count
) {
900 ArgumentCharacter
= ((*ArgumentString
& 0xff) | (*(ArgumentString
+ 1) << 8)) & ArgumentMask
;
902 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
903 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
904 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, ArgumentCharacter
, BytesPerOutputCharacter
);
906 ArgumentString
+= BytesPerArgumentCharacter
;
914 LengthToReturn
+= (1 * BytesPerOutputCharacter
);
915 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
916 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, 1, ',', BytesPerOutputCharacter
);
924 // Pad after the string
926 if ((Flags
& (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) == (PAD_TO_WIDTH
| LEFT_JUSTIFY
)) {
927 LengthToReturn
+= ((Width
- Precision
) * BytesPerOutputCharacter
);
928 if ((Flags
& COUNT_ONLY_NO_PRINT
) == 0 && Buffer
!= NULL
) {
929 Buffer
= BasePrintLibFillBuffer (Buffer
, EndBuffer
, Width
- Precision
, ' ', BytesPerOutputCharacter
);
934 // Get the next character from the format string
936 Format
+= BytesPerFormatCharacter
;
939 // Get the next character from the format string
941 FormatCharacter
= ((*Format
& 0xff) | (*(Format
+ 1) << 8)) & FormatMask
;
944 if ((Flags
& COUNT_ONLY_NO_PRINT
) != 0) {
945 return (LengthToReturn
/ BytesPerOutputCharacter
);
948 ASSERT (Buffer
!= NULL
);
950 // Null terminate the Unicode or ASCII string
952 BasePrintLibFillBuffer (Buffer
, EndBuffer
+ BytesPerOutputCharacter
, 1, 0, BytesPerOutputCharacter
);
954 // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
955 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
957 ASSERT ((((Flags
& OUTPUT_UNICODE
) == 0)) || (StrSize ((CHAR16
*) OriginalBuffer
) != 0));
959 // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength
960 // ASCII characters if PcdMaximumAsciiStringLength is not zero.
962 ASSERT ((((Flags
& OUTPUT_UNICODE
) != 0)) || (AsciiStrSize (OriginalBuffer
) != 0));
964 return ((Buffer
- OriginalBuffer
) / BytesPerOutputCharacter
);
968 Worker function that produces a Null-terminated string in an output buffer
969 based on a Null-terminated format string and variable argument list.
971 VSPrint function to process format and place the results in Buffer. Since a
972 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
973 this is the main print working routine
975 @param StartOfBuffer The character buffer to print the results of the parsing
977 @param BufferSize The maximum number of characters to put into buffer.
979 @param Flags Initial flags value.
980 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
981 @param FormatString A Null-terminated format string.
982 @param ... The variable argument list.
984 @return The number of characters printed.
990 OUT CHAR8
*StartOfBuffer
,
993 IN CONST CHAR8
*FormatString
,
998 UINTN NumberOfPrinted
;
1000 VA_START (Marker
, FormatString
);
1001 NumberOfPrinted
= BasePrintLibSPrintMarker (StartOfBuffer
, BufferSize
, Flags
, FormatString
, Marker
, NULL
);
1003 return NumberOfPrinted
;