:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / rpcrt4 / midl / midl.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <sys/wait.h>
6
7 extern FILE* yyin;
8 extern int yyparse(void);
9 extern int yydebug;
10 extern int nr_errors;
11 extern char* current_file;
12
13 int main(int argc, char* argv[])
14 {
15    int fd;
16    char* tempname;
17    int n, p, status;
18    char* args[9];
19    
20    if (argc == 1)
21      {
22         printf("Not enough arguments\n");
23         exit(1);
24      }
25    
26    tempname = tempnam(NULL, "midl");
27    
28    args[0] = strdup("/usr/bin/gcc");
29    args[1] = strdup("-x");
30    args[2] = strdup("c");
31    args[3] = strdup("-P");
32    args[4] = strdup("-E");
33    args[5] = strdup(argv[1]);
34    args[6] = strdup("-o");
35    args[7] = strdup(tempname);
36    args[8] = NULL;
37    
38    if ((n = fork()) == 0)
39      {
40         execv("/usr/bin/gcc", args);
41         perror("gcc");
42         exit(1);
43      }
44    else if (n == -1)
45      {
46         perror("midl");
47         exit(1);
48      }
49    
50    p = waitpid(n, &status, WUNTRACED);
51    if (p == -1 || p == 0 || !WIFEXITED(status))
52      {
53         perror("midl");
54         exit(1);
55      }
56    if (WEXITSTATUS(status) != 0)
57      {
58         printf("midl: the preprocessor %s failed\n");
59         exit(1);
60      }
61    
62 //   yydebug = 1;
63    
64    yyin = fopen(tempname, "r+b");
65    if (yyin == NULL)
66      {
67         perror(argv[1]);
68         exit(1);
69      }
70    
71    current_file = strdup(argv[1]);
72    
73    if (yyparse() != 0 || nr_errors > 0)
74      {
75         exit(1);
76      }
77    
78    unlink(tempname);
79 }