3 Copyright (c) 1999-2006 Intel Corporation. All rights reserved
\r
4 This program and the accompanying materials are licensed and made available
\r
5 under the terms and conditions of the BSD License which accompanies this
\r
6 distribution. The full text of the license may be found at
\r
7 http://opensource.org/licenses/bsd-license.php
\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
19 It is a simple tool to modify some fields in a FV inf file
\r
20 and output a new FV inf file.
\r
27 #define UTILITY_NAME "ModifyInf"
\r
28 #define UTILITY_MAJOR_VERSION 1
\r
29 #define UTILITY_MINOR_VERSION 1
\r
32 // Read a line into buffer including '\r\n'
\r
41 Routine Description:
\r
43 GC_TODO: Add function description
\r
47 LineBuffer - GC_TODO: add argument description
\r
48 fp - GC_TODO: add argument description
\r
52 GC_TODO: add return values
\r
61 while ((CharC = fgetc (fp)) != EOF) {
\r
62 *Line++ = (char) CharC;
\r
63 if (CharC == 0x0a) {
\r
78 // Write a line into output file
\r
87 Routine Description:
\r
89 GC_TODO: Add function description
\r
93 Line - GC_TODO: add argument description
\r
94 fp - GC_TODO: add argument description
\r
98 GC_TODO: add return values
\r
102 fwrite (Line, strlen (Line), 1, fp);
\r
106 // Apply patterns to a line
\r
107 // Currently there are 2 patterns to support
\r
108 // '==' replace a field value with a new value
\r
109 // '+=' append a string at the end of original line
\r
110 // '-' prevent the line from applying any patterns
\r
111 // it has the highest priority
\r
121 Routine Description:
\r
123 GC_TODO: Add function description
\r
127 Line - GC_TODO: add argument description
\r
128 ] - GC_TODO: add argument description
\r
129 argc - GC_TODO: add argument description
\r
133 GC_TODO: add return values
\r
137 static char Section[256];
\r
138 char PatternBuffer[256];
\r
145 Pattern = PatternBuffer;
\r
150 // For section field
\r
151 // record current scope section into static buffer
\r
155 while (*Ptr != ']') {
\r
161 strcpy (Section, Line);
\r
162 Section[Ptr - Line + 1] = 0;
\r
165 // Apply each pattern on the line
\r
167 while (PatternNum-- > 3) {
\r
169 strcpy (Pattern, argv[PatternNum]);
\r
173 // keep it unmodified by other patterns
\r
175 if (*Pattern == '-') {
\r
176 if (strstr (Line, Pattern + 1)) {
\r
183 // For other patterns
\r
184 // get its section at first if it has
\r
186 if (*Pattern == '[') {
\r
187 if (strncmp (Section, Pattern, strlen (Section))) {
\r
189 // This pattern can't be appied for current section
\r
194 // Strip the section field
\r
196 while (*Pattern != ']') {
\r
197 if (!(*Pattern++)) {
\r
207 Pattern1 = strstr (Pattern, "==");
\r
208 Pattern2 = strstr (Pattern, "+=");
\r
211 // For pattern '=='
\r
212 // replace the field value with a new string
\r
214 if (!strncmp (Line, Pattern, Pattern1 - Pattern)) {
\r
216 Ptr = strstr (Line, "=");
\r
221 while (*(++Ptr) == ' ')
\r
224 strcat (Line, Pattern1);
\r
225 strcat (Line, "\r\n");
\r
227 } else if (Pattern2) {
\r
229 // For pattern '+='
\r
230 // append a string at end of the original string
\r
232 if (!strncmp (Line, Pattern, Pattern2 - Pattern)) {
\r
235 while (*Ptr != 0x0D && *Ptr != 0x0A) {
\r
240 strcat (Line, Pattern2);
\r
241 strcat (Line, "\r\n");
\r
255 Routine Description:
\r
257 Print out version information for Strip.
\r
269 printf ("%s v%d.%d -EDK Modify fields in FV inf files.\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);
\r
270 printf ("Copyright (c) 2005-2006 Intel Corporation. All rights reserved.\n");
\r
279 Routine Description:
\r
281 Print out usage information for Strip.
\r
294 printf ("\nUsage: %s InputFile OutputFile Pattern_String [Pattern_String ¡]\n\
\r
296 Pattern_String is of the format (note that the section name must be \n\
\r
297 enclosed within square brackets):\n\
\r
298 [section]FieldKey<op>Value [(FieldKey<op>Value) ¡] \n\
\r
299 The operator, <op>, must be one of the following: \n\
\r
300 '==' replace a field value with a new value \n\
\r
301 '+=' append a string at the end of original line \n\
\r
302 '-' prevent the line from applying any patterns \n\
\r
304 ModifyInf BuildRootFvFvMain.inf BuildRootFvFvMainEXP.inf \\ \n\
\r
305 [files]EFI_FILE_NAME+=.Org EFI_NUM_BLOCKS==0x20 \\ \n\
\r
306 [options]EFI_FILENAME==FcMainCompact.fv -DpsdSignature.dxe \n", UTILITY_NAME);
\r
317 Routine Description:
\r
319 GC_TODO: Add function description
\r
323 argc - GC_TODO: add argument description
\r
324 ] - GC_TODO: add argument description
\r
328 GC_TODO: add return values
\r
332 char LineBuffer[256];
\r
341 if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0) ||
\r
342 (strcmp(argv[1], "-?") == 0) || (strcmp(argv[1], "/?") == 0)) {
\r
347 if ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0)) {
\r
357 fpin = fopen (argv[1], "rb");
\r
359 printf ("Can't open input file!\r\n");
\r
363 fpout = fopen (argv[2], "wb");
\r
366 printf ("Can't create output file!\r\n");
\r
370 while (ReadLine (LineBuffer, fpin)) {
\r
371 ApplyPattern (LineBuffer, argv, argc);
\r
372 WriteLine (LineBuffer, fpout);
\r