]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Sample/Tools/Source/UefiVfrCompile/VfrCompiler.cpp
Sync all bug fixes between EDK1.04 and EDK1.06 into EdkCompatibilityPkg.
[mirror_edk2.git] / EdkCompatibilityPkg / Sample / Tools / Source / UefiVfrCompile / VfrCompiler.cpp
index 6adef8a41b2a68f850bcd32289cc7c820245e9cc..2972e1692ab2e755ddfc3a356bddeb663b75741d 100644 (file)
@@ -11,7 +11,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 Module Name:\r
 \r
-VfrCompiler.cpp\r
+  VfrCompiler.cpp\r
 \r
 Abstract:\r
 \r
@@ -41,7 +41,7 @@ CVfrCompiler::IS_RUN_STATUS (
 \r
 VOID\r
 CVfrCompiler::OptionInitialization (\r
-  IN INT32      Argc, \r
+  IN INT32      Argc,\r
   IN INT8       **Argv\r
   )\r
 {\r
@@ -57,6 +57,7 @@ CVfrCompiler::OptionInitialization (
   mOptions.PreprocessorOutputFileName[0] = '\0';\r
   mOptions.VfrBaseFileName[0]            = '\0';\r
   mOptions.IncludePaths                  = NULL;\r
+  mOptions.SkipCPreprocessor             = FALSE;\r
   mOptions.CPreprocessorOptions          = NULL;\r
 \r
   for (Index = 1; (Index < Argc) && (Argv[Index][0] == '-'); Index++) {\r
@@ -70,7 +71,7 @@ CVfrCompiler::OptionInitialization (
     } else if (_stricmp(Argv[Index], "-i") == 0) {\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        printf ("%s -i - missing path argument\n", PROGRAM_NAME);\r
+        printf ("%s -i - missing path argument\n", UTILITY_NAME);\r
         goto Fail;\r
       }\r
 \r
@@ -78,30 +79,33 @@ CVfrCompiler::OptionInitialization (
     } else if (_stricmp(Argv[Index], "-od") == 0) {\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        printf ("%s -od - missing output directory name\n", PROGRAM_NAME);\r
+        printf ("%s -od - missing output directory name\n", UTILITY_NAME);\r
         goto Fail;\r
       }\r
       strcpy (mOptions.OutputDirectory, Argv[Index]);\r
+      strcat (mOptions.OutputDirectory, "\\");\r
     } else if (_stricmp(Argv[Index], "-ibin") == 0) {\r
       mOptions.CreateIfrPkgFile = TRUE;\r
     } else if (_stricmp(Argv[Index], "-nostrings") == 0) {\r
+    } else if (_stricmp(Argv[Index], "-nopp") == 0) {\r
+      mOptions.SkipCPreprocessor = TRUE;\r
     } else if (_stricmp(Argv[Index], "-ppflag") == 0) {\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        printf ("%s -od - missing C-preprocessor argument\n", PROGRAM_NAME);\r
+        printf ("%s -od - missing C-preprocessor argument\n", UTILITY_NAME);\r
         goto Fail;\r
       }\r
 \r
       AppendCPreprocessorOptions (Argv[Index]);\r
     } else {\r
-      printf ("%s unrecognized option %s\n", PROGRAM_NAME, Argv[Index]);\r
+      printf ("%s unrecognized option %s\n", UTILITY_NAME, Argv[Index]);\r
       Usage ();\r
       goto Fail;\r
     }\r
   }\r
 \r
   if (Index != Argc - 1) {\r
-    printf ("%s must specify VFR file name", PROGRAM_NAME);\r
+    printf ("%s must specify VFR file name\n", UTILITY_NAME);\r
     Usage ();\r
     goto Fail;\r
   } else {\r
@@ -140,7 +144,7 @@ Fail:
   if (mOptions.IncludePaths != NULL) {\r
     delete mOptions.IncludePaths;\r
     mOptions.IncludePaths                = NULL;\r
-  } \r
+  }\r
   if (mOptions.CPreprocessorOptions != NULL) {\r
     delete mOptions.CPreprocessorOptions;\r
     mOptions.CPreprocessorOptions        = NULL;\r
@@ -161,7 +165,7 @@ CVfrCompiler::AppendIncludePath (
   }\r
   IncludePaths = new INT8[Len];\r
   if (IncludePaths == NULL) {\r
-    printf ("%s memory allocation failure\n", PROGRAM_NAME);\r
+    printf ("%s memory allocation failure\n", UTILITY_NAME);\r
     return;\r
   }\r
   IncludePaths[0] = '\0';\r
@@ -190,7 +194,7 @@ CVfrCompiler::AppendCPreprocessorOptions (
   }\r
   Opt = new INT8[Len];\r
   if (Opt == NULL) {\r
-    printf ("%s memory allocation failure\n", PROGRAM_NAME);\r
+    printf ("%s memory allocation failure\n", UTILITY_NAME);\r
     return;\r
   }\r
   Opt[0] = 0;\r
@@ -217,7 +221,11 @@ CVfrCompiler::SetBaseFileName (
   }\r
 \r
   pFileName = mOptions.VfrFileName;\r
-  while ((pPath = strchr (pFileName, '\\')) != NULL) {\r
+  while (\r
+    ((pPath = strchr (pFileName, '\\')) != NULL) ||\r
+    ((pPath = strchr (pFileName, '/')) != NULL)\r
+    )\r
+  {\r
     pFileName = pPath + 1;\r
   }\r
 \r
@@ -300,7 +308,7 @@ CVfrCompiler::SetRecordListFileName (
 }\r
 \r
 CVfrCompiler::CVfrCompiler (\r
-  IN INT32      Argc, \r
+  IN INT32      Argc,\r
   IN INT8       **Argv\r
   )\r
 {\r
@@ -333,35 +341,40 @@ CVfrCompiler::~CVfrCompiler (
   SET_RUN_STATUS(STATUS_DEAD);\r
 }\r
 \r
-VOID \r
+VOID\r
 CVfrCompiler::Usage (\r
   VOID\r
   )\r
 {\r
-  UINT32 Index;\r
-  CONST  INT8 *Help[] = {\r
-    " ", \r
-    "VfrCompile version " VFR_COMPILER_VERSION,\r
-    " ",\r
-    "  Usage: VfrCompile {options} [VfrFile]",\r
-    " ",\r
-    "    where options include:",\r
-    "      -? or -h       prints this help",\r
-    "      -l             create an output IFR listing file",\r
-    "      -i IncPath     add IncPath to the search path for VFR included files",\r
-    "      -od OutputDir  deposit all output files to directory OutputDir (default=cwd)",\r
-    "      -ibin          create an IFR HII pack file"\r
-    "      -ppflag        C-preprocessor argument",\r
-    "    where parameters include:",\r
-    "      VfrFile        name of the input VFR script file",\r
-    " ",\r
+  int          Index;\r
+  const char   *Str[] = {\r
+    UTILITY_NAME" "UTILITY_VERSION" - Intel UEFI VFR Compiler Utility",\r
+    "  Copyright (C), 2004 - 2008 Intel Corporation",\r
+#if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )\r
+    "  Built from "UTILITY_BUILD", project of "UTILITY_VENDOR,\r
+#endif\r
+    "",\r
+    "Usage:",\r
+    "  "UTILITY_NAME" [OPTION] VFRFILE",\r
+    "Description:",\r
+    "  Compile VFRFILE.",\r
+    "Options:",\r
+    "  -? or -h        print this help",\r
+    "  -l              create an output IFR listing file",\r
+    "  -i IncPath      add IncPath to the search path for VFR included files",\r
+    "  -od OutputDir   deposit all output files to directory OutputDir (default=cwd)",\r
+    "  -ibin           create an IFR HII pack file",\r
+    "  -ppflag CFlags  pass Flags as C-preprocessor-flag",\r
+    "  -v or -version  print version information",\r
     NULL\r
-    };\r
-  for (Index = 0; Help[Index] != NULL; Index++) {\r
-    fprintf (stdout, "%s\n", Help[Index]);\r
+  };\r
+\r
+  for (Index = 0; Str[Index] != NULL; Index++) {\r
+    fprintf (stdout, "%s\n", Str[Index]);\r
   }\r
 }\r
 \r
+\r
 VOID\r
 CVfrCompiler::PreProcess (\r
   VOID\r
@@ -375,8 +388,12 @@ CVfrCompiler::PreProcess (
     goto Fail;\r
   }\r
 \r
+  if (mOptions.SkipCPreprocessor == TRUE) {\r
+    goto Out;\r
+  }\r
+\r
   if ((pVfrFile = fopen (mOptions.VfrFileName, "r")) == NULL) {\r
-    printf ("%s could not open input VFR file - %s\n", PROGRAM_NAME, mOptions.VfrFileName);\r
+    printf ("%s could not open input VFR file - %s\n", UTILITY_NAME, mOptions.VfrFileName);\r
     goto Fail;\r
   }\r
   fclose (pVfrFile);\r
@@ -392,7 +409,7 @@ CVfrCompiler::PreProcess (
 \r
   PreProcessCmd = new INT8[CmdLen + 10];\r
   if (PreProcessCmd == NULL) {\r
-    printf ("%s could not allocate memory\n", PROGRAM_NAME);\r
+    printf ("%s could not allocate memory\n", UTILITY_NAME);\r
     goto Fail;\r
   }\r
   strcpy (PreProcessCmd, mPreProcessCmd), strcat (PreProcessCmd, " ");\r
@@ -407,11 +424,13 @@ CVfrCompiler::PreProcess (
   strcat (PreProcessCmd, mOptions.PreprocessorOutputFileName);\r
 \r
   if (system (PreProcessCmd) != 0) {\r
-    printf ("%s failed to spawn C preprocessor on VFR file \n\t - %s\n", PROGRAM_NAME, PreProcessCmd);\r
+    printf ("%s failed to spawn C preprocessor on VFR file \n\t - %s\n", UTILITY_NAME, PreProcessCmd);\r
     goto Fail;\r
   }\r
 \r
   delete PreProcessCmd;\r
+\r
+Out:\r
   SET_RUN_STATUS (STATUS_PREPROCESSED);\r
   return;\r
 \r
@@ -429,22 +448,27 @@ CVfrCompiler::Compile (
   VOID\r
   )\r
 {\r
-  FILE *VfrFile = NULL;\r
+  FILE *pInFile    = NULL;\r
+  INT8 *InFileName = NULL;\r
 \r
   if (!IS_RUN_STATUS(STATUS_PREPROCESSED)) {\r
     goto Fail;\r
   }\r
 \r
-  if ((VfrFile = fopen (mOptions.PreprocessorOutputFileName, "r")) == NULL) {\r
-    printf ("%s failed to open input VFR preprocessor output file - %s\n", PROGRAM_NAME, mOptions.PreprocessorOutputFileName);\r
+  InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;\r
+\r
+  gCVfrErrorHandle.SetInputFile (InFileName);\r
+\r
+  if ((pInFile = fopen (InFileName, "r")) == NULL) {\r
+    printf ("%s failed to open input file - %s\n", UTILITY_NAME, InFileName);\r
     goto Fail;\r
   }\r
 \r
-  if (VfrParserStart (VfrFile) != 0) {\r
+  if (VfrParserStart (pInFile) != 0) {\r
     goto Fail;\r
   }\r
 \r
-  fclose (VfrFile);\r
+  fclose (pInFile);\r
 \r
   if (gCFormPkg.HavePendingUnassigned () == TRUE) {\r
     gCFormPkg.PendingAssignPrintAll ();\r
@@ -456,11 +480,11 @@ CVfrCompiler::Compile (
 \r
 Fail:\r
   if (!IS_RUN_STATUS(STATUS_DEAD)) {\r
-    printf ("%s compile error!\n", PROGRAM_NAME);\r
+    printf ("%s compile error!\n", UTILITY_NAME);\r
     SET_RUN_STATUS (STATUS_FAILED);\r
   }\r
-  if (VfrFile != NULL) {\r
-    fclose (VfrFile);\r
+  if (pInFile != NULL) {\r
+    fclose (pInFile);\r
   }\r
 }\r
 \r
@@ -477,7 +501,7 @@ CVfrCompiler::GenBinary (
 \r
   if (mOptions.CreateIfrPkgFile == TRUE) {\r
     if ((pFile = fopen (mOptions.PkgOutputFileName, "wb")) == NULL) {\r
-      printf ("can not open PkgFileName\n", mOptions.PkgOutputFileName);\r
+      printf ("can not open %s\n", mOptions.PkgOutputFileName);\r
       goto Fail;\r
     }\r
     if (gCFormPkg.BuildPkg (pFile) != VFR_RETURN_SUCCESS) {\r
@@ -548,27 +572,30 @@ CVfrCompiler::GenRecordListFile (
   VOID\r
   )\r
 {\r
-  FILE   *pInFile  = NULL;\r
-  FILE   *pOutFile = NULL;\r
+  INT8   *InFileName = NULL;\r
+  FILE   *pInFile    = NULL;\r
+  FILE   *pOutFile   = NULL;\r
   INT8   LineBuf[MAX_LINE_LEN];\r
   UINT32 LineNo;\r
 \r
+  InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;\r
+\r
   if (mOptions.CreateRecordListFile == TRUE) {\r
-    if ((mOptions.PreprocessorOutputFileName[0] == '\0') || (mOptions.RecordListFile[0] == '\0')) {\r
+    if ((InFileName[0] == '\0') || (mOptions.RecordListFile[0] == '\0')) {\r
       return;\r
     }\r
 \r
-    if ((pInFile = fopen (mOptions.PreprocessorOutputFileName, "r")) == NULL) {\r
-      printf ("%s failed to open input VFR preprocessor output file - %s\n", PROGRAM_NAME, mOptions.PreprocessorOutputFileName);\r
+    if ((pInFile = fopen (InFileName, "r")) == NULL) {\r
+      printf ("%s failed to open input VFR preprocessor output file - %s\n", UTILITY_NAME, InFileName);\r
       return;\r
     }\r
 \r
     if ((pOutFile = fopen (mOptions.RecordListFile, "w")) == NULL) {\r
-      printf ("%s failed to open record list file for writing - %s\n", PROGRAM_NAME, mOptions.RecordListFile);\r
+      printf ("%s failed to open record list file for writing - %s\n", UTILITY_NAME, mOptions.RecordListFile);\r
       goto Err1;\r
     }\r
 \r
-    fprintf (pOutFile, "//\n//  VFR compiler version " VFR_COMPILER_VERSION "\n//\n");\r
+    fprintf (pOutFile, "//\n//  VFR compiler version " UTILITY_VERSION "\n//\n");\r
     LineNo = 0;\r
     while (!feof (pInFile)) {\r
       if (fgets (LineBuf, MAX_LINE_LEN, pInFile) != NULL) {\r
@@ -590,7 +617,7 @@ Err1:
 \r
 INT32\r
 main (\r
-  IN INT32             Argc, \r
+  IN INT32             Argc,\r
   IN INT8              **Argv\r
   )\r
 {\r