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