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