summaryrefslogtreecommitdiff
path: root/Tools/Source/TianoTools
diff options
context:
space:
mode:
authorbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>2006-06-15 16:23:53 +0000
committerbbahnsen <bbahnsen@6f19259b-4bc3-4df7-8a09-765794883524>2006-06-15 16:23:53 +0000
commit19eba4a7b455ba6744968fd9592b7fab6f8a2a26 (patch)
tree44f5dfe88463f9fd91d495eba0c551782fa11de5 /Tools/Source/TianoTools
parent6f7e61a03a654ad08ba198432c2ed196a9df0c3e (diff)
downloadedk2-platforms-19eba4a7b455ba6744968fd9592b7fab6f8a2a26.tar.xz
Add the ModifyInf tool
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@532 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Tools/Source/TianoTools')
-rwxr-xr-xTools/Source/TianoTools/ModifyInf/ModifyInf.c321
-rw-r--r--Tools/Source/TianoTools/ModifyInf/build.xml117
2 files changed, 438 insertions, 0 deletions
diff --git a/Tools/Source/TianoTools/ModifyInf/ModifyInf.c b/Tools/Source/TianoTools/ModifyInf/ModifyInf.c
new file mode 100755
index 0000000000..1b6eee6cd5
--- /dev/null
+++ b/Tools/Source/TianoTools/ModifyInf/ModifyInf.c
@@ -0,0 +1,321 @@
+/*++
+
+Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
+This software and associated documentation (if any) is furnished
+under a license and may only be used or copied in accordance
+with the terms of the license. Except as permitted by such
+license, no part of this software or documentation may be
+reproduced, stored in a retrieval system, or transmitted in any
+form or by any means without the express written consent of
+Intel Corporation.
+
+
+Module Name:
+
+ ModifyInf.c
+
+Abstract:
+
+ It is a simple tool to modify some fields in a FV inf file
+ and output a new FV inf file.
+
+--*/
+
+#include "stdio.h"
+#include "string.h"
+
+//
+// Read a line into buffer including '\r\n'
+//
+int
+ReadLine (
+ char *LineBuffer,
+ FILE *fp
+ )
+/*++
+
+Routine Description:
+
+ GC_TODO: Add function description
+
+Arguments:
+
+ LineBuffer - GC_TODO: add argument description
+ fp - GC_TODO: add argument description
+
+Returns:
+
+ GC_TODO: add return values
+
+--*/
+{
+ int CharC;
+ char *Line;
+
+ Line = LineBuffer;
+
+ while ((CharC = fgetc (fp)) != EOF) {
+ *Line++ = (char) CharC;
+ if (CharC == 0x0a) {
+ break;
+ }
+ }
+
+ *Line = 0;
+
+ if (CharC == EOF) {
+ return 0;
+ } else {
+ return 1;
+ }
+
+}
+//
+// Write a line into output file
+//
+int
+WriteLine (
+ char *Line,
+ FILE *fp
+ )
+/*++
+
+Routine Description:
+
+ GC_TODO: Add function description
+
+Arguments:
+
+ Line - GC_TODO: add argument description
+ fp - GC_TODO: add argument description
+
+Returns:
+
+ GC_TODO: add return values
+
+--*/
+{
+ fwrite (Line, strlen (Line), 1, fp);
+ return 0;
+}
+//
+// Apply patterns to a line
+// Currently there are 2 patterns to support
+// '==' replace a field value with a new value
+// '+=' append a string at the end of original line
+// '-' prevent the line from applying any patterns
+// it has the highest priority
+//
+int
+ApplyPattern (
+ char *Line,
+ char *argv[],
+ int argc
+ )
+/*++
+
+Routine Description:
+
+ GC_TODO: Add function description
+
+Arguments:
+
+ Line - GC_TODO: add argument description
+ ] - GC_TODO: add argument description
+ argc - GC_TODO: add argument description
+
+Returns:
+
+ GC_TODO: add return values
+
+--*/
+{
+ static char Section[256];
+ char PatternBuffer[256];
+ char *Pattern;
+ char *Pattern1;
+ char *Pattern2;
+ int PatternNum;
+ char *Ptr;
+
+ Pattern = PatternBuffer;
+
+ PatternNum = argc;
+
+ //
+ // For section field
+ // record current scope section into static buffer
+ //
+ Ptr = Line;
+ if (*Ptr == '[') {
+ while (*Ptr != ']') {
+ if (!(*Ptr++)) {
+ return -1;
+ }
+ }
+
+ strcpy (Section, Line);
+ Section[Ptr - Line + 1] = 0;
+ }
+ //
+ // Apply each pattern on the line
+ //
+ while (PatternNum-- > 3) {
+
+ strcpy (Pattern, argv[PatternNum]);
+
+ //
+ // For pattern '-'
+ // keep it unmodified by other patterns
+ //
+ if (*Pattern == '-') {
+ if (strstr (Line, Pattern + 1)) {
+ return 0;
+ } else {
+ continue;
+ }
+ }
+ //
+ // For other patterns
+ // get its section at first if it has
+ //
+ if (*Pattern == '[') {
+ if (strncmp (Section, Pattern, strlen (Section))) {
+ //
+ // This pattern can't be appied for current section
+ //
+ continue;
+ }
+ //
+ // Strip the section field
+ //
+ while (*Pattern != ']') {
+ if (!(*Pattern++)) {
+ return -1;
+ }
+ }
+
+ Pattern++;
+ }
+ //
+ // Apply patterns
+ //
+ Pattern1 = strstr (Pattern, "==");
+ Pattern2 = strstr (Pattern, "+=");
+ if (Pattern1) {
+ //
+ // For pattern '=='
+ // replace the field value with a new string
+ //
+ if (!strncmp (Line, Pattern, Pattern1 - Pattern)) {
+ Pattern1 += 2;
+ Ptr = strstr (Line, "=");
+ if (!Ptr) {
+ return -1;
+ }
+
+ while (*(++Ptr) == ' ')
+ ;
+ *Ptr = 0;
+ strcat (Line, Pattern1);
+ strcat (Line, "\r\n");
+ }
+ } else if (Pattern2) {
+ //
+ // For pattern '+='
+ // append a string at end of the original string
+ //
+ if (!strncmp (Line, Pattern, Pattern2 - Pattern)) {
+ Pattern2 += 2;
+ Ptr = Line;
+ while (*Ptr != 0x0D && *Ptr != 0x0A) {
+ Ptr++;
+ }
+
+ *Ptr = 0;
+ strcat (Line, Pattern2);
+ strcat (Line, "\r\n");
+ }
+ }
+ }
+
+ return 0;
+}
+
+void
+Usage (
+ void
+ )
+/*++
+
+Routine Description:
+
+ GC_TODO: Add function description
+
+Arguments:
+
+ None
+
+Returns:
+
+ GC_TODO: add return values
+
+--*/
+{
+ printf ("ModifyInf InputFVInfFileName OutputFVInfFileName [Pattern strings]\r\n");
+}
+
+int
+main (
+ int argc,
+ char*argv[]
+ )
+/*++
+
+Routine Description:
+
+ GC_TODO: Add function description
+
+Arguments:
+
+ argc - GC_TODO: add argument description
+ ] - GC_TODO: add argument description
+
+Returns:
+
+ GC_TODO: add return values
+
+--*/
+{
+ char LineBuffer[256];
+ FILE *fpin;
+ FILE *fpout;
+
+ if (argc < 3) {
+ Usage ();
+ return -1;
+ }
+
+ fpin = fopen (argv[1], "rb");
+ if (!fpin) {
+ printf ("Can't open input file!\r\n");
+ return -1;
+ }
+
+ fpout = fopen (argv[2], "wb");
+ if (!fpout) {
+ fclose (fpin);
+ printf ("Can't create output file!\r\n");
+ return -1;
+ }
+
+ while (ReadLine (LineBuffer, fpin)) {
+ ApplyPattern (LineBuffer, argv, argc);
+ WriteLine (LineBuffer, fpout);
+ }
+
+ fclose (fpin);
+ fclose (fpout);
+
+ return 0;
+}
diff --git a/Tools/Source/TianoTools/ModifyInf/build.xml b/Tools/Source/TianoTools/ModifyInf/build.xml
new file mode 100644
index 0000000000..aadd823188
--- /dev/null
+++ b/Tools/Source/TianoTools/ModifyInf/build.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" ?>
+<!--
+Copyright (c) 2006, Intel Corporation
+All rights reserved. This program and the accompanying materials
+are licensed and made available under the terms and conditions of the BSD License
+which accompanies this distribution. The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+-->
+<project default="GenTool" basedir=".">
+<!--
+ EDK ModifyInf Tool
+ Copyright (c) 2006, Intel Corporation
+-->
+ <property name="ToolName" value="ModifyInf"/>
+ <property name="FileSet" value="ModifyInf.c"/>
+
+ <taskdef resource="cpptasks.tasks"/>
+ <typedef resource="cpptasks.types"/>
+ <taskdef resource="net/sf/antcontrib/antlib.xml"/>
+
+ <property environment="env"/>
+
+ <property name="LINK_OUTPUT_TYPE" value="static"/>
+ <property name="BUILD_DIR" value="${PACKAGE_DIR}/${ToolName}/tmp"/>
+
+ <target name="GenTool" depends="init, Tool">
+ <echo message="Building the EDK Tool: ${ToolName}"/>
+ </target>
+
+ <target name="init">
+ <echo message="The EDK Tool: ${ToolName}"/>
+ <mkdir dir="${BUILD_DIR}"/>
+ <if>
+ <equals arg1="${GCC}" arg2="cygwin"/>
+ <then>
+ <echo message="Cygwin Family"/>
+ <property name="ToolChain" value="gcc"/>
+ </then>
+ <elseif>
+ <os family="dos"/>
+ <then>
+ <echo message="Windows Family"/>
+ <property name="ToolChain" value="msvc"/>
+ </then>
+ </elseif>
+ <elseif>
+ <os family="unix"/>
+ <then>
+ <echo message="UNIX Family"/>
+ <property name="ToolChain" value="gcc"/>
+ </then>
+ </elseif>
+
+ <else>
+ <echo>
+ Unsupported Operating System
+ Please Contact Intel Corporation
+ </echo>
+ </else>
+ </if>
+ <if>
+ <equals arg1="${ToolChain}" arg2="msvc"/>
+ <then>
+ <property name="ext_static" value=".lib"/>
+ <property name="ext_dynamic" value=".dll"/>
+ <property name="ext_exe" value=".exe"/>
+ </then>
+ <elseif>
+ <equals arg1="${ToolChain}" arg2="gcc"/>
+ <then>
+ <property name="ext_static" value=".a"/>
+ <property name="ext_dynamic" value=".so"/>
+ <property name="ext_exe" value=""/>
+ </then>
+ </elseif>
+ </if>
+ </target>
+
+ <target name="Tool" depends="init">
+ <cc name="${ToolChain}" objdir="${BUILD_DIR}"
+ outfile="${BIN_DIR}/${ToolName}"
+ outtype="executable"
+ libtool="${haveLibtool}"
+ optimize="speed">
+
+ <fileset dir="${basedir}/${ToolName}"
+ includes="${FileSet}"
+ defaultexcludes="TRUE"
+ excludes="*.xml *.inf"/>
+
+ <includepath path="${PACKAGE_DIR}/Include"/>
+ <includepath path="${PACKAGE_DIR}/Include/Common"/>
+ <includepath path="${PACKAGE_DIR}/Include/Ia32"/>
+ <includepath path="${PACKAGE_DIR}/Common"/>
+ <libset dir="${LIB_DIR}" libs="CommonTools"/>
+
+ </cc>
+ </target>
+
+ <target name="clean" depends="init">
+ <echo message="Removing Intermediate Files Only"/>
+ <delete>
+ <fileset dir="${BUILD_DIR}" includes="*.obj"/>
+ </delete>
+ </target>
+
+ <target name="cleanall" depends="init">
+ <echo message="Removing Object Files and the Executable: ${ToolName}${ext_exe}"/>
+ <delete dir="${BUILD_DIR}">
+ <fileset dir="${BIN_DIR}" includes="${ToolName}${ext_exe}"/>
+ </delete>
+ </target>
+
+</project>