]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiLib/UefiLibPrint.c
Code clean up.
[mirror_edk2.git] / MdePkg / Library / UefiLib / UefiLibPrint.c
CommitLineData
e386b444 1/** @file\r
2 Mde UEFI library API implemention.\r
3 Print to StdErr or ConOut defined in EFI_SYSTEM_TABLE\r
4\r
5 Copyright (c) 2007, Intel Corporation<BR>\r
6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16//\r
17// Include common header file for this module.\r
18//\r
f734a10a 19#include "UefiLibInternal.h"\r
e386b444 20\r
21/**\r
22 Internal function which prints a formatted Unicode string to the console output device\r
23 specified by Console\r
24\r
25 This function prints a formatted Unicode string to the console output device\r
26 specified by Console and returns the number of Unicode characters that printed\r
27 to it. If the length of the formatted Unicode string is greater than PcdUefiLibMaxPrintBufferSize,\r
28 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.\r
f80b0830 29 If Format is NULL, then ASSERT().\r
30 If Format is not aligned on a 16-bit boundary, then ASSERT().\r
e386b444 31\r
32 @param Format Null-terminated Unicode format string.\r
33 @param Console The output console.\r
34 @param Marker VA_LIST marker for the variable argument list.\r
f80b0830 35 \r
36 @return The number of Unicode characters in the produced\r
37 output buffer not including the Null-terminator.\r
e386b444 38**/\r
e386b444 39UINTN\r
42eedea9 40EFIAPI\r
e386b444 41InternalPrint (\r
42 IN CONST CHAR16 *Format,\r
43 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,\r
44 IN VA_LIST Marker\r
45 )\r
46{\r
47 UINTN Return;\r
48 CHAR16 *Buffer;\r
49 UINTN BufferSize;\r
50\r
51 ASSERT (Format != NULL);\r
52 ASSERT (((UINTN) Format & 0x01) == 0);\r
53\r
54 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
55\r
56 Buffer = (CHAR16 *) AllocatePool(BufferSize);\r
57 ASSERT (Buffer != NULL);\r
58\r
59 Return = UnicodeVSPrint (Buffer, BufferSize, Format, Marker);\r
60\r
2ad4dad0 61 if (Console != NULL && Return > 0) {\r
e386b444 62 //\r
63 // To be extra safe make sure Console has been initialized\r
64 //\r
65 Console->OutputString (Console, Buffer);\r
66 }\r
67\r
68 FreePool (Buffer);\r
69\r
70 return Return;\r
71}\r
72\r
73/**\r
74 Prints a formatted Unicode string to the console output device specified by\r
75 ConOut defined in the EFI_SYSTEM_TABLE.\r
76\r
77 This function prints a formatted Unicode string to the console output device\r
78 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of Unicode\r
79 characters that printed to ConOut. If the length of the formatted Unicode\r
80 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
81 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
f80b0830 82 If Format is NULL, then ASSERT().\r
83 If Format is not aligned on a 16-bit boundary, then ASSERT().\r
e386b444 84\r
85 @param Format Null-terminated Unicode format string.\r
86 @param ... VARARG list consumed to process Format.\r
f80b0830 87 \r
88 @return The number of Unicode characters in the produced\r
89 output buffer not including the Null-terminator.\r
e386b444 90\r
91**/\r
92UINTN\r
93EFIAPI\r
94Print (\r
95 IN CONST CHAR16 *Format,\r
96 ...\r
97 )\r
98{\r
99 VA_LIST Marker;\r
100 UINTN Return;\r
101\r
102 VA_START (Marker, Format);\r
103\r
104 Return = InternalPrint (Format, gST->ConOut, Marker);\r
105\r
106 VA_END (Marker);\r
107\r
108 return Return;\r
109}\r
110\r
111/**\r
112 Prints a formatted Unicode string to the console output device specified by\r
113 StdErr defined in the EFI_SYSTEM_TABLE.\r
114\r
115 This function prints a formatted Unicode string to the console output device\r
116 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of Unicode\r
117 characters that printed to StdErr. If the length of the formatted Unicode\r
118 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
119 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
f80b0830 120 If Format is NULL, then ASSERT().\r
121 If Format is not aligned on a 16-bit boundary, then ASSERT().\r
e386b444 122\r
123 @param Format Null-terminated Unicode format string.\r
124 @param ... VARARG list consumed to process Format.\r
e386b444 125\r
f80b0830 126 @return The number of Unicode characters in the produced\r
127 output buffer not including the Null-terminator.\r
e386b444 128**/\r
129\r
130UINTN\r
131EFIAPI\r
132ErrorPrint (\r
133 IN CONST CHAR16 *Format,\r
134 ...\r
135 )\r
136{\r
137 VA_LIST Marker;\r
138 UINTN Return;\r
139\r
140 VA_START (Marker, Format);\r
141\r
142 Return = InternalPrint( Format, gST->StdErr, Marker);\r
143\r
144 VA_END (Marker);\r
145\r
146 return Return;\r
147}\r
148\r
149\r
150/**\r
151 Internal function which prints a formatted ASCII string to the console output device\r
152 specified by Console\r
153\r
154 This function prints a formatted ASCII string to the console output device\r
155 specified by Console and returns the number of ASCII characters that printed\r
156 to it. If the length of the formatted ASCII string is greater than PcdUefiLibMaxPrintBufferSize,\r
157 then only the first PcdUefiLibMaxPrintBufferSize characters are sent to Console.\r
f80b0830 158 If Format is NULL, then ASSERT().\r
159\r
160 If Format is NULL, then ASSERT().\r
161 If Format is not aligned on a 16-bit boundary, then ASSERT().\r
162 \r
e386b444 163\r
164 @param Format Null-terminated ASCII format string.\r
165 @param Console The output console.\r
166 @param Marker VA_LIST marker for the variable argument list.\r
167\r
f80b0830 168 @return The number of Unicode characters in the produced\r
169 output buffer not including the Null-terminator.\r
e386b444 170\r
171**/\r
e386b444 172UINTN\r
42eedea9 173EFIAPI\r
e386b444 174AsciiInternalPrint (\r
175 IN CONST CHAR8 *Format,\r
176 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Console,\r
177 IN VA_LIST Marker\r
178 )\r
179{\r
180 UINTN Return;\r
181 CHAR16 *Buffer;\r
182 UINTN BufferSize;\r
183\r
184 ASSERT (Format != NULL);\r
185\r
186 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
187\r
188 Buffer = (CHAR16 *) AllocatePool(BufferSize);\r
189 ASSERT (Buffer != NULL);\r
190\r
191 Return = UnicodeVSPrintAsciiFormat (Buffer, BufferSize, Format, Marker);\r
192\r
193 if (Console != NULL) {\r
194 //\r
195 // To be extra safe make sure Console has been initialized\r
196 //\r
197 Console->OutputString (Console, Buffer);\r
198 }\r
199\r
200 FreePool (Buffer);\r
201\r
202 return Return;\r
203}\r
204\r
205/**\r
206 Prints a formatted ASCII string to the console output device specified by\r
207 ConOut defined in the EFI_SYSTEM_TABLE.\r
208\r
209 This function prints a formatted ASCII string to the console output device\r
210 specified by ConOut in EFI_SYSTEM_TABLE and returns the number of ASCII\r
211 characters that printed to ConOut. If the length of the formatted ASCII\r
212 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
213 PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
f80b0830 214 If Format is NULL, then ASSERT().\r
e386b444 215\r
216 @param Format Null-terminated ASCII format string.\r
217 @param ... VARARG list consumed to process Format.\r
f80b0830 218 \r
219 @return The number of Ascii characters in the produced\r
220 output buffer not including the Null-terminator.\r
e386b444 221\r
222**/\r
223UINTN\r
224EFIAPI\r
225AsciiPrint (\r
226 IN CONST CHAR8 *Format,\r
227 ...\r
228 )\r
229{\r
230 VA_LIST Marker;\r
231 UINTN Return;\r
9edc73ad 232 ASSERT (Format != NULL);\r
233 \r
e386b444 234 VA_START (Marker, Format);\r
235\r
236 Return = AsciiInternalPrint( Format, gST->ConOut, Marker);\r
237\r
238 VA_END (Marker);\r
239\r
240 return Return;\r
241}\r
242\r
243/**\r
244 Prints a formatted ASCII string to the console output device specified by\r
245 StdErr defined in the EFI_SYSTEM_TABLE.\r
246\r
247 This function prints a formatted ASCII string to the console output device\r
248 specified by StdErr in EFI_SYSTEM_TABLE and returns the number of ASCII\r
249 characters that printed to StdErr. If the length of the formatted ASCII\r
250 string is greater than PcdUefiLibMaxPrintBufferSize, then only the first\r
251 PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
f80b0830 252 If Format is NULL, then ASSERT().\r
e386b444 253\r
254 @param Format Null-terminated ASCII format string.\r
255 @param ... VARARG list consumed to process Format.\r
f80b0830 256 \r
257 @return The number of Ascii characters in the produced output\r
258 buffer not including the Null-terminator.\r
e386b444 259\r
260**/\r
261UINTN\r
262EFIAPI\r
263AsciiErrorPrint (\r
264 IN CONST CHAR8 *Format,\r
265 ...\r
266 )\r
267{\r
268 VA_LIST Marker;\r
269 UINTN Return;\r
270\r
9edc73ad 271 ASSERT (Format != NULL);\r
272 \r
e386b444 273 VA_START (Marker, Format);\r
274\r
275 Return = AsciiInternalPrint( Format, gST->StdErr, Marker);\r
276\r
277 VA_END (Marker);\r
278\r
279 return Return;\r
280}\r
281\r