-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
60 lines (44 loc) · 968 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
52
53
54
55
56
57
58
59
60
#include <assert.h>
#include <stdio.h>
#include "table.h"
#include "relation.h"
extern char *top;
/* TODO: declare these elsewhere...
*/
int yyparse();
void yy_scan_string(char *);
int
main(int argc, char **argv) {
char *awk;
if (argc == 1) {
printf("USAGE: tsv-sql SELECT_STMT [FILE.tsv ...]\n");
return 1;
}
char *select_stmt = argv[1];
int i;
query qry;
table *tables = NULL;
table *tbl = NULL;
for (i = 2; i < argc; ++i) {
if (!tbl) {
tbl = new_table_from_path(argv[i]);
assert(tbl);
qry.tables = tbl;
}
else {
tbl->next = new_table_from_path(argv[i]);
assert(tbl->next);
tbl = tbl->next;
}
}
yy_scan_string(select_stmt);
return yyparse();
if ( 0 == yyparse() ) {
printf("[DEBUG] parses as: %s\n", top);
for (tbl = qry.tables; tbl; tbl = tbl->next) {
table_print(tbl, stdout);
}
} else {
fprintf(stderr, "[ERROR] parse failed\n");
}
}