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