Restore question value for question without storage after CHANGING callback return...
[mirror_edk2.git] / MdeModulePkg / Library / DxePrintLibPrint2Protocol / PrintLib.c
CommitLineData
504214c4 1/** @file\r
bee67555 2 Instance of Print Library based on gEfiPrint2ProtocolGuid.\r
a0afd019 3\r
504214c4 4 Implement the print library instance by wrap the interface \r
bee67555 5 provided in the Print2 protocol. This protocol is defined as the internal\r
504214c4
LG
6 protocol related to this implementation, not in the public spec. So, this \r
7 library instance is only for this code base.\r
8\r
6e1e5405 9Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 10This program and the accompanying materials\r
a0afd019 11are licensed and made available under the terms and conditions of the BSD License\r
12which accompanies this distribution. The full text of the license may be found at\r
13http://opensource.org/licenses/bsd-license.php\r
14\r
15THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
16WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
17\r
504214c4 18**/\r
a0afd019 19\r
60c93673 20#include <Uefi.h>\r
f405c067 21#include <Base.h>\r
0ed0c867 22#include <Protocol/Print2.h>\r
504dcb0a 23\r
24#include <Library/PrintLib.h>\r
25\r
26#include <Library/BaseLib.h>\r
bee67555 27#include <Library/DebugLib.h>\r
a0afd019 28\r
bee67555 29EFI_PRINT2_PROTOCOL *mPrint2Protocol = NULL;\r
a0afd019 30\r
ce95aa7a 31/**\r
bee67555 32 The constructor function caches the pointer to Print2 protocol.\r
33 \r
34 The constructor function locates Print2 protocol from protocol database.\r
35 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
ce95aa7a 36\r
bee67555 37 @param ImageHandle The firmware allocated handle for the EFI image.\r
38 @param SystemTable A pointer to the EFI System Table.\r
39 \r
40 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
ce95aa7a 41\r
42**/\r
2ad4dad0
LG
43EFI_STATUS\r
44EFIAPI\r
bee67555 45PrintLibConstructor (\r
46 IN EFI_HANDLE ImageHandle,\r
47 IN EFI_SYSTEM_TABLE *SystemTable\r
a0afd019 48 )\r
a0afd019 49{\r
bee67555 50 EFI_STATUS Status;\r
51\r
35289219 52 Status = SystemTable->BootServices->LocateProtocol (\r
53 &gEfiPrint2ProtocolGuid,\r
54 NULL,\r
55 (VOID**) &mPrint2Protocol\r
56 );\r
bee67555 57 ASSERT_EFI_ERROR (Status);\r
58 ASSERT (mPrint2Protocol != NULL);\r
59\r
60 return Status;\r
2ad4dad0
LG
61}\r
62\r
bee67555 63\r
504dcb0a 64/**\r
65 Worker function that converts a VA_LIST to a BASE_LIST based on a Null-terminated \r
66 format string.\r
67\r
68 @param AsciiFormat TRUE if Format is an ASCII string. FALSE if Format is a Unicode string.\r
69 @param Format Null-terminated format string.\r
70 @param VaListMarker VA_LIST style variable argument list consumed by processing Format.\r
71 @param BaseListMarker BASE_LIST style variable argument list consumed by processing Format.\r
72 @param Size The size, in bytes, of the BaseListMarker buffer.\r
73\r
74 @return The number of bytes in BaseListMarker. 0 if BaseListMarker is too small.\r
75\r
76**/\r
77BOOLEAN\r
78DxePrintLibPrint2ProtocolVaListToBaseList (\r
79 IN BOOLEAN AsciiFormat,\r
80 IN CONST CHAR8 *Format,\r
81 IN VA_LIST VaListMarker,\r
82 OUT BASE_LIST BaseListMarker,\r
83 IN UINTN Size\r
84 )\r
85{\r
86 BASE_LIST BaseListStart;\r
87 UINTN BytesPerFormatCharacter;\r
88 UINTN FormatMask;\r
89 UINTN FormatCharacter;\r
90 BOOLEAN Long;\r
91 BOOLEAN Done;\r
92\r
93 ASSERT (Format != NULL);\r
504dcb0a 94 ASSERT (BaseListMarker != NULL);\r
95\r
96 BaseListStart = BaseListMarker;\r
97\r
98 if (AsciiFormat) {\r
99 ASSERT (AsciiStrSize (Format) != 0);\r
100 BytesPerFormatCharacter = 1;\r
101 FormatMask = 0xff;\r
102 } else {\r
103 ASSERT (StrSize ((CHAR16 *) Format) != 0);\r
104 BytesPerFormatCharacter = 2;\r
105 FormatMask = 0xffff;\r
106 }\r
107\r
108 //\r
109 // Get the first character from the format string\r
110 //\r
111 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
112\r
113 while (FormatCharacter != 0) {\r
114 if (FormatCharacter == '%') {\r
115 Long = FALSE;\r
116\r
117 //\r
118 // Parse Flags and Width\r
119 //\r
120 for (Done = FALSE; !Done; ) {\r
121 //\r
122 // Get the next character from the format string\r
123 //\r
124 Format += BytesPerFormatCharacter;\r
125\r
126 //\r
127 // Get the next character from the format string\r
128 //\r
129 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
130\r
131 switch (FormatCharacter) {\r
132 case '.': \r
133 case '-': \r
134 case '+': \r
135 case ' ': \r
136 case ',': \r
137 case '0':\r
138 case '1':\r
139 case '2':\r
140 case '3':\r
141 case '4':\r
142 case '5':\r
143 case '6':\r
144 case '7':\r
145 case '8':\r
146 case '9':\r
147 break;\r
148 case 'L':\r
149 case 'l': \r
150 Long = TRUE;\r
151 break;\r
152 case '*':\r
153 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
154 break;\r
155 case '\0':\r
156 //\r
157 // Make no output if Format string terminates unexpectedly when\r
158 // looking up for flag, width, precision and type. \r
159 //\r
160 Format -= BytesPerFormatCharacter;\r
161 //\r
162 // break skipped on purpose.\r
163 //\r
164 default:\r
165 Done = TRUE;\r
166 break;\r
167 }\r
168 } \r
169 \r
170 //\r
171 // Handle each argument type\r
172 //\r
173 switch (FormatCharacter) {\r
174 case 'p':\r
175 if (sizeof (VOID *) > 4) {\r
176 Long = TRUE;\r
177 }\r
178 case 'X':\r
179 case 'x':\r
180 case 'd':\r
181 if (Long) {\r
182 BASE_ARG (BaseListMarker, INT64) = VA_ARG (VaListMarker, INT64);\r
183 } else {\r
184 BASE_ARG (BaseListMarker, int) = VA_ARG (VaListMarker, int);\r
185 }\r
186 break;\r
187 case 's':\r
188 case 'S':\r
189 case 'a':\r
190 case 'g':\r
191 case 't':\r
192 BASE_ARG (BaseListMarker, VOID *) = VA_ARG (VaListMarker, VOID *);\r
193 break;\r
194 case 'c':\r
195 BASE_ARG (BaseListMarker, UINTN) = VA_ARG (VaListMarker, UINTN);\r
196 break;\r
197 case 'r':\r
198 BASE_ARG (BaseListMarker, RETURN_STATUS) = VA_ARG (VaListMarker, RETURN_STATUS);\r
199 break;\r
200 }\r
201 }\r
202\r
203 //\r
204 // If BASE_LIST is larger than Size, then return FALSE\r
205 //\r
206 if ((UINTN)((UINT8 *)BaseListMarker - (UINT8 *)BaseListStart) > Size) {\r
207 return FALSE;\r
208 }\r
209\r
210 //\r
211 // Get the next character from the format string\r
212 //\r
213 Format += BytesPerFormatCharacter;\r
214\r
215 //\r
216 // Get the next character from the format string\r
217 //\r
218 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
219 }\r
220 return TRUE;\r
221}\r
222\r
2ad4dad0
LG
223/**\r
224 Produces a Null-terminated Unicode string in an output buffer based on \r
225 a Null-terminated Unicode format string and a VA_LIST argument list\r
226 \r
227 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
228 and BufferSize. \r
229 The Unicode string is produced by parsing the format string specified by FormatString. \r
230 Arguments are pulled from the variable argument list specified by Marker based on the \r
231 contents of the format string. \r
232 The number of Unicode characters in the produced output buffer is returned not including\r
233 the Null-terminator.\r
234 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
235\r
236 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
237 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
238 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
239 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
240 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
241 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
242 ASSERT().\r
243 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
244 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
245 Null-terminator, then ASSERT().\r
246\r
247 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
248 Unicode string.\r
249 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
250 @param FormatString Null-terminated Unicode format string.\r
251 @param Marker VA_LIST marker for the variable argument list.\r
252 \r
253 @return The number of Unicode characters in the produced output buffer not including the\r
254 Null-terminator.\r
255\r
256**/\r
257UINTN\r
258EFIAPI\r
259UnicodeVSPrint (\r
260 OUT CHAR16 *StartOfBuffer,\r
261 IN UINTN BufferSize,\r
262 IN CONST CHAR16 *FormatString,\r
263 IN VA_LIST Marker\r
264 )\r
265{\r
97f77815 266 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
504dcb0a 267\r
268 DxePrintLibPrint2ProtocolVaListToBaseList (\r
269 FALSE, \r
270 (CHAR8 *)FormatString, \r
271 Marker, \r
272 (BASE_LIST)BaseListMarker, \r
273 sizeof (BaseListMarker) - 8\r
274 );\r
275\r
276 return UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
277}\r
278\r
279/**\r
280 Produces a Null-terminated Unicode string in an output buffer based on \r
281 a Null-terminated Unicode format string and a BASE_LIST argument list\r
282 \r
283 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
284 and BufferSize. \r
285 The Unicode string is produced by parsing the format string specified by FormatString. \r
286 Arguments are pulled from the variable argument list specified by Marker based on the \r
287 contents of the format string. \r
288 The number of Unicode characters in the produced output buffer is returned not including\r
289 the Null-terminator.\r
290 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
291\r
292 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
293 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
294 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
295 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
296 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
297 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
298 ASSERT().\r
299 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
300 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
301 Null-terminator, then ASSERT().\r
302\r
303 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
304 Unicode string.\r
305 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
306 @param FormatString Null-terminated Unicode format string.\r
307 @param Marker BASE_LIST marker for the variable argument list.\r
308 \r
309 @return The number of Unicode characters in the produced output buffer not including the\r
310 Null-terminator.\r
311\r
312**/\r
313UINTN\r
314EFIAPI\r
315UnicodeBSPrint (\r
316 OUT CHAR16 *StartOfBuffer,\r
317 IN UINTN BufferSize,\r
318 IN CONST CHAR16 *FormatString,\r
319 IN BASE_LIST Marker\r
320 )\r
321{\r
322 return mPrint2Protocol->UnicodeBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
a0afd019 323}\r
324\r
2ad4dad0
LG
325/**\r
326 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
327 Unicode format string and variable argument list.\r
328 \r
329 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
330 and BufferSize.\r
331 The Unicode string is produced by parsing the format string specified by FormatString.\r
332 Arguments are pulled from the variable argument list based on the contents of the format string.\r
333 The number of Unicode characters in the produced output buffer is returned not including\r
334 the Null-terminator.\r
335 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
336\r
337 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
338 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
339 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
340 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
341 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
342 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
343 ASSERT().\r
344 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
345 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
346 Null-terminator, then ASSERT().\r
347\r
348 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
349 Unicode string.\r
350 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
351 @param FormatString Null-terminated Unicode format string.\r
71898234 352 @param ... Variable argument list whose contents are accessed based on the \r
353 format string specified by FormatString.\r
ce95aa7a 354\r
2ad4dad0
LG
355 @return The number of Unicode characters in the produced output buffer not including the\r
356 Null-terminator.\r
357\r
358**/\r
a0afd019 359UINTN\r
2ad4dad0 360EFIAPI\r
a0afd019 361UnicodeSPrint (\r
362 OUT CHAR16 *StartOfBuffer,\r
363 IN UINTN BufferSize,\r
2ad4dad0 364 IN CONST CHAR16 *FormatString,\r
a0afd019 365 ...\r
366 )\r
a0afd019 367{\r
2ad4dad0 368 VA_LIST Marker;\r
3bbe68a3 369 UINTN NumberOfPrinted;\r
a0afd019 370\r
371 VA_START (Marker, FormatString);\r
3bbe68a3 372 NumberOfPrinted = UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
373 VA_END (Marker);\r
374 return NumberOfPrinted;\r
a0afd019 375}\r
376\r
2ad4dad0
LG
377/**\r
378 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
379 ASCII format string and a VA_LIST argument list\r
380 \r
381 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
382 and BufferSize.\r
383 The Unicode string is produced by parsing the format string specified by FormatString.\r
384 Arguments are pulled from the variable argument list specified by Marker based on the \r
385 contents of the format string.\r
386 The number of Unicode characters in the produced output buffer is returned not including\r
387 the Null-terminator.\r
388 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
389\r
390 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
391 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
392 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
393 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
394 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
395 ASSERT().\r
396 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
397 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
398 Null-terminator, then ASSERT().\r
399\r
400 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
401 Unicode string.\r
402 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
403 @param FormatString Null-terminated Unicode format string.\r
404 @param Marker VA_LIST marker for the variable argument list.\r
405 \r
406 @return The number of Unicode characters in the produced output buffer not including the\r
407 Null-terminator.\r
408\r
409**/\r
a0afd019 410UINTN\r
2ad4dad0
LG
411EFIAPI\r
412UnicodeVSPrintAsciiFormat (\r
413 OUT CHAR16 *StartOfBuffer,\r
414 IN UINTN BufferSize,\r
415 IN CONST CHAR8 *FormatString,\r
416 IN VA_LIST Marker\r
a0afd019 417 )\r
2ad4dad0 418{\r
97f77815 419 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
504dcb0a 420\r
421 DxePrintLibPrint2ProtocolVaListToBaseList (\r
422 TRUE, \r
423 FormatString, \r
424 Marker, \r
425 (BASE_LIST)BaseListMarker, \r
426 sizeof (BaseListMarker) - 8\r
427 );\r
428\r
429 return UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
430}\r
431\r
432/**\r
433 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
434 ASCII format string and a BASE_LIST argument list\r
435 \r
436 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
437 and BufferSize.\r
438 The Unicode string is produced by parsing the format string specified by FormatString.\r
439 Arguments are pulled from the variable argument list specified by Marker based on the \r
440 contents of the format string.\r
441 The number of Unicode characters in the produced output buffer is returned not including\r
442 the Null-terminator.\r
443 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
444\r
445 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
446 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
447 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
448 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
449 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
450 ASSERT().\r
451 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
452 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
453 Null-terminator, then ASSERT().\r
454\r
455 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
456 Unicode string.\r
457 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
458 @param FormatString Null-terminated Unicode format string.\r
459 @param Marker BASE_LIST marker for the variable argument list.\r
460 \r
461 @return The number of Unicode characters in the produced output buffer not including the\r
462 Null-terminator.\r
463\r
464**/\r
465UINTN\r
466EFIAPI\r
467UnicodeBSPrintAsciiFormat (\r
468 OUT CHAR16 *StartOfBuffer,\r
469 IN UINTN BufferSize,\r
470 IN CONST CHAR8 *FormatString,\r
471 IN BASE_LIST Marker\r
472 )\r
473{\r
474 return mPrint2Protocol->UnicodeBSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
2ad4dad0 475}\r
a0afd019 476\r
2ad4dad0
LG
477/**\r
478 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
479 ASCII format string and variable argument list.\r
480 \r
481 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
482 and BufferSize.\r
483 The Unicode string is produced by parsing the format string specified by FormatString.\r
484 Arguments are pulled from the variable argument list based on the contents of the \r
485 format string.\r
486 The number of Unicode characters in the produced output buffer is returned not including\r
487 the Null-terminator.\r
488 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
489\r
490 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
491 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
492 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
493 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
494 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
495 ASSERT().\r
496 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
497 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
498 Null-terminator, then ASSERT().\r
499\r
500 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
501 Unicode string.\r
502 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
503 @param FormatString Null-terminated Unicode format string.\r
71898234 504 @param ... Variable argument list whose contents are accessed based on the \r
505 format string specified by FormatString.\r
2ad4dad0
LG
506 \r
507 @return The number of Unicode characters in the produced output buffer not including the\r
508 Null-terminator.\r
509\r
510**/\r
511UINTN\r
512EFIAPI\r
513UnicodeSPrintAsciiFormat (\r
514 OUT CHAR16 *StartOfBuffer,\r
515 IN UINTN BufferSize,\r
516 IN CONST CHAR8 *FormatString,\r
517 ...\r
518 )\r
519{\r
520 VA_LIST Marker;\r
3bbe68a3 521 UINTN NumberOfPrinted;\r
a0afd019 522\r
2ad4dad0 523 VA_START (Marker, FormatString);\r
3bbe68a3 524 NumberOfPrinted = UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
525 VA_END (Marker);\r
526 return NumberOfPrinted;\r
2ad4dad0 527}\r
a0afd019 528\r
2ad4dad0
LG
529/**\r
530 Converts a decimal value to a Null-terminated Unicode string.\r
531 \r
532 Converts the decimal number specified by Value to a Null-terminated Unicode \r
533 string specified by Buffer containing at most Width characters. No padding of spaces \r
534 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
535 The number of Unicode characters in Buffer is returned not including the Null-terminator.\r
536 If the conversion contains more than Width characters, then only the first\r
537 Width characters are returned, and the total number of characters \r
538 required to perform the conversion is returned.\r
539 Additional conversion parameters are specified in Flags. \r
540 \r
541 The Flags bit LEFT_JUSTIFY is always ignored.\r
542 All conversions are left justified in Buffer.\r
543 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
544 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
545 are inserted every 3rd digit starting from the right.\r
df8d0595 546 If RADIX_HEX is set in Flags, then the output buffer will be \r
2ad4dad0 547 formatted in hexadecimal format.\r
df8d0595 548 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.\r
2ad4dad0
LG
549 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
550 then Buffer is padded with '0' characters so the combination of the optional '-' \r
551 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
552 add up to Width characters.\r
df8d0595 553 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
2ad4dad0
LG
554 If Buffer is NULL, then ASSERT().\r
555 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
556 If unsupported bits are set in Flags, then ASSERT().\r
df8d0595 557 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
2ad4dad0
LG
558 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
559\r
560 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
561 Unicode string.\r
562 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
563 @param Value The 64-bit signed value to convert to a string.\r
564 @param Width The maximum number of Unicode characters to place in Buffer, not including\r
565 the Null-terminator.\r
566 \r
567 @return The number of Unicode characters in Buffer not including the Null-terminator.\r
568\r
569**/\r
570UINTN\r
571EFIAPI\r
572UnicodeValueToString (\r
573 IN OUT CHAR16 *Buffer,\r
574 IN UINTN Flags,\r
575 IN INT64 Value,\r
576 IN UINTN Width\r
577 )\r
578{\r
bee67555 579 return mPrint2Protocol->UnicodeValueToString (Buffer, Flags, Value, Width);\r
2ad4dad0 580}\r
a0afd019 581\r
2ad4dad0
LG
582/**\r
583 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
584 ASCII format string and a VA_LIST argument list.\r
585 \r
586 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
587 and BufferSize.\r
588 The ASCII string is produced by parsing the format string specified by FormatString.\r
589 Arguments are pulled from the variable argument list specified by Marker based on \r
590 the contents of the format string.\r
591 The number of ASCII characters in the produced output buffer is returned not including\r
592 the Null-terminator.\r
593 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
594\r
595 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
596 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
597 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
598 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
599 ASSERT().\r
600 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
601 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
602 Null-terminator, then ASSERT().\r
603\r
604 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
605 ASCII string.\r
606 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
607 @param FormatString Null-terminated Unicode format string.\r
608 @param Marker VA_LIST marker for the variable argument list.\r
609 \r
610 @return The number of ASCII characters in the produced output buffer not including the\r
611 Null-terminator.\r
612\r
613**/\r
614UINTN\r
615EFIAPI\r
616AsciiVSPrint (\r
617 OUT CHAR8 *StartOfBuffer,\r
618 IN UINTN BufferSize,\r
619 IN CONST CHAR8 *FormatString,\r
620 IN VA_LIST Marker\r
621 )\r
a0afd019 622{\r
97f77815 623 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
504dcb0a 624\r
625 DxePrintLibPrint2ProtocolVaListToBaseList (\r
626 TRUE, \r
627 FormatString, \r
628 Marker, \r
629 (BASE_LIST)BaseListMarker, \r
630 sizeof (BaseListMarker) - 8\r
631 );\r
632\r
633 return AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
634}\r
635\r
636/**\r
637 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
638 ASCII format string and a BASE_LIST argument list.\r
639 \r
640 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
641 and BufferSize.\r
642 The ASCII string is produced by parsing the format string specified by FormatString.\r
643 Arguments are pulled from the variable argument list specified by Marker based on \r
644 the contents of the format string.\r
645 The number of ASCII characters in the produced output buffer is returned not including\r
646 the Null-terminator.\r
647 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
648\r
649 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
650 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
651 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
652 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
653 ASSERT().\r
654 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
655 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
656 Null-terminator, then ASSERT().\r
657\r
658 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
659 ASCII string.\r
660 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
661 @param FormatString Null-terminated Unicode format string.\r
662 @param Marker BASE_LIST marker for the variable argument list.\r
663 \r
664 @return The number of ASCII characters in the produced output buffer not including the\r
665 Null-terminator.\r
666\r
667**/\r
668UINTN\r
669EFIAPI\r
670AsciiBSPrint (\r
671 OUT CHAR8 *StartOfBuffer,\r
672 IN UINTN BufferSize,\r
673 IN CONST CHAR8 *FormatString,\r
674 IN BASE_LIST Marker\r
675 )\r
676{\r
677 return mPrint2Protocol->AsciiBSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
a0afd019 678}\r
679\r
2ad4dad0
LG
680/**\r
681 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
682 ASCII format string and variable argument list.\r
683 \r
684 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
685 and BufferSize.\r
686 The ASCII string is produced by parsing the format string specified by FormatString.\r
687 Arguments are pulled from the variable argument list based on the contents of the \r
688 format string.\r
689 The number of ASCII characters in the produced output buffer is returned not including\r
690 the Null-terminator.\r
691 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
692\r
693 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
694 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
695 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
696 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
697 ASSERT().\r
698 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
699 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
700 Null-terminator, then ASSERT().\r
701\r
702 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
703 ASCII string.\r
704 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
705 @param FormatString Null-terminated Unicode format string.\r
71898234 706 @param ... Variable argument list whose contents are accessed based on the \r
707 format string specified by FormatString.\r
ce95aa7a 708\r
2ad4dad0
LG
709 @return The number of ASCII characters in the produced output buffer not including the\r
710 Null-terminator.\r
711\r
712**/\r
a0afd019 713UINTN\r
2ad4dad0 714EFIAPI\r
a0afd019 715AsciiSPrint (\r
716 OUT CHAR8 *StartOfBuffer,\r
717 IN UINTN BufferSize,\r
2ad4dad0 718 IN CONST CHAR8 *FormatString,\r
a0afd019 719 ...\r
720 )\r
2ad4dad0
LG
721{\r
722 VA_LIST Marker;\r
3bbe68a3 723 UINTN NumberOfPrinted;\r
2ad4dad0
LG
724\r
725 VA_START (Marker, FormatString);\r
3bbe68a3 726 NumberOfPrinted = AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker);\r
727 VA_END (Marker);\r
728 return NumberOfPrinted;\r
2ad4dad0 729}\r
a0afd019 730\r
2ad4dad0
LG
731/**\r
732 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
733 ASCII format string and a VA_LIST argument list.\r
734 \r
735 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
736 and BufferSize.\r
737 The ASCII string is produced by parsing the format string specified by FormatString.\r
738 Arguments are pulled from the variable argument list specified by Marker based on \r
739 the contents of the format string.\r
740 The number of ASCII characters in the produced output buffer is returned not including\r
741 the Null-terminator.\r
742 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
743\r
744 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
745 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
746 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
747 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
748 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
749 ASSERT().\r
750 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
751 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
752 Null-terminator, then ASSERT().\r
753\r
754 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
755 ASCII string.\r
756 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
757 @param FormatString Null-terminated Unicode format string.\r
758 @param Marker VA_LIST marker for the variable argument list.\r
759 \r
760 @return The number of ASCII characters in the produced output buffer not including the\r
761 Null-terminator.\r
762\r
763**/\r
764UINTN\r
765EFIAPI\r
766AsciiVSPrintUnicodeFormat (\r
767 OUT CHAR8 *StartOfBuffer,\r
768 IN UINTN BufferSize,\r
769 IN CONST CHAR16 *FormatString,\r
770 IN VA_LIST Marker\r
771 )\r
a0afd019 772{\r
97f77815 773 UINT64 BaseListMarker[256 / sizeof (UINT64)];\r
504dcb0a 774\r
775 DxePrintLibPrint2ProtocolVaListToBaseList (\r
776 FALSE, \r
777 (CHAR8 *)FormatString, \r
778 Marker, \r
779 (BASE_LIST)BaseListMarker, \r
780 sizeof (BaseListMarker) - 8\r
781 );\r
782\r
783 return AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, (BASE_LIST)BaseListMarker);\r
784}\r
785\r
786/**\r
787 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
788 ASCII format string and a BASE_LIST argument list.\r
789 \r
790 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
791 and BufferSize.\r
792 The ASCII string is produced by parsing the format string specified by FormatString.\r
793 Arguments are pulled from the variable argument list specified by Marker based on \r
794 the contents of the format string.\r
795 The number of ASCII characters in the produced output buffer is returned not including\r
796 the Null-terminator.\r
797 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
798\r
799 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
800 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
801 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
802 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
803 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
804 ASSERT().\r
805 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
806 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
807 Null-terminator, then ASSERT().\r
808\r
809 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
810 ASCII string.\r
811 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
812 @param FormatString Null-terminated Unicode format string.\r
813 @param Marker BASE_LIST marker for the variable argument list.\r
814 \r
815 @return The number of ASCII characters in the produced output buffer not including the\r
816 Null-terminator.\r
817\r
818**/\r
819UINTN\r
820EFIAPI\r
821AsciiBSPrintUnicodeFormat (\r
822 OUT CHAR8 *StartOfBuffer,\r
823 IN UINTN BufferSize,\r
824 IN CONST CHAR16 *FormatString,\r
825 IN BASE_LIST Marker\r
826 )\r
827{\r
828 return mPrint2Protocol->AsciiBSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
2ad4dad0
LG
829}\r
830\r
831/**\r
832 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
833 ASCII format string and variable argument list.\r
834 \r
835 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
836 and BufferSize.\r
837 The ASCII string is produced by parsing the format string specified by FormatString.\r
838 Arguments are pulled from the variable argument list based on the contents of the \r
839 format string.\r
840 The number of ASCII characters in the produced output buffer is returned not including\r
841 the Null-terminator.\r
842 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
843\r
844 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
845 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
846 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
847 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
848 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
849 ASSERT().\r
850 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
851 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
852 Null-terminator, then ASSERT().\r
853\r
854 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
855 ASCII string.\r
856 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
857 @param FormatString Null-terminated Unicode format string.\r
71898234 858 @param ... Variable argument list whose contents are accessed based on the \r
859 format string specified by FormatString.\r
ce95aa7a 860\r
2ad4dad0
LG
861 @return The number of ASCII characters in the produced output buffer not including the\r
862 Null-terminator.\r
863\r
864**/\r
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
3bbe68a3 875 UINTN NumberOfPrinted;\r
a0afd019 876\r
877 VA_START (Marker, FormatString);\r
3bbe68a3 878 NumberOfPrinted = AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker);\r
879 VA_END (Marker);\r
880 return NumberOfPrinted;\r
2ad4dad0
LG
881}\r
882\r
883\r
884/**\r
885 Converts a decimal value to a Null-terminated ASCII string.\r
886 \r
887 Converts the decimal number specified by Value to a Null-terminated ASCII string \r
888 specified by Buffer containing at most Width characters. No padding of spaces \r
889 is ever performed.\r
890 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
891 The number of ASCII characters in Buffer is returned not including the Null-terminator.\r
892 If the conversion contains more than Width characters, then only the first Width\r
893 characters are returned, and the total number of characters required to perform\r
894 the conversion is returned.\r
895 Additional conversion parameters are specified in Flags. \r
896 The Flags bit LEFT_JUSTIFY is always ignored.\r
897 All conversions are left justified in Buffer.\r
898 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
899 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
900 are inserted every 3rd digit starting from the right.\r
df8d0595 901 If RADIX_HEX is set in Flags, then the output buffer will be \r
2ad4dad0 902 formatted in hexadecimal format.\r
df8d0595 903 If Value is < 0 and RADIX_HEX is not set in Flags, then the fist character in Buffer is a '-'.\r
2ad4dad0
LG
904 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
905 then Buffer is padded with '0' characters so the combination of the optional '-' \r
906 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
907 add up to Width characters.\r
908 \r
909 If Buffer is NULL, then ASSERT().\r
910 If unsupported bits are set in Flags, then ASSERT().\r
df8d0595 911 If both COMMA_TYPE and RADIX_HEX are set in Flags, then ASSERT().\r
2ad4dad0
LG
912 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
913\r
914 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
915 ASCII string.\r
916 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
917 @param Value The 64-bit signed value to convert to a string.\r
918 @param Width The maximum number of ASCII characters to place in Buffer, not including\r
919 the Null-terminator.\r
920 \r
921 @return The number of ASCII characters in Buffer not including the Null-terminator.\r
922\r
923**/\r
924UINTN\r
925EFIAPI\r
926AsciiValueToString (\r
ea99d5d1 927 OUT CHAR8 *Buffer,\r
928 IN UINTN Flags,\r
929 IN INT64 Value,\r
930 IN UINTN Width\r
2ad4dad0
LG
931 )\r
932{\r
bee67555 933 return mPrint2Protocol->AsciiValueToString (Buffer, Flags, Value, Width);\r
a0afd019 934}\r
f405c067 935\r
936#define PREFIX_SIGN BIT1\r
937#define PREFIX_BLANK BIT2\r
938#define LONG_TYPE BIT4\r
939#define OUTPUT_UNICODE BIT6\r
940#define FORMAT_UNICODE BIT8\r
941#define PAD_TO_WIDTH BIT9\r
942#define ARGUMENT_UNICODE BIT10\r
943#define PRECISION BIT11\r
944#define ARGUMENT_REVERSED BIT12\r
945#define COUNT_ONLY_NO_PRINT BIT13\r
946\r
947//\r
948// Record date and time information\r
949//\r
950typedef struct {\r
951 UINT16 Year;\r
952 UINT8 Month;\r
953 UINT8 Day;\r
954 UINT8 Hour;\r
955 UINT8 Minute;\r
956 UINT8 Second;\r
957 UINT8 Pad1;\r
958 UINT32 Nanosecond;\r
959 INT16 TimeZone;\r
960 UINT8 Daylight;\r
961 UINT8 Pad2;\r
962} TIME;\r
963\r
964GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 mHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
965\r
966/**\r
967 Internal function that convert a number to a string in Buffer.\r
968\r
969 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.\r
970\r
971 @param Buffer Location to place the ASCII string of Value.\r
972 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.\r
973 @param Radix Radix of the value\r
974\r
975 @return A pointer to the end of buffer filled with ASCII string.\r
976\r
977**/\r
978CHAR8 *\r
979InternalPrintLibValueToString (\r
980 IN OUT CHAR8 *Buffer, \r
981 IN INT64 Value, \r
982 IN UINTN Radix\r
983 )\r
984{\r
985 UINT32 Remainder;\r
986\r
987 //\r
988 // Loop to convert one digit at a time in reverse order\r
989 //\r
990 *Buffer = 0;\r
991 do {\r
992 Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder);\r
993 *(++Buffer) = mHexStr[Remainder];\r
994 } while (Value != 0);\r
995\r
996 //\r
997 // Return pointer of the end of filled buffer.\r
998 //\r
999 return Buffer;\r
1000}\r
1001\r
1002/**\r
1003 Worker function that produces a Null-terminated string in an output buffer \r
1004 based on a Null-terminated format string and a VA_LIST argument list.\r
1005\r
1006 VSPrint function to process format and place the results in Buffer. Since a \r
1007 VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
1008 this is the main print working routine.\r
1009\r
1010 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.\r
1011\r
1012 @param[out] Buffer The character buffer to print the results of the \r
1013 parsing of Format into.\r
1014 @param[in] BufferSize The maximum number of characters to put into \r
1015 buffer.\r
1016 @param[in] Flags Initial flags value.\r
1017 Can only have FORMAT_UNICODE, OUTPUT_UNICODE, \r
1018 and COUNT_ONLY_NO_PRINT set.\r
1019 @param[in] Format A Null-terminated format string.\r
1020 @param[in] VaListMarker VA_LIST style variable argument list consumed by\r
1021 processing Format.\r
1022 @param[in] BaseListMarker BASE_LIST style variable argument list consumed\r
1023 by processing Format.\r
1024\r
1025 @return The number of characters printed not including the Null-terminator.\r
1026 If COUNT_ONLY_NO_PRINT was set returns the same, but without any\r
1027 modification to Buffer.\r
1028\r
1029**/\r
1030UINTN\r
1031InternalPrintLibSPrintMarker (\r
1032 OUT CHAR8 *Buffer,\r
1033 IN UINTN BufferSize,\r
1034 IN UINTN Flags,\r
1035 IN CONST CHAR8 *Format,\r
1036 IN VA_LIST VaListMarker, OPTIONAL\r
1037 IN BASE_LIST BaseListMarker OPTIONAL\r
1038 );\r
1039\r
1040/**\r
1041 Worker function that produces a Null-terminated string in an output buffer \r
1042 based on a Null-terminated format string and variable argument list.\r
1043\r
1044 VSPrint function to process format and place the results in Buffer. Since a \r
1045 VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
1046 this is the main print working routine\r
1047\r
1048 @param StartOfBuffer The character buffer to print the results of the parsing\r
1049 of Format into.\r
1050 @param BufferSize The maximum number of characters to put into buffer.\r
1051 Zero means no limit.\r
1052 @param Flags Initial flags value.\r
1053 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set\r
1054 @param FormatString A Null-terminated format string.\r
1055 @param ... The variable argument list.\r
1056\r
1057 @return The number of characters printed.\r
1058\r
1059**/\r
1060UINTN\r
1061EFIAPI\r
1062InternalPrintLibSPrint (\r
1063 OUT CHAR8 *StartOfBuffer,\r
1064 IN UINTN BufferSize,\r
1065 IN UINTN Flags,\r
1066 IN CONST CHAR8 *FormatString,\r
1067 ...\r
1068 )\r
1069{\r
1070 VA_LIST Marker;\r
3bbe68a3 1071 UINTN NumberOfPrinted;\r
f405c067 1072\r
1073 VA_START (Marker, FormatString);\r
3bbe68a3 1074 NumberOfPrinted = InternalPrintLibSPrintMarker (StartOfBuffer, BufferSize, Flags, FormatString, Marker, NULL);\r
1075 VA_END (Marker);\r
1076 return NumberOfPrinted;\r
f405c067 1077}\r
1078\r
1079#define WARNING_STATUS_NUMBER 4\r
1080#define ERROR_STATUS_NUMBER 24\r
1081\r
1082GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *mStatusString[] = {\r
1083 "Success", // RETURN_SUCCESS = 0\r
1084 "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1\r
1085 "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2\r
1086 "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3\r
1087 "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4\r
1088 "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT\r
1089 "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT\r
1090 "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT\r
1091 "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT\r
1092 "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT\r
1093 "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT\r
1094 "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT\r
1095 "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT\r
1096 "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT\r
1097 "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT\r
1098 "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT\r
1099 "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT\r
1100 "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT\r
1101 "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT\r
1102 "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT\r
1103 "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT\r
1104 "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT\r
1105 "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT\r
1106 "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT\r
1107 "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT\r
1108 "Aborted", // RETURN_ABORTED = 21 | MAX_BIT\r
1109 "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT\r
1110 "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT\r
1111 "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT\r
1112};\r
1113\r
1114/**\r
1115 Worker function that produces a Null-terminated string in an output buffer \r
1116 based on a Null-terminated format string and a VA_LIST argument list.\r
1117\r
1118 VSPrint function to process format and place the results in Buffer. Since a \r
1119 VA_LIST is used this routine allows the nesting of Vararg routines. Thus \r
1120 this is the main print working routine.\r
1121\r
1122 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.\r
1123\r
1124 @param[out] Buffer The character buffer to print the results of the \r
1125 parsing of Format into.\r
1126 @param[in] BufferSize The maximum number of characters to put into \r
1127 buffer.\r
1128 @param[in] Flags Initial flags value.\r
1129 Can only have FORMAT_UNICODE, OUTPUT_UNICODE, \r
1130 and COUNT_ONLY_NO_PRINT set.\r
1131 @param[in] Format A Null-terminated format string.\r
1132 @param[in] VaListMarker VA_LIST style variable argument list consumed by\r
1133 processing Format.\r
1134 @param[in] BaseListMarker BASE_LIST style variable argument list consumed\r
1135 by processing Format.\r
1136\r
1137 @return The number of characters printed not including the Null-terminator.\r
1138 If COUNT_ONLY_NO_PRINT was set returns the same, but without any\r
1139 modification to Buffer.\r
1140\r
1141**/\r
1142UINTN\r
1143InternalPrintLibSPrintMarker (\r
1144 OUT CHAR8 *Buffer,\r
1145 IN UINTN BufferSize,\r
1146 IN UINTN Flags,\r
1147 IN CONST CHAR8 *Format,\r
1148 IN VA_LIST VaListMarker, OPTIONAL\r
1149 IN BASE_LIST BaseListMarker OPTIONAL\r
1150 )\r
1151{\r
f405c067 1152 CHAR8 *EndBuffer;\r
1153 CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS];\r
1154 UINT32 BytesPerOutputCharacter;\r
1155 UINTN BytesPerFormatCharacter;\r
1156 UINTN FormatMask;\r
1157 UINTN FormatCharacter;\r
1158 UINTN Width;\r
1159 UINTN Precision;\r
1160 INT64 Value;\r
1161 CONST CHAR8 *ArgumentString;\r
1162 UINTN Character;\r
1163 GUID *TmpGuid;\r
1164 TIME *TmpTime;\r
1165 UINTN Count;\r
1166 UINTN ArgumentMask;\r
1167 INTN BytesPerArgumentCharacter;\r
1168 UINTN ArgumentCharacter;\r
1169 BOOLEAN Done;\r
1170 UINTN Index;\r
1171 CHAR8 Prefix;\r
1172 BOOLEAN ZeroPad;\r
1173 BOOLEAN Comma;\r
1174 UINTN Digits;\r
1175 UINTN Radix;\r
1176 RETURN_STATUS Status;\r
1177 UINT32 GuidData1;\r
1178 UINT16 GuidData2;\r
1179 UINT16 GuidData3;\r
be5ec8c5 1180 UINTN LengthToReturn;\r
f405c067 1181\r
1182 //\r
1183 // If you change this code be sure to match the 2 versions of this function.\r
1184 // Nearly identical logic is found in the BasePrintLib and \r
1185 // DxePrintLibPrint2Protocol (both PrintLib instances).\r
1186 //\r
1187\r
1188 ASSERT(Flags & COUNT_ONLY_NO_PRINT);\r
1189\r
ad9aa87b 1190 if ((Flags & OUTPUT_UNICODE) != 0) {\r
f405c067 1191 BytesPerOutputCharacter = 2;\r
1192 } else {\r
1193 BytesPerOutputCharacter = 1;\r
1194 }\r
1195\r
1196 LengthToReturn = 0;\r
1197\r
1198 //\r
1199 // Reserve space for the Null terminator.\r
1200 //\r
1201 BufferSize--;\r
f405c067 1202\r
1203 //\r
1204 // Set the tag for the end of the input Buffer.\r
1205 //\r
1206 EndBuffer = Buffer + BufferSize * BytesPerOutputCharacter;\r
1207\r
1208 if ((Flags & FORMAT_UNICODE) != 0) {\r
1209 //\r
1210 // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength\r
1211 // Unicode characters if PcdMaximumUnicodeStringLength is not zero. \r
1212 //\r
1213 ASSERT (StrSize ((CHAR16 *) Format) != 0);\r
1214 BytesPerFormatCharacter = 2;\r
1215 FormatMask = 0xffff;\r
1216 } else {\r
1217 //\r
1218 // Make sure format string cannot contain more than PcdMaximumAsciiStringLength\r
1219 // Ascii characters if PcdMaximumAsciiStringLength is not zero. \r
1220 //\r
1221 ASSERT (AsciiStrSize (Format) != 0);\r
1222 BytesPerFormatCharacter = 1;\r
1223 FormatMask = 0xff;\r
1224 }\r
1225\r
1226 //\r
1227 // Get the first character from the format string\r
1228 //\r
1229 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1230\r
1231 //\r
1232 // Loop until the end of the format string is reached or the output buffer is full\r
1233 //\r
1234 while (FormatCharacter != 0 && Buffer < EndBuffer) {\r
1235 //\r
1236 // Clear all the flag bits except those that may have been passed in\r
1237 //\r
6e1e5405 1238 Flags &= (UINTN)(OUTPUT_UNICODE | FORMAT_UNICODE | COUNT_ONLY_NO_PRINT);\r
f405c067 1239\r
1240 //\r
1241 // Set the default width to zero, and the default precision to 1\r
1242 //\r
1243 Width = 0;\r
1244 Precision = 1;\r
1245 Prefix = 0;\r
1246 Comma = FALSE;\r
1247 ZeroPad = FALSE;\r
1248 Count = 0;\r
1249 Digits = 0;\r
1250\r
1251 switch (FormatCharacter) {\r
1252 case '%':\r
1253 //\r
1254 // Parse Flags and Width\r
1255 //\r
1256 for (Done = FALSE; !Done; ) {\r
1257 Format += BytesPerFormatCharacter;\r
1258 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1259 switch (FormatCharacter) {\r
1260 case '.': \r
1261 Flags |= PRECISION; \r
1262 break;\r
1263 case '-': \r
1264 Flags |= LEFT_JUSTIFY; \r
1265 break;\r
1266 case '+': \r
1267 Flags |= PREFIX_SIGN; \r
1268 break;\r
1269 case ' ': \r
1270 Flags |= PREFIX_BLANK; \r
1271 break;\r
1272 case ',': \r
1273 Flags |= COMMA_TYPE; \r
1274 break;\r
1275 case 'L':\r
1276 case 'l': \r
1277 Flags |= LONG_TYPE; \r
1278 break;\r
1279 case '*':\r
1280 if ((Flags & PRECISION) == 0) {\r
1281 Flags |= PAD_TO_WIDTH;\r
1282 if (BaseListMarker == NULL) {\r
1283 Width = VA_ARG (VaListMarker, UINTN);\r
1284 } else {\r
1285 Width = BASE_ARG (BaseListMarker, UINTN);\r
1286 }\r
1287 } else {\r
1288 if (BaseListMarker == NULL) {\r
1289 Precision = VA_ARG (VaListMarker, UINTN);\r
1290 } else {\r
1291 Precision = BASE_ARG (BaseListMarker, UINTN);\r
1292 }\r
1293 }\r
1294 break;\r
1295 case '0':\r
1296 if ((Flags & PRECISION) == 0) {\r
1297 Flags |= PREFIX_ZERO;\r
1298 }\r
1299 case '1':\r
1300 case '2':\r
1301 case '3':\r
1302 case '4':\r
1303 case '5':\r
1304 case '6':\r
1305 case '7':\r
1306 case '8':\r
1307 case '9':\r
1308 for (Count = 0; ((FormatCharacter >= '0') && (FormatCharacter <= '9')); ){\r
1309 Count = (Count * 10) + FormatCharacter - '0';\r
1310 Format += BytesPerFormatCharacter;\r
1311 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1312 }\r
1313 Format -= BytesPerFormatCharacter;\r
1314 if ((Flags & PRECISION) == 0) {\r
1315 Flags |= PAD_TO_WIDTH;\r
1316 Width = Count;\r
1317 } else {\r
1318 Precision = Count;\r
1319 }\r
1320 break;\r
1321 \r
1322 case '\0':\r
1323 //\r
1324 // Make no output if Format string terminates unexpectedly when\r
1325 // looking up for flag, width, precision and type. \r
1326 //\r
1327 Format -= BytesPerFormatCharacter;\r
1328 Precision = 0;\r
1329 //\r
1330 // break skipped on purpose.\r
1331 //\r
1332 default:\r
1333 Done = TRUE;\r
1334 break;\r
1335 }\r
1336 } \r
1337\r
1338 //\r
1339 // Handle each argument type\r
1340 //\r
1341 switch (FormatCharacter) {\r
1342 case 'p':\r
1343 //\r
1344 // Flag space, +, 0, L & l are invalid for type p.\r
1345 //\r
6e1e5405 1346 Flags &= ~(UINTN)(PREFIX_BLANK | PREFIX_SIGN | PREFIX_ZERO | LONG_TYPE);\r
f405c067 1347 if (sizeof (VOID *) > 4) {\r
1348 Flags |= LONG_TYPE;\r
1349 }\r
1350 case 'X':\r
1351 Flags |= PREFIX_ZERO;\r
1352 //\r
1353 // break skipped on purpose\r
1354 //\r
1355 case 'x':\r
1356 Flags |= RADIX_HEX;\r
1357 //\r
1358 // break skipped on purpose\r
1359 //\r
1360 case 'd':\r
1361 if ((Flags & LONG_TYPE) == 0) {\r
1362 //\r
1363 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r
1364 // This assumption is made so the format string definition is compatible with the ANSI C\r
1365 // Specification for formatted strings. It is recommended that the Base Types be used \r
1366 // everywhere, but in this one case, compliance with ANSI C is more important, and \r
1367 // provides an implementation that is compatible with that largest possible set of CPU \r
1368 // architectures. This is why the type "int" is used in this one case.\r
1369 //\r
1370 if (BaseListMarker == NULL) {\r
1371 Value = VA_ARG (VaListMarker, int);\r
1372 } else {\r
1373 Value = BASE_ARG (BaseListMarker, int);\r
1374 }\r
1375 } else {\r
1376 if (BaseListMarker == NULL) {\r
1377 Value = VA_ARG (VaListMarker, INT64);\r
1378 } else {\r
1379 Value = BASE_ARG (BaseListMarker, INT64);\r
1380 }\r
1381 }\r
1382 if ((Flags & PREFIX_BLANK) != 0) {\r
1383 Prefix = ' ';\r
1384 }\r
1385 if ((Flags & PREFIX_SIGN) != 0) {\r
1386 Prefix = '+';\r
1387 }\r
1388 if ((Flags & COMMA_TYPE) != 0) {\r
1389 Comma = TRUE;\r
1390 }\r
1391 if ((Flags & RADIX_HEX) == 0) {\r
1392 Radix = 10;\r
1393 if (Comma) {\r
6e1e5405 1394 Flags &= (~(UINTN)PREFIX_ZERO);\r
f405c067 1395 Precision = 1;\r
1396 }\r
1397 if (Value < 0) {\r
1398 Flags |= PREFIX_SIGN;\r
1399 Prefix = '-';\r
1400 Value = -Value;\r
1401 }\r
1402 } else {\r
1403 Radix = 16;\r
1404 Comma = FALSE;\r
1405 if ((Flags & LONG_TYPE) == 0 && Value < 0) {\r
1406 //\r
1407 // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed to be type "int".\r
1408 // This assumption is made so the format string definition is compatible with the ANSI C\r
1409 // Specification for formatted strings. It is recommended that the Base Types be used \r
1410 // everywhere, but in this one case, compliance with ANSI C is more important, and \r
1411 // provides an implementation that is compatible with that largest possible set of CPU \r
1412 // architectures. This is why the type "unsigned int" is used in this one case.\r
1413 //\r
1414 Value = (unsigned int)Value;\r
1415 }\r
1416 }\r
1417 //\r
1418 // Convert Value to a reversed string\r
1419 //\r
1420 Count = InternalPrintLibValueToString (ValueBuffer, Value, Radix) - ValueBuffer;\r
1421 if (Value == 0 && Precision == 0) {\r
1422 Count = 0;\r
1423 }\r
1424 ArgumentString = (CHAR8 *)ValueBuffer + Count;\r
1425 \r
1426 Digits = Count % 3;\r
1427 if (Digits != 0) {\r
1428 Digits = 3 - Digits;\r
1429 }\r
1430 if (Comma && Count != 0) {\r
1431 Count += ((Count - 1) / 3);\r
1432 }\r
1433 if (Prefix != 0) {\r
1434 Count++;\r
1435 Precision++;\r
1436 }\r
1437 Flags |= ARGUMENT_REVERSED;\r
1438 ZeroPad = TRUE;\r
1439 if ((Flags & PREFIX_ZERO) != 0) {\r
1440 if ((Flags & LEFT_JUSTIFY) == 0) {\r
1441 if ((Flags & PAD_TO_WIDTH) != 0) {\r
1442 if ((Flags & PRECISION) == 0) {\r
1443 Precision = Width;\r
1444 }\r
1445 }\r
1446 }\r
1447 }\r
1448 break;\r
1449\r
1450 case 's':\r
1451 case 'S':\r
1452 Flags |= ARGUMENT_UNICODE;\r
1453 //\r
1454 // break skipped on purpose\r
1455 //\r
1456 case 'a':\r
1457 if (BaseListMarker == NULL) {\r
1458 ArgumentString = VA_ARG (VaListMarker, CHAR8 *);\r
1459 } else {\r
1460 ArgumentString = BASE_ARG (BaseListMarker, CHAR8 *);\r
1461 }\r
1462 if (ArgumentString == NULL) {\r
6e1e5405 1463 Flags &= (~(UINTN)ARGUMENT_UNICODE);\r
f405c067 1464 ArgumentString = "<null string>";\r
1465 }\r
1466 //\r
1467 // Set the default precision for string to be zero if not specified.\r
1468 //\r
1469 if ((Flags & PRECISION) == 0) {\r
1470 Precision = 0;\r
1471 }\r
1472 break;\r
1473\r
1474 case 'c':\r
1475 if (BaseListMarker == NULL) {\r
1476 Character = VA_ARG (VaListMarker, UINTN) & 0xffff;\r
1477 } else {\r
1478 Character = BASE_ARG (BaseListMarker, UINTN) & 0xffff;\r
1479 }\r
1480 ArgumentString = (CHAR8 *)&Character;\r
1481 Flags |= ARGUMENT_UNICODE;\r
1482 break;\r
1483\r
1484 case 'g':\r
1485 if (BaseListMarker == NULL) {\r
1486 TmpGuid = VA_ARG (VaListMarker, GUID *);\r
1487 } else {\r
1488 TmpGuid = BASE_ARG (BaseListMarker, GUID *);\r
1489 }\r
1490 if (TmpGuid == NULL) {\r
1491 ArgumentString = "<null guid>";\r
1492 } else {\r
1493 GuidData1 = ReadUnaligned32 (&(TmpGuid->Data1));\r
1494 GuidData2 = ReadUnaligned16 (&(TmpGuid->Data2));\r
1495 GuidData3 = ReadUnaligned16 (&(TmpGuid->Data3));\r
1496 InternalPrintLibSPrint (\r
1497 ValueBuffer,\r
1498 MAXIMUM_VALUE_CHARACTERS, \r
1499 0,\r
1500 "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",\r
1501 GuidData1,\r
1502 GuidData2,\r
1503 GuidData3,\r
1504 TmpGuid->Data4[0],\r
1505 TmpGuid->Data4[1],\r
1506 TmpGuid->Data4[2],\r
1507 TmpGuid->Data4[3],\r
1508 TmpGuid->Data4[4],\r
1509 TmpGuid->Data4[5],\r
1510 TmpGuid->Data4[6],\r
1511 TmpGuid->Data4[7]\r
1512 );\r
1513 ArgumentString = ValueBuffer;\r
1514 }\r
1515 break;\r
1516\r
1517 case 't':\r
1518 if (BaseListMarker == NULL) {\r
1519 TmpTime = VA_ARG (VaListMarker, TIME *); \r
1520 } else {\r
1521 TmpTime = BASE_ARG (BaseListMarker, TIME *); \r
1522 }\r
1523 if (TmpTime == NULL) {\r
1524 ArgumentString = "<null time>";\r
1525 } else {\r
1526 InternalPrintLibSPrint (\r
1527 ValueBuffer,\r
1528 MAXIMUM_VALUE_CHARACTERS,\r
1529 0,\r
1530 "%02d/%02d/%04d %02d:%02d",\r
1531 TmpTime->Month,\r
1532 TmpTime->Day,\r
1533 TmpTime->Year,\r
1534 TmpTime->Hour,\r
1535 TmpTime->Minute\r
1536 );\r
1537 ArgumentString = ValueBuffer;\r
1538 }\r
1539 break;\r
1540\r
1541 case 'r':\r
1542 if (BaseListMarker == NULL) {\r
1543 Status = VA_ARG (VaListMarker, RETURN_STATUS);\r
1544 } else {\r
1545 Status = BASE_ARG (BaseListMarker, RETURN_STATUS);\r
1546 }\r
1547 ArgumentString = ValueBuffer;\r
1548 if (RETURN_ERROR (Status)) {\r
1549 //\r
1550 // Clear error bit\r
1551 //\r
1552 Index = Status & ~MAX_BIT;\r
1553 if (Index > 0 && Index <= ERROR_STATUS_NUMBER) {\r
1554 ArgumentString = mStatusString [Index + WARNING_STATUS_NUMBER];\r
1555 }\r
1556 } else {\r
1557 Index = Status;\r
1558 if (Index <= WARNING_STATUS_NUMBER) {\r
1559 ArgumentString = mStatusString [Index];\r
1560 }\r
1561 }\r
1562 if (ArgumentString == ValueBuffer) {\r
1563 InternalPrintLibSPrint ((CHAR8 *) ValueBuffer, MAXIMUM_VALUE_CHARACTERS, 0, "%08X", Status);\r
1564 }\r
1565 break;\r
1566\r
1567 case '\r':\r
1568 Format += BytesPerFormatCharacter;\r
1569 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1570 if (FormatCharacter == '\n') {\r
1571 //\r
1572 // Translate '\r\n' to '\r\n'\r
1573 //\r
1574 ArgumentString = "\r\n";\r
1575 } else {\r
1576 //\r
1577 // Translate '\r' to '\r'\r
1578 //\r
1579 ArgumentString = "\r";\r
1580 Format -= BytesPerFormatCharacter;\r
1581 }\r
1582 break;\r
1583\r
1584 case '\n':\r
1585 //\r
1586 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'\r
1587 //\r
1588 ArgumentString = "\r\n";\r
1589 Format += BytesPerFormatCharacter;\r
1590 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1591 if (FormatCharacter != '\r') {\r
1592 Format -= BytesPerFormatCharacter;\r
1593 }\r
1594 break;\r
1595\r
1596 case '%':\r
1597 default:\r
1598 //\r
1599 // if the type is '%' or unknown, then print it to the screen\r
1600 //\r
1601 ArgumentString = (CHAR8 *)&FormatCharacter;\r
1602 Flags |= ARGUMENT_UNICODE;\r
1603 break;\r
1604 }\r
1605 break;\r
1606 \r
1607 case '\r':\r
1608 Format += BytesPerFormatCharacter;\r
1609 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1610 if (FormatCharacter == '\n') {\r
1611 //\r
1612 // Translate '\r\n' to '\r\n'\r
1613 //\r
1614 ArgumentString = "\r\n";\r
1615 } else {\r
1616 //\r
1617 // Translate '\r' to '\r'\r
1618 //\r
1619 ArgumentString = "\r";\r
1620 Format -= BytesPerFormatCharacter;\r
1621 }\r
1622 break;\r
1623\r
1624 case '\n':\r
1625 //\r
1626 // Translate '\n' to '\r\n' and '\n\r' to '\r\n'\r
1627 //\r
1628 ArgumentString = "\r\n";\r
1629 Format += BytesPerFormatCharacter;\r
1630 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1631 if (FormatCharacter != '\r') {\r
1632 Format -= BytesPerFormatCharacter;\r
1633 }\r
1634 break;\r
1635\r
1636 default:\r
1637 ArgumentString = (CHAR8 *)&FormatCharacter;\r
1638 Flags |= ARGUMENT_UNICODE;\r
1639 break;\r
1640 }\r
1641\r
1642 //\r
1643 // Retrieve the ArgumentString attriubutes\r
1644 //\r
1645 if ((Flags & ARGUMENT_UNICODE) != 0) {\r
1646 ArgumentMask = 0xffff;\r
1647 BytesPerArgumentCharacter = 2;\r
1648 } else {\r
1649 ArgumentMask = 0xff;\r
1650 BytesPerArgumentCharacter = 1;\r
1651 }\r
1652 if ((Flags & ARGUMENT_REVERSED) != 0) {\r
1653 BytesPerArgumentCharacter = -BytesPerArgumentCharacter;\r
1654 } else {\r
1655 //\r
1656 // Compute the number of characters in ArgumentString and store it in Count\r
1657 // ArgumentString is either null-terminated, or it contains Precision characters\r
1658 //\r
1659 for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) {\r
1660 ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask;\r
1661 if (ArgumentCharacter == 0) {\r
1662 break;\r
1663 }\r
1664 }\r
1665 }\r
1666\r
1667 if (Precision < Count) {\r
1668 Precision = Count;\r
1669 }\r
1670\r
1671 //\r
1672 // Pad before the string\r
1673 //\r
1674 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) {\r
6bae492f 1675 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r
f405c067 1676 }\r
1677\r
1678 if (ZeroPad) {\r
1679 if (Prefix != 0) {\r
6bae492f 1680 LengthToReturn += (1 * BytesPerOutputCharacter);\r
f405c067 1681 }\r
6bae492f 1682 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r
f405c067 1683 } else {\r
6bae492f 1684 LengthToReturn += ((Precision - Count) * BytesPerOutputCharacter);\r
f405c067 1685 if (Prefix != 0) {\r
6bae492f 1686 LengthToReturn += (1 * BytesPerOutputCharacter);\r
f405c067 1687 }\r
1688 }\r
1689\r
1690 //\r
1691 // Output the Prefix character if it is present\r
1692 //\r
1693 Index = 0;\r
1694 if (Prefix != 0) {\r
1695 Index++;\r
1696 }\r
1697\r
1698 //\r
1699 // Copy the string into the output buffer performing the required type conversions\r
1700 //\r
1701 while (Index < Count) {\r
1702 ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask;\r
1703\r
6bae492f 1704 LengthToReturn += (1 * BytesPerOutputCharacter);\r
f405c067 1705 ArgumentString += BytesPerArgumentCharacter;\r
1706 Index++;\r
1707 if (Comma) {\r
1708 Digits++;\r
1709 if (Digits == 3) {\r
1710 Digits = 0;\r
1711 Index++;\r
1712 if (Index < Count) {\r
6bae492f 1713 LengthToReturn += (1 * BytesPerOutputCharacter);\r
f405c067 1714 }\r
1715 }\r
1716 }\r
1717 }\r
1718\r
1719 //\r
1720 // Pad after the string\r
1721 //\r
1722 if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) {\r
6bae492f 1723 LengthToReturn += ((Width - Precision) * BytesPerOutputCharacter);\r
f405c067 1724 }\r
1725\r
1726 //\r
1727 // Get the next character from the format string\r
1728 //\r
1729 Format += BytesPerFormatCharacter;\r
1730\r
1731 //\r
1732 // Get the next character from the format string\r
1733 //\r
1734 FormatCharacter = ((*Format & 0xff) | (*(Format + 1) << 8)) & FormatMask;\r
1735 }\r
1736\r
1737 return (LengthToReturn / BytesPerOutputCharacter);\r
1738}\r
1739\r
1740/**\r
1741 Returns the number of characters that would be produced by if the formatted \r
1742 output were produced not including the Null-terminator.\r
1743\r
1744 If FormatString is NULL, then ASSERT().\r
1745 If FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
1746\r
1747 @param[in] FormatString A Null-terminated Unicode format string.\r
1748 @param[in] Marker VA_LIST marker for the variable argument list.\r
1749\r
1750 @return The number of characters that would be produced, not including the \r
1751 Null-terminator.\r
1752**/\r
1753UINTN\r
1754EFIAPI\r
1755SPrintLength (\r
1756 IN CONST CHAR16 *FormatString,\r
1757 IN VA_LIST Marker\r
1758 )\r
1759{\r
1760 ASSERT(FormatString != NULL);\r
1761 return InternalPrintLibSPrintMarker (NULL, 0, FORMAT_UNICODE | OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r
1762}\r
1763\r
1764/**\r
1765 Returns the number of characters that would be produced by if the formatted \r
1766 output were produced not including the Null-terminator.\r
1767\r
1768 If FormatString is NULL, then ASSERT().\r
1769\r
1770 @param[in] FormatString A Null-terminated ASCII format string.\r
1771 @param[in] Marker VA_LIST marker for the variable argument list.\r
1772\r
1773 @return The number of characters that would be produced, not including the \r
1774 Null-terminator.\r
1775**/\r
1776UINTN\r
1777EFIAPI\r
1778SPrintLengthAsciiFormat (\r
1779 IN CONST CHAR8 *FormatString,\r
1780 IN VA_LIST Marker\r
1781 )\r
1782{\r
1783 ASSERT(FormatString != NULL);\r
1784 return InternalPrintLibSPrintMarker (NULL, 0, OUTPUT_UNICODE | COUNT_ONLY_NO_PRINT, (CHAR8 *)FormatString, Marker, NULL);\r
1785}\r