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