]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/SetupBrowserDxe/Print.c
Update to follow doxygen style file header.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Print.c
CommitLineData
93e3992d 1/** @file
2
3Copyright (c) 2004 - 2007, Intel Corporation
4All rights reserved. This program and the accompanying materials
5are licensed and made available under the terms and conditions of the BSD License
6which accompanies this distribution. The full text of the license may be found at
7http://opensource.org/licenses/bsd-license.php
8
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12Module Name:
13
14 Print.c
15
16Abstract:
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//@MT:#include "Tiano.h"
37//@MT:#include "EfiDriverLib.h"
38//@MT:#include "EfiPrintLib.h"
39//@MT:#include "EfiStdArg.h"
40//@MT:#include "TianoHii.h"
41#include "Setup.h"
42
43UINTN
44ValueToString (
45 IN OUT CHAR16 *Buffer,
46 IN BOOLEAN Flags,
47 IN INT64 Value
48 );
49
50UINTN
51PrintInternal (
52 IN UINTN Column,
53 IN UINTN Row,
54 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Out,
55 IN CHAR16 *fmt,
56 IN VA_LIST args
57 )
58//
59// Display string worker for: Print, PrintAt, IPrint, IPrintAt
60//
61{
62 CHAR16 *Buffer;
63 CHAR16 *BackupBuffer;
64 UINTN Index;
65 UINTN PreviousIndex;
66
67 //
68 // For now, allocate an arbitrarily long buffer
69 //
70 Buffer = AllocateZeroPool (0x10000);
71 BackupBuffer = AllocateZeroPool (0x10000);
72 ASSERT (Buffer);
73 ASSERT (BackupBuffer);
74
75 if (Column != (UINTN) -1) {
76 Out->SetCursorPosition (Out, Column, Row);
77 }
78
79 UnicodeVSPrint (Buffer, 0x10000, fmt, args);
80
81 Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
82
83 Out->SetAttribute (Out, Out->Mode->Attribute);
84
85 Index = 0;
86 PreviousIndex = 0;
87
88 do {
89 for (; (Buffer[Index] != NARROW_CHAR) && (Buffer[Index] != WIDE_CHAR) && (Buffer[Index] != 0); Index++) {
90 BackupBuffer[Index] = Buffer[Index];
91 }
92
93 if (Buffer[Index] == 0) {
94 break;
95 }
96 //
97 // Null-terminate the temporary string
98 //
99 BackupBuffer[Index] = 0;
100
101 //
102 // Print this out, we are about to switch widths
103 //
104 Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
105
106 //
107 // Preserve the current index + 1, since this is where we will start printing from next
108 //
109 PreviousIndex = Index + 1;
110
111 //
112 // We are at a narrow or wide character directive. Set attributes and strip it and print it
113 //
114 if (Buffer[Index] == NARROW_CHAR) {
115 //
116 // Preserve bits 0 - 6 and zero out the rest
117 //
118 Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
119 Out->SetAttribute (Out, Out->Mode->Attribute);
120 } else {
121 //
122 // Must be wide, set bit 7 ON
123 //
124 Out->Mode->Attribute = Out->Mode->Attribute | EFI_WIDE_ATTRIBUTE;
125 Out->SetAttribute (Out, Out->Mode->Attribute);
126 }
127
128 Index++;
129
130 } while (Buffer[Index] != 0);
131
132 //
133 // We hit the end of the string - print it
134 //
135 Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
136
137 gBS->FreePool (Buffer);
138 gBS->FreePool (BackupBuffer);
139 return EFI_SUCCESS;
140}
141
142
143/**
144 Prints a formatted unicode string to the default console
145
146 @param fmt Format string
147
148 @return Length of string printed to the console
149
150**/
151UINTN
152ConsolePrint (
153 IN CHAR16 *fmt,
154 ...
155 )
156{
157 VA_LIST args;
158
159 VA_START (args, fmt);
160 return PrintInternal ((UINTN) -1, (UINTN) -1, gST->ConOut, fmt, args);
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**/
173UINTN
174PrintString (
175 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**/
191UINTN
192PrintChar (
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 Row The cursor position to print the string at
205 @param fmt Format string
206
207 @return Length of string printed to the console
208
209**/
210UINTN
211PrintAt (
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 Row The cursor position to print the string at
230 @param String String pointer.
231
232 @return Length of string printed to the console
233
234**/
235UINTN
236PrintStringAt (
237 IN UINTN Column,
238 IN UINTN Row,
239 CHAR16 *String
240 )
241{
242 return PrintAt (Column, Row, L"%s", String);
243}
244
245
246/**
247 Prints a chracter to the default console, at
248 the supplied cursor position, using L"%c" format.
249
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**/
256UINTN
257PrintCharAt (
258 IN UINTN Column,
259 IN UINTN Row,
260 CHAR16 Character
261 )
262{
263 return PrintAt (Column, Row, L"%c", Character);
264}
265
266
267/**
268 VSPrint worker function that prints a Value as a decimal number in Buffer
269
270 @param Buffer Location to place ascii decimal number string of Value.
271 @param Value Decimal value to convert to a string in Buffer.
272 @param Flags Flags to use in printing decimal string, see file header for
273 details.
274
275 @return Number of characters printed.
276
277**/
278UINTN
279ValueToString (
280 IN OUT CHAR16 *Buffer,
281 IN BOOLEAN Flags,
282 IN INT64 Value
283 )
284{
285 CHAR16 TempBuffer[30];
286 CHAR16 *TempStr;
287 CHAR16 *BufferPtr;
288 UINTN Count;
289 UINTN NumberCount;
290 UINT32 Remainder;
291 BOOLEAN Negative;
292
293 Negative = FALSE;
294 TempStr = TempBuffer;
295 BufferPtr = Buffer;
296 Count = 0;
297 NumberCount = 0;
298
299 if (Value < 0) {
300 Negative = TRUE;
301 Value = -Value;
302 }
303
304 do {
305 Value = (INT64) DivU64x32Remainder ((UINT64) Value, 10, &Remainder);
306 *(TempStr++) = (CHAR16) (Remainder + '0');
307 Count++;
308 NumberCount++;
309 if ((Flags & COMMA_TYPE) == COMMA_TYPE) {
310 if (NumberCount % 3 == 0 && Value != 0) {
311 *(TempStr++) = ',';
312 Count++;
313 }
314 }
315 } while (Value != 0);
316
317 if (Negative) {
318 *(BufferPtr++) = '-';
319 Count++;
320 }
321
322 //
323 // Reverse temp string into Buffer.
324 //
325 while (TempStr != TempBuffer) {
326 *(BufferPtr++) = *(--TempStr);
327 }
328
329 *BufferPtr = 0;
330 return Count;
331}