]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
Sync EDKII BaseTools to BaseTools project r1903.
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrCompiler.cpp
index e3c150cd3dc236f97eea644df8a25f0498f635fa..508b68371eb3ac7b993afcf3b3be3b79814f3f4a 100644 (file)
@@ -2,7 +2,7 @@
   \r
   VfrCompiler main class and main function.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation                                                         \r
+Copyright (c) 2004 - 2010, 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
@@ -24,9 +24,19 @@ PACKAGE_DATA  gCBuffer;
 PACKAGE_DATA  gRBuffer;\r
 \r
 VOID \r
-CVfrCompiler::DebugError () {\r
-  Error (NULL, 0, 0001, "Error parsing vfr file", " %s", mOptions.VfrFileName);\r
-  //_asm int 3;\r
+CVfrCompiler::DebugError (\r
+  IN CHAR8         *FileName,\r
+  IN UINT32        LineNumber,\r
+  IN UINT32        MessageCode,\r
+  IN CONST CHAR8   *Text,\r
+  IN CONST CHAR8   *MsgFmt,\r
+  ...\r
+  ) \r
+{\r
+  va_list List;\r
+  va_start (List, MsgFmt);\r
+  PrintMessage ((CHAR8 *) "ERROR", FileName, LineNumber, MessageCode, (CHAR8 *) Text, (CHAR8 *) MsgFmt, List);\r
+  va_end (List);\r
 }\r
 \r
 VOID\r
@@ -53,7 +63,7 @@ CVfrCompiler::OptionInitialization (
 {\r
   INT32         Index;\r
   \r
-  SetUtilityName (PROGRAM_NAME);\r
+  SetUtilityName ((CHAR8*) PROGRAM_NAME);\r
 \r
   mOptions.VfrFileName[0]                = '\0';\r
   mOptions.RecordListFile[0]             = '\0';\r
@@ -84,11 +94,9 @@ CVfrCompiler::OptionInitialization (
       mOptions.CreateRecordListFile = TRUE;\r
       gCIfrRecordInfoDB.TurnOn ();\r
     } else if (stricmp(Argv[Index], "-i") == 0) {\r
-      Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);\r
-      goto Fail;\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        Error (NULL, 0, 1001, "Missing option", "-i missing path argument"); \r
+        DebugError (NULL, 0, 1001, "Missing option", "-i missing path argument"); \r
         goto Fail;\r
       }\r
 \r
@@ -96,7 +104,7 @@ CVfrCompiler::OptionInitialization (
     } else if (stricmp(Argv[Index], "-o") == 0 || stricmp(Argv[Index], "--output-directory") == 0 || stricmp(Argv[Index], "-od") == 0) {\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        Error (NULL, 0, 1001, "Missing option", "-o missing output directory name");\r
+        DebugError (NULL, 0, 1001, "Missing option", "-o missing output directory name");\r
         goto Fail;\r
       }\r
       strcpy (mOptions.OutputDirectory, Argv[Index]);\r
@@ -109,17 +117,15 @@ CVfrCompiler::OptionInitialization (
           strcat (mOptions.OutputDirectory, "\\");\r
         }\r
       }\r
-      DebugMsg (NULL, 0, 9, "Output Directory", mOptions.OutputDirectory);\r
+      DebugMsg (NULL, 0, 9, (CHAR8 *) "Output Directory", mOptions.OutputDirectory);\r
     } else if (stricmp(Argv[Index], "-b") == 0 || stricmp(Argv[Index], "--create-ifr-package") == 0 || stricmp(Argv[Index], "-ibin") == 0) {\r
       mOptions.CreateIfrPkgFile = TRUE;\r
     } else if (stricmp(Argv[Index], "-n") == 0 || stricmp(Argv[Index], "--no-pre-processing") == 0 || stricmp(Argv[Index], "-nopp") == 0) {\r
       mOptions.SkipCPreprocessor = TRUE;\r
     } else if (stricmp(Argv[Index], "-f") == 0 || stricmp(Argv[Index], "--pre-processing-flag") == 0 || stricmp(Argv[Index], "-ppflag") == 0) {\r
-      Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);\r
-      goto Fail;\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        Error (NULL, 0, 1001, "Missing option", "-od - missing C-preprocessor argument");\r
+        DebugError (NULL, 0, 1001, "Missing option", "-od - missing C-preprocessor argument");\r
         goto Fail;\r
       }\r
 \r
@@ -127,13 +133,13 @@ CVfrCompiler::OptionInitialization (
     } else if (stricmp(Argv[Index], "-c") == 0 || stricmp(Argv[Index], "--compatible-framework") == 0) {\r
       mOptions.CompatibleMode = TRUE;\r
     } else {\r
-      Error (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);\r
+      DebugError (NULL, 0, 1000, "Unknown option", "unrecognized option %s", Argv[Index]);\r
       goto Fail;\r
     }\r
   }\r
 \r
   if (Index != Argc - 1) {\r
-    Error (NULL, 0, 1001, "Missing option", "VFR file name is not specified.");\r
+    DebugError (NULL, 0, 1001, "Missing option", "VFR file name is not specified.");\r
     goto Fail;\r
   } else {\r
     strcpy (mOptions.VfrFileName, Argv[Index]);\r
@@ -192,7 +198,7 @@ CVfrCompiler::AppendIncludePath (
   }\r
   IncludePaths = new CHAR8[Len];\r
   if (IncludePaths == NULL) {\r
-    Error (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
+    DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
     return;\r
   }\r
   IncludePaths[0] = '\0';\r
@@ -221,7 +227,7 @@ CVfrCompiler::AppendCPreprocessorOptions (
   }\r
   Opt = new CHAR8[Len];\r
   if (Opt == NULL) {\r
-    Error (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
+    DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
     return;\r
   }\r
   Opt[0] = 0;\r
@@ -339,8 +345,8 @@ CVfrCompiler::CVfrCompiler (
   IN CHAR8      **Argv\r
   )\r
 {\r
-  mPreProcessCmd = PREPROCESSOR_COMMAND;\r
-  mPreProcessOpt = PREPROCESSOR_OPTIONS;\r
+  mPreProcessCmd = (CHAR8 *) PREPROCESSOR_COMMAND;\r
+  mPreProcessOpt = (CHAR8 *) PREPROCESSOR_OPTIONS;\r
 \r
   OptionInitialization(Argc, Argv);\r
 \r
@@ -377,6 +383,7 @@ CVfrCompiler::Usage (
   CONST  CHAR8 *Help[] = {\r
     " ", \r
     "VfrCompile version " VFR_COMPILER_VERSION VFR_COMPILER_UPDATE_TIME,\r
+    "Copyright (c) 2004-2010 Intel Corporation. All rights reserved.",\r
     " ",\r
     "Usage: VfrCompile [options] VfrFile",\r
     " ",\r
@@ -417,7 +424,7 @@ CVfrCompiler::PreProcess (
   }\r
 \r
   if ((pVfrFile = fopen (mOptions.VfrFileName, "r")) == NULL) {\r
-    Error (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);\r
+    DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);\r
     goto Fail;\r
   }\r
   fclose (pVfrFile);\r
@@ -433,7 +440,7 @@ CVfrCompiler::PreProcess (
 \r
   PreProcessCmd = new CHAR8[CmdLen + 10];\r
   if (PreProcessCmd == NULL) {\r
-    Error (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
+    DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
     goto Fail;\r
   }\r
   strcpy (PreProcessCmd, mPreProcessCmd), strcat (PreProcessCmd, " ");\r
@@ -448,7 +455,7 @@ CVfrCompiler::PreProcess (
   strcat (PreProcessCmd, mOptions.PreprocessorOutputFileName);\r
 \r
   if (system (PreProcessCmd) != 0) {\r
-    Error (NULL, 0, 0003, "Error parsing file", "failed to spawn C preprocessor on VFR file %s\n", PreProcessCmd);\r
+    DebugError (NULL, 0, 0003, "Error parsing file", "failed to spawn C preprocessor on VFR file %s\n", PreProcessCmd);\r
     goto Fail;\r
   }\r
 \r
@@ -484,7 +491,7 @@ CVfrCompiler::Compile (
   gCVfrErrorHandle.SetInputFile (InFileName);\r
 \r
   if ((pInFile = fopen (InFileName, "r")) == NULL) {\r
-    Error (NULL, 0, 0001, "Error opening the input file", InFileName);\r
+    DebugError (NULL, 0, 0001, "Error opening the input file", InFileName);\r
     goto Fail;\r
   }\r
 \r
@@ -504,7 +511,7 @@ CVfrCompiler::Compile (
 \r
 Fail:\r
   if (!IS_RUN_STATUS(STATUS_DEAD)) {\r
-    Error (NULL, 0, 0003, "Error parsing", "compile error in file %s", InFileName);\r
+    DebugError (NULL, 0, 0003, "Error parsing", "compile error in file %s", InFileName);\r
     SET_RUN_STATUS (STATUS_FAILED);\r
   }\r
   if (pInFile != NULL) {\r
@@ -534,7 +541,7 @@ CVfrCompiler::AdjustBin (
   if (gCBuffer.Buffer != NULL && gRBuffer.Buffer != NULL) {\r
     UINT32 Index;\r
     if (gCBuffer.Size != gRBuffer.Size) {\r
-      Error (NULL, 0, 0001, "Error parsing vfr file", " %s. FormBinary Size 0x%X is not same to RecordBuffer Size 0x%X", mOptions.VfrFileName, gCBuffer.Size, gRBuffer.Size);\r
+      DebugError (NULL, 0, 0001, "Error parsing vfr file", " %s. FormBinary Size 0x%X is not same to RecordBuffer Size 0x%X", mOptions.VfrFileName, gCBuffer.Size, gRBuffer.Size);\r
     }\r
     for (Index = 0; Index < gCBuffer.Size; Index ++) {\r
       if (gCBuffer.Buffer[Index] != gRBuffer.Buffer[Index]) {\r
@@ -542,13 +549,13 @@ CVfrCompiler::AdjustBin (
       }\r
     }\r
     if (Index != gCBuffer.Size) {\r
-      Error (NULL, 0, 0001, "Error parsing vfr file", " %s. the 0x%X byte is different between Form and Record", mOptions.VfrFileName, Index);\r
+      DebugError (NULL, 0, 0001, "Error parsing vfr file", " %s. the 0x%X byte is different between Form and Record", mOptions.VfrFileName, Index);\r
     }\r
-    DebugMsg (NULL, 0, 9, "IFR Buffer", "Form Buffer same to Record Buffer and Size is 0x%X", Index);\r
+    DebugMsg (NULL, 0, 9, (CHAR8 *) "IFR Buffer", (CHAR8 *) "Form Buffer same to Record Buffer and Size is 0x%X", Index);\r
   } else if (gCBuffer.Buffer == NULL && gRBuffer.Buffer == NULL) {\r
     //ok\r
   } else {\r
-    Error (NULL, 0, 0001, "Error parsing vfr file", " %s.Buffer not allocated.", mOptions.VfrFileName);\r
+    DebugError (NULL, 0, 0001, "Error parsing vfr file", " %s.Buffer not allocated.", mOptions.VfrFileName);\r
   }\r
 \r
   //\r
@@ -588,7 +595,7 @@ CVfrCompiler::GenBinary (
 \r
   if (mOptions.CreateIfrPkgFile == TRUE) {\r
     if ((pFile = fopen (mOptions.PkgOutputFileName, "wb")) == NULL) {\r
-      Error (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);\r
       goto Fail;\r
     }\r
     if (gCFormPkg.BuildPkg (pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {\r
@@ -631,7 +638,7 @@ CVfrCompiler::GenCFile (
   \r
   if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) {\r
     if ((pFile = fopen (mOptions.COutputFileName, "w")) == NULL) {\r
-      Error (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);\r
       goto Fail;\r
     }\r
 \r
@@ -678,12 +685,12 @@ CVfrCompiler::GenRecordListFile (
     }\r
 \r
     if ((pInFile = fopen (InFileName, "r")) == NULL) {\r
-      Error (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName);\r
       return;\r
     }\r
 \r
     if ((pOutFile = fopen (mOptions.RecordListFile, "w")) == NULL) {\r
-      Error (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);\r
+      DebugError (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);\r
       goto Err1;\r
     }\r
 \r
@@ -713,8 +720,8 @@ Err1:
 \r
 int\r
 main (\r
-  IN INT32             Argc, \r
-  IN CHAR8             **Argv\r
+  IN int             Argc, \r
+  IN char            **Argv\r
   )\r
 {\r
   COMPILER_RUN_STATUS  Status;\r
@@ -743,3 +750,4 @@ main (
   return GetUtilityStatus ();\r
 }\r
 \r
+\r