]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/SetupBrowserDxe/Print.c
Clean up DEC files:
[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
e5eed7d3
HT
18Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>\r
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
155\r
156 VA_START (Args, Fmt);\r
157 return PrintInternal ((UINTN) -1, (UINTN) -1, gST->ConOut, Fmt, Args);\r
158}\r
159\r
160\r
161/**\r
162 Prints a unicode string to the default console,\r
163 using L"%s" format.\r
164\r
165 @param String String pointer.\r
166\r
167 @return Length of string printed to the console\r
168\r
169**/\r
170UINTN\r
171PrintString (\r
172 IN CHAR16 *String\r
173 )\r
174{\r
175 return ConsolePrint (L"%s", String);\r
176}\r
177\r
178\r
179/**\r
180 Prints a chracter to the default console,\r
181 using L"%c" format.\r
182\r
183 @param Character Character to print.\r
184\r
185 @return Length of string printed to the console.\r
186\r
187**/\r
188UINTN\r
189PrintChar (\r
190 CHAR16 Character\r
191 )\r
192{\r
193 return ConsolePrint (L"%c", Character);\r
194}\r
195\r
196\r
197/**\r
198 Prints a formatted unicode string to the default console, at\r
199 the supplied cursor position.\r
200\r
201 @param Column The cursor position to print the string at.\r
202 @param Row The cursor position to print the string at.\r
203 @param Fmt Format string.\r
204 @param ... Variable argument list for format string.\r
205\r
206 @return Length of string printed to the console\r
207\r
208**/\r
209UINTN\r
8091267c 210EFIAPI\r
7936fb6a 211PrintAt (\r
212 IN UINTN Column,\r
213 IN UINTN Row,\r
214 IN CHAR16 *Fmt,\r
215 ...\r
216 )\r
217{\r
218 VA_LIST Args;\r
219\r
220 VA_START (Args, Fmt);\r
221 return PrintInternal (Column, Row, gST->ConOut, Fmt, Args);\r
222}\r
223\r
224\r
225/**\r
226 Prints a unicode string to the default console, at\r
227 the supplied cursor position, using L"%s" format.\r
228\r
229 @param Column The cursor position to print the string at.\r
230 @param Row The cursor position to print the string at\r
231 @param String String pointer.\r
232\r
233 @return Length of string printed to the console\r
234\r
235**/\r
236UINTN\r
237PrintStringAt (\r
238 IN UINTN Column,\r
239 IN UINTN Row,\r
7064c0a5 240 IN CHAR16 *String\r
7936fb6a 241 )\r
242{\r
243 return PrintAt (Column, Row, L"%s", String);\r
244}\r
245\r
246\r
247/**\r
248 Prints a chracter to the default console, at\r
249 the supplied cursor position, using L"%c" format.\r
250\r
251 @param Column The cursor position to print the string at.\r
252 @param Row The cursor position to print the string at.\r
253 @param Character Character to print.\r
254\r
255 @return Length of string printed to the console.\r
256\r
257**/\r
258UINTN\r
259PrintCharAt (\r
260 IN UINTN Column,\r
261 IN UINTN Row,\r
262 CHAR16 Character\r
263 )\r
264{\r
265 return PrintAt (Column, Row, L"%c", Character);\r
266}\r