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