-
Notifications
You must be signed in to change notification settings - Fork 35
/
main.c
52 lines (40 loc) · 827 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "sql.tab.h"
#include "yyl.h"
#include "sql.lex.h"
#include "sql-parser.h"
extern char *filename;
int
main(int ac, char **av)
{
FILE *in_f;
struct psql_state *pstate;
if(ac > 1 && !strcmp(av[1], "-d")) {
yydebug = 1; ac--; av++; // TODO: move global into lib (layering issue)
}
pstate = psql_new();
if (!pstate)
abort();
if(ac > 1) {
if((in_f = fopen(av[1], "r")) == NULL) {
perror(av[1]);
exit(1);
}
filename = av[1];
} else {
filename = "(stdin)";
in_f = stdin;
}
psql_set_input(pstate, in_f);
int res = psql_parse(pstate);
psql_free(pstate);
if (!res) {
printf("{\"result\":true}\n");
return 0;
} else {
printf("{\"result\":false}\n");
return 1;
}
} /* main */