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