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