add function header
[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
238 case 'X':\r
239 Flags |= PREFIX_ZERO;\r
240 //\r
241 // break skiped on purpose\r
242 //\r
243 case 'x':\r
244 Flags |= RADIX_HEX;\r
245 //\r
246 // break skiped on purpose\r
247 //\r
248 case 'd':\r
249 if ((Flags & LONG_TYPE) == 0) {\r
250 Value = (VA_ARG (Marker, INTN));\r
251 } else {\r
252 Value = VA_ARG (Marker, INT64);\r
253 }\r
254 if ((Flags & PREFIX_BLANK) != 0) {\r
255 Prefix = ' ';\r
256 }\r
257 if ((Flags & PREFIX_SIGN) != 0) {\r
258 Prefix = '+';\r
259 }\r
260 if ((Flags & COMMA_TYPE) != 0) {\r
261 Comma = TRUE;\r
262 }\r
263 if ((Flags & RADIX_HEX) == 0) {\r
264 Radix = 10;\r
265 if (Comma) {\r
266 Flags &= (~PREFIX_ZERO);\r
267 Precision = 1;\r
268 }\r
269 if (Value < 0) {\r
270 Flags |= PREFIX_SIGN;\r
271 Prefix = '-';\r
272 Value = -Value;\r
273 }\r
274 } else {\r
275 Radix = 16;\r
276 Comma = FALSE;\r
277 if ((Flags & LONG_TYPE) == 0 && Value < 0) {\r
278 Value = (UINTN)Value;\r
279 }\r
280 }\r
281 //\r
282 // Convert Value to a reversed string\r
283 //\r
284 Count = BasePrintLibValueToString (ValueBuffer, Value, Radix);\r
285 if (Value == 0 && Precision == 0) {\r
286 Count = 0;\r
287 }\r
288 ArgumentString = (CHAR8 *)ValueBuffer + Count;\r
289 Digits = 3 - (Count % 3);\r
290 if (Comma && Count != 0) {\r
291 Count += ((Count - 1) / 3);\r
292 }\r
293 if (Prefix != 0) {\r
294 Count++;\r
295 }\r
296 Flags |= ARGUMENT_REVERSED;\r
297 ZeroPad = TRUE;\r
298 if ((Flags & PREFIX_ZERO) != 0) {\r
299 if ((Flags & PAD_TO_WIDTH) != 0) {\r
300 if ((Flags & PRECISION) == 0) {\r
301 Precision = Width;\r
302 }\r
303 }\r
304 }\r
305 break;\r
306\r
307 case 's':\r
308 case 'S':\r
309 Flags |= ARGUMENT_UNICODE;\r
310 //\r
311 // break skipped on purpose\r
312 //\r
313 case 'a':\r
314 ArgumentString = (CHAR8 *)VA_ARG (Marker, CHAR8 *);\r
315 if (ArgumentString == NULL) {\r
316 Flags &= (~ARGUMENT_UNICODE);\r
317 ArgumentString = "<null string>";\r
318 }\r
319 break;\r
320\r
321 case 'c':\r
322 Character = VA_ARG (Marker, UINTN) & 0xffff;\r
323 ArgumentString = (CHAR8 *)&Character;\r
324 Flags |= ARGUMENT_UNICODE;\r
325 break;\r
326\r
327 case 'g':\r
328 TmpGuid = VA_ARG (Marker, GUID *);\r
329 if (TmpGuid == NULL) {\r
330 ArgumentString = "<null guid>";\r
331 } else {\r
332 BasePrintLibSPrint (\r
333 ValueBuffer,\r
334 0, \r
335 0,\r
336 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",\r
f76fd83e 337 TmpGuid->Data1,\r
338 TmpGuid->Data2,\r
339 TmpGuid->Data3,\r
340 TmpGuid->Data4[0],\r
341 TmpGuid->Data4[1],\r
342 TmpGuid->Data4[2],\r
343 TmpGuid->Data4[3],\r
344 TmpGuid->Data4[4],\r
345 TmpGuid->Data4[5],\r
346 TmpGuid->Data4[6],\r
347 TmpGuid->Data4[7]\r
878ddf1f 348 );\r
349 ArgumentString = ValueBuffer;\r
350 }\r
351 break;\r
352\r
353 case 't':\r
354 TmpTime = VA_ARG (Marker, TIME *); \r
355 if (TmpTime == NULL) {\r
356 ArgumentString = "<null time>";\r
357 } else {\r
358 BasePrintLibSPrint (\r
359 ValueBuffer,\r
360 0,\r
361 0,\r
362 "%02d/%02d/%04d %02d:%02d",\r
f76fd83e 363 TmpTime->Month,\r
364 TmpTime->Day,\r
365 TmpTime->Year,\r
366 TmpTime->Hour,\r
367 TmpTime->Minute\r
878ddf1f 368 );\r
369 ArgumentString = ValueBuffer;\r
370 }\r
371 break;\r
372\r
373 case 'r':\r
374 Status = VA_ARG (Marker, RETURN_STATUS);\r
375 ArgumentString = ValueBuffer;\r
376 for (Index = 0; StatusString[Index].String != NULL; Index++) {\r
377 if (Status == StatusString[Index].Status) {\r
378 ArgumentString = StatusString[Index].String;\r
379 }\r
380 }\r
381 if (ArgumentString == ValueBuffer) {\r
382 BasePrintLibSPrint ((CHAR8 *) ValueBuffer, 0, 0, "%08X", Status);\r
383 }\r
384 break;\r
385\r
386 case '%':\r
387 default:\r
388 //\r
389 // if the type is '%' or unknown, then print it to the screen\r
390 //\r
391 ArgumentString = (CHAR8 *)&FormatCharacter;\r
392 Flags |= ARGUMENT_UNICODE;\r
393 break;\r
394 }\r
395 break;\r
396 case '\n':\r
397 ArgumentString = "\r\n";\r
398 break;\r
399 default:\r
400 ArgumentString = (CHAR8 *)&FormatCharacter;\r
401 Flags |= ARGUMENT_UNICODE;\r
402 break;\r
403 }\r
404\r
405 //\r
406 // Retrieve the ArgumentString attriubutes\r
407 //\r
408 if ((Flags & ARGUMENT_UNICODE) != 0) {\r
409 ArgumentMask = 0xffff;\r
410 BytesPerArgumentCharacter = 2;\r
411 } else {\r
412 ArgumentMask = 0xff;\r
413 BytesPerArgumentCharacter = 1;\r
414 }\r
415 if ((Flags & ARGUMENT_REVERSED) != 0) {\r
416 BytesPerArgumentCharacter = -BytesPerArgumentCharacter;\r
417 } else {\r
418 //\r
419 // Compute the number of characters in ArgumentString and store it in Count\r
420 // ArgumentString is either null-terminated, or it contains Precision characters\r
421 //\r
422 for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {\r
423 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;\r
424 if (ArgumentCharacter == 0) {\r
425 break;\r
426 }\r
427 }\r
428 }\r
429\r
430 //\r
431 // Limit the length of the string to append to the remaining characters in the output buffer\r
432 //\r
433 if (Count > BufferSize) {\r
434 Count = BufferSize;\r
435 }\r
436 if (Precision < Count) {\r
437 Precision = Count;\r
438 }\r
439\r
440 //\r
441 // Pad before the string\r
442 //\r
443 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {\r
444 Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
445 }\r
446\r
447 if (ZeroPad) {\r
448 if (Prefix != 0) {\r
449 Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);\r
450 }\r
451 Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, '0', BytesPerOutputCharacter);\r
452 } else {\r
453 Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, ' ', BytesPerOutputCharacter);\r
454 if (Prefix != 0) {\r
455 Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter);\r
456 }\r
457 }\r
458\r
459 //\r
460 // Output the Prefix character if it is present\r
461 //\r
462 Index = 0;\r
463 if (Prefix) {\r
464 Index++;\r
465 }\r
466\r
467 //\r
468 // Copy the string into the output buffer performing the required type conversions\r
469 //\r
470 while (Index < Count) {\r
471 ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;\r
472\r
473 Buffer = BasePrintLibFillBuffer (Buffer, 1, ArgumentCharacter, BytesPerOutputCharacter);\r
474 ArgumentString += BytesPerArgumentCharacter;\r
475 Index++;\r
476 if (Comma) {\r
477 Digits++;\r
478 if (Digits == 3) {\r
479 Digits = 0;\r
480 Index++;\r
481 if (Index < Count) {\r
482 Buffer = BasePrintLibFillBuffer (Buffer, 1, ',', BytesPerOutputCharacter);\r
483 }\r
484 }\r
485 }\r
486 }\r
487\r
488 //\r
489 // Pad after the string\r
490 //\r
491 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {\r
492 Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter);\r
493 }\r
494\r
495 //\r
496 // Reduce the number of characters\r
497 //\r
498 BufferSize -= Count;\r
499\r
500 //\r
501 // Get the next character from the format string\r
502 //\r
503 Format += BytesPerFormatCharacter;\r
504\r
505 //\r
506 // Get the next character from the format string\r
507 //\r
508 FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask;\r
509 }\r
510\r
511 //\r
512 // Null terminate the Unicode or ASCII string\r
513 //\r
514 Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter);\r
515 \r
516 return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter);\r
517}\r
518\r
3f9f540d 519/**\r
520 Worker function that produces a Null-terminated string in an output buffer \r
521 based on a Null-terminated format string and variable argument list.\r
522\r
523 VSPrint function to process format and place the results in Buffer. Since a \r
524 VA_LIST is used this rountine allows the nesting of Vararg routines. Thus \r
525 this is the main print working routine\r
526\r
527 @param Buffer Character buffer to print the results of the parsing\r
528 of Format into.\r
529 @param BufferSize Maximum number of characters to put into buffer.\r
530 Zero means no limit.\r
531 @param Flags Intial flags value.\r
532 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set\r
533 @param FormatString Null-terminated format string.\r
534\r
535 @return Number of characters printed.\r
536\r
537**/\r
878ddf1f 538UINTN\r
539BasePrintLibSPrint (\r
540 OUT CHAR8 *StartOfBuffer,\r
541 IN UINTN BufferSize,\r
542 IN UINTN Flags,\r
543 IN CONST CHAR8 *FormatString,\r
544 ...\r
545 )\r
546{\r
547 VA_LIST Marker;\r
548\r
549 VA_START (Marker, FormatString);\r
550 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, Flags, FormatString, Marker);\r
551}\r
552\r
3f9f540d 553/**\r
554 Produces a Null-terminated Unicode string in an output buffer based on \r
555 a Null-terminated Unicode format string and a VA_LIST argument list\r
556 \r
557 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
558 and BufferSize. \r
559 The Unicode string is produced by parsing the format string specified by FormatString. \r
560 Arguments are pulled from the variable argument list specified by Marker based on the \r
561 contents of the format string. \r
562 The length of the produced output buffer is returned.\r
563 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
564\r
565 If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().\r
566 If BufferSize is not 0 and FormatString is NULL, then ASSERT().\r
567 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
568 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
569 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
570 contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
571\r
572 @param StartOfBuffer APointer to the output buffer for the produced Null-terminated \r
573 Unicode string.\r
574 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
575 @param FormatString Null-terminated Unicode format string.\r
576 @param Marker VA_LIST marker for the variable argument list.\r
577 \r
578 @return return Length of the produced output buffer.\r
579\r
580**/\r
878ddf1f 581UINTN\r
582EFIAPI\r
583UnicodeVSPrint (\r
584 OUT CHAR16 *StartOfBuffer,\r
585 IN UINTN BufferSize,\r
586 IN CONST CHAR16 *FormatString,\r
587 IN VA_LIST Marker\r
588 )\r
589{\r
590 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, FORMAT_UNICODE | OUTPUT_UNICODE, (CHAR8 *)FormatString, Marker);\r
591}\r
592\r
3f9f540d 593/**\r
594 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
595 Unicode format string and variable argument list.\r
596 \r
597 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
598 and BufferSize.\r
599 The Unicode string is produced by parsing the format string specified by FormatString.\r
600 Arguments are pulled from the variable argument list based on the contents of the format string.\r
601 The length of the produced output buffer is returned. \r
602 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
603\r
604 If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().\r
605 If BufferSize is not 0 and FormatString is NULL, then ASSERT().\r
606 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
607 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
608 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
609 contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
610\r
611 @param StartOfBuffer APointer to the output buffer for the produced Null-terminated \r
612 Unicode string.\r
613 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
614 @param FormatString Null-terminated Unicode format string.\r
615 \r
616 @return Length of the produced output buffer.\r
617\r
618**/\r
878ddf1f 619UINTN\r
620EFIAPI\r
621UnicodeSPrint (\r
622 OUT CHAR16 *StartOfBuffer,\r
623 IN UINTN BufferSize,\r
624 IN CONST CHAR16 *FormatString,\r
625 ...\r
626 )\r
627{\r
628 VA_LIST Marker;\r
629\r
630 VA_START (Marker, FormatString);\r
631 return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
632}\r
633\r
3f9f540d 634/**\r
635 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
636 ASCII format string and a VA_LIST argument list\r
637 \r
638 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
639 and BufferSize.\r
640 The Unicode string is produced by parsing the format string specified by FormatString.\r
641 Arguments are pulled from the variable argument list specified by Marker based on the \r
642 contents of the format string.\r
643 The length of the produced output buffer is returned.\r
644 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
645\r
646 If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().\r
647 If BufferSize is not 0 and FormatString is NULL, then ASSERT().\r
648 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
649 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
650 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
651 contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
652\r
653 @param StartOfBuffer APointer to the output buffer for the produced Null-terminated \r
654 Unicode string.\r
655 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
656 @param FormatString Null-terminated Unicode format string.\r
657 @param Marker VA_LIST marker for the variable argument list.\r
658 \r
659 @return Length of the produced output buffer.\r
660\r
661**/\r
878ddf1f 662UINTN\r
663EFIAPI\r
664UnicodeVSPrintAsciiFormat (\r
665 OUT CHAR16 *StartOfBuffer,\r
666 IN UINTN BufferSize,\r
667 IN CONST CHAR8 *FormatString,\r
668 IN VA_LIST Marker\r
669 )\r
670{\r
671 return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, OUTPUT_UNICODE,FormatString, Marker);\r
672}\r
673\r
3f9f540d 674/**\r
675 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
676 ASCII format string and variable argument list.\r
677 \r
678 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
679 and BufferSize.\r
680 The Unicode string is produced by parsing the format string specified by FormatString.\r
681 Arguments are pulled from the variable argument list based on the contents of the \r
682 format string.\r
683 The length of the produced output buffer is returned.\r
684 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
685\r
686 If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().\r
687 If BufferSize is not 0 and FormatString is NULL, then ASSERT().\r
688 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
689 PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
690 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
691 contains more than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT().\r
692\r
693 @param StartOfBuffer APointer to the output buffer for the produced Null-terminated \r
694 Unicode string.\r
695 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
696 @param FormatString Null-terminated Unicode format string.\r
697 \r
698 @return Length of the produced output buffer.\r
699\r
700**/\r
878ddf1f 701UINTN\r
702EFIAPI\r
703UnicodeSPrintAsciiFormat (\r
704 OUT CHAR16 *StartOfBuffer,\r
705 IN UINTN BufferSize,\r
706 IN CONST CHAR8 *FormatString,\r
707 ...\r
708 )\r
709{\r
710 VA_LIST Marker;\r
711\r
712 VA_START (Marker, FormatString);\r
713 return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize >> 1, FormatString, Marker);\r
714}\r
715\r
3f9f540d 716/**\r
717 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
718 ASCII format string and a VA_LIST argument list.\r
719 \r
720 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
721 and BufferSize.\r
722 The ASCII string is produced by parsing the format string specified by FormatString.\r
723 Arguments are pulled from the variable argument list specified by Marker based on \r
724 the contents of the format string.\r
725 The length of the produced output buffer is returned.\r
726 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
727\r
728 If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().\r
729 If BufferSize is not 0 and FormatString is NULL, then ASSERT().\r
730 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
731 PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().\r
732 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
733 contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().\r
734\r
735 @param StartOfBuffer APointer to the output buffer for the produced Null-terminated \r
736 ASCII string.\r
737 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
738 @param FormatString Null-terminated Unicode format string.\r
739 @param Marker VA_LIST marker for the variable argument list.\r
740 \r
741 @return Length of the produced output buffer.\r
742\r
743**/\r
878ddf1f 744UINTN\r
745EFIAPI\r
746AsciiVSPrint (\r
747 OUT CHAR8 *StartOfBuffer,\r
748 IN UINTN BufferSize,\r
749 IN CONST CHAR8 *FormatString,\r
750 IN VA_LIST Marker\r
751 )\r
752{\r
753 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, 0, FormatString, Marker);\r
754}\r
755\r
3f9f540d 756/**\r
757 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
758 ASCII format string and variable argument list.\r
759 \r
760 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
761 and BufferSize.\r
762 The ASCII string is produced by parsing the format string specified by FormatString.\r
763 Arguments are pulled from the variable argument list based on the contents of the \r
764 format string.\r
765 The length of the produced output buffer is returned.\r
766 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
767\r
768 If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().\r
769 If BufferSize is not 0 and FormatString is NULL, then ASSERT().\r
770 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
771 PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().\r
772 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
773 contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().\r
774\r
775 @param StartOfBuffer APointer to the output buffer for the produced Null-terminated \r
776 ASCII string.\r
777 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
778 @param FormatString Null-terminated Unicode format string.\r
779 \r
780 @return Length of the produced output buffer.\r
781\r
782**/\r
878ddf1f 783UINTN\r
784EFIAPI\r
785AsciiSPrint (\r
786 OUT CHAR8 *StartOfBuffer,\r
787 IN UINTN BufferSize,\r
788 IN CONST CHAR8 *FormatString,\r
789 ...\r
790 )\r
791{\r
792 VA_LIST Marker;\r
793\r
794 VA_START (Marker, FormatString);\r
795 return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
796}\r
797\r
3f9f540d 798/**\r
799 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
800 ASCII format string and a VA_LIST argument list.\r
801 \r
802 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
803 and BufferSize.\r
804 The ASCII string is produced by parsing the format string specified by FormatString.\r
805 Arguments are pulled from the variable argument list specified by Marker based on \r
806 the contents of the format string.\r
807 The length of the produced output buffer is returned.\r
808 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
809\r
810 If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().\r
811 If BufferSize is not 0 and FormatString is NULL, then ASSERT().\r
812 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
813 PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().\r
814 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
815 contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().\r
816\r
817 @param StartOfBuffer APointer to the output buffer for the produced Null-terminated \r
818 ASCII string.\r
819 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
820 @param FormatString Null-terminated Unicode format string.\r
821 @param Marker VA_LIST marker for the variable argument list.\r
822 \r
823 @return Length of the produced output buffer.\r
824\r
825**/\r
878ddf1f 826UINTN\r
827EFIAPI\r
828AsciiVSPrintUnicodeFormat (\r
829 OUT CHAR8 *StartOfBuffer,\r
830 IN UINTN BufferSize,\r
831 IN CONST CHAR16 *FormatString,\r
832 IN VA_LIST Marker\r
833 )\r
834{\r
835 return BasePrintLibVSPrint (StartOfBuffer, BufferSize, FORMAT_UNICODE, (CHAR8 *)FormatString, Marker);\r
836}\r
837\r
3f9f540d 838/**\r
839 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
840 ASCII format string and variable argument list.\r
841 \r
842 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
843 and BufferSize.\r
844 The ASCII string is produced by parsing the format string specified by FormatString.\r
845 Arguments are pulled from the variable argument list based on the contents of the \r
846 format string.\r
847 The length of the produced output buffer is returned.\r
848 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
849\r
850 If BufferSize is not 0 and StartOfBuffer is NULL, then ASSERT().\r
851 If BufferSize is not 0 and FormatString is NULL, then ASSERT().\r
852 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
853 PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().\r
854 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
855 contains more than PcdMaximumUnicodeStringLength ASCII characters, then ASSERT().\r
856\r
857 @param StartOfBuffer APointer to the output buffer for the produced Null-terminated \r
858 ASCII string.\r
859 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
860 @param FormatString Null-terminated Unicode format string.\r
861 \r
862 @return Length of the produced output buffer.\r
863\r
864**/\r
878ddf1f 865UINTN\r
866EFIAPI\r
867AsciiSPrintUnicodeFormat (\r
868 OUT CHAR8 *StartOfBuffer,\r
869 IN UINTN BufferSize,\r
870 IN CONST CHAR16 *FormatString,\r
871 ...\r
872 )\r
873{\r
874 VA_LIST Marker;\r
875\r
876 VA_START (Marker, FormatString);\r
877 return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
878}\r
a3657e3e 879\r
3f9f540d 880/**\r
881 Converts a decimal value to a Null-terminated Unicode string.\r
882 \r
883 Converts the decimal number specified by Value to a Null-terminated Unicode \r
884 string specified by Buffer containing at most Width characters.\r
885 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
886 The total number of characters placed in Buffer is returned.\r
887 If the conversion contains more than Width characters, then only the first\r
888 Width characters are returned, and the total number of characters \r
889 required to perform the conversion is returned.\r
890 Additional conversion parameters are specified in Flags. \r
891 The Flags bit LEFT_JUSTIFY is always ignored.\r
892 All conversions are left justified in Buffer.\r
893 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
894 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
895 are inserted every 3rd digit starting from the right.\r
896 If Value is < 0, then the fist character in Buffer is a '-'.\r
897 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
898 then Buffer is padded with '0' characters so the combination of the optional '-' \r
899 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
900 add up to Width characters.\r
901\r
902 If Buffer is NULL, then ASSERT().\r
903 If unsupported bits are set in Flags, then ASSERT().\r
904 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
905\r
906 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
907 Unicode string.\r
908 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
909 @param Value The 64-bit signed value to convert to a string.\r
910 @param Width The maximum number of Unicode characters to place in Buffer.\r
911 \r
912 @return Total number of characters required to perform the conversion.\r
913\r
914**/\r
a3657e3e 915UINTN\r
916EFIAPI\r
917UnicodeValueToString (\r
918 IN OUT CHAR16 *Buffer,\r
919 IN UINTN Flags,\r
920 IN INT64 Value,\r
921 IN UINTN Width\r
922 )\r
923{\r
924 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2);\r
925}\r
926\r
3f9f540d 927/**\r
928 Converts a decimal value to a Null-terminated ASCII string.\r
929 \r
930 Converts the decimal number specified by Value to a Null-terminated ASCII string \r
931 specified by Buffer containing at most Width characters.\r
932 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
933 The total number of characters placed in Buffer is returned.\r
934 If the conversion contains more than Width characters, then only the first Width\r
935 characters are returned, and the total number of characters required to perform\r
936 the conversion is returned.\r
937 Additional conversion parameters are specified in Flags. \r
938 The Flags bit LEFT_JUSTIFY is always ignored.\r
939 All conversions are left justified in Buffer.\r
940 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
941 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas \r
942 are inserted every 3rd digit starting from the right.\r
943 If Value is < 0, then the fist character in Buffer is a '-'.\r
944 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, then Buffer\r
945 is padded with '0' characters so the combination of the optional '-'\r
946 sign character, '0' characters, digit characters for Value, and the \r
947 Null-terminator add up to Width characters.\r
948\r
949 If Buffer is NULL, then ASSERT().\r
950 If unsupported bits are set in Flags, then ASSERT().\r
951 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
952\r
953 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
954 ASCII string.\r
955 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
956 @param Value The 64-bit signed value to convert to a string.\r
957 @param Width The maximum number of ASCII characters to place in Buffer.\r
958 \r
959 @return Total number of characters required to perform the conversion.\r
960\r
961**/\r
a3657e3e 962UINTN\r
963EFIAPI\r
964AsciiValueToString (\r
965 IN OUT CHAR8 *Buffer,\r
966 IN UINTN Flags,\r
967 IN INT64 Value,\r
968 IN UINTN Width\r
969 )\r
970{\r
971 return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 1);\r
972}\r