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