1 | %{ |
---|
2 | /**************************************** |
---|
3 | * Computer Algebra System SINGULAR * |
---|
4 | ****************************************/ |
---|
5 | /* $Id: libparse.l,v 1.44 2000-12-19 18:31:43 obachman Exp $ */ |
---|
6 | #include <stdio.h> |
---|
7 | #include <string.h> |
---|
8 | #include <stdlib.h> |
---|
9 | #include <ctype.h> |
---|
10 | #ifdef STANDALONE_PARSER |
---|
11 | #include "utils.h" |
---|
12 | #define HAVE_LIBPARSER |
---|
13 | #define YYLPDEBUG 1 |
---|
14 | #else |
---|
15 | #include "mod2.h" |
---|
16 | #include "subexpr.h" |
---|
17 | #include "grammar.h" |
---|
18 | #include "ipshell.h" |
---|
19 | #include "ipid.h" |
---|
20 | #include "tok.h" |
---|
21 | #include "febase.h" |
---|
22 | #include "omalloc.h" |
---|
23 | #endif |
---|
24 | #include "libparse.h" |
---|
25 | |
---|
26 | #ifdef HAVE_LIBPARSER |
---|
27 | #define YY_SKIP_YYWRAP |
---|
28 | |
---|
29 | typedef enum { LP_NONE, LP_INFO, LP_CATEGORY, LP_VERSION} lib_cmds; |
---|
30 | |
---|
31 | int libread(FILE* f, char* buf, int max_size); |
---|
32 | int current_pos(int i); |
---|
33 | void print_version(lp_modes mode, char *p); |
---|
34 | #ifdef HAVE_NAMESPACES |
---|
35 | void copy_string(lp_modes mode, idhdl pl); |
---|
36 | extern void piCleanUp(procinfov pi); |
---|
37 | #else /* HAVE_NAMESPACES */ |
---|
38 | void copy_string(lp_modes mode); |
---|
39 | #endif /* HAVE_NAMESPACES */ |
---|
40 | void make_version(char *p, int what); |
---|
41 | |
---|
42 | int brace1 = 0; /* { } */ |
---|
43 | int brace2 = 0; /* ( ) */ |
---|
44 | int brace3 = 0; /* [ ] */ |
---|
45 | int quote = 0; /* " */ |
---|
46 | int offset = 0; |
---|
47 | BOOLEAN p_static = FALSE; |
---|
48 | int old_state = 0; |
---|
49 | lib_cmds last_cmd = LP_NONE; |
---|
50 | |
---|
51 | char libnamebuf[128]; |
---|
52 | char *text_buffer=NULL; |
---|
53 | long string_start; |
---|
54 | |
---|
55 | char *yylp_buffer_start; |
---|
56 | int yylplineno = 1; |
---|
57 | int lpverbose = 0, check = 0; |
---|
58 | int texinfo_out = 0; |
---|
59 | int found_info=0, |
---|
60 | found_cat=0, |
---|
61 | found_version=0, |
---|
62 | found_oldhelp = 0, |
---|
63 | found_proc_in_proc = 0; |
---|
64 | |
---|
65 | char *yylp_errlist[]= { |
---|
66 | "", |
---|
67 | "missing close bracket ')' for proc definition in line %d.", /* 1 */ |
---|
68 | "missing close bracket ')' for procbody in line %d.", /* 2 */ |
---|
69 | "missing close bracket ']' for procbody in line %d.", /* 3 */ |
---|
70 | "too many ')' closed brackets in line %d.", /* 4 */ |
---|
71 | "too many ']' closed brackets in line %d.", /* 5 */ |
---|
72 | "missing close bracket ')' for example in line %d.", /* 6 */ |
---|
73 | "missing close bracket ']' for example in line %d.", /* 7 */ |
---|
74 | "cannot assign character '%c' in line %d to any group.", /* 8 */ |
---|
75 | "there must be a quote missing somewhere before line %d.", /* 9 */ |
---|
76 | "missing close bracket '}' at end of library in line %d.", /* 10 */ |
---|
77 | "missing close bracket ')' at end of library in line %d.", /* 11 */ |
---|
78 | "missing close bracket ']' at end of library in line %d.", /* 12 */ |
---|
79 | NULL |
---|
80 | }; |
---|
81 | int yylp_errno = 0; |
---|
82 | |
---|
83 | #ifdef __MWERKS__ |
---|
84 | #ifdef __cplusplus |
---|
85 | extern "C" { |
---|
86 | #endif |
---|
87 | long ftell(FILE *fp); |
---|
88 | #ifdef macintosh |
---|
89 | int fileno(FILE *stream); |
---|
90 | FILE *fdopen(int filedes, char *type); |
---|
91 | int isatty(int filedes); |
---|
92 | #else |
---|
93 | int _fileno(FILE *stream); |
---|
94 | FILE *_fdopen(int filedes, char *type); |
---|
95 | int _isatty(int filedes); |
---|
96 | #define fileno _fileno |
---|
97 | #define fdopen _fdopen |
---|
98 | #define isatty _isatty |
---|
99 | #endif /* macintosh */ |
---|
100 | #ifdef __cplusplus |
---|
101 | } |
---|
102 | #endif |
---|
103 | #endif |
---|
104 | |
---|
105 | #ifdef STANDALONE_PARSER |
---|
106 | procinfov pi; |
---|
107 | int category_out = 0; |
---|
108 | void printpi(procinfov pi); |
---|
109 | void pi_clear(procinfov pi); |
---|
110 | extern "C" { |
---|
111 | int yylpwrap(); |
---|
112 | } |
---|
113 | void main_init(int argc, char *argv[]); |
---|
114 | void main_result(char *libname); |
---|
115 | #else /* STANDALONE_PARSER */ |
---|
116 | idhdl h0; |
---|
117 | #ifdef HAVE_NAMESPACES |
---|
118 | idhdl h_top; |
---|
119 | extern namehdl namespaceroot; |
---|
120 | #endif /* HAVE_NAMESPACES */ |
---|
121 | #define pi IDPROC(h0) |
---|
122 | extern "C" |
---|
123 | { |
---|
124 | int yylpwrap(); |
---|
125 | } |
---|
126 | extern libstackv library_stack; |
---|
127 | #endif /* STANDALONE_PARSER */ |
---|
128 | |
---|
129 | static unsigned long help_chksum; |
---|
130 | |
---|
131 | #define SET_DEF_END(mode, pi, p) \ |
---|
132 | if ( mode == LOAD_LIB) pi->data.s.def_end = p; |
---|
133 | #define SET_HELP_START(mode, pi, p) \ |
---|
134 | if ( mode == LOAD_LIB) {pi->data.s.help_start = p; help_chksum = 0;} |
---|
135 | #define SET_HELP_END(mode, pi, p) \ |
---|
136 | if ( mode == LOAD_LIB) {pi->data.s.help_end = p; \ |
---|
137 | pi->data.s.help_chksum = help_chksum;} |
---|
138 | |
---|
139 | #define SET_BODY_START(mode, pi, l, p) \ |
---|
140 | if ( mode == LOAD_LIB) \ |
---|
141 | { \ |
---|
142 | pi->data.s.body_lineno = l; \ |
---|
143 | pi->data.s.body_start = p; \ |
---|
144 | } |
---|
145 | #define SET_BODY_END(mode, pi, p) \ |
---|
146 | if ( mode == LOAD_LIB) \ |
---|
147 | { \ |
---|
148 | pi->data.s.body_end = p-1; \ |
---|
149 | pi->data.s.proc_end = p-1; \ |
---|
150 | } |
---|
151 | |
---|
152 | #define SET_EXAMPLE_START(mode, pi, l, p) \ |
---|
153 | if ( mode == LOAD_LIB) \ |
---|
154 | { \ |
---|
155 | pi->data.s.example_lineno = l; \ |
---|
156 | pi->data.s.example_start = p; \ |
---|
157 | } |
---|
158 | #define SET_PROC_END(mode, pi, p) \ |
---|
159 | if ( mode == LOAD_LIB) \ |
---|
160 | { \ |
---|
161 | pi->data.s.proc_end = p-1; \ |
---|
162 | if(pi->data.s.body_end==0) \ |
---|
163 | pi->data.s.body_end = p-1; \ |
---|
164 | } |
---|
165 | |
---|
166 | #define ROTATE_RIGHT(c) if ((c) & 01) (c) = ((c) >>1) + 0x8000; else (c) >>= 1; |
---|
167 | #define IncrCheckSum(c) \ |
---|
168 | do \ |
---|
169 | { \ |
---|
170 | ROTATE_RIGHT(help_chksum); \ |
---|
171 | help_chksum += c; \ |
---|
172 | help_chksum &= 0xffff; \ |
---|
173 | } \ |
---|
174 | while(0) |
---|
175 | |
---|
176 | #undef YY_DECL |
---|
177 | #ifdef HAVE_NAMESPACES |
---|
178 | #define YY_DECL int yylex(char *newlib, char *libfile, \ |
---|
179 | lib_style_types *lib_style, \ |
---|
180 | idhdl pl, BOOLEAN autoexport, lp_modes mode) |
---|
181 | #else /* HAVE_NAMESPACES */ |
---|
182 | #define YY_DECL int yylex(char *newlib, char *libfile, \ |
---|
183 | lib_style_types *lib_style, \ |
---|
184 | lp_modes mode) |
---|
185 | #endif /* HAVE_NAMESPACES */ |
---|
186 | |
---|
187 | #undef YY_INPUT |
---|
188 | #define YY_INPUT(buf,result,max_size) \ |
---|
189 | if ( ((result = libread( (yyin), (char *) buf, max_size )) < 0 ) \ |
---|
190 | && ferror( yyin ) ) \ |
---|
191 | YY_FATAL_ERROR( "read in flex scanner failed" ); |
---|
192 | |
---|
193 | #define YY_USER_INIT { \ |
---|
194 | BEGIN(header); \ |
---|
195 | yylplineno = 1; \ |
---|
196 | yylp_errno = 0; \ |
---|
197 | *lib_style = OLD_LIBSTYLE; \ |
---|
198 | strcpy(libnamebuf,"(**unknown version**)"); \ |
---|
199 | } |
---|
200 | |
---|
201 | #if 0 |
---|
202 | <pbody>proc[ \t]+{name} { |
---|
203 | printf("MISSING: PROC-cmd found. ERROR!\n"); } |
---|
204 | <pbody>example[ \t]*\n { |
---|
205 | yylplineno++; |
---|
206 | printf("MISSING: EXAMPLE-cmd found. ERROR!\n"); } |
---|
207 | info=+"\"" { |
---|
208 | #endif |
---|
209 | |
---|
210 | %} |
---|
211 | |
---|
212 | digit [0-9] |
---|
213 | letter [@a-zA-Z\'] |
---|
214 | name ({letter}({letter}*{digit}*_*)*|_) |
---|
215 | varname ({letter}({letter}*{digit}*_*\(\))*|_|#) |
---|
216 | letters ({letter}|{digit}|[_./#%^*:,]) |
---|
217 | string ({letters}*) |
---|
218 | comment [\/][\/] |
---|
219 | dolar [$] |
---|
220 | nls [\n\r] |
---|
221 | symbols [~!@#$%^&*()_+-=\\\|\[\];:,<.>/\?\' \t\~\`] |
---|
222 | asymbols ({symbols}|[{}]) |
---|
223 | bsymbols ({symbols}|{escbrack}|[}]) |
---|
224 | aletters ({letter}|{digit}|{asymbols}|{dolar}|{escquote}|{nls}) |
---|
225 | bletters ({letter}|{digit}|{bsymbols}|{dolar}|{quote}|{nls}) |
---|
226 | cletters ({letter}|{digit}|{asymbols}|{dolar}|{quote}) |
---|
227 | strings ({aletters}*) |
---|
228 | escstrings ({bletters}*) |
---|
229 | fstring ({cletters}*) |
---|
230 | param ({name}+{tos}+{varname}) |
---|
231 | parameters ({param}(,{param})*) |
---|
232 | paramlist ("("{parameters}")") |
---|
233 | quote [\"] |
---|
234 | escquote (\\\") |
---|
235 | escbrack (\\\{) |
---|
236 | tnl ([ \t\n]*) |
---|
237 | eos ({quote}+{tnl}+"{") |
---|
238 | tos ([ \t]*) |
---|
239 | eq ([ \t]*+=[ \t]*) |
---|
240 | eqnl ([ \t\n]*+=[ \t\n]*) |
---|
241 | |
---|
242 | /* %start START */ |
---|
243 | |
---|
244 | %x header |
---|
245 | %x help |
---|
246 | %x libcmd |
---|
247 | %x libcmd2 |
---|
248 | %x pdef |
---|
249 | %x phead |
---|
250 | %x poldhelp |
---|
251 | %x phelp |
---|
252 | %x pbody |
---|
253 | %x pstr |
---|
254 | %x pexample |
---|
255 | %x pestr |
---|
256 | %x string |
---|
257 | %x comment |
---|
258 | %x info |
---|
259 | %x category |
---|
260 | %x version |
---|
261 | |
---|
262 | %% |
---|
263 | (\/\/[^\n]*)|(^#![^\n]*)|([ \t]) { } |
---|
264 | \/\/* { old_state = YYSTATE; BEGIN(comment); } |
---|
265 | |
---|
266 | (info+{eqnl}+{quote}+{strings}+{quote}) { |
---|
267 | yyless(4); old_state = YYSTATE; BEGIN(info); |
---|
268 | } |
---|
269 | (category+{eqnl}+{quote}+{strings}+{quote}) { |
---|
270 | yyless(8); old_state = YYSTATE; BEGIN(category); |
---|
271 | } |
---|
272 | (version+{eqnl}+{quote}+{strings}+{quote}) { |
---|
273 | found_version++; |
---|
274 | if ( mode != GET_INFO ) |
---|
275 | { |
---|
276 | make_version(yytext,1); |
---|
277 | #ifdef STANDALONE_PARSER |
---|
278 | if (texinfo_out) |
---|
279 | { |
---|
280 | char *c = libnamebuf; |
---|
281 | printf("$version = \""); |
---|
282 | while (*c != '\0') |
---|
283 | { |
---|
284 | if (*c == '$' || *c == '@') putchar('\\'); |
---|
285 | if (*c != '\r') putchar(*c); |
---|
286 | if (*c == '\\') |
---|
287 | { |
---|
288 | c++; |
---|
289 | if (*c != '"') putchar('\\'); |
---|
290 | } |
---|
291 | else |
---|
292 | c++; |
---|
293 | } |
---|
294 | printf("\";\n"); |
---|
295 | } |
---|
296 | else if (!category_out) |
---|
297 | printf("Version:%s;\n", libnamebuf); |
---|
298 | #else |
---|
299 | #ifdef HAVE_NAMESPACES |
---|
300 | h0 = enterid( omStrDup("version"), myynest, STRING_CMD, |
---|
301 | &IDPACKAGE(pl)->idroot, FALSE ); |
---|
302 | if (h0!=NULL) |
---|
303 | { |
---|
304 | IDSTRING(h0) = omStrDup(libnamebuf); |
---|
305 | } |
---|
306 | #else /* HAVE_NAMESPACES */ |
---|
307 | if (text_buffer!=NULL) omFree((ADDRESS)text_buffer); |
---|
308 | text_buffer = omStrDup(libnamebuf); |
---|
309 | omMarkAsStaticAddr(text_buffer); |
---|
310 | #endif /* HAVE_NAMESPACES */ |
---|
311 | #endif |
---|
312 | } |
---|
313 | } |
---|
314 | |
---|
315 | static { p_static=TRUE; } |
---|
316 | |
---|
317 | (proc[ \t]+{name})|([ \t]proc[ \t]+{name}) { |
---|
318 | char proc[256]; |
---|
319 | BEGIN(pdef); |
---|
320 | found_proc_in_proc = 0; |
---|
321 | proc[0]='\0'; |
---|
322 | sscanf( yytext, "%*[^p]proc %s", proc); |
---|
323 | if(strlen(proc)<1) sscanf( yytext, "proc %s", proc); |
---|
324 | #if YYLPDEBUG > 1 |
---|
325 | printf("Newlib:%s\n", newlib); |
---|
326 | #endif |
---|
327 | #ifdef STANDALONE_PARSER |
---|
328 | if ( pi != NULL ) |
---|
329 | { |
---|
330 | printpi(pi); |
---|
331 | pi_clear(pi); |
---|
332 | } |
---|
333 | pi = (procinfo *)malloc(sizeof(procinfo)); |
---|
334 | iiInitSingularProcinfo(pi, newlib, proc, yylplineno, |
---|
335 | current_pos(0), p_static); |
---|
336 | #else STANDALONE_PARSER |
---|
337 | if( mode == LOAD_LIB) |
---|
338 | { |
---|
339 | #ifdef HAVE_NAMESPACES |
---|
340 | h0 = enterid( omStrDup(proc), 0 /*myynest*/, PROC_CMD, |
---|
341 | &IDPACKAGE(pl)->idroot, TRUE); |
---|
342 | if(!p_static && autoexport) |
---|
343 | { |
---|
344 | namespaceroot->push( NSPACK(namespaceroot->root) ,""); |
---|
345 | h_top = enterid( omStrDup(proc), myynest, PROC_CMD, |
---|
346 | &NSROOT(namespaceroot->root), FALSE ); |
---|
347 | namespaceroot->pop(); |
---|
348 | } |
---|
349 | #else /* HAVE_NAMESPACES */ |
---|
350 | h0 = enterid( omStrDup(proc), 0 /*myynest*/, PROC_CMD, |
---|
351 | &idroot, TRUE ); |
---|
352 | #endif /* HAVE_NAMESPACES */ |
---|
353 | if (h0!=NULL) |
---|
354 | { |
---|
355 | iiInitSingularProcinfo(IDPROC(h0), newlib, proc, |
---|
356 | yylplineno, current_pos(0),p_static); |
---|
357 | #ifdef HAVE_NAMESPACES |
---|
358 | if (!p_static && h_top != NULL && autoexport) |
---|
359 | { |
---|
360 | if(IDPROC(h_top)!=NULL) piCleanUp((procinfo *)IDPROC(h_top)); |
---|
361 | IDPROC(h_top)=IDPROC(h0); |
---|
362 | IDPROC(h_top)->ref++; |
---|
363 | } |
---|
364 | #endif /* HAVE_NAMESPACES */ |
---|
365 | if (BVERBOSE(V_LOAD_PROC)) |
---|
366 | Warn( " proc '%s' registered", proc ); |
---|
367 | } |
---|
368 | #endif STANDALONE_PARSER |
---|
369 | SET_DEF_END(mode, pi, current_pos(yyleng+1)); |
---|
370 | #if YYLPDEBUG |
---|
371 | if(lpverbose) |
---|
372 | { |
---|
373 | printf("// PROCEDURE '%s' status: %s, ", proc, |
---|
374 | p_static ? "local" : "global"); |
---|
375 | printf("starting at line %d,%d: definition end: %d (%d).\n", |
---|
376 | yylplineno, current_pos(0), (int)pi->data.s.def_end, brace1); |
---|
377 | } |
---|
378 | #endif |
---|
379 | p_static=FALSE; |
---|
380 | #ifndef STANDALONE_PARSER |
---|
381 | } |
---|
382 | #endif STANDALONE_PARSER |
---|
383 | } |
---|
384 | example { |
---|
385 | BEGIN(pexample); |
---|
386 | SET_EXAMPLE_START(mode, pi, yylplineno, current_pos(0)); |
---|
387 | #if YYLPDEBUG |
---|
388 | if(lpverbose) |
---|
389 | { |
---|
390 | printf("// EXAMPLE at line %d,%d (%d)\n", yylplineno, |
---|
391 | current_pos(0), brace1); |
---|
392 | } |
---|
393 | #endif |
---|
394 | } |
---|
395 | |
---|
396 | LIB[ \t]+"\"" { quote++; |
---|
397 | BEGIN(libcmd); |
---|
398 | } |
---|
399 | |
---|
400 | LIB[ \t]*"(\"" { quote++; brace2++; |
---|
401 | BEGIN(libcmd2); |
---|
402 | } |
---|
403 | |
---|
404 | <header>({comment}+{tos}+{dolar}+Id:+{string}+[^\n]*)|({comment}+{tos}+{dolar}+Header:+{string}+[^\n]*) { |
---|
405 | make_version(yytext, 0); |
---|
406 | #if YYLPDEBUG > 1 |
---|
407 | printf("+(id)HEAD:%s\n", yytext); |
---|
408 | #endif |
---|
409 | } |
---|
410 | <header>(^{comment}+[^\n]*) { |
---|
411 | #if YYLPDEBUG |
---|
412 | printf("+(cmt)HEAD:%s\n", yytext); |
---|
413 | #endif |
---|
414 | } |
---|
415 | <header>(^#![^\n]*) { |
---|
416 | #if YYLPDEBUG > 1 |
---|
417 | printf("-HEAD:%s\n", yytext); |
---|
418 | #endif |
---|
419 | } |
---|
420 | <header>^proc\ { yyless(0); |
---|
421 | BEGIN(INITIAL); |
---|
422 | yymore(); |
---|
423 | } |
---|
424 | <header>(info+{eqnl}+{quote})|(version+{eqnl}+{quote})|(category+{eqnl}+{quote}) { |
---|
425 | yyless(0); |
---|
426 | *lib_style = NEW_LIBSTYLE; |
---|
427 | BEGIN(INITIAL); |
---|
428 | yymore(); |
---|
429 | } |
---|
430 | |
---|
431 | <header>^LIB[ \t]+"\"" { quote++; |
---|
432 | BEGIN(libcmd); |
---|
433 | } |
---|
434 | <header>^LIB[ \t]+"(\"" { quote++; brace2++; |
---|
435 | BEGIN(libcmd2); |
---|
436 | } |
---|
437 | <header>\n { yylplineno++; } |
---|
438 | <header>. { |
---|
439 | #if YYLPDEBUG > 1 |
---|
440 | printf(" HEAD:%s\n", yytext); |
---|
441 | #endif |
---|
442 | yyless(0); |
---|
443 | BEGIN(help); |
---|
444 | } |
---|
445 | <help>(^{comment}+[^\n]*) { |
---|
446 | #if YYLPDEBUG > 1 |
---|
447 | printf(" HELP:%s\n", yytext); |
---|
448 | #endif |
---|
449 | BEGIN(INITIAL); } |
---|
450 | <help>(^#![^\n]*) { |
---|
451 | #if YYLPDEBUG > 1 |
---|
452 | printf(" HELP:%s\n", yytext); |
---|
453 | #endif |
---|
454 | BEGIN(INITIAL); |
---|
455 | } |
---|
456 | <help>(info+{eqnl}+{quote})|(version+{eqnl}+{quote})|(category+{eqnl}+{quote}) { |
---|
457 | yyless(0); |
---|
458 | *lib_style = NEW_LIBSTYLE; |
---|
459 | BEGIN(INITIAL); |
---|
460 | yymore(); |
---|
461 | } |
---|
462 | <help>^proc\ { |
---|
463 | yyless(0); |
---|
464 | //printf("2) proc found.\n"); |
---|
465 | BEGIN(INITIAL); |
---|
466 | yymore(); |
---|
467 | } |
---|
468 | <help>^LIB[ \t]+"\"" { quote++; |
---|
469 | BEGIN(libcmd); |
---|
470 | } |
---|
471 | <help>^LIB[ \t]+"(\"" { quote++; brace2++; |
---|
472 | BEGIN(libcmd2); |
---|
473 | } |
---|
474 | |
---|
475 | <help>\n { yylplineno++; } |
---|
476 | <help>({tos}|{comment}+{fstring}) { |
---|
477 | #if YYLPDEBUG |
---|
478 | if(lpverbose>2) printf("--->%s<---\n", yytext); |
---|
479 | #endif |
---|
480 | } |
---|
481 | <help>. { |
---|
482 | found_oldhelp=1; |
---|
483 | #if YYLPDEBUG > 1 |
---|
484 | printf("-HELP:%s\n", yytext); |
---|
485 | #endif |
---|
486 | } |
---|
487 | |
---|
488 | |
---|
489 | <libcmd>{string}"\"" { quote--; |
---|
490 | yytext[yyleng-1] = '\0'; |
---|
491 | #ifndef STANDALONE_PARSER |
---|
492 | if ( mode == LOAD_LIB ) |
---|
493 | { |
---|
494 | library_stack->push(newlib, yytext); |
---|
495 | } |
---|
496 | #endif /* STANDALONE_PARSER */ |
---|
497 | #if YYLPDEBUG |
---|
498 | if(lpverbose>1) printf("LIB:'%s'\n", yytext); |
---|
499 | #endif |
---|
500 | BEGIN(INITIAL); |
---|
501 | } |
---|
502 | <libcmd2>{string}"\")" { quote--; brace2--; |
---|
503 | yytext[yyleng-1] = '\0'; |
---|
504 | #ifndef STANDALONE_PARSER |
---|
505 | if ( mode == LOAD_LIB ) |
---|
506 | { |
---|
507 | library_stack->push(newlib, yytext); |
---|
508 | } |
---|
509 | #endif /* STANDALONE_PARSER */ |
---|
510 | #if YYLPDEBUG |
---|
511 | if(lpverbose>1) printf("LIB:'%s'\n", yytext); |
---|
512 | #endif |
---|
513 | BEGIN(INITIAL); |
---|
514 | } |
---|
515 | |
---|
516 | <pdef>[ \t] { } |
---|
517 | <pdef>\( { |
---|
518 | brace2++; |
---|
519 | #if YYLPDEBUG > 1 |
---|
520 | printf("%s", yytext); |
---|
521 | #endif |
---|
522 | } |
---|
523 | <pdef>\) { |
---|
524 | brace2--; |
---|
525 | #if YYLPDEBUG > 1 |
---|
526 | printf(">%s<\n", yytext); |
---|
527 | printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
528 | #endif |
---|
529 | if(brace2<=0) |
---|
530 | { |
---|
531 | #if YYLPDEBUG > 1 |
---|
532 | printf("BEGIN(phead){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
533 | #endif |
---|
534 | SET_DEF_END(mode, pi, current_pos(yyleng)); |
---|
535 | BEGIN(phead); |
---|
536 | } |
---|
537 | } |
---|
538 | <pdef>"{" { |
---|
539 | if(brace2>0) |
---|
540 | { |
---|
541 | #if YYLPDEBUG > 1 |
---|
542 | printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
543 | #endif |
---|
544 | yylp_errno = YYLP_DEF_BR2; |
---|
545 | return(1); |
---|
546 | } |
---|
547 | else |
---|
548 | { |
---|
549 | brace1++; BEGIN(pbody); |
---|
550 | if(lpverbose) |
---|
551 | printf("// BODY at line %d,%d (%d)\n", yylplineno, |
---|
552 | current_pos(0), brace1); |
---|
553 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
554 | } |
---|
555 | } |
---|
556 | <pdef>\n { yylplineno++; |
---|
557 | if(brace2<=0) |
---|
558 | { |
---|
559 | #if YYLPDEBUG > 1 |
---|
560 | printf("BEGIN(phead-2){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
561 | #endif |
---|
562 | BEGIN(phead); |
---|
563 | } |
---|
564 | } |
---|
565 | <pdef>({comment}[^\n]*) { } |
---|
566 | <pdef>\/\/* { old_state = YYSTATE; BEGIN(comment); } |
---|
567 | <pdef>. { |
---|
568 | if(brace2<=0) |
---|
569 | { |
---|
570 | BEGIN(phead); |
---|
571 | yyless(0); |
---|
572 | } |
---|
573 | } |
---|
574 | |
---|
575 | <phead>({tnl}+{quote}+{strings}+{escquote}+{tnl}+"{") { |
---|
576 | #if YYLPDEBUG |
---|
577 | if(lpverbose>2)printf("0-Len=%d;\n", yyleng); |
---|
578 | #endif |
---|
579 | if(check) |
---|
580 | { |
---|
581 | printf("Procedure %s (line %d) has OLD-STYLE-HELP!\n", |
---|
582 | pi->procname, pi->data.s.proc_lineno); |
---|
583 | } |
---|
584 | SET_HELP_START(mode, pi, current_pos(0)); |
---|
585 | BEGIN(poldhelp); |
---|
586 | yyless(0); |
---|
587 | } |
---|
588 | <phead>({tnl}+{quote}+{strings}+{eos}) { |
---|
589 | #if YYLPDEBUG |
---|
590 | if(lpverbose>2)printf("1-Len=%d;\n", yyleng); |
---|
591 | #endif |
---|
592 | BEGIN(phelp); |
---|
593 | yyless(0); |
---|
594 | } |
---|
595 | <phead>{escstrings}+"{" { |
---|
596 | if(check && yyleng>2) |
---|
597 | { |
---|
598 | printf("Procedure %s (line %d) has OLD-STYLE-HELP!\n", |
---|
599 | pi->procname, pi->data.s.proc_lineno); |
---|
600 | } |
---|
601 | #if YYLPDEBUG |
---|
602 | if(lpverbose>2 && yyleng>2) |
---|
603 | printf("2-Len=%d, %s;\n", yyleng, pi->procname); |
---|
604 | #endif |
---|
605 | SET_HELP_START(mode, pi, current_pos(0)); |
---|
606 | BEGIN(poldhelp); |
---|
607 | yyless(0); |
---|
608 | } |
---|
609 | <phead>. { printf("[%s]", yytext); } |
---|
610 | |
---|
611 | <poldhelp>{escbrack} { } |
---|
612 | <poldhelp>"{" { |
---|
613 | SET_HELP_END(mode, pi, current_pos(0)); |
---|
614 | brace1++; BEGIN(pbody); |
---|
615 | if(lpverbose) |
---|
616 | { |
---|
617 | printf("// HELP from %d to %d\n", |
---|
618 | (int)pi->data.s.help_start, (int)pi->data.s.help_end); |
---|
619 | printf("// BODY at line %d,%d (%d)\n", yylplineno, |
---|
620 | current_pos(0), brace1); |
---|
621 | } |
---|
622 | #if YYLPDEBUG > 1 |
---|
623 | printf("BEGIN(pbody){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
624 | #endif |
---|
625 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
626 | #if YYLPDEBUG > 1 |
---|
627 | printf("BODY at %d/%d", yylplineno, current_pos(0)); |
---|
628 | #endif |
---|
629 | } |
---|
630 | <poldhelp>\n { yylplineno++; } |
---|
631 | <poldhelp>. { } |
---|
632 | |
---|
633 | <phelp>{quote} { |
---|
634 | old_state = YYSTATE; |
---|
635 | BEGIN(string); |
---|
636 | SET_HELP_START(mode, pi, current_pos(1)); |
---|
637 | } |
---|
638 | <phelp>{tos} {} |
---|
639 | <phelp>"{" { |
---|
640 | brace1++; BEGIN(pbody); |
---|
641 | if(lpverbose) |
---|
642 | { |
---|
643 | printf("// HELP from %d to %d\n", |
---|
644 | (int)pi->data.s.help_start, (int)pi->data.s.help_end); |
---|
645 | printf("// BODY at line %d,%d (%d)\n", yylplineno, |
---|
646 | current_pos(0), brace1); |
---|
647 | } |
---|
648 | #if YYLPDEBUG > 1 |
---|
649 | printf("BEGIN(pbody){=%d, (=%d, [=%d\n", brace1, brace2, brace3); |
---|
650 | #endif |
---|
651 | SET_BODY_START(mode, pi, yylplineno, current_pos(0)); |
---|
652 | #if YYLPDEBUG > 1 |
---|
653 | printf("BODY at %d/%d", yylplineno, current_pos(0)); |
---|
654 | #endif |
---|
655 | } |
---|
656 | <phelp>\n { yylplineno++;} |
---|
657 | |
---|
658 | <pbody>({comment}[^\n]*) { } |
---|
659 | <pbody>{quote} { quote++; old_state = YYSTATE; |
---|
660 | BEGIN(string); /* printf("%s", yytext); */ |
---|
661 | } |
---|
662 | |
---|
663 | <pbody>proc+{tos}+{name}+{tnl}+{paramlist}+{tnl}+"{" { |
---|
664 | if(check) printf("*** found 2 proc whithin procedure '%s'.\n", |
---|
665 | pi->procname); |
---|
666 | yyless(yyleng-1); |
---|
667 | } |
---|
668 | <pbody>proc+{tos}+{name}+{tnl}+"{" { |
---|
669 | if(check) printf("*** found 1 proc whithin procedure '%s'.\n", |
---|
670 | pi->procname); |
---|
671 | yyless(yyleng-1); |
---|
672 | } |
---|
673 | <pbody>"{" { |
---|
674 | brace1++; |
---|
675 | #if YYLPDEBUG > 1 |
---|
676 | printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext); |
---|
677 | #endif |
---|
678 | } |
---|
679 | <pbody>"}" { |
---|
680 | #if YYLPDEBUG > 1 |
---|
681 | printf("line: %d, (%d)%s\n", |
---|
682 | yylplineno, brace1, yytext); |
---|
683 | #endif |
---|
684 | brace1--; |
---|
685 | if(brace2>0) |
---|
686 | { |
---|
687 | yylp_errno = YYLP_BODY_BR2; |
---|
688 | return(1); |
---|
689 | } |
---|
690 | if(brace3>0) |
---|
691 | { |
---|
692 | yylp_errno = YYLP_BODY_BR3; |
---|
693 | return(1); |
---|
694 | } |
---|
695 | if(brace1<=0) |
---|
696 | { |
---|
697 | SET_BODY_END(mode, pi, current_pos(yyleng)); |
---|
698 | SET_PROC_END(mode, pi, current_pos(yyleng)); |
---|
699 | #if YYLPDEBUG > 1 |
---|
700 | printf("-%d\n", current_pos(0)); |
---|
701 | #endif |
---|
702 | BEGIN(INITIAL); |
---|
703 | } |
---|
704 | } |
---|
705 | <pbody>"(" { |
---|
706 | brace2++; /* printf("%s", yytext); */ |
---|
707 | } |
---|
708 | <pbody>")" { |
---|
709 | brace2--; /* printf("%s", yytext); */ |
---|
710 | if(brace2<0) { |
---|
711 | yylp_errno = YYLP_BODY_TMBR2; |
---|
712 | return(1); |
---|
713 | } |
---|
714 | } |
---|
715 | <pbody>"[" { |
---|
716 | brace3++; /* printf("%s", yytext); */ |
---|
717 | } |
---|
718 | <pbody>"]" { |
---|
719 | brace3--; /* printf("%s", yytext); */ |
---|
720 | if(brace3<0) { |
---|
721 | yylp_errno = YYLP_BODY_TMBR3; |
---|
722 | return(1); |
---|
723 | } |
---|
724 | } |
---|
725 | <pbody>\n { yylplineno++; } |
---|
726 | <pbody>. { } |
---|
727 | |
---|
728 | <info>{quote} { |
---|
729 | quote++; BEGIN(string); |
---|
730 | found_info++; |
---|
731 | string_start = current_pos(yyleng); |
---|
732 | *lib_style = NEW_LIBSTYLE; |
---|
733 | last_cmd = LP_INFO; |
---|
734 | } |
---|
735 | <info>\n { yylplineno++; } |
---|
736 | <info>. { } |
---|
737 | |
---|
738 | <category>{quote} { |
---|
739 | quote++; BEGIN(string); |
---|
740 | found_cat++; |
---|
741 | string_start = current_pos(yyleng); |
---|
742 | *lib_style = NEW_LIBSTYLE; |
---|
743 | last_cmd = LP_CATEGORY; |
---|
744 | } |
---|
745 | <category>\n { yylplineno++; } |
---|
746 | <category>. { } |
---|
747 | |
---|
748 | <string>"\"" { quote--; |
---|
749 | #ifdef HAVE_NAMESPACES |
---|
750 | copy_string(mode, pl); |
---|
751 | #else /* HAVE_NAMESPACES */ |
---|
752 | copy_string(mode); |
---|
753 | #endif /* HAVE_NAMESPACES */ |
---|
754 | last_cmd = LP_NONE; |
---|
755 | if(old_state==phelp) |
---|
756 | { |
---|
757 | SET_HELP_END(mode, pi, current_pos(0)); |
---|
758 | } |
---|
759 | BEGIN(old_state); /* printf("%s", yytext); */ |
---|
760 | } |
---|
761 | <string>(\\\\)|(\\\") { if (old_state == phelp) IncrCheckSum(*yytext);} |
---|
762 | <string>\n { yylplineno++; if (old_state == phelp) IncrCheckSum('\n');} |
---|
763 | <string>. { if (old_state == phelp) IncrCheckSum(*yytext);} |
---|
764 | |
---|
765 | <pexample>(\/\/[^\n]*) { } |
---|
766 | <pexample>"\"" { quote++; old_state = YYSTATE; |
---|
767 | BEGIN(string); /* printf("%s", yytext); */ |
---|
768 | } |
---|
769 | <pexample>"{" { |
---|
770 | brace1++; /* printf("(%d)%s", brace1, yytext); */ |
---|
771 | } |
---|
772 | <pexample>"}" { |
---|
773 | brace1--; /* printf("(%d)%s", brace1, yytext); */ |
---|
774 | if(brace1<=0) { |
---|
775 | if(brace2>0) { yylp_errno=YYLP_EX_BR2; return(1); } |
---|
776 | if(brace3>0) { yylp_errno=YYLP_EX_BR3; return(1); } |
---|
777 | BEGIN(INITIAL); |
---|
778 | SET_PROC_END(mode, pi, current_pos(yyleng)); |
---|
779 | } |
---|
780 | } |
---|
781 | <pexample>"(" { |
---|
782 | brace2++; /* printf("%s", yytext); */ |
---|
783 | } |
---|
784 | <pexample>")" { |
---|
785 | brace2--; /* printf("%s", yytext); */ |
---|
786 | } |
---|
787 | <pexample>"[" { |
---|
788 | brace3++; /* printf("%s", yytext); */ |
---|
789 | } |
---|
790 | <pexample>"]" { |
---|
791 | brace3--; /* printf("%s", yytext); */ |
---|
792 | } |
---|
793 | <pexample>\n { yylplineno++; } |
---|
794 | <pexample>. { } |
---|
795 | |
---|
796 | <pestr>"\"" { quote--; |
---|
797 | BEGIN(pexample); /* printf("%s", yytext); */ |
---|
798 | } |
---|
799 | <pestr>\\\\ { } |
---|
800 | <pestr>\\\" { } |
---|
801 | <pestr>\n { yylplineno++; } |
---|
802 | <pestr>. { } |
---|
803 | |
---|
804 | <comment>\*\/ { BEGIN(old_state); } |
---|
805 | <comment>\n { yylplineno++; } |
---|
806 | <comment>. { } |
---|
807 | |
---|
808 | \n { yylplineno++; } |
---|
809 | \r { } |
---|
810 | ; { p_static = FALSE; |
---|
811 | #if YYLPDEBUG > 1 |
---|
812 | printf("%s", yytext); |
---|
813 | #endif |
---|
814 | } |
---|
815 | . { p_static = FALSE; |
---|
816 | yylp_errno = YYLP_BAD_CHAR; |
---|
817 | #ifdef STANDALONE_PARSER |
---|
818 | printf("[%d]", *yytext); |
---|
819 | #else |
---|
820 | if (text_buffer!=NULL) omFree((ADDRESS)text_buffer); |
---|
821 | text_buffer = omStrDup(yytext); |
---|
822 | omMarkAsStaticAddr(text_buffer); |
---|
823 | #endif |
---|
824 | #if YYLPDEBUG > 1 |
---|
825 | printf("[%s]", yytext); |
---|
826 | #endif |
---|
827 | return(1); |
---|
828 | } |
---|
829 | |
---|
830 | %% |
---|
831 | |
---|
832 | int current_pos(int i) |
---|
833 | { |
---|
834 | return(i+offset+(int)(yytext-yylp_buffer_start)); |
---|
835 | } |
---|
836 | |
---|
837 | int libread(FILE* f, char* buf, int max_size) |
---|
838 | { int rc; |
---|
839 | |
---|
840 | offset = ftell(f); |
---|
841 | rc = myfread( buf, 1, max_size, f ); |
---|
842 | #if YYLPDEBUG >2 |
---|
843 | printf("fread: %d of %d\n", rc, max_size); |
---|
844 | #endif |
---|
845 | yylp_buffer_start = buf; |
---|
846 | return rc; |
---|
847 | } |
---|
848 | |
---|
849 | extern "C" { |
---|
850 | int yylpwrap() |
---|
851 | { |
---|
852 | //printf("======================= YYWRAP ====================\n"); |
---|
853 | if(brace1>0) { yylp_errno=YYLP_MISS_BR1; } |
---|
854 | if(brace2>0) { yylp_errno=YYLP_MISS_BR2; } |
---|
855 | if(brace3>0) { yylp_errno=YYLP_MISS_BR3; } |
---|
856 | if(quote>0) { yylp_errno=YYLP_MISSQUOT; } |
---|
857 | /* printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3);/**/ |
---|
858 | if(feof(yyin)) return 1; else return 0; |
---|
859 | } |
---|
860 | } |
---|
861 | |
---|
862 | void reinit_yylp() |
---|
863 | { |
---|
864 | brace1 = 0; |
---|
865 | brace2 = 0; |
---|
866 | brace3 = 0; |
---|
867 | quote = 0; |
---|
868 | yy_init=1; |
---|
869 | yy_delete_buffer(yy_current_buffer); |
---|
870 | } |
---|
871 | |
---|
872 | void make_version(char *p,int what) |
---|
873 | { |
---|
874 | char ver[10]; |
---|
875 | char date[16]; |
---|
876 | ver[0]='?'; ver[1]='.'; ver[2]='?'; ver[3]='\0'; |
---|
877 | date[0]='?'; date[1]='\0'; |
---|
878 | if(what) sscanf(p,"%*[^=]= %*s %*s %10s %16s",ver,date); |
---|
879 | else sscanf(p,"// %*s %*s %10s %16s",ver,date); |
---|
880 | strcpy(libnamebuf,"("); |
---|
881 | strcat(libnamebuf,ver); |
---|
882 | strcat(libnamebuf,","); |
---|
883 | strcat(libnamebuf,date); |
---|
884 | strcat(libnamebuf,")"); |
---|
885 | if(what && strcmp(libnamebuf, "(?.?,?)")==0) |
---|
886 | { |
---|
887 | sscanf(p,"%*[^\"]\"%[^\"]\"",libnamebuf); |
---|
888 | } |
---|
889 | //printf("ID=(%d)%s; \n", what, p); |
---|
890 | } |
---|
891 | |
---|
892 | #ifdef HAVE_NAMESPACES |
---|
893 | void copy_string(lp_modes mode, idhdl pl) |
---|
894 | #else /* HAVE_NAMESPACES */ |
---|
895 | void copy_string(lp_modes mode) |
---|
896 | #endif /* HAVE_NAMESPACES */ |
---|
897 | { |
---|
898 | #ifdef STANDALONE_PARSER |
---|
899 | if ((texinfo_out && (last_cmd == LP_INFO || last_cmd == LP_CATEGORY)) || |
---|
900 | (category_out && last_cmd == LP_CATEGORY)) |
---|
901 | { |
---|
902 | long current_location = ftell(yylpin), i = string_start, quote = 0; |
---|
903 | char c; |
---|
904 | if (texinfo_out) |
---|
905 | { |
---|
906 | if (last_cmd == LP_INFO) |
---|
907 | { |
---|
908 | printf("$info = <<EOT;\n"); |
---|
909 | } |
---|
910 | else |
---|
911 | { |
---|
912 | printf("$category = <<EOT;\n"); |
---|
913 | } |
---|
914 | } |
---|
915 | fseek (yylpin, i, SEEK_SET); |
---|
916 | while (i< current_location) |
---|
917 | { |
---|
918 | c = fgetc(yylpin); |
---|
919 | if (c == '\\') |
---|
920 | { |
---|
921 | quote = (! quote); |
---|
922 | } |
---|
923 | else if (c == '"') |
---|
924 | { |
---|
925 | if (! quote) break; |
---|
926 | } |
---|
927 | else |
---|
928 | quote = 0; |
---|
929 | if (c == '@' || c == '$') putchar('\\'); |
---|
930 | if (c != '\r') putchar(c); |
---|
931 | i++; |
---|
932 | } |
---|
933 | if (category_out) exit(0); |
---|
934 | fseek (yylpin, current_location, SEEK_SET); |
---|
935 | printf("\nEOT\n"); |
---|
936 | } |
---|
937 | #else |
---|
938 | if((last_cmd == LP_INFO)&&(mode == GET_INFO)) |
---|
939 | { |
---|
940 | int i, offset=0; |
---|
941 | long current_location = ftell(yylpin); |
---|
942 | int len = (int)(current_pos(0) - string_start); |
---|
943 | fseek(yylpin, string_start, SEEK_SET); |
---|
944 | if (text_buffer!=NULL) omFree((ADDRESS)text_buffer); |
---|
945 | text_buffer = (char *)omAlloc(len+2); |
---|
946 | omMarkAsStaticAddr(text_buffer); |
---|
947 | myfread(text_buffer, len, 1, yylpin); |
---|
948 | fseek(yylpin, current_location, SEEK_SET); |
---|
949 | text_buffer[len]='\0'; |
---|
950 | offset=0; |
---|
951 | for(i=0;i<=len; i++) |
---|
952 | { |
---|
953 | if(text_buffer[i]=='\\' && |
---|
954 | (text_buffer[i+1]=='\"' || text_buffer[i+1]=='{' || |
---|
955 | text_buffer[i+1]=='}' || text_buffer[i+1]=='\\')) |
---|
956 | { |
---|
957 | i++; |
---|
958 | offset++; |
---|
959 | } |
---|
960 | if(offset>0) text_buffer[i-offset] = text_buffer[i]; |
---|
961 | } |
---|
962 | #ifdef HAVE_NAMESPACES |
---|
963 | if( mode != GET_INFO ) { |
---|
964 | h0 = enterid( omStrDup("info"), myynest, STRING_CMD, |
---|
965 | &IDPACKAGE(pl)->idroot, FALSE ); |
---|
966 | if (h0!=NULL) |
---|
967 | { |
---|
968 | IDSTRING(h0) = omStrDup(text_buffer); |
---|
969 | } |
---|
970 | } |
---|
971 | #endif /* HAVE_NAMESPACES */ |
---|
972 | } |
---|
973 | #endif /* STANDALONE_PARSER */ |
---|
974 | } |
---|
975 | |
---|
976 | void print_init() |
---|
977 | { |
---|
978 | printf("Init=%d\n", yy_init); |
---|
979 | } |
---|
980 | |
---|
981 | void print_version(lp_modes mode, char *p) |
---|
982 | { |
---|
983 | #ifdef STANDALONE_PARSER |
---|
984 | //printf("loading %s%s", p, libnamebuf); |
---|
985 | #else |
---|
986 | if ( mode == LOAD_LIB ) |
---|
987 | { |
---|
988 | if (BVERBOSE(V_LOAD_LIB) && p!=NULL ) Print(" %s...", p); |
---|
989 | //Warn( "loading %s%s", p, libnamebuf); |
---|
990 | } |
---|
991 | #endif |
---|
992 | } |
---|
993 | |
---|
994 | #ifdef STANDALONE_PARSER |
---|
995 | main( int argc, char *argv[] ) |
---|
996 | { |
---|
997 | lib_style_types lib_style; |
---|
998 | main_init(argc, argv); |
---|
999 | if(yyin == NULL) { |
---|
1000 | fprintf(stderr, "No library found to parse.\n"); |
---|
1001 | exit(1); |
---|
1002 | } |
---|
1003 | if (! (texinfo_out || category_out)) |
---|
1004 | { |
---|
1005 | if(lpverbose)printf("Verbose level=%d\n", lpverbose); |
---|
1006 | if(check)printf("Reporting most possible annomalies.\n"); |
---|
1007 | if(lpverbose||check)printf("\n"); |
---|
1008 | |
---|
1009 | printf( " %-15s %20s %s,%s %s,%s %s,%s\n", "Library", |
---|
1010 | "function", "line", "start-eod", "line", "body-eob", |
---|
1011 | "line", "example-eoe"); |
---|
1012 | } |
---|
1013 | yylplex(argv[0], argv[0], &lib_style); |
---|
1014 | if(yylp_errno) { |
---|
1015 | printf("ERROR occured: [%d] ", yylp_errno); |
---|
1016 | printf(yylp_errlist[yylp_errno], yylplineno); |
---|
1017 | printf("\n"); |
---|
1018 | } |
---|
1019 | else if(pi!=NULL) printpi(pi); |
---|
1020 | if (texinfo_out) |
---|
1021 | printf("1;"); |
---|
1022 | exit(0); |
---|
1023 | } |
---|
1024 | |
---|
1025 | #endif /* STANDALONE_PARSER */ |
---|
1026 | #endif /* HAVE_LIBPARSE */ |
---|