]>
Commit | Line | Data |
---|---|---|
19eba4a7 | 1 | /*++\r |
2 | \r | |
ad1f8df0 | 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 | |
8 | \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 | |
19eba4a7 | 11 | \r |
12 | \r | |
13 | Module Name:\r | |
14 | \r | |
15 | ModifyInf.c\r | |
16 | \r | |
17 | Abstract:\r | |
18 | \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 | |
21 | \r | |
22 | --*/\r | |
23 | \r | |
24 | #include "stdio.h"\r | |
25 | #include "string.h"\r | |
26 | \r | |
a85cb24e | 27 | #define UTILITY_NAME "ModifyInf"\r |
28 | #define UTILITY_MAJOR_VERSION 1\r | |
29 | #define UTILITY_MINOR_VERSION 1\r | |
30 | \r | |
19eba4a7 | 31 | //\r |
32 | // Read a line into buffer including '\r\n'\r | |
33 | //\r | |
34 | int\r | |
35 | ReadLine (\r | |
36 | char *LineBuffer,\r | |
37 | FILE *fp\r | |
38 | )\r | |
39 | /*++\r | |
40 | \r | |
41 | Routine Description:\r | |
42 | \r | |
43 | GC_TODO: Add function description\r | |
44 | \r | |
45 | Arguments:\r | |
46 | \r | |
47 | LineBuffer - GC_TODO: add argument description\r | |
48 | fp - GC_TODO: add argument description\r | |
49 | \r | |
50 | Returns:\r | |
51 | \r | |
52 | GC_TODO: add return values\r | |
53 | \r | |
54 | --*/\r | |
55 | {\r | |
56 | int CharC;\r | |
57 | char *Line;\r | |
58 | \r | |
59 | Line = LineBuffer;\r | |
60 | \r | |
61 | while ((CharC = fgetc (fp)) != EOF) {\r | |
62 | *Line++ = (char) CharC;\r | |
63 | if (CharC == 0x0a) {\r | |
64 | break;\r | |
65 | }\r | |
66 | }\r | |
67 | \r | |
68 | *Line = 0;\r | |
69 | \r | |
70 | if (CharC == EOF) {\r | |
71 | return 0;\r | |
72 | } else {\r | |
73 | return 1;\r | |
74 | }\r | |
75 | \r | |
76 | }\r | |
77 | //\r | |
78 | // Write a line into output file\r | |
79 | //\r | |
80 | int\r | |
81 | WriteLine (\r | |
82 | char *Line,\r | |
83 | FILE *fp\r | |
84 | )\r | |
85 | /*++\r | |
86 | \r | |
87 | Routine Description:\r | |
88 | \r | |
89 | GC_TODO: Add function description\r | |
90 | \r | |
91 | Arguments:\r | |
92 | \r | |
93 | Line - GC_TODO: add argument description\r | |
94 | fp - GC_TODO: add argument description\r | |
95 | \r | |
96 | Returns:\r | |
97 | \r | |
98 | GC_TODO: add return values\r | |
99 | \r | |
100 | --*/\r | |
101 | {\r | |
102 | fwrite (Line, strlen (Line), 1, fp);\r | |
103 | return 0;\r | |
104 | }\r | |
105 | //\r | |
106 | // Apply patterns to a line\r | |
107 | // Currently there are 2 patterns to support\r | |
108 | // '==' replace a field value with a new value\r | |
109 | // '+=' append a string at the end of original line\r | |
110 | // '-' prevent the line from applying any patterns\r | |
111 | // it has the highest priority\r | |
112 | //\r | |
113 | int\r | |
114 | ApplyPattern (\r | |
115 | char *Line,\r | |
116 | char *argv[],\r | |
117 | int argc\r | |
118 | )\r | |
119 | /*++\r | |
120 | \r | |
121 | Routine Description:\r | |
122 | \r | |
123 | GC_TODO: Add function description\r | |
124 | \r | |
125 | Arguments:\r | |
126 | \r | |
127 | Line - GC_TODO: add argument description\r | |
128 | ] - GC_TODO: add argument description\r | |
129 | argc - GC_TODO: add argument description\r | |
130 | \r | |
131 | Returns:\r | |
132 | \r | |
133 | GC_TODO: add return values\r | |
134 | \r | |
135 | --*/\r | |
136 | {\r | |
137 | static char Section[256];\r | |
138 | char PatternBuffer[256];\r | |
139 | char *Pattern;\r | |
140 | char *Pattern1;\r | |
141 | char *Pattern2;\r | |
142 | int PatternNum;\r | |
143 | char *Ptr;\r | |
144 | \r | |
145 | Pattern = PatternBuffer;\r | |
146 | \r | |
147 | PatternNum = argc;\r | |
148 | \r | |
149 | //\r | |
150 | // For section field\r | |
151 | // record current scope section into static buffer\r | |
152 | //\r | |
153 | Ptr = Line;\r | |
154 | if (*Ptr == '[') {\r | |
155 | while (*Ptr != ']') {\r | |
156 | if (!(*Ptr++)) {\r | |
157 | return -1;\r | |
158 | }\r | |
159 | }\r | |
160 | \r | |
161 | strcpy (Section, Line);\r | |
162 | Section[Ptr - Line + 1] = 0;\r | |
163 | }\r | |
164 | //\r | |
165 | // Apply each pattern on the line\r | |
166 | //\r | |
167 | while (PatternNum-- > 3) {\r | |
168 | \r | |
169 | strcpy (Pattern, argv[PatternNum]);\r | |
170 | \r | |
171 | //\r | |
172 | // For pattern '-'\r | |
173 | // keep it unmodified by other patterns\r | |
174 | //\r | |
175 | if (*Pattern == '-') {\r | |
176 | if (strstr (Line, Pattern + 1)) {\r | |
177 | return 0;\r | |
178 | } else {\r | |
179 | continue;\r | |
180 | }\r | |
181 | }\r | |
182 | //\r | |
183 | // For other patterns\r | |
184 | // get its section at first if it has\r | |
185 | //\r | |
186 | if (*Pattern == '[') {\r | |
187 | if (strncmp (Section, Pattern, strlen (Section))) {\r | |
188 | //\r | |
189 | // This pattern can't be appied for current section\r | |
190 | //\r | |
191 | continue;\r | |
192 | }\r | |
193 | //\r | |
194 | // Strip the section field\r | |
195 | //\r | |
196 | while (*Pattern != ']') {\r | |
197 | if (!(*Pattern++)) {\r | |
198 | return -1;\r | |
199 | }\r | |
200 | }\r | |
201 | \r | |
202 | Pattern++;\r | |
203 | }\r | |
204 | //\r | |
205 | // Apply patterns\r | |
206 | //\r | |
207 | Pattern1 = strstr (Pattern, "==");\r | |
208 | Pattern2 = strstr (Pattern, "+=");\r | |
209 | if (Pattern1) {\r | |
210 | //\r | |
211 | // For pattern '=='\r | |
212 | // replace the field value with a new string\r | |
213 | //\r | |
214 | if (!strncmp (Line, Pattern, Pattern1 - Pattern)) {\r | |
215 | Pattern1 += 2;\r | |
216 | Ptr = strstr (Line, "=");\r | |
217 | if (!Ptr) {\r | |
218 | return -1;\r | |
219 | }\r | |
220 | \r | |
221 | while (*(++Ptr) == ' ')\r | |
222 | ;\r | |
223 | *Ptr = 0;\r | |
224 | strcat (Line, Pattern1);\r | |
225 | strcat (Line, "\r\n");\r | |
226 | }\r | |
227 | } else if (Pattern2) {\r | |
228 | //\r | |
229 | // For pattern '+='\r | |
230 | // append a string at end of the original string\r | |
231 | //\r | |
232 | if (!strncmp (Line, Pattern, Pattern2 - Pattern)) {\r | |
233 | Pattern2 += 2;\r | |
234 | Ptr = Line;\r | |
235 | while (*Ptr != 0x0D && *Ptr != 0x0A) {\r | |
236 | Ptr++;\r | |
237 | }\r | |
238 | \r | |
239 | *Ptr = 0;\r | |
240 | strcat (Line, Pattern2);\r | |
241 | strcat (Line, "\r\n");\r | |
242 | }\r | |
243 | }\r | |
244 | }\r | |
245 | \r | |
246 | return 0;\r | |
247 | }\r | |
248 | \r | |
a85cb24e | 249 | void \r |
66b23b95 | 250 | Version(\r |
19eba4a7 | 251 | void\r |
252 | )\r | |
253 | /*++\r | |
254 | \r | |
255 | Routine Description:\r | |
256 | \r | |
a85cb24e | 257 | Print out version information for Strip.\r |
19eba4a7 | 258 | \r |
259 | Arguments:\r | |
260 | \r | |
261 | None\r | |
a85cb24e | 262 | \r |
19eba4a7 | 263 | Returns:\r |
264 | \r | |
a85cb24e | 265 | None\r |
266 | \r | |
267 | --*/ \r | |
268 | {\r | |
269 | printf ("%s v%d.%d -EDK Modify fields in FV inf files.\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r | |
270 | printf ("Copyright (c) 2005-2006 Intel Corporation. All rights reserved.\n");\r | |
271 | }\r | |
19eba4a7 | 272 | \r |
a85cb24e | 273 | void \r |
f091efb3 | 274 | Usage(\r |
a85cb24e | 275 | void\r |
276 | )\r | |
277 | /*++\r | |
278 | \r | |
279 | Routine Description:\r | |
280 | \r | |
281 | Print out usage information for Strip.\r | |
282 | \r | |
283 | Arguments:\r | |
284 | \r | |
285 | None\r | |
286 | \r | |
287 | Returns:\r | |
288 | \r | |
289 | None\r | |
290 | \r | |
291 | --*/ \r | |
19eba4a7 | 292 | {\r |
66b23b95 | 293 | Version();\r |
f091efb3 | 294 | Content-type: text/html ]>