Mercurial > ~dholland > hg > tradcpp > index.cgi
comparison main.c @ 172:3e7e696fe558
Clean up the mess Joerg made of apply_builtin_macros().
author | David A. Holland |
---|---|
date | Fri, 12 Jun 2015 02:14:45 -0400 |
parents | 8cef6d7227a8 |
children | 44ea61019069 |
comparison
equal
deleted
inserted
replaced
171:5922e6ca6b80 | 172:3e7e696fe558 |
---|---|
193 array_setsize(&commandline_macros, 0); | 193 array_setsize(&commandline_macros, 0); |
194 } | 194 } |
195 | 195 |
196 static | 196 static |
197 void | 197 void |
198 apply_special_macros(unsigned *builtin_counter) | 198 apply_magic_macro(unsigned num, const char *name) |
199 { | 199 { |
200 struct place p; | 200 struct place p; |
201 | 201 |
202 place_setbuiltin(&p, ++(*builtin_counter)); | 202 place_setbuiltin(&p, num); |
203 macro_define_file(&p); | 203 macro_define_magic(&p, name); |
204 place_setbuiltin(&p, ++(*builtin_counter)); | |
205 macro_define_line(&p); | |
206 } | 204 } |
207 | 205 |
208 static | 206 static |
209 void | 207 void |
210 apply_builtin_macro(unsigned num, const char *name, const char *val) | 208 apply_builtin_macro(unsigned num, const char *name, const char *val) |
215 macro_define_plain(&p, name, &p, val); | 213 macro_define_plain(&p, name, &p, val); |
216 } | 214 } |
217 | 215 |
218 static | 216 static |
219 void | 217 void |
220 apply_builtin_macros(unsigned *builtin_counter) | 218 apply_builtin_macros(void) |
221 { | 219 { |
220 unsigned n = 1; | |
221 | |
222 apply_magic_macro(n++, "__FILE__"); | |
223 apply_magic_macro(n++, "__LINE__"); | |
224 | |
222 #ifdef CONFIG_OS | 225 #ifdef CONFIG_OS |
223 apply_builtin_macro(++(*builtin_counter), CONFIG_OS, "1"); | 226 apply_builtin_macro(n++, CONFIG_OS, "1"); |
224 #endif | 227 #endif |
225 #ifdef CONFIG_OS_2 | 228 #ifdef CONFIG_OS_2 |
226 apply_builtin_macro(++(*builtin_counter), CONFIG_OS_2, "1"); | 229 apply_builtin_macro(n++, CONFIG_OS_2, "1"); |
227 #endif | 230 #endif |
228 | 231 |
229 #ifdef CONFIG_CPU | 232 #ifdef CONFIG_CPU |
230 apply_builtin_macro(++(*builtin_counter), CONFIG_CPU, "1"); | 233 apply_builtin_macro(n++, CONFIG_CPU, "1"); |
231 #endif | 234 #endif |
232 #ifdef CONFIG_CPU_2 | 235 #ifdef CONFIG_CPU_2 |
233 apply_builtin_macro(++(*builtin_counter), CONFIG_CPU_2, "1"); | 236 apply_builtin_macro(n++, CONFIG_CPU_2, "1"); |
234 #endif | 237 #endif |
235 | 238 |
236 #ifdef CONFIG_SIZE | 239 #ifdef CONFIG_SIZE |
237 apply_builtin_macro(++(*builtin_counter), CONFIG_SIZE, "1"); | 240 apply_builtin_macro(n++, CONFIG_SIZE, "1"); |
238 #endif | 241 #endif |
239 #ifdef CONFIG_BINFMT | 242 #ifdef CONFIG_BINFMT |
240 apply_builtin_macro(++(*builtin_counter), CONFIG_BINFMT, "1"); | 243 apply_builtin_macro(n++, CONFIG_BINFMT, "1"); |
241 #endif | 244 #endif |
242 | 245 |
243 #ifdef CONFIG_COMPILER | 246 #ifdef CONFIG_COMPILER |
244 apply_builtin_macro(++(*builtin_counter), CONFIG_COMPILER, | 247 apply_builtin_macro(n++, CONFIG_COMPILER, VERSION_MAJOR); |
245 VERSION_MAJOR); | 248 apply_builtin_macro(n++, CONFIG_COMPILER_MINOR, VERSION_MINOR); |
246 apply_builtin_macro(++(*builtin_counter), CONFIG_COMPILER_MINOR, | 249 apply_builtin_macro(n++, "__VERSION__", VERSION_LONG); |
247 VERSION_MINOR); | |
248 apply_builtin_macro(++(*builtin_counter), "__VERSION__", VERSION_LONG); | |
249 #endif | 250 #endif |
250 } | 251 } |
251 | 252 |
252 //////////////////////////////////////////////////////////// | 253 //////////////////////////////////////////////////////////// |
253 // extra included files | 254 // extra included files |
1041 { | 1042 { |
1042 const char *progname; | 1043 const char *progname; |
1043 const char *inputfile = NULL; | 1044 const char *inputfile = NULL; |
1044 const char *outputfile = NULL; | 1045 const char *outputfile = NULL; |
1045 struct place cmdplace; | 1046 struct place cmdplace; |
1046 unsigned builtin_counter; | |
1047 int i; | 1047 int i; |
1048 | 1048 |
1049 progname = strrchr(argv[0], '/'); | 1049 progname = strrchr(argv[0], '/'); |
1050 progname = progname == NULL ? argv[0] : progname + 1; | 1050 progname = progname == NULL ? argv[0] : progname + 1; |
1051 complain_init(progname); | 1051 complain_init(progname); |
1087 } | 1087 } |
1088 | 1088 |
1089 mode.output_file = outputfile; | 1089 mode.output_file = outputfile; |
1090 | 1090 |
1091 loadincludepath(); | 1091 loadincludepath(); |
1092 | 1092 apply_builtin_macros(); |
1093 builtin_counter = 0; | |
1094 apply_special_macros(&builtin_counter); | |
1095 apply_builtin_macros(&builtin_counter); | |
1096 | |
1097 apply_commandline_macros(); | 1093 apply_commandline_macros(); |
1098 read_commandline_files(); | 1094 read_commandline_files(); |
1099 place_setnowhere(&cmdplace); | 1095 place_setnowhere(&cmdplace); |
1100 file_readabsolute(&cmdplace, inputfile); | 1096 file_readabsolute(&cmdplace, inputfile); |
1101 | 1097 |