]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/String.c
The input StringInfo should be kept for HiiStringIdToImage() function.
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / String.c
index 321b2f704035dd65c4be08e0f4350f3526e254b5..931e7b397b81b4b5de25d08e9b2ff9a9775499d0 100644 (file)
@@ -2,8 +2,8 @@
 Implementation for EFI_HII_STRING_PROTOCOL.\r
 \r
 \r
-Copyright (c) 2007 - 2010, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2007 - 2011, 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
@@ -248,6 +248,7 @@ GetStringFontInfo (
   @param  StringTextOffset        Offset, relative to the found block address, of\r
                                   the  string text information.\r
   @param  LastStringId            Output the last string id when StringId = 0 or StringId = -1.\r
+  @param  StartStringId           The first id in the skip block which StringId in the block.\r
 \r
   @retval EFI_SUCCESS             The string text and font is retrieved\r
                                   successfully.\r
@@ -265,7 +266,8 @@ FindStringBlock (
   OUT UINT8                           *BlockType, OPTIONAL\r
   OUT UINT8                           **StringBlockAddr, OPTIONAL\r
   OUT UINTN                           *StringTextOffset, OPTIONAL\r
-  OUT EFI_STRING_ID                   *LastStringId OPTIONAL\r
+  OUT EFI_STRING_ID                   *LastStringId, OPTIONAL\r
+  OUT EFI_STRING_ID                   *StartStringId OPTIONAL\r
   )\r
 {\r
   UINT8                                *BlockHdr;\r
@@ -540,12 +542,21 @@ FindStringBlock (
       break;\r
     }\r
 \r
-    if (StringId > 0) {\r
+    if (StringId > 0 && StringId != (EFI_STRING_ID)(-1)) {\r
+      ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);\r
+      *BlockType        = *BlockHdr;\r
+      *StringBlockAddr  = BlockHdr;\r
+      *StringTextOffset = Offset;\r
+\r
       if (StringId == CurrentStringId - 1) {\r
-        *BlockType        = *BlockHdr;\r
-        *StringBlockAddr  = BlockHdr;\r
-        *StringTextOffset = Offset;\r
-        return EFI_SUCCESS;\r
+        //\r
+        // if only one skip item, return EFI_NOT_FOUND.\r
+        //\r
+        if(*BlockType == EFI_HII_SIBT_SKIP2 || *BlockType == EFI_HII_SIBT_SKIP1) {\r
+          return EFI_NOT_FOUND;\r
+        } else {\r
+          return EFI_SUCCESS;\r
+        }\r
       }\r
 \r
       if (StringId < CurrentStringId - 1) {\r
@@ -553,7 +564,9 @@ FindStringBlock (
       }\r
     }\r
     BlockHdr  = StringPackage->StringBlock + BlockSize;\r
-\r
+    if (StartStringId != NULL) {\r
+        *StartStringId  = CurrentStringId;\r
+    }\r
   }\r
   \r
   //\r
@@ -623,6 +636,7 @@ GetStringWorker (
              &BlockType,\r
              &StringBlockAddr,\r
              &StringTextOffset,\r
+             NULL,\r
              NULL\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -684,6 +698,153 @@ GetStringWorker (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  If GetStringBlock find the StringId's string is not saved in the exist string block,\r
+  this function will create the UCS2 string block to save the string; also split the \r
+  skip block into two or one skip block.\r
+\r
+  This is a internal function.\r
+  \r
+  @param  StringPackage           Hii string package instance.\r
+  @param  StartStringId           The first id in the skip block which StringId in the block.\r
+  @param  StringId                The string's id, which is unique within\r
+                                  PackageList.  \r
+  @param  BlockType               Output the block type of found string block.  \r
+  @param  StringBlockAddr         Output the block address of found string block.  \r
+  @param  FontBlock               whether this string block has font info.\r
+\r
+  @retval EFI_SUCCESS            The string font is outputed successfully.\r
+  @retval EFI_OUT_OF_RESOURCES   NO resource for the memory to save the new string block.\r
+\r
+**/\r
+EFI_STATUS\r
+InsertLackStringBlock (\r
+  IN OUT HII_STRING_PACKAGE_INSTANCE         *StringPackage,\r
+  IN EFI_STRING_ID                           StartStringId,\r
+  IN EFI_STRING_ID                           StringId,\r
+  IN OUT UINT8                               *BlockType,\r
+  IN OUT UINT8                               **StringBlockAddr,\r
+  IN BOOLEAN                                 FontBlock\r
+  )\r
+{\r
+  UINT8                                *BlockPtr;\r
+  UINT8                                *StringBlock;\r
+  UINT32                               SkipLen;    \r
+  UINT32                               OldBlockSize;\r
+  UINT32                               NewBlockSize;\r
+  UINT32                               FrontSkipNum;\r
+  UINT32                               NewUCSBlockLen;\r
+  UINT8                                *OldStringAddr;\r
+  UINT32                               IdCount;\r
+\r
+  FrontSkipNum  = 0;\r
+  SkipLen       = 0;\r
+  OldStringAddr = *StringBlockAddr;\r
+  \r
+  ASSERT (*BlockType == EFI_HII_SIBT_SKIP1 || *BlockType == EFI_HII_SIBT_SKIP2);\r
+  //\r
+  // Old skip block size.\r
+  //\r
+  if (*BlockType == EFI_HII_SIBT_SKIP1) {\r
+    SkipLen = sizeof (EFI_HII_SIBT_SKIP1_BLOCK);\r
+    IdCount = *(UINT8*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK));\r
+  } else {\r
+    SkipLen = sizeof (EFI_HII_SIBT_SKIP2_BLOCK);\r
+    IdCount = *(UINT16*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK));\r
+  } \r
+\r
+  //\r
+  // New create UCS or UCS2 block size.\r
+  //\r
+  if (FontBlock) {\r
+    NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK);\r
+  } else {\r
+    NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);\r
+  }\r
+\r
+  OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r
+\r
+  if (StartStringId == StringId) {\r
+    //\r
+    // New block + [Skip block]\r
+    //\r
+    if (IdCount > 1) {\r
+      NewBlockSize = OldBlockSize + NewUCSBlockLen;\r
+    } else {\r
+      NewBlockSize = OldBlockSize + NewUCSBlockLen - SkipLen;\r
+    }\r
+  } else if (StartStringId + IdCount - 1 == StringId){\r
+    //\r
+    // Skip block + New block\r
+    //\r
+    NewBlockSize = OldBlockSize + NewUCSBlockLen;\r
+    FrontSkipNum = StringId - StartStringId;\r
+  } else {\r
+    //\r
+    // Skip block + New block + [Skip block]\r
+    //\r
+    NewBlockSize = OldBlockSize + NewUCSBlockLen + SkipLen;\r
+    FrontSkipNum = StringId - StartStringId;\r
+  }\r
+\r
+  StringBlock = (UINT8 *) AllocateZeroPool (NewBlockSize);\r
+  if (StringBlock == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Copy old block in front of skip block.\r
+  //\r
+  CopyMem (StringBlock, StringPackage->StringBlock, OldStringAddr - StringPackage->StringBlock);  \r
+  BlockPtr = StringBlock + (OldStringAddr - StringPackage->StringBlock);\r
+\r
+  if (FrontSkipNum > 0) {\r
+    *BlockPtr = *BlockType;\r
+    if (*BlockType == EFI_HII_SIBT_SKIP1) {\r
+      *(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT8) FrontSkipNum;\r
+    } else {\r
+      *(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT16) FrontSkipNum;\r
+    }\r
+    BlockPtr += SkipLen;\r
+  }\r
+\r
+  //\r
+  // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK\r
+  //\r
+  *StringBlockAddr = BlockPtr;\r
+  if (FontBlock) {\r
+    *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;\r
+  } else {\r
+    *BlockPtr = EFI_HII_SIBT_STRING_UCS2;\r
+  }\r
+  BlockPtr += NewUCSBlockLen;\r
+\r
+  if (IdCount > FrontSkipNum + 1) {\r
+    *BlockPtr = *BlockType;\r
+    if (*BlockType == EFI_HII_SIBT_SKIP1) {\r
+      *(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT8) (IdCount - FrontSkipNum - 1);\r
+    } else {\r
+      *(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT16) (IdCount - FrontSkipNum - 1);\r
+    }\r
+    BlockPtr += SkipLen;\r
+  }\r
+\r
+  //\r
+  // Append a EFI_HII_SIBT_END block to the end.\r
+  //\r
+  CopyMem (BlockPtr, OldStringAddr + SkipLen, OldBlockSize - (OldStringAddr - StringPackage->StringBlock) - SkipLen);  \r
+\r
+  if (FontBlock) {\r
+    *BlockType = EFI_HII_SIBT_STRING_UCS2_FONT;\r
+  } else {\r
+    *BlockType = EFI_HII_SIBT_STRING_UCS2;\r
+  }\r
+  FreePool (StringPackage->StringBlock);\r
+  StringPackage->StringBlock = StringBlock;\r
+  StringPackage->StringPkgHdr->Header.Length += NewBlockSize - OldBlockSize;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
 \r
 /**\r
   Parse all string blocks to set a String specified by StringId.\r
@@ -731,8 +892,9 @@ SetStringWorker (
   EFI_HII_SIBT_EXT2_BLOCK              Ext2;\r
   UINTN                                StringSize;\r
   UINTN                                TmpSize;\r
+  EFI_STRING_ID                        StartStringId;\r
 \r
-\r
+  StartStringId = 0;\r
   ASSERT (Private != NULL && StringPackage != NULL && String != NULL);\r
   ASSERT (Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);\r
   //\r
@@ -745,10 +907,25 @@ SetStringWorker (
              &BlockType,\r
              &StringBlockAddr,\r
              &StringTextOffset,\r
-             NULL\r
+             NULL,\r
+             &StartStringId\r
              );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  if (EFI_ERROR (Status) && (BlockType == EFI_HII_SIBT_SKIP1 || BlockType == EFI_HII_SIBT_SKIP2)) {\r
+    Status = InsertLackStringBlock(StringPackage, \r
+                          StartStringId, \r
+                          StringId, \r
+                          &BlockType,\r
+                          &StringBlockAddr,\r
+                          (BOOLEAN)(StringFontInfo != NULL)\r
+                          );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    if (StringFontInfo != NULL) {\r
+      StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);\r
+    } else {\r
+      StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK) - sizeof (CHAR16);\r
+    }\r
   }\r
 \r
   LocalFont  = NULL;\r
@@ -806,7 +983,7 @@ SetStringWorker (
   case EFI_HII_SIBT_STRINGS_SCSU:\r
   case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r
     BlockSize = OldBlockSize + StrLen (String);\r
-    BlockSize -= AsciiStrLen ((CHAR8 *) StringTextPtr);\r
+    BlockSize -= AsciiStrSize ((CHAR8 *) StringTextPtr);\r
     Block = AllocateZeroPool (BlockSize);\r
     if (Block == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
@@ -1048,7 +1225,8 @@ HiiNewString (
                NULL,\r
                NULL,\r
                NULL,\r
-               &NextStringId\r
+               &NextStringId,\r
+               NULL\r
                );\r
     if (EFI_ERROR (Status)) {\r
       goto Done;\r
@@ -1789,25 +1967,8 @@ HiiCompareLanguage (
   IN  CHAR8  *Language2\r
   )\r
 {\r
-  //\r
-  // Porting Guide:\r
-  // This library interface is simply obsolete.\r
-  // Include the source code to user code.\r
-  //\r
-  UINTN Index;\r
+  UINTN Language2Len;\r
 \r
-  for (Index = 0; (Language1[Index] != 0) && (Language2[Index] != 0); Index++) {\r
-    if (Language1[Index] != Language2[Index]) {\r
-      return FALSE;\r
-    }\r
-  }\r
-\r
-  if (((Language1[Index] == 0) && (Language2[Index] == 0))   || \r
-         ((Language1[Index] == 0) && (Language2[Index] != ';')) ||\r
-         ((Language1[Index] == ';') && (Language2[Index] != 0)) ||\r
-         ((Language1[Index] == ';') && (Language2[Index] != ';'))) {\r
-    return TRUE;\r
-  }\r
-\r
-  return FALSE;\r
+  Language2Len = AsciiStrLen (Language2);\r
+  return  (BOOLEAN) (AsciiStrnCmp (Language1, Language2, Language2Len) == 0);\r
 }\r