Parse after preprocessing
This commit is contained in:
parent
a87b938234
commit
bd220b9b14
29
src/main.c
29
src/main.c
@ -4,15 +4,25 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
void preprocess(const char * input_fname)
|
static char preprocessed_fname[] = "/tmp/cxlppXXXXXX";
|
||||||
|
static bool preprocessed_fname_created = false;
|
||||||
|
|
||||||
|
bool preprocess(const char * input_fname)
|
||||||
{
|
{
|
||||||
char fname[] = "/tmp/cxlppXXXXXX";
|
int fd = mkstemp(preprocessed_fname);
|
||||||
int fd = mkstemp(fname);
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
perror("mkstemp");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
preprocessed_fname_created = true;
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
{
|
{
|
||||||
perror("fork");
|
perror("fork");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
else if (pid == 0)
|
else if (pid == 0)
|
||||||
{
|
{
|
||||||
@ -24,13 +34,22 @@ void preprocess(const char * input_fname)
|
|||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
unlink(fname);
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
preprocess(argv[1]);
|
bool preprocess_successful = preprocess(argv[1]);
|
||||||
|
if (preprocess_successful)
|
||||||
|
{
|
||||||
|
parse(preprocessed_fname);
|
||||||
|
}
|
||||||
|
/* Clean up temporary files. */
|
||||||
|
if (preprocessed_fname_created)
|
||||||
|
{
|
||||||
|
unlink(preprocessed_fname);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user