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