X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=EdkCompatibilityPkg%2FCompatibility%2FFrameworkHiiOnUefiHiiThunk%2FStrings.c;h=d83750bc9b8f16bd70e89e7a19dffee64e50140b;hb=f324bf4dbeda4d64b769bd005331e8f9404b692d;hp=caa702d5dda17b49fb4ee14afc61ffccc93a2947;hpb=ad5a96ab2daeeac53f0c924113f23dc931f965c5;p=mirror_edk2.git diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c index caa702d5dd..d83750bc9b 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c @@ -15,258 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "HiiDatabase.h" -typedef struct { - CHAR8 *Iso639; - CHAR8 *Rfc3066; -} ISO639TORFC3066MAP; - -ISO639TORFC3066MAP Iso639ToRfc3066Map [] = { - {"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 Iso639ToRfc3066ConversionTable[] = -"\ -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 * -ConvertIso639ToRfc3066 ( - 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 (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) { - if (AsciiStrnCmp (AsciiLanguage, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (AsciiLanguage)) == 0) { - return Iso639ToRfc3066Map[Index].Rfc3066; - } - } - - return (CHAR8 *) NULL; -} - -/** - Convert language code from RFC3066 to ISO639-2. - - @param LanguageRfc3066 RFC3066 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 -ConvertRfc3066LanguageToIso639Language ( - IN CHAR8 *LanguageRfc3066, - OUT CHAR8 *LanguageIso639 - ) -{ - UINTN Index; - - if ((LanguageRfc3066[2] != '-') && (LanguageRfc3066[2] != 0)) { - CopyMem (LanguageIso639, LanguageRfc3066, 3); - return EFI_SUCCESS; - } - - for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) { - if (CompareMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2) == 0) { - CopyMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3); - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - - -/** - Convert language code from ISO639-2 to RFC3066 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 LanguageRfc3066 is NULL, then ASSERT. - - @param LanguageIso639 ISO639-2 language code. - - @return the allocated buffer or NULL, if the language is not found. - -**/ -CHAR8* -EFIAPI -ConvertIso639LanguageToRfc3066Language ( - IN CONST CHAR8 *LanguageIso639 - ) -{ - UINTN Index; - CHAR8 *Rfc3066Language; - - for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) { - if (CompareMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3) == 0) { - Rfc3066Language = AllocateZeroPool (3); - if (Rfc3066Language != NULL) { - Rfc3066Language = CopyMem (Rfc3066Language, &Iso639ToRfc3066ConversionTable[Index + 3], 2); - } - return Rfc3066Language; - } - } - - return NULL; -} - /** Test if all of the characters in a string have corresponding font characters. @@ -342,7 +90,7 @@ GetTagGuidByFwHiiHandle ( Create or update the String given a new string and String ID. @param ThunkContext The Thunk Context. - @param Rfc3066AsciiLanguage The RFC 3066 Language code in ASCII string format. + @param Rfc4646AsciiLanguage The RFC 4646 Language code in ASCII string format. @param NewString The new string. @param StringId The String ID. If StringId is 0, a new String Token is created. Otherwise, the String Token StringId is @@ -358,14 +106,14 @@ GetTagGuidByFwHiiHandle ( EFI_STATUS UpdateString ( IN CONST HII_THUNK_CONTEXT *ThunkContext, - IN CONST CHAR8 *Rfc3066AsciiLanguage, + IN CONST CHAR8 *Rfc4646AsciiLanguage, IN CHAR16 *NewString, IN OUT STRING_REF *StringId ) { EFI_STRING_ID NewStringId; - NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc3066AsciiLanguage); + NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc4646AsciiLanguage); *StringId = NewStringId; if (NewStringId == 0) { // @@ -416,19 +164,19 @@ HiiNewString ( EFI_STRING_ID LastStringId; CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1]; CHAR16 LanguageCopy[ISO_639_2_ENTRY_SIZE + 1]; - CHAR8 *Rfc3066AsciiLanguage; + CHAR8 *Rfc4646AsciiLanguage; LastStringId = (EFI_STRING_ID) 0; StringId = (EFI_STRING_ID) 0; - Rfc3066AsciiLanguage = NULL; + Rfc4646AsciiLanguage = NULL; if (Language != NULL) { ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));; ZeroMem (LanguageCopy, sizeof (LanguageCopy)); CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16)); UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage); - Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage); - ASSERT (Rfc3066AsciiLanguage != NULL); + Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (AsciiLanguage); + ASSERT (Rfc4646AsciiLanguage != NULL); } Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This); @@ -449,7 +197,7 @@ HiiNewString ( if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) { if (ThunkContext->SharingStringPack) { StringId = *Reference; - Status = UpdateString (ThunkContext, Rfc3066AsciiLanguage, NewString, &StringId); + Status = UpdateString (ThunkContext, Rfc4646AsciiLanguage, NewString, &StringId); if (EFI_ERROR (Status)) { break; } @@ -477,7 +225,7 @@ HiiNewString ( } } else { StringId = *Reference; - Status = UpdateString (StringPackThunkContext, Rfc3066AsciiLanguage, NewString, &StringId); + Status = UpdateString (StringPackThunkContext, Rfc4646AsciiLanguage, NewString, &StringId); } if (!EFI_ERROR (Status)) { @@ -550,7 +298,7 @@ HiiThunkGetString ( { HII_THUNK_PRIVATE_DATA *Private; CHAR8 *Iso639AsciiLanguage; - CHAR8 *Rfc3066AsciiLanguage; + CHAR8 *Rfc4646AsciiLanguage; CHAR8 *SupportedLanguages; CHAR8 *PlatformLanguage; CHAR8 *BestLanguage; @@ -559,8 +307,7 @@ HiiThunkGetString ( Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This); - Iso639AsciiLanguage = NULL; - Rfc3066AsciiLanguage = NULL; + Rfc4646AsciiLanguage = NULL; if (LanguageString != NULL) { Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1); @@ -571,15 +318,16 @@ HiiThunkGetString ( // // Caller of Framework HII Interface uses the Language Identification String defined - // in Iso639. So map it to the Language Identifier defined in RFC3066. + // in Iso639. So map it to the Language Identifier defined in RFC4646. // - Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage); + Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (Iso639AsciiLanguage); + FreePool (Iso639AsciiLanguage); // - // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to - // Iso639ToRfc3066Map. + // If Rfc4646AsciiLanguage is NULL, more language mapping must be added to + // Iso639ToRfc4646Map. // - ASSERT (Rfc3066AsciiLanguage != NULL); + ASSERT (Rfc4646AsciiLanguage != NULL); } @@ -589,67 +337,56 @@ HiiThunkGetString ( goto Done; } - if (Rfc3066AsciiLanguage == NULL) { - // - // Get the languages that the package specified by HiiHandle supports - // - SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle); - if (SupportedLanguages == NULL) { - goto Error2; - } + // + // Get the languages that the package specified by HiiHandle supports + // + SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle); + if (SupportedLanguages == NULL) { + goto Error2; + } - // - // Get the current platform language setting - // - PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang"); - if (PlatformLanguage == NULL) { - goto Error1; - } + // + // Get the current platform language setting + // + PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang"); + if (PlatformLanguage == NULL) { + goto Error1; + } - // - // Get the best matching language from SupportedLanguages - // - BestLanguage = GetBestLanguage ( - SupportedLanguages, - FALSE, // RFC 4646 mode - PlatformLanguage, // Next highest priority - SupportedLanguages, // Lowest priority - NULL - ); - if (BestLanguage == NULL) { - FreePool (PlatformLanguage); + // + // Get the best matching language from SupportedLanguages + // + BestLanguage = GetBestLanguage ( + SupportedLanguages, + FALSE, // RFC 4646 mode + (Rfc4646AsciiLanguage != NULL) ? Rfc4646AsciiLanguage : "", + PlatformLanguage, // Next highest priority + SupportedLanguages, // Lowest priority + NULL + ); + if (BestLanguage == NULL) { + FreePool (PlatformLanguage); Error1: - FreePool (SupportedLanguages); + FreePool (SupportedLanguages); Error2: - Status = EFI_INVALID_PARAMETER; - goto Done; - } - - Status = mHiiStringProtocol->GetString ( - mHiiStringProtocol, - BestLanguage, - UefiHiiHandle, - Token, - StringBuffer, - BufferLengthTemp, - NULL - ); - FreePool (BestLanguage); - } else { - Status = mHiiStringProtocol->GetString ( - mHiiStringProtocol, - Rfc3066AsciiLanguage, - UefiHiiHandle, - Token, - StringBuffer, - BufferLengthTemp, - NULL - ); + Status = EFI_INVALID_PARAMETER; + goto Done; } + Status = mHiiStringProtocol->GetString ( + mHiiStringProtocol, + BestLanguage, + UefiHiiHandle, + Token, + StringBuffer, + BufferLengthTemp, + NULL + ); + FreePool (BestLanguage); + Done: - if (Iso639AsciiLanguage != NULL) { - FreePool (Iso639AsciiLanguage); + if (Rfc4646AsciiLanguage != NULL) { + FreePool (Rfc4646AsciiLanguage); } return Status;