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