diff options
author | qwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-06-28 07:00:39 +0000 |
---|---|---|
committer | qwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524> | 2007-06-28 07:00:39 +0000 |
commit | 3eb9473ea9a949badfe06ae61d2d3fcfa53651c7 (patch) | |
tree | e9d8c368dbb1e58794b2c00acefe4bbad270f8c4 /EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf | |
parent | 30d4a0c7ec19938196b1308006b990e0945150da (diff) | |
download | edk2-platforms-3eb9473ea9a949badfe06ae61d2d3fcfa53651c7.tar.xz |
Add in the 1st version of ECP.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2832 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf')
-rw-r--r-- | EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/Makefile | 82 | ||||
-rw-r--r-- | EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/ModifyInf.c | 322 |
2 files changed, 404 insertions, 0 deletions
diff --git a/EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/Makefile b/EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/Makefile new file mode 100644 index 0000000000..f303a54d10 --- /dev/null +++ b/EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/Makefile @@ -0,0 +1,82 @@ +#/*++
+#
+# Copyright (c) 2001 - 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.
+#
+# Module Name:
+#
+# Makefile
+#
+# Abstract:
+#
+# This file is used to build the EFI utility.
+#
+#--*/
+
+#
+# Make sure environmental variable EDK_SOURCE is set
+#
+!IFNDEF EDK_SOURCE
+!ERROR EDK_SOURCE environmental variable not set
+!ENDIF
+
+#
+# Do this if you want to compile from this directory
+#
+!IFNDEF TOOLCHAIN
+TOOLCHAIN = TOOLCHAIN_MSVC
+!ENDIF
+
+!INCLUDE $(BUILD_DIR)\PlatformTools.env
+
+#
+# Target specific information
+#
+
+TARGET_NAME = ModifyInf
+TARGET_SRC_DIR = $(EDK_TOOLS_SOURCE)\$(TARGET_NAME)
+TARGET_EXE = $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).exe
+
+TARGET_EXE_SOURCE = "$(TARGET_SRC_DIR)\ModifyInf.c"
+TARGET_EXE_INCLUDE =
+OBJECTS = $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
+
+#
+# Build targets
+#
+
+all: $(TARGET_EXE)
+
+#
+# Build EXE
+#
+
+$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj: $(TARGET_EXE_SOURCE) $(TARGET_EXE_INCLUDE)
+ $(CC) $(C_FLAGS) $(INC) $(TARGET_EXE_SOURCE) /Fo$(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).obj
+
+#
+# Add Binary Build description for this tool.
+#
+
+!IF (("$(EFI_BINARY_TOOLS)" == "YES") && EXIST($(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe))
+$(TARGET_EXE): $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe
+ copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).exe $(TARGET_EXE) /Y
+ if exist $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb \
+ copy $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb /Y
+!ELSE
+$(TARGET_EXE) : $(OBJECTS)
+ $(LINK) $(MSVS_LINK_LIBPATHS) $(L_FLAGS) $(LIBS) /out:$(TARGET_EXE) $(OBJECTS)
+ if not exist $(EFI_PLATFORM_BIN)\Tools mkdir $(EFI_PLATFORM_BIN)\Tools
+ if exist $(TARGET_EXE) copy $(TARGET_EXE) $(EFI_PLATFORM_BIN)\tools\$(TARGET_NAME).exe /Y
+ if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb \
+ copy $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).pdb $(EFI_PLATFORM_BIN)\Tools\$(TARGET_NAME).pdb /Y
+!ENDIF
+
+clean:
+ @if exist $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* del $(EDK_TOOLS_OUTPUT)\$(TARGET_NAME).* > NUL
diff --git a/EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/ModifyInf.c b/EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/ModifyInf.c new file mode 100644 index 0000000000..edfcba00a9 --- /dev/null +++ b/EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/ModifyInf.c @@ -0,0 +1,322 @@ +/*++
+
+Copyright (c) 1999 - 2002 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.
+
+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];
+ int SectionLength;
+ 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;
+ }
+ }
+ SectionLength = Ptr - Line + 1;
+ SectionLength = SectionLength > 255 ? 255 : SectionLength;
+ strncpy (Section, Line, SectionLength);
+ Section[SectionLength] = 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;
+}
|