]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BasePrintLib/PrintLib.c
33da6cb6b07795e7f56ec7a56d0a868b2c495c61
[mirror_edk2.git] / MdePkg / Library / BasePrintLib / PrintLib.c
1 /** @file
2 Print Library.
3
4 Copyright (c) 2006, 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
9
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.
12
13 Module Name: PrintLib.c
14
15 **/
16
17 #include "PrintLibInternal.h"
18
19 #define WARNING_STATUS_NUMBER 4
20 #define ERROR_STATUS_NUMBER 24
21
22 STATIC CONST CHAR8 *StatusString [] = {
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 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT
29 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT
30 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT
31 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT
32 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT
33 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT
34 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT
35 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT
36 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT
37 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT
38 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT
39 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT
40 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT
41 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT
42 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT
43 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT
44 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT
45 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT
46 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT
47 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT
48 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT
49 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT
50 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT
51 "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT
52 };
53
54 /**
55 Worker function that produces a Null-terminated string in an output buffer
56 based on a Null-terminated format string and a VA_LIST argument list.
57
58 VSPrint function to process format and place the results in Buffer. Since a
59 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
60 this is the main print working routine.
61
62 @param Buffer Character buffer to print the results of the parsing
63 of Format into.
64 @param BufferSize Maximum number of characters to put into buffer.
65 @param Flags Intial flags value.
66 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set.
67 @param Format Null-terminated format string.
68 @param Marker Vararg list consumed by processing Format.
69
70 @return Number of characters printed not including the Null-terminator.
71
72 **/
73 UINTN
74 BasePrintLibVSPrint (
75 OUT CHAR8 *Buffer,
76 IN UINTN BufferSize,
77 IN UINTN Flags,
78 IN CONST CHAR8 *Format,
79 IN VA_LIST Marker
80 )
81 {
82 CHAR8 *OriginalBuffer;
83 CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];
84 UINTN BytesPerOutputCharacter;
85 UINTN BytesPerFormatCharacter;
86 UINTN FormatMask;
87 UINTN FormatCharacter;
88 UINTN Width;
89 UINTN Precision;
90 INT64 Value;
91 CONST CHAR8 *ArgumentString;
92 UINTN Character;
93 GUID *TmpGuid;
94 TIME *TmpTime;
95 UINTN Count;
96 UINTN ArgumentMask;
97 INTN BytesPerArgumentCharacter;
98 UINTN ArgumentCharacter;
99 BOOLEAN Done;
100 UINTN Index;
101 CHAR8 Prefix;
102 BOOLEAN ZeroPad;
103 BOOLEAN Comma;
104 UINTN Digits;
105 UINTN Radix;
106 RETURN_STATUS Status;
107
108 if (BufferSize == 0) {
109 return 0;
110 }
111 ASSERT (Buffer != NULL);
112
113 OriginalBuffer = Buffer;
114
115 if ((Flags & OUTPUT_UNICODE) != 0) {
116 BytesPerOutputCharacter = 2;
117 } else {
118 BytesPerOutputCharacter = 1;
119 }
120 if ((Flags & FORMAT_UNICODE) != 0) {
121 //
122 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength
123 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
124 //
125 ASSERT (StrSize ((CHAR16 *) Format) != 0);
126 BytesPerFormatCharacter = 2;
127 FormatMask = 0xffff;
128 } else {
129 //
130 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength
131 // Ascii characters if PcdMaximumAsciiStringLength is not zero.
132 //
133 ASSERT (AsciiStrSize (Format) != 0);
134 BytesPerFormatCharacter = 1;
135 FormatMask = 0xff;
136 }
137
138 //
139 // Reserve space for the Null terminator.
140 //
141 BufferSize--;
142
143 //
144 // Get the first character from the format string
145 //
146 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
147
148 //
149 // Loop until the end of the format string is reached or the output buffer is full
150 //
151 while (FormatCharacter != 0 && BufferSize > 0) {
152 //
153 // Clear all the flag bits except those that may have been passed in
154 //
155 Flags &= (OUTPUT_UNICODE | FORMAT_UNICODE);
156
157 //
158 // Set the default width to zero, and the default precision to 1
159 //
160 Width = 0;
161 Precision = 1;
162 Prefix = 0;
163 Comma = FALSE;
164 ZeroPad = FALSE;
165 Count = 0;
166 Digits = 0;
167
168 switch (FormatCharacter) {
169 case '%':
170 //
171 // Parse Flags and Width
172 //
173 for (Done = FALSE; !Done; ) {
174 Format += BytesPerFormatCharacter;
175 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
176 switch (FormatCharacter) {
177 case '.':
178 Flags |= PRECISION;
179 break;
180 case '-':
181 Flags |= LEFT_JUSTIFY;
182 break;
183 case '+':
184 Flags |= PREFIX_SIGN;
185 break;
186 case ' ':
187 Flags |= PREFIX_BLANK;
188 break;
189 case ',':
190 Flags |= COMMA_TYPE;
191 break;
192 case 'L':
193 case 'l':
194 Flags |= LONG_TYPE;
195 break;
196 case '*':
197 if ((Flags & PRECISION) == 0) {
198 Flags |= PAD_TO_WIDTH;
199 Width = VA_ARG (Marker, UINTN);
200 } else {
201 Precision = VA_ARG (Marker, UINTN);
202 }
203 break;
204 case '0':
205 if ((Flags & PRECISION) == 0) {
206 Flags |= PREFIX_ZERO;
207 }
208 case '1':
209 case '2':
210 case '3':
211 case '4':
212 case '5':
213 case '6':
214 case '7':
215 case '8':
216 case '9':
217 for (Count = 0; ((FormatCharacter >= '0') && (FormatCharacter <= '9')); ){
218 Count = (Count * 10) + FormatCharacter - '0';
219 Format += BytesPerFormatCharacter;
220 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
221 }
222 Format -= BytesPerFormatCharacter;
223 if ((Flags & PRECISION) == 0) {
224 Flags |= PAD_TO_WIDTH;
225 Width = Count;
226 } else {
227 Precision = Count;
228 }
229 break;
230
231 case '\0':
232 //
233 // Make no output if Format string terminates unexpectedly when
234 // looking up for flag, width, precision and type.
235 //
236 Format -= BytesPerFormatCharacter;
237 Precision = 0;
238 //
239 // break skipped on purpose.
240 //
241 default:
242 Done = TRUE;
243 break;
244 }
245 }
246
247 //
248 // Limit the maximum field width to the remaining characters in the output buffer
249 //
250 if (Width > BufferSize) {
251 Width = BufferSize;
252 }
253
254 //
255 // Handle each argument type
256 //
257 switch (FormatCharacter) {
258 case 'p':
259 //
260 // Flag space, +, 0, L & l are invalid for type p.
261 //
262 Flags &= ~(PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE);
263 if (sizeof (VOID *) > 4) {
264 Flags |= LONG_TYPE;
265 }
266 case 'X':
267 Flags |= PREFIX_ZERO;
268 //
269 // break skipped on purpose
270 //
271 case 'x':
272 Flags |= RADIX_HEX;
273 //
274 // break skipped on purpose
275 //
276 case 'd':
277 if ((Flags & LONG_TYPE) == 0) {
278 Value = (VA_ARG (Marker, int));
279 } else {
280 Value = VA_ARG (Marker, INT64);
281 }
282 if ((Flags & PREFIX_BLANK) != 0) {
283 Prefix = ' ';
284 }
285 if ((Flags & PREFIX_SIGN) != 0) {
286 Prefix = '+';
287 }
288 if ((Flags & COMMA_TYPE) != 0) {
289 Comma = TRUE;
290 }
291 if ((Flags & RADIX_HEX) == 0) {
292 Radix = 10;
293 if (Comma) {
294 Flags &= (~PREFIX_ZERO);
295 Precision = 1;
296 }
297 if (Value < 0) {
298 Flags |= PREFIX_SIGN;
299 Prefix = '-';
300 Value = -Value;
301 }
302 } else {
303 Radix = 16;
304 Comma = FALSE;
305 if ((Flags & LONG_TYPE) == 0 && Value < 0) {
306 Value = (unsigned int)Value;
307 }
308 }
309 //
310 // Convert Value to a reversed string
311 //
312 Count = BasePrintLibValueToString (ValueBuffer, Value, Radix);
313 if (Value == 0 && Precision == 0) {
314 Count = 0;
315 }
316 ArgumentString = (CHAR8 *)ValueBuffer + Count;
317
318 Digits = Count % 3;
319 if (Digits != 0) {
320 Digits = 3 - Digits;
321 }
322 if (Comma && Count != 0) {
323 Count += ((Count - 1) / 3);
324 }
325 if (Prefix != 0) {
326 Count++;
327 Precision++;
328 }
329 Flags |= ARGUMENT_REVERSED;
330 ZeroPad = TRUE;
331 if ((Flags & PREFIX_ZERO) != 0) {
332 if ((Flags & LEFT_JUSTIFY) == 0) {
333 if ((Flags & PAD_TO_WIDTH) != 0) {
334 if ((Flags & PRECISION) == 0) {
335 Precision = Width;
336 }
337 }
338 }
339 }
340 break;
341
342 case 's':
343 case 'S':
344 Flags |= ARGUMENT_UNICODE;
345 //
346 // break skipped on purpose
347 //
348 case 'a':
349 ArgumentString = (CHAR8 *)VA_ARG (Marker, CHAR8 *);
350 if (ArgumentString == NULL) {
351 Flags &= (~ARGUMENT_UNICODE);
352 ArgumentString = "<null string>";
353 }
354 break;
355
356 case 'c':
357 Character = VA_ARG (Marker, UINTN) & 0xffff;
358 ArgumentString = (CHAR8 *)&Character;
359 Flags |= ARGUMENT_UNICODE;
360 break;
361
362 case 'g':
363 TmpGuid = VA_ARG (Marker, GUID *);
364 if (TmpGuid == NULL) {
365 ArgumentString = "<null guid>";
366 } else {
367 BasePrintLibSPrint (
368 ValueBuffer,
369 MAXIMUM_VALUE_CHARACTERS,
370 0,
371 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
372 TmpGuid->Data1,
373 TmpGuid->Data2,
374 TmpGuid->Data3,
375 TmpGuid->Data4[0],
376 TmpGuid->Data4[1],
377 TmpGuid->Data4[2],
378 TmpGuid->Data4[3],
379 TmpGuid->Data4[4],
380 TmpGuid->Data4[5],
381 TmpGuid->Data4[6],
382 TmpGuid->Data4[7]
383 );
384 ArgumentString = ValueBuffer;
385 }
386 break;
387
388 case 't':
389 TmpTime = VA_ARG (Marker, TIME *);
390 if (TmpTime == NULL) {
391 ArgumentString = "<null time>";
392 } else {
393 BasePrintLibSPrint (
394 ValueBuffer,
395 MAXIMUM_VALUE_CHARACTERS,
396 0,
397 "%02d/%02d/%04d %02d:%02d",
398 TmpTime->Month,
399 TmpTime->Day,
400 TmpTime->Year,
401 TmpTime->Hour,
402 TmpTime->Minute
403 );
404 ArgumentString = ValueBuffer;
405 }
406 break;
407
408 case 'r':
409 Status = VA_ARG (Marker, RETURN_STATUS);
410 ArgumentString = ValueBuffer;
411 if (RETURN_ERROR (Status)) {
412 //
413 // Clear error bit
414 //
415 Index = Status & ~MAX_BIT;
416 if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {
417 ArgumentString = StatusString [Index + WARNING_STATUS_NUMBER];
418 }
419 } else {
420 Index = Status;
421 if (Index <= WARNING_STATUS_NUMBER) {
422 ArgumentString = StatusString [Index];
423 }
424 }
425 if (ArgumentString == ValueBuffer) {
426 BasePrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);
427 }
428 break;
429
430 case '\n':
431 ArgumentString = "\n\r";
432 break;
433
434 case '%':
435 default:
436 //
437 // if the type is '%' or unknown, then print it to the screen
438 //
439 ArgumentString = (CHAR8 *)&FormatCharacter;
440 Flags |= ARGUMENT_UNICODE;
441 break;
442 }
443 break;
444
445 case '\n':
446 ArgumentString = "\n\r";
447 break;
448
449 default:
450 ArgumentString = (CHAR8 *)&FormatCharacter;
451 Flags |= ARGUMENT_UNICODE;
452 break;
453 }
454
455 //
456 // Retrieve the ArgumentString attriubutes
457 //
458 if ((Flags & ARGUMENT_UNICODE) != 0) {
459 ArgumentMask = 0xffff;
460 BytesPerArgumentCharacter = 2;
461 } else {
462 ArgumentMask = 0xff;
463 BytesPerArgumentCharacter = 1;
464 }
465 if ((Flags & ARGUMENT_REVERSED) != 0) {
466 BytesPerArgumentCharacter = -BytesPerArgumentCharacter;
467 } else {
468 //
469 // Compute the number of characters in ArgumentString and store it in Count
470 // ArgumentString is either null-terminated, or it contains Precision characters
471 //
472 for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {
473 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
474 if (ArgumentCharacter == 0) {
475 break;
476 }
477 }
478 }
479
480 //
481 // Limit the length of the string to append to the remaining characters in the output buffer
482 //
483 if (Count > BufferSize) {
484 Count = BufferSize;
485 }
486 if (Precision < Count) {
487 Precision = Count;
488 }
489
490 //
491 // Pad before the string
492 //
493 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {
494 Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);
495 }
496
497 if (ZeroPad) {
498 if (Prefix != 0) {
499 Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);
500 }
501 Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, '0', BytesPerOutputCharacter);
502 } else {
503 Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, ' ', BytesPerOutputCharacter);
504 if (Prefix != 0) {
505 Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);
506 }
507 }
508
509 //
510 // Output the Prefix character if it is present
511 //
512 Index = 0;
513 if (Prefix != 0) {
514 Index++;
515 }
516
517 //
518 // Copy the string into the output buffer performing the required type conversions
519 //
520 while (Index < Count) {
521 ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;
522
523 Buffer = BasePrintLibFillBuffer (Buffer, 1, ArgumentCharacter, BytesPerOutputCharacter);
524 ArgumentString += BytesPerArgumentCharacter;
525 Index++;
526 if (Comma) {
527 Digits++;
528 if (Digits == 3) {
529 Digits = 0;
530 Index++;
531 if (Index < Count) {
532 Buffer = BasePrintLibFillBuffer (Buffer, 1, ',', BytesPerOutputCharacter);
533 }
534 }
535 }
536 }
537
538 //
539 // Pad after the string
540 //
541 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {
542 Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);
543 }
544
545 //
546 // Reduce the number of characters
547 //
548 BufferSize -= Count;
549
550 //
551 // Get the next character from the format string
552 //
553 Format += BytesPerFormatCharacter;
554
555 //
556 // Get the next character from the format string
557 //
558 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
559 }
560
561 //
562 // Null terminate the Unicode or ASCII string
563 //
564 BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter);
565 //
566 // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
567 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
568 //
569 ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));
570 //
571 // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength
572 // ASCII characters if PcdMaximumAsciiStringLength is not zero.
573 //
574 ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));
575
576 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);
577 }
578
579 /**
580 Worker function that produces a Null-terminated string in an output buffer
581 based on a Null-terminated format string and variable argument list.
582
583 VSPrint function to process format and place the results in Buffer. Since a
584 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus
585 this is the main print working routine.
586
587 @param Buffer Character buffer to print the results of the parsing
588 of Format into.
589 @param BufferSize Maximum number of characters to put into buffer.
590 Zero means no limit.
591 @param Flags Intial flags value.
592 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
593 @param FormatString Null-terminated format string.
594
595 @return Number of characters printed not including the Null-terminator.
596
597 **/
598 UINTN
599 BasePrintLibSPrint (
600 OUT CHAR8 *StartOfBuffer,
601 IN UINTN BufferSize,
602 IN UINTN Flags,
603 IN CONST CHAR8 *FormatString,
604 ...
605 )
606 {
607 VA_LIST Marker;
608
609 VA_START (Marker, FormatString);
610 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, Flags, FormatString, Marker);
611 }
612
613 /**
614 Produces a Null-terminated Unicode string in an output buffer based on
615 a Null-terminated Unicode format string and a VA_LIST argument list
616
617 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
618 and BufferSize.
619 The Unicode string is produced by parsing the format string specified by FormatString.
620 Arguments are pulled from the variable argument list specified by Marker based on the
621 contents of the format string.
622 The number of Unicode characters in the produced output buffer is returned not including
623 the Null-terminator.
624 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
625
626 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
627 If BufferSize > 1 and FormatString is NULL, then ASSERT().
628 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
629 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
630 ASSERT().
631 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
632 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
633 Null-terminator, then ASSERT().
634
635 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
636 Unicode string.
637 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
638 @param FormatString Null-terminated Unicode format string.
639 @param Marker VA_LIST marker for the variable argument list.
640
641 @return The number of Unicode characters in the produced output buffer not including the
642 Null-terminator.
643
644 **/
645 UINTN
646 EFIAPI
647 UnicodeVSPrint (
648 OUT CHAR16 *StartOfBuffer,
649 IN UINTN BufferSize,
650 IN CONST CHAR16 *FormatString,
651 IN VA_LIST Marker
652 )
653 {
654 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, FORMAT_UNICODE | OUTPUT_UNICODE, (CHAR8 *)FormatString, Marker);
655 }
656
657 /**
658 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
659 Unicode format string and variable argument list.
660
661 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
662 and BufferSize.
663 The Unicode string is produced by parsing the format string specified by FormatString.
664 Arguments are pulled from the variable argument list based on the contents of the format string.
665 The number of Unicode characters in the produced output buffer is returned not including
666 the Null-terminator.
667 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
668
669 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
670 If BufferSize > 1 and FormatString is NULL, then ASSERT().
671 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
672 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
673 ASSERT().
674 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
675 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
676 Null-terminator, then ASSERT().
677
678 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
679 Unicode string.
680 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
681 @param FormatString Null-terminated Unicode format string.
682
683 @return The number of Unicode characters in the produced output buffer not including the
684 Null-terminator.
685
686 **/
687 UINTN
688 EFIAPI
689 UnicodeSPrint (
690 OUT CHAR16 *StartOfBuffer,
691 IN UINTN BufferSize,
692 IN CONST CHAR16 *FormatString,
693 ...
694 )
695 {
696 VA_LIST Marker;
697
698 VA_START (Marker, FormatString);
699 return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
700 }
701
702 /**
703 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
704 ASCII format string and a VA_LIST argument list
705
706 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
707 and BufferSize.
708 The Unicode string is produced by parsing the format string specified by FormatString.
709 Arguments are pulled from the variable argument list specified by Marker based on the
710 contents of the format string.
711 The number of Unicode characters in the produced output buffer is returned not including
712 the Null-terminator.
713 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
714
715 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
716 If BufferSize > 1 and FormatString is NULL, then ASSERT().
717 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
718 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
719 ASSERT().
720 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
721 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
722 Null-terminator, then ASSERT().
723
724 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
725 Unicode string.
726 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
727 @param FormatString Null-terminated Unicode format string.
728 @param Marker VA_LIST marker for the variable argument list.
729
730 @return The number of Unicode characters in the produced output buffer not including the
731 Null-terminator.
732
733 **/
734 UINTN
735 EFIAPI
736 UnicodeVSPrintAsciiFormat (
737 OUT CHAR16 *StartOfBuffer,
738 IN UINTN BufferSize,
739 IN CONST CHAR8 *FormatString,
740 IN VA_LIST Marker
741 )
742 {
743 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, OUTPUT_UNICODE,FormatString, Marker);
744 }
745
746 /**
747 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
748 ASCII format string and variable argument list.
749
750 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
751 and BufferSize.
752 The Unicode string is produced by parsing the format string specified by FormatString.
753 Arguments are pulled from the variable argument list based on the contents of the
754 format string.
755 The number of Unicode characters in the produced output buffer is returned not including
756 the Null-terminator.
757 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
758
759 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
760 If BufferSize > 1 and FormatString is NULL, then ASSERT().
761 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
762 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
763 ASSERT().
764 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
765 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
766 Null-terminator, then ASSERT().
767
768 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
769 Unicode string.
770 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
771 @param FormatString Null-terminated Unicode format string.
772
773 @return The number of Unicode characters in the produced output buffer not including the
774 Null-terminator.
775
776 **/
777 UINTN
778 EFIAPI
779 UnicodeSPrintAsciiFormat (
780 OUT CHAR16 *StartOfBuffer,
781 IN UINTN BufferSize,
782 IN CONST CHAR8 *FormatString,
783 ...
784 )
785 {
786 VA_LIST Marker;
787
788 VA_START (Marker, FormatString);
789 return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
790 }
791
792 /**
793 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
794 ASCII format string and a VA_LIST argument list.
795
796 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
797 and BufferSize.
798 The ASCII string is produced by parsing the format string specified by FormatString.
799 Arguments are pulled from the variable argument list specified by Marker based on
800 the contents of the format string.
801 The number of ASCII characters in the produced output buffer is returned not including
802 the Null-terminator.
803 If BufferSize is 0, then no output buffer is produced and 0 is returned.
804
805 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
806 If BufferSize > 0 and FormatString is NULL, then ASSERT().
807 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
808 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
809 ASSERT().
810 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
811 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
812 Null-terminator, then ASSERT().
813
814 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
815 ASCII string.
816 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
817 @param FormatString Null-terminated Unicode format string.
818 @param Marker VA_LIST marker for the variable argument list.
819
820 @return The number of ASCII characters in the produced output buffer not including the
821 Null-terminator.
822
823 **/
824 UINTN
825 EFIAPI
826 AsciiVSPrint (
827 OUT CHAR8 *StartOfBuffer,
828 IN UINTN BufferSize,
829 IN CONST CHAR8 *FormatString,
830 IN VA_LIST Marker
831 )
832 {
833 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, 0, FormatString, Marker);
834 }
835
836 /**
837 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
838 ASCII format string and variable argument list.
839
840 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
841 and BufferSize.
842 The ASCII string is produced by parsing the format string specified by FormatString.
843 Arguments are pulled from the variable argument list based on the contents of the
844 format string.
845 The number of ASCII characters in the produced output buffer is returned not including
846 the Null-terminator.
847 If BufferSize is 0, then no output buffer is produced and 0 is returned.
848
849 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
850 If BufferSize > 0 and FormatString is NULL, then ASSERT().
851 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
852 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
853 ASSERT().
854 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
855 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
856 Null-terminator, then ASSERT().
857
858 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
859 ASCII string.
860 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
861 @param FormatString Null-terminated Unicode format string.
862
863 @return The number of ASCII characters in the produced output buffer not including the
864 Null-terminator.
865
866 **/
867 UINTN
868 EFIAPI
869 AsciiSPrint (
870 OUT CHAR8 *StartOfBuffer,
871 IN UINTN BufferSize,
872 IN CONST CHAR8 *FormatString,
873 ...
874 )
875 {
876 VA_LIST Marker;
877
878 VA_START (Marker, FormatString);
879 return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
880 }
881
882 /**
883 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
884 ASCII format string and a VA_LIST argument list.
885
886 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
887 and BufferSize.
888 The ASCII string is produced by parsing the format string specified by FormatString.
889 Arguments are pulled from the variable argument list specified by Marker based on
890 the contents of the format string.
891 The number of ASCII characters in the produced output buffer is returned not including
892 the Null-terminator.
893 If BufferSize is 0, then no output buffer is produced and 0 is returned.
894
895 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
896 If BufferSize > 0 and FormatString is NULL, then ASSERT().
897 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
898 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
899 ASSERT().
900 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
901 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
902 Null-terminator, then ASSERT().
903
904 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
905 ASCII string.
906 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
907 @param FormatString Null-terminated Unicode format string.
908 @param Marker VA_LIST marker for the variable argument list.
909
910 @return The number of ASCII characters in the produced output buffer not including the
911 Null-terminator.
912
913 **/
914 UINTN
915 EFIAPI
916 AsciiVSPrintUnicodeFormat (
917 OUT CHAR8 *StartOfBuffer,
918 IN UINTN BufferSize,
919 IN CONST CHAR16 *FormatString,
920 IN VA_LIST Marker
921 )
922 {
923 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, FORMAT_UNICODE, (CHAR8 *)FormatString, Marker);
924 }
925
926 /**
927 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
928 ASCII format string and variable argument list.
929
930 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
931 and BufferSize.
932 The ASCII string is produced by parsing the format string specified by FormatString.
933 Arguments are pulled from the variable argument list based on the contents of the
934 format string.
935 The number of ASCII characters in the produced output buffer is returned not including
936 the Null-terminator.
937 If BufferSize is 0, then no output buffer is produced and 0 is returned.
938
939 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
940 If BufferSize > 0 and FormatString is NULL, then ASSERT().
941 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
942 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
943 ASSERT().
944 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
945 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
946 Null-terminator, then ASSERT().
947
948 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
949 ASCII string.
950 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
951 @param FormatString Null-terminated Unicode format string.
952
953 @return The number of ASCII characters in the produced output buffer not including the
954 Null-terminator.
955
956 **/
957 UINTN
958 EFIAPI
959 AsciiSPrintUnicodeFormat (
960 OUT CHAR8 *StartOfBuffer,
961 IN UINTN BufferSize,
962 IN CONST CHAR16 *FormatString,
963 ...
964 )
965 {
966 VA_LIST Marker;
967
968 VA_START (Marker, FormatString);
969 return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
970 }
971
972 /**
973 Converts a decimal value to a Null-terminated Unicode string.
974
975 Converts the decimal number specified by Value to a Null-terminated Unicode
976 string specified by Buffer containing at most Width characters.
977 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
978 The number of Unicode characters in Buffer is returned not including the Null-terminator.
979 If the conversion contains more than Width characters, then only the first
980 Width characters are returned, and the total number of characters
981 required to perform the conversion is returned.
982 Additional conversion parameters are specified in Flags.
983 The Flags bit LEFT_JUSTIFY is always ignored.
984 All conversions are left justified in Buffer.
985 If Width is 0, PREFIX_ZERO is ignored in Flags.
986 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
987 are inserted every 3rd digit starting from the right.
988 If Value is < 0, then the fist character in Buffer is a '-'.
989 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
990 then Buffer is padded with '0' characters so the combination of the optional '-'
991 sign character, '0' characters, digit characters for Value, and the Null-terminator
992 add up to Width characters.
993
994 If Buffer is NULL, then ASSERT().
995 If unsupported bits are set in Flags, then ASSERT().
996 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
997
998 @param Buffer Pointer to the output buffer for the produced Null-terminated
999 Unicode string.
1000 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
1001 @param Value The 64-bit signed value to convert to a string.
1002 @param Width The maximum number of Unicode characters to place in Buffer.
1003
1004 @return The number of Unicode characters in Buffer not including the Null-terminator.
1005
1006 **/
1007 UINTN
1008 EFIAPI
1009 UnicodeValueToString (
1010 IN OUT CHAR16 *Buffer,
1011 IN UINTN Flags,
1012 IN INT64 Value,
1013 IN UINTN Width
1014 )
1015 {
1016 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);
1017 }
1018
1019 /**
1020 Converts a decimal value to a Null-terminated ASCII string.
1021
1022 Converts the decimal number specified by Value to a Null-terminated ASCII string
1023 specified by Buffer containing at most Width characters.
1024 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
1025 The number of ASCII characters in Buffer is returned not including the Null-terminator.
1026 If the conversion contains more than Width characters, then only the first Width
1027 characters are returned, and the total number of characters required to perform
1028 the conversion is returned.
1029 Additional conversion parameters are specified in Flags.
1030 The Flags bit LEFT_JUSTIFY is always ignored.
1031 All conversions are left justified in Buffer.
1032 If Width is 0, PREFIX_ZERO is ignored in Flags.
1033 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
1034 are inserted every 3rd digit starting from the right.
1035 If Value is < 0, then the fist character in Buffer is a '-'.
1036 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then Buffer
1037 is padded with '0' characters so the combination of the optional '-'
1038 sign character, '0' characters, digit characters for Value, and the
1039 Null-terminator add up to Width characters.
1040
1041 If Buffer is NULL, then ASSERT().
1042 If unsupported bits are set in Flags, then ASSERT().
1043 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
1044
1045 @param Buffer Pointer to the output buffer for the produced Null-terminated
1046 ASCII string.
1047 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
1048 @param Value The 64-bit signed value to convert to a string.
1049 @param Width The maximum number of ASCII characters to place in Buffer.
1050
1051 @return The number of ASCII characters in Buffer not including the Null-terminator.
1052
1053 **/
1054 UINTN
1055 EFIAPI
1056 AsciiValueToString (
1057 IN OUT CHAR8 *Buffer,
1058 IN UINTN Flags,
1059 IN INT64 Value,
1060 IN UINTN Width
1061 )
1062 {
1063 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 1);
1064 }