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