-
Notifications
You must be signed in to change notification settings - Fork 35
/
lib.c
45 lines (34 loc) · 658 Bytes
/
lib.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <jansson.h>
#include "sql.tab.h"
#include "yyl.h"
#include "sql.lex.h"
#include "sql-parser.h"
struct psql_state *psql_new(void)
{
struct psql_state *st = calloc(1, sizeof(*st));
if (!st)
return NULL;
if (yylex_init_extra(st, &st->scanner)) {
free(st);
return NULL;
}
return st;
}
void psql_free(struct psql_state *st)
{
if (!st)
return;
yylex_destroy(st->scanner);
free(st);
}
void psql_set_input(struct psql_state *pstate, FILE *in_f)
{
yyset_in(in_f, pstate->scanner);
}
int psql_parse(struct psql_state *pstate)
{
return yyparse(pstate->scanner, pstate);
}