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
28 // Read a line into buffer including '\r\n'
\r
37 Routine Description:
\r
39 GC_TODO: Add function description
\r
43 LineBuffer - GC_TODO: add argument description
\r
44 fp - GC_TODO: add argument description
\r
48 GC_TODO: add return values
\r
57 while ((CharC = fgetc (fp)) != EOF) {
\r
58 *Line++ = (char) CharC;
\r
59 if (CharC == 0x0a) {
\r
74 // Write a line into output file
\r
83 Routine Description:
\r
85 GC_TODO: Add function description
\r
89 Line - GC_TODO: add argument description
\r
90 fp - GC_TODO: add argument description
\r
94 GC_TODO: add return values
\r
98 fwrite (Line, strlen (Line), 1, fp);
\r
102 // Apply patterns to a line
\r
103 // Currently there are 2 patterns to support
\r
104 // '==' replace a field value with a new value
\r
105 // '+=' append a string at the end of original line
\r
106 // '-' prevent the line from applying any patterns
\r
107 // it has the highest priority
\r
117 Routine Description:
\r
119 GC_TODO: Add function description
\r
123 Line - GC_TODO: add argument description
\r
124 ] - GC_TODO: add argument description
\r
125 argc - GC_TODO: add argument description
\r
129 GC_TODO: add return values
\r
133 static char Section[256];
\r
134 char PatternBuffer[256];
\r
141 Pattern = PatternBuffer;
\r
146 // For section field
\r
147 // record current scope section into static buffer
\r
151 while (*Ptr != ']') {
\r
157 strcpy (Section, Line);
\r
158 Section[Ptr - Line + 1] = 0;
\r
161 // Apply each pattern on the line
\r
163 while (PatternNum-- > 3) {
\r
165 strcpy (Pattern, argv[PatternNum]);
\r
169 // keep it unmodified by other patterns
\r
171 if (*Pattern == '-') {
\r
172 if (strstr (Line, Pattern + 1)) {
\r
179 // For other patterns
\r
180 // get its section at first if it has
\r
182 if (*Pattern == '[') {
\r
183 if (strncmp (Section, Pattern, strlen (Section))) {
\r
185 // This pattern can't be appied for current section
\r
190 // Strip the section field
\r
192 while (*Pattern != ']') {
\r
193 if (!(*Pattern++)) {
\r
203 Pattern1 = strstr (Pattern, "==");
\r
204 Pattern2 = strstr (Pattern, "+=");
\r
207 // For pattern '=='
\r
208 // replace the field value with a new string
\r
210 if (!strncmp (Line, Pattern, Pattern1 - Pattern)) {
\r
212 Ptr = strstr (Line, "=");
\r
217 while (*(++Ptr) == ' ')
\r
220 strcat (Line, Pattern1);
\r
221 strcat (Line, "\r\n");
\r
223 } else if (Pattern2) {
\r
225 // For pattern '+='
\r
226 // append a string at end of the original string
\r
228 if (!strncmp (Line, Pattern, Pattern2 - Pattern)) {
\r
231 while (*Ptr != 0x0D && *Ptr != 0x0A) {
\r
236 strcat (Line, Pattern2);
\r
237 strcat (Line, "\r\n");
\r
251 Routine Description:
\r
253 GC_TODO: Add function description
\r
261 GC_TODO: add return values
\r
265 printf ("ModifyInf InputFVInfFileName OutputFVInfFileName [Pattern strings]\r\n");
\r
275 Routine Description:
\r
277 GC_TODO: Add function description
\r
281 argc - GC_TODO: add argument description
\r
282 ] - GC_TODO: add argument description
\r
286 GC_TODO: add return values
\r
290 char LineBuffer[256];
\r
299 fpin = fopen (argv[1], "rb");
\r
301 printf ("Can't open input file!\r\n");
\r
305 fpout = fopen (argv[2], "wb");
\r
308 printf ("Can't create output file!\r\n");
\r
312 while (ReadLine (LineBuffer, fpin)) {
\r
313 ApplyPattern (LineBuffer, argv, argc);
\r
314 WriteLine (LineBuffer, fpout);
\r