]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c
Add new interface GetVariable2 and GetEfiGlobalVariable2 to return more info. Also...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Strings.c
index 05a885cc8ffc0ad14fc7d38d9bf0464f7f8c1f5a..3b14c75df5702f17f555f8bd38e5506f8f784850 100644 (file)
@@ -1,8 +1,8 @@
-/**@file\r
+/** @file\r
   This file implements the protocol functions related to string package.\r
   \r
-Copyright (c) 2006 - 2008, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+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
@@ -15,42 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "HiiDatabase.h"\r
 \r
-typedef struct {\r
-  CHAR8 *Iso639;\r
-  CHAR8 *Rfc3066;\r
-} ISO639TORFC3066MAP;\r
-\r
-ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {\r
-    {"eng", "en-US"},\r
-    {"fra", "fr-FR"},\r
-};\r
-\r
-CHAR8 *\r
-ConvertIso639ToRfc3066 (\r
-  CHAR8 *Iso638Lang\r
-  )\r
-{\r
-  UINTN Index;\r
-  CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
-  \r
-  AsciiStrnCpy (AsciiLanguage, Iso638Lang, sizeof (AsciiLanguage));\r
-  for (Index = 0; Index < ISO_639_2_ENTRY_SIZE + 1; Index ++) {\r
-       if (AsciiLanguage [Index] == 0) {\r
-               break;\r
-       } else if (AsciiLanguage [Index] >= 'A' && AsciiLanguage [Index] <= 'Z') {\r
-               AsciiLanguage [Index] = (CHAR8) (AsciiLanguage [Index] - 'A' + 'a');\r
-       }\r
-  }\r
-\r
-  for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {\r
-    if (AsciiStrnCmp (AsciiLanguage, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (AsciiLanguage)) == 0) {\r
-      return Iso639ToRfc3066Map[Index].Rfc3066;\r
-    }\r
-  }\r
-\r
-  return (CHAR8 *) NULL;\r
-}\r
-\r
 /**\r
   Test if all of the characters in a string have corresponding font characters.\r
 \r
@@ -126,7 +90,7 @@ GetTagGuidByFwHiiHandle (
   Create or update the String given a new string and String ID.\r
 \r
   @param ThunkContext           The Thunk Context.\r
-  @param Rfc3066AsciiLanguage   The RFC 3066 Language code in ASCII string format.\r
+  @param Rfc4646AsciiLanguage   The RFC 4646 Language code in ASCII string format.\r
   @param NewString              The new string.\r
   @param StringId               The String ID. If StringId is 0, a new String Token\r
                                 is created. Otherwise, the String Token StringId is \r
@@ -142,14 +106,14 @@ GetTagGuidByFwHiiHandle (
 EFI_STATUS\r
 UpdateString (\r
   IN CONST HII_THUNK_CONTEXT        *ThunkContext,\r
-  IN CONST CHAR8                    *Rfc3066AsciiLanguage,\r
+  IN CONST CHAR8                    *Rfc4646AsciiLanguage,\r
   IN       CHAR16                   *NewString,\r
   IN OUT STRING_REF                 *StringId\r
   )\r
 {\r
   EFI_STRING_ID                             NewStringId;\r
 \r
-  NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc3066AsciiLanguage);\r
+  NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc4646AsciiLanguage);\r
   *StringId = NewStringId;\r
   if (NewStringId == 0) {\r
     //\r
@@ -171,7 +135,7 @@ UpdateString (
                          identifier, indicating the language to print. A string consisting of\r
                          all spaces indicates that the string is applicable to all languages.\r
   @param Handle          The handle of the language pack to which the string is to be added.\r
-  @param Token           The string token assigned to the string.\r
+  @param Reference       The string token assigned to the string.\r
   @param NewString       The string to be added.\r
 \r
 \r
@@ -179,7 +143,6 @@ UpdateString (
   @retval EFI_INVALID_PARAMETER   The Handle was unknown. The string is not created or updated in the\r
                                   the string package.\r
 **/\r
-\r
 EFI_STATUS\r
 EFIAPI\r
 HiiNewString (\r
@@ -200,19 +163,19 @@ HiiNewString (
   EFI_STRING_ID                             LastStringId;\r
   CHAR8                                     AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
   CHAR16                                    LanguageCopy[ISO_639_2_ENTRY_SIZE + 1];\r
-  CHAR8                                     *Rfc3066AsciiLanguage;\r
+  CHAR8                                     *Rfc4646AsciiLanguage;\r
 \r
   LastStringId      = (EFI_STRING_ID) 0;\r
   StringId          = (EFI_STRING_ID) 0;\r
-  Rfc3066AsciiLanguage = NULL;\r
+  Rfc4646AsciiLanguage = NULL;\r
 \r
   if (Language != NULL) {\r
     ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;\r
     ZeroMem (LanguageCopy, sizeof (LanguageCopy));\r
     CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));\r
     UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);\r
-    Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);\r
-    ASSERT (Rfc3066AsciiLanguage != NULL);\r
+    Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (AsciiLanguage);\r
+    ASSERT (Rfc4646AsciiLanguage != NULL);\r
   }\r
 \r
   Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
@@ -233,7 +196,7 @@ HiiNewString (
       if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {\r
         if (ThunkContext->SharingStringPack) {\r
           StringId = *Reference;\r
-          Status = UpdateString (ThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);\r
+          Status = UpdateString (ThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
           if (EFI_ERROR (Status)) {\r
             break;\r
           }\r
@@ -261,7 +224,7 @@ HiiNewString (
     }\r
   } else {\r
     StringId = *Reference;\r
-    Status = UpdateString (StringPackThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);\r
+    Status = UpdateString (StringPackThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
   }\r
 \r
   if (!EFI_ERROR (Status)) {\r
@@ -328,13 +291,13 @@ HiiThunkGetString (
   IN     STRING_REF                 Token,\r
   IN     BOOLEAN                    Raw,\r
   IN     CHAR16                     *LanguageString,\r
-  IN OUT UINTN                      *BufferLengthTemp,\r
+  IN OUT UINTN                      *BufferLength,\r
   OUT    EFI_STRING                 StringBuffer\r
   )\r
 {\r
   HII_THUNK_PRIVATE_DATA                *Private;\r
   CHAR8                                 *Iso639AsciiLanguage;\r
-  CHAR8                                 *Rfc3066AsciiLanguage;\r
+  CHAR8                                 *Rfc4646AsciiLanguage;\r
   CHAR8                                 *SupportedLanguages;\r
   CHAR8                                 *PlatformLanguage;\r
   CHAR8                                 *BestLanguage;\r
@@ -343,8 +306,10 @@ HiiThunkGetString (
 \r
   Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
 \r
-  Iso639AsciiLanguage = NULL;\r
-  Rfc3066AsciiLanguage = NULL;\r
+  Rfc4646AsciiLanguage = NULL;\r
+  SupportedLanguages   = NULL;\r
+  PlatformLanguage     = NULL;\r
+  Status               = EFI_SUCCESS;\r
 \r
   if (LanguageString != NULL) {\r
     Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
@@ -355,16 +320,16 @@ HiiThunkGetString (
 \r
     //\r
     // Caller of Framework HII Interface uses the Language Identification String defined \r
-    // in Iso639. So map it to the Language Identifier defined in RFC3066.\r
+    // in Iso639. So map it to the Language Identifier defined in RFC4646.\r
     //\r
-    Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage);\r
+    Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (Iso639AsciiLanguage);\r
+    FreePool (Iso639AsciiLanguage);\r
 \r
     //\r
-    // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to \r
-    // Iso639ToRfc3066Map.\r
+    // If Rfc4646AsciiLanguage is NULL, more language mapping must be added to \r
+    // Iso639ToRfc4646Map.\r
     //\r
-    ASSERT (Rfc3066AsciiLanguage != NULL);\r
-    \r
+    ASSERT (Rfc4646AsciiLanguage != NULL);\r
   }\r
 \r
   UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);\r
@@ -373,69 +338,57 @@ HiiThunkGetString (
     goto Done;\r
   }\r
 \r
-  if (Rfc3066AsciiLanguage == NULL) {\r
-    //\r
-    // Get the languages that the package specified by HiiHandle supports\r
-    //\r
-    SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle);\r
-    if (SupportedLanguages == NULL) {\r
-      goto Error2;\r
-    }\r
-\r
-    //\r
-    // Get the current platform language setting\r
-    //\r
-    PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang");\r
-    if (PlatformLanguage == NULL) {\r
-      goto Error1;\r
-    }\r
-\r
-    //\r
-    // Get the best matching language from SupportedLanguages\r
-    //\r
-    BestLanguage = GetBestLanguage (\r
-                     SupportedLanguages, \r
-                     FALSE,                // RFC 4646 mode\r
-                     PlatformLanguage,     // Next highest priority\r
-                     SupportedLanguages,   // Lowest priority \r
-                     NULL\r
-                     );\r
-    if (BestLanguage == NULL) {\r
-      FreePool (PlatformLanguage);\r
-Error1:\r
-      FreePool (SupportedLanguages);\r
-Error2:\r
-      Status = EFI_INVALID_PARAMETER;\r
-      goto Done;\r
-    }\r
+  //\r
+  // Get the languages that the package specified by HiiHandle supports\r
+  //\r
+  SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle);\r
+  if (SupportedLanguages == NULL) {\r
+    goto Done;\r
+  }\r
 \r
+  //\r
+  // Get the current platform language setting\r
+  //\r
+  GetEfiGlobalVariable2 (L"PlatformLang", &PlatformLanguage, NULL);\r
+\r
+  //\r
+  // Get the best matching language from SupportedLanguages\r
+  //\r
+  BestLanguage = GetBestLanguage (\r
+                   SupportedLanguages, \r
+                   FALSE,                // RFC 4646 mode\r
+                   (Rfc4646AsciiLanguage != NULL) ? Rfc4646AsciiLanguage : "", // Highest priority \r
+                   (PlatformLanguage != NULL) ? PlatformLanguage : "",         // Next highest priority\r
+                   SupportedLanguages,   // Lowest priority \r
+                   NULL\r
+                   );\r
+  if (BestLanguage != NULL) {\r
     Status = mHiiStringProtocol->GetString (\r
                                  mHiiStringProtocol,\r
                                  BestLanguage,\r
                                  UefiHiiHandle,\r
                                  Token,\r
                                  StringBuffer,\r
-                                 BufferLengthTemp,\r
+                                 BufferLength,\r
                                  NULL\r
                                  );\r
     FreePool (BestLanguage);\r
   } else {\r
-    Status = mHiiStringProtocol->GetString (\r
-                                 mHiiStringProtocol,\r
-                                 Rfc3066AsciiLanguage,\r
-                                 UefiHiiHandle,\r
-                                 Token,\r
-                                 StringBuffer,\r
-                                 BufferLengthTemp,\r
-                                 NULL\r
-                                 );\r
+    Status = EFI_INVALID_PARAMETER;\r
   }\r
 \r
 Done:\r
-       if (Iso639AsciiLanguage != NULL) {\r
-    FreePool (Iso639AsciiLanguage);\r
+       if (Rfc4646AsciiLanguage != NULL) {\r
+    FreePool (Rfc4646AsciiLanguage);\r
+  }\r
+\r
+  if (SupportedLanguages != NULL) {\r
+    FreePool (SupportedLanguages);\r
+  }\r
+\r
+  if (PlatformLanguage != NULL) {\r
+    FreePool (PlatformLanguage);\r
   }\r
-  \r
   return Status;\r
 }\r
 \r
@@ -451,9 +404,10 @@ Done:
   @param This            A pointer to the EFI_HII_PROTOCOL instance.\r
   @param Handle          The HII handle on which the string resides.\r
   @param Token           The string token assigned to the string.\r
-  @param Raw             If TRUE, the string is returned unedited in the internal storage format described\r
-                         above. If false, the string returned is edited by replacing <cr> with <space>\r
-                         and by removing special characters such as the <wide> prefix.\r
+  @param Index           On input, the offset into the string where the line is to start.\r
+                         On output, the index is updated to point to beyond the last character returned\r
+                         in the call.\r
+  @param LineWidth       The maximum width of the line in units of narrow glyphs.\r
   @param LanguageString  Pointer to a NULL-terminated string containing a single ISO 639-2 language\r
                          identifier, indicating the language to print. If the LanguageString is empty (starts\r
                          with a NULL), the default system language will be used to determine the language.\r