X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=FatPkg%2FEnhancedFatDxe%2FUnicodeCollation.c;h=61b9aab4d93a66296001cd0b2bd175490c826f60;hb=19d29d358f80a1f2b462d8a52943aae724b8702c;hp=4a849af2eb642e013345d686cc537128a8388ab4;hpb=8288dd3ef894b6a080cf3b61d02e9a27f01af742;p=mirror_edk2.git diff --git a/FatPkg/EnhancedFatDxe/UnicodeCollation.c b/FatPkg/EnhancedFatDxe/UnicodeCollation.c index 4a849af2eb..61b9aab4d9 100644 --- a/FatPkg/EnhancedFatDxe/UnicodeCollation.c +++ b/FatPkg/EnhancedFatDxe/UnicodeCollation.c @@ -1,144 +1,77 @@ /** @file - Unicode Collation Library that hides the trival difference of Unicode Collation + Unicode Collation Support component that hides the trivial difference of Unicode Collation and Unicode collation 2 Protocol. - Copyright (c) 2007, Intel Corporation
- All rights reserved. This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php + Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available +under the terms and conditions of the BSD License which accompanies this +distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #include "Fat.h" -STATIC EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationInterface = NULL; +EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationInterface = NULL; -typedef -BOOLEAN -(* SEARCH_LANG_CODE) ( - IN CONST CHAR8 *Languages, - IN CONST CHAR8 *MatchLangCode - ); - -struct _UNICODE_INTERFACE { - CHAR16 *VariableName; - CHAR8 *DefaultLangCode; - SEARCH_LANG_CODE SearchLangCode; - EFI_GUID *UnicodeProtocolGuid; -}; - -typedef struct _UNICODE_INTERFACE UNICODE_INTERFACE; - -STATIC -BOOLEAN -SearchIso639LangCode ( - IN CONST CHAR8 *Languages, - IN CONST CHAR8 *MatchLangCode - ) -{ - CONST CHAR8 *LangCode; - - for (LangCode = Languages; *LangCode != '\0'; LangCode += 3) { - if (CompareMem (LangCode, MatchLangCode, 3) == 0) { - return TRUE; - } - } - - return FALSE; -} - -STATIC -BOOLEAN -SearchRfc3066LangCode ( - IN CONST CHAR8 *Languages, - IN CONST CHAR8 *MatchLangCode - ) -{ - CHAR8 *SubStr; - CHAR8 Terminal; - - SubStr = AsciiStrStr (Languages, MatchLangCode); - if (SubStr == NULL) { - return FALSE; - } +/** + Worker function to initialize Unicode Collation support. - if (SubStr != Languages && *(SubStr - 1) != ';') { - return FALSE; - } + It tries to locate Unicode Collation (2) protocol and matches it with current + platform language code. - Terminal = *(SubStr + AsciiStrLen (MatchLangCode)); - if (Terminal != '\0' && Terminal != ';') { - return FALSE; - } + @param AgentHandle The handle used to open Unicode Collation (2) protocol. + @param ProtocolGuid The pointer to Unicode Collation (2) protocol GUID. + @param VariableName The name of the RFC 4646 or ISO 639-2 language variable. + @param DefaultLanguage The default language in case the RFC 4646 or ISO 639-2 language is absent. - return TRUE; -} + @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located. + @retval Others The Unicode Collation (2) protocol has not been located. -GLOBAL_REMOVE_IF_UNREFERENCED UNICODE_INTERFACE mIso639Lang = { - L"Lang", - (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang), - SearchIso639LangCode, - &gEfiUnicodeCollationProtocolGuid, -}; - -GLOBAL_REMOVE_IF_UNREFERENCED UNICODE_INTERFACE mRfc3066Lang = { - L"PlatformLang", - (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang), - SearchRfc3066LangCode, - &gEfiUnicodeCollation2ProtocolGuid, -}; - -STATIC +**/ EFI_STATUS -InitializeUnicodeCollationSupportWithConfig ( +InitializeUnicodeCollationSupportWorker ( IN EFI_HANDLE AgentHandle, - IN UNICODE_INTERFACE *UnicodeInterface + IN EFI_GUID *ProtocolGuid, + IN CONST CHAR16 *VariableName, + IN CONST CHAR8 *DefaultLanguage ) { + EFI_STATUS ReturnStatus; EFI_STATUS Status; - CHAR8 Buffer[100]; - UINTN BufferSize; + UINTN NumHandles; UINTN Index; - CHAR8 *LangCode; - UINTN NoHandles; EFI_HANDLE *Handles; EFI_UNICODE_COLLATION_PROTOCOL *Uci; - - LangCode = Buffer; - BufferSize = sizeof (Buffer); - Status = gRT->GetVariable ( - UnicodeInterface->VariableName, - &gEfiGlobalVariableGuid, - NULL, - &BufferSize, - Buffer - ); - if (EFI_ERROR (Status)) { - LangCode = UnicodeInterface->DefaultLangCode; - } + BOOLEAN Iso639Language; + CHAR8 *Language; + CHAR8 *BestLanguage; Status = gBS->LocateHandleBuffer ( ByProtocol, - UnicodeInterface->UnicodeProtocolGuid, + ProtocolGuid, NULL, - &NoHandles, + &NumHandles, &Handles ); if (EFI_ERROR (Status)) { return Status; } - for (Index = 0; Index < NoHandles; Index++) { + Iso639Language = (BOOLEAN) (ProtocolGuid == &gEfiUnicodeCollationProtocolGuid); + GetEfiGlobalVariable2 (VariableName, (VOID**) &Language, NULL); + + ReturnStatus = EFI_UNSUPPORTED; + for (Index = 0; Index < NumHandles; Index++) { // // Open Unicode Collation Protocol // Status = gBS->OpenProtocol ( Handles[Index], - UnicodeInterface->UnicodeProtocolGuid, + ProtocolGuid, (VOID **) &Uci, AgentHandle, NULL, @@ -148,20 +81,41 @@ InitializeUnicodeCollationSupportWithConfig ( continue; } - if (UnicodeInterface->SearchLangCode (Uci->SupportedLanguages, LangCode)) { + // + // Find the best matching matching language from the supported languages + // of Unicode Collation (2) protocol. + // + BestLanguage = GetBestLanguage ( + Uci->SupportedLanguages, + Iso639Language, + (Language == NULL) ? "" : Language, + DefaultLanguage, + NULL + ); + if (BestLanguage != NULL) { + FreePool (BestLanguage); mUnicodeCollationInterface = Uci; + ReturnStatus = EFI_SUCCESS; break; } } + if (Language != NULL) { + FreePool (Language); + } + FreePool (Handles); - return (mUnicodeCollationInterface != NULL)? EFI_SUCCESS : EFI_NOT_FOUND; + return ReturnStatus; } /** Initialize Unicode Collation support. + It tries to locate Unicode Collation 2 protocol and matches it with current + platform language code. If for any reason the first attempt fails, it then tries to + use Unicode Collation Protocol. + @param AgentHandle The handle used to open Unicode Collation (2) protocol. @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located. @@ -177,17 +131,33 @@ InitializeUnicodeCollationSupport ( EFI_STATUS Status; Status = EFI_UNSUPPORTED; - if (FeaturePcdGet (PcdUnicodeCollation2Support)) { - Status = InitializeUnicodeCollationSupportWithConfig (AgentHandle, &mRfc3066Lang); - } - if (FeaturePcdGet (PcdUnicodeCollationSupport) && EFI_ERROR (Status)) { - Status = InitializeUnicodeCollationSupportWithConfig (AgentHandle, &mIso639Lang); + // + // First try to use RFC 4646 Unicode Collation 2 Protocol. + // + Status = InitializeUnicodeCollationSupportWorker ( + AgentHandle, + &gEfiUnicodeCollation2ProtocolGuid, + L"PlatformLang", + (CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang) + ); + // + // If the attempt to use Unicode Collation 2 Protocol fails, then we fall back + // on the ISO 639-2 Unicode Collation Protocol. + // + if (EFI_ERROR (Status)) { + Status = InitializeUnicodeCollationSupportWorker ( + AgentHandle, + &gEfiUnicodeCollationProtocolGuid, + L"Lang", + (CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang) + ); } return Status; } + /** Performs a case-insensitive comparison of two Null-terminated Unicode strings.