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