]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c
Fixed build failed.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Strings.c
... / ...
CommitLineData
1/** @file\r
2 This file implements the protocol functions related to string package.\r
3 \r
4Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
5This 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
18/**\r
19 Test if all of the characters in a string have corresponding font characters.\r
20\r
21 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
22 return EFI_UNSUPPORTED.\r
23\r
24 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
25 @param StringToTest A pointer to a Unicode string.\r
26 @param FirstMissing A pointer to an index into the string. On input, the index of \r
27 the first character in the StringToTest to examine. On exit, the index \r
28 of the first character encountered for which a glyph is unavailable. \r
29 If all glyphs in the string are available, the index is the index of the terminator \r
30 of the string. \r
31 @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS, \r
32 it contains the amount of memory that is required to store the string? glyph equivalent.\r
33\r
34 @retval EFI_UNSUPPORTED The function performs nothing and return EFI_UNSUPPORTED.\r
35**/\r
36EFI_STATUS\r
37EFIAPI\r
38HiiTestString (\r
39 IN EFI_HII_PROTOCOL *This,\r
40 IN CHAR16 *StringToTest,\r
41 IN OUT UINT32 *FirstMissing,\r
42 OUT UINT32 *GlyphBufferSize\r
43 )\r
44{\r
45 ASSERT (FALSE);\r
46 \r
47 return EFI_UNSUPPORTED;\r
48}\r
49\r
50\r
51/**\r
52 Find the corressponding TAG GUID from a Framework HII Handle given.\r
53\r
54 @param Private The HII Thunk Module Private context.\r
55 @param FwHiiHandle The Framemwork HII Handle.\r
56 @param TagGuid The output of TAG GUID found.\r
57\r
58 @return NULL If Framework HII Handle is invalid.\r
59 @return The corresponding HII Thunk Context.\r
60**/\r
61EFI_STATUS\r
62GetTagGuidByFwHiiHandle (\r
63 IN CONST HII_THUNK_PRIVATE_DATA *Private,\r
64 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle,\r
65 OUT EFI_GUID *TagGuid\r
66 )\r
67{\r
68 LIST_ENTRY *Link;\r
69 HII_THUNK_CONTEXT *ThunkContext;\r
70\r
71 ASSERT (TagGuid != NULL);\r
72\r
73 Link = GetFirstNode (&Private->ThunkContextListHead);\r
74 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
75\r
76 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
77\r
78 if (FwHiiHandle == ThunkContext->FwHiiHandle) {\r
79 CopyGuid (TagGuid, &ThunkContext->TagGuid);\r
80 return EFI_SUCCESS;\r
81 }\r
82\r
83 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
84 }\r
85\r
86 return EFI_NOT_FOUND;\r
87}\r
88\r
89/**\r
90 Create or update the String given a new string and String ID.\r
91\r
92 @param ThunkContext The Thunk Context.\r
93 @param Rfc4646AsciiLanguage The RFC 4646 Language code in ASCII string format.\r
94 @param NewString The new string.\r
95 @param StringId The String ID. If StringId is 0, a new String Token\r
96 is created. Otherwise, the String Token StringId is \r
97 updated.\r
98 \r
99\r
100 @retval EFI_SUCCESS The new string is created or updated successfully. \r
101 The new String Token ID is returned in StringId if\r
102 *StringId is 0 on input.\r
103 @return Others The update of string failed. \r
104 \r
105**/\r
106EFI_STATUS\r
107UpdateString (\r
108 IN CONST HII_THUNK_CONTEXT *ThunkContext,\r
109 IN CONST CHAR8 *Rfc4646AsciiLanguage,\r
110 IN CHAR16 *NewString,\r
111 IN OUT STRING_REF *StringId\r
112 )\r
113{\r
114 EFI_STRING_ID NewStringId;\r
115\r
116 NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc4646AsciiLanguage);\r
117 *StringId = NewStringId;\r
118 if (NewStringId == 0) {\r
119 //\r
120 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
121 //\r
122 return EFI_INVALID_PARAMETER;\r
123 } else {\r
124 return EFI_SUCCESS;\r
125 }\r
126}\r
127\r
128/**\r
129 Create or update a String Token in a String Package.\r
130\r
131 If *Reference == 0, a new String Token is created.\r
132\r
133 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
134 @param Language Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
135 identifier, indicating the language to print. A string consisting of\r
136 all spaces indicates that the string is applicable to all languages.\r
137 @param Handle The handle of the language pack to which the string is to be added.\r
138 @param Reference The string token assigned to the string.\r
139 @param NewString The string to be added.\r
140\r
141\r
142 @retval EFI_SUCCESS The string was effectively registered.\r
143 @retval EFI_INVALID_PARAMETER The Handle was unknown. The string is not created or updated in the\r
144 the string package.\r
145**/\r
146EFI_STATUS\r
147EFIAPI\r
148HiiNewString (\r
149 IN EFI_HII_PROTOCOL *This,\r
150 IN CHAR16 *Language,\r
151 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
152 IN OUT STRING_REF *Reference,\r
153 IN CHAR16 *NewString\r
154 )\r
155{\r
156 EFI_STATUS Status;\r
157 HII_THUNK_PRIVATE_DATA *Private;\r
158 EFI_GUID TagGuid;\r
159 LIST_ENTRY *Link;\r
160 HII_THUNK_CONTEXT *ThunkContext;\r
161 HII_THUNK_CONTEXT *StringPackThunkContext;\r
162 EFI_STRING_ID StringId;\r
163 EFI_STRING_ID LastStringId;\r
164 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
165 CHAR16 LanguageCopy[ISO_639_2_ENTRY_SIZE + 1];\r
166 CHAR8 *Rfc4646AsciiLanguage;\r
167\r
168 LastStringId = (EFI_STRING_ID) 0;\r
169 StringId = (EFI_STRING_ID) 0;\r
170 Rfc4646AsciiLanguage = NULL;\r
171\r
172 if (Language != NULL) {\r
173 ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;\r
174 ZeroMem (LanguageCopy, sizeof (LanguageCopy));\r
175 CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));\r
176 UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);\r
177 Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (AsciiLanguage);\r
178 ASSERT (Rfc4646AsciiLanguage != NULL);\r
179 }\r
180\r
181 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
182\r
183 StringPackThunkContext = FwHiiHandleToThunkContext (Private, Handle);\r
184 if (StringPackThunkContext == NULL) {\r
185 return EFI_INVALID_PARAMETER;\r
186 }\r
187\r
188 if (StringPackThunkContext->SharingStringPack) {\r
189 Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);\r
190 ASSERT_EFI_ERROR (Status);\r
191\r
192 Link = GetFirstNode (&Private->ThunkContextListHead);\r
193 while (!IsNull (&Private->ThunkContextListHead, Link)) {\r
194 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);\r
195\r
196 if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {\r
197 if (ThunkContext->SharingStringPack) {\r
198 StringId = *Reference;\r
199 Status = UpdateString (ThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
200 if (EFI_ERROR (Status)) {\r
201 break;\r
202 }\r
203 \r
204 DEBUG_CODE_BEGIN ();\r
205 if (*Reference == 0) {\r
206 //\r
207 // When creating new string token, make sure all created token is the same\r
208 // for all string packages registered using FW HII interface.\r
209 //\r
210 if (LastStringId == (EFI_STRING_ID) 0) {\r
211 LastStringId = StringId;\r
212 } else {\r
213 if (LastStringId != StringId) {\r
214 ASSERT(FALSE);\r
215 }\r
216 }\r
217 }\r
218 DEBUG_CODE_END ();\r
219 \r
220 }\r
221 }\r
222\r
223 Link = GetNextNode (&Private->ThunkContextListHead, Link);\r
224 }\r
225 } else {\r
226 StringId = *Reference;\r
227 Status = UpdateString (StringPackThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
228 }\r
229\r
230 if (!EFI_ERROR (Status)) {\r
231 if (*Reference == 0) {\r
232 *Reference = StringId;\r
233 }\r
234 } else {\r
235 //\r
236 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
237 //\r
238 Status = EFI_INVALID_PARAMETER;\r
239 }\r
240 \r
241 return Status;\r
242}\r
243\r
244/**\r
245 This function removes any new strings that were added after the initial string export for this handle.\r
246 UEFI HII String Protocol does not have Reset String function. This function perform nothing.\r
247\r
248 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
249 @param Handle The HII handle on which the string resides.\r
250\r
251 @retval EFI_SUCCESS This function is a NOP and always return EFI_SUCCESS.\r
252\r
253**/\r
254EFI_STATUS\r
255EFIAPI\r
256HiiResetStrings (\r
257 IN EFI_HII_PROTOCOL *This,\r
258 IN FRAMEWORK_EFI_HII_HANDLE Handle\r
259 )\r
260{\r
261 return EFI_SUCCESS;\r
262}\r
263\r
264/**\r
265 This function extracts a string from a package already registered with the EFI HII database.\r
266\r
267 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
268 @param Handle The HII handle on which the string resides.\r
269 @param Token The string token assigned to the string.\r
270 @param Raw If TRUE, the string is returned unedited in the internal storage format described\r
271 above. If false, the string returned is edited by replacing <cr> with <space>\r
272 and by removing special characters such as the <wide> prefix.\r
273 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
274 identifier, indicating the language to print. If the LanguageString is empty (starts\r
275 with a NULL), the default system language will be used to determine the language.\r
276 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too\r
277 small, this parameter is filled with the length of the buffer needed.\r
278 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is\r
279 defined in String.\r
280\r
281 @retval EFI_INVALID_PARAMETER If input parameter is invalid.\r
282 @retval EFI_BUFFER_TOO_SMALL If the *BufferLength is too small.\r
283 @retval EFI_SUCCESS Operation is successful.\r
284\r
285**/\r
286EFI_STATUS\r
287EFIAPI\r
288HiiThunkGetString (\r
289 IN EFI_HII_PROTOCOL *This,\r
290 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
291 IN STRING_REF Token,\r
292 IN BOOLEAN Raw,\r
293 IN CHAR16 *LanguageString,\r
294 IN OUT UINTN *BufferLength,\r
295 OUT EFI_STRING StringBuffer\r
296 )\r
297{\r
298 HII_THUNK_PRIVATE_DATA *Private;\r
299 CHAR8 *Iso639AsciiLanguage;\r
300 CHAR8 *Rfc4646AsciiLanguage;\r
301 CHAR8 *SupportedLanguages;\r
302 CHAR8 *PlatformLanguage;\r
303 CHAR8 *BestLanguage;\r
304 EFI_HII_HANDLE UefiHiiHandle;\r
305 EFI_STATUS Status;\r
306\r
307 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
308\r
309 Rfc4646AsciiLanguage = NULL;\r
310 SupportedLanguages = NULL;\r
311 PlatformLanguage = NULL;\r
312 Status = EFI_SUCCESS;\r
313\r
314 if (LanguageString != NULL) {\r
315 Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
316 if (Iso639AsciiLanguage == NULL) {\r
317 return EFI_OUT_OF_RESOURCES;\r
318 }\r
319 UnicodeStrToAsciiStr (LanguageString, Iso639AsciiLanguage);\r
320\r
321 //\r
322 // Caller of Framework HII Interface uses the Language Identification String defined \r
323 // in Iso639. So map it to the Language Identifier defined in RFC4646.\r
324 //\r
325 Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (Iso639AsciiLanguage);\r
326 FreePool (Iso639AsciiLanguage);\r
327\r
328 //\r
329 // If Rfc4646AsciiLanguage is NULL, more language mapping must be added to \r
330 // Iso639ToRfc4646Map.\r
331 //\r
332 ASSERT (Rfc4646AsciiLanguage != NULL);\r
333 }\r
334\r
335 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r
336 if (UefiHiiHandle == NULL) {\r
337 Status = EFI_NOT_FOUND;\r
338 goto Done;\r
339 }\r
340\r
341 //\r
342 // Get the languages that the package specified by HiiHandle supports\r
343 //\r
344 SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle);\r
345 if (SupportedLanguages == NULL) {\r
346 goto Done;\r
347 }\r
348\r
349 //\r
350 // Get the current platform language setting\r
351 //\r
352 GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);\r
353\r
354 //\r
355 // Get the best matching language from SupportedLanguages\r
356 //\r
357 BestLanguage = GetBestLanguage (\r
358 SupportedLanguages, \r
359 FALSE, // RFC 4646 mode\r
360 (Rfc4646AsciiLanguage != NULL) ? Rfc4646AsciiLanguage : "", // Highest priority \r
361 (PlatformLanguage != NULL) ? PlatformLanguage : "", // Next highest priority\r
362 SupportedLanguages, // Lowest priority \r
363 NULL\r
364 );\r
365 if (BestLanguage != NULL) {\r
366 Status = mHiiStringProtocol->GetString (\r
367 mHiiStringProtocol,\r
368 BestLanguage,\r
369 UefiHiiHandle,\r
370 Token,\r
371 StringBuffer,\r
372 BufferLength,\r
373 NULL\r
374 );\r
375 FreePool (BestLanguage);\r
376 } else {\r
377 Status = EFI_INVALID_PARAMETER;\r
378 }\r
379\r
380Done:\r
381 if (Rfc4646AsciiLanguage != NULL) {\r
382 FreePool (Rfc4646AsciiLanguage);\r
383 }\r
384\r
385 if (SupportedLanguages != NULL) {\r
386 FreePool (SupportedLanguages);\r
387 }\r
388\r
389 if (PlatformLanguage != NULL) {\r
390 FreePool (PlatformLanguage);\r
391 }\r
392 return Status;\r
393}\r
394\r
395/**\r
396\r
397 This function allows a program to extract a part of a string of not more than a given width.\r
398 With repeated calls, this allows a calling program to extract "lines" of text that fit inside\r
399 columns. The effort of measuring the fit of strings inside columns is localized to this call.\r
400\r
401 This is a deprecated API. No Framework HII module is calling it. This function will ASSERT and\r
402 return EFI_UNSUPPORTED.\r
403\r
404 @param This A pointer to the EFI_HII_PROTOCOL instance.\r
405 @param Handle The HII handle on which the string resides.\r
406 @param Token The string token assigned to the string.\r
407 @param Index On input, the offset into the string where the line is to start.\r
408 On output, the index is updated to point to beyond the last character returned\r
409 in the call.\r
410 @param LineWidth The maximum width of the line in units of narrow glyphs.\r
411 @param LanguageString Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
412 identifier, indicating the language to print. If the LanguageString is empty (starts\r
413 with a NULL), the default system language will be used to determine the language.\r
414 @param BufferLength Length of the StringBuffer. If the status reports that the buffer width is too\r
415 small, this parameter is filled with the length of the buffer needed.\r
416 @param StringBuffer The buffer designed to receive the characters in the string. Type EFI_STRING is\r
417 defined in String.\r
418\r
419 @retval EFI_UNSUPPORTED.\r
420**/\r
421EFI_STATUS\r
422EFIAPI\r
423HiiGetLine (\r
424 IN EFI_HII_PROTOCOL *This,\r
425 IN FRAMEWORK_EFI_HII_HANDLE Handle,\r
426 IN STRING_REF Token,\r
427 IN OUT UINT16 *Index,\r
428 IN UINT16 LineWidth,\r
429 IN CHAR16 *LanguageString,\r
430 IN OUT UINT16 *BufferLength,\r
431 OUT EFI_STRING StringBuffer\r
432 )\r
433{\r
434 ASSERT (FALSE);\r
435 return EFI_UNSUPPORTED;\r
436}\r
437\r
438\r