projects
/
cparser
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2e75b09
)
preprocessor: implement -o in pptest
author
Matthias Braun
<matthias.braun@kit.edu>
Fri, 18 May 2012 21:15:11 +0000
(23:15 +0200)
committer
Matthias Braun
<matthias.braun@kit.edu>
Fri, 18 May 2012 23:55:27 +0000
(
01:55
+0200)
preprocessor.c
patch
|
blob
|
history
diff --git
a/preprocessor.c
b/preprocessor.c
index
3449063
..
4e1dc25
100644
(file)
--- a/
preprocessor.c
+++ b/
preprocessor.c
@@
-1833,6
+1833,7
@@
int pptest_main(int argc, char **argv)
/* simplistic commandline parser */
const char *filename = NULL;
/* simplistic commandline parser */
const char *filename = NULL;
+ const char *output = NULL;
for (int i = 1; i < argc; ++i) {
const char *opt = argv[i];
if (streq(opt, "-I")) {
for (int i = 1; i < argc; ++i) {
const char *opt = argv[i];
if (streq(opt, "-I")) {
@@
-1840,6
+1841,9
@@
int pptest_main(int argc, char **argv)
continue;
} else if (streq(opt, "-E")) {
/* ignore */
continue;
} else if (streq(opt, "-E")) {
/* ignore */
+ } else if (streq(opt, "-o")) {
+ output = argv[++i];
+ continue;
} else if (opt[0] == '-') {
fprintf(stderr, "Unknown option '%s'\n", opt);
} else {
} else if (opt[0] == '-') {
fprintf(stderr, "Unknown option '%s'\n", opt);
} else {
@@
-1853,7
+1857,15
@@
int pptest_main(int argc, char **argv)
return 1;
}
return 1;
}
- out = stdout;
+ if (output == NULL) {
+ out = stdout;
+ } else {
+ out = fopen(output, "w");
+ if (out == NULL) {
+ fprintf(stderr, "Couldn't open output '%s'\n", output);
+ return 1;
+ }
+ }
/* just here for gcc compatibility */
fprintf(out, "# 1 \"%s\"\n", filename);
/* just here for gcc compatibility */
fprintf(out, "# 1 \"%s\"\n", filename);
@@
-1922,6
+1934,8
@@
end_of_main_loop:
fputc('\n', out);
check_unclosed_conditionals();
close_input();
fputc('\n', out);
check_unclosed_conditionals();
close_input();
+ if (out != stdout)
+ fclose(out);
obstack_free(&input_obstack, NULL);
obstack_free(&pp_obstack, NULL);
obstack_free(&input_obstack, NULL);
obstack_free(&pp_obstack, NULL);