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