--- /dev/null
+/*++\r
+\r
+Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved\r
+This software and associated documentation (if any) is furnished\r
+under a license and may only be used or copied in accordance\r
+with the terms of the license. Except as permitted by such\r
+license, no part of this software or documentation may be\r
+reproduced, stored in a retrieval system, or transmitted in any\r
+form or by any means without the express written consent of\r
+Intel Corporation.\r
+\r
+\r
+Module Name:\r
+\r
+ ModifyInf.c\r
+\r
+Abstract:\r
+\r
+ It is a simple tool to modify some fields in a FV inf file \r
+ and output a new FV inf file. \r
+\r
+--*/\r
+\r
+#include "stdio.h"\r
+#include "string.h"\r
+\r
+//\r
+// Read a line into buffer including '\r\n'\r
+//\r
+int\r
+ReadLine (\r
+ char *LineBuffer,\r
+ FILE *fp\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ LineBuffer - GC_TODO: add argument description\r
+ fp - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+ int CharC;\r
+ char *Line;\r
+\r
+ Line = LineBuffer;\r
+\r
+ while ((CharC = fgetc (fp)) != EOF) {\r
+ *Line++ = (char) CharC;\r
+ if (CharC == 0x0a) {\r
+ break;\r
+ }\r
+ }\r
+\r
+ *Line = 0;\r
+\r
+ if (CharC == EOF) {\r
+ return 0;\r
+ } else {\r
+ return 1;\r
+ }\r
+\r
+}\r
+//\r
+// Write a line into output file\r
+//\r
+int\r
+WriteLine (\r
+ char *Line,\r
+ FILE *fp\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Line - GC_TODO: add argument description\r
+ fp - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+ fwrite (Line, strlen (Line), 1, fp);\r
+ return 0;\r
+}\r
+//\r
+// Apply patterns to a line\r
+// Currently there are 2 patterns to support\r
+// '==' replace a field value with a new value\r
+// '+=' append a string at the end of original line\r
+// '-' prevent the line from applying any patterns\r
+// it has the highest priority\r
+//\r
+int\r
+ApplyPattern (\r
+ char *Line,\r
+ char *argv[],\r
+ int argc\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ Line - GC_TODO: add argument description\r
+ ] - GC_TODO: add argument description\r
+ argc - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+ static char Section[256];\r
+ char PatternBuffer[256];\r
+ char *Pattern;\r
+ char *Pattern1;\r
+ char *Pattern2;\r
+ int PatternNum;\r
+ char *Ptr;\r
+\r
+ Pattern = PatternBuffer;\r
+\r
+ PatternNum = argc;\r
+\r
+ //\r
+ // For section field\r
+ // record current scope section into static buffer\r
+ //\r
+ Ptr = Line;\r
+ if (*Ptr == '[') {\r
+ while (*Ptr != ']') {\r
+ if (!(*Ptr++)) {\r
+ return -1;\r
+ }\r
+ }\r
+\r
+ strcpy (Section, Line);\r
+ Section[Ptr - Line + 1] = 0;\r
+ }\r
+ //\r
+ // Apply each pattern on the line\r
+ //\r
+ while (PatternNum-- > 3) {\r
+\r
+ strcpy (Pattern, argv[PatternNum]);\r
+\r
+ //\r
+ // For pattern '-'\r
+ // keep it unmodified by other patterns\r
+ //\r
+ if (*Pattern == '-') {\r
+ if (strstr (Line, Pattern + 1)) {\r
+ return 0;\r
+ } else {\r
+ continue;\r
+ }\r
+ }\r
+ //\r
+ // For other patterns\r
+ // get its section at first if it has\r
+ //\r
+ if (*Pattern == '[') {\r
+ if (strncmp (Section, Pattern, strlen (Section))) {\r
+ //\r
+ // This pattern can't be appied for current section\r
+ //\r
+ continue;\r
+ }\r
+ //\r
+ // Strip the section field\r
+ //\r
+ while (*Pattern != ']') {\r
+ if (!(*Pattern++)) {\r
+ return -1;\r
+ }\r
+ }\r
+\r
+ Pattern++;\r
+ }\r
+ //\r
+ // Apply patterns\r
+ //\r
+ Pattern1 = strstr (Pattern, "==");\r
+ Pattern2 = strstr (Pattern, "+=");\r
+ if (Pattern1) {\r
+ //\r
+ // For pattern '=='\r
+ // replace the field value with a new string\r
+ //\r
+ if (!strncmp (Line, Pattern, Pattern1 - Pattern)) {\r
+ Pattern1 += 2;\r
+ Ptr = strstr (Line, "=");\r
+ if (!Ptr) {\r
+ return -1;\r
+ }\r
+\r
+ while (*(++Ptr) == ' ')\r
+ ;\r
+ *Ptr = 0;\r
+ strcat (Line, Pattern1);\r
+ strcat (Line, "\r\n");\r
+ }\r
+ } else if (Pattern2) {\r
+ //\r
+ // For pattern '+='\r
+ // append a string at end of the original string\r
+ //\r
+ if (!strncmp (Line, Pattern, Pattern2 - Pattern)) {\r
+ Pattern2 += 2;\r
+ Ptr = Line;\r
+ while (*Ptr != 0x0D && *Ptr != 0x0A) {\r
+ Ptr++;\r
+ }\r
+\r
+ *Ptr = 0;\r
+ strcat (Line, Pattern2);\r
+ strcat (Line, "\r\n");\r
+ }\r
+ }\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+void\r
+Usage (\r
+ void\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ None\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+ printf ("ModifyInf InputFVInfFileName OutputFVInfFileName [Pattern strings]\r\n");\r
+}\r
+\r
+int\r
+main (\r
+ int argc,\r
+ char*argv[]\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ GC_TODO: Add function description\r
+\r
+Arguments:\r
+\r
+ argc - GC_TODO: add argument description\r
+ ] - GC_TODO: add argument description\r
+\r
+Returns:\r
+\r
+ GC_TODO: add return values\r
+\r
+--*/\r
+{\r
+ char LineBuffer[256];\r
+ FILE *fpin;\r
+ FILE *fpout;\r
+\r
+ if (argc < 3) {\r
+ Usage ();\r
+ return -1;\r
+ }\r
+\r
+ fpin = fopen (argv[1], "rb");\r
+ if (!fpin) {\r
+ printf ("Can't open input file!\r\n");\r
+ return -1;\r
+ }\r
+\r
+ fpout = fopen (argv[2], "wb");\r
+ if (!fpout) {\r
+ fclose (fpin);\r
+ printf ("Can't create output file!\r\n");\r
+ return -1;\r
+ }\r
+\r
+ while (ReadLine (LineBuffer, fpin)) {\r
+ ApplyPattern (LineBuffer, argv, argc);\r
+ WriteLine (LineBuffer, fpout);\r
+ }\r
+\r
+ fclose (fpin);\r
+ fclose (fpout);\r
+\r
+ return 0;\r
+}\r
--- /dev/null
+<?xml version="1.0" ?>\r
+<!--\r
+Copyright (c) 2006, 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
+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
+<project default="GenTool" basedir=".">\r
+<!--\r
+ EDK ModifyInf Tool\r
+ Copyright (c) 2006, Intel Corporation\r
+-->\r
+ <property name="ToolName" value="ModifyInf"/>\r
+ <property name="FileSet" value="ModifyInf.c"/>\r
+\r
+ <taskdef resource="cpptasks.tasks"/>\r
+ <typedef resource="cpptasks.types"/>\r
+ <taskdef resource="net/sf/antcontrib/antlib.xml"/>\r
+\r
+ <property environment="env"/>\r
+\r
+ <property name="LINK_OUTPUT_TYPE" value="static"/>\r
+ <property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>\r
+\r
+ <target name="GenTool" depends="init, Tool">\r
+ <echo message="Building the EDK Tool: ${ToolName}"/>\r
+ </target>\r
+\r
+ <target name="init">\r
+ <echo message="The EDK Tool: ${ToolName}"/>\r
+ <mkdir dir="${BUILD_DIR}"/>\r
+ <if>\r
+ <equals arg1="${GCC}" arg2="cygwin"/>\r
+ <then>\r
+ <echo message="Cygwin Family"/>\r
+ <property name="ToolChain" value="gcc"/>\r
+ </then>\r
+ <elseif>\r
+ <os family="dos"/>\r
+ <then>\r
+ <echo message="Windows Family"/>\r
+ <property name="ToolChain" value="msvc"/>\r
+ </then>\r
+ </elseif>\r
+ <elseif>\r
+ <os family="unix"/>\r
+ <then>\r
+ <echo message="UNIX Family"/>\r
+ <property name="ToolChain" value="gcc"/>\r
+ </then>\r
+ </elseif>\r
+\r
+ <else>\r
+ <echo>\r
+ Unsupported Operating System\r
+ Please Contact Intel Corporation\r
+ </echo>\r
+ </else>\r
+ </if>\r
+ <if>\r
+ <equals arg1="${ToolChain}" arg2="msvc"/>\r
+ <then>\r
+ <property name="ext_static" value=".lib"/>\r
+ <property name="ext_dynamic" value=".dll"/>\r
+ <property name="ext_exe" value=".exe"/>\r
+ </then>\r
+ <elseif>\r
+ <equals arg1="${ToolChain}" arg2="gcc"/>\r
+ <then>\r
+ <property name="ext_static" value=".a"/>\r
+ <property name="ext_dynamic" value=".so"/>\r
+ <property name="ext_exe" value=""/>\r
+ </then>\r
+ </elseif>\r
+ </if>\r
+ </target>\r
+\r
+ <target name="Tool" depends="init">\r
+ <cc name="${ToolChain}" objdir="${BUILD_DIR}" \r
+ outfile="${BIN_DIR}/${ToolName}"\r
+ outtype="executable"\r
+ libtool="${haveLibtool}"\r
+ optimize="speed">\r
+\r
+ <fileset dir="${basedir}/${ToolName}" \r
+ includes="${FileSet}" \r
+ defaultexcludes="TRUE" \r
+ excludes="*.xml *.inf"/>\r
+\r
+ <includepath path="${PACKAGE_DIR}/Include"/>\r
+ <includepath path="${PACKAGE_DIR}/Include/Common"/>\r
+ <includepath path="${PACKAGE_DIR}/Include/Ia32"/>\r
+ <includepath path="${PACKAGE_DIR}/Common"/>\r
+ <libset dir="${LIB_DIR}" libs="CommonTools"/>\r
+\r
+ </cc>\r
+ </target>\r
+\r
+ <target name="clean" depends="init">\r
+ <echo message="Removing Intermediate Files Only"/> \r
+ <delete>\r
+ <fileset dir="${BUILD_DIR}" includes="*.obj"/>\r
+ </delete>\r
+ </target>\r
+\r
+ <target name="cleanall" depends="init">\r
+ <echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/> \r
+ <delete dir="${BUILD_DIR}">\r
+ <fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>\r
+ </delete>\r
+ </target>\r
+\r
+</project>\r