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