]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Apply GetBestLanguage() UefiLib to initialize Unicode Collation Protocol.
authorQing Huang <qing.huang@intel.com>
Tue, 24 Mar 2009 14:19:12 +0000 (14:19 +0000)
committerJordan Justen <jordan.l.justen@intel.com>
Thu, 7 Apr 2016 06:22:43 +0000 (23:22 -0700)
(based on FatPkg commit 63726907ef8f40b3ffea8aab464d133fa06f1e67)

[jordan.l.justen@intel.com: Use script to relicense to 2-clause BSD]
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Acked-by: Mark Doran <mark.doran@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
FatPkg/EnhancedFatDxe/Fat.h
FatPkg/EnhancedFatDxe/Fat.inf
FatPkg/EnhancedFatDxe/UnicodeCollation.c

index 2df8f78e84f5d4cae5ddc662b4eef9a7c74c2775..3a782cb0266993e68638effd25257724e98e2536 100644 (file)
@@ -30,7 +30,6 @@ Revision History
 #include <Guid/FileInfo.h>\r
 #include <Guid/FileSystemInfo.h>\r
 #include <Guid/FileSystemVolumeLabelInfo.h>\r
-#include <Guid/GlobalVariable.h>\r
 #include <Protocol/BlockIo.h>\r
 #include <Protocol/DiskIo.h>\r
 #include <Protocol/SimpleFileSystem.h>\r
index 56f37cb6678085b0fb5cd16324ca5b9a44168025..cf2bfe8935f58a8c14666dadfeb4c786a2fbdb0c 100644 (file)
@@ -80,7 +80,6 @@
   gEfiFileInfoGuid\r
   gEfiFileSystemInfoGuid\r
   gEfiFileSystemVolumeLabelInfoIdGuid\r
-  gEfiGlobalVariableGuid\r
 \r
 [Protocols]\r
   gEfiDiskIoProtocolGuid\r
index 9e5db7b96714abc2d80a6db95bdd03ebc4918f71..574db9783e3518cb6864b91ef14347c78b3d7216 100644 (file)
@@ -1,8 +1,8 @@
 /** @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
+  Copyright (c) 2007 - 2009, 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
 \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
-  SubStr = AsciiStrStr (Languages, MatchLangCode);\r
-  if (SubStr == NULL) {\r
-    return FALSE;\r
-  }\r
+/**\r
+  Worker function to initialize Unicode Collation support.\r
 \r
-  if (SubStr != Languages && *(SubStr - 1) != ';') {\r
-    return FALSE;\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
+  platform language code. If for any reason the first attempt fails, it then tries to\r
+  use Unicode Collation Protocol.\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                      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
+  Language = GetEfiGlobalVariable(VariableName);\r
+\r
+  Status = 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
@@ -148,15 +83,42 @@ InitializeUnicodeCollationSupportWithConfig (
       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
+    if (Language == NULL) {\r
+      BestLanguage = GetBestLanguage (\r
+                       Uci->SupportedLanguages,\r
+                       Iso639Language,\r
+                       DefaultLanguage,\r
+                       NULL\r
+                       );\r
+    } else {\r
+      BestLanguage = GetBestLanguage (\r
+                       Uci->SupportedLanguages,\r
+                       Iso639Language,\r
+                       Language,\r
+                       Iso639Language,\r
+                       DefaultLanguage,\r
+                       NULL\r
+                       );\r
+    }\r
+    if (BestLanguage != NULL) {\r
+      FreePool (BestLanguage);\r
       mUnicodeCollationInterface = Uci;\r
+      Status = 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 Status;\r
 }\r
 \r
 /**\r
@@ -185,10 +147,15 @@ InitializeUnicodeCollationSupport (
   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
+    Status = InitializeUnicodeCollationSupportWorker (\r
+               AgentHandle,\r
+               &gEfiUnicodeCollation2ProtocolGuid,\r
+               L"PlatformLang",\r
+               (CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang)\r
+               );\r
   }\r
 \r
   //\r
@@ -196,12 +163,18 @@ InitializeUnicodeCollationSupport (
   // on the ISO 639-2 Unicode Collation Protocol.\r
   //\r
   if (FeaturePcdGet (PcdUnicodeCollationSupport) && EFI_ERROR (Status)) {\r
-    Status = InitializeUnicodeCollationSupportWithConfig (AgentHandle, &mIso639Lang);\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