]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Sample/Tools/Source/StrGather/StrGather.c
Sync all bug fixes between EDK1.04 and EDK1.06 into EdkCompatibilityPkg.
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / StrGather / StrGather.c
index f830400b24fe98253f0d1ea567063eca959ef1f9..2d6d35bb885fc96e3bc080c8634dbd65ecc57e20 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2010, 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
@@ -29,7 +29,8 @@ Abstract:
 #include "StrGather.h"\r
 #include "StringDB.h"\r
 \r
-#define TOOL_VERSION  "0.31"\r
+#define UTILITY_NAME     "StrGather"\r
+#define UTILITY_VERSION  "v1.0"\r
 \r
 typedef UINT16  WCHAR;\r
 \r
@@ -281,11 +282,6 @@ ParseIndirectionFiles (
   TEXT_STRING_LIST    *Files\r
   );\r
 \r
-STATUS\r
-StringDBCreateHiiExportPack (\r
-  INT8                *OutputFileName\r
-  );\r
-\r
 int\r
 main (\r
   int   Argc,\r
@@ -311,7 +307,7 @@ Returns:
 {\r
   STATUS  Status;\r
 \r
-  SetUtilityName (PROGRAM_NAME);\r
+  SetUtilityName (UTILITY_NAME);\r
   //\r
   // Process the command-line arguments\r
   //\r
@@ -405,7 +401,7 @@ Returns:
   // Dump the string data as HII binary string pack if requested\r
   //\r
   if ((mGlobals.HiiExportPackFileName[0] != 0) && (GetUtilityStatus () < STATUS_ERROR)) {\r
-    StringDBCreateHiiExportPack (mGlobals.HiiExportPackFileName);\r
+    StringDBCreateHiiExportPack (mGlobals.HiiExportPackFileName, mGlobals.Language);\r
   }\r
   //\r
   // Always update the database if no errors and not in dump mode. If they specified -od\r
@@ -1481,7 +1477,7 @@ FindFile (
     // Put the path and filename together\r
     //\r
     if (strlen (List->Str) + strlen (FileName) + 1 > FoundFileNameLen) {\r
-      Error (PROGRAM_NAME, 0, 0, NULL, "internal error - cannot concatenate path+filename");\r
+      Error (UTILITY_NAME, 0, 0, NULL, "internal error - cannot concatenate path+filename");\r
       return NULL;\r
     }\r
     //\r
@@ -1581,7 +1577,7 @@ ProcessArgs (
       // check for one more arg\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing include path");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing include path");\r
         return STATUS_ERROR;\r
       }\r
       //\r
@@ -1591,7 +1587,7 @@ ProcessArgs (
       //\r
       NewList = malloc (sizeof (TEXT_STRING_LIST));\r
       if (NewList == NULL) {\r
-        Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+        Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1599,7 +1595,7 @@ ProcessArgs (
       NewList->Str = malloc (strlen (Argv[1]) + 2);\r
       if (NewList->Str == NULL) {\r
         free (NewList);\r
-        Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+        Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1624,7 +1620,7 @@ ProcessArgs (
       // Indirection file -- check for one more arg\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing indirection file name");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing indirection file name");\r
         return STATUS_ERROR;\r
       }\r
       //\r
@@ -1634,7 +1630,7 @@ ProcessArgs (
       //\r
       NewList = malloc (sizeof (TEXT_STRING_LIST));\r
       if (NewList == NULL) {\r
-        Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+        Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1642,7 +1638,7 @@ ProcessArgs (
       NewList->Str = malloc (strlen (Argv[1]) + 1);\r
       if (NewList->Str == NULL) {\r
         free (NewList);\r
-        Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+        Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1665,13 +1661,13 @@ ProcessArgs (
       // Check for one more arg (the database file name)\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing database file name");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing database file name");\r
         return STATUS_ERROR;\r
       }\r
 \r
       NewList = malloc (sizeof (TEXT_STRING_LIST));\r
       if (NewList == NULL) {\r
-        Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+        Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1679,7 +1675,7 @@ ProcessArgs (
       NewList->Str = malloc (strlen (Argv[1]) + 1);\r
       if (NewList->Str == NULL) {\r
         free (NewList);\r
-        Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+        Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1702,14 +1698,14 @@ ProcessArgs (
       // which we can dump our database.\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing database dump output file name");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing database dump output file name");\r
         return STATUS_ERROR;\r
       }\r
 \r
       if (mGlobals.DumpUFileName[0] == 0) {\r
         strcpy (mGlobals.DumpUFileName, Argv[1]);\r
       } else {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[1], "-ou option already specified with '%s'", mGlobals.DumpUFileName);\r
+        Error (UTILITY_NAME, 0, 0, Argv[1], "-ou option already specified with '%s'", mGlobals.DumpUFileName);\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1720,14 +1716,14 @@ ProcessArgs (
       // -hpk option to create an HII export pack of the input database file\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing raw string data dump output file name");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing raw string data dump output file name");\r
         return STATUS_ERROR;\r
       }\r
 \r
       if (mGlobals.HiiExportPackFileName[0] == 0) {\r
         strcpy (mGlobals.HiiExportPackFileName, Argv[1]);\r
       } else {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[1], "-or option already specified with '%s'", mGlobals.HiiExportPackFileName);\r
+        Error (UTILITY_NAME, 0, 0, Argv[1], "-or option already specified with '%s'", mGlobals.HiiExportPackFileName);\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1751,7 +1747,7 @@ ProcessArgs (
       // check for one more arg\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing output C filename");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing output C filename");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1763,7 +1759,7 @@ ProcessArgs (
       // check for one more arg\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing base name");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing base name");\r
         Usage ();\r
         return STATUS_ERROR;\r
       }\r
@@ -1776,7 +1772,7 @@ ProcessArgs (
       // -oh to specify output .h defines file name\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing output .h filename");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing output .h filename");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1788,7 +1784,7 @@ ProcessArgs (
       // -dep to specify output dependency file name\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing output dependency filename");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing output dependency filename");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1800,7 +1796,7 @@ ProcessArgs (
       // -skipext to skip scanning of files with certain filename extensions\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing filename extension");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing filename extension");\r
         return STATUS_ERROR;\r
       }\r
       //\r
@@ -1810,7 +1806,7 @@ ProcessArgs (
       //\r
       NewList = malloc (sizeof (TEXT_STRING_LIST));\r
       if (NewList == NULL) {\r
-        Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+        Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1818,7 +1814,7 @@ ProcessArgs (
       NewList->Str = malloc (strlen (Argv[1]) + 2);\r
       if (NewList->Str == NULL) {\r
         free (NewList);\r
-        Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+        Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1845,7 +1841,7 @@ ProcessArgs (
       // "-lang eng" or "-lang spa+cat" to only output certain languages\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing language name");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing language name");\r
         Usage ();\r
         return STATUS_ERROR;\r
       }\r
@@ -1861,7 +1857,7 @@ ProcessArgs (
       // Output database file name -- check for another arg\r
       //\r
       if ((Argc <= 1) || (Argv[1][0] == '-')) {\r
-        Error (PROGRAM_NAME, 0, 0, Argv[0], "missing output database file name");\r
+        Error (UTILITY_NAME, 0, 0, Argv[0], "missing output database file name");\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1872,7 +1868,7 @@ ProcessArgs (
       //\r
       // Unrecognized arg\r
       //\r
-      Error (PROGRAM_NAME, 0, 0, Argv[0], "unrecognized option");\r
+      Error (UTILITY_NAME, 0, 0, Argv[0], "unrecognized option");\r
       Usage ();\r
       return STATUS_ERROR;\r
     }\r
@@ -1919,7 +1915,7 @@ ProcessArgs (
   //\r
   if (mGlobals.Mode == MODE_SCAN) {\r
     if (Argc < 1) {\r
-      Error (PROGRAM_NAME, 0, 0, NULL, "must specify at least one source file to scan with -scan");\r
+      Error (UTILITY_NAME, 0, 0, NULL, "must specify at least one source file to scan with -scan");\r
       Usage ();\r
       return STATUS_ERROR;\r
     }\r
@@ -1929,14 +1925,14 @@ ProcessArgs (
     while (Argc > 0) {\r
       NewList = malloc (sizeof (TEXT_STRING_LIST));\r
       if (NewList == NULL) {\r
-        Error (PROGRAM_NAME, 0, 0, "memory allocation failure", NULL);\r
+        Error (UTILITY_NAME, 0, 0, "memory allocation failure", NULL);\r
         return STATUS_ERROR;\r
       }\r
 \r
       memset (NewList, 0, sizeof (TEXT_STRING_LIST));\r
       NewList->Str = (UINT8 *) malloc (strlen (Argv[0]) + 1);\r
       if (NewList->Str == NULL) {\r
-        Error (PROGRAM_NAME, 0, 0, "memory allocation failure", NULL);\r
+        Error (UTILITY_NAME, 0, 0, "memory allocation failure", NULL);\r
         return STATUS_ERROR;\r
       }\r
 \r
@@ -1956,7 +1952,7 @@ ProcessArgs (
     // Parse mode -- must specify an input unicode file name\r
     //\r
     if (Argc < 1) {\r
-      Error (PROGRAM_NAME, 0, 0, NULL, "must specify input unicode string file name with -parse");\r
+      Error (UTILITY_NAME, 0, 0, NULL, "must specify input unicode string file name with -parse");\r
       Usage ();\r
       return STATUS_ERROR;\r
     }\r
@@ -1989,7 +1985,7 @@ AddCommandLineLanguage (
     //\r
     WNewList = MALLOC (sizeof (WCHAR_STRING_LIST));\r
     if (WNewList == NULL) {\r
-      Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+      Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
       return STATUS_ERROR;\r
     }\r
 \r
@@ -1997,7 +1993,7 @@ AddCommandLineLanguage (
     WNewList->Str = malloc ((strlen (Language) + 1) * sizeof (WCHAR));\r
     if (WNewList->Str == NULL) {\r
       free (WNewList);\r
-      Error (PROGRAM_NAME, 0, 0, NULL, "memory allocation failure");\r
+      Error (UTILITY_NAME, 0, 0, NULL, "memory allocation failure");\r
       return STATUS_ERROR;\r
     }\r
     //\r
@@ -2024,7 +2020,7 @@ AddCommandLineLanguage (
               (From[LANGUAGE_IDENTIFIER_NAME_LEN] != L',')\r
             )\r
           ) {\r
-        Error (PROGRAM_NAME, 0, 0, Language, "invalid format for language name on command line");\r
+        Error (UTILITY_NAME, 0, 0, Language, "invalid format for language name on command line");\r
         FREE (WNewList->Str);\r
         FREE (WNewList);\r
         return STATUS_ERROR;\r
@@ -2523,48 +2519,56 @@ Returns:
   \r
 --*/\r
 {\r
-  int               Index;\r
-  static const char *Str[] = {\r
+  int         Index;\r
+  const char  *Str[] = {\r
+    UTILITY_NAME" "UTILITY_VERSION" - Intel String Gather Utility",\r
+    "  Copyright (C), 2004 - 2008 Intel Corporation",\r
+    \r
+#if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )\r
+    "  Built from "UTILITY_BUILD", project of "UTILITY_VENDOR,\r
+#endif\r
     "",\r
-    PROGRAM_NAME " version "TOOL_VERSION " -- process unicode strings file",\r
-    "  Usage: "PROGRAM_NAME " -parse {parse options} [FileNames]",\r
-    "         "PROGRAM_NAME " -scan {scan options} [FileName]",\r
-    "         "PROGRAM_NAME " -dump {dump options}",\r
-    "    Common options include:",\r
-    "      -h or -?         for this help information",\r
-    "      -db Database     required name of output/input database file",\r
-    "      -bn BaseName     for use in the .h and .c output files",\r
-    "                       Default = "DEFAULT_BASE_NAME,\r
-    "      -v               for verbose output",\r
-    "      -vdbw            for verbose output when writing database",\r
-    "      -vdbr            for verbose output when reading database",\r
-    "      -od FileName     to specify an output database file name",\r
-    "    Parse options include:",\r
-    "      -i IncludePath   add IncludePath to list of search paths",\r
-    "      -dep FileName    to specify an output dependency file name",\r
-    "      -newdb           to not read in existing database file",\r
-    "      -uqs             to indicate that unquoted strings are used",\r
-    "      FileNames        name of one or more unicode files to parse",\r
-    "    Scan options include:",\r
-    "      -scan            scan text file(s) for STRING_TOKEN() usage",\r
-    "      -skipext .ext    to skip scan of files with .ext filename extension",\r
-    "      -ignorenotfound  ignore if a given STRING_TOKEN(STR) is not ",\r
-    "                       found in the database",\r
-    "      FileNames        one or more files to scan",\r
-    "    Dump options include:",\r
-    "      -oc FileName     write string data to FileName",\r
-    "      -oh FileName     write string defines to FileName",\r
-    "      -ou FileName     dump database to unicode file FileName",\r
-    "      -lang Lang       only dump for the language 'Lang'",\r
-    "      -if FileName     to specify an indirection file",\r
-    "      -hpk FileName    to create an HII export pack of the strings",\r
+    "Usage:",\r
+    "  "UTILITY_NAME" -parse [OPTION] FILE",\r
+    "  "UTILITY_NAME" -scan  [OPTION] FILE",\r
+    "  "UTILITY_NAME" -dump  [OPTION]",\r
+    "Description:",\r
+    "  Process unicode strings file.",\r
+    "Common options include:",\r
+    "  -h or -?         for this help information",\r
+    "  -db Database     required name of output/input database file",\r
+    "  -bn BaseName     for use in the .h and .c output files",\r
+    "                   Default = "DEFAULT_BASE_NAME,\r
+    "  -v               for verbose output",\r
+    "  -vdbw            for verbose output when writing database",\r
+    "  -vdbr            for verbose output when reading database",\r
+    "  -od FileName     to specify an output database file name",\r
+    "Parse options include:",\r
+    "  -i IncludePath   add IncludePath to list of search paths",\r
+    "  -dep FileName    to specify an output dependency file name",\r
+    "  -newdb           to not read in existing database file",\r
+    "  -uqs             to indicate that unquoted strings are used",\r
+    "  FileNames        name of one or more unicode files to parse",\r
+    "Scan options include:",\r
+    "  -scan            scan text file(s) for STRING_TOKEN() usage",\r
+    "  -skipext .ext    to skip scan of files with .ext filename extension",\r
+    "  -ignorenotfound  ignore if a given STRING_TOKEN(STR) is not ",\r
+    "                   found in the database",\r
+    "  FileNames        one or more files to scan",\r
+    "Dump options include:",\r
+    "  -oc FileName     write string data to FileName",\r
+    "  -oh FileName     write string defines to FileName",\r
+    "  -ou FileName     dump database to unicode file FileName",\r
+    "  -lang Lang       only dump for the language 'Lang'",\r
+    "  -if FileName     to specify an indirection file",\r
+    "  -hpk FileName    to create an HII export pack of the strings",\r
     "",\r
-    "  The expected process is to parse a unicode string file to create an initial",\r
-    "  database of string identifier names and string definitions. Then text files",\r
-    "  should be scanned for STRING_TOKEN() usages, and the referenced",\r
-    "  strings will be tagged as used in the database. After all files have been",\r
-    "  scanned, then the database should be dumped to create the necessary output",\r
-    "  files.",\r
+    "The expected process is to parse a unicode string file to create an initial",\r
+    "database of string identifier names and string definitions. Then text files",\r
+    "should be scanned for STRING_TOKEN() usages, and the referenced",\r
+    "strings will be tagged as used in the database. After all files have been",\r
+    "scanned, then the database should be dumped to create the necessary output",\r
+    "files.",\r
     "",\r
     NULL\r
   };\r