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