]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/TianoTools/StrGather/StringDB.c
Add Mde String and PrintLibs. Port StrGather to the Mde Unicode implementation. Compi...
[mirror_edk2.git] / Tools / Source / TianoTools / StrGather / StringDB.c
index f452bbc86bf0d9a4ad9054f6775f6c0e81b7f7b8..353fabb68226f42b0158ff6c140f19bf2cb4d5e4 100644 (file)
@@ -26,6 +26,7 @@ Abstract:
 #include <Base.h>\r
 #include <UefiBaseTypes.h>\r
 #include <MultiPhase.h>\r
 #include <Base.h>\r
 #include <UefiBaseTypes.h>\r
 #include <MultiPhase.h>\r
+#include <BaseLib.h>\r
 #include "EfiUtilityMsgs.h"\r
 #include "StrGather.h"\r
 #include "StringDB.h"\r
 #include "EfiUtilityMsgs.h"\r
 #include "StrGather.h"\r
 #include "StringDB.h"\r
@@ -399,6 +400,7 @@ StringDBDumpCStrings (
   WCHAR                       *TempStringPtr;\r
   WCHAR                       *LangName;\r
   STRING_IDENTIFIER           *StringIdentifier;\r
   WCHAR                       *TempStringPtr;\r
   WCHAR                       *LangName;\r
   STRING_IDENTIFIER           *StringIdentifier;\r
+  WCHAR                       Line[200];\r
 \r
   if ((Fptr = fopen (FileName, "w")) == NULL) {\r
     Error (NULL, 0, 0, FileName, "failed to open output C string file");\r
 \r
   if ((Fptr = fopen (FileName, "w")) == NULL) {\r
     Error (NULL, 0, 0, FileName, "failed to open output C string file");\r
@@ -434,7 +436,7 @@ StringDBDumpCStrings (
     if (LanguagesOfInterest != NULL) {\r
       LanguageOk = FALSE;\r
       for (LOIPtr = LanguagesOfInterest; LOIPtr != NULL; LOIPtr = LOIPtr->Next) {\r
     if (LanguagesOfInterest != NULL) {\r
       LanguageOk = FALSE;\r
       for (LOIPtr = LanguagesOfInterest; LOIPtr != NULL; LOIPtr = LOIPtr->Next) {\r
-        if (wcsncmp (LOIPtr->Str, Lang->LanguageName, LANGUAGE_IDENTIFIER_NAME_LEN) == 0) {\r
+        if (StrnCmp (LOIPtr->Str, Lang->LanguageName, LANGUAGE_IDENTIFIER_NAME_LEN) == 0) {\r
           LangName    = LOIPtr->Str;\r
           LanguageOk  = TRUE;\r
           break;\r
           LangName    = LOIPtr->Str;\r
           LanguageOk  = TRUE;\r
           break;\r
@@ -460,13 +462,13 @@ StringDBDumpCStrings (
     //   Offset[]  -- an array of offsets to strings, of type RELOFST each\r
     //   String[]  -- the actual strings themselves\r
     //\r
     //   Offset[]  -- an array of offsets to strings, of type RELOFST each\r
     //   String[]  -- the actual strings themselves\r
     //\r
-    fprintf (\r
-      Fptr,\r
+    AsciiSPrint ( Line, sizeof(Line),\r
       "\n//******************************************************************************"\r
       "\n//******************************************************************************"\r
-      "\n// Start of string definitions for %S/%S",\r
+      "\n// Start of string definitions for %s/%s",\r
       Lang->LanguageName,\r
       Lang->PrintableLanguageName\r
       );\r
       Lang->LanguageName,\r
       Lang->PrintableLanguageName\r
       );\r
+    fprintf (Fptr, "%s", Line);\r
     memset ((char *) &StringPack, 0, sizeof (EFI_HII_STRING_PACK));\r
     StringPack.Header.Type        = EFI_HII_STRING;\r
     StringPack.NumStringPointers  = (UINT16) mDBData.NumStringIdentifiersReferenced;\r
     memset ((char *) &StringPack, 0, sizeof (EFI_HII_STRING_PACK));\r
     StringPack.Header.Type        = EFI_HII_STRING;\r
     StringPack.NumStringPointers  = (UINT16) mDBData.NumStringIdentifiersReferenced;\r
@@ -479,7 +481,7 @@ StringDBDumpCStrings (
     // entry for the printable language name as well.\r
     //\r
     StringPack.LanguageNameString = (STRING_OFFSET) (sizeof (EFI_HII_STRING_PACK) + (mDBData.NumStringIdentifiersReferenced * sizeof (STRING_OFFSET)));\r
     // entry for the printable language name as well.\r
     //\r
     StringPack.LanguageNameString = (STRING_OFFSET) (sizeof (EFI_HII_STRING_PACK) + (mDBData.NumStringIdentifiersReferenced * sizeof (STRING_OFFSET)));\r
-    StringPack.PrintableLanguageName = (STRING_OFFSET) (StringPack.LanguageNameString + (wcslen (LangName) + 1) * sizeof (WCHAR));\r
+    StringPack.PrintableLanguageName = (STRING_OFFSET) (StringPack.LanguageNameString + (StrLen (LangName) + 1) * sizeof (WCHAR));\r
     //\r
     // Add up the size of all strings so we can fill in our header.\r
     //\r
     //\r
     // Add up the size of all strings so we can fill in our header.\r
     //\r
@@ -490,7 +492,7 @@ StringDBDumpCStrings (
       // requested it. We set LangName to point to the proper language name string above.\r
       //\r
       if (StringIndex == STRING_ID_LANGUAGE_NAME) {\r
       // requested it. We set LangName to point to the proper language name string above.\r
       //\r
       if (StringIndex == STRING_ID_LANGUAGE_NAME) {\r
-        Len += (wcslen (LangName) + 1) * sizeof (WCHAR);\r
+        Len += (StrLen (LangName) + 1) * sizeof (WCHAR);\r
       } else {\r
         //\r
         // Find a string with this language.stringname\r
       } else {\r
         //\r
         // Find a string with this language.stringname\r
@@ -578,13 +580,14 @@ StringDBDumpCStrings (
         return STATUS_ERROR;\r
       }\r
 \r
         return STATUS_ERROR;\r
       }\r
 \r
-      fprintf (Fptr, " // offset to string %S (0x%04X)", StringIdentifier->StringName, StringIndex);\r
+      AsciiSPrint (Line, sizeof(Line) , " // offset to string %s (0x%04X)", StringIdentifier->StringName, StringIndex);\r
+      fprintf (Fptr, "%s", Line);\r
       //\r
       // For the first string (language name), we print out the "spacat" if they\r
       // requested it. We set LangName to point to the proper language name string above.\r
       //\r
       if (StringIndex == STRING_ID_LANGUAGE_NAME) {\r
       //\r
       // For the first string (language name), we print out the "spacat" if they\r
       // requested it. We set LangName to point to the proper language name string above.\r
       //\r
       if (StringIndex == STRING_ID_LANGUAGE_NAME) {\r
-        Offset += (wcslen (LangName) + 1) * sizeof (WCHAR);\r
+        Offset += (StrLen (LangName) + 1) * sizeof (WCHAR);\r
         CurrString = StringDBFindString (\r
                       Lang->LanguageName,\r
                       StringIdentifier->StringName,\r
         CurrString = StringDBFindString (\r
                       Lang->LanguageName,\r
                       StringIdentifier->StringName,\r
@@ -634,12 +637,13 @@ StringDBDumpCStrings (
 \r
       if (CurrString->Flags & STRING_FLAGS_UNDEFINED) {\r
         fprintf (Fptr, " - not defined for this language");\r
 \r
       if (CurrString->Flags & STRING_FLAGS_UNDEFINED) {\r
         fprintf (Fptr, " - not defined for this language");\r
-      } else if (wcscmp (CurrString->LanguageName, Lang->LanguageName) != 0) {\r
-        fprintf (\r
-          Fptr,\r
-          " - not defined for this language -- using secondary language %S definition",\r
+      } else if (StrCmp (CurrString->LanguageName, Lang->LanguageName) != 0) {\r
+        AsciiSPrint (\r
+          Line, sizeof(Line),\r
+          " - not defined for this language -- using secondary language %s definition",\r
           CurrString->LanguageName\r
           );\r
           CurrString->LanguageName\r
           );\r
+        fprintf ( Fptr, "%s", Line);\r
       }\r
 \r
       fprintf (Fptr, "\n");\r
       }\r
 \r
       fprintf (Fptr, "\n");\r
@@ -650,7 +654,8 @@ StringDBDumpCStrings (
     while (StringIndex < mDBData.NumStringIdentifiers) {\r
       StringIdentifier = StringDBFindStringIdentifierByIndex (StringIndex);\r
       if (StringIdentifier != NULL) {\r
     while (StringIndex < mDBData.NumStringIdentifiers) {\r
       StringIdentifier = StringDBFindStringIdentifierByIndex (StringIndex);\r
       if (StringIdentifier != NULL) {\r
-        fprintf (Fptr, "  // %S not referenced\n", StringIdentifier->StringName);\r
+        AsciiSPrint (Line, sizeof(Line), "  // %s not referenced\n", StringIdentifier->StringName);\r
+        fprintf (Fptr, "%s", Line);\r
       }\r
 \r
       StringIndex++;\r
       }\r
 \r
       StringIndex++;\r
@@ -669,7 +674,8 @@ StringDBDumpCStrings (
         return STATUS_ERROR;\r
       }\r
 \r
         return STATUS_ERROR;\r
       }\r
 \r
-      fprintf (Fptr, "  // string %S offset 0x%08X\n  ", StringIdentifier->StringName, Offset);\r
+      AsciiSPrint (Line, sizeof(Line), "  // string %s offset 0x%08X\n  ", StringIdentifier->StringName, Offset);\r
+      fprintf (Fptr, "%s", Line);\r
       //\r
       // For the first string (language name), we print out the "spacat" if they\r
       // requested it. We set LangName to point to the proper language name string above.\r
       //\r
       // For the first string (language name), we print out the "spacat" if they\r
       // requested it. We set LangName to point to the proper language name string above.\r
@@ -795,6 +801,7 @@ StringDBDumpStringDefines (
   FILE              *Fptr;\r
   STRING_IDENTIFIER *Identifier;\r
   INT8              CopyBaseName[100];\r
   FILE              *Fptr;\r
   STRING_IDENTIFIER *Identifier;\r
   INT8              CopyBaseName[100];\r
+  WCHAR             Line[200];\r
   UINT32            Index;\r
   const INT8        *StrDefHeader[] = {\r
     "#ifndef _%s_STRINGS_DEFINE_H_\n",\r
   UINT32            Index;\r
   const INT8        *StrDefHeader[] = {\r
     "#ifndef _%s_STRINGS_DEFINE_H_\n",\r
@@ -844,9 +851,11 @@ StringDBDumpStringDefines (
     }\r
 \r
     if (Identifier->Flags & STRING_FLAGS_REFERENCED) {\r
     }\r
 \r
     if (Identifier->Flags & STRING_FLAGS_REFERENCED) {\r
-      fprintf (Fptr, "#define %-40S 0x%04X\n", Identifier->StringName, Identifier->Index);\r
+      AsciiSPrint (Line, sizeof(Line), "#define %-40s 0x%04X\n", Identifier->StringName, Identifier->Index);\r
+      fprintf (Fptr, "%s", Line);\r
     } else {\r
     } else {\r
-      fprintf (Fptr, "//#define %-40S 0x%04X // not referenced\n", Identifier->StringName, Identifier->Index);\r
+      AsciiSPrint (Line, sizeof(Line), "//#define %-40s 0x%04X // not referenced\n", Identifier->StringName, Identifier->Index);\r
+      fprintf (Fptr, "%s", Line);\r
     }\r
 \r
     Identifier = Identifier->Next;\r
     }\r
 \r
     Identifier = Identifier->Next;\r
@@ -909,13 +918,13 @@ StringDBAddStringIdentifier (
   }\r
 \r
   memset ((char *) StringIdentifier, 0, sizeof (STRING_IDENTIFIER));\r
   }\r
 \r
   memset ((char *) StringIdentifier, 0, sizeof (STRING_IDENTIFIER));\r
-  StringIdentifier->StringName = (WCHAR *) malloc ((wcslen (StringName) + 1) * sizeof (WCHAR));\r
+  StringIdentifier->StringName = (WCHAR *) malloc ((StrLen (StringName) + 1) * sizeof (WCHAR));\r
   if (StringIdentifier->StringName == NULL) {\r
     Error (NULL, 0, 0, NULL, "memory allocation error");\r
     return STATUS_ERROR;\r
   }\r
 \r
   if (StringIdentifier->StringName == NULL) {\r
     Error (NULL, 0, 0, NULL, "memory allocation error");\r
     return STATUS_ERROR;\r
   }\r
 \r
-  wcscpy (StringIdentifier->StringName, StringName);\r
+  StrCpy (StringIdentifier->StringName, StringName);\r
   if (*NewId != STRING_ID_INVALID) {\r
     StringIdentifier->Index = *NewId;\r
     StringIdentifier->Flags |= STRING_FLAGS_INDEX_ASSIGNED;\r
   if (*NewId != STRING_ID_INVALID) {\r
     StringIdentifier->Index = *NewId;\r
     StringIdentifier->Flags |= STRING_FLAGS_INDEX_ASSIGNED;\r
@@ -991,7 +1000,7 @@ StringDBAddString (
   // Truncate at 3 if it's longer, or make it 3 if it's shorter.\r
   //\r
   if (LanguageName != NULL) {\r
   // Truncate at 3 if it's longer, or make it 3 if it's shorter.\r
   //\r
   if (LanguageName != NULL) {\r
-    Size = wcslen (LanguageName);\r
+    Size = StrLen (LanguageName);\r
     if (Size != 3) {\r
       ParserError (0, "invalid length for language name", "%S", LanguageName);\r
       if (Size > 3) {\r
     if (Size != 3) {\r
       ParserError (0, "invalid length for language name", "%S", LanguageName);\r
       if (Size > 3) {\r
@@ -1002,7 +1011,7 @@ StringDBAddString (
         // 3 characters since we make assumptions elsewhere in this program\r
         // on the length.\r
         //\r
         // 3 characters since we make assumptions elsewhere in this program\r
         // on the length.\r
         //\r
-        wcscpy (TempLangName, LanguageName);\r
+        StrCpy (TempLangName, LanguageName);\r
         for (; Size < 3; Size++) {\r
           TempLangName[Size] = L'?';\r
         }\r
         for (; Size < 3; Size++) {\r
           TempLangName[Size] = L'?';\r
         }\r
@@ -1061,8 +1070,8 @@ StringDBAddString (
   // user does not specifically define them.\r
   //\r
   if (StringDBFindString (Lang->LanguageName, StringName, Scope, NULL, NULL) != NULL) {\r
   // user does not specifically define them.\r
   //\r
   if (StringDBFindString (Lang->LanguageName, StringName, Scope, NULL, NULL) != NULL) {\r
-    if ((wcscmp (StringName, LANGUAGE_NAME_STRING_NAME) == 0) &&\r
-        (wcscmp (StringName, PRINTABLE_LANGUAGE_NAME_STRING_NAME) == 0)\r
+    if ((StrCmp (StringName, LANGUAGE_NAME_STRING_NAME) == 0) &&\r
+        (StrCmp (StringName, PRINTABLE_LANGUAGE_NAME_STRING_NAME) == 0)\r
         ) {\r
       ParserError (\r
         0,\r
         ) {\r
       ParserError (\r
         0,\r
@@ -1092,7 +1101,7 @@ StringDBAddString (
   }\r
 \r
   memset ((char *) Str, 0, sizeof (STRING_LIST));\r
   }\r
 \r
   memset ((char *) Str, 0, sizeof (STRING_LIST));\r
-  Size              = (wcslen (String) + 1) * sizeof (WCHAR);\r
+  Size              = (StrLen (String) + 1) * sizeof (WCHAR);\r
   Str->Flags        = Flags;\r
   Str->Scope        = Scope;\r
   Str->StringName   = StringIdentifier->StringName;\r
   Str->Flags        = Flags;\r
   Str->Scope        = Scope;\r
   Str->StringName   = StringIdentifier->StringName;\r
@@ -1105,7 +1114,7 @@ StringDBAddString (
   //\r
   // If not formatting, just copy the string.\r
   //\r
   //\r
   // If not formatting, just copy the string.\r
   //\r
-  wcscpy (Str->Str, String);\r
+  StrCpy (Str->Str, String);\r
   if (Format) {\r
     StringDBFormatString (Str->Str);\r
   }\r
   if (Format) {\r
     StringDBFormatString (Str->Str);\r
   }\r
@@ -1114,7 +1123,7 @@ StringDBAddString (
   // the actual size of the string, including the null for\r
   // easier processing later.\r
   //\r
   // the actual size of the string, including the null for\r
   // easier processing later.\r
   //\r
-  Str->Size = (wcslen (Str->Str) + 1) * sizeof (WCHAR);\r
+  Str->Size = (StrLen (Str->Str) + 1) * sizeof (WCHAR);\r
   if (Lang->String == NULL) {\r
     Lang->String = Str;\r
   } else {\r
   if (Lang->String == NULL) {\r
     Lang->String = Str;\r
   } else {\r
@@ -1152,7 +1161,7 @@ StringDBFindLanguageList (
 \r
   Lang = mDBData.LanguageList;\r
   while (Lang != NULL) {\r
 \r
   Lang = mDBData.LanguageList;\r
   while (Lang != NULL) {\r
-    if (wcscmp (LanguageName, Lang->LanguageName) == 0) {\r
+    if (StrCmp (LanguageName, Lang->LanguageName) == 0) {\r
       break;\r
     }\r
 \r
       break;\r
     }\r
 \r
@@ -1196,7 +1205,7 @@ StringDBAddLanguage (
     //\r
     // Better be the same printable name\r
     //\r
     //\r
     // Better be the same printable name\r
     //\r
-    if (wcscmp (PrintableLanguageName, Lang->PrintableLanguageName) != 0) {\r
+    if (StrCmp (PrintableLanguageName, Lang->PrintableLanguageName) != 0) {\r
       ParserError (\r
         0,\r
         "language redefinition",\r
       ParserError (\r
         0,\r
         "language redefinition",\r
@@ -1228,14 +1237,14 @@ StringDBAddLanguage (
     // Save the language name, then allocate memory to save the\r
     // printable language name\r
     //\r
     // Save the language name, then allocate memory to save the\r
     // printable language name\r
     //\r
-    wcscpy (Lang->LanguageName, LanguageName);\r
-    Lang->PrintableLanguageName = (WCHAR *) malloc ((wcslen (PrintableLanguageName) + 1) * sizeof (WCHAR));\r
+    StrCpy (Lang->LanguageName, LanguageName);\r
+    Lang->PrintableLanguageName = (WCHAR *) malloc ((StrLen (PrintableLanguageName) + 1) * sizeof (WCHAR));\r
     if (Lang->PrintableLanguageName == NULL) {\r
       Error (NULL, 0, 0, NULL, "memory allocation error");\r
       return STATUS_ERROR;\r
     }\r
 \r
     if (Lang->PrintableLanguageName == NULL) {\r
       Error (NULL, 0, 0, NULL, "memory allocation error");\r
       return STATUS_ERROR;\r
     }\r
 \r
-    wcscpy (Lang->PrintableLanguageName, PrintableLanguageName);\r
+    StrCpy (Lang->PrintableLanguageName, PrintableLanguageName);\r
 \r
     if (mDBData.LanguageList == NULL) {\r
       mDBData.LanguageList = Lang;\r
 \r
     if (mDBData.LanguageList == NULL) {\r
       mDBData.LanguageList = Lang;\r
@@ -1284,7 +1293,7 @@ StringDBFindStringIdentifierByName (
 \r
   Identifier = mDBData.StringIdentifier;\r
   while (Identifier != NULL) {\r
 \r
   Identifier = mDBData.StringIdentifier;\r
   while (Identifier != NULL) {\r
-    if (wcscmp (StringName, Identifier->StringName) == 0) {\r
+    if (StrCmp (StringName, Identifier->StringName) == 0) {\r
       return Identifier;\r
     }\r
 \r
       return Identifier;\r
     }\r
 \r
@@ -1366,22 +1375,22 @@ StringDBFormatString (
       // when you have "define STR L"ABC"", then sizeof(ABC) is 8 because the null char is\r
       // counted. Make adjustments for this. We advance From below, so subtract 2 each time.\r
       //\r
       // when you have "define STR L"ABC"", then sizeof(ABC) is 8 because the null char is\r
       // counted. Make adjustments for this. We advance From below, so subtract 2 each time.\r
       //\r
-      if (wcsncmp (From, UNICODE_WIDE_STRING, sizeof (UNICODE_WIDE_STRING) / sizeof (WCHAR) - 1) == 0) {\r
+      if (StrnCmp (From, UNICODE_WIDE_STRING, sizeof (UNICODE_WIDE_STRING) / sizeof (WCHAR) - 1) == 0) {\r
         *To = WIDE_CHAR;\r
         From += sizeof (UNICODE_WIDE_STRING) / sizeof (WCHAR) - 2;\r
         *To = WIDE_CHAR;\r
         From += sizeof (UNICODE_WIDE_STRING) / sizeof (WCHAR) - 2;\r
-      } else if (wcsncmp (From, UNICODE_NARROW_STRING, sizeof (UNICODE_NARROW_STRING) / sizeof (WCHAR) - 1) == 0) {\r
+      } else if (StrnCmp (From, UNICODE_NARROW_STRING, sizeof (UNICODE_NARROW_STRING) / sizeof (WCHAR) - 1) == 0) {\r
         //\r
         // Found: \narrow\r
         //\r
         *To = NARROW_CHAR;\r
         From += sizeof (UNICODE_NARROW_STRING) / sizeof (WCHAR) - 2;\r
         //\r
         // Found: \narrow\r
         //\r
         *To = NARROW_CHAR;\r
         From += sizeof (UNICODE_NARROW_STRING) / sizeof (WCHAR) - 2;\r
-      } else if (wcsncmp (From, UNICODE_NBR_STRING, sizeof (UNICODE_NBR_STRING) / sizeof (WCHAR) - 1) == 0) {\r
+      } else if (StrnCmp (From, UNICODE_NBR_STRING, sizeof (UNICODE_NBR_STRING) / sizeof (WCHAR) - 1) == 0) {\r
         //\r
         // Found: \nbr\r
         //\r
         *To = NON_BREAKING_CHAR;\r
         From += sizeof (UNICODE_NBR_STRING) / sizeof (WCHAR) - 2;\r
         //\r
         // Found: \nbr\r
         //\r
         *To = NON_BREAKING_CHAR;\r
         From += sizeof (UNICODE_NBR_STRING) / sizeof (WCHAR) - 2;\r
-      } else if (wcsncmp (From, UNICODE_BR_STRING, sizeof (UNICODE_BR_STRING) / sizeof (WCHAR) - 1) == 0) {\r
+      } else if (StrnCmp (From, UNICODE_BR_STRING, sizeof (UNICODE_BR_STRING) / sizeof (WCHAR) - 1) == 0) {\r
         //\r
         // Found: \br -- pass through untouched\r
         //\r
         //\r
         // Found: \br -- pass through untouched\r
         //\r
@@ -1594,7 +1603,7 @@ StringDBWriteDatabase (
 {\r
   STRING_DB_HEADER  DbHeader;\r
   UINT32            Counter;\r
 {\r
   STRING_DB_HEADER  DbHeader;\r
   UINT32            Counter;\r
-  UINT32            StrLen;\r
+  UINT32            StrLength;\r
   LANGUAGE_LIST     *Lang;\r
   STRING_IDENTIFIER *StringIdentifier;\r
   STRING_LIST       *StrList;\r
   LANGUAGE_LIST     *Lang;\r
   STRING_IDENTIFIER *StringIdentifier;\r
   STRING_LIST       *StrList;\r
@@ -1629,8 +1638,8 @@ StringDBWriteDatabase (
   DbHeader.NumStringIdenfiers = mDBData.NumStringIdentifiers;\r
   StringIdentifier            = mDBData.StringIdentifier;\r
   for (Counter = 0; Counter < mDBData.NumStringIdentifiers; Counter++) {\r
   DbHeader.NumStringIdenfiers = mDBData.NumStringIdentifiers;\r
   StringIdentifier            = mDBData.StringIdentifier;\r
   for (Counter = 0; Counter < mDBData.NumStringIdentifiers; Counter++) {\r
-    StrLen = wcslen (StringIdentifier->StringName) + 1;\r
-    DbHeader.StringIdentifiersSize += StrLen * sizeof (WCHAR) + sizeof (StringIdentifier->Flags);\r
+    StrLength = StrLen (StringIdentifier->StringName) + 1;\r
+    DbHeader.StringIdentifiersSize += StrLength * sizeof (WCHAR) + sizeof (StringIdentifier->Flags);\r
     StringIdentifier = StringIdentifier->Next;\r
   }\r
 \r
     StringIdentifier = StringIdentifier->Next;\r
   }\r
 \r
@@ -1688,7 +1697,7 @@ StringDBSetStringReferenced (
   //\r
   Status  = STATUS_SUCCESS;\r
   WName   = (WCHAR *) malloc ((strlen (StringIdentifierName) + 1) * sizeof (WCHAR));\r
   //\r
   Status  = STATUS_SUCCESS;\r
   WName   = (WCHAR *) malloc ((strlen (StringIdentifierName) + 1) * sizeof (WCHAR));\r
-  swprintf (WName, L"%S", StringIdentifierName);\r
+  UnicodeSPrint (WName, (strlen (StringIdentifierName) + 1) * sizeof (WCHAR), L"%a", StringIdentifierName);\r
   Id = StringDBFindStringIdentifierByName (WName);\r
   if (Id != NULL) {\r
     Id->Flags |= STRING_FLAGS_REFERENCED;\r
   Id = StringDBFindStringIdentifierByName (WName);\r
   if (Id != NULL) {\r
     Id->Flags |= STRING_FLAGS_REFERENCED;\r
@@ -1765,8 +1774,8 @@ StringDBDumpDatabase (
   // The default control character is '/'. Make it '#' by writing\r
   // "/=#" to the output file.\r
   //\r
   // The default control character is '/'. Make it '#' by writing\r
   // "/=#" to the output file.\r
   //\r
-  swprintf (Line, L"/=#");\r
-  fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr);\r
+  UnicodeSPrint (Line, sizeof(Line), L"/=#");\r
+  fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr);\r
   fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
   fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
   //\r
   fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
   fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
   //\r
@@ -1778,24 +1787,24 @@ StringDBDumpDatabase (
     // Write the "#define " string\r
     //\r
     if (StringIdentifier->Flags & STRING_FLAGS_REFERENCED) {\r
     // Write the "#define " string\r
     //\r
     if (StringIdentifier->Flags & STRING_FLAGS_REFERENCED) {\r
-      swprintf (\r
+      UnicodeSPrint (\r
         Line,\r
         Line,\r
-        L"%s %-60.60s 0x%04X",\r
+        sizeof(Line), L"%s %-60.60s 0x%04X",\r
         DEFINE_STR,\r
         StringIdentifier->StringName,\r
         StringIdentifier->Index\r
         );\r
     } else {\r
         DEFINE_STR,\r
         StringIdentifier->StringName,\r
         StringIdentifier->Index\r
         );\r
     } else {\r
-      swprintf (\r
+      UnicodeSPrint (\r
         Line,\r
         Line,\r
-        L"%s %-60.60s 0x%04X  // NOT REFERENCED",\r
+        sizeof(Line), L"%s %-60.60s 0x%04X  // NOT REFERENCED",\r
         DEFINE_STR,\r
         StringIdentifier->StringName,\r
         StringIdentifier->Index\r
         );\r
     }\r
 \r
         DEFINE_STR,\r
         StringIdentifier->StringName,\r
         StringIdentifier->Index\r
         );\r
     }\r
 \r
-    fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr);\r
+    fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr);\r
     fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
   }\r
 \r
     fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
   }\r
 \r
@@ -1807,8 +1816,8 @@ StringDBDumpDatabase (
   Scope = NULL;\r
   for (Lang = mDBData.LanguageList; Lang != NULL; Lang = Lang->Next) {\r
     fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
   Scope = NULL;\r
   for (Lang = mDBData.LanguageList; Lang != NULL; Lang = Lang->Next) {\r
     fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
-    swprintf (Line, L"#langdef %s \"%s\"", Lang->LanguageName, Lang->PrintableLanguageName);\r
-    fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr);\r
+    UnicodeSPrint (Line, sizeof(Line), L"#langdef %s \"%s\"", Lang->LanguageName, Lang->PrintableLanguageName);\r
+    fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr);\r
     fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
     fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
     //\r
     fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
     fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
     //\r
@@ -1819,29 +1828,29 @@ StringDBDumpDatabase (
       //\r
       // Print the internal flags for debug\r
       //\r
       //\r
       // Print the internal flags for debug\r
       //\r
-      swprintf (Line, L"// flags=0x%02X", (UINT32) StrList->Flags);\r
-      fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr);\r
+      UnicodeSPrint (Line, sizeof(Line), L"// flags=0x%02X", (UINT32) StrList->Flags);\r
+      fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr);\r
       fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
       //\r
       // Print the scope if changed\r
       //\r
       fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
       //\r
       // Print the scope if changed\r
       //\r
-      if ((Scope == NULL) || (wcscmp (Scope, StrList->Scope) != 0)) {\r
-        swprintf (Line, L"#scope %s", StrList->Scope);\r
-        fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr);\r
+      if ((Scope == NULL) || (StrCmp (Scope, StrList->Scope) != 0)) {\r
+        UnicodeSPrint (Line, sizeof(Line), L"#scope %s", StrList->Scope);\r
+        fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr);\r
         fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
         Scope = StrList->Scope;\r
       }\r
 \r
         fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
         Scope = StrList->Scope;\r
       }\r
 \r
-      swprintf (\r
+      UnicodeSPrint (\r
         Line,\r
         Line,\r
-        L"#string %-50.50s #language %s \"",\r
+        sizeof(Line), L"#string %-50.50s #language %s \"",\r
         StrList->StringName,\r
         Lang->LanguageName\r
         );\r
         StrList->StringName,\r
         Lang->LanguageName\r
         );\r
-      fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr);\r
+      fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr);\r
       fwrite (StrList->Str, StrList->Size - sizeof (WCHAR), 1, OutFptr);\r
       fwrite (StrList->Str, StrList->Size - sizeof (WCHAR), 1, OutFptr);\r
-      swprintf (Line, L"\"");\r
-      fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr);\r
+      UnicodeSPrint (Line, sizeof(Line), L"\"");\r
+      fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr);\r
       fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
     }\r
   }\r
       fwrite (&CrLf, sizeof (CrLf), 1, OutFptr);\r
     }\r
   }\r
@@ -2175,7 +2184,7 @@ StringDBWriteGenericString (
     Flags         = STRING_FLAGS_UNDEFINED;\r
   } else {\r
     Flags = 0;\r
     Flags         = STRING_FLAGS_UNDEFINED;\r
   } else {\r
     Flags = 0;\r
-    Size  = (UINT16) ((wcslen (Str) + 1) * sizeof (WCHAR));\r
+    Size  = (UINT16) ((StrLen (Str) + 1) * sizeof (WCHAR));\r
   }\r
 \r
   if (fwrite (&Size, sizeof (UINT16), 1, DBFptr) != 1) {\r
   }\r
 \r
   if (fwrite (&Size, sizeof (UINT16), 1, DBFptr) != 1) {\r
@@ -2220,7 +2229,7 @@ StringDBFindString (
   //\r
   if (IndirectionList != NULL) {\r
     for (IndListPtr = IndirectionList; IndListPtr != NULL; IndListPtr = IndListPtr->Next) {\r
   //\r
   if (IndirectionList != NULL) {\r
     for (IndListPtr = IndirectionList; IndListPtr != NULL; IndListPtr = IndListPtr->Next) {\r
-      if (wcscmp (StringName, IndListPtr->Str1) == 0) {\r
+      if (StrCmp (StringName, IndListPtr->Str1) == 0) {\r
         CurrString = StringDBFindString (LanguageName, StringName, IndListPtr->Str2, LanguagesOfInterest, NULL);\r
         if (CurrString != NULL) {\r
           return CurrString;\r
         CurrString = StringDBFindString (LanguageName, StringName, IndListPtr->Str2, LanguagesOfInterest, NULL);\r
         if (CurrString != NULL) {\r
           return CurrString;\r
@@ -2232,18 +2241,18 @@ StringDBFindString (
   // First look for exact match language.stringname\r
   //\r
   for (Lang = mDBData.LanguageList; Lang != NULL; Lang = Lang->Next) {\r
   // First look for exact match language.stringname\r
   //\r
   for (Lang = mDBData.LanguageList; Lang != NULL; Lang = Lang->Next) {\r
-    if (wcscmp (LanguageName, Lang->LanguageName) == 0) {\r
+    if (StrCmp (LanguageName, Lang->LanguageName) == 0) {\r
       //\r
       // Found language match. Try to find string name match\r
       //\r
       for (CurrString = Lang->String; CurrString != NULL; CurrString = CurrString->Next) {\r
       //\r
       // Found language match. Try to find string name match\r
       //\r
       for (CurrString = Lang->String; CurrString != NULL; CurrString = CurrString->Next) {\r
-        if (wcscmp (StringName, CurrString->StringName) == 0) {\r
+        if (StrCmp (StringName, CurrString->StringName) == 0) {\r
           //\r
           // Found a string name match. See if we're supposed to find\r
           // a scope match.\r
           //\r
           if (Scope != NULL) {\r
           //\r
           // Found a string name match. See if we're supposed to find\r
           // a scope match.\r
           //\r
           if (Scope != NULL) {\r
-            if (wcscmp (CurrString->Scope, Scope) == 0) {\r
+            if (StrCmp (CurrString->Scope, Scope) == 0) {\r
               return CurrString;\r
             }\r
           } else {\r
               return CurrString;\r
             }\r
           } else {\r
@@ -2263,19 +2272,19 @@ StringDBFindString (
     // If this is the language we're looking for, then process the\r
     // languages of interest list for it.\r
     //\r
     // If this is the language we're looking for, then process the\r
     // languages of interest list for it.\r
     //\r
-    if (wcsncmp (LanguageName, LanguagesOfInterest->Str, LANGUAGE_IDENTIFIER_NAME_LEN) == 0) {\r
+    if (StrnCmp (LanguageName, LanguagesOfInterest->Str, LANGUAGE_IDENTIFIER_NAME_LEN) == 0) {\r
       WCharPtr = LanguagesOfInterest->Str + LANGUAGE_IDENTIFIER_NAME_LEN;\r
       while (*WCharPtr) {\r
         //\r
         // Double-check the length, though it should have been checked on the\r
         // command line.\r
         //\r
       WCharPtr = LanguagesOfInterest->Str + LANGUAGE_IDENTIFIER_NAME_LEN;\r
       while (*WCharPtr) {\r
         //\r
         // Double-check the length, though it should have been checked on the\r
         // command line.\r
         //\r
-        if (wcslen (WCharPtr) < LANGUAGE_IDENTIFIER_NAME_LEN) {\r
+        if (StrLen (WCharPtr) < LANGUAGE_IDENTIFIER_NAME_LEN) {\r
           Error (NULL, 0, 0, "malformed alternate language list", "%S", LanguagesOfInterest->Str);\r
           return NULL;\r
         }\r
 \r
           Error (NULL, 0, 0, "malformed alternate language list", "%S", LanguagesOfInterest->Str);\r
           return NULL;\r
         }\r
 \r
-        wcsncpy (TempLangName, WCharPtr, LANGUAGE_IDENTIFIER_NAME_LEN);\r
+        StrnCpy (TempLangName, WCharPtr, LANGUAGE_IDENTIFIER_NAME_LEN);\r
         TempLangName[LANGUAGE_IDENTIFIER_NAME_LEN]  = 0;\r
         CurrString = StringDBFindString (TempLangName, StringName, NULL, NULL, IndirectionList);\r
         if (CurrString != NULL) {\r
         TempLangName[LANGUAGE_IDENTIFIER_NAME_LEN]  = 0;\r
         CurrString = StringDBFindString (TempLangName, StringName, NULL, NULL, IndirectionList);\r
         if (CurrString != NULL) {\r
@@ -2401,13 +2410,13 @@ DuplicateString (
     return NULL;\r
   }\r
 \r
     return NULL;\r
   }\r
 \r
-  NewStr = MALLOC ((wcslen (Str) + 1) * sizeof (WCHAR));\r
+  NewStr = MALLOC ((StrLen (Str) + 1) * sizeof (WCHAR));\r
   if (NewStr == NULL) {\r
     Error (NULL, 0, 0, "memory allocation failure", NULL);\r
     return NULL;\r
   }\r
 \r
   if (NewStr == NULL) {\r
     Error (NULL, 0, 0, "memory allocation failure", NULL);\r
     return NULL;\r
   }\r
 \r
-  wcscpy (NewStr, Str);\r
+  StrCpy (NewStr, Str);\r
   return NewStr;\r
 }\r
 \r
   return NewStr;\r
 }\r
 \r
@@ -2515,7 +2524,7 @@ StringDBCreateHiiExportPack (
     // entry for the printable language name as well.\r
     //\r
     StringPack.LanguageNameString = (STRING_OFFSET) (sizeof (EFI_HII_STRING_PACK) + (mDBData.NumStringIdentifiersReferenced * sizeof (STRING_OFFSET)));\r
     // entry for the printable language name as well.\r
     //\r
     StringPack.LanguageNameString = (STRING_OFFSET) (sizeof (EFI_HII_STRING_PACK) + (mDBData.NumStringIdentifiersReferenced * sizeof (STRING_OFFSET)));\r
-    StringPack.PrintableLanguageName = (STRING_OFFSET) (StringPack.LanguageNameString + (wcslen (LangName) + 1) * sizeof (WCHAR));\r
+    StringPack.PrintableLanguageName = (STRING_OFFSET) (StringPack.LanguageNameString + (StrLen (LangName) + 1) * sizeof (WCHAR));\r
     //\r
     // Add up the size of all strings so we can fill in our header.\r
     //\r
     //\r
     // Add up the size of all strings so we can fill in our header.\r
     //\r
@@ -2526,7 +2535,7 @@ StringDBCreateHiiExportPack (
       // requested it. We set LangName to point to the proper language name string above.\r
       //\r
       if (StringIndex == STRING_ID_LANGUAGE_NAME) {\r
       // requested it. We set LangName to point to the proper language name string above.\r
       //\r
       if (StringIndex == STRING_ID_LANGUAGE_NAME) {\r
-        Len += (wcslen (LangName) + 1) * sizeof (WCHAR);\r
+        Len += (StrLen (LangName) + 1) * sizeof (WCHAR);\r
       } else {\r
         //\r
         // Find a string with this language.stringname\r
       } else {\r
         //\r
         // Find a string with this language.stringname\r
@@ -2611,7 +2620,7 @@ StringDBCreateHiiExportPack (
       // requested it. We set LangName to point to the proper language name string above.\r
       //\r
       if (StringIndex == STRING_ID_LANGUAGE_NAME) {\r
       // requested it. We set LangName to point to the proper language name string above.\r
       //\r
       if (StringIndex == STRING_ID_LANGUAGE_NAME) {\r
-        Offset += (wcslen (LangName) + 1) * sizeof (WCHAR);\r
+        Offset += (StrLen (LangName) + 1) * sizeof (WCHAR);\r
         CurrString = StringDBFindString (\r
                       Lang->LanguageName,\r
                       StringIdentifier->StringName,\r
         CurrString = StringDBFindString (\r
                       Lang->LanguageName,\r
                       StringIdentifier->StringName,\r