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