-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfuncSqlTranslasi.h
199 lines (153 loc) · 6.83 KB
/
funcSqlTranslasi.h
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Bahasa Anak Indonesia untuk Komputer - BAIK
// Copyright Haris Hasanudin - 2005 - 2010
//
// Kupersembahkan untuk istriku tercinta Masako, anakku tersayang Takumi
// dan Tomoki serta seluruh putra putri Indonesia
#include "sqltrans01.h"
PARSING SQLgetlex( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
void SQLungetlex( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg);
PARSING SQLGetChar( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
PARSING SQLlex_ident( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
PARSING SQLlex_string( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
int SQLValLabel( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg, char *ident, int data, int flag );
SQL_VAL_LABEL *SQLMakeValLabelTree( char *ident, int data );
void SQLAddValLabelTree( SQL_VAL_LABEL *t, SQL_VAL_LABEL *n );
int SQLMakeAddValLabelTree( SQL_VAL_LABEL *t, char *ident, int data );
SQL_VAL_LABEL *SQLSearchValLabelTree( SQL_VAL_LABEL *t, char *ident );
void SQLDeleteValLabelTree( SQL_VAL_LABEL *t );
int SQLexpression( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
int SQLAndOr( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
int SQLNotFunc( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
int SQLCompare( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg);
int SQLAddSub( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
int SQLMulDiv( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
int SQLFactor( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg );
void SQLError( SQL_LEX_T sql_lex, SQL_S_ADDR sql_pg, const char *format, ... );
#include "sqltrans02.h"
VAL_LABEL funcSQLTranslasi ()
{
VAL_LABEL datx;
//SQL_LEX_T sql_lex;
//SQL_S_ADDR sql_pg;
char tmpMsg[MAX_STRING_LEN * 2];
VAL_LABEL valdat, tmpdat;
long idx=0; // array index
float tmp = 0.0;
// var list for class params
char class_tmpvar[MAX_STRING_LEN];
memset(&datx, '\0', sizeof(datx));
memset(&valdat, '\0', sizeof(valdat));
memset(&tmpdat, '\0', sizeof(tmpdat));
memset(&tmpMsg, '\0', sizeof(tmpMsg));
memset(&class_tmpvar, '\0', sizeof(class_tmpvar));
getlex();
/* printf("lex detail num : %d\n", lex.detail.num);
printf("lex type : %d\n", lex.type); */
if(lex.type == TYPE_NUM) {
Error("TRANS_SQL: masukan data salah");
} else if(lex.type == TYPE_DBL) {
Error("TRANS_SQL: masukan data salah");
} else if(lex.type == TYPE_STR) {
sprintf (datx.str, "%s", SQLInterpreter(lex.detail.string));
datx.datatype = 3;
} else if(lex.type == TYPE_ARRAY) {
if(strlen(lex.detail.array_str) > 0) {
strcpy(valdat.array_str, lex.detail.array_str);
getArrayName(lex.detail.array_str, (char *)&valdat.array_name);
getArrayIdx(lex.detail.array_str, (char *)&valdat.array_idx);
if(currentClass != NULL && strlen(currentClass) > 0) {
sprintf(class_tmpvar, "%s->%s", currentClass, valdat.array_name);
//printf("construct class var: %s\n", class_tmpvar);
memset(&valdat.array_name[0], '\0', sizeof(valdat.array_name));
strcpy(valdat.array_name, class_tmpvar);
if(!isdigit(valdat.array_idx[0])) {
memset(&class_tmpvar, '\0', sizeof(class_tmpvar));
sprintf(class_tmpvar, "%s->%s", currentClass, valdat.array_idx);
//printf("construct class var: %s\n", class_tmpvar);
memset(&valdat.array_idx[0], '\0', sizeof(valdat.array_idx));
strcpy(valdat.array_idx, class_tmpvar);
}
}
if(isdigit(valdat.array_idx[0])) {
/* printf("show digit\n"); */
idx = atoi (valdat.array_idx);
} else {
/* printf("show NOT digit\n"); */
/* Read index param */
tmpdat = ValLabel( valdat.array_idx, sub_deep, tmpdat, VAL_FLAG_SEARCH_R );
if(tmpdat.datatype==0)
idx = tmpdat.val;
else
Error("Untaian salah masukan");
}
/* read data */
valdat = ValLabel( valdat.array_name, sub_deep, valdat, VAL_FLAG_SEARCH_R );
sprintf(valdat.array_idx, "%li", idx);
if(idx < 0 || idx > MAX_ARRAY)
Error("ukuran Untaian tidak sesuai kapasitas");
if(valdat.datatype == 8 && valdat.array_s != '\0') {
if(valdat.array_s == '\0')
Error("TRANS_SQL: ukuran Untaian belum terdefinisi");
memset(&tmpMsg, '\0', sizeof(tmpMsg));
get_str_array(valdat, idx, (char *) &tmpMsg);
sprintf (datx.str, "%s", SQLInterpreter(tmpMsg));
datx.datatype = 3;
} else if (valdat.datatype == 10) {
sprintf (datx.str, "%s", SQLInterpreter(valdat.long_str[idx]));
datx.datatype = 3;
} else {
Error("TRANS_SQL: masukan data salah");
}
}
} else {
if(currentClass != NULL && strlen(currentClass) > 0) {
sprintf(class_tmpvar, "%s->%s", currentClass, lex.detail.ident);
//printf("construct class var: %s\n", class_tmpvar);
datx = ValLabel( class_tmpvar, sub_deep, datx, VAL_FLAG_SEARCH_R );
} else {
datx = ValLabel( lex.detail.ident, sub_deep, datx, VAL_FLAG_SEARCH_R );
}
// datx = ValLabel( lex.detail.ident, sub_deep, datx, VAL_FLAG_SEARCH_R );
if(datx.datatype == 3) {
sprintf (datx.str, "%s", SQLInterpreter(datx.str));
datx.datatype = 3;
} else {
Error("TRANS_SQL: masukan data salah");
}
}
// clear all sql translation
// memset(&sql_lex, '\0', sizeof(sql_lex));
// memset(&sql_pg, '\0', sizeof(sql_pg));
// printf("cleaning sql...\n");
// SQLValLabel( sql_lex, sql_pg, NULL, 0, SQL_VAL_FLAG_END );
// printf("cleaning sql ok\n");
if(valdat.filename != NULL)
free(valdat.filename);
if(valdat.folder != NULL)
free(valdat.folder);
if(valdat.filedata != NULL)
free(valdat.filedata);
if(valdat.long_str != NULL)
free(valdat.long_str);
if(valdat.left != NULL)
free(valdat.left);
if(valdat.right != NULL)
free(valdat.right);
if(valdat.pnext != NULL)
free(valdat.pnext);
if(tmpdat.filename != NULL)
free(tmpdat.filename);
if(tmpdat.folder != NULL)
free(tmpdat.folder);
if(tmpdat.filedata != NULL)
free(tmpdat.filedata);
if(tmpdat.long_str != NULL)
free(tmpdat.long_str);
if(tmpdat.left != NULL)
free(tmpdat.left);
if(tmpdat.right != NULL)
free(tmpdat.right);
if(tmpdat.pnext != NULL)
free(tmpdat.pnext);
return datx;
}