Port DriverSample.inf, HiiDatabase.inf and SetupBrowser.inf
[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 //
36 // Include common header file for this module.
37 //
38 #include "CommonHeader.h"
39
40 #include "Print.h"
41
42 STATIC
43 UINTN
44 _IPrint (
45 IN UINTN Column,
46 IN UINTN Row,
47 IN EFI_SIMPLE_TEXT_OUT_PROTOCOL *Out,
48 IN CHAR16 *fmt,
49 IN VA_LIST args
50 )
51 //
52 // Display string worker for: Print, PrintAt, IPrint, IPrintAt
53 //
54 {
55 CHAR16 *Buffer;
56 CHAR16 *BackupBuffer;
57 UINTN Index;
58 UINTN PreviousIndex;
59
60 //
61 // For now, allocate an arbitrarily long buffer
62 //
63 Buffer = AllocateZeroPool (0x10000);
64 BackupBuffer = AllocateZeroPool (0x10000);
65 ASSERT (Buffer);
66 ASSERT (BackupBuffer);
67
68 if (Column != (UINTN) -1) {
69 Out->SetCursorPosition (Out, Column, Row);
70 }
71
72 UnicodeVSPrint (Buffer, 0x10000, fmt, args);
73
74 Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
75
76 Out->SetAttribute (Out, Out->Mode->Attribute);
77
78 Index = 0;
79 PreviousIndex = 0;
80
81 do {
82 for (; (Buffer[Index] != NARROW_CHAR) && (Buffer[Index] != WIDE_CHAR) && (Buffer[Index] != 0); Index++) {
83 BackupBuffer[Index] = Buffer[Index];
84 }
85
86 if (Buffer[Index] == 0) {
87 break;
88 }
89 //
90 // Null-terminate the temporary string
91 //
92 BackupBuffer[Index] = 0;
93
94 //
95 // Print this out, we are about to switch widths
96 //
97 Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
98
99 //
100 // Preserve the current index + 1, since this is where we will start printing from next
101 //
102 PreviousIndex = Index + 1;
103
104 //
105 // We are at a narrow or wide character directive. Set attributes and strip it and print it
106 //
107 if (Buffer[Index] == NARROW_CHAR) {
108 //
109 // Preserve bits 0 - 6 and zero out the rest
110 //
111 Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
112 Out->SetAttribute (Out, Out->Mode->Attribute);
113 } else {
114 //
115 // Must be wide, set bit 7 ON
116 //
117 Out->Mode->Attribute = Out->Mode->Attribute | EFI_WIDE_ATTRIBUTE;
118 Out->SetAttribute (Out, Out->Mode->Attribute);
119 }
120
121 Index++;
122
123 } while (Buffer[Index] != 0);
124
125 //
126 // We hit the end of the string - print it
127 //
128 Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
129
130 FreePool (Buffer);
131 FreePool (BackupBuffer);
132 return EFI_SUCCESS;
133 }
134
135 UINTN
136 Print (
137 IN CHAR16 *fmt,
138 ...
139 )
140 /*++
141
142 Routine Description:
143
144 Prints a formatted unicode string to the default console
145
146 Arguments:
147
148 fmt - Format string
149
150 Returns:
151
152 Length of string printed to the console
153
154 --*/
155 {
156 VA_LIST args;
157
158 VA_START (args, fmt);
159 return _IPrint ((UINTN) -1, (UINTN) -1, gST->ConOut, fmt, args);
160 }
161
162 UINTN
163 PrintString (
164 CHAR16 *String
165 )
166 /*++
167
168 Routine Description:
169
170 Prints a unicode string to the default console,
171 using L"%s" format.
172
173 Arguments:
174
175 String - String pointer.
176
177 Returns:
178
179 Length of string printed to the console
180
181 --*/
182 {
183 return Print ((CHAR16 *) L"%s", String);
184 }
185
186 UINTN
187 PrintChar (
188 CHAR16 Character
189 )
190 /*++
191
192 Routine Description:
193
194 Prints a chracter to the default console,
195 using L"%c" format.
196
197 Arguments:
198
199 Character - Character to print.
200
201 Returns:
202
203 Length of string printed to the console.
204
205 --*/
206 {
207 return Print ((CHAR16 *) L"%c", Character);
208 }
209
210 UINTN
211 PrintAt (
212 IN UINTN Column,
213 IN UINTN Row,
214 IN CHAR16 *fmt,
215 ...
216 )
217 /*++
218
219 Routine Description:
220
221 Prints a formatted unicode string to the default console, at
222 the supplied cursor position
223
224 Arguments:
225
226 Column, Row - The cursor position to print the string at
227
228 fmt - Format string
229
230 Returns:
231
232 Length of string printed to the console
233
234 --*/
235 {
236 VA_LIST args;
237
238 VA_START (args, fmt);
239 return _IPrint (Column, Row, gST->ConOut, fmt, args);
240 }
241
242 UINTN
243 PrintStringAt (
244 IN UINTN Column,
245 IN UINTN Row,
246 CHAR16 *String
247 )
248 /*++
249
250 Routine Description:
251
252 Prints a unicode string to the default console, at
253 the supplied cursor position, using L"%s" format.
254
255 Arguments:
256
257 Column, Row - The cursor position to print the string at
258
259 String - String pointer.
260
261 Returns:
262
263 Length of string printed to the console
264
265 --*/
266 {
267 return PrintAt (Column, Row, (CHAR16 *) L"%s", String);
268 }
269
270 UINTN
271 PrintCharAt (
272 IN UINTN Column,
273 IN UINTN Row,
274 CHAR16 Character
275 )
276 /*++
277
278 Routine Description:
279
280 Prints a chracter to the default console, at
281 the supplied cursor position, using L"%c" format.
282
283 Arguments:
284
285 Column, Row - The cursor position to print the string at
286
287 Character - Character to print.
288
289 Returns:
290
291 Length of string printed to the console.
292
293 --*/
294 {
295 return PrintAt (Column, Row, (CHAR16 *) L"%c", Character);
296 }
297
298