-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.c
More file actions
90 lines (76 loc) · 1.74 KB
/
module.c
File metadata and controls
90 lines (76 loc) · 1.74 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "module.h"
#include "parser.h"
#include "scanner.h"
int CPR_SUCCESSED(module_yy_extra *mod)
{
return (!mod->yyresult || mod->yyresult == 2) ? 1 : 0;
}
module_yy_extra *raw_parser(char *src)
{
module_yy_extra *extra;
core_yyscan_t scanner;
if (src == NULL)
{
fprintf(stderr, "input of raw_parser CANNOT be NULL");
exit(0);
}
scanner = module_scanner_create(src);
extra = (module_yy_extra *)malloc(sizeof(module_yy_extra));
extra->src = fmemopen(src, strlen(src) + 1, "r");
extra->yyresult = module_yyparse(scanner, extra);
module_scanner_destroy(scanner);
return extra;
}
char *
print_module(module_yy_extra *mod)
{
#if 0
char *sql = malloc(8192 * 3); // TODO : 8192 ????
memset(sql, 0, 8192 * 3);
char *order = malloc(8192);
switch (mod->cmdType)
{
case C_MatchReturn:
ReturnStmtPrint(mod->rt, sql, order); // print return clasue
// head += strlen(sql);
if (mod->exWhereExpr)
{
WhereStmtPrint(mod->wh, sql); // print where clause
// head += strlen(head);
}
MatchStmtPrint(mod->mch, sql); // print match clause
break;
case C_Create:
CreateStmtPrint(mod->crt, sql); // print return clasue
break;
case C_MatchDelete:
MatchStmtPrint(mod->mch, sql); // print match clause
DeleteStmtPrint(mod->dlt, sql);
break;
}
strcat(sql, order);
return sql;
#else
return NULL;
#endif
}
void delete_module(module_yy_extra *mod)
{
#if 0
if (mod->rt != NULL)
{
DELETE_RETURN_CLAUSE_NODE(mod->rt);
}
if (mod->exWhereExpr)
{
DELETE_WHERE_CLAUSE_NODE(mod->wh);
mod->exWhereExpr = false;
}
if (mod->mch != NULL) /* delete match clause node */
{
DELETE_MATCH_CLAUSE_NODE(mod->mch);
}
FCLOSE(mod->src);
FREE(mod);
#endif
}