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