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 |
|
---|
18 | Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
|
---|
19 | This program and the accompanying materials
|
---|
20 | are licensed and made available under the terms and conditions of the BSD License
|
---|
21 | which accompanies this distribution. The full text of the license may be found at
|
---|
22 | http://opensource.org/licenses/bsd-license.php
|
---|
23 |
|
---|
24 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
25 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
26 |
|
---|
27 | **/
|
---|
28 |
|
---|
29 | #include "Setup.h"
|
---|
30 |
|
---|
31 | /**
|
---|
32 | The internal function prints to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
|
---|
33 | protocol instance.
|
---|
34 |
|
---|
35 | @param Column The position of the output string.
|
---|
36 | @param Row The position of the output string.
|
---|
37 | @param Out The EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.
|
---|
38 | @param Fmt The format string.
|
---|
39 | @param Args The additional argument for the variables in the format string.
|
---|
40 |
|
---|
41 | @return Number of Unicode character printed.
|
---|
42 |
|
---|
43 | **/
|
---|
44 | UINTN
|
---|
45 | PrintInternal (
|
---|
46 | IN UINTN Column,
|
---|
47 | IN UINTN Row,
|
---|
48 | IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Out,
|
---|
49 | IN CHAR16 *Fmt,
|
---|
50 | IN VA_LIST Args
|
---|
51 | )
|
---|
52 | {
|
---|
53 | CHAR16 *Buffer;
|
---|
54 | CHAR16 *BackupBuffer;
|
---|
55 | UINTN Index;
|
---|
56 | UINTN PreviousIndex;
|
---|
57 | UINTN Count;
|
---|
58 |
|
---|
59 | //
|
---|
60 | // For now, allocate an arbitrarily long buffer
|
---|
61 | //
|
---|
62 | Buffer = AllocateZeroPool (0x10000);
|
---|
63 | BackupBuffer = AllocateZeroPool (0x10000);
|
---|
64 | ASSERT (Buffer);
|
---|
65 | ASSERT (BackupBuffer);
|
---|
66 |
|
---|
67 | if (Column != (UINTN) -1) {
|
---|
68 | Out->SetCursorPosition (Out, Column, Row);
|
---|
69 | }
|
---|
70 |
|
---|
71 | UnicodeVSPrint (Buffer, 0x10000, Fmt, Args);
|
---|
72 |
|
---|
73 | Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
|
---|
74 |
|
---|
75 | Out->SetAttribute (Out, Out->Mode->Attribute);
|
---|
76 |
|
---|
77 | Index = 0;
|
---|
78 | PreviousIndex = 0;
|
---|
79 | Count = 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 | Count += StrLen (&BackupBuffer[PreviousIndex]);
|
---|
99 |
|
---|
100 | //
|
---|
101 | // Preserve the current index + 1, since this is where we will start printing from next
|
---|
102 | //
|
---|
103 | PreviousIndex = Index + 1;
|
---|
104 |
|
---|
105 | //
|
---|
106 | // We are at a narrow or wide character directive. Set attributes and strip it and print it
|
---|
107 | //
|
---|
108 | if (Buffer[Index] == NARROW_CHAR) {
|
---|
109 | //
|
---|
110 | // Preserve bits 0 - 6 and zero out the rest
|
---|
111 | //
|
---|
112 | Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
|
---|
113 | Out->SetAttribute (Out, Out->Mode->Attribute);
|
---|
114 | } else {
|
---|
115 | //
|
---|
116 | // Must be wide, set bit 7 ON
|
---|
117 | //
|
---|
118 | Out->Mode->Attribute = Out->Mode->Attribute | EFI_WIDE_ATTRIBUTE;
|
---|
119 | Out->SetAttribute (Out, Out->Mode->Attribute);
|
---|
120 | }
|
---|
121 |
|
---|
122 | Index++;
|
---|
123 |
|
---|
124 | } while (Buffer[Index] != 0);
|
---|
125 |
|
---|
126 | //
|
---|
127 | // We hit the end of the string - print it
|
---|
128 | //
|
---|
129 | Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
|
---|
130 | Count += StrLen (&BackupBuffer[PreviousIndex]);
|
---|
131 |
|
---|
132 | FreePool (Buffer);
|
---|
133 | FreePool (BackupBuffer);
|
---|
134 | return Count;
|
---|
135 | }
|
---|
136 |
|
---|
137 |
|
---|
138 | /**
|
---|
139 | Prints a formatted unicode string to the default console.
|
---|
140 |
|
---|
141 | @param Fmt Format string
|
---|
142 | @param ... Variable argument list for format string.
|
---|
143 |
|
---|
144 | @return Length of string printed to the console.
|
---|
145 |
|
---|
146 | **/
|
---|
147 | UINTN
|
---|
148 | EFIAPI
|
---|
149 | ConsolePrint (
|
---|
150 | IN CHAR16 *Fmt,
|
---|
151 | ...
|
---|
152 | )
|
---|
153 | {
|
---|
154 | VA_LIST Args;
|
---|
155 | UINTN LengthOfPrinted;
|
---|
156 |
|
---|
157 | VA_START (Args, Fmt);
|
---|
158 | LengthOfPrinted = PrintInternal ((UINTN) -1, (UINTN) -1, gST->ConOut, Fmt, Args);
|
---|
159 | VA_END (Args);
|
---|
160 | return LengthOfPrinted;
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | /**
|
---|
165 | Prints a unicode string to the default console,
|
---|
166 | using L"%s" format.
|
---|
167 |
|
---|
168 | @param String String pointer.
|
---|
169 |
|
---|
170 | @return Length of string printed to the console
|
---|
171 |
|
---|
172 | **/
|
---|
173 | UINTN
|
---|
174 | PrintString (
|
---|
175 | IN CHAR16 *String
|
---|
176 | )
|
---|
177 | {
|
---|
178 | return ConsolePrint (L"%s", String);
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | /**
|
---|
183 | Prints a chracter to the default console,
|
---|
184 | using L"%c" format.
|
---|
185 |
|
---|
186 | @param Character Character to print.
|
---|
187 |
|
---|
188 | @return Length of string printed to the console.
|
---|
189 |
|
---|
190 | **/
|
---|
191 | UINTN
|
---|
192 | PrintChar (
|
---|
193 | CHAR16 Character
|
---|
194 | )
|
---|
195 | {
|
---|
196 | return ConsolePrint (L"%c", Character);
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 | /**
|
---|
201 | Prints a formatted unicode string to the default console, at
|
---|
202 | the supplied cursor position.
|
---|
203 |
|
---|
204 | @param Column The cursor position to print the string at.
|
---|
205 | @param Row The cursor position to print the string at.
|
---|
206 | @param Fmt Format string.
|
---|
207 | @param ... Variable argument list for format string.
|
---|
208 |
|
---|
209 | @return Length of string printed to the console
|
---|
210 |
|
---|
211 | **/
|
---|
212 | UINTN
|
---|
213 | EFIAPI
|
---|
214 | PrintAt (
|
---|
215 | IN UINTN Column,
|
---|
216 | IN UINTN Row,
|
---|
217 | IN CHAR16 *Fmt,
|
---|
218 | ...
|
---|
219 | )
|
---|
220 | {
|
---|
221 | VA_LIST Args;
|
---|
222 | UINTN LengthOfPrinted;
|
---|
223 |
|
---|
224 | VA_START (Args, Fmt);
|
---|
225 | LengthOfPrinted = PrintInternal (Column, Row, gST->ConOut, Fmt, Args);
|
---|
226 | VA_END (Args);
|
---|
227 | return LengthOfPrinted;
|
---|
228 | }
|
---|
229 |
|
---|
230 |
|
---|
231 | /**
|
---|
232 | Prints a unicode string to the default console, at
|
---|
233 | the supplied cursor position, using L"%s" format.
|
---|
234 |
|
---|
235 | @param Column The cursor position to print the string at.
|
---|
236 | @param Row The cursor position to print the string at
|
---|
237 | @param String String pointer.
|
---|
238 |
|
---|
239 | @return Length of string printed to the console
|
---|
240 |
|
---|
241 | **/
|
---|
242 | UINTN
|
---|
243 | PrintStringAt (
|
---|
244 | IN UINTN Column,
|
---|
245 | IN UINTN Row,
|
---|
246 | IN CHAR16 *String
|
---|
247 | )
|
---|
248 | {
|
---|
249 | return PrintAt (Column, Row, L"%s", String);
|
---|
250 | }
|
---|
251 |
|
---|
252 |
|
---|
253 | /**
|
---|
254 | Prints a chracter to the default console, at
|
---|
255 | the supplied cursor position, using L"%c" format.
|
---|
256 |
|
---|
257 | @param Column The cursor position to print the string at.
|
---|
258 | @param Row The cursor position to print the string at.
|
---|
259 | @param Character Character to print.
|
---|
260 |
|
---|
261 | @return Length of string printed to the console.
|
---|
262 |
|
---|
263 | **/
|
---|
264 | UINTN
|
---|
265 | PrintCharAt (
|
---|
266 | IN UINTN Column,
|
---|
267 | IN UINTN Row,
|
---|
268 | CHAR16 Character
|
---|
269 | )
|
---|
270 | {
|
---|
271 | return PrintAt (Column, Row, L"%c", Character);
|
---|
272 | }
|
---|