]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/SetupBrowserDxe/Print.c
Add Missing invocations to VA_END() for VA_START().
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Print.c
CommitLineData
7936fb6a 1/** @file\r
2Basic Ascii AvSPrintf() function named VSPrint(). VSPrint() enables very\r
3simple implemenation of SPrint() and Print() to support debug.\r
4\r
5You can not Print more than EFI_DRIVER_LIB_MAX_PRINT_BUFFER characters at a\r
6time. This makes the implementation very simple.\r
7\r
8VSPrint, Print, SPrint format specification has the follwoing form\r
9\r
10%type\r
11\r
12type:\r
13 'S','s' - argument is an Unicode string\r
14 'c' - argument is an ascii character\r
15 '%' - Print a %\r
16\r
17\r
3bbe68a3 18Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 19This program and the accompanying materials\r
7936fb6a 20are licensed and made available under the terms and conditions of the BSD License\r
21which accompanies this distribution. The full text of the license may be found at\r
22http://opensource.org/licenses/bsd-license.php\r
23\r
24THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
25WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
26\r
27**/\r
28\r
29#include "Setup.h"\r
30\r
7936fb6a 31/**\r
32 The internal function prints to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r
33 protocol instance.\r
34\r
35 @param Column The position of the output string.\r
36 @param Row The position of the output string.\r
37 @param Out The EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.\r
38 @param Fmt The format string.\r
39 @param Args The additional argument for the variables in the format string.\r
40\r
41 @return Number of Unicode character printed.\r
42\r
43**/\r
44UINTN\r
45PrintInternal (\r
46 IN UINTN Column,\r
47 IN UINTN Row,\r
48 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Out,\r
49 IN CHAR16 *Fmt,\r
50 IN VA_LIST Args\r
51 )\r
52{\r
53 CHAR16 *Buffer;\r
54 CHAR16 *BackupBuffer;\r
55 UINTN Index;\r
56 UINTN PreviousIndex;\r
57 UINTN Count;\r
58\r
59 //\r
60 // For now, allocate an arbitrarily long buffer\r
61 //\r
62 Buffer = AllocateZeroPool (0x10000);\r
63 BackupBuffer = AllocateZeroPool (0x10000);\r
64 ASSERT (Buffer);\r
65 ASSERT (BackupBuffer);\r
66\r
67 if (Column != (UINTN) -1) {\r
68 Out->SetCursorPosition (Out, Column, Row);\r
69 }\r
70\r
71 UnicodeVSPrint (Buffer, 0x10000, Fmt, Args);\r
72\r
73 Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;\r
74\r
75 Out->SetAttribute (Out, Out->Mode->Attribute);\r
76\r
77 Index = 0;\r
78 PreviousIndex = 0;\r
79 Count = 0;\r
80\r
81 do {\r
82 for (; (Buffer[Index] != NARROW_CHAR) && (Buffer[Index] != WIDE_CHAR) && (Buffer[Index] != 0); Index++) {\r
83 BackupBuffer[Index] = Buffer[Index];\r
84 }\r
85\r
86 if (Buffer[Index] == 0) {\r
87 break;\r
88 }\r
89 //\r
90 // Null-terminate the temporary string\r
91 //\r
92 BackupBuffer[Index] = 0;\r
93\r
94 //\r
95 // Print this out, we are about to switch widths\r
96 //\r
97 Out->OutputString (Out, &BackupBuffer[PreviousIndex]);\r
98 Count += StrLen (&BackupBuffer[PreviousIndex]);\r
99\r
100 //\r
101 // Preserve the current index + 1, since this is where we will start printing from next\r
102 //\r
103 PreviousIndex = Index + 1;\r
104\r
105 //\r
106 // We are at a narrow or wide character directive. Set attributes and strip it and print it\r
107 //\r
108 if (Buffer[Index] == NARROW_CHAR) {\r
109 //\r
110 // Preserve bits 0 - 6 and zero out the rest\r
111 //\r
112 Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;\r
113 Out->SetAttribute (Out, Out->Mode->Attribute);\r
114 } else {\r
115 //\r
116 // Must be wide, set bit 7 ON\r
117 //\r
118 Out->Mode->Attribute = Out->Mode->Attribute | EFI_WIDE_ATTRIBUTE;\r
119 Out->SetAttribute (Out, Out->Mode->Attribute);\r
120 }\r
121\r
122 Index++;\r
123\r
124 } while (Buffer[Index] != 0);\r
125\r
126 //\r
127 // We hit the end of the string - print it\r
128 //\r
129 Out->OutputString (Out, &BackupBuffer[PreviousIndex]);\r
130 Count += StrLen (&BackupBuffer[PreviousIndex]);\r
131\r
f4113e1f 132 FreePool (Buffer);\r
133 FreePool (BackupBuffer);\r
7936fb6a 134 return Count;\r
135}\r
136\r
137\r
138/**\r
139 Prints a formatted unicode string to the default console.\r
140\r
141 @param Fmt Format string\r
142 @param ... Variable argument list for format string.\r
143\r
144 @return Length of string printed to the console.\r
145\r
146**/\r
147UINTN\r
8091267c 148EFIAPI\r
7936fb6a 149ConsolePrint (\r
150 IN CHAR16 *Fmt,\r
7064c0a5 151 ...\r
7936fb6a 152 )\r
153{\r
154 VA_LIST Args;\r
3bbe68a3 155 UINTN LengthOfPrinted;\r
7936fb6a 156\r
157 VA_START (Args, Fmt);\r
3bbe68a3 158 LengthOfPrinted = PrintInternal ((UINTN) -1, (UINTN) -1, gST->ConOut, Fmt, Args);\r
159 VA_END (Args);\r
160 return LengthOfPrinted;\r
7936fb6a 161}\r
162\r
163\r
164/**\r
165 Prints a unicode string to the default console,\r
166 using L"%s" format.\r
167\r
168 @param String String pointer.\r
169\r
170 @return Length of string printed to the console\r
171\r
172**/\r
173UINTN\r
174PrintString (\r
175 IN CHAR16 *String\r
176 )\r
177{\r
178 return ConsolePrint (L"%s", String);\r
179}\r
180\r
181\r
182/**\r
183 Prints a chracter to the default console,\r
184 using L"%c" format.\r
185\r
186 @param Character Character to print.\r
187\r
188 @return Length of string printed to the console.\r
189\r
190**/\r
191UINTN\r
192PrintChar (\r
193 CHAR16 Character\r
194 )\r
195{\r
196 return ConsolePrint (L"%c", Character);\r
197}\r
198\r
199\r
200/**\r
201 Prints a formatted unicode string to the default console, at\r
202 the supplied cursor position.\r
203\r
204 @param Column The cursor position to print the string at.\r
205 @param Row The cursor position to print the string at.\r
206 @param Fmt Format string.\r
207 @param ... Variable argument list for format string.\r
208\r
209 @return Length of string printed to the console\r
210\r
211**/\r
212UINTN\r
8091267c 213EFIAPI\r
7936fb6a 214PrintAt (\r
215 IN UINTN Column,\r
216 IN UINTN Row,\r
217 IN CHAR16 *Fmt,\r
218 ...\r
219 )\r
220{\r
221 VA_LIST Args;\r
3bbe68a3 222 UINTN LengthOfPrinted;\r
7936fb6a 223\r
224 VA_START (Args, Fmt);\r
3bbe68a3 225 LengthOfPrinted = PrintInternal (Column, Row, gST->ConOut, Fmt, Args);\r
226 VA_END (Args);\r
227 return LengthOfPrinted;\r
7936fb6a 228}\r
229\r
230\r
231/**\r
232 Prints a unicode string to the default console, at\r
233 the supplied cursor position, using L"%s" format.\r
234\r
235 @param Column The cursor position to print the string at.\r
236 @param Row The cursor position to print the string at\r
237 @param String String pointer.\r
238\r
239 @return Length of string printed to the console\r
240\r
241**/\r
242UINTN\r
243PrintStringAt (\r
244 IN UINTN Column,\r
245 IN UINTN Row,\r
7064c0a5 246 IN CHAR16 *String\r
7936fb6a 247 )\r
248{\r
249 return PrintAt (Column, Row, L"%s", String);\r
250}\r
251\r
252\r
253/**\r
254 Prints a chracter to the default console, at\r
255 the supplied cursor position, using L"%c" format.\r
256\r
257 @param Column The cursor position to print the string at.\r
258 @param Row The cursor position to print the string at.\r
259 @param Character Character to print.\r
260\r
261 @return Length of string printed to the console.\r
262\r
263**/\r
264UINTN\r
265PrintCharAt (\r
266 IN UINTN Column,\r
267 IN UINTN Row,\r
268 CHAR16 Character\r
269 )\r
270{\r
271 return PrintAt (Column, Row, L"%c", Character);\r
272}\r