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