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