Add some temporary code to preprocess with gcc -E

This commit is contained in:
Josh Holtrop 2018-04-07 11:06:47 -04:00
parent 19c61a91fe
commit a87b938234

View File

@ -1,8 +1,36 @@
#include <stdio.h>
#include "parser.h"
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
void preprocess(const char * input_fname)
{
char fname[] = "/tmp/cxlppXXXXXX";
int fd = mkstemp(fname);
pid_t pid = fork();
if (pid < 0)
{
perror("fork");
}
else if (pid == 0)
{
dup2(fd, STDOUT_FILENO);
close(fd);
execlp("gcc", "gcc", "-x", "c", "-E", input_fname, NULL);
}
else
{
close(fd);
waitpid(pid, NULL, 0);
unlink(fname);
}
}
int main(int argc, char * argv[])
{
printf("coming soon...\n");
preprocess(argv[1]);
return 0;
}