/* 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")) {
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 {
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);
fputc('\n', out);
check_unclosed_conditionals();
close_input();
+ if (out != stdout)
+ fclose(out);
obstack_free(&input_obstack, NULL);
obstack_free(&pp_obstack, NULL);