]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/CCode/Source/StrGather/StrGather.c
Modified version and usage display.
[mirror_edk2.git] / Tools / CCode / Source / StrGather / StrGather.c
index 8908b430a156c0ae1a68ced5c4452669a5b3fb88..b9d4a493aff5e37a2f57e5b1cf961356741a4c95 100644 (file)
@@ -1,6 +1,6 @@
 /*++\r
 \r
-Copyright (c) 2004, Intel Corporation                                                         \r
+Copyright (c) 2004-2007, Intel Corporation                                                         \r
 All rights reserved. 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
@@ -31,8 +31,6 @@ Abstract:
 #include "StrGather.h"\r
 #include "StringDB.h"\r
 \r
-#define TOOL_VERSION  "0.31"\r
-\r
 #ifndef MAX_PATH\r
 #define MAX_PATH                    255\r
 #endif\r
@@ -237,6 +235,12 @@ wstrcmp (
   WCHAR *Str\r
   );\r
 \r
+static\r
+void\r
+Version (\r
+  VOID\r
+  );\r
+\r
 static\r
 void\r
 Usage (\r
@@ -321,7 +325,7 @@ Returns:
 {\r
   STATUS  Status;\r
 \r
-  SetUtilityName (PROGRAM_NAME);\r
+  SetUtilityName (UTILITY_NAME);\r
   //\r
   // Process the command-line arguments\r
   //\r
@@ -1470,7 +1474,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
@@ -1519,6 +1523,17 @@ ProcessArgs (
     Usage ();\r
     return STATUS_ERROR;\r
   }\r
+  \r
+  if ((strcmp(Argv[0], "-h") == 0) || (strcmp(Argv[0], "--help") == 0) ||\r
+      (strcmp(Argv[0], "-?") == 0) || (strcmp(Argv[0], "/?") == 0)) {\r
+    Usage();\r
+    return STATUS_ERROR;\r
+  }\r
+  \r
+  if ((strcmp(Argv[0], "-V") == 0) || (strcmp(Argv[0], "--version") == 0)) {\r
+    Version();\r
+    return STATUS_ERROR;\r
+  }\r
 \r
   mGlobals.Mode = MODE_UNKNOWN;\r
   //\r
@@ -1570,7 +1585,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
@@ -1580,7 +1595,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
@@ -1588,7 +1603,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
@@ -1613,7 +1628,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
@@ -1623,7 +1638,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
@@ -1631,7 +1646,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
@@ -1654,13 +1669,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
@@ -1668,7 +1683,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
@@ -1691,14 +1706,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
@@ -1709,14 +1724,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
@@ -1740,7 +1755,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
@@ -1752,7 +1767,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
@@ -1765,7 +1780,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
@@ -1777,7 +1792,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
@@ -1787,7 +1802,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
@@ -1795,7 +1810,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
@@ -1822,7 +1837,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
@@ -1838,7 +1853,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
@@ -1849,7 +1864,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
@@ -1896,7 +1911,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
@@ -1906,14 +1921,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 = (CHAR8 *) 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
@@ -1933,7 +1948,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
@@ -1966,7 +1981,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
@@ -1974,7 +1989,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
@@ -1997,7 +2012,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
@@ -2470,6 +2485,31 @@ SkipTo (
   return FALSE;\r
 }\r
 \r
+static\r
+void\r
+Version (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Displays the standard utility information to SDTOUT\r
+\r
+Arguments:\r
+\r
+  None\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  printf ("%s v%d.%d -Utility to process unicode strings file..\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r
+  printf ("Copyright (c) 1999-2007 Intel Corporation. All rights reserved.\n");\r
+}\r
+\r
 static\r
 void\r
 Usage (\r
@@ -2494,12 +2534,12 @@ Returns:
   int               Index;\r
   static const char *Str[] = {\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
+    "  Usage: "UTILITY_NAME " -parse {parse options} [FileNames]",\r
+    "         "UTILITY_NAME " -scan {scan options} [FileName]",\r
+    "         "UTILITY_NAME " -dump {dump options}",\r
     "    Common options include:",\r
-    "      -h or -?         for this help information",\r
+    "      -h,--help,-?,/?  display help messages",\r
+    "      -V,--version     display version 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
@@ -2535,6 +2575,9 @@ Returns:
     "",\r
     NULL\r
   };\r
+  \r
+  Version();\r
+  \r
   for (Index = 0; Str[Index] != NULL; Index++) {\r
     fprintf (stdout, "%s\n", Str[Index]);\r
   }\r