]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BasePrintLib/PrintLib.c
d33f49d3882aa32f08541cd361e2176ef162e6cc
[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 skiped 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 if (sizeof (VOID *) > 4) {
260 Flags |= LONG_TYPE;
261 }
262 case 'X':
263 Flags |= PREFIX_ZERO;
264 //
265 // break skiped on purpose
266 //
267 case 'x':
268 Flags |= RADIX_HEX;
269 //
270 // break skiped on purpose
271 //
272 case 'd':
273 if ((Flags & LONG_TYPE) == 0) {
274 Value = (VA_ARG (Marker, int));
275 } else {
276 Value = VA_ARG (Marker, INT64);
277 }
278 if ((Flags & PREFIX_BLANK) != 0) {
279 Prefix = ' ';
280 }
281 if ((Flags & PREFIX_SIGN) != 0) {
282 Prefix = '+';
283 }
284 if ((Flags & COMMA_TYPE) != 0) {
285 Comma = TRUE;
286 }
287 if ((Flags & RADIX_HEX) == 0) {
288 Radix = 10;
289 if (Comma) {
290 Flags &= (~PREFIX_ZERO);
291 Precision = 1;
292 }
293 if (Value < 0) {
294 Flags |= PREFIX_SIGN;
295 Prefix = '-';
296 Value = -Value;
297 }
298 } else {
299 Radix = 16;
300 Comma = FALSE;
301 if ((Flags & LONG_TYPE) == 0 && Value < 0) {
302 Value = (unsigned int)Value;
303 }
304 }
305 //
306 // Convert Value to a reversed string
307 //
308 Count = BasePrintLibValueToString (ValueBuffer, Value, Radix);
309 if (Value == 0 && Precision == 0) {
310 Count = 0;
311 }
312 ArgumentString = (CHAR8 *)ValueBuffer + Count;
313
314 Digits = Count % 3;
315 if (Digits != 0) {
316 Digits = 3 - Digits;
317 }
318 if (Comma && Count != 0) {
319 Count += ((Count - 1) / 3);
320 }
321 if (Prefix != 0) {
322 Count++;
323 Precision++;
324 }
325 Flags |= ARGUMENT_REVERSED;
326 ZeroPad = TRUE;
327 if ((Flags & PREFIX_ZERO) != 0) {
328 if ((Flags & LEFT_JUSTIFY) == 0) {
329 if ((Flags & PAD_TO_WIDTH) != 0) {
330 if ((Flags & PRECISION) == 0) {
331 Precision = Width;
332 }
333 }
334 }
335 }
336 break;
337
338 case 's':
339 case 'S':
340 Flags |= ARGUMENT_UNICODE;
341 //
342 // break skipped on purpose
343 //
344 case 'a':
345 ArgumentString = (CHAR8 *)VA_ARG (Marker, CHAR8 *);
346 if (ArgumentString == NULL) {
347 Flags &= (~ARGUMENT_UNICODE);
348 ArgumentString = "<null string>";
349 }
350 break;
351
352 case 'c':
353 Character = VA_ARG (Marker, UINTN) & 0xffff;
354 ArgumentString = (CHAR8 *)&Character;
355 Flags |= ARGUMENT_UNICODE;
356 break;
357
358 case 'g':
359 TmpGuid = VA_ARG (Marker, GUID *);
360 if (TmpGuid == NULL) {
361 ArgumentString = "<null guid>";
362 } else {
363 BasePrintLibSPrint (
364 ValueBuffer,
365 MAXIMUM_VALUE_CHARACTERS,
366 0,
367 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
368 TmpGuid->Data1,
369 TmpGuid->Data2,
370 TmpGuid->Data3,
371 TmpGuid->Data4[0],
372 TmpGuid->Data4[1],
373 TmpGuid->Data4[2],
374 TmpGuid->Data4[3],
375 TmpGuid->Data4[4],
376 TmpGuid->Data4[5],
377 TmpGuid->Data4[6],
378 TmpGuid->Data4[7]
379 );
380 ArgumentString = ValueBuffer;
381 }
382 break;
383
384 case 't':
385 TmpTime = VA_ARG (Marker, TIME *);
386 if (TmpTime == NULL) {
387 ArgumentString = "<null time>";
388 } else {
389 BasePrintLibSPrint (
390 ValueBuffer,
391 MAXIMUM_VALUE_CHARACTERS,
392 0,
393 "%02d/%02d/%04d %02d:%02d",
394 TmpTime->Month,
395 TmpTime->Day,
396 TmpTime->Year,
397 TmpTime->Hour,
398 TmpTime->Minute
399 );
400 ArgumentString = ValueBuffer;
401 }
402 break;
403
404 case 'r':
405 Status = VA_ARG (Marker, RETURN_STATUS);
406 ArgumentString = ValueBuffer;
407 if (RETURN_ERROR (Status)) {
408 //
409 // Clear error bit
410 //
411 Index = Status & ~MAX_BIT;
412 if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {
413 ArgumentString = StatusString [Index + WARNING_STATUS_NUMBER];
414 }
415 } else {
416 Index = Status;
417 if (Index <= WARNING_STATUS_NUMBER) {
418 ArgumentString = StatusString [Index];
419 }
420 }
421 if (ArgumentString == ValueBuffer) {
422 BasePrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);
423 }
424 break;
425
426 case '\n':
427 ArgumentString = "\n\r";
428 break;
429
430 case '%':
431 default:
432 //
433 // if the type is '%' or unknown, then print it to the screen
434 //
435 ArgumentString = (CHAR8 *)&FormatCharacter;
436 Flags |= ARGUMENT_UNICODE;
437 break;
438 }
439 break;
440
441 case '\n':
442 ArgumentString = "\n\r";
443 break;
444
445 default:
446 ArgumentString = (CHAR8 *)&FormatCharacter;
447 Flags |= ARGUMENT_UNICODE;
448 break;
449 }
450
451 //
452 // Retrieve the ArgumentString attriubutes
453 //
454 if ((Flags & ARGUMENT_UNICODE) != 0) {
455 ArgumentMask = 0xffff;
456 BytesPerArgumentCharacter = 2;
457 } else {
458 ArgumentMask = 0xff;
459 BytesPerArgumentCharacter = 1;
460 }
461 if ((Flags & ARGUMENT_REVERSED) != 0) {
462 BytesPerArgumentCharacter = -BytesPerArgumentCharacter;
463 } else {
464 //
465 // Compute the number of characters in ArgumentString and store it in Count
466 // ArgumentString is either null-terminated, or it contains Precision characters
467 //
468 for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {
469 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;
470 if (ArgumentCharacter == 0) {
471 break;
472 }
473 }
474 }
475
476 //
477 // Limit the length of the string to append to the remaining characters in the output buffer
478 //
479 if (Count > BufferSize) {
480 Count = BufferSize;
481 }
482 if (Precision < Count) {
483 Precision = Count;
484 }
485
486 //
487 // Pad before the string
488 //
489 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {
490 Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);
491 }
492
493 if (ZeroPad) {
494 if (Prefix != 0) {
495 Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);
496 }
497 Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, '0', BytesPerOutputCharacter);
498 } else {
499 Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, ' ', BytesPerOutputCharacter);
500 if (Prefix != 0) {
501 Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);
502 }
503 }
504
505 //
506 // Output the Prefix character if it is present
507 //
508 Index = 0;
509 if (Prefix != 0) {
510 Index++;
511 }
512
513 //
514 // Copy the string into the output buffer performing the required type conversions
515 //
516 while (Index < Count) {
517 ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;
518
519 Buffer = BasePrintLibFillBuffer (Buffer, 1, ArgumentCharacter, BytesPerOutputCharacter);
520 ArgumentString += BytesPerArgumentCharacter;
521 Index++;
522 if (Comma) {
523 Digits++;
524 if (Digits == 3) {
525 Digits = 0;
526 Index++;
527 if (Index < Count) {
528 Buffer = BasePrintLibFillBuffer (Buffer, 1, ',', BytesPerOutputCharacter);
529 }
530 }
531 }
532 }
533
534 //
535 // Pad after the string
536 //
537 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {
538 Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);
539 }
540
541 //
542 // Reduce the number of characters
543 //
544 BufferSize -= Count;
545
546 //
547 // Get the next character from the format string
548 //
549 Format += BytesPerFormatCharacter;
550
551 //
552 // Get the next character from the format string
553 //
554 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;
555 }
556
557 //
558 // Null terminate the Unicode or ASCII string
559 //
560 BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter);
561 //
562 // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength
563 // Unicode characters if PcdMaximumUnicodeStringLength is not zero.
564 //
565 ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0));
566 //
567 // Make sure output buffer cannot contain more than PcdMaximumAsciiStringLength
568 // ASCII characters if PcdMaximumAsciiStringLength is not zero.
569 //
570 ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0));
571
572 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);
573 }
574
575 /**
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.
578
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.
582
583 @param Buffer Character buffer to print the results of the parsing
584 of Format into.
585 @param BufferSize Maximum number of characters to put into buffer.
586 Zero means no limit.
587 @param Flags Intial flags value.
588 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
589 @param FormatString Null-terminated format string.
590
591 @return Number of characters printed not including the Null-terminator.
592
593 **/
594 UINTN
595 BasePrintLibSPrint (
596 OUT CHAR8 *StartOfBuffer,
597 IN UINTN BufferSize,
598 IN UINTN Flags,
599 IN CONST CHAR8 *FormatString,
600 ...
601 )
602 {
603 VA_LIST Marker;
604
605 VA_START (Marker, FormatString);
606 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, Flags, FormatString, Marker);
607 }
608
609 /**
610 Produces a Null-terminated Unicode string in an output buffer based on
611 a Null-terminated Unicode format string and a VA_LIST argument list
612
613 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
614 and BufferSize.
615 The Unicode string is produced by parsing the format string specified by FormatString.
616 Arguments are pulled from the variable argument list specified by Marker based on the
617 contents of the format string.
618 The number of Unicode characters in the produced output buffer is returned not including
619 the Null-terminator.
620 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
621
622 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
623 If BufferSize > 1 and FormatString is NULL, then ASSERT().
624 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
625 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
626 ASSERT().
627 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
628 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
629 Null-terminator, then ASSERT().
630
631 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
632 Unicode string.
633 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
634 @param FormatString Null-terminated Unicode format string.
635 @param Marker VA_LIST marker for the variable argument list.
636
637 @return The number of Unicode characters in the produced output buffer not including the
638 Null-terminator.
639
640 **/
641 UINTN
642 EFIAPI
643 UnicodeVSPrint (
644 OUT CHAR16 *StartOfBuffer,
645 IN UINTN BufferSize,
646 IN CONST CHAR16 *FormatString,
647 IN VA_LIST Marker
648 )
649 {
650 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, FORMAT_UNICODE | OUTPUT_UNICODE, (CHAR8 *)FormatString, Marker);
651 }
652
653 /**
654 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
655 Unicode format string and variable argument list.
656
657 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
658 and BufferSize.
659 The Unicode string is produced by parsing the format string specified by FormatString.
660 Arguments are pulled from the variable argument list based on the contents of the format string.
661 The number of Unicode characters in the produced output buffer is returned not including
662 the Null-terminator.
663 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
664
665 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
666 If BufferSize > 1 and FormatString is NULL, then ASSERT().
667 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
668 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
669 ASSERT().
670 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
671 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
672 Null-terminator, then ASSERT().
673
674 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
675 Unicode string.
676 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
677 @param FormatString Null-terminated Unicode format string.
678
679 @return The number of Unicode characters in the produced output buffer not including the
680 Null-terminator.
681
682 **/
683 UINTN
684 EFIAPI
685 UnicodeSPrint (
686 OUT CHAR16 *StartOfBuffer,
687 IN UINTN BufferSize,
688 IN CONST CHAR16 *FormatString,
689 ...
690 )
691 {
692 VA_LIST Marker;
693
694 VA_START (Marker, FormatString);
695 return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
696 }
697
698 /**
699 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
700 ASCII format string and a VA_LIST argument list
701
702 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
703 and BufferSize.
704 The Unicode string is produced by parsing the format string specified by FormatString.
705 Arguments are pulled from the variable argument list specified by Marker based on the
706 contents of the format string.
707 The number of Unicode characters in the produced output buffer is returned not including
708 the Null-terminator.
709 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
710
711 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
712 If BufferSize > 1 and FormatString is NULL, then ASSERT().
713 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
714 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
715 ASSERT().
716 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
717 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
718 Null-terminator, then ASSERT().
719
720 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
721 Unicode string.
722 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
723 @param FormatString Null-terminated Unicode format string.
724 @param Marker VA_LIST marker for the variable argument list.
725
726 @return The number of Unicode characters in the produced output buffer not including the
727 Null-terminator.
728
729 **/
730 UINTN
731 EFIAPI
732 UnicodeVSPrintAsciiFormat (
733 OUT CHAR16 *StartOfBuffer,
734 IN UINTN BufferSize,
735 IN CONST CHAR8 *FormatString,
736 IN VA_LIST Marker
737 )
738 {
739 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, OUTPUT_UNICODE,FormatString, Marker);
740 }
741
742 /**
743 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
744 ASCII format string and variable argument list.
745
746 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
747 and BufferSize.
748 The Unicode string is produced by parsing the format string specified by FormatString.
749 Arguments are pulled from the variable argument list based on the contents of the
750 format string.
751 The number of Unicode characters in the produced output buffer is returned not including
752 the Null-terminator.
753 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
754
755 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
756 If BufferSize > 1 and FormatString is NULL, then ASSERT().
757 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
758 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
759 ASSERT().
760 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
761 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
762 Null-terminator, then ASSERT().
763
764 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
765 Unicode string.
766 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
767 @param FormatString Null-terminated Unicode format string.
768
769 @return The number of Unicode characters in the produced output buffer not including the
770 Null-terminator.
771
772 **/
773 UINTN
774 EFIAPI
775 UnicodeSPrintAsciiFormat (
776 OUT CHAR16 *StartOfBuffer,
777 IN UINTN BufferSize,
778 IN CONST CHAR8 *FormatString,
779 ...
780 )
781 {
782 VA_LIST Marker;
783
784 VA_START (Marker, FormatString);
785 return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
786 }
787
788 /**
789 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
790 ASCII format string and a VA_LIST argument list.
791
792 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
793 and BufferSize.
794 The ASCII string is produced by parsing the format string specified by FormatString.
795 Arguments are pulled from the variable argument list specified by Marker based on
796 the contents of the format string.
797 The number of ASCII characters in the produced output buffer is returned not including
798 the Null-terminator.
799 If BufferSize is 0, then no output buffer is produced and 0 is returned.
800
801 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
802 If BufferSize > 0 and FormatString is NULL, then ASSERT().
803 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
804 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
805 ASSERT().
806 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
807 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
808 Null-terminator, then ASSERT().
809
810 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
811 ASCII string.
812 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
813 @param FormatString Null-terminated Unicode format string.
814 @param Marker VA_LIST marker for the variable argument list.
815
816 @return The number of ASCII characters in the produced output buffer not including the
817 Null-terminator.
818
819 **/
820 UINTN
821 EFIAPI
822 AsciiVSPrint (
823 OUT CHAR8 *StartOfBuffer,
824 IN UINTN BufferSize,
825 IN CONST CHAR8 *FormatString,
826 IN VA_LIST Marker
827 )
828 {
829 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, 0, FormatString, Marker);
830 }
831
832 /**
833 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
834 ASCII format string and variable argument list.
835
836 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
837 and BufferSize.
838 The ASCII string is produced by parsing the format string specified by FormatString.
839 Arguments are pulled from the variable argument list based on the contents of the
840 format string.
841 The number of ASCII characters in the produced output buffer is returned not including
842 the Null-terminator.
843 If BufferSize is 0, then no output buffer is produced and 0 is returned.
844
845 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
846 If BufferSize > 0 and FormatString is NULL, then ASSERT().
847 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
848 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
849 ASSERT().
850 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
851 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
852 Null-terminator, then ASSERT().
853
854 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
855 ASCII string.
856 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
857 @param FormatString Null-terminated Unicode format string.
858
859 @return The number of ASCII characters in the produced output buffer not including the
860 Null-terminator.
861
862 **/
863 UINTN
864 EFIAPI
865 AsciiSPrint (
866 OUT CHAR8 *StartOfBuffer,
867 IN UINTN BufferSize,
868 IN CONST CHAR8 *FormatString,
869 ...
870 )
871 {
872 VA_LIST Marker;
873
874 VA_START (Marker, FormatString);
875 return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
876 }
877
878 /**
879 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
880 ASCII format string and a VA_LIST argument list.
881
882 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
883 and BufferSize.
884 The ASCII string is produced by parsing the format string specified by FormatString.
885 Arguments are pulled from the variable argument list specified by Marker based on
886 the contents of the format string.
887 The number of ASCII characters in the produced output buffer is returned not including
888 the Null-terminator.
889 If BufferSize is 0, then no output buffer is produced and 0 is returned.
890
891 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
892 If BufferSize > 0 and FormatString is NULL, then ASSERT().
893 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
894 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
895 ASSERT().
896 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
897 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
898 Null-terminator, then ASSERT().
899
900 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
901 ASCII string.
902 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
903 @param FormatString Null-terminated Unicode format string.
904 @param Marker VA_LIST marker for the variable argument list.
905
906 @return The number of ASCII characters in the produced output buffer not including the
907 Null-terminator.
908
909 **/
910 UINTN
911 EFIAPI
912 AsciiVSPrintUnicodeFormat (
913 OUT CHAR8 *StartOfBuffer,
914 IN UINTN BufferSize,
915 IN CONST CHAR16 *FormatString,
916 IN VA_LIST Marker
917 )
918 {
919 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, FORMAT_UNICODE, (CHAR8 *)FormatString, Marker);
920 }
921
922 /**
923 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
924 ASCII format string and variable argument list.
925
926 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
927 and BufferSize.
928 The ASCII string is produced by parsing the format string specified by FormatString.
929 Arguments are pulled from the variable argument list based on the contents of the
930 format string.
931 The number of ASCII characters in the produced output buffer is returned not including
932 the Null-terminator.
933 If BufferSize is 0, then no output buffer is produced and 0 is returned.
934
935 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
936 If BufferSize > 0 and FormatString is NULL, then ASSERT().
937 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
938 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
939 ASSERT().
940 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
941 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
942 Null-terminator, then ASSERT().
943
944 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
945 ASCII string.
946 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
947 @param FormatString Null-terminated Unicode format string.
948
949 @return The number of ASCII characters in the produced output buffer not including the
950 Null-terminator.
951
952 **/
953 UINTN
954 EFIAPI
955 AsciiSPrintUnicodeFormat (
956 OUT CHAR8 *StartOfBuffer,
957 IN UINTN BufferSize,
958 IN CONST CHAR16 *FormatString,
959 ...
960 )
961 {
962 VA_LIST Marker;
963
964 VA_START (Marker, FormatString);
965 return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
966 }
967
968 /**
969 Converts a decimal value to a Null-terminated Unicode string.
970
971 Converts the decimal number specified by Value to a Null-terminated Unicode
972 string specified by Buffer containing at most Width characters.
973 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
974 The number of Unicode characters in Buffer is returned not including the Null-terminator.
975 If the conversion contains more than Width characters, then only the first
976 Width characters are returned, and the total number of characters
977 required to perform the conversion is returned.
978 Additional conversion parameters are specified in Flags.
979 The Flags bit LEFT_JUSTIFY is always ignored.
980 All conversions are left justified in Buffer.
981 If Width is 0, PREFIX_ZERO is ignored in Flags.
982 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
983 are inserted every 3rd digit starting from the right.
984 If Value is < 0, then the fist character in Buffer is a '-'.
985 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
986 then Buffer is padded with '0' characters so the combination of the optional '-'
987 sign character, '0' characters, digit characters for Value, and the Null-terminator
988 add up to Width characters.
989
990 If Buffer is NULL, then ASSERT().
991 If unsupported bits are set in Flags, then ASSERT().
992 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
993
994 @param Buffer Pointer to the output buffer for the produced Null-terminated
995 Unicode string.
996 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
997 @param Value The 64-bit signed value to convert to a string.
998 @param Width The maximum number of Unicode characters to place in Buffer.
999
1000 @return The number of Unicode characters in Buffer not including the Null-terminator.
1001
1002 **/
1003 UINTN
1004 EFIAPI
1005 UnicodeValueToString (
1006 IN OUT CHAR16 *Buffer,
1007 IN UINTN Flags,
1008 IN INT64 Value,
1009 IN UINTN Width
1010 )
1011 {
1012 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);
1013 }
1014
1015 /**
1016 Converts a decimal value to a Null-terminated ASCII string.
1017
1018 Converts the decimal number specified by Value to a Null-terminated ASCII string
1019 specified by Buffer containing at most Width characters.
1020 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
1021 The number of ASCII characters in Buffer is returned not including the Null-terminator.
1022 If the conversion contains more than Width characters, then only the first Width
1023 characters are returned, and the total number of characters required to perform
1024 the conversion is returned.
1025 Additional conversion parameters are specified in Flags.
1026 The Flags bit LEFT_JUSTIFY is always ignored.
1027 All conversions are left justified in Buffer.
1028 If Width is 0, PREFIX_ZERO is ignored in Flags.
1029 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
1030 are inserted every 3rd digit starting from the right.
1031 If Value is < 0, then the fist character in Buffer is a '-'.
1032 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then Buffer
1033 is padded with '0' characters so the combination of the optional '-'
1034 sign character, '0' characters, digit characters for Value, and the
1035 Null-terminator add up to Width characters.
1036
1037 If Buffer is NULL, then ASSERT().
1038 If unsupported bits are set in Flags, then ASSERT().
1039 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
1040
1041 @param Buffer Pointer to the output buffer for the produced Null-terminated
1042 ASCII string.
1043 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
1044 @param Value The 64-bit signed value to convert to a string.
1045 @param Width The maximum number of ASCII characters to place in Buffer.
1046
1047 @return The number of ASCII characters in Buffer not including the Null-terminator.
1048
1049 **/
1050 UINTN
1051 EFIAPI
1052 AsciiValueToString (
1053 IN OUT CHAR8 *Buffer,
1054 IN UINTN Flags,
1055 IN INT64 Value,
1056 IN UINTN Width
1057 )
1058 {
1059 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 1);
1060 }