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