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