]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Foundation/Library/EdkIIGlueLib/Library/BasePrintLib/PrintLib.c
Add Missing invocations to VA_END() for VA_START().
[mirror_edk2.git] / EdkCompatibilityPkg / Foundation / Library / EdkIIGlueLib / Library / BasePrintLib / PrintLib.c
1 /*++
2
3 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
4 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 = (UINTN) 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 UINTN NumberOfPrinted;
605
606 VA_START (Marker, FormatString);
607 NumberOfPrinted = BasePrintLibVSPrint (StartOfBuffer, BufferSize, Flags, FormatString, Marker);
608 VA_END (Marker);
609 return NumberOfPrinted;
610 }
611
612 /**
613 Produces a Null-terminated Unicode string in an output buffer based on
614 a Null-terminated Unicode format string and a VA_LIST argument list
615
616 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
617 and BufferSize.
618 The Unicode string is produced by parsing the format string specified by FormatString.
619 Arguments are pulled from the variable argument list specified by Marker based on the
620 contents of the format string.
621 The number of Unicode characters in the produced output buffer is returned not including
622 the Null-terminator.
623 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
624
625 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
626 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
627 If BufferSize > 1 and FormatString is NULL, then ASSERT().
628 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
629 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
630 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
631 ASSERT().
632 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
633 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
634 Null-terminator, then ASSERT().
635
636 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
637 Unicode string.
638 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
639 @param FormatString Null-terminated Unicode format string.
640 @param Marker VA_LIST marker for the variable argument list.
641
642 @return The number of Unicode characters in the produced output buffer not including the
643 Null-terminator.
644
645 **/
646 UINTN
647 EFIAPI
648 UnicodeVSPrint (
649 OUT CHAR16 *StartOfBuffer,
650 IN UINTN BufferSize,
651 IN CONST CHAR16 *FormatString,
652 IN VA_LIST Marker
653 )
654 {
655 ASSERT_UNICODE_BUFFER(StartOfBuffer);
656 ASSERT_UNICODE_BUFFER(FormatString);
657 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, FORMAT_UNICODE | OUTPUT_UNICODE, (CHAR8 *)FormatString, Marker);
658 }
659
660 /**
661 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
662 Unicode format string and variable argument list.
663
664 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
665 and BufferSize.
666 The Unicode string is produced by parsing the format string specified by FormatString.
667 Arguments are pulled from the variable argument list based on the contents of the format string.
668 The number of Unicode characters in the produced output buffer is returned not including
669 the Null-terminator.
670 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
671
672 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
673 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
674 If BufferSize > 1 and FormatString is NULL, then ASSERT().
675 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
676 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
677 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
678 ASSERT().
679 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
680 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
681 Null-terminator, then ASSERT().
682
683 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
684 Unicode string.
685 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
686 @param FormatString Null-terminated Unicode format string.
687
688 @return The number of Unicode characters in the produced output buffer not including the
689 Null-terminator.
690
691 **/
692 UINTN
693 EFIAPI
694 UnicodeSPrint (
695 OUT CHAR16 *StartOfBuffer,
696 IN UINTN BufferSize,
697 IN CONST CHAR16 *FormatString,
698 ...
699 )
700 {
701 VA_LIST Marker;
702 UINTN NumberOfPrinted;
703
704 VA_START (Marker, FormatString);
705 NumberOfPrinted = UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
706 VA_END (Marker);
707 return NumberOfPrinted;
708 }
709
710 /**
711 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
712 ASCII format string and a VA_LIST argument list
713
714 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
715 and BufferSize.
716 The Unicode string is produced by parsing the format string specified by FormatString.
717 Arguments are pulled from the variable argument list specified by Marker based on the
718 contents of the format string.
719 The number of Unicode characters in the produced output buffer is returned not including
720 the Null-terminator.
721 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
722
723 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
724 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
725 If BufferSize > 1 and FormatString is NULL, then ASSERT().
726 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
727 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
728 ASSERT().
729 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
730 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
731 Null-terminator, then ASSERT().
732
733 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
734 Unicode string.
735 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
736 @param FormatString Null-terminated Unicode format string.
737 @param Marker VA_LIST marker for the variable argument list.
738
739 @return The number of Unicode characters in the produced output buffer not including the
740 Null-terminator.
741
742 **/
743 UINTN
744 EFIAPI
745 UnicodeVSPrintAsciiFormat (
746 OUT CHAR16 *StartOfBuffer,
747 IN UINTN BufferSize,
748 IN CONST CHAR8 *FormatString,
749 IN VA_LIST Marker
750 )
751 {
752 ASSERT_UNICODE_BUFFER(StartOfBuffer);
753 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, OUTPUT_UNICODE,FormatString, Marker);
754 }
755
756 /**
757 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated
758 ASCII format string and variable argument list.
759
760 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer
761 and BufferSize.
762 The Unicode string is produced by parsing the format string specified by FormatString.
763 Arguments are pulled from the variable argument list based on the contents of the
764 format string.
765 The number of Unicode characters in the produced output buffer is returned not including
766 the Null-terminator.
767 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.
768
769 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().
770 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().
771 If BufferSize > 1 and FormatString is NULL, then ASSERT().
772 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
773 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
774 ASSERT().
775 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string
776 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the
777 Null-terminator, then ASSERT().
778
779 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
780 Unicode string.
781 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
782 @param FormatString Null-terminated Unicode format string.
783
784 @return The number of Unicode characters in the produced output buffer not including the
785 Null-terminator.
786
787 **/
788 UINTN
789 EFIAPI
790 UnicodeSPrintAsciiFormat (
791 OUT CHAR16 *StartOfBuffer,
792 IN UINTN BufferSize,
793 IN CONST CHAR8 *FormatString,
794 ...
795 )
796 {
797 VA_LIST Marker;
798 UINTN NumberOfPrinted;
799
800 VA_START (Marker, FormatString);
801 NumberOfPrinted = UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);
802 VA_END (Marker);
803 return NumberOfPrinted;
804 }
805
806 /**
807 Converts a decimal value to a Null-terminated Unicode string.
808
809 Converts the decimal number specified by Value to a Null-terminated Unicode
810 string specified by Buffer containing at most Width characters. No padding of spaces
811 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
812 The number of Unicode characters in Buffer is returned not including the Null-terminator.
813 If the conversion contains more than Width characters, then only the first
814 Width characters are returned, and the total number of characters
815 required to perform the conversion is returned.
816 Additional conversion parameters are specified in Flags.
817
818 The Flags bit LEFT_JUSTIFY is always ignored.
819 All conversions are left justified in Buffer.
820 If Width is 0, PREFIX_ZERO is ignored in Flags.
821 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
822 are inserted every 3rd digit starting from the right.
823 If RADIX_HEX is set in Flags, then the output buffer will be
824 formatted in hexadecimal format.
825 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
826 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
827 then Buffer is padded with '0' characters so the combination of the optional '-'
828 sign character, '0' characters, digit characters for Value, and the Null-terminator
829 add up to Width characters.
830 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
831 If Buffer is NULL, then ASSERT().
832 If Buffer is not aligned on a 16-bit boundary, then ASSERT().
833 If unsupported bits are set in Flags, then ASSERT().
834 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
835 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
836
837 @param Buffer Pointer to the output buffer for the produced Null-terminated
838 Unicode string.
839 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
840 @param Value The 64-bit signed value to convert to a string.
841 @param Width The maximum number of Unicode characters to place in Buffer, not including
842 the Null-terminator.
843
844 @return The number of Unicode characters in Buffer not including the Null-terminator.
845
846 **/
847 UINTN
848 EFIAPI
849 UnicodeValueToString (
850 IN OUT CHAR16 *Buffer,
851 IN UINTN Flags,
852 IN INT64 Value,
853 IN UINTN Width
854 )
855 {
856 ASSERT_UNICODE_BUFFER(Buffer);
857 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);
858 }
859
860 /**
861 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
862 ASCII format string and a VA_LIST argument list.
863
864 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
865 and BufferSize.
866 The ASCII string is produced by parsing the format string specified by FormatString.
867 Arguments are pulled from the variable argument list specified by Marker based on
868 the contents of the format string.
869 The number of ASCII characters in the produced output buffer is returned not including
870 the Null-terminator.
871 If BufferSize is 0, then no output buffer is produced and 0 is returned.
872
873 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
874 If BufferSize > 0 and FormatString is NULL, then ASSERT().
875 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
876 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
877 ASSERT().
878 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
879 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
880 Null-terminator, then ASSERT().
881
882 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
883 ASCII string.
884 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
885 @param FormatString Null-terminated Unicode format string.
886 @param Marker VA_LIST marker for the variable argument list.
887
888 @return The number of ASCII characters in the produced output buffer not including the
889 Null-terminator.
890
891 **/
892 UINTN
893 EFIAPI
894 AsciiVSPrint (
895 OUT CHAR8 *StartOfBuffer,
896 IN UINTN BufferSize,
897 IN CONST CHAR8 *FormatString,
898 IN VA_LIST Marker
899 )
900 {
901 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, 0, FormatString, Marker);
902 }
903
904 /**
905 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
906 ASCII format string and variable argument list.
907
908 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
909 and BufferSize.
910 The ASCII string is produced by parsing the format string specified by FormatString.
911 Arguments are pulled from the variable argument list based on the contents of the
912 format string.
913 The number of ASCII characters in the produced output buffer is returned not including
914 the Null-terminator.
915 If BufferSize is 0, then no output buffer is produced and 0 is returned.
916
917 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
918 If BufferSize > 0 and FormatString is NULL, then ASSERT().
919 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than
920 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then
921 ASSERT().
922 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
923 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
924 Null-terminator, then ASSERT().
925
926 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
927 ASCII string.
928 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
929 @param FormatString Null-terminated Unicode format string.
930
931 @return The number of ASCII characters in the produced output buffer not including the
932 Null-terminator.
933
934 **/
935 UINTN
936 EFIAPI
937 AsciiSPrint (
938 OUT CHAR8 *StartOfBuffer,
939 IN UINTN BufferSize,
940 IN CONST CHAR8 *FormatString,
941 ...
942 )
943 {
944 VA_LIST Marker;
945 UINTN NumberOfPrinted;
946
947 VA_START (Marker, FormatString);
948 NumberOfPrinted = AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);
949 VA_END (Marker);
950 return NumberOfPrinted;
951 }
952
953 /**
954 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
955 ASCII format string and a VA_LIST argument list.
956
957 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
958 and BufferSize.
959 The ASCII string is produced by parsing the format string specified by FormatString.
960 Arguments are pulled from the variable argument list specified by Marker based on
961 the contents of the format string.
962 The number of ASCII characters in the produced output buffer is returned not including
963 the Null-terminator.
964 If BufferSize is 0, then no output buffer is produced and 0 is returned.
965
966 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
967 If BufferSize > 0 and FormatString is NULL, then ASSERT().
968 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
969 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
970 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
971 ASSERT().
972 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
973 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
974 Null-terminator, then ASSERT().
975
976 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
977 ASCII string.
978 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
979 @param FormatString Null-terminated Unicode format string.
980 @param Marker VA_LIST marker for the variable argument list.
981
982 @return The number of ASCII characters in the produced output buffer not including the
983 Null-terminator.
984
985 **/
986 UINTN
987 EFIAPI
988 AsciiVSPrintUnicodeFormat (
989 OUT CHAR8 *StartOfBuffer,
990 IN UINTN BufferSize,
991 IN CONST CHAR16 *FormatString,
992 IN VA_LIST Marker
993 )
994 {
995 ASSERT_UNICODE_BUFFER (FormatString);
996 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, FORMAT_UNICODE, (CHAR8 *)FormatString, Marker);
997 }
998
999 /**
1000 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated
1001 ASCII format string and variable argument list.
1002
1003 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer
1004 and BufferSize.
1005 The ASCII string is produced by parsing the format string specified by FormatString.
1006 Arguments are pulled from the variable argument list based on the contents of the
1007 format string.
1008 The number of ASCII characters in the produced output buffer is returned not including
1009 the Null-terminator.
1010 If BufferSize is 0, then no output buffer is produced and 0 is returned.
1011
1012 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().
1013 If BufferSize > 0 and FormatString is NULL, then ASSERT().
1014 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().
1015 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than
1016 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then
1017 ASSERT().
1018 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string
1019 contains more than PcdMaximumAsciiStringLength ASCII characters not including the
1020 Null-terminator, then ASSERT().
1021
1022 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
1023 ASCII string.
1024 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
1025 @param FormatString Null-terminated Unicode format string.
1026
1027 @return The number of ASCII characters in the produced output buffer not including the
1028 Null-terminator.
1029
1030 **/
1031 UINTN
1032 EFIAPI
1033 AsciiSPrintUnicodeFormat (
1034 OUT CHAR8 *StartOfBuffer,
1035 IN UINTN BufferSize,
1036 IN CONST CHAR16 *FormatString,
1037 ...
1038 )
1039 {
1040 VA_LIST Marker;
1041 UINTN NumberOfPrinted;
1042
1043 VA_START (Marker, FormatString);
1044 NumberOfPrinted = AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);
1045 VA_END (Marker);
1046 return NumberOfPrinted;
1047 }
1048
1049
1050 /**
1051 Converts a decimal value to a Null-terminated ASCII string.
1052
1053 Converts the decimal number specified by Value to a Null-terminated ASCII string
1054 specified by Buffer containing at most Width characters. No padding of spaces
1055 is ever performed.
1056 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
1057 The number of ASCII characters in Buffer is returned not including the Null-terminator.
1058 If the conversion contains more than Width characters, then only the first Width
1059 characters are returned, and the total number of characters required to perform
1060 the conversion is returned.
1061 Additional conversion parameters are specified in Flags.
1062 The Flags bit LEFT_JUSTIFY is always ignored.
1063 All conversions are left justified in Buffer.
1064 If Width is 0, PREFIX_ZERO is ignored in Flags.
1065 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
1066 are inserted every 3rd digit starting from the right.
1067 If RADIX_HEX is set in Flags, then the output buffer will be
1068 formatted in hexadecimal format.
1069 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.
1070 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
1071 then Buffer is padded with '0' characters so the combination of the optional '-'
1072 sign character, '0' characters, digit characters for Value, and the Null-terminator
1073 add up to Width characters.
1074
1075 If Buffer is NULL, then ASSERT().
1076 If unsupported bits are set in Flags, then ASSERT().
1077 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().
1078 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
1079
1080 @param Buffer Pointer to the output buffer for the produced Null-terminated
1081 ASCII string.
1082 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.
1083 @param Value The 64-bit signed value to convert to a string.
1084 @param Width The maximum number of ASCII characters to place in Buffer, not including
1085 the Null-terminator.
1086
1087 @return The number of ASCII characters in Buffer not including the Null-terminator.
1088
1089 **/
1090 UINTN
1091 EFIAPI
1092 AsciiValueToString (
1093 IN OUT CHAR8 *Buffer,
1094 IN UINTN Flags,
1095 IN INT64 Value,
1096 IN UINTN Width
1097 )
1098 {
1099 return BasePrintLibConvertValueToString (Buffer, Flags, Value, Width, 1);
1100 }
1101