]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VfrCompile/VfrCompiler.cpp
BaseTools: Enable structure pcd in FDF file
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrCompiler.cpp
index 16453439ec0b148bec6368b0dd408361037c7431..0e9c2df48d93b1ef09b8fa7caaf2ba3bb7e65350 100644 (file)
@@ -1,15 +1,15 @@
 /** @file\r
-  \r
+\r
   VfrCompiler main class and main function.\r
 \r
-Copyright (c) 2004 - 2016, 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
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+Copyright (c) 2004 - 2018, 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
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 \r
@@ -24,7 +24,7 @@ PACKAGE_DATA  gCBuffer;
 PACKAGE_DATA  gRBuffer;\r
 CVfrStringDB  gCVfrStringDB;\r
 \r
-VOID \r
+VOID\r
 CVfrCompiler::DebugError (\r
   IN CHAR8         *FileName,\r
   IN UINT32        LineNumber,\r
@@ -32,7 +32,7 @@ CVfrCompiler::DebugError (
   IN CONST CHAR8   *Text,\r
   IN CONST CHAR8   *MsgFmt,\r
   ...\r
-  ) \r
+  )\r
 {\r
   va_list List;\r
   va_start (List, MsgFmt);\r
@@ -58,7 +58,7 @@ CVfrCompiler::IS_RUN_STATUS (
 \r
 VOID\r
 CVfrCompiler::OptionInitialization (\r
-  IN INT32      Argc, \r
+  IN INT32      Argc,\r
   IN CHAR8      **Argv\r
   )\r
 {\r
@@ -86,7 +86,7 @@ CVfrCompiler::OptionInitialization (
   mOptions.AutoDefault                   = FALSE;\r
   mOptions.CheckDefault                  = FALSE;\r
   memset (&mOptions.OverrideClassGuid, 0, sizeof (EFI_GUID));\r
-  \r
+\r
   if (Argc == 1) {\r
     Usage ();\r
     SET_RUN_STATUS (STATUS_DEAD);\r
@@ -108,7 +108,7 @@ CVfrCompiler::OptionInitialization (
     } else if (stricmp(Argv[Index], "-i") == 0) {\r
       Index++;\r
       if ((Index >= Argc) || (Argv[Index][0] == '-')) {\r
-        DebugError (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
@@ -119,10 +119,6 @@ CVfrCompiler::OptionInitialization (
         DebugError (NULL, 0, 1001, "Missing option", "-o missing output directory name");\r
         goto Fail;\r
       }\r
-      if (strlen (Argv[Index]) > MAX_PATH - 1) {\r
-        DebugError (NULL, 0, 1003, "Invalid option value", "Output directory name %s is too long", Argv[Index]);\r
-        goto Fail;\r
-      }\r
 \r
       mOptions.OutputDirectory = (CHAR8 *) malloc (strlen (Argv[Index]) + strlen ("\\") + 1);\r
       if (mOptions.OutputDirectory == NULL) {\r
@@ -130,7 +126,7 @@ CVfrCompiler::OptionInitialization (
         goto Fail;\r
       }\r
       strcpy (mOptions.OutputDirectory, Argv[Index]);\r
-      \r
+\r
       CHAR8 lastChar = mOptions.OutputDirectory[strlen(mOptions.OutputDirectory) - 1];\r
       if ((lastChar != '/') && (lastChar != '\\')) {\r
         if (strchr(mOptions.OutputDirectory, '/') != NULL) {\r
@@ -139,7 +135,7 @@ CVfrCompiler::OptionInitialization (
           strcat (mOptions.OutputDirectory, "\\");\r
         }\r
       }\r
-      DebugMsg (NULL, 0, 9, (CHAR8 *) "Output Directory", mOptions.OutputDirectory);\r
+      DebugMsg (NULL, 0, 9, (CHAR8 *) "Output Directory", (CHAR8 *) "%s", 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
@@ -161,7 +157,7 @@ CVfrCompiler::OptionInitialization (
         goto Fail;\r
       }\r
       gCVfrStringDB.SetStringFileName(Argv[Index]);\r
-      DebugMsg (NULL, 0, 9, (CHAR8 *) "Input string file path", Argv[Index]);\r
+      DebugMsg (NULL, 0, 9, (CHAR8 *) "Input string file path", (CHAR8 *) "%s", Argv[Index]);\r
     } else if ((stricmp (Argv[Index], "-g") == 0) || (stricmp (Argv[Index], "--guid") == 0)) {\r
       Index++;\r
       Status = StringToGuid (Argv[Index], &mOptions.OverrideClassGuid);\r
@@ -186,10 +182,6 @@ CVfrCompiler::OptionInitialization (
     DebugError (NULL, 0, 1001, "Missing option", "VFR file name is not specified.");\r
     goto Fail;\r
   } else {\r
-    if (strlen (Argv[Index]) > MAX_PATH) {\r
-      DebugError (NULL, 0, 1003, "Invalid option value", "VFR file name %s is too long.", Argv[Index]);\r
-      goto Fail;\r
-    }\r
     mOptions.VfrFileName = (CHAR8 *) malloc (strlen (Argv[Index]) + 1);\r
     if (mOptions.VfrFileName == NULL) {\r
       DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL);\r
@@ -261,7 +253,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
@@ -292,7 +284,7 @@ CVfrCompiler::AppendIncludePath (
   strcat (IncludePaths, " -I ");\r
   strcat (IncludePaths, PathStr);\r
   if (mOptions.IncludePaths != NULL) {\r
-    delete mOptions.IncludePaths;\r
+    delete[] mOptions.IncludePaths;\r
   }\r
   mOptions.IncludePaths = IncludePaths;\r
 }\r
@@ -321,7 +313,7 @@ CVfrCompiler::AppendCPreprocessorOptions (
   strcat (Opt, " ");\r
   strcat (Opt, Options);\r
   if (mOptions.CPreprocessorOptions != NULL) {\r
-    delete mOptions.CPreprocessorOptions;\r
+    delete[] mOptions.CPreprocessorOptions;\r
   }\r
   mOptions.CPreprocessorOptions = Opt;\r
 }\r
@@ -355,10 +347,6 @@ CVfrCompiler::SetBaseFileName (
   }\r
 \r
   *pExt = '\0';\r
-  if (strlen (pFileName) > MAX_PATH - 1) {\r
-    *pExt = '.';\r
-    return -1;\r
-  }\r
 \r
   mOptions.VfrBaseFileName = (CHAR8 *) malloc (strlen (pFileName) + 1);\r
   if (mOptions.VfrBaseFileName == NULL) {\r
@@ -387,9 +375,6 @@ CVfrCompiler::SetPkgOutputFileName (
            strlen (mOptions.VfrBaseFileName) +\r
            strlen (VFR_PACKAGE_FILENAME_EXTENSION) +\r
            1;\r
-  if (Length > MAX_PATH) {\r
-    return -1;\r
-  }\r
 \r
   mOptions.PkgOutputFileName = (CHAR8 *) malloc (Length);\r
   if (mOptions.PkgOutputFileName == NULL) {\r
@@ -418,9 +403,6 @@ CVfrCompiler::SetCOutputFileName (
            strlen (mOptions.VfrBaseFileName) +\r
            strlen (".c") +\r
            1;\r
-  if (Length > MAX_PATH) {\r
-    return -1;\r
-  }\r
 \r
   mOptions.COutputFileName = (CHAR8 *) malloc (Length);\r
   if (mOptions.COutputFileName == NULL) {\r
@@ -449,9 +431,6 @@ CVfrCompiler::SetPreprocessorOutputFileName (
            strlen (mOptions.VfrBaseFileName) +\r
            strlen (VFR_PREPROCESS_FILENAME_EXTENSION) +\r
            1;\r
-  if (Length > MAX_PATH) {\r
-    return -1;\r
-  }\r
 \r
   mOptions.PreprocessorOutputFileName = (CHAR8 *) malloc (Length);\r
   if (mOptions.PreprocessorOutputFileName == NULL) {\r
@@ -480,9 +459,6 @@ CVfrCompiler::SetRecordListFileName (
            strlen (mOptions.VfrBaseFileName) +\r
            strlen (VFR_RECORDLIST_FILENAME_EXTENSION) +\r
            1;\r
-  if (Length > MAX_PATH) {\r
-    return -1;\r
-  }\r
 \r
   mOptions.RecordListFile = (CHAR8 *) malloc (Length);\r
   if (mOptions.RecordListFile == NULL) {\r
@@ -497,7 +473,7 @@ CVfrCompiler::SetRecordListFileName (
 }\r
 \r
 CVfrCompiler::CVfrCompiler (\r
-  IN INT32      Argc, \r
+  IN INT32      Argc,\r
   IN CHAR8      **Argv\r
   )\r
 {\r
@@ -555,26 +531,26 @@ CVfrCompiler::~CVfrCompiler (
   }\r
 \r
   if (mOptions.IncludePaths != NULL) {\r
-    delete mOptions.IncludePaths;\r
+    delete[] mOptions.IncludePaths;\r
     mOptions.IncludePaths = NULL;\r
   }\r
 \r
   if (mOptions.CPreprocessorOptions != NULL) {\r
-    delete mOptions.CPreprocessorOptions;\r
+    delete[] mOptions.CPreprocessorOptions;\r
     mOptions.CPreprocessorOptions = NULL;\r
   }\r
 \r
   SET_RUN_STATUS(STATUS_DEAD);\r
 }\r
 \r
-VOID \r
+VOID\r
 CVfrCompiler::Usage (\r
   VOID\r
   )\r
 {\r
   UINT32 Index;\r
   CONST  CHAR8 *Help[] = {\r
-    " ", \r
+    " ",\r
     "VfrCompile version " VFR_COMPILER_VERSION "Build " __BUILD_VERSION,\r
     "Copyright (c) 2004-2016 Intel Corporation. All rights reserved.",\r
     " ",\r
@@ -609,7 +585,7 @@ CVfrCompiler::Usage (
   }\r
 }\r
 \r
-VOID \r
+VOID\r
 CVfrCompiler::Version (\r
   VOID\r
   )\r
@@ -642,13 +618,13 @@ CVfrCompiler::PreProcess (
   }\r
 \r
   if ((pVfrFile = fopen (LongFilePath (mOptions.VfrFileName), "r")) == NULL) {\r
-    DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);\r
+    DebugError (NULL, 0, 0001, "Error opening the input VFR file", "%s", mOptions.VfrFileName);\r
     goto Fail;\r
   }\r
   fclose (pVfrFile);\r
 \r
-  CmdLen = strlen (mPreProcessCmd) + strlen (mPreProcessOpt) + \r
-              strlen (mOptions.VfrFileName) + strlen (mOptions.PreprocessorOutputFileName);\r
+  CmdLen = strlen (mPreProcessCmd) + strlen (mPreProcessOpt) +\r
+           strlen (mOptions.VfrFileName) + strlen (mOptions.PreprocessorOutputFileName);\r
   if (mOptions.CPreprocessorOptions != NULL) {\r
     CmdLen += strlen (mOptions.CPreprocessorOptions);\r
   }\r
@@ -677,7 +653,7 @@ CVfrCompiler::PreProcess (
     goto Fail;\r
   }\r
 \r
-  delete PreProcessCmd;\r
+  delete[] PreProcessCmd;\r
 \r
 Out:\r
   SET_RUN_STATUS (STATUS_PREPROCESSED);\r
@@ -687,7 +663,7 @@ Fail:
   if (!IS_RUN_STATUS(STATUS_DEAD)) {\r
     SET_RUN_STATUS (STATUS_FAILED);\r
   }\r
-  delete PreProcessCmd;\r
+  delete[] PreProcessCmd;\r
 }\r
 \r
 extern UINT8 VfrParserStart (IN FILE *, IN INPUT_INFO_TO_SYNTAX *);\r
@@ -711,7 +687,7 @@ CVfrCompiler::Compile (
   gCVfrErrorHandle.SetWarningAsError(mOptions.WarningAsError);\r
 \r
   if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
-    DebugError (NULL, 0, 0001, "Error opening the input file", InFileName);\r
+    DebugError (NULL, 0, 0001, "Error opening the input file", "%s", InFileName);\r
     goto Fail;\r
   }\r
 \r
@@ -727,6 +703,7 @@ CVfrCompiler::Compile (
   }\r
 \r
   fclose (pInFile);\r
+  pInFile = NULL;\r
 \r
   if (gCFormPkg.HavePendingUnassigned () == TRUE) {\r
     gCFormPkg.PendingAssignPrintAll ();\r
@@ -779,7 +756,7 @@ CVfrCompiler::AdjustBin (
   // Get Package Data and IfrRecord Data\r
   //\r
   gCFormPkg.BuildPkg (gCBuffer);\r
-  gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer); \r
+  gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);\r
 \r
   //\r
   // Compare Form and Record data\r
@@ -822,7 +799,7 @@ CVfrCompiler::AdjustBin (
     //\r
     // Re get the IfrRecord Buffer.\r
     //\r
-    gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer); \r
+    gCIfrRecordInfoDB.IfrRecordOutput (gRBuffer);\r
   }\r
 \r
   return;\r
@@ -841,7 +818,7 @@ CVfrCompiler::GenBinary (
 \r
   if (mOptions.CreateIfrPkgFile == TRUE) {\r
     if ((pFile = fopen (LongFilePath (mOptions.PkgOutputFileName), "wb")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening file", "%s", mOptions.PkgOutputFileName);\r
       goto Fail;\r
     }\r
     if (gCFormPkg.BuildPkg (pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {\r
@@ -881,10 +858,10 @@ CVfrCompiler::GenCFile (
   if (!IS_RUN_STATUS(STATUS_GENBINARY)) {\r
     goto Fail;\r
   }\r
-  \r
+\r
   if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) {\r
     if ((pFile = fopen (LongFilePath (mOptions.COutputFileName), "w")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening output C file", "%s", mOptions.COutputFileName);\r
       goto Fail;\r
     }\r
 \r
@@ -892,7 +869,7 @@ CVfrCompiler::GenCFile (
       fprintf (pFile, "%s\n", gSourceFileHeader[Index]);\r
     }\r
 \r
-    if (mOptions.CompatibleMode) { \r
+    if (mOptions.CompatibleMode) {\r
       gCVfrBufferConfig.OutputCFile (pFile, mOptions.VfrBaseFileName);\r
     }\r
 \r
@@ -925,18 +902,18 @@ CVfrCompiler::GenRecordListFile (
 \r
   InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;\r
 \r
-  if (mOptions.CreateRecordListFile == TRUE) {\r
+  if (mOptions.CreateRecordListFile == TRUE && InFileName != NULL && mOptions.RecordListFile != NULL) {\r
     if ((InFileName[0] == '\0') || (mOptions.RecordListFile[0] == '\0')) {\r
       return;\r
     }\r
 \r
     if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
-      DebugError (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", "%s", InFileName);\r
       return;\r
     }\r
 \r
     if ((pOutFile = fopen (LongFilePath (mOptions.RecordListFile), "w")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);\r
+      DebugError (NULL, 0, 0001, "Error opening the record list file", "%s", mOptions.RecordListFile);\r
       goto Err1;\r
     }\r
 \r
@@ -949,7 +926,7 @@ CVfrCompiler::GenRecordListFile (
         gCIfrRecordInfoDB.IfrRecordOutput (pOutFile, LineNo);\r
       }\r
     }\r
-    \r
+\r
     fprintf (pOutFile, "\n//\n// All Opcode Record List \n//\n");\r
     gCIfrRecordInfoDB.IfrRecordOutput (pOutFile, 0);\r
     gCVfrVarDataTypeDB.Dump(pOutFile);\r
@@ -966,7 +943,7 @@ Err1:
 \r
 int\r
 main (\r
-  IN int             Argc, \r
+  IN int             Argc,\r
   IN char            **Argv\r
   )\r
 {\r
@@ -974,7 +951,7 @@ main (
 \r
   SetPrintLevel(WARNING_LOG_LEVEL);\r
   CVfrCompiler         Compiler(Argc, Argv);\r
-  \r
+\r
   Compiler.PreProcess();\r
   Compiler.Compile();\r
   Compiler.AdjustBin();\r
@@ -988,11 +965,11 @@ main (
   }\r
 \r
   if (gCBuffer.Buffer != NULL) {\r
-    delete gCBuffer.Buffer;\r
+    delete[] gCBuffer.Buffer;\r
   }\r
-  \r
+\r
   if (gRBuffer.Buffer != NULL) {\r
-    delete gRBuffer.Buffer;\r
+    delete[] gRBuffer.Buffer;\r
   }\r
 \r
   return GetUtilityStatus ();\r