]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/BasePrintLib/PrintLibInternal.h
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / BasePrintLib / PrintLibInternal.h
1 /** @file
2 Base Print Library instance Internal Functions definition.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef __PRINT_LIB_INTERNAL_H__
10 #define __PRINT_LIB_INTERNAL_H__
11
12 #include <Base.h>
13 #include <Library/PrintLib.h>
14 #include <Library/BaseLib.h>
15 #include <Library/DebugLib.h>
16 #include <Library/PcdLib.h>
17
18
19 //
20 // Print primitives
21 //
22 #define PREFIX_SIGN BIT1
23 #define PREFIX_BLANK BIT2
24 #define LONG_TYPE BIT4
25 #define OUTPUT_UNICODE BIT6
26 #define FORMAT_UNICODE BIT8
27 #define PAD_TO_WIDTH BIT9
28 #define ARGUMENT_UNICODE BIT10
29 #define PRECISION BIT11
30 #define ARGUMENT_REVERSED BIT12
31 #define COUNT_ONLY_NO_PRINT BIT13
32 #define UNSIGNED_TYPE BIT14
33
34 //
35 // Record date and time information
36 //
37 typedef struct {
38 UINT16 Year;
39 UINT8 Month;
40 UINT8 Day;
41 UINT8 Hour;
42 UINT8 Minute;
43 UINT8 Second;
44 UINT8 Pad1;
45 UINT32 Nanosecond;
46 INT16 TimeZone;
47 UINT8 Daylight;
48 UINT8 Pad2;
49 } TIME;
50
51 /**
52 Worker function that produces a Null-terminated string in an output buffer
53 based on a Null-terminated format string and a VA_LIST argument list.
54
55 VSPrint function to process format and place the results in Buffer. Since a
56 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
57 this is the main print working routine.
58
59 If COUNT_ONLY_NO_PRINT is set in Flags, Buffer will not be modified at all.
60
61 @param[out] Buffer The character buffer to print the results of the
62 parsing of Format into.
63 @param[in] BufferSize The maximum number of characters to put into
64 buffer.
65 @param[in] Flags Initial flags value.
66 Can only have FORMAT_UNICODE, OUTPUT_UNICODE,
67 and COUNT_ONLY_NO_PRINT set.
68 @param[in] Format A Null-terminated format string.
69 @param[in] VaListMarker VA_LIST style variable argument list consumed by
70 processing Format.
71 @param[in] BaseListMarker BASE_LIST style variable argument list consumed
72 by processing Format.
73
74 @return The number of characters printed not including the Null-terminator.
75 If COUNT_ONLY_NO_PRINT was set returns the same, but without any
76 modification to Buffer.
77
78 **/
79 UINTN
80 BasePrintLibSPrintMarker (
81 OUT CHAR8 *Buffer,
82 IN UINTN BufferSize,
83 IN UINTN Flags,
84 IN CONST CHAR8 *Format,
85 IN VA_LIST VaListMarker, OPTIONAL
86 IN BASE_LIST BaseListMarker OPTIONAL
87 );
88
89 /**
90 Worker function that produces a Null-terminated string in an output buffer
91 based on a Null-terminated format string and variable argument list.
92
93 VSPrint function to process format and place the results in Buffer. Since a
94 VA_LIST is used this routine allows the nesting of Vararg routines. Thus
95 this is the main print working routine
96
97 @param StartOfBuffer The character buffer to print the results of the parsing
98 of Format into.
99 @param BufferSize The maximum number of characters to put into buffer.
100 Zero means no limit.
101 @param Flags Initial flags value.
102 Can only have FORMAT_UNICODE and OUTPUT_UNICODE set
103 @param FormatString Null-terminated format string.
104 @param ... The variable argument list.
105
106 @return The number of characters printed.
107
108 **/
109 UINTN
110 EFIAPI
111 BasePrintLibSPrint (
112 OUT CHAR8 *StartOfBuffer,
113 IN UINTN BufferSize,
114 IN UINTN Flags,
115 IN CONST CHAR8 *FormatString,
116 ...
117 );
118
119 /**
120 Internal function that places the character into the Buffer.
121
122 Internal function that places ASCII or Unicode character into the Buffer.
123
124 @param Buffer Buffer to place the Unicode or ASCII string.
125 @param EndBuffer The end of the input Buffer. No characters will be
126 placed after that.
127 @param Length The count of character to be placed into Buffer.
128 (Negative value indicates no buffer fill.)
129 @param Character The character to be placed into Buffer.
130 @param Increment The character increment in Buffer.
131
132 @return Buffer Buffer filled with the input Character.
133
134 **/
135 CHAR8 *
136 BasePrintLibFillBuffer (
137 OUT CHAR8 *Buffer,
138 IN CHAR8 *EndBuffer,
139 IN INTN Length,
140 IN UINTN Character,
141 IN INTN Increment
142 );
143
144 /**
145 Internal function that convert a number to a string in Buffer.
146
147 Print worker function that converts a decimal or hexadecimal number to an ASCII string in Buffer.
148
149 @param Buffer Location to place the ASCII string of Value.
150 @param Value The value to convert to a Decimal or Hexadecimal string in Buffer.
151 @param Radix Radix of the value
152
153 @return A pointer to the end of buffer filled with ASCII string.
154
155 **/
156 CHAR8 *
157 BasePrintLibValueToString (
158 IN OUT CHAR8 *Buffer,
159 IN INT64 Value,
160 IN UINTN Radix
161 );
162
163 /**
164 Internal function that converts a decimal value to a Null-terminated string.
165
166 Converts the decimal number specified by Value to a Null-terminated
167 string specified by Buffer containing at most Width characters.
168 If Width is 0 then a width of MAXIMUM_VALUE_CHARACTERS is assumed.
169 The total number of characters placed in Buffer is returned.
170 If the conversion contains more than Width characters, then only the first
171 Width characters are returned, and the total number of characters
172 required to perform the conversion is returned.
173 Additional conversion parameters are specified in Flags.
174 The Flags bit LEFT_JUSTIFY is always ignored.
175 All conversions are left justified in Buffer.
176 If Width is 0, PREFIX_ZERO is ignored in Flags.
177 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and commas
178 are inserted every 3rd digit starting from the right.
179 If Value is < 0, then the fist character in Buffer is a '-'.
180 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
181 then Buffer is padded with '0' characters so the combination of the optional '-'
182 sign character, '0' characters, digit characters for Value, and the Null-terminator
183 add up to Width characters.
184
185 If Buffer is NULL, then ASSERT().
186 If unsupported bits are set in Flags, then ASSERT().
187 If Width >= MAXIMUM_VALUE_CHARACTERS, then ASSERT()
188
189 @param Buffer The pointer to the output buffer for the produced Null-terminated
190 string.
191 @param Flags The bitmask of flags that specify left justification, zero pad,
192 and commas.
193 @param Value The 64-bit signed value to convert to a string.
194 @param Width The maximum number of characters to place in Buffer, not including
195 the Null-terminator.
196 @param Increment Character increment in Buffer.
197
198 @return Total number of characters required to perform the conversion.
199
200 **/
201 UINTN
202 BasePrintLibConvertValueToString (
203 IN OUT CHAR8 *Buffer,
204 IN UINTN Flags,
205 IN INT64 Value,
206 IN UINTN Width,
207 IN UINTN Increment
208 );
209
210 /**
211 Internal function that converts a decimal value to a Null-terminated string.
212
213 Converts the decimal number specified by Value to a Null-terminated string
214 specified by Buffer containing at most Width characters. If Width is 0 then a
215 width of MAXIMUM_VALUE_CHARACTERS is assumed. If the conversion contains more
216 than Width characters, then only the first Width characters are placed in
217 Buffer. Additional conversion parameters are specified in Flags.
218 The Flags bit LEFT_JUSTIFY is always ignored.
219 All conversions are left justified in Buffer.
220 If Width is 0, PREFIX_ZERO is ignored in Flags.
221 If COMMA_TYPE is set in Flags, then PREFIX_ZERO is ignored in Flags, and
222 commas are inserted every 3rd digit starting from the right.
223 If Value is < 0, then the fist character in Buffer is a '-'.
224 If PREFIX_ZERO is set in Flags and PREFIX_ZERO is not being ignored,
225 then Buffer is padded with '0' characters so the combination of the optional
226 '-' sign character, '0' characters, digit characters for Value, and the
227 Null-terminator add up to Width characters.
228
229 If an error would be returned, the function will ASSERT().
230
231 @param Buffer The pointer to the output buffer for the produced
232 Null-terminated string.
233 @param BufferSize The size of Buffer in bytes, including the
234 Null-terminator.
235 @param Flags The bitmask of flags that specify left justification,
236 zero pad, and commas.
237 @param Value The 64-bit signed value to convert to a string.
238 @param Width The maximum number of characters to place in Buffer,
239 not including the Null-terminator.
240 @param Increment The character increment in Buffer.
241
242 @retval RETURN_SUCCESS The decimal value is converted.
243 @retval RETURN_BUFFER_TOO_SMALL If BufferSize cannot hold the converted
244 value.
245 @retval RETURN_INVALID_PARAMETER If Buffer is NULL.
246 If Increment is 1 and
247 PcdMaximumAsciiStringLength is not zero,
248 BufferSize is greater than
249 PcdMaximumAsciiStringLength.
250 If Increment is not 1 and
251 PcdMaximumUnicodeStringLength is not zero,
252 BufferSize is greater than
253 (PcdMaximumUnicodeStringLength *
254 sizeof (CHAR16) + 1).
255 If unsupported bits are set in Flags.
256 If both COMMA_TYPE and RADIX_HEX are set in
257 Flags.
258 If Width >= MAXIMUM_VALUE_CHARACTERS.
259
260 **/
261 RETURN_STATUS
262 BasePrintLibConvertValueToStringS (
263 IN OUT CHAR8 *Buffer,
264 IN UINTN BufferSize,
265 IN UINTN Flags,
266 IN INT64 Value,
267 IN UINTN Width,
268 IN UINTN Increment
269 );
270
271 #endif