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