]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Print.c
8633e618481bb6a47b046156936eed704e058ba8
[mirror_edk2.git] / MdeModulePkg / 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
18 Copyright (c) 2004 - 2007, Intel Corporation
19 All rights reserved. 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 ConsolePrint (
149 IN CHAR16 *Fmt,
150 ...
151 )
152 {
153 VA_LIST Args;
154
155 VA_START (Args, Fmt);
156 return PrintInternal ((UINTN) -1, (UINTN) -1, gST->ConOut, Fmt, Args);
157 }
158
159
160 /**
161 Prints a unicode string to the default console,
162 using L"%s" format.
163
164 @param String String pointer.
165
166 @return Length of string printed to the console
167
168 **/
169 UINTN
170 PrintString (
171 IN CHAR16 *String
172 )
173 {
174 return ConsolePrint (L"%s", String);
175 }
176
177
178 /**
179 Prints a chracter to the default console,
180 using L"%c" format.
181
182 @param Character Character to print.
183
184 @return Length of string printed to the console.
185
186 **/
187 UINTN
188 PrintChar (
189 CHAR16 Character
190 )
191 {
192 return ConsolePrint (L"%c", Character);
193 }
194
195
196 /**
197 Prints a formatted unicode string to the default console, at
198 the supplied cursor position.
199
200 @param Column The cursor position to print the string at.
201 @param Row The cursor position to print the string at.
202 @param Fmt Format string.
203 @param ... Variable argument list for format string.
204
205 @return Length of string printed to the console
206
207 **/
208 UINTN
209 PrintAt (
210 IN UINTN Column,
211 IN UINTN Row,
212 IN CHAR16 *Fmt,
213 ...
214 )
215 {
216 VA_LIST Args;
217
218 VA_START (Args, Fmt);
219 return PrintInternal (Column, Row, gST->ConOut, Fmt, Args);
220 }
221
222
223 /**
224 Prints a unicode string to the default console, at
225 the supplied cursor position, using L"%s" format.
226
227 @param Column The cursor position to print the string at.
228 @param Row The cursor position to print the string at
229 @param String String pointer.
230
231 @return Length of string printed to the console
232
233 **/
234 UINTN
235 PrintStringAt (
236 IN UINTN Column,
237 IN UINTN Row,
238 IN CHAR16 *String
239 )
240 {
241 return PrintAt (Column, Row, L"%s", String);
242 }
243
244
245 /**
246 Prints a chracter to the default console, at
247 the supplied cursor position, using L"%c" format.
248
249 @param Column The cursor position to print the string at.
250 @param Row The cursor position to print the string at.
251 @param Character Character to print.
252
253 @return Length of string printed to the console.
254
255 **/
256 UINTN
257 PrintCharAt (
258 IN UINTN Column,
259 IN UINTN Row,
260 CHAR16 Character
261 )
262 {
263 return PrintAt (Column, Row, L"%c", Character);
264 }