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