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