2 HII Library implementation that uses DXE protocols and services.
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "InternalHiiLib.h"
19 This function adds the string into String Package of each language
20 supported by the package list.
22 If String is NULL, then ASSERT.
23 If StringId is NULL, the ASSERT.
24 If PackageList could not be found in the default HII database, then ASSERT.
26 @param PackageList Handle of the package list where this string will
28 @param StringId On return, contains the new strings id, which is
29 unique within PackageList.
30 @param String Points to the new null-terminated string.
32 @retval EFI_SUCCESS The new string was added successfully.
33 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
39 IN EFI_HII_HANDLE PackageList
,
40 OUT EFI_STRING_ID
*StringId
,
41 IN CONST EFI_STRING String
47 CHAR8 Lang
[RFC_3066_ENTRY_SIZE
];
49 ASSERT (String
!= NULL
);
50 ASSERT (StringId
!= NULL
);
54 Languages
= HiiLibGetSupportedLanguages (PackageList
);
56 LangStrings
= Languages
;
57 while (*LangStrings
!= 0) {
58 HiiLibGetNextLanguage (&LangStrings
, Lang
);
61 // For each language supported by the package,
62 // a string token is created.
64 Status
= mHiiStringProt
->NewString (
73 if (EFI_ERROR (Status
)) {
86 This function update the specified string in String Package of each language
87 supported by the package list.
89 If String is NULL, then ASSERT.
90 If PackageList could not be found in the default HII database, then ASSERT.
91 If StringId is not found in PackageList, then ASSERT.
93 @param PackageList Handle of the package list where this string will
95 @param StringId Ths String Id to be updated.
96 @param String Points to the new null-terminated string.
98 @retval EFI_SUCCESS The new string was added successfully.
99 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
105 IN EFI_HII_HANDLE PackageList
,
106 IN EFI_STRING_ID StringId
,
107 IN CONST EFI_STRING String
113 CHAR8 Lang
[RFC_3066_ENTRY_SIZE
];
115 ASSERT (IsHiiHandleRegistered (PackageList
));
117 Status
= EFI_SUCCESS
;
119 Languages
= HiiLibGetSupportedLanguages (PackageList
);
120 ASSERT (Languages
!= NULL
);
122 LangStrings
= Languages
;
123 while (*LangStrings
!= 0) {
124 HiiLibGetNextLanguage (&LangStrings
, Lang
);
127 // For each language supported by the package,
128 // the string is updated.
130 Status
= mHiiStringProt
->SetString (
138 if (EFI_ERROR (Status
)) {
143 FreePool (Languages
);
150 Get the string given the StringId and String package Producer's Guid. The caller
151 is responsible to free the *String.
153 If PackageList with the matching ProducerGuid is not found, then ASSERT.
154 If PackageList with the matching ProducerGuid is found but no String is
155 specified by StringId is found, then ASSERT.
157 @param ProducerGuid The Guid of String package list.
158 @param StringId The String ID.
159 @param String The output string.
161 @retval EFI_SUCCESS Operation is successful.
162 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
167 HiiLibGetStringFromToken (
168 IN EFI_GUID
*ProducerGuid
,
169 IN EFI_STRING_ID StringId
,
170 OUT EFI_STRING
*String
175 UINTN HandleBufferLen
;
176 EFI_HII_HANDLE
*HiiHandleBuffer
;
179 Status
= HiiLibGetHiiHandles (&HandleBufferLen
, &HiiHandleBuffer
);
180 if (EFI_ERROR(Status
)) {
183 for (Index
= 0; Index
< (HandleBufferLen
/ sizeof (EFI_HII_HANDLE
)); Index
++) {
184 Status
= HiiLibExtractGuidFromHiiHandle (HiiHandleBuffer
[Index
], &Guid
);
185 if (EFI_ERROR(Status
)) {
188 if (CompareGuid (&Guid
, ProducerGuid
)) {
193 if (Index
>= (HandleBufferLen
/ sizeof (EFI_HII_HANDLE
))) {
195 // If PackageList with the matching ProducerGuid is not found, then ASSERT.
198 Status
= EFI_NOT_FOUND
;
202 Status
= HiiLibGetStringFromHandle (HiiHandleBuffer
[Index
], StringId
, String
);
205 if (HiiHandleBuffer
!= NULL
) {
206 FreePool (HiiHandleBuffer
);
212 This function try to retrieve string from String package of current language.
213 If fails, it try to retrieve string from String package of first language it support.
215 If StringSize is NULL, then ASSERT.
216 If String is NULL and *StringSize is not 0, then ASSERT.
217 If PackageList could not be found in the default HII database, then ASSERT.
218 If StringId is not found in PackageList, then ASSERT.
220 @param PackageList The package list in the HII database to search for
221 the specified string.
222 @param StringId The string's id, which is unique within
224 @param String Points to the new null-terminated string.
225 @param StringSize On entry, points to the size of the buffer pointed
226 to by String, in bytes. On return, points to the
227 length of the string, in bytes.
229 @retval EFI_SUCCESS The string was returned successfully.
230 @retval EFI_NOT_FOUND The string specified by StringId is not available.
231 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringLength is too small
238 IN EFI_HII_HANDLE PackageList
,
239 IN EFI_STRING_ID StringId
,
240 OUT EFI_STRING String
,
241 IN OUT UINTN
*StringSize
247 CHAR8 Lang
[RFC_3066_ENTRY_SIZE
];
248 CHAR8 CurrentLang
[RFC_3066_ENTRY_SIZE
];
250 ASSERT (StringSize
!= NULL
);
251 ASSERT (!(*StringSize
!= 0 && String
== NULL
));
252 ASSERT (IsHiiHandleRegistered (PackageList
));
254 HiiLibGetCurrentLanguage (CurrentLang
);
256 Status
= mHiiStringProt
->GetString (
266 if (EFI_ERROR (Status
) && (Status
!= EFI_BUFFER_TOO_SMALL
)) {
267 Languages
= HiiLibGetSupportedLanguages (PackageList
);
268 ASSERT (Languages
!= NULL
);
270 LangStrings
= Languages
;
271 HiiLibGetNextLanguage (&LangStrings
, Lang
);
272 FreePool (Languages
);
274 Status
= mHiiStringProt
->GetString (
290 Get string specified by StringId form the HiiHandle. The caller
291 is responsible to free the *String.
293 If String is NULL, then ASSERT.
294 If HiiHandle could not be found in the default HII database, then ASSERT.
295 If StringId is not found in PackageList, then ASSERT.
297 @param HiiHandle The HII handle of package list.
298 @param StringId The String ID.
299 @param String The output string.
301 @retval EFI_NOT_FOUND String is not found.
302 @retval EFI_SUCCESS Operation is successful.
303 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
304 @retval EFI_INVALID_PARAMETER The String is NULL.
309 HiiLibGetStringFromHandle (
310 IN EFI_HII_HANDLE HiiHandle
,
311 IN EFI_STRING_ID StringId
,
312 OUT EFI_STRING
*String
318 ASSERT (String
!= NULL
);
320 StringSize
= HII_LIB_DEFAULT_STRING_SIZE
;
321 *String
= AllocateZeroPool (StringSize
);
322 if (*String
== NULL
) {
323 return EFI_OUT_OF_RESOURCES
;
326 Status
= HiiLibGetString (HiiHandle
, StringId
, *String
, &StringSize
);
327 if (Status
== EFI_BUFFER_TOO_SMALL
) {
329 *String
= AllocateZeroPool (StringSize
);
330 if (*String
== NULL
) {
331 return EFI_OUT_OF_RESOURCES
;
333 Status
= HiiLibGetString (HiiHandle
, StringId
, *String
, &StringSize
);
342 // Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
343 // Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
344 // The last 2 CHAR8 values are the ISO 639-1 code.
346 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable
[] =
487 Convert language code from RFC3066 to ISO639-2.
489 @param LanguageRfc3066 RFC3066 language code.
490 @param LanguageIso639 ISO639-2 language code.
492 @retval EFI_SUCCESS Language code converted.
493 @retval EFI_NOT_FOUND Language code not found.
498 ConvertRfc3066LanguageToIso639Language (
499 CHAR8
*LanguageRfc3066
,
500 CHAR8
*LanguageIso639
505 if ((LanguageRfc3066
[2] != '-') && (LanguageRfc3066
[2] != 0)) {
506 CopyMem (LanguageIso639
, LanguageRfc3066
, 3);
510 for (Index
= 0; Iso639ToRfc3066ConversionTable
[Index
] != 0; Index
+= 5) {
511 if (CompareMem (LanguageRfc3066
, &Iso639ToRfc3066ConversionTable
[Index
+ 3], 2) == 0) {
512 CopyMem (LanguageIso639
, &Iso639ToRfc3066ConversionTable
[Index
], 3);
517 return EFI_NOT_FOUND
;
522 Convert language code from ISO639-2 to RFC3066.
524 LanguageIso639 contain a single ISO639-2 code such as
527 The LanguageRfc3066 must be a buffer large enough
528 for RFC_3066_ENTRY_SIZE characters.
530 If LanguageIso639 is NULL, then ASSERT.
531 If LanguageRfc3066 is NULL, then ASSERT.
533 @param LanguageIso639 ISO639-2 language code.
534 @param LanguageRfc3066 RFC3066 language code.
536 @retval EFI_SUCCESS Language code converted.
537 @retval EFI_NOT_FOUND Language code not found.
542 ConvertIso639LanguageToRfc3066Language (
543 IN CONST CHAR8
*LanguageIso639
,
544 OUT CHAR8
*LanguageRfc3066
549 for (Index
= 0; Iso639ToRfc3066ConversionTable
[Index
] != 0; Index
+= 5) {
550 if (CompareMem (LanguageIso639
, &Iso639ToRfc3066ConversionTable
[Index
], 3) == 0) {
551 CopyMem (LanguageRfc3066
, &Iso639ToRfc3066ConversionTable
[Index
+ 3], 2);
556 return EFI_NOT_FOUND
;
560 Convert language code list from RFC3066 to ISO639-2, e.g. "en-US;fr-FR" will
561 be converted to "engfra".
563 @param SupportedLanguages The RFC3066 language list.
565 @return The ISO639-2 language list.
571 CHAR8
*SupportedLanguages
577 CHAR8 LangRfc3066
[RFC_3066_ENTRY_SIZE
];
578 CHAR8 LangIso639
[ISO_639_2_ENTRY_SIZE
];
581 ReturnValue
= AllocateZeroPool (AsciiStrSize (SupportedLanguages
));
582 if (ReturnValue
== NULL
) {
586 Languages
= ReturnValue
;
587 LangCodes
= SupportedLanguages
;
588 while (*LangCodes
!= 0) {
589 HiiLibGetNextLanguage (&LangCodes
, LangRfc3066
);
591 Status
= ConvertRfc3066LanguageToIso639Language (LangRfc3066
, LangIso639
);
592 if (!EFI_ERROR (Status
)) {
593 CopyMem (Languages
, LangIso639
, 3);
594 Languages
= Languages
+ 3;