]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/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.
27 #define UTILITY_NAME "ModifyInf"
28 #define UTILITY_MAJOR_VERSION 1
29 #define UTILITY_MINOR_VERSION 1
32 // Read a line into buffer including '\r\n'
43 GC_TODO: Add function description
47 LineBuffer - GC_TODO: add argument description
48 fp - GC_TODO: add argument description
52 GC_TODO: add return values
61 while ((CharC
= fgetc (fp
)) != EOF
) {
62 *Line
++ = (char) CharC
;
78 // Write a line into output file
89 GC_TODO: Add function description
93 Line - GC_TODO: add argument description
94 fp - GC_TODO: add argument description
98 GC_TODO: add return values
102 fwrite (Line
, strlen (Line
), 1, fp
);
106 // Apply patterns to a line
107 // Currently there are 2 patterns to support
108 // '==' replace a field value with a new value
109 // '+=' append a string at the end of original line
110 // '-' prevent the line from applying any patterns
111 // it has the highest priority
123 GC_TODO: Add function description
127 Line - GC_TODO: add argument description
128 ] - GC_TODO: add argument description
129 argc - GC_TODO: add argument description
133 GC_TODO: add return values
137 static char Section
[256];
138 char PatternBuffer
[256];
145 Pattern
= PatternBuffer
;
151 // record current scope section into static buffer
155 while (*Ptr
!= ']') {
161 strcpy (Section
, Line
);
162 Section
[Ptr
- Line
+ 1] = 0;
165 // Apply each pattern on the line
167 while (PatternNum
-- > 3) {
169 strcpy (Pattern
, argv
[PatternNum
]);
173 // keep it unmodified by other patterns
175 if (*Pattern
== '-') {
176 if (strstr (Line
, Pattern
+ 1)) {
183 // For other patterns
184 // get its section at first if it has
186 if (*Pattern
== '[') {
187 if (strncmp (Section
, Pattern
, strlen (Section
))) {
189 // This pattern can't be appied for current section
194 // Strip the section field
196 while (*Pattern
!= ']') {
207 Pattern1
= strstr (Pattern
, "==");
208 Pattern2
= strstr (Pattern
, "+=");
212 // replace the field value with a new string
214 if (!strncmp (Line
, Pattern
, Pattern1
- Pattern
)) {
216 Ptr
= strstr (Line
, "=");
221 while (*(++Ptr
) == ' ')
224 strcat (Line
, Pattern1
);
225 strcat (Line
, "\r\n");
227 } else if (Pattern2
) {
230 // append a string at end of the original string
232 if (!strncmp (Line
, Pattern
, Pattern2
- Pattern
)) {
235 while (*Ptr
!= 0x0D && *Ptr
!= 0x0A) {
240 strcat (Line
, Pattern2
);
241 strcat (Line
, "\r\n");
257 Print out version information for Strip.
269 printf ("%s v%d.%d -EDK Modify fields in FV inf files.\n", UTILITY_NAME
, UTILITY_MAJOR_VERSION
, UTILITY_MINOR_VERSION
);
270 printf ("Copyright (c) 2005-2006 Intel Corporation. All rights reserved.\n");
281 Print out usage information for Strip.
294 printf ("\n Usage: %s InputFile OutputFile Pattern_String [Pattern_String ¡]\n\
296 Pattern_String is of the format (note that the section name must be \n\
297 enclosed within square brackets):\n\
298 [section]FieldKey<op>Value [(FieldKey<op>Value) ¡] \n\
299 The operator, <op>, must be one of the following: \n\
300 '==' replace a field value with a new value \n\
301 '+=' append a string at the end of original line \n\
302 '-' prevent the line from applying any patterns \n\
304 ModifyInf BuildRootFvFvMain.inf BuildRootFvFvMainEXP.inf \\ \n\
305 [files]EFI_FILE_NAME+=.Org EFI_NUM_BLOCKS==0x20 \\ \n\
306 [options]EFI_FILENAME==FcMainCompact.fv -DpsdSignature.dxe \n", UTILITY_NAME
);
319 GC_TODO: Add function description
323 argc - GC_TODO: add argument description
324 ] - GC_TODO: add argument description
328 GC_TODO: add return values
332 char LineBuffer
[256];
341 if ((strcmp(argv
[1], "-h") == 0) || (strcmp(argv
[1], "--help") == 0) ||
342 (strcmp(argv
[1], "-?") == 0) || (strcmp(argv
[1], "/?") == 0)) {
347 if ((strcmp(argv
[1], "-V") == 0) || (strcmp(argv
[1], "--version") == 0)) {
357 fpin
= fopen (argv
[1], "rb");
359 printf ("Can't open input file!\r\n");
363 fpout
= fopen (argv
[2], "wb");
366 printf ("Can't create output file!\r\n");
370 while (ReadLine (LineBuffer
, fpin
)) {
371 ApplyPattern (LineBuffer
, argv
, argc
);
372 WriteLine (LineBuffer
, fpout
);