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