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