]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c
1) Add BufToHexString, HexStringToBuf and IsHexDigit to BaseLib.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / Strings.c
1 /**@file
2
3 This file contains the keyboard processing code to the HII database.
4
5 Copyright (c) 2006 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16
17 #include "HiiDatabase.h"
18
19 EFI_STATUS
20 EFIAPI
21 HiiTestString (
22 IN EFI_HII_PROTOCOL *This,
23 IN CHAR16 *StringToTest,
24 IN OUT UINT32 *FirstMissing,
25 OUT UINT32 *GlyphBufferSize
26 )
27 /*++
28
29 Routine Description:
30 Test if all of the characters in a string have corresponding font characters.
31
32 Arguments:
33
34 Returns:
35
36 --*/
37 {
38 ASSERT (FALSE);
39 return EFI_SUCCESS;
40 }
41
42 EFI_STATUS
43 GetTagGuidByFrameworkHiiHandle (
44 IN CONST EFI_HII_THUNK_PRIVATE_DATA *Private,
45 IN FRAMEWORK_EFI_HII_HANDLE FrameworkHiiHandle,
46 OUT EFI_GUID *TagGuid
47 )
48 {
49 LIST_ENTRY *ListEntry;
50 HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY *HandleMapEntry;
51
52 ASSERT (TagGuid != NULL);
53
54 for (ListEntry = Private->HiiThunkHandleMappingDBListHead.ForwardLink;
55 ListEntry != &Private->HiiThunkHandleMappingDBListHead;
56 ListEntry = ListEntry->ForwardLink
57 ) {
58
59 HandleMapEntry = HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY_FROM_LISTENTRY (ListEntry);
60
61 if (FrameworkHiiHandle == HandleMapEntry->FrameworkHiiHandle) {
62 CopyGuid (TagGuid, &HandleMapEntry->TagGuid);
63 return EFI_SUCCESS;
64 }
65 }
66
67 return EFI_NOT_FOUND;
68 }
69
70 EFI_STATUS
71 HiiThunkNewStringForAllStringPackages (
72 IN CONST EFI_HII_THUNK_PRIVATE_DATA *Private,
73 OUT CONST EFI_GUID *TagGuid,
74 IN CHAR16 *Language,
75 IN OUT STRING_REF *Reference,
76 IN CHAR16 *NewString
77 )
78 {
79 EFI_STATUS Status;
80 LIST_ENTRY *ListEntry;
81 HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY *HandleMapEntry;
82 EFI_STRING_ID StringId1;
83 EFI_STRING_ID StringId2;
84 CHAR8 *AsciiLanguage;
85 BOOLEAN Found;
86
87 ASSERT (TagGuid != NULL);
88
89 StringId1 = (EFI_STRING_ID) 0;
90 StringId2 = (EFI_STRING_ID) 0;
91 Found = FALSE;
92
93 if (Language == NULL) {
94 AsciiLanguage = NULL;
95 } else {
96 AsciiLanguage = AllocateZeroPool (StrLen (Language) + 1);
97 UnicodeStrToAsciiStr (Language, AsciiLanguage);
98 }
99
100 for (ListEntry = Private->HiiThunkHandleMappingDBListHead.ForwardLink;
101 ListEntry != &Private->HiiThunkHandleMappingDBListHead;
102 ListEntry = ListEntry->ForwardLink
103 ) {
104
105 HandleMapEntry = HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY_FROM_LISTENTRY (ListEntry);
106
107 if (CompareGuid (TagGuid, &HandleMapEntry->TagGuid)) {
108 Found = TRUE;
109 if (*Reference == 0) {
110 if (AsciiLanguage == NULL) {
111 Status = HiiLibNewString (HandleMapEntry->UefiHiiHandle, &StringId2, NewString);
112 } else {
113 Status = mHiiStringProtocol->NewString (
114 mHiiStringProtocol,
115 HandleMapEntry->UefiHiiHandle,
116 &StringId2,
117 AsciiLanguage,
118 NULL,
119 NewString,
120 NULL
121 );
122 }
123 } else {
124 if (AsciiLanguage == NULL) {
125 Status = HiiLibSetString (HandleMapEntry->UefiHiiHandle, *Reference, NewString);
126 } else {
127 Status = mHiiStringProtocol->SetString (
128 mHiiStringProtocol,
129 HandleMapEntry->UefiHiiHandle,
130 *Reference,
131 AsciiLanguage,
132 NewString,
133 NULL
134 );
135 }
136 }
137 if (EFI_ERROR (Status)) {
138 return Status;
139 }
140 if (*Reference == 0) {
141 if (StringId1 == (EFI_STRING_ID) 0) {
142 StringId1 = StringId2;
143 } else {
144 if (StringId1 != StringId2) {
145 ASSERT(FALSE);
146 return EFI_INVALID_PARAMETER;
147 }
148 }
149 }
150 }
151 }
152
153 if (Found) {
154 *Reference = StringId1;
155 Status = EFI_SUCCESS;
156 } else {
157 ASSERT (FALSE);
158 Status = EFI_NOT_FOUND;
159 }
160
161 return Status;
162 }
163
164 EFI_STATUS
165 EFIAPI
166 HiiNewString (
167 IN EFI_HII_PROTOCOL *This,
168 IN CHAR16 *Language,
169 IN FRAMEWORK_EFI_HII_HANDLE Handle,
170 IN OUT STRING_REF *Reference,
171 IN CHAR16 *NewString
172 )
173 /*++
174
175 Routine Description:
176 This function allows a new String to be added to an already existing String Package.
177 We will make a buffer the size of the package + StrSize of the new string. We will
178 copy the string package that first gets changed and the following language packages until
179 we encounter the NULL string package. All this time we will ensure that the offsets have
180 been adjusted.
181
182 Arguments:
183
184 Returns:
185
186 --*/
187 {
188 EFI_STATUS Status;
189 EFI_HII_THUNK_PRIVATE_DATA *Private;
190 EFI_GUID TagGuid;
191
192 Private = EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
193
194 Status = GetTagGuidByFrameworkHiiHandle (Private, Handle, &TagGuid);
195 ASSERT_EFI_ERROR (Status);
196
197 Status = HiiThunkNewStringForAllStringPackages (Private, &TagGuid, Language, Reference, NewString);
198 //
199 // For UNI file, some String may not be defined for a language. This has been true for a lot of platform code.
200 // For this case, EFI_NOT_FOUND will be returned. To allow the old code to be run without porting, we don't assert
201 // on EFI_NOT_FOUND. The missing Strings will be shown if user select a differnt languages other than the default
202 // English language for the platform.
203 //
204 ASSERT_EFI_ERROR (EFI_ERROR (Status) && Status != EFI_NOT_FOUND);
205
206 return Status;
207 }
208
209 EFI_STATUS
210 EFIAPI
211 HiiResetStrings (
212 IN EFI_HII_PROTOCOL *This,
213 IN FRAMEWORK_EFI_HII_HANDLE Handle
214 )
215 /*++
216
217 Routine Description:
218
219 This function removes any new strings that were added after the initial string export for this handle.
220
221 Arguments:
222
223 Returns:
224
225 --*/
226 {
227 ASSERT (FALSE);
228 return EFI_UNSUPPORTED;
229 }
230
231 typedef struct {
232 CHAR8 *Iso639;
233 CHAR8 *Rfc3066;
234 } ISO639TORFC3066MAP;
235
236 ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {
237 {"eng", "en-US"},
238 {"fra", "fr-FR"},
239 };
240
241 CHAR8 *
242 Iso639ToRfc3066 (
243 CHAR8 *Iso638Lang
244 )
245 {
246 UINTN Index;
247
248 for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {
249 if (AsciiStrnCmp (Iso638Lang, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (Iso638Lang)) == 0) {
250 return Iso639ToRfc3066Map[Index].Rfc3066;
251 }
252 }
253
254 return (CHAR8 *) NULL;
255 }
256
257 EFI_STATUS
258 EFIAPI
259 HiiGetString (
260 IN EFI_HII_PROTOCOL *This,
261 IN FRAMEWORK_EFI_HII_HANDLE Handle,
262 IN STRING_REF Token,
263 IN BOOLEAN Raw,
264 IN CHAR16 *LanguageString,
265 IN OUT UINTN *BufferLengthTemp,
266 OUT EFI_STRING StringBuffer
267 )
268 /*++
269
270 Routine Description:
271
272 This function extracts a string from a package already registered with the EFI HII database.
273
274 Arguments:
275 This - A pointer to the EFI_HII_PROTOCOL instance.
276 Handle - The HII handle on which the string resides.
277 Token - The string token assigned to the string.
278 Raw - If TRUE, the string is returned unedited in the internal storage format described
279 above. If false, the string returned is edited by replacing <cr> with <space>
280 and by removing special characters such as the <wide> prefix.
281 LanguageString - Pointer to a NULL-terminated string containing a single ISO 639-2 language
282 identifier, indicating the language to print. If the LanguageString is empty (starts
283 with a NULL), the default system language will be used to determine the language.
284 BufferLength - Length of the StringBuffer. If the status reports that the buffer width is too
285 small, this parameter is filled with the length of the buffer needed.
286 StringBuffer - The buffer designed to receive the characters in the string. Type EFI_STRING is
287 defined in String.
288
289 Returns:
290 EFI_INVALID_PARAMETER - If input parameter is invalid.
291 EFI_BUFFER_TOO_SMALL - If the *BufferLength is too small.
292 EFI_SUCCESS - Operation is successful.
293
294 --*/
295 {
296 LIST_ENTRY *ListEntry;
297 HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY *HandleMapEntry;
298 CHAR8 *AsciiLanguage;
299 EFI_HII_THUNK_PRIVATE_DATA *Private;
300 CHAR8 *Rfc3066AsciiLanguage;
301
302 Private = EFI_HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
303
304 if (LanguageString == NULL) {
305 AsciiLanguage = NULL;
306 } else {
307 AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);
308 if (AsciiLanguage == NULL) {
309 return EFI_OUT_OF_RESOURCES;
310 }
311 UnicodeStrToAsciiStr (LanguageString, AsciiLanguage);
312
313 Rfc3066AsciiLanguage = Iso639ToRfc3066 (AsciiLanguage);
314 //
315 // Caller of Framework HII Interface uses the Language Identification String defined
316 // in Iso639. So map it to the Language Identifier defined in RFC3066.
317 //
318 if (Rfc3066AsciiLanguage != NULL) {
319 FreePool (AsciiLanguage);
320 AsciiLanguage = AllocateCopyPool (AsciiStrSize (Rfc3066AsciiLanguage), Rfc3066AsciiLanguage);
321 }
322
323 }
324
325 for (ListEntry = Private->HiiThunkHandleMappingDBListHead.ForwardLink;
326 ListEntry != &Private->HiiThunkHandleMappingDBListHead;
327 ListEntry = ListEntry->ForwardLink
328 ) {
329
330 HandleMapEntry = HII_TRHUNK_HANDLE_MAPPING_DATABASE_ENTRY_FROM_LISTENTRY (ListEntry);
331
332 if (Handle == HandleMapEntry->FrameworkHiiHandle) {
333 if (AsciiLanguage == NULL) {
334 return HiiLibGetString (HandleMapEntry->UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);
335 } else {
336 return mHiiStringProtocol->GetString (
337 mHiiStringProtocol,
338 AsciiLanguage,
339 HandleMapEntry->UefiHiiHandle,
340 Token,
341 StringBuffer,
342 BufferLengthTemp,
343 NULL
344 );
345 }
346 }
347 }
348
349 return EFI_NOT_FOUND;
350 }
351
352 EFI_STATUS
353 EFIAPI
354 HiiGetLine (
355 IN EFI_HII_PROTOCOL *This,
356 IN FRAMEWORK_EFI_HII_HANDLE Handle,
357 IN STRING_REF Token,
358 IN OUT UINT16 *Index,
359 IN UINT16 LineWidth,
360 IN CHAR16 *LanguageString,
361 IN OUT UINT16 *BufferLength,
362 OUT EFI_STRING StringBuffer
363 )
364 /*++
365
366 Routine Description:
367
368 This function allows a program to extract a part of a string of not more than a given width.
369 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
370 columns. The effort of measuring the fit of strings inside columns is localized to this call.
371
372 Arguments:
373
374 Returns:
375
376 --*/
377 {
378 ASSERT (FALSE);
379 return EFI_UNSUPPORTED;
380 }
381