-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.c
379 lines (327 loc) · 11.2 KB
/
scanner.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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <malloc.h>
#include "compiler.h"
#include "vslanguage.h"
#include "y.tab.h"
#ifdef WIN32
#include "win32tools.h"
#include <io.h>
#include <fcntl.h>
#define strncasecmp _strnicmp
#endif
extern int yydebug;
extern void yyparse();
char *out_file_name;
int yyinit = 1;
int html_parse = 1;
int string_parse = 0;
int skip_newline = 0;
int LineNumber = 1;
#ifdef MTLCOMPILE
#define REM "!!REM"
#define REMEND "!!REMEND"
#define ECHO "!!ECHO"
#define ECHOEND "!!ECHOEND"
#define PREFIX "!!"
#define PREFIXCHAR '!'
#else
#define REM "%%REM"
#define REMEND "%%REMEND"
#define ECHO "%%ECHO"
#define ECHOEND "%%ECHOEND"
#define PREFIX "%%"
#define PREFIXCHAR '%'
#endif
/*----------------------------------------------------------------------------------*/
void ErrorMessage(char *Text)
{
/*
if (DebugOutput == 1) double
printf("<font color=\"#FF0000\">%s</font>",Text);
*/
}
/*----------------------------------------------------------------------------------*/
void yyerror()
{
if (DebugOutput == 1)
printf("<font color=\"#FF0000\"><blink><b>ERROR</b></blink></font>");
}
/*----------------------------------------------------------------------------------*/
#define TOK_MATCH(s1,token) if(!strncasecmp(buf+current,s1,strlen(s1))) { current+=strlen(s1); if (DebugOutput == 1) printf("<font color=\"#000099\">%s</font>", s1); begin=current; return token; }
#ifndef WIN32
#define end_of_file (current > buflength)
#else
#define end_of_file (current >= buflength)
#endif
int yylex()
{
while (1)
{
if (end_of_file)
return -1;
if (html_parse)
{
while (1)
{
if (buf[current] == '\n')
{
LineNumber++;
if (DebugOutput == 1) printf("<BR>");
}
if (buf[current] == PREFIXCHAR || end_of_file)
if (buf[current + 1] == PREFIXCHAR || end_of_file)
{
if ((buf[begin] == '\n') || (buf[begin] == '\r'))
begin++;
if ((buf[begin] == '\n') || (buf[begin] == '\r'))
begin++;
html_parse = 0;
yylval.string = malloc(current - begin + 1);
strncpy(yylval.string, buf + begin, current - begin);
yylval.string[current - begin] = 0;
begin = current;
return HTML;
}
if (DebugOutput == 1)
{
if (buf[current] == '<')
printf("<font color=#555555><i><");
else
if (buf[current] == '>')
printf("></i></font>");
else
printf("%c",buf[current]);
}
current++;
}
}
else
if (string_parse == 1)
{
begin = current;
while ((buf[current] != '"') || ((buf[current] == '"') && (buf[current-1] == '\\')))
{
if (buf[current] == '"')
{
int StartPoint = current;
while(buf[StartPoint] != '\0')
{
buf[StartPoint-1] = buf[StartPoint];
StartPoint++;
}
}
current++;
}
string_parse = 0;
yylval.string = malloc(current - begin + 1);
strncpy(yylval.string, buf + begin, current - begin);
yylval.string[current - begin] = 0;
if (DebugOutput == 1) printf("%s",yylval.string);
current++;
return STRING;
}
else
{
begin = current;
if (isdigit(buf[current]))
{
int isfloat = 0;
while (isdigit(buf[current]))
current++;
if (buf[current] == '.')
{
isfloat = 1;
current++;
while (isdigit(buf[current]))
current++;
}
yylval.string = malloc(current - begin + 1);
strncpy(yylval.string, buf + begin, current - begin);
yylval.string[current - begin] = 0;
if (DebugOutput == 1) printf("%s",yylval.string);
if (isfloat)
return FLOAT;
else
return NUMBER;
}
else
{
if(strncasecmp(buf+current,REM,strlen(REM))==0)
{
while(strncasecmp(buf+current,REMEND,strlen(REMEND)) != 0
&& (! end_of_file))
current++;
if (end_of_file)
return -1;
current +=8;
begin=current;
}
if(strncasecmp(buf+current,"ECHO",strlen("ECHO"))==0)
{
begin=current + 6;
while(strncasecmp(buf+current,"ECHOEND",strlen("ECHOEND")) != 0
&& (! end_of_file))
current++;
yylval.string = malloc(current - begin + 1);
strncpy(yylval.string, buf + begin, current - begin);
yylval.string[current - begin] = 0;
current +=9;
begin=current;
return HTML;
}
TOK_MATCH("NOT ", NOT);
TOK_MATCH("OR ", OR);
TOK_MATCH("AND ", AND);
if(strncasecmp(buf+current,PREFIX,strlen(PREFIX)) == 0)
{
current+=2;
begin=current;
TOK_MATCH("PRINTSTACK",PRINTSTACK);
TOK_MATCH("VAL_FOR", FOR_VALUE);
TOK_MATCH("FORVALUE", FOR_VALUE);
TOK_MATCH("IF", IF);
TOK_MATCH("ELSE", ELSE);
TOK_MATCH("ENDIF", ENDIF);
TOK_MATCH("FOR[", FOR);
TOK_MATCH("FOR [", FOR);
TOK_MATCH("NEXT", NEXT);
TOK_MATCH("WHILE", WHILE);
TOK_MATCH("WEND", WEND);
TOK_MATCH("REPEAT", REPEAT);
TOK_MATCH("UNTIL", UNTIL);
TOK_MATCH("CATALOGLIST", CATALOGLIST);
TOK_MATCH("CATALOGEND", CATALOGEND);
TOK_MATCH("CATALOG.[", CATALOG);
TOK_MATCH("CATALOGVALUE", CATALOGVALUE);
TOK_MATCH("CATALOGLINK", CATALOGLINK);
TOK_MATCH("PRODUCTLIST", PRODUCTLIST);
TOK_MATCH("PRODUCTEND", PRODUCTEND);
TOK_MATCH("PRODUCT.[", PRODUCT);
TOK_MATCH("PRODUCTVALUE", PRODUCTVALUE);
TOK_MATCH("PRODUCTLINK", PRODUCTLINK);
TOK_MATCH("BASKETLIST", BASKETLIST);
TOK_MATCH("BASKETEND", BASKETEND);
TOK_MATCH("BASKET.[", BASKET);
TOK_MATCH("BASKETVALUE", BASKETVALUE);
TOK_MATCH("PAYMENTLIST", PAYMENTLIST);
TOK_MATCH("PAYMENTEND", PAYMENTEND);
TOK_MATCH("PAYMENT.[", PAYMENT);
TOK_MATCH("PROMOTIONLIST", PROMOTIONLIST);
TOK_MATCH("PROMOTIONEND", PROMOTIONEND);
TOK_MATCH("PROMOTION.[", PROMOTION);
TOK_MATCH("PROMOTIONVALUE", PROMOTIONVALUE);
TOK_MATCH("RELEVANTLIST", RELEVANTLIST);
TOK_MATCH("RELEVANTEND", RELEVANTEND);
TOK_MATCH("RELEVANT.[", RELEVANT);
TOK_MATCH("RELEVANTVALUE", PROMOTIONVALUE);
TOK_MATCH("SHIPPINGCOST.[", SHIPPINGCOST);
TOK_MATCH("SETCOOKIE", SETCOOKIE);
TOK_MATCH("REDIRECT", REDIRECT);
TOK_MATCH("MIMETYPE", MIMETYPE);
TOK_MATCH("SENDFILE", SENDFILE);
TOK_MATCH("INCLUDEVSL", INCLUDEVSL);
TOK_MATCH("MODULE", INCLUDEVSL);
TOK_MATCH("", ESC);
}
if (isalnum(buf[current]) || buf[current] == '_')
{
while (isalnum(buf[current]) || buf[current] == '_')
current++;
yylval.string = malloc(current - begin + 1);
strncpy(yylval.string, buf + begin, current - begin);
yylval.string[current - begin] = 0;
if (DebugOutput == 1)
printf("<font color=\"#000000\">%s</font>", yylval.string);
return IDENT;
}
else
if (isspace(buf[current]))
{
#ifdef WIN32
if ((buf[current] == '\r') || (buf[current] == '\n'))
{
begin++;
#else
if (buf[current] == '\n')
{
begin++;
#endif
if (DebugOutput == 1) printf("<BR>\n");
LineNumber++;
if (!skip_newline)
html_parse = 1;
}
else
if (DebugOutput == 1) printf(" ");
}
else
{
begin++;
if (DebugOutput == 1)
{
printf("<font color=#000099><B>%c</B></font>",buf[current]);
}
return buf[current++];
}
}
}
current++;
}
}
/*----------------------------------------------------------------------------------*/
void main(int argc, char **argv)
{
#ifndef WIN32
FILE *inp;
#else
int fd;
#endif
char* Ptr;
if (argc < 2)
{
printf("%s\n",TEXT_VERSION);
exit(0);
}
if (argc == 3)
DebugOutput = 1;
else
DebugOutput = 0;
Magic = 0;
#ifndef WIN32
if (yyinit)
{
if ((inp = fopen(argv[1], "r")) == NULL)
exit(0);
buflength = fread(buf, 1, 64000, inp);
fclose(inp);
}
#else
if ((fd = _open(argv[1], O_RDONLY | _O_TEXT )) == NULL)
exit(0);
buflength = _read(fd,buf,64000);
_close(fd);
#endif
yyinit = 0;
strcpy(Path,argv[1]);
#ifdef WIN32
if ((Ptr = strrchr(Path,'\\')) != NULL)
{
*Ptr = '\0';
}
#else
if ((Ptr = strrchr(Path,'/')) != NULL)
{
*Ptr = '\0';
}
#endif
out_file_name = malloc(strlen(argv[1]) + 3);
strcpy(out_file_name, argv[1]);
strcat(out_file_name, ".p");
yydebug = 1;
yyparse();
free(out_file_name);
exit(1);
}