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