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
);
60 Status
= mHiiStringProt
->NewString (
69 if (EFI_ERROR (Status
)) {
82 This function update the specified string in String Package of each language
83 supported by the package list.
85 If String is NULL, then ASSERT.
86 If PackageList could not be found in the default HII database, then ASSERT.
87 If StringId is not found in PackageList, then ASSERT.
89 @param PackageList Handle of the package list where this string will
91 @param StringId Ths String Id to be updated.
92 @param String Points to the new null-terminated string.
94 @retval EFI_SUCCESS The new string was added successfully.
95 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.
101 IN EFI_HII_HANDLE PackageList
,
102 IN EFI_STRING_ID StringId
,
103 IN CONST EFI_STRING String
109 CHAR8 Lang
[RFC_3066_ENTRY_SIZE
];
111 ASSERT (IsHiiHandleRegistered (PackageList
));
113 Status
= EFI_SUCCESS
;
115 Languages
= HiiLibGetSupportedLanguages (PackageList
);
116 ASSERT (Languages
!= NULL
);
118 LangStrings
= Languages
;
119 while (*LangStrings
!= 0) {
120 HiiLibGetNextLanguage (&LangStrings
, Lang
);
122 Status
= mHiiStringProt
->SetString (
130 if (EFI_ERROR (Status
)) {
135 FreePool (Languages
);
142 Get the string given the StringId and String package Producer's Guid. The caller
143 is responsible to free the *String.
145 If PackageList with the matching ProducerGuid is not found, then ASSERT.
146 If PackageList with the matching ProducerGuid is found but no String is
147 specified by StringId is found, then ASSERT.
149 @param ProducerGuid The Guid of String package list.
150 @param StringId The String ID.
151 @param String The output string.
153 @retval EFI_SUCCESS Operation is successful.
154 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
159 HiiLibGetStringFromToken (
160 IN EFI_GUID
*ProducerGuid
,
161 IN EFI_STRING_ID StringId
,
162 OUT EFI_STRING
*String
167 UINTN HandleBufferLen
;
168 EFI_HII_HANDLE
*HiiHandleBuffer
;
171 Status
= HiiLibGetHiiHandles (&HandleBufferLen
, &HiiHandleBuffer
);
172 if (EFI_ERROR(Status
)) {
175 for (Index
= 0; Index
< (HandleBufferLen
/ sizeof (EFI_HII_HANDLE
)); Index
++) {
176 Status
= HiiLibExtractGuidFromHiiHandle (HiiHandleBuffer
[Index
], &Guid
);
177 if (EFI_ERROR(Status
)) {
180 if (CompareGuid (&Guid
, ProducerGuid
)) {
185 if (Index
>= (HandleBufferLen
/ sizeof (EFI_HII_HANDLE
))) {
187 // If PackageList with the matching ProducerGuid is not found, then ASSERT.
190 Status
= EFI_NOT_FOUND
;
194 Status
= HiiLibGetStringFromHandle (HiiHandleBuffer
[Index
], StringId
, String
);
197 if (HiiHandleBuffer
!= NULL
) {
198 gBS
->FreePool (HiiHandleBuffer
);
204 This function try to retrieve string from String package of current language.
205 If fails, it try to retrieve string from String package of first language it support.
207 If String is NULL, then ASSERT.
208 If StringSize is NULL, then ASSERT.
209 If PackageList could not be found in the default HII database, then ASSERT.
210 If StringId is not found in PackageList, then ASSERT.
212 @param PackageList The package list in the HII database to search for
213 the specified string.
214 @param StringId The string's id, which is unique within
216 @param String Points to the new null-terminated string.
217 @param StringSize On entry, points to the size of the buffer pointed
218 to by String, in bytes. On return, points to the
219 length of the string, in bytes.
221 @retval EFI_SUCCESS The string was returned successfully.
222 @retval EFI_NOT_FOUND The string specified by StringId is not available.
223 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringLength is too small
225 @retval EFI_INVALID_PARAMETER The String or StringSize was NULL.
231 IN EFI_HII_HANDLE PackageList
,
232 IN EFI_STRING_ID StringId
,
233 OUT EFI_STRING String
,
234 IN OUT UINTN
*StringSize
240 CHAR8 Lang
[RFC_3066_ENTRY_SIZE
];
241 CHAR8 CurrentLang
[RFC_3066_ENTRY_SIZE
];
243 ASSERT (String
!= NULL
);
244 ASSERT (StringSize
!= NULL
);
245 ASSERT (IsHiiHandleRegistered (PackageList
));
247 HiiLibGetCurrentLanguage (CurrentLang
);
249 Status
= mHiiStringProt
->GetString (
259 if (EFI_ERROR (Status
) && (Status
!= EFI_BUFFER_TOO_SMALL
)) {
260 Languages
= HiiLibGetSupportedLanguages (PackageList
);
261 ASSERT (Languages
!= NULL
);
263 LangStrings
= Languages
;
264 HiiLibGetNextLanguage (&LangStrings
, Lang
);
265 gBS
->FreePool (Languages
);
267 Status
= mHiiStringProt
->GetString (
283 Get string specified by StringId form the HiiHandle. The caller
284 is responsible to free the *String.
286 If String is NULL, then ASSERT.
287 If HiiHandle could not be found in the default HII database, then ASSERT.
288 If StringId is not found in PackageList, then ASSERT.
290 @param HiiHandle The HII handle of package list.
291 @param StringId The String ID.
292 @param String The output string.
294 @retval EFI_NOT_FOUND String is not found.
295 @retval EFI_SUCCESS Operation is successful.
296 @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system.
297 @retval EFI_INVALID_PARAMETER The String is NULL.
302 HiiLibGetStringFromHandle (
303 IN EFI_HII_HANDLE HiiHandle
,
304 IN EFI_STRING_ID StringId
,
305 OUT EFI_STRING
*String
311 ASSERT (String
!= NULL
);
313 StringSize
= HII_LIB_DEFAULT_STRING_SIZE
;
314 *String
= AllocateZeroPool (StringSize
);
315 if (*String
== NULL
) {
316 return EFI_OUT_OF_RESOURCES
;
319 Status
= HiiLibGetString (HiiHandle
, StringId
, *String
, &StringSize
);
320 if (Status
== EFI_BUFFER_TOO_SMALL
) {
321 gBS
->FreePool (*String
);
322 *String
= AllocateZeroPool (StringSize
);
323 if (*String
== NULL
) {
324 return EFI_OUT_OF_RESOURCES
;
326 Status
= HiiLibGetString (HiiHandle
, StringId
, *String
, &StringSize
);
335 // Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
336 // Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
337 // The last 2 CHAR8 values are the ISO 639-1 code.
339 CHAR8 Iso639ToRfc3066ConversionTable
[] =
480 Convert language code from RFC3066 to ISO639-2.
482 @param LanguageRfc3066 RFC3066 language code.
483 @param LanguageIso639 ISO639-2 language code.
485 @retval EFI_SUCCESS Language code converted.
486 @retval EFI_NOT_FOUND Language code not found.
491 ConvertRfc3066LanguageToIso639Language (
492 CHAR8
*LanguageRfc3066
,
493 CHAR8
*LanguageIso639
498 if ((LanguageRfc3066
[2] != '-') && (LanguageRfc3066
[2] != 0)) {
499 CopyMem (LanguageIso639
, LanguageRfc3066
, 3);
503 for (Index
= 0; Iso639ToRfc3066ConversionTable
[Index
] != 0; Index
+= 5) {
504 if (CompareMem (LanguageRfc3066
, &Iso639ToRfc3066ConversionTable
[Index
+ 3], 2) == 0) {
505 CopyMem (LanguageIso639
, &Iso639ToRfc3066ConversionTable
[Index
], 3);
510 return EFI_NOT_FOUND
;
515 Convert language code from ISO639-2 to RFC3066.
517 LanguageIso639 contain a single ISO639-2 code such as
520 The LanguageRfc3066 must be a buffer large enough
521 for RFC_3066_ENTRY_SIZE characters.
523 If LanguageIso639 is NULL, then ASSERT.
524 If LanguageRfc3066 is NULL, then ASSERT.
526 @param LanguageIso639 ISO639-2 language code.
527 @param LanguageRfc3066 RFC3066 language code.
529 @retval EFI_SUCCESS Language code converted.
530 @retval EFI_NOT_FOUND Language code not found.
535 ConvertIso639LanguageToRfc3066Language (
536 IN CONST CHAR8
*LanguageIso639
,
537 OUT CHAR8
*LanguageRfc3066
542 for (Index
= 0; Iso639ToRfc3066ConversionTable
[Index
] != 0; Index
+= 5) {
543 if (CompareMem (LanguageIso639
, &Iso639ToRfc3066ConversionTable
[Index
], 3) == 0) {
544 CopyMem (LanguageRfc3066
, &Iso639ToRfc3066ConversionTable
[Index
+ 3], 2);
549 return EFI_NOT_FOUND
;
553 Convert language code list from RFC3066 to ISO639-2, e.g. "en-US;fr-FR" will
554 be converted to "engfra".
556 @param SupportedLanguages The RFC3066 language list.
558 @return The ISO639-2 language list.
564 CHAR8
*SupportedLanguages
570 CHAR8 LangRfc3066
[RFC_3066_ENTRY_SIZE
];
571 CHAR8 LangIso639
[ISO_639_2_ENTRY_SIZE
];
574 ReturnValue
= AllocateZeroPool (AsciiStrSize (SupportedLanguages
));
575 if (ReturnValue
== NULL
) {
579 Languages
= ReturnValue
;
580 LangCodes
= SupportedLanguages
;
581 while (*LangCodes
!= 0) {
582 HiiLibGetNextLanguage (&LangCodes
, LangRfc3066
);
584 Status
= ConvertRfc3066LanguageToIso639Language (LangRfc3066
, LangIso639
);
585 if (!EFI_ERROR (Status
)) {
586 CopyMem (Languages
, LangIso639
, 3);
587 Languages
= Languages
+ 3;