]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Sample/Tools/Source/ModifyInf/ModifyInf.c
3 Copyright (c) 1999 - 2010, 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.
26 #define UTILITY_NAME "ModifyInf"
27 #define UTILITY_VERSION "v1.0"
29 // Read a line into buffer including '\r\n'
40 GC_TODO: Add function description
44 LineBuffer - GC_TODO: add argument description
45 fp - GC_TODO: add argument description
49 GC_TODO: add return values
58 while ((CharC
= fgetc (fp
)) != EOF
) {
59 *Line
++ = (char) CharC
;
75 // Write a line into output file
86 GC_TODO: Add function description
90 Line - GC_TODO: add argument description
91 fp - GC_TODO: add argument description
95 GC_TODO: add return values
99 fwrite (Line
, strlen (Line
), 1, fp
);
103 // Apply patterns to a line
104 // Currently there are 2 patterns to support
105 // '==' replace a field value with a new value
106 // '+=' append a string at the end of original line
107 // '-' prevent the line from applying any patterns
108 // it has the highest priority
120 GC_TODO: Add function description
124 Line - GC_TODO: add argument description
125 ] - GC_TODO: add argument description
126 argc - GC_TODO: add argument description
130 GC_TODO: add return values
134 static char Section
[256];
136 char PatternBuffer
[256];
143 Pattern
= PatternBuffer
;
149 // record current scope section into static buffer
153 while (*Ptr
!= ']') {
158 SectionLength
= Ptr
- Line
+ 1;
159 SectionLength
= SectionLength
> 255 ? 255 : SectionLength
;
160 strncpy (Section
, Line
, SectionLength
);
161 Section
[SectionLength
] = 0;
164 // Apply each pattern on the line
166 while (PatternNum
-- > 3) {
168 strcpy (Pattern
, argv
[PatternNum
]);
172 // keep it unmodified by other patterns
174 if (*Pattern
== '-') {
175 if (strstr (Line
, Pattern
+ 1)) {
182 // For other patterns
183 // get its section at first if it has
185 if (*Pattern
== '[') {
186 if (strncmp (Section
, Pattern
, strlen (Section
))) {
188 // This pattern can't be appied for current section
193 // Strip the section field
195 while (*Pattern
!= ']') {
206 Pattern1
= strstr (Pattern
, "==");
207 Pattern2
= strstr (Pattern
, "+=");
211 // replace the field value with a new string
213 if (!strncmp (Line
, Pattern
, Pattern1
- Pattern
)) {
215 Ptr
= strstr (Line
, "=");
220 while (*(++Ptr
) == ' ')
223 strcat (Line
, Pattern1
);
224 strcat (Line
, "\r\n");
226 } else if (Pattern2
) {
229 // append a string at end of the original string
231 if (!strncmp (Line
, Pattern
, Pattern2
- Pattern
)) {
234 while (*Ptr
!= 0x0D && *Ptr
!= 0x0A) {
239 strcat (Line
, Pattern2
);
240 strcat (Line
, "\r\n");
256 GC_TODO: Add function description
264 GC_TODO: add return values
269 const char *Str
[] = {
270 UTILITY_NAME
" "UTILITY_VERSION
" - Intel Modify INF File Utility",
271 " Copyright (C), 1999 - 2008 Intel Corporation",
273 #if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )
274 " Built from "UTILITY_BUILD
", project of "UTILITY_VENDOR
,
278 " "UTILITY_NAME
" SOURCE DEST [PATTERN]",
281 for (Index
= 0; Str
[Index
] != NULL
; Index
++) {
282 fprintf (stdout
, "%s\n", Str
[Index
]);
295 GC_TODO: Add function description
299 argc - GC_TODO: add argument description
300 ] - GC_TODO: add argument description
304 GC_TODO: add return values
308 char LineBuffer
[256];
317 fpin
= fopen (argv
[1], "rb");
319 printf ("Can't open input file!\r\n");
323 fpout
= fopen (argv
[2], "wb");
326 printf ("Can't create output file!\r\n");
330 while (ReadLine (LineBuffer
, fpin
)) {
331 ApplyPattern (LineBuffer
, argv
, argc
);
332 WriteLine (LineBuffer
, fpout
);