6 static const char *cpp
= "cc";
7 static const char **options
;
8 static int noptions
= 2;
10 static void cc_option(const char *s
) {
11 options
= xrealloc(options
, ++noptions
* sizeof(char *));
12 options
[noptions
- 1] = s
;
15 int commandline(int argc
, char **argv
) {
19 while(n
< argc
&& strcmp(argv
[n
], "--")) {
20 if(!strcmp(argv
[n
], "--cpp") && n
+ 1 < argc
)
22 else if(!strcmp(argv
[n
], "--no-cpp"))
24 else if(!strcmp(argv
[n
], "--yydebug"))
26 else if(!strcmp(argv
[n
], "--flexdebug"))
37 struct external_declaration
*parse(const char *filename
) {
41 struct external_declaration
*tu
;
44 if(pipe(p
) < 0) fatal(errno
, "pipe");
45 if((pid
= fork()) < 0) fatal(errno
, "fork");
48 if(close(p
[0]) < 0) fatal(errno
, "close");
50 if(dup2(p
[1], 1) < 0) fatal(errno
, "dup2");
51 if(close(p
[1]) < 0) fatal(errno
, "close");
57 execvp(options
[0], (char **)options
);
58 fatal(errno
, "execve %s", cpp
);
60 if(close(p
[1]) < 0) fatal(errno
, "close");
61 if(!(fp
= fdopen(p
[0], "r"))) fatal(errno
, "fdopen");
63 if(!(fp
= fopen(filename
, "r"))) fatal(errno
, "opening %s", filename
);
67 if(fclose(fp
) < 0) fatal(errno
, "fclose");
69 while((r
= waitpid(pid
, &w
, 0)) < 0 && errno
== EINTR
)
71 if(r
< 0) fatal(errno
, "waitpid");
72 if(w
) fatal(0, "%s exited with status %d", cpp
, w
);
74 tu
= translation_unit
;