]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
HII Library Class interface refine.
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLanguage.c
index 21173296ba90a7158be4c8005d0c03fd95fdf30b..45e178c44646ddb7e36cef6a659b4cc17547d56e 100644 (file)
@@ -58,155 +58,81 @@ HiiLibGetNextLanguage (
 \r
 \r
 /**\r
-  This function returns the list of supported languages, in the format specified\r
-  in UEFI specification Appendix M.\r
-\r
-  If HiiHandle is not a valid Handle in the default HII database, then ASSERT.\r
+  Retrieves a pointer to the a Null-terminated ASCII string containing the list \r
+  of languages that an HII handle in the HII Database supports.  The returned \r
+  string is allocated using AllocatePool().  The caller is responsible for freeing\r
+  the returned string using FreePool().  The format of the returned string follows\r
+  the language format assumed the HII Database.\r
+  \r
+  If HiiHandle is NULL, then ASSERT().\r
 \r
-  @param  HiiHandle              The HII package list handle.\r
+  @param[in]  HiiHandle  A handle that was previously registered in the HII Database.\r
 \r
-  @retval   !NULL  The supported languages.\r
-  @retval   NULL    If Supported Languages can not be retrived.\r
+  @retval NULL   HiiHandle is not registered in the HII database\r
+  @retval NULL   There are not enough resources available to retrieve the suported \r
+                 languages.\r
+  @retval NULL   The list of suported languages could not be retrieved.\r
+  @retval Other  A pointer to the Null-terminated ASCII string of supported languages.\r
 \r
 **/\r
 CHAR8 *\r
 EFIAPI\r
-HiiLibGetSupportedLanguages (\r
+HiiGetSupportedLanguages (\r
   IN EFI_HII_HANDLE           HiiHandle\r
   )\r
 {\r
   EFI_STATUS  Status;\r
-  UINTN       BufferSize;\r
-  CHAR8       *LanguageString;\r
+  UINTN       LanguageSize;\r
+  CHAR8       TempSupportedLanguages;\r
+  CHAR8       *SupportedLanguages;\r
+\r
+  ASSERT (HiiHandle != NULL);\r
 \r
-  ASSERT (IsHiiHandleRegistered (HiiHandle));\r
   //\r
-  // Collect current supported Languages for given HII handle\r
-  // First try allocate 4K buffer to store the current supported languages.\r
+  // Retrieve the size required for the supported languages buffer.\r
   //\r
-  BufferSize = 0x1000;\r
-  LanguageString = AllocateZeroPool (BufferSize);\r
-  if (LanguageString == NULL) {\r
-    return NULL;\r
-  }\r
-\r
-  Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize);\r
-  \r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    FreePool (LanguageString);\r
-    LanguageString = AllocateZeroPool (BufferSize);\r
-    if (LanguageString == NULL) {\r
-      return NULL;\r
-    }\r
-\r
-    Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize);\r
-  }\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    LanguageString = NULL;\r
-  }\r
-\r
-  return LanguageString;\r
-}\r
-\r
-\r
-/**\r
-  This function returns the number of supported languages on HiiHandle.\r
-\r
-  If HiiHandle is not a valid Handle in the default HII database, then ASSERT.\r
-  If not enough resource to complete the operation, then ASSERT.\r
-\r
-  @param  HiiHandle              The HII package list handle.\r
-\r
-  @return The  number of supported languages.\r
-\r
-**/\r
-UINT16\r
-EFIAPI\r
-HiiLibGetSupportedLanguageNumber (\r
-  IN EFI_HII_HANDLE           HiiHandle\r
-  )\r
-{\r
-  CHAR8   *Languages;\r
-  CHAR8   *LanguageString;\r
-  UINT16  LangNumber;\r
-  CHAR8   *Lang;\r
-\r
-  Languages = HiiLibGetSupportedLanguages (HiiHandle);\r
-  if (Languages == NULL) {\r
-    return 0;\r
-  }\r
-\r
-  LangNumber = 0;\r
-  Lang = AllocatePool (AsciiStrSize (Languages));\r
-  if (Lang != NULL) {\r
-    LanguageString = Languages;\r
-    while (*LanguageString != 0) {\r
-      HiiLibGetNextLanguage (&LanguageString, Lang);\r
-      LangNumber++;\r
-    }\r
+  LanguageSize = 0;\r
+  Status = gHiiString->GetLanguages (gHiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize);\r
 \r
-    FreePool (Lang);\r
-  }\r
-  FreePool (Languages);\r
-\r
-  return LangNumber;\r
-}\r
-\r
-/**\r
-  This function returns the list of supported 2nd languages, in the format specified\r
-  in UEFI specification Appendix M.\r
-\r
-  If HiiHandle is not a valid Handle in the default HII database, then ASSERT.\r
-  If not enough resource to complete the operation, then ASSERT.\r
-\r
-  @param  HiiHandle              The HII package list handle.\r
-  @param  FirstLanguage          Pointer to language name buffer.\r
-  \r
-  @return The supported languages.\r
-\r
-**/\r
-CHAR8 *\r
-EFIAPI\r
-HiiLibGetSupportedSecondaryLanguages (\r
-  IN EFI_HII_HANDLE           HiiHandle,\r
-  IN CONST CHAR8              *FirstLanguage\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-  UINTN       BufferSize;\r
-  CHAR8       *LanguageString;\r
-\r
-  ASSERT (HiiHandle != NULL);\r
-  ASSERT (IsHiiHandleRegistered (HiiHandle));\r
   //\r
-  // Collect current supported 2nd Languages for given HII handle\r
-  // First try allocate 4K buffer to store the current supported 2nd languages.\r
+  // If GetLanguages() returns EFI_SUCCESS for a zero size, \r
+  // then there are no supported languages registered for HiiHandle.  If GetLanguages() \r
+  // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present\r
+  // in the HII Database\r
   //\r
-  BufferSize = 0x1000;\r
-  LanguageString = AllocateZeroPool (BufferSize);\r
-  if (LanguageString == NULL) {\r
+  if (Status != EFI_BUFFER_TOO_SMALL) {\r
+    //\r
+    // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database\r
+    //\r
     return NULL;\r
   }\r
 \r
-  Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize);\r
-  \r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    FreePool (LanguageString);\r
-    LanguageString = AllocateZeroPool (BufferSize);\r
-    if (LanguageString == NULL) {\r
-      return NULL;\r
-    }\r
-\r
-    Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize);\r
+  //\r
+  // Allocate the supported languages buffer.\r
+  //\r
+  SupportedLanguages = AllocateZeroPool (LanguageSize);\r
+  if (SupportedLanguages == NULL) {\r
+    //\r
+    // Return NULL if allocation fails.\r
+    //\r
+    return NULL;\r
   }\r
 \r
+  //\r
+  // Retrieve the supported languages string\r
+  //\r
+  Status = gHiiString->GetLanguages (gHiiString, HiiHandle, SupportedLanguages, &LanguageSize);\r
   if (EFI_ERROR (Status)) {\r
-    LanguageString = NULL;\r
+    //\r
+    // Free the buffer and return NULL if the supported languages can not be retrieved.\r
+    //\r
+    FreePool (SupportedLanguages);\r
+    return NULL;\r
   }\r
 \r
-  return LanguageString;\r
+  //\r
+  // Return the Null-terminated ASCII string of supported languages\r
+  //\r
+  return SupportedLanguages;\r
 }\r
 \r
-\r
-\r