]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLanguage.c
index 58817c1bafdc4cc91fe4d27c16e8dce7ae9f333c..2519afa7d42328e4d8959e2ecb2ad0f488a730d4 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Language related HII Library implementation.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2006 - 2008, 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
 #include "InternalHiiLib.h"\r
 \r
 /**\r
-  Get next language from language code list (with separator ';').\r
-\r
-  If LangCode is NULL, then ASSERT.\r
-  If Lang is NULL, then ASSERT.\r
-\r
-  @param  LangCode    On input: point to first language in the list. On\r
-                                 output: point to next language in the list, or\r
-                                 NULL if no more language in the list.\r
-  @param  Lang           The first language in the list.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-HiiLibGetNextLanguage (\r
-  IN OUT CHAR8      **LangCode,\r
-  OUT CHAR8         *Lang\r
-  )\r
-{\r
-  UINTN  Index;\r
-  CHAR8  *StringPtr;\r
-\r
-  ASSERT (LangCode != NULL);\r
-  ASSERT (*LangCode != NULL);\r
-  ASSERT (Lang != NULL);\r
-\r
-  Index = 0;\r
-  StringPtr = *LangCode;\r
-  while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {\r
-    Index++;\r
-  }\r
-\r
-  CopyMem (Lang, StringPtr, Index);\r
-  Lang[Index] = 0;\r
-\r
-  if (StringPtr[Index] == ';') {\r
-    Index++;\r
-  }\r
-  *LangCode = StringPtr + Index;\r
-}\r
-\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
+  LanguageSize = 0;\r
+  Status = gHiiString->GetLanguages (gHiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize);\r
 \r
-  Status = mHiiStringProt->GetLanguages (mHiiStringProt, 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 = mHiiStringProt->GetLanguages (mHiiStringProt, 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[RFC_3066_ENTRY_SIZE];\r
-\r
-  Languages = HiiLibGetSupportedLanguages (HiiHandle);\r
-  if (Languages == NULL) {\r
-    return 0;\r
-  }\r
-\r
-  LangNumber = 0;\r
-  LanguageString = Languages;\r
-  while (*LanguageString != 0) {\r
-    HiiLibGetNextLanguage (&LanguageString, Lang);\r
-    LangNumber++;\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 = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, 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 = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize);\r
-  }\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    LanguageString = NULL;\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
-  return LanguageString;\r
-}\r
-\r
-\r
-/**\r
-  Determine what is the current language setting. The space reserved for Lang\r
-  must be at least RFC_3066_ENTRY_SIZE bytes;\r
-\r
-  If Lang is NULL, then ASSERT.\r
-\r
-  @param  Lang                   Pointer of system language. Lang will always be filled with \r
-                                 a valid RFC 3066 language string. If "PlatformLang" is not\r
-                                 set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang\r
-                                 is returned.\r
-\r
-  @return  EFI_SUCCESS     If the EFI Variable with "PlatformLang" is set and return in Lang.\r
-  @return  EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetCurrentLanguage (\r
-  OUT     CHAR8               *Lang\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-  UINTN       Size;\r
-\r
-  ASSERT (Lang != NULL);\r
-\r
   //\r
-  // Get current language setting\r
+  // Retrieve the supported languages string\r
   //\r
-  Size = RFC_3066_ENTRY_SIZE;\r
-  Status = gRT->GetVariable (\r
-                  L"PlatformLang",\r
-                  &gEfiGlobalVariableGuid,\r
-                  NULL,\r
-                  &Size,\r
-                  Lang\r
-                  );\r
-\r
+  Status = gHiiString->GetLanguages (gHiiString, HiiHandle, SupportedLanguages, &LanguageSize);\r
   if (EFI_ERROR (Status)) {\r
-    AsciiStrCpy (Lang, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang));\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 Status;\r
+  //\r
+  // Return the Null-terminated ASCII string of supported languages\r
+  //\r
+  return SupportedLanguages;\r
 }\r
 \r
-\r
-\r