From 7c9d25ae76f53b3cf20f615ae8902eef1648c5b5 Mon Sep 17 00:00:00 2001 From: rsun3 Date: Fri, 8 May 2009 01:51:35 +0000 Subject: Refine language conversion in ECP. Create a new library LanguageLib providing functions for language conversion between ISO 639-2 and RFC 4646 styles. Update FrameworkHiiOnUefiHiiThunk, UcOnUc2Thunk and Uc2OnUcThunk modules to use this library. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8258 6f19259b-4bc3-4df7-8a09-765794883524 --- .../FrameworkHiiOnUefiHiiThunk.inf | 2 + .../FrameworkHiiOnUefiHiiThunk/HiiDatabase.c | 75 +----- .../FrameworkHiiOnUefiHiiThunk/HiiDatabase.h | 1 + .../FrameworkHiiOnUefiHiiThunk/Strings.c | 297 +-------------------- 4 files changed, 14 insertions(+), 361 deletions(-) (limited to 'EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk') diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/FrameworkHiiOnUefiHiiThunk.inf b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/FrameworkHiiOnUefiHiiThunk.inf index 2b037182eb..1c0c362161 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/FrameworkHiiOnUefiHiiThunk.inf +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/FrameworkHiiOnUefiHiiThunk.inf @@ -66,6 +66,7 @@ MdeModulePkg/MdeModulePkg.dec IntelFrameworkPkg/IntelFrameworkPkg.dec IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec + EdkCompatibilityPkg/EdkCompatibilityPkg.dec [LibraryClasses] UefiRuntimeServicesTableLib @@ -79,6 +80,7 @@ PrintLib UefiLib PcdLib + LanguageLib [Guids] gEfiIfrTianoGuid diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.c index a25650d8d7..ec7159b60b 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.c @@ -305,65 +305,6 @@ HiiFindHandles ( return EFI_SUCCESS; } -EFI_STATUS -LangCodes4646To639 ( - IN CHAR8 *LangCodes4646, - IN CHAR8 **LangCodes639 - ) -{ - CHAR8 *AsciiLangCodes; - CHAR8 *Lang; - UINTN Index; - UINTN Count; - EFI_STATUS Status; - - ASSERT (LangCodes4646 != NULL); - ASSERT (LangCodes639 != NULL); - - // - // Allocate working buffer to contain substring of LangCodes4646. - // - Lang = AllocatePool (AsciiStrSize (LangCodes4646)); - if (Lang == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Count the number of RFC 4646 language codes. - // - Index = 0; - AsciiLangCodes = LangCodes4646; - while (AsciiStrLen (AsciiLangCodes) != 0) { - GetNextLanguage (&AsciiLangCodes, Lang); - Index++; - } - - Count = Index; - - // - // - // - *LangCodes639 = AllocateZeroPool (ISO_639_2_ENTRY_SIZE * Count + 1); - if (*LangCodes639 == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Done; - } - - AsciiLangCodes = LangCodes4646; - - for (Index = 0; Index < Count; Index++) { - GetNextLanguage (&AsciiLangCodes, Lang); - Status = ConvertRfc4646LanguageToIso639Language (Lang, *LangCodes639 + Index * ISO_639_2_ENTRY_SIZE); - ASSERT_EFI_ERROR (Status); - } - - Status = EFI_SUCCESS; - -Done: - FreePool (Lang); - return Status; -} - /** Allows a program to determine the primary languages that are supported on a given handle. @@ -409,10 +350,9 @@ HiiGetPrimaryLanguages ( return EFI_INVALID_PARAMETER; } - - LangCodes639 = NULL; - Status = LangCodes4646To639 (LangCodes4646, &LangCodes639); - if (EFI_ERROR (Status)) { + LangCodes639 = ConvertLanguagesRfc4646ToIso639 (LangCodes4646); + if (LangCodes639 == NULL) { + Status = EFI_INVALID_PARAMETER; goto Done; } @@ -427,6 +367,7 @@ HiiGetPrimaryLanguages ( // AsciiStrToUnicodeStr (LangCodes639, UnicodeLangCodes639); *LanguageString = UnicodeLangCodes639; + Status = EFI_SUCCESS; Done: FreePool (LangCodes4646); @@ -551,7 +492,7 @@ HiiGetSecondaryLanguages ( UnicodeStrToAsciiStr (PrimaryLanguage, PrimaryLang639); - PrimaryLang4646 = ConvertIso639LanguageToRfc4646Language (PrimaryLang639); + PrimaryLang4646 = ConvertLanguagesIso639ToRfc4646 (PrimaryLang639); ASSERT_EFI_ERROR (PrimaryLang4646 != NULL); SecLangCodes4646 = HiiGetSupportedSecondaryLanguages (UefiHiiHandle, PrimaryLang4646); @@ -561,8 +502,9 @@ HiiGetSecondaryLanguages ( goto Done; } - Status = LangCodes4646To639 (SecLangCodes4646, &SecLangCodes639); - if (EFI_ERROR (Status)) { + SecLangCodes639 = ConvertLanguagesIso639ToRfc4646 (SecLangCodes4646); + if (SecLangCodes639 == NULL) { + Status = EFI_INVALID_PARAMETER; goto Done; } @@ -576,6 +518,7 @@ HiiGetSecondaryLanguages ( // The language returned is in RFC 4646 format. // *LanguageString = AsciiStrToUnicodeStr (SecLangCodes639, UnicodeSecLangCodes639); + Status = EFI_SUCCESS; Done: if (PrimaryLang639 != NULL) { diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.h b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.h index 1ae31b4e6f..9878df45de 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.h +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/HiiDatabase.h @@ -47,6 +47,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c index daf652c1ab..d0b356be51 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c @@ -15,299 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "HiiDatabase.h" -typedef struct { - CHAR8 *Iso639; - CHAR8 *Rfc4646; -} ISO639TORFC4646MAP; - -ISO639TORFC4646MAP Iso639ToRfc4646Map [] = { - {"eng", "en-US"}, - {"fra", "fr-FR"}, -}; - -// -// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes -// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code. -// The last 2 CHAR8 values are the ISO 639-1 code. -// -GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc4646ConversionTable[] = -"\ -aaraa\ -abkab\ -afraf\ -amham\ -araar\ -asmas\ -aymay\ -azeaz\ -bakba\ -belbe\ -benbn\ -bihbh\ -bisbi\ -bodbo\ -brebr\ -bulbg\ -catca\ -cescs\ -corkw\ -cosco\ -cymcy\ -danda\ -deude\ -dzodz\ -ellel\ -engen\ -epoeo\ -estet\ -euseu\ -faofo\ -fasfa\ -fijfj\ -finfi\ -frafr\ -fryfy\ -gaiga\ -gdhgd\ -glggl\ -grngn\ -gujgu\ -hauha\ -hebhe\ -hinhi\ -hrvhr\ -hunhu\ -hyehy\ -ikuiu\ -ileie\ -inaia\ -indid\ -ipkik\ -islis\ -itait\ -jawjw\ -jpnja\ -kalkl\ -kankn\ -kasks\ -katka\ -kazkk\ -khmkm\ -kinrw\ -kirky\ -korko\ -kurku\ -laolo\ -latla\ -lavlv\ -linln\ -litlt\ -ltzlb\ -malml\ -marmr\ -mkdmk\ -mlgmg\ -mltmt\ -molmo\ -monmn\ -mrimi\ -msams\ -myamy\ -nauna\ -nepne\ -nldnl\ -norno\ -ocioc\ -ormom\ -panpa\ -polpl\ -porpt\ -pusps\ -quequ\ -rohrm\ -ronro\ -runrn\ -rusru\ -sagsg\ -sansa\ -sinsi\ -slksk\ -slvsl\ -smise\ -smosm\ -snasn\ -sndsd\ -somso\ -sotst\ -spaes\ -sqisq\ -srpsr\ -sswss\ -sunsu\ -swasw\ -swesv\ -tamta\ -tattt\ -telte\ -tgktg\ -tgltl\ -thath\ -tsnts\ -tuktk\ -twitw\ -uigug\ -ukruk\ -urdur\ -uzbuz\ -vievi\ -volvo\ -wolwo\ -xhoxh\ -yidyi\ -zhaza\ -zhozh\ -zulzu\ -"; - -CHAR8 * -ConvertIso639ToRfc4646 ( - CHAR8 *Iso638Lang - ) -{ - UINTN Index; - CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1]; - - AsciiStrnCpy (AsciiLanguage, Iso638Lang, sizeof (AsciiLanguage)); - for (Index = 0; Index < ISO_639_2_ENTRY_SIZE + 1; Index ++) { - if (AsciiLanguage [Index] == 0) { - break; - } else if (AsciiLanguage [Index] >= 'A' && AsciiLanguage [Index] <= 'Z') { - AsciiLanguage [Index] = (CHAR8) (AsciiLanguage [Index] - 'A' + 'a'); - } - } - - for (Index = 0; Index < sizeof (Iso639ToRfc4646Map) / sizeof (Iso639ToRfc4646Map[0]); Index++) { - if (AsciiStrnCmp (AsciiLanguage, Iso639ToRfc4646Map[Index].Iso639, AsciiStrSize (AsciiLanguage)) == 0) { - return Iso639ToRfc4646Map[Index].Rfc4646; - } - } - - return (CHAR8 *) NULL; -} - -/** - Convert language code from RFC4646 to ISO639-2. - - @param LanguageRfc4646 RFC4646 language code. - @param LanguageIso639 ISO639-2 language code. - - @retval EFI_SUCCESS Language code converted. - @retval EFI_NOT_FOUND Language code not found. - -**/ -EFI_STATUS -EFIAPI -ConvertRfc4646LanguageToIso639Language ( - IN CHAR8 *LanguageRfc4646, - OUT CHAR8 *LanguageIso639 - ) -{ - UINTN Index; - - if ((LanguageRfc4646[2] != '-') && (LanguageRfc4646[2] != 0)) { - CopyMem (LanguageIso639, LanguageRfc4646, 3); - return EFI_SUCCESS; - } - - for (Index = 0; Iso639ToRfc4646ConversionTable[Index] != 0; Index += 5) { - if (CompareMem (LanguageRfc4646, &Iso639ToRfc4646ConversionTable[Index + 3], 2) == 0) { - CopyMem (LanguageIso639, &Iso639ToRfc4646ConversionTable[Index], 3); - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - - -/** - Convert language code from ISO639-2 to RFC4646 and return the converted language. - Caller is responsible for freeing the allocated buffer. - - LanguageIso639 contain a single ISO639-2 code such as - "eng" or "fra". - - If LanguageIso639 is NULL, then ASSERT. - If LanguageRfc4646 is NULL, then ASSERT. - - @param LanguageIso639 ISO639-2 language code. - - @return the allocated buffer or NULL, if the language is not found. - -**/ -CHAR8* -EFIAPI -ConvertIso639LanguageToRfc4646Language ( - IN CONST CHAR8 *LanguageIso639 - ) -{ - UINTN Index; - CHAR8 *Rfc4646Language; - - for (Index = 0; Iso639ToRfc4646ConversionTable[Index] != 0; Index += 5) { - if (CompareMem (LanguageIso639, &Iso639ToRfc4646ConversionTable[Index], 3) == 0) { - Rfc4646Language = AllocateZeroPool (3); - if (Rfc4646Language != NULL) { - Rfc4646Language = CopyMem (Rfc4646Language, &Iso639ToRfc4646ConversionTable[Index + 3], 2); - } - return Rfc4646Language; - } - } - - return NULL; -} - -/** - Get next language from language code list (with separator ';'). - - If LangCode is NULL, then ASSERT. - If Lang is NULL, then ASSERT. - - @param LangCode On input: point to first language in the list. On - output: point to next language in the list, or - NULL if no more language in the list. - @param Lang The first language in the list. - -**/ -VOID -EFIAPI -GetNextLanguage ( - IN OUT CHAR8 **LangCode, - OUT CHAR8 *Lang - ) -{ - UINTN Index; - CHAR8 *StringPtr; - - ASSERT (LangCode != NULL); - ASSERT (*LangCode != NULL); - ASSERT (Lang != NULL); - - Index = 0; - StringPtr = *LangCode; - while (StringPtr[Index] != 0 && StringPtr[Index] != ';') { - Index++; - } - - CopyMem (Lang, StringPtr, Index); - Lang[Index] = 0; - - if (StringPtr[Index] == ';') { - Index++; - } - *LangCode = StringPtr + Index; -} - /** Test if all of the characters in a string have corresponding font characters. @@ -468,7 +175,7 @@ HiiNewString ( ZeroMem (LanguageCopy, sizeof (LanguageCopy)); CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16)); UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage); - Rfc4646AsciiLanguage = ConvertIso639ToRfc4646 (AsciiLanguage); + Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (AsciiLanguage); ASSERT (Rfc4646AsciiLanguage != NULL); } @@ -614,7 +321,7 @@ HiiThunkGetString ( // Caller of Framework HII Interface uses the Language Identification String defined // in Iso639. So map it to the Language Identifier defined in RFC4646. // - Rfc4646AsciiLanguage = ConvertIso639ToRfc4646 (Iso639AsciiLanguage); + Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (Iso639AsciiLanguage); // // If Rfc4646AsciiLanguage is NULL, more language mapping must be added to -- cgit v1.2.3