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