]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/ModifyInf.c
3 Copyright (c) 1999 - 2002, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this 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.
18 It is a simple tool to modify some fields in a FV inf file
19 and output a new FV inf file.
27 // Read a line into buffer including '\r\n'
38 GC_TODO: Add function description
42 LineBuffer - GC_TODO: add argument description
43 fp - GC_TODO: add argument description
47 GC_TODO: add return values
56 while ((CharC
= fgetc (fp
)) != EOF
) {
57 *Line
++ = (char) CharC
;
73 // Write a line into output file
84 GC_TODO: Add function description
88 Line - GC_TODO: add argument description
89 fp - GC_TODO: add argument description
93 GC_TODO: add return values
97 fwrite (Line
, strlen (Line
), 1, fp
);
101 // Apply patterns to a line
102 // Currently there are 2 patterns to support
103 // '==' replace a field value with a new value
104 // '+=' append a string at the end of original line
105 // '-' prevent the line from applying any patterns
106 // it has the highest priority
118 GC_TODO: Add function description
122 Line - GC_TODO: add argument description
123 ] - GC_TODO: add argument description
124 argc - GC_TODO: add argument description
128 GC_TODO: add return values
132 static char Section
[256];
134 char PatternBuffer
[256];
141 Pattern
= PatternBuffer
;
147 // record current scope section into static buffer
151 while (*Ptr
!= ']') {
156 SectionLength
= Ptr
- Line
+ 1;
157 SectionLength
= SectionLength
> 255 ? 255 : SectionLength
;
158 strncpy (Section
, Line
, SectionLength
);
159 Section
[SectionLength
] = 0;
162 // Apply each pattern on the line
164 while (PatternNum
-- > 3) {
166 strcpy (Pattern
, argv
[PatternNum
]);
170 // keep it unmodified by other patterns
172 if (*Pattern
== '-') {
173 if (strstr (Line
, Pattern
+ 1)) {
180 // For other patterns
181 // get its section at first if it has
183 if (*Pattern
== '[') {
184 if (strncmp (Section
, Pattern
, strlen (Section
))) {
186 // This pattern can't be appied for current section
191 // Strip the section field
193 while (*Pattern
!= ']') {
204 Pattern1
= strstr (Pattern
, "==");
205 Pattern2
= strstr (Pattern
, "+=");
209 // replace the field value with a new string
211 if (!strncmp (Line
, Pattern
, Pattern1
- Pattern
)) {
213 Ptr
= strstr (Line
, "=");
218 while (*(++Ptr
) == ' ')
221 strcat (Line
, Pattern1
);
222 strcat (Line
, "\r\n");
224 } else if (Pattern2
) {
227 // append a string at end of the original string
229 if (!strncmp (Line
, Pattern
, Pattern2
- Pattern
)) {
232 while (*Ptr
!= 0x0D && *Ptr
!= 0x0A) {
237 strcat (Line
, Pattern2
);
238 strcat (Line
, "\r\n");
254 GC_TODO: Add function description
262 GC_TODO: add return values
266 printf ("ModifyInf InputFVInfFileName OutputFVInfFileName [Pattern strings]\r\n");
278 GC_TODO: Add function description
282 argc - GC_TODO: add argument description
283 ] - GC_TODO: add argument description
287 GC_TODO: add return values
291 char LineBuffer
[256];
300 fpin
= fopen (argv
[1], "rb");
302 printf ("Can't open input file!\r\n");
306 fpout
= fopen (argv
[2], "wb");
309 printf ("Can't create output file!\r\n");
313 while (ReadLine (LineBuffer
, fpin
)) {
314 ApplyPattern (LineBuffer
, argv
, argc
);
315 WriteLine (LineBuffer
, fpout
);