]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/PrintLib.h
refine the comments
[mirror_edk2.git] / MdePkg / Include / Library / PrintLib.h
CommitLineData
488ee641 1/** @file\r
50a64e5b 2 Provides services to print a formatted string to a buffer. All combinations of\r
3 Unicode and ASCII strings are supported.\r
488ee641 4\r
50a64e5b 5Copyright (c) 2006 - 2008, Intel Corporation\r
6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
488ee641 10\r
50a64e5b 11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
488ee641 13\r
14**/\r
15\r
16#ifndef __PRINT_LIB_H__\r
17#define __PRINT_LIB_H__\r
18\r
19///\r
20/// Define the maximum number of characters that are required to\r
21/// encode a decimal, hexidecimal, GUID, or TIME value with a NULL \r
22/// terminator.\r
23/// \r
24/// Maximum Length Decimal String = 28\r
25/// "-9,223,372,036,854,775,808"\r
26/// Maximum Length Hexidecimal String = 17\r
27/// "FFFFFFFFFFFFFFFF"\r
28/// Maximum Length GUID = 37\r
29/// "00000000-0000-0000-0000-000000000000"\r
30/// Maximum Length TIME = 18\r
31/// "12/12/2006 12:12"\r
32///\r
33#define MAXIMUM_VALUE_CHARACTERS 38\r
34\r
35///\r
36/// Flags bitmask values use in UnicodeValueToString() and \r
37/// AsciiValueToString()\r
38///\r
39#define LEFT_JUSTIFY 0x01\r
40#define COMMA_TYPE 0x08\r
41#define PREFIX_ZERO 0x20\r
42#define RADIX_HEX 0x80\r
43\r
44/**\r
45 Produces a Null-terminated Unicode string in an output buffer based on \r
46 a Null-terminated Unicode format string and a VA_LIST argument list\r
47 \r
48 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
49 and BufferSize. \r
50 The Unicode string is produced by parsing the format string specified by FormatString. \r
51 Arguments are pulled from the variable argument list specified by Marker based on the \r
52 contents of the format string. \r
53 The number of Unicode characters in the produced output buffer is returned not including\r
54 the Null-terminator.\r
55 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
56\r
57 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
58 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
59 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
60 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
61 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
62 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
63 ASSERT().\r
64 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
65 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
66 Null-terminator, then ASSERT().\r
67\r
68 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
69 Unicode string.\r
70 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
71 @param FormatString Null-terminated Unicode format string.\r
72 @param Marker VA_LIST marker for the variable argument list.\r
73 \r
74 @return The number of Unicode characters in the produced output buffer not including the\r
75 Null-terminator.\r
76\r
77**/\r
78UINTN\r
79EFIAPI\r
80UnicodeVSPrint (\r
81 OUT CHAR16 *StartOfBuffer,\r
82 IN UINTN BufferSize,\r
83 IN CONST CHAR16 *FormatString,\r
84 IN VA_LIST Marker\r
85 );\r
86\r
87/**\r
88 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
89 Unicode format string and variable argument list.\r
90 \r
91 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
92 and BufferSize.\r
93 The Unicode string is produced by parsing the format string specified by FormatString.\r
94 Arguments are pulled from the variable argument list based on the contents of the format string.\r
95 The number of Unicode characters in the produced output buffer is returned not including\r
96 the Null-terminator.\r
97 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
98\r
99 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
100 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
101 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
102 If BufferSize > 1 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
103 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than \r
104 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
105 ASSERT().\r
106 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
107 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
108 Null-terminator, then ASSERT().\r
109\r
110 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
111 Unicode string.\r
112 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
113 @param FormatString Null-terminated Unicode format string.\r
114 @param ... The variable argument list.\r
115 \r
116 @return The number of Unicode characters in the produced output buffer not including the\r
117 Null-terminator.\r
118\r
119**/\r
120UINTN\r
121EFIAPI\r
122UnicodeSPrint (\r
123 OUT CHAR16 *StartOfBuffer,\r
124 IN UINTN BufferSize,\r
125 IN CONST CHAR16 *FormatString,\r
126 ...\r
127 );\r
128\r
129/**\r
130 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated\r
131 ASCII format string and a VA_LIST argument list\r
132 \r
133 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
134 and BufferSize.\r
135 The Unicode string is produced by parsing the format string specified by FormatString.\r
136 Arguments are pulled from the variable argument list specified by Marker based on the \r
137 contents of the format string.\r
138 The number of Unicode characters in the produced output buffer is returned not including\r
139 the Null-terminator.\r
140 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
141\r
142 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
143 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
144 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
145 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
146 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
147 ASSERT().\r
148 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
149 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
150 Null-terminator, then ASSERT().\r
151\r
152 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
153 Unicode string.\r
154 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
155 @param FormatString Null-terminated ASCII format string.\r
156 @param Marker VA_LIST marker for the variable argument list.\r
157 \r
158 @return The number of Unicode characters in the produced output buffer not including the\r
159 Null-terminator.\r
160\r
161**/\r
162UINTN\r
163EFIAPI\r
164UnicodeVSPrintAsciiFormat (\r
165 OUT CHAR16 *StartOfBuffer,\r
166 IN UINTN BufferSize,\r
167 IN CONST CHAR8 *FormatString,\r
168 IN VA_LIST Marker\r
169 );\r
170\r
171/**\r
172 Produces a Null-terminated Unicode string in an output buffer based on a Null-terminated \r
173 ASCII format string and variable argument list.\r
174 \r
175 Produces a Null-terminated Unicode string in the output buffer specified by StartOfBuffer\r
176 and BufferSize.\r
177 The Unicode string is produced by parsing the format string specified by FormatString.\r
178 Arguments are pulled from the variable argument list based on the contents of the \r
179 format string.\r
180 The number of Unicode characters in the produced output buffer is returned not including\r
181 the Null-terminator.\r
182 If BufferSize is 0 or 1, then no output buffer is produced and 0 is returned.\r
183\r
184 If BufferSize > 1 and StartOfBuffer is NULL, then ASSERT().\r
185 If BufferSize > 1 and StartOfBuffer is not aligned on a 16-bit boundary, then ASSERT().\r
186 If BufferSize > 1 and FormatString is NULL, then ASSERT().\r
187 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
188 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
189 ASSERT().\r
190 If PcdMaximumUnicodeStringLength is not zero, and produced Null-terminated Unicode string\r
191 contains more than PcdMaximumUnicodeStringLength Unicode characters not including the\r
192 Null-terminator, then ASSERT().\r
193\r
194 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
195 Unicode string.\r
196 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
197 @param FormatString Null-terminated ASCII format string.\r
198 @param ... The variable argument list.\r
199 \r
200 @return The number of Unicode characters in the produced output buffer not including the\r
201 Null-terminator.\r
202\r
203**/\r
204UINTN\r
205EFIAPI\r
206UnicodeSPrintAsciiFormat (\r
207 OUT CHAR16 *StartOfBuffer,\r
208 IN UINTN BufferSize,\r
209 IN CONST CHAR8 *FormatString,\r
210 ...\r
211 );\r
212\r
213/**\r
214 Converts a decimal value to a Null-terminated Unicode string.\r
215 \r
216 Converts the decimal number specified by Value to a Null-terminated Unicode \r
217 string specified by Buffer containing at most Width characters. No padding of spaces \r
218 is ever performed. If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
219 The number of Unicode characters in Buffer is returned not including the Null-terminator.\r
220 If the conversion contains more than Width characters, then only the first\r
221 Width characters are returned, and the total number of characters \r
222 required to perform the conversion is returned.\r
223 Additional conversion parameters are specified in Flags. \r
224 \r
225 The Flags bit LEFT_JUSTIFY is always ignored.\r
226 All conversions are left justified in Buffer.\r
227 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
228 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
229 are inserted every 3rd digit starting from the right.\r
230 If HEX_RADIX is set in Flags, then the output buffer will be \r
231 formatted in hexadecimal format.\r
232 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.\r
233 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
234 then Buffer is padded with '0' characters so the combination of the optional '-' \r
235 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
236 add up to Width characters.\r
237 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().\r
238 If Buffer is NULL, then ASSERT().\r
239 If Buffer is not aligned on a 16-bit boundary, then ASSERT().\r
240 If unsupported bits are set in Flags, then ASSERT().\r
241 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().\r
242 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
243\r
244 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
245 Unicode string.\r
246 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
247 @param Value The 64-bit signed value to convert to a string.\r
248 @param Width The maximum number of Unicode characters to place in Buffer, not including\r
249 the Null-terminator.\r
250 \r
251 @return The number of Unicode characters in Buffer not including the Null-terminator.\r
252\r
253**/\r
254UINTN\r
255EFIAPI\r
256UnicodeValueToString (\r
257 IN OUT CHAR16 *Buffer,\r
258 IN UINTN Flags,\r
259 IN INT64 Value,\r
260 IN UINTN Width\r
261 );\r
262\r
263/**\r
264 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
265 ASCII format string and a VA_LIST argument list.\r
266 \r
267 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
268 and BufferSize.\r
269 The ASCII string is produced by parsing the format string specified by FormatString.\r
270 Arguments are pulled from the variable argument list specified by Marker based on \r
271 the contents of the format string.\r
272 The number of ASCII characters in the produced output buffer is returned not including\r
273 the Null-terminator.\r
274 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
275\r
276 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
277 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
278 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
279 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
280 ASSERT().\r
281 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
282 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
283 Null-terminator, then ASSERT().\r
284\r
285 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
286 ASCII string.\r
287 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
288 @param FormatString Null-terminated ASCII format string.\r
289 @param Marker VA_LIST marker for the variable argument list.\r
290 \r
291 @return The number of ASCII characters in the produced output buffer not including the\r
292 Null-terminator.\r
293\r
294**/\r
295UINTN\r
296EFIAPI\r
297AsciiVSPrint (\r
298 OUT CHAR8 *StartOfBuffer,\r
299 IN UINTN BufferSize,\r
300 IN CONST CHAR8 *FormatString,\r
301 IN VA_LIST Marker\r
302 );\r
303\r
304/**\r
305 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
306 ASCII format string and variable argument list.\r
307 \r
308 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
309 and BufferSize.\r
310 The ASCII string is produced by parsing the format string specified by FormatString.\r
311 Arguments are pulled from the variable argument list based on the contents of the \r
312 format string.\r
313 The number of ASCII characters in the produced output buffer is returned not including\r
314 the Null-terminator.\r
315 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
316\r
317 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
318 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
319 If PcdMaximumAsciiStringLength is not zero, and FormatString contains more than\r
320 PcdMaximumAsciiStringLength ASCII characters not including the Null-terminator, then\r
321 ASSERT().\r
322 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
323 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
324 Null-terminator, then ASSERT().\r
325\r
326 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
327 ASCII string.\r
328 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
329 @param FormatString Null-terminated ASCII format string.\r
330 @param ... The variable argument list. \r
331 \r
332 @return The number of ASCII characters in the produced output buffer not including the\r
333 Null-terminator.\r
334\r
335**/\r
336UINTN\r
337EFIAPI\r
338AsciiSPrint (\r
339 OUT CHAR8 *StartOfBuffer,\r
340 IN UINTN BufferSize,\r
341 IN CONST CHAR8 *FormatString,\r
342 ...\r
343 );\r
344\r
345/**\r
346 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
347 Unicode format string and a VA_LIST argument list.\r
348 \r
349 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
350 and BufferSize.\r
351 The ASCII string is produced by parsing the format string specified by FormatString.\r
352 Arguments are pulled from the variable argument list specified by Marker based on \r
353 the contents of the format string.\r
354 The number of ASCII characters in the produced output buffer is returned not including\r
355 the Null-terminator.\r
356 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
357\r
358 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
359 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
360 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
361 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
362 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
363 ASSERT().\r
364 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
365 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
366 Null-terminator, then ASSERT().\r
367\r
368 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
369 ASCII string.\r
370 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
371 @param FormatString Null-terminated Unicode format string.\r
372 @param Marker VA_LIST marker for the variable argument list.\r
373 \r
374 @return The number of ASCII characters in the produced output buffer not including the\r
375 Null-terminator.\r
376\r
377**/\r
378UINTN\r
379EFIAPI\r
380AsciiVSPrintUnicodeFormat (\r
381 OUT CHAR8 *StartOfBuffer,\r
382 IN UINTN BufferSize,\r
383 IN CONST CHAR16 *FormatString,\r
384 IN VA_LIST Marker\r
385 );\r
386\r
387/**\r
388 Produces a Null-terminated ASCII string in an output buffer based on a Null-terminated\r
389 Unicode format string and variable argument list.\r
390 \r
391 Produces a Null-terminated ASCII string in the output buffer specified by StartOfBuffer\r
392 and BufferSize.\r
393 The ASCII string is produced by parsing the format string specified by FormatString.\r
394 Arguments are pulled from the variable argument list based on the contents of the \r
395 format string.\r
396 The number of ASCII characters in the produced output buffer is returned not including\r
397 the Null-terminator.\r
398 If BufferSize is 0, then no output buffer is produced and 0 is returned.\r
399\r
400 If BufferSize > 0 and StartOfBuffer is NULL, then ASSERT().\r
401 If BufferSize > 0 and FormatString is NULL, then ASSERT().\r
402 If BufferSize > 0 and FormatString is not aligned on a 16-bit boundary, then ASSERT().\r
403 If PcdMaximumUnicodeStringLength is not zero, and FormatString contains more than\r
404 PcdMaximumUnicodeStringLength Unicode characters not including the Null-terminator, then\r
405 ASSERT().\r
406 If PcdMaximumAsciiStringLength is not zero, and produced Null-terminated ASCII string\r
407 contains more than PcdMaximumAsciiStringLength ASCII characters not including the\r
408 Null-terminator, then ASSERT().\r
409\r
410 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated \r
411 ASCII string.\r
412 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
413 @param FormatString Null-terminated Unicode format string.\r
414 @param ... The variable argument list.\r
415 \r
416 @return The number of ASCII characters in the produced output buffer not including the\r
417 Null-terminator.\r
418\r
419**/\r
420UINTN\r
421EFIAPI\r
422AsciiSPrintUnicodeFormat (\r
423 OUT CHAR8 *StartOfBuffer,\r
424 IN UINTN BufferSize,\r
425 IN CONST CHAR16 *FormatString,\r
426 ...\r
427 );\r
428\r
429/**\r
430 Converts a decimal value to a Null-terminated ASCII string.\r
431 \r
432 Converts the decimal number specified by Value to a Null-terminated ASCII string \r
433 specified by Buffer containing at most Width characters. No padding of spaces \r
434 is ever performed.\r
435 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.\r
436 The number of ASCII characters in Buffer is returned not including the Null-terminator.\r
437 If the conversion contains more than Width characters, then only the first Width\r
438 characters are returned, and the total number of characters required to perform\r
439 the conversion is returned.\r
440 Additional conversion parameters are specified in Flags. \r
441 The Flags bit LEFT_JUSTIFY is always ignored.\r
442 All conversions are left justified in Buffer.\r
443 If Width is 0, PREFIX_ZERO is ignored in Flags.\r
444 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas\r
445 are inserted every 3rd digit starting from the right.\r
446 If HEX_RADIX is set in Flags, then the output buffer will be \r
447 formatted in hexadecimal format.\r
448 If Value is < 0 and HEX_RADIX is not set in Flags, then the fist character in Buffer is a '-'.\r
449 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored, \r
450 then Buffer is padded with '0' characters so the combination of the optional '-' \r
451 sign character, '0' characters, digit characters for Value, and the Null-terminator\r
452 add up to Width characters.\r
453 \r
454 If Buffer is NULL, then ASSERT().\r
455 If unsupported bits are set in Flags, then ASSERT().\r
456 If both COMMA_TYPE and HEX_RADIX are set in Flags, then ASSERT().\r
457 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()\r
458\r
459 @param Buffer Pointer to the output buffer for the produced Null-terminated\r
460 ASCII string.\r
461 @param Flags The bitmask of flags that specify left justification, zero pad, and commas.\r
462 @param Value The 64-bit signed value to convert to a string.\r
463 @param Width The maximum number of ASCII characters to place in Buffer, not including\r
464 the Null-terminator.\r
465 \r
466 @return The number of ASCII characters in Buffer not including the Null-terminator.\r
467\r
468**/\r
469UINTN\r
470EFIAPI\r
471AsciiValueToString (\r
472 IN OUT CHAR8 *Buffer,\r
473 IN UINTN Flags,\r
474 IN INT64 Value,\r
475 IN UINTN Width\r
476 );\r
477\r
478#endif\r