1 |
%{ |
2 |
/* |
3 |
* This SQL Lexer is copied from the O'Reilly Lex & Yacc book, 2nd Edition, |
4 |
* 1995, by John R. Levine, Tony Mason, and Doug Brown. It probably contains |
5 |
* words that we don't need for the Object Server, and will probably need |
6 |
* enhancements. I removed the DDL and non-query words, but I'm going to |
7 |
* leave in all other O'Reilly stuff unless it becomes real obvious that we |
8 |
* don't need it. |
9 |
* |
10 |
* Jeremy Hickerson, 5/8/2002 |
11 |
*/ |
12 |
#define LEX_SOURCE_FILE |
13 |
|
14 |
#include <string.h> |
15 |
#include "obj_srvr.h" |
16 |
#include "flexdef.h" |
17 |
|
18 |
#ifdef VMS |
19 |
#include <unixio.h> |
20 |
#endif |
21 |
|
22 |
#include <string.h> |
23 |
#include <stdlib.h> |
24 |
#include <unistd.h> |
25 |
#include <types.h> |
26 |
#include <socket.h> |
27 |
#include <in.h> |
28 |
#include <inet.h> |
29 |
#include <netdb.h> |
30 |
#include <stdio.h> |
31 |
#include <errno.h> |
32 |
#include <time.h> |
33 |
#include <timeb.h> |
34 |
|
35 |
#define bcopy(s,d,l) memcpy(d,s,l) |
36 |
#define bzero(d,l) memset(d,0,l) |
37 |
#define BUF_SIZE 2048 |
38 |
|
39 |
char buf[BUF_SIZE]; |
40 |
int sock; |
41 |
|
42 |
#include "obj_srvr_tab.h" |
43 |
|
44 |
int lineno = 1; |
45 |
char mode; |
46 |
|
47 |
void yyerror(char *s); |
48 |
void connect_to_oracle_obj_srvr(char *host, int port); |
49 |
|
50 |
/* macro to save the text of a SQL token */ |
51 |
#define SV save_str(yytext) |
52 |
|
53 |
/* macro to save the text and return a token */ |
54 |
#define TOK(name) { SV; token = name; return name; } |
55 |
|
56 |
/* read input through perl, since perl has access to oracle_obj_srvr socket */ |
57 |
/* (we connected to it in perl, because if we connect in C (here) then haven't |
58 |
figured out how to make perl see socket for output) */ |
59 |
#define YY_INPUT(buf,result,max_size) { \ |
60 |
strcpy(buf, call_perl_get_yyin(max_size) ); \ |
61 |
result = strlen(buf); \ |
62 |
} |
63 |
|
64 |
%} |
65 |
|
66 |
%s SQL |
67 |
%% |
68 |
|
69 |
/* EXEC[ \t]+SQL { BEGIN SQL; printf("SQL> "); start_save(); } */ |
70 |
SQL { |
71 |
|
72 |
BEGIN SQL; |
73 |
|
74 |
call_perl_send_yyout("SQL> "); |
75 |
|
76 |
if (mode == 'S') |
77 |
call_perl_send_yyout("\n"); |
78 |
|
79 |
start_save(); |
80 |
} |
81 |
|
82 |
QUIT { close(sock); exit(0); } |
83 |
|
84 |
/* literal keyword tokens */ |
85 |
<SQL>ALL TOK(ALL) |
86 |
<SQL>AND TOK(AND) |
87 |
<SQL>AVG TOK(AMMSC) |
88 |
<SQL>MIN TOK(AMMSC) |
89 |
<SQL>MAX TOK(AMMSC) |
90 |
<SQL>SUM TOK(AMMSC) |
91 |
<SQL>COUNT TOK(AMMSC) |
92 |
<SQL>ANY TOK(ANY) |
93 |
<SQL>AS TOK(AS) |
94 |
<SQL>ASC TOK(ASC) |
95 |
<SQL>AUTHORIZATION TOK(AUTHORIZATION) |
96 |
<SQL>BETWEEN TOK(BETWEEN) |
97 |
<SQL>BY TOK(BY) |
98 |
<SQL>CHAR(ACTER)? TOK(CHARACTER) |
99 |
<SQL>CHECK TOK(CHECK) |
100 |
<SQL>CLOSE TOK(CLOSE) |
101 |
<SQL>CONTINUE TOK(CONTINUE) |
102 |
<SQL>CURRENT TOK(CURRENT) |
103 |
<SQL>CURSOR TOK(CURSOR) |
104 |
<SQL>DECIMAL TOK(DECIMAL) |
105 |
<SQL>DECLARE TOK(DECLARE) |
106 |
<SQL>DEFAULT TOK(DEFAULT) |
107 |
<SQL>DESC TOK(DESC) |
108 |
<SQL>DISTINCT TOK(DISTINCT) |
109 |
<SQL>DOUBLE TOK(DOUBLE) |
110 |
<SQL>ESCAPE TOK(ESCAPE) |
111 |
<SQL>EXISTS TOK(EXISTS) |
112 |
<SQL>FETCH TOK(FETCH) |
113 |
<SQL>FLOAT TOK(FLOAT) |
114 |
<SQL>FOR TOK(FOR) |
115 |
<SQL>FOREIGN TOK(FOREIGN) |
116 |
<SQL>FOUND TOK(FOUND) |
117 |
<SQL>FROM TOK(FROM) |
118 |
<SQL>GO[ \t]*TO TOK(GOTO) |
119 |
<SQL>GROUP TOK(GROUP) |
120 |
<SQL>HAVING TOK(HAVING) |
121 |
<SQL>IN TOK(IN) |
122 |
<SQL>INDICATOR TOK(INDICATOR) |
123 |
<SQL>INT(EGER)? TOK(INTEGER) |
124 |
<SQL>INTO TOK(INTO) |
125 |
<SQL>IS TOK(IS) |
126 |
<SQL>KEY TOK(KEY) |
127 |
<SQL>LANGUAGE TOK(LANGUAGE) |
128 |
<SQL>LIKE TOK(LIKE) |
129 |
<SQL>NOT TOK(NOT) |
130 |
<SQL>NULL TOK(NULLX) |
131 |
<SQL>NUMERIC TOK(NUMERIC) |
132 |
<SQL>OF TOK(OF) |
133 |
<SQL>ON TOK(ON) |
134 |
<SQL>OPEN TOK(OPEN) |
135 |
<SQL>OPTION TOK(OPTION) |
136 |
<SQL>OR TOK(OR) |
137 |
<SQL>ORDER TOK(ORDER) |
138 |
<SQL>PRECISION TOK(PRECISION) |
139 |
<SQL>PRIMARY TOK(PRIMARY) |
140 |
<SQL>PRIVILEGES TOK(PRIVILEGES) |
141 |
<SQL>PROCEDURE TOK(PROCEDURE) |
142 |
<SQL>REAL TOK(REAL) |
143 |
<SQL>REFERENCES TOK(REFERENCES) |
144 |
<SQL>SCHEMA TOK(SCHEMA) |
145 |
<SQL>SELECT TOK(SELECT) |
146 |
<SQL>SMALLINT TOK(SMALLINT) |
147 |
<SQL>SOME TOK(SOME) |
148 |
<SQL>SQLCODE TOK(SQLCODE) |
149 |
<SQL>TO TOK(TO) |
150 |
<SQL>UNION TOK(UNION) |
151 |
<SQL>UNIQUE TOK(UNIQUE) |
152 |
<SQL>USER TOK(USER) |
153 |
<SQL>VALUES TOK(VALUES) |
154 |
<SQL>WHENEVER TOK(WHENEVER) |
155 |
<SQL>WHERE TOK(WHERE) |
156 |
<SQL>WITH TOK(WITH) |
157 |
<SQL>WORK TOK(WORK) |
158 |
|
159 |
|
160 |
|
161 |
/* punctuation */ |
162 |
<SQL>"=" TOK(COMP_EQ) |
163 |
<SQL>"<>" TOK(COMP_NE1) |
164 |
<SQL>"!=" TOK(COMP_NE2) |
165 |
<SQL>"<" TOK(COMP_LT) |
166 |
<SQL>">" TOK(COMP_GT) |
167 |
<SQL>"<=" TOK(COMP_LE) |
168 |
<SQL>">=" TOK(COMP_GE) |
169 |
|
170 |
<SQL>[-+*/:(),.;] TOK(yytext[0]) |
171 |
|
172 |
|
173 |
/* names */ |
174 |
<SQL>[A-Za-z][A-Za-z0-9_]* TOK(NAME) |
175 |
|
176 |
/* strings */ |
177 |
<SQL>'[^'\n]*' TOK(STRING) |
178 |
|
179 |
<SQL>'[^'\n]*$ { yyerror("Unterminated string"); } |
180 |
|
181 |
|
182 |
/* numbers */ |
183 |
<SQL>[0-9]+ | |
184 |
<SQL>[0-9]+"."[0-9]* | |
185 |
<SQL>"."[0-9]* TOK(INTNUM) |
186 |
|
187 |
<SQL>[0-9]+[eE][+-]?[0-9]+ | |
188 |
<SQL>[0-9]+"."[0-9]*[eE][+-]?[0-9]+ | |
189 |
<SQL>"."[0-9]*[eE][+-]?[0-9]+ TOK(APPROXNUM) |
190 |
|
191 |
|
192 |
/* whitespace */ |
193 |
<SQL>\n { save_str(" "); lineno++; } |
194 |
\n { save_str(" "); lineno++; } /* jh: non-SQL */ |
195 |
|
196 |
<SQL>[ \t\r]+ save_str(" "); /* whitespace */ |
197 |
|
198 |
<SQL>"--".* ; /* comment */ |
199 |
|
200 |
|
201 |
/* anything else */ |
202 |
. ; /* ignore */ |
203 |
|
204 |
%% |
205 |
|
206 |
|
207 |
void yyerror(char *s) { |
208 |
printf("%d: %s at %s\n", lineno, s, yytext); |
209 |
} |
210 |
|
211 |
|
212 |
/* leave SQL lexing mode */ |
213 |
un_sql() { |
214 |
BEGIN INITIAL; |
215 |
} |
216 |
|
217 |
|
218 |
main(int argc, char *argv[]) { |
219 |
|
220 |
|
221 |
if (argc < 4) { |
222 |
fprintf(stderr, "Usage: obj_srvr <db_uid> db_passwd> <mode: (I)nteractive/(S)erver> [host] [port]\n"); |
223 |
return; |
224 |
} |
225 |
|
226 |
char perlscript_to_embed[] = "obj_srvr.pl"; |
227 |
static char *perl_argv[5]; |
228 |
int i; |
229 |
|
230 |
perl_argv[0] = argv[0]; |
231 |
perl_argv[1] = perlscript_to_embed; |
232 |
perl_argv[2] = argv[1]; |
233 |
perl_argv[3] = argv[2]; |
234 |
|
235 |
/* start the perl interpreter and compile obj_srvr.pl */ |
236 |
if ( !strcmp(argv[3], "S") || !strcmp(argv[3], "s") ) { |
237 |
strcpy(perl_argv[2], ""); |
238 |
strcpy(perl_argv[3], ""); |
239 |
} |
240 |
embed_perl_obj_srvr(4, perl_argv, NULL); |
241 |
|
242 |
/* connect to "wrapper" server running on foreign tnslsnr */ |
243 |
if ( !strcmp(argv[3], "S") || !strcmp(argv[3], "s") ) { |
244 |
mode = 'S'; |
245 |
call_perl_connect2client(argv[4], argv[5]); |
246 |
} |
247 |
|
248 |
do { |
249 |
if (yyparse() ) { |
250 |
call_perl_send_yyout("\nQUIT\n"); |
251 |
break; |
252 |
} |
253 |
} while (!feof(yyin) ) ; |
254 |
|
255 |
end_perl(); |
256 |
} |
257 |
|