]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/ModifyInf/ModifyInf.c
3 Copyright (c) 1999-2006 Intel Corporation. All rights reserved
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 It is a simple tool to modify some fields in a FV inf file
20 and output a new FV inf file.
28 // Read a line into buffer including '\r\n'
39 GC_TODO: Add function description
43 LineBuffer - GC_TODO: add argument description
44 fp - GC_TODO: add argument description
48 GC_TODO: add return values
57 while ((CharC
= fgetc (fp
)) != EOF
) {
58 *Line
++ = (char) CharC
;
74 // Write a line into output file
85 GC_TODO: Add function description
89 Line - GC_TODO: add argument description
90 fp - GC_TODO: add argument description
94 GC_TODO: add return values
98 fwrite (Line
, strlen (Line
), 1, fp
);
102 // Apply patterns to a line
103 // Currently there are 2 patterns to support
104 // '==' replace a field value with a new value
105 // '+=' append a string at the end of original line
106 // '-' prevent the line from applying any patterns
107 // it has the highest priority
119 GC_TODO: Add function description
123 Line - GC_TODO: add argument description
124 ] - GC_TODO: add argument description
125 argc - GC_TODO: add argument description
129 GC_TODO: add return values
133 static char Section
[256];
134 char PatternBuffer
[256];
141 Pattern
= PatternBuffer
;
147 // record current scope section into static buffer
151 while (*Ptr
!= ']') {
157 strcpy (Section
, Line
);
158 Section
[Ptr
- Line
+ 1] = 0;
161 // Apply each pattern on the line
163 while (PatternNum
-- > 3) {
165 strcpy (Pattern
, argv
[PatternNum
]);
169 // keep it unmodified by other patterns
171 if (*Pattern
== '-') {
172 if (strstr (Line
, Pattern
+ 1)) {
179 // For other patterns
180 // get its section at first if it has
182 if (*Pattern
== '[') {
183 if (strncmp (Section
, Pattern
, strlen (Section
))) {
185 // This pattern can't be appied for current section
190 // Strip the section field
192 while (*Pattern
!= ']') {
203 Pattern1
= strstr (Pattern
, "==");
204 Pattern2
= strstr (Pattern
, "+=");
208 // replace the field value with a new string
210 if (!strncmp (Line
, Pattern
, Pattern1
- Pattern
)) {
212 Ptr
= strstr (Line
, "=");
217 while (*(++Ptr
) == ' ')
220 strcat (Line
, Pattern1
);
221 strcat (Line
, "\r\n");
223 } else if (Pattern2
) {
226 // append a string at end of the original string
228 if (!strncmp (Line
, Pattern
, Pattern2
- Pattern
)) {
231 while (*Ptr
!= 0x0D && *Ptr
!= 0x0A) {
236 strcat (Line
, Pattern2
);
237 strcat (Line
, "\r\n");
253 GC_TODO: Add function description
261 GC_TODO: add return values
265 printf ("ModifyInf InputFVInfFileName OutputFVInfFileName [Pattern strings]\r\n");
277 GC_TODO: Add function description
281 argc - GC_TODO: add argument description
282 ] - GC_TODO: add argument description
286 GC_TODO: add return values
290 char LineBuffer
[256];
299 fpin
= fopen (argv
[1], "rb");
301 printf ("Can't open input file!\r\n");
305 fpout
= fopen (argv
[2], "wb");
308 printf ("Can't create output file!\r\n");
312 while (ReadLine (LineBuffer
, fpin
)) {
313 ApplyPattern (LineBuffer
, argv
, argc
);
314 WriteLine (LineBuffer
, fpout
);