source: git/Singular/libparse.l @ 94fcf4

fieker-DuValspielwiese
Last change on this file since 94fcf4 was 60a3add, checked in by Kai Krüger <krueger@…>, 26 years ago
fixed report C.Gorzel 2. git-svn-id: file:///usr/local/Singular/svn/trunk@2011 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 23.6 KB
Line 
1%{
2/****************************************
3*  Computer Algebra System SINGULAR     *
4****************************************/
5/* $Id: libparse.l,v 1.24 1998-05-31 15:42:23 krueger 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
30typedef enum { LP_NONE, LP_INFO, LP_VERSION} lib_cmds;
31
32int libread(FILE* f, char* buf, int max_size);
33int current_pos(int i);
34void print_version(lp_modes mode, char *p);
35void copy_string(lp_modes mode);
36void make_version(char *p, int what);
37
38int brace1 = 0;  /* { } */
39int brace2 = 0;  /* ( ) */
40int brace3 = 0;  /* [ ] */
41int quote  = 0;  /* " */
42int offset = 0;
43BOOLEAN p_static = FALSE;
44int old_state = 0;
45lib_cmds last_cmd = LP_NONE;
46
47char libnamebuf[128];
48char *text_buffer;
49long string_start;
50
51char *yylp_buffer_start;
52int yylplineno = 1;
53int lpverbose = 0, check = 0;
54int found_info=0,
55    found_version=0,
56    found_oldhelp = 0,
57    found_proc_in_proc = 0;
58
59char *yylp_errlist[]= {
60   "",
61   "missing close bracket ')' for proc definition in line %d.",  /*  1 */
62   "missing close bracket ')' for procbody in line %d.",         /*  2 */
63   "missing close bracket ']' for procbody in line %d.",         /*  3 */
64   "too many ')' closed brackets in line %d.",                   /*  4 */
65   "too many ']' closed brackets in line %d.",                   /*  5 */
66   "missing close bracket ')' for example in line %d.",          /*  6 */
67   "missing close bracket ']' for example in line %d.",          /*  7 */
68   "cannot assign character '%c' in line %d to any group.",      /*  8 */
69   "there must be a quote missing somewhere before line %d.",    /*  9 */
70   "missing close bracket '}' at end of library in line %d.",    /* 10 */
71   "missing close bracket ')' at end of library in line %d.",    /* 11 */
72   "missing close bracket ']' at end of library in line %d.",    /* 12 */
73   NULL
74};
75int yylp_errno = 0;
76
77#  ifdef __MWERKS__
78#    ifdef __cplusplus
79extern "C" {
80#    endif
81long   ftell(FILE *fp);
82#    ifdef macintosh
83int    fileno(FILE *stream);
84FILE   *fdopen(int filedes, char *type);
85int    isatty(int filedes);
86#else
87int    _fileno(FILE *stream);
88FILE   *_fdopen(int filedes, char *type);
89int    _isatty(int filedes);
90#      define fileno  _fileno
91#      define fdopen  _fdopen
92#      define isatty  _isatty
93#    endif /* macintosh */
94#    ifdef __cplusplus
95}
96#    endif
97#  endif
98
99#  ifdef STANDALONE_PARSER
100procinfov pi;
101printpi(procinfov pi);
102pi_clear(procinfov pi);
103extern "C" {
104  int yylpwrap();
105}
106void main_init(int argc, char *argv[]);
107void main_result(char *libname);
108#  else /* STANDALONE_PARSER */
109idhdl h0;
110#    define pi IDPROC(h0)
111extern "C"
112{
113  int yylpwrap();
114}
115extern libstackv library_stack;
116#  endif /* STANDALONE_PARSER */
117
118#  define SET_DEF_END(mode, pi, p) \
119     if ( mode == LOAD_LIB) pi->data.s.def_end = p;
120#  define SET_HELP_START(mode, pi, p) \
121     if ( mode == LOAD_LIB) pi->data.s.help_start = p;
122
123#  define SET_HELP_END(mode, pi, p) \
124     if ( mode == LOAD_LIB) pi->data.s.help_end = p;
125
126#  define SET_BODY_START(mode, pi, l, p) \
127     if ( mode == LOAD_LIB) { \
128       pi->data.s.body_lineno = l; \
129       pi->data.s.body_start = p; \
130     }
131#  define SET_BODY_END(mode, pi, p) \
132     if ( mode == LOAD_LIB) { \
133       pi->data.s.body_end = p-1; \
134       pi->data.s.proc_end = p-1; \
135     }
136
137#  define SET_EXAMPLE_START(mode, pi, l, p) \
138     if ( mode == LOAD_LIB) { \
139       pi->data.s.example_lineno = l; \
140       pi->data.s.example_start = p; \
141     }
142#  define SET_PROC_END(mode, pi, p) \
143     if ( mode == LOAD_LIB) { \
144       pi->data.s.proc_end = p-1; \
145       if(pi->data.s.body_end==0) pi->data.s.body_end = p-1; \
146     }
147
148#  undef YY_DECL
149#  define YY_DECL int yylex(char *newlib, char *libfile, \
150                                 lib_style_types *lib_style, \
151                                 lp_modes mode)
152
153#  undef YY_INPUT
154#  define YY_INPUT(buf,result,max_size) \
155          if ( ((result = libread( (yyin), (char *) buf, max_size )) < 0 ) \
156                  && ferror( yyin ) ) \
157                YY_FATAL_ERROR( "read in flex scanner failed" );
158
159#  define YY_USER_INIT { \
160       BEGIN(header); \
161       yylplineno = 1; \
162       yylp_errno = 0; \
163       *lib_style = OLD_LIBSTYLE; \
164       strcpy(libnamebuf,"(**unknown version**)"); \
165     }
166
167#  if 0
168<pbody>proc[ \t]+{name}  {
169                           printf("MISSING: PROC-cmd found. ERROR!\n"); }
170<pbody>example[ \t]*\n   {
171                           yylplineno++;
172                           printf("MISSING: EXAMPLE-cmd found. ERROR!\n"); }
173info=+"\"" {
174#  endif
175%}
176
177digit          [0-9]
178letter         [@a-zA-Z\']
179name           ({letter}({letter}*{digit}*_*)*|_)
180varname        ({letter}({letter}*{digit}*_*\(\))*|_|#)
181letters        ({letter}|{digit}|[_./#%^*:,])
182string         ({letters}*)
183comment        [\/][\/]
184dolar          [$]
185nls            [\n\r]
186symbols        [~!@#$%^&*()_+-=\\\|\[\];:,<.>/\?\' \t\~\`]
187asymbols       ({symbols}|[{}])
188bsymbols       ({symbols}|{escbrack}|[}])
189aletters       ({letter}|{digit}|{asymbols}|{dolar}|{escquote}|{nls})
190bletters       ({letter}|{digit}|{bsymbols}|{dolar}|{quote}|{nls})
191cletters       ({letter}|{digit}|{asymbols}|{dolar}|{quote})
192strings        ({aletters}*)
193escstrings     ({bletters}*)
194fstring        ({cletters}*)
195param          ({name}+{tos}+{varname})
196parameters     ({param}(,{param})*)
197paramlist      ("("{parameters}")")
198quote          [\"]
199escquote       (\\\")
200escbrack       (\\\{)
201tnl            ([ \t\n]*)
202eos            ({quote}+{tnl}+"{")
203tos            ([ \t]*)
204eq             ([ \t]*+=[ \t]*)
205eqnl           ([ \t\n]*+=[ \t\n]*)
206
207/* %start START */
208
209%x header
210%x help
211%x libcmd
212%x pdef
213%x phead
214%x poldhelp
215%x phelp
216%x pbody
217%x pstr
218%x pexample
219%x pestr
220%x string
221%x comment
222%x info
223%x version
224
225%%
226(\/\/[^\n]*)|(^#![^\n]*)|([ \t]) { }
227\/\/*      { old_state = YYSTATE; BEGIN(comment); }
228
229(info+{eqnl}+{quote}+{strings}+{quote}) {
230         yyless(4); old_state = YYSTATE; BEGIN(info);
231       }
232
233(version+{eqnl}+{quote}+{strings}+{quote}) {
234             found_version++;
235             if ( mode != GET_INFO ) {
236               make_version(yytext,1);
237#ifdef STANDALONE_PARSER
238               printf("Version:%s;\n", libnamebuf);
239#else
240               text_buffer = mstrdup(libnamebuf);
241#endif
242             }
243           }
244
245static     { p_static=TRUE; }
246
247(proc[ \t]+{name})|([ \t]proc[ \t]+{name}) {
248             char proc[256];
249             BEGIN(pdef);
250             found_proc_in_proc = 0;
251             proc[0]='\0';
252             sscanf( yytext, "%*[^p]proc %s", proc);
253             if(strlen(proc)<1) sscanf( yytext, "proc %s", proc);
254#if YYLPDEBUG > 1
255             printf("Newlib:%s\n", newlib);
256#endif
257#ifdef STANDALONE_PARSER
258               if ( pi != NULL ) {
259                 printpi(pi);
260                 pi_clear(pi);
261               }
262               pi = (procinfo *)malloc(sizeof(procinfo));
263               iiInitSingularProcinfo(pi, newlib, proc, yylplineno,
264                                        current_pos(0), p_static);
265#else STANDALONE_PARSER
266             if( mode == LOAD_LIB) {
267               h0 = enterid( mstrdup(proc), myynest, PROC_CMD,
268                                   &idroot, FALSE );
269               if (h0!=NULL) {
270                 iiInitSingularProcinfo(IDPROC(h0), newlib, proc,
271                                yylplineno, current_pos(0),p_static);
272                 if (BVERBOSE(V_LOAD_PROC))
273                   Warn( "     proc '%s' registered", proc );
274               }
275#endif STANDALONE_PARSER
276               SET_DEF_END(mode, pi, current_pos(yyleng+1));
277#if YYLPDEBUG
278               if(lpverbose) {
279                  printf("// PROCEDURE '%s' status: %s, ", proc,
280                      p_static ? "local" : "global");
281                  printf("starting at line %d,%d: definition end: %d (%d).\n",
282                      yylplineno, current_pos(0), (int)pi->data.s.def_end, brace1);
283               }
284#endif
285               p_static=FALSE;
286#ifndef STANDALONE_PARSER
287             }
288#endif STANDALONE_PARSER
289           }
290example    {
291             BEGIN(pexample);
292             SET_EXAMPLE_START(mode, pi, yylplineno, current_pos(0));
293#if YYLPDEBUG
294             if(lpverbose)
295                printf("//     EXAMPLE at line %d,%d (%d)\n", yylplineno,
296                    current_pos(0), brace1);
297#endif
298           }
299
300LIB[ \t]+"\"" { quote++;
301             BEGIN(libcmd);
302           }
303
304<header>({comment}+{tos}+{dolar}+Id:+{string}+[^\n]*)|({comment}+{tos}+{dolar}+Header:+{string}+[^\n]*) {
305             make_version(yytext, 0);
306#if YYLPDEBUG > 1
307             printf("+(id)HEAD:%s\n", yytext);
308#endif
309           }
310<header>(^{comment}+[^\n]*) {
311#if YYLPDEBUG
312             printf("+(cmt)HEAD:%s\n", yytext);
313#endif
314           }
315<header>(^#![^\n]*) {
316#if YYLPDEBUG > 1
317             printf("-HEAD:%s\n", yytext);
318#endif
319           }
320<header>^proc\  { yyless(0);
321             BEGIN(INITIAL);
322             yymore();
323           }
324<header>(info+{eqnl}+{quote})|(version+{eqnl}+{quote}) {
325             yyless(0);
326             *lib_style = NEW_LIBSTYLE;
327             BEGIN(INITIAL);
328             yymore();
329           }
330
331<header>^LIB[ \t]+"\""   { quote++;
332             BEGIN(libcmd);
333           }
334<header>\n { yylplineno++; }
335<header>.  {
336#if YYLPDEBUG > 1
337             printf(" HEAD:%s\n", yytext);
338#endif
339             yyless(0);
340             BEGIN(help);
341           }
342<help>(^{comment}+[^\n]*)  {
343#if YYLPDEBUG > 1
344             printf(" HELP:%s\n", yytext);
345#endif
346             BEGIN(INITIAL); }
347<help>(^#![^\n]*) {
348#if YYLPDEBUG > 1
349             printf(" HELP:%s\n", yytext);
350#endif
351             BEGIN(INITIAL);
352           }
353<help>(info+{eqnl}+{quote})|(version+{eqnl}+{quote}) {
354             yyless(0);
355             *lib_style = NEW_LIBSTYLE;
356             BEGIN(INITIAL);
357             yymore();
358           }
359<help>^proc\  {
360             yyless(0);
361             //printf("2) proc found.\n");
362             BEGIN(INITIAL);
363             yymore();
364           }
365<help>^LIB[ \t]+"\""     { quote++;
366             BEGIN(libcmd);
367           }
368
369<help>\n { yylplineno++; }
370<help>({tos}|{comment}+{fstring}) {
371#if YYLPDEBUG
372             if(lpverbose>2) printf("--->%s<---\n", yytext);
373#endif
374           }
375<help>.    {
376             found_oldhelp=1;
377#if YYLPDEBUG > 1
378             printf("-HELP:%s\n", yytext);
379#endif
380           }
381
382
383<libcmd>{string}"\""     { quote--;
384             yytext[yyleng-1] = '\0';
385#ifndef STANDALONE_PARSER
386             if ( mode == LOAD_LIB ) {
387             library_stack->push(newlib, yytext);
388           }
389#endif /* STANDALONE_PARSER */
390#if YYLPDEBUG
391             if(lpverbose>1) printf("LIB:'%s'\n", yytext);
392#endif
393             BEGIN(INITIAL);
394           }
395
396<pdef>[ \t] { }
397<pdef>\(   {
398             brace2++;
399#if YYLPDEBUG > 1
400             printf("%s", yytext);
401#endif
402           }
403<pdef>\)   {
404             brace2--;
405#if YYLPDEBUG > 1
406             printf(">%s<\n", yytext);
407             printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3);
408#endif
409             if(brace2<=0) {
410#if YYLPDEBUG > 1
411               printf("BEGIN(phead){=%d, (=%d, [=%d\n", brace1, brace2, brace3);
412#endif
413               SET_DEF_END(mode, pi, current_pos(yyleng));
414               BEGIN(phead);
415             }
416           }
417<pdef>"{"  {
418             if(brace2>0) {
419#if YYLPDEBUG > 1
420               printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3);
421#endif
422               yylp_errno = YYLP_DEF_BR2;
423               return(1);
424             } else {
425               brace1++; BEGIN(pbody);
426               if(lpverbose)
427                  printf("//     BODY at line %d,%d (%d)\n", yylplineno,
428                      current_pos(0), brace1);
429               SET_BODY_START(mode, pi, yylplineno, current_pos(0));
430             }
431           }
432<pdef>\n { yylplineno++;
433              if(brace2<=0) {
434#if YYLPDEBUG > 1
435                printf("BEGIN(phead-2){=%d, (=%d, [=%d\n", brace1, brace2, brace3);
436#endif
437                BEGIN(phead);
438              }
439            }
440<pdef>({comment}[^\n]*)  { }
441<pdef>\/\/*      { old_state = YYSTATE; BEGIN(comment); }
442<pdef>.    {
443             if(brace2<=0) {
444               BEGIN(phead);
445               yyless(0);
446             }
447           }
448
449<phead>({tnl}+{quote}+{strings}+{escquote}+{tnl}+"{") {
450#if YYLPDEBUG
451              if(lpverbose>2)printf("0-Len=%d;\n", yyleng);
452#endif
453              if(check) {
454                printf("Procedure %s (line %d) has OLD-STYLE-HELP!\n",
455                       pi->procname, pi->data.s.proc_lineno);
456              }
457              SET_HELP_START(mode, pi, current_pos(0));
458              BEGIN(poldhelp);
459              yyless(0);
460           }
461<phead>({tnl}+{quote}+{strings}+{eos}) {
462#if YYLPDEBUG
463              if(lpverbose>2)printf("1-Len=%d;\n", yyleng);
464#endif
465              BEGIN(phelp);
466              yyless(0);
467           }
468<phead>{escstrings}+"{" {
469              if(check && yyleng>2) {
470                printf("Procedure %s (line %d) has OLD-STYLE-HELP!\n",
471                       pi->procname, pi->data.s.proc_lineno);
472              }
473#if YYLPDEBUG
474              if(lpverbose>2 && yyleng>2)
475                 printf("2-Len=%d, %s;\n", yyleng, pi->procname);
476#endif
477              SET_HELP_START(mode, pi, current_pos(0));
478              BEGIN(poldhelp);
479              yyless(0);
480           }
481<phead>.   { printf("[%s]", yytext); }
482
483<poldhelp>{escbrack} { }
484<poldhelp>"{" {
485                SET_HELP_END(mode, pi, current_pos(0));
486                brace1++; BEGIN(pbody);
487                if(lpverbose) {
488                   printf("//     HELP from %d to %d\n",
489                       (int)pi->data.s.help_start, (int)pi->data.s.help_end);
490                   printf("//     BODY at line %d,%d (%d)\n", yylplineno,
491                       current_pos(0), brace1);
492                }
493#if YYLPDEBUG > 1
494                printf("BEGIN(pbody){=%d, (=%d, [=%d\n", brace1, brace2, brace3);
495#endif
496                SET_BODY_START(mode, pi, yylplineno, current_pos(0));
497#if YYLPDEBUG > 1
498                printf("BODY at %d/%d", yylplineno, current_pos(0));
499#endif
500              }
501<poldhelp>\n  { yylplineno++; }
502<poldhelp>.   { }
503
504<phelp>{quote} {
505             old_state = YYSTATE;
506             BEGIN(string);
507             SET_HELP_START(mode, pi, current_pos(1));
508           }
509<phelp>{tos} {}
510<phelp>"{" {
511             brace1++; BEGIN(pbody);
512             if(lpverbose) {
513                printf("//     HELP from %d to %d\n",
514                    (int)pi->data.s.help_start, (int)pi->data.s.help_end);
515                printf("//     BODY at line %d,%d (%d)\n", yylplineno,
516                    current_pos(0), brace1);
517             }
518#if YYLPDEBUG > 1
519             printf("BEGIN(pbody){=%d, (=%d, [=%d\n", brace1, brace2, brace3);
520#endif
521             SET_BODY_START(mode, pi, yylplineno, current_pos(0));
522#if YYLPDEBUG > 1
523             printf("BODY at %d/%d", yylplineno, current_pos(0));
524#endif
525           }
526<phelp>\n  { yylplineno++; }
527
528<pbody>({comment}[^\n]*) { }
529<pbody>{quote} { quote++; old_state = YYSTATE;
530                 BEGIN(string); /* printf("%s", yytext); */
531               }
532
533<pbody>proc+{tos}+{name}+{tnl}+{paramlist}+{tnl}+"{" {
534             if(check) printf("*** found 2 proc whithin procedure '%s'.\n",
535                          pi->procname);
536             yyless(yyleng-1);
537           }
538<pbody>proc+{tos}+{name}+{tnl}+"{" {
539             if(check) printf("*** found 1 proc whithin procedure '%s'.\n",
540                          pi->procname);
541             yyless(yyleng-1);
542           }
543<pbody>"{"     {
544                 brace1++;
545#if YYLPDEBUG > 1
546                 printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext);
547#endif
548                }
549<pbody>"}"               {
550#if YYLPDEBUG > 1
551                           printf("line: %d, (%d)%s\n", yylplineno, brace1, yytext);
552#endif
553                           brace1--;
554                           if(brace2>0) {
555                             yylp_errno = YYLP_BODY_BR2;
556                             return(1);
557                           }
558                           if(brace3>0) {
559                             yylp_errno = YYLP_BODY_BR3;
560                             return(1);
561                           }
562                           if(brace1<=0) {
563                             SET_BODY_END(mode, pi, current_pos(yyleng));
564                             SET_PROC_END(mode, pi, current_pos(yyleng));
565#if YYLPDEBUG > 1
566                             printf("-%d\n", current_pos(0));
567#endif
568                             BEGIN(INITIAL);
569                           }
570                         }
571<pbody>"("               {
572                           brace2++; /* printf("%s", yytext); */
573                         }
574<pbody>")"               {
575                           brace2--; /* printf("%s", yytext); */
576                           if(brace2<0) {
577                             yylp_errno = YYLP_BODY_TMBR2;
578                             return(1);
579                           }
580                         }
581<pbody>"["               {
582                           brace3++; /* printf("%s", yytext); */
583                         }
584<pbody>"]"               {
585                           brace3--; /* printf("%s", yytext); */
586                           if(brace3<0) {
587                             yylp_errno = YYLP_BODY_TMBR3;
588                             return(1);
589                           }
590                         }
591<pbody>\n                { yylplineno++; }
592<pbody>.                 { }
593
594<info>{quote} {
595             quote++; BEGIN(string);
596             found_info++;
597             string_start = current_pos(yyleng);
598             *lib_style = NEW_LIBSTYLE;
599             last_cmd = LP_INFO;
600       }
601<info>\n { yylplineno++; }
602<info>.  { }
603
604<string>"\""             { quote--;
605                           copy_string(mode);
606                           last_cmd = LP_NONE;
607                           if(old_state==phelp)
608                              SET_HELP_END(mode, pi, current_pos(0));
609                           BEGIN(old_state); /* printf("%s", yytext); */
610                         }
611<string>(\\\\)|(\\\")    { }
612<string>\n               { yylplineno++; }
613<string>.                { }
614
615<pexample>(\/\/[^\n]*)  { }
616<pexample>"\""           { quote++; old_state = YYSTATE;
617                           BEGIN(string); /* printf("%s", yytext); */
618                         }
619<pexample>"{"            {
620                           brace1++; /* printf("(%d)%s", brace1, yytext); */
621                         }
622<pexample>"}"            {
623                           brace1--; /* printf("(%d)%s", brace1, yytext); */
624                           if(brace1<=0) {
625                             if(brace2>0) { yylp_errno=YYLP_EX_BR2; return(1); }
626                             if(brace3>0) { yylp_errno=YYLP_EX_BR3; return(1); }
627                             BEGIN(INITIAL);
628                             SET_PROC_END(mode, pi, current_pos(yyleng));
629                           }
630                         }
631<pexample>"("            {
632                           brace2++; /* printf("%s", yytext); */
633                         }
634<pexample>")"            {
635                           brace2--; /* printf("%s", yytext); */
636                         }
637<pexample>"["            {
638                           brace3++; /* printf("%s", yytext); */
639                         }
640<pexample>"]"            {
641                           brace3--; /* printf("%s", yytext); */
642                         }
643<pexample>\n             { yylplineno++; }
644<pexample>.              { }
645
646<pestr>"\""              { quote--;
647                           BEGIN(pexample); /* printf("%s", yytext); */
648                         }
649<pestr>\\\\              { }
650<pestr>\\\"              { }
651<pestr>\n                { yylplineno++; }
652<pestr>.                 { }
653
654<comment>\*\/            { BEGIN(old_state); }
655<comment>\n              { yylplineno++; }
656<comment>.               { }
657
658\n                       { yylplineno++; }
659\r                       { }
660;                        { p_static = FALSE;
661#if YYLPDEBUG > 1
662                            printf("%s", yytext);
663#endif
664                         }
665.                        { p_static = FALSE;
666                           yylp_errno = YYLP_BAD_CHAR;
667#  ifdef STANDALONE_PARSER
668                           printf("[%d]", *yytext);
669#  else
670                           text_buffer = mstrdup(yytext);
671#  endif
672#if YYLPDEBUG > 1
673                           printf("[%s]", yytext);
674#endif
675                           return(1);
676                         }
677
678%%
679
680int current_pos(int i)
681{
682  return(i+offset+(int)(yytext-yylp_buffer_start));
683}
684
685int libread(FILE* f, char* buf, int max_size)
686{ int rc;
687
688  offset = ftell(f);
689  rc  = myfread( buf, 1, max_size, f );
690#if YYLPDEBUG >2
691  printf("fread: %d of %d\n", rc, max_size);
692#endif
693  yylp_buffer_start = buf;
694  return rc;
695}
696
697extern "C" {
698  int yylpwrap() {
699    //printf("======================= YYWRAP ====================\n");
700    if(brace1>0) { yylp_errno=YYLP_MISS_BR1; }
701    if(brace2>0) { yylp_errno=YYLP_MISS_BR2; }
702    if(brace3>0) { yylp_errno=YYLP_MISS_BR3; }
703    if(quote>0) { yylp_errno=YYLP_MISSQUOT; }
704    /* printf("{=%d, (=%d, [=%d\n", brace1, brace2, brace3);/**/
705    if(feof(yyin)) return 1; else return 0;
706  }
707}
708
709void reinit_yylp()
710{
711   brace1 = 0;
712   brace2 = 0;
713   brace3 = 0;
714   quote  = 0;
715   yy_init=1;
716   yy_delete_buffer(yy_current_buffer);
717}
718
719void make_version(char *p,int what)
720{
721  char ver[10];
722  char date[16];
723  ver[0]='?'; ver[1]='.'; ver[2]='?'; ver[3]='\0';
724  date[0]='?'; date[1]='\0';
725  if(what) sscanf(p,"%*[^=]= %*s %*s %10s %16s",ver,date);
726  else sscanf(p,"// %*s %*s %10s %16s",ver,date);
727  strcpy(libnamebuf,"(");
728  strcat(libnamebuf,ver);
729  strcat(libnamebuf,",");
730  strcat(libnamebuf,date);
731  strcat(libnamebuf,")");
732  if(what && strcmp(libnamebuf, "(?.?,?)")==0) {
733    sscanf(p,"%*[^\"]\"%[^\"]\"",libnamebuf);
734  }
735  //printf("ID=(%d)%s; \n", what, p);
736}
737
738void copy_string(lp_modes mode)
739{
740#  ifndef STANDALONE_PARSER
741  if((last_cmd == LP_INFO)&&(mode == GET_INFO))
742  {
743    int i, offset=0;
744    long current_location = ftell(yylpin);
745    int len = (int)(current_pos(0) - string_start);
746    fseek(yylpin, string_start, SEEK_SET);
747    text_buffer = (char *)AllocL(len+2);
748    myfread(text_buffer, len, 1, yylpin);
749    fseek(yylpin, current_location, SEEK_SET);
750    text_buffer[len]='\0';
751    offset=0;
752    for(i=0;i<=len; i++) {
753      if(text_buffer[i]=='\\' &&
754         (text_buffer[i+1]=='"' || text_buffer[i+1]=='{' ||
755          text_buffer[i+1]=='}' || text_buffer[i+1]=='\\')) {
756        i++;
757        offset++;
758      }
759      if(offset>0) text_buffer[i-offset] = text_buffer[i];
760    }
761  }
762#  endif /* STANDALONE_PARSER */
763}
764
765void print_init()
766{
767   printf("Init=%d\n", yy_init);
768}
769
770void print_version(lp_modes mode, char *p)
771{
772#  ifdef STANDALONE_PARSER
773  //printf("loading %s%s", p, libnamebuf);
774#  else
775  if ( mode == LOAD_LIB ) {
776    if (BVERBOSE(V_LOAD_LIB) && p!=NULL ) Print(" %s...", p);
777       //Warn( "loading %s%s", p, libnamebuf);
778  }
779#  endif
780}
781
782#  ifdef STANDALONE_PARSER
783main( int argc, char *argv[] )
784{
785  lib_style_types lib_style;
786  main_init(argc, argv);
787  if(yyin == NULL) {
788    printf("No library found to parse.\n");
789    exit(1);
790  }
791 
792  if(lpverbose)printf("Verbose level=%d\n", lpverbose);
793  if(check)printf("Reporting most possible annomalies.\n");
794  if(lpverbose||check)printf("\n");
795
796  printf( "  %-15s  %20s      %s,%s    %s,%s     %s,%s\n", "Library",
797          "function", "line", "start-eod", "line", "body-eob",
798          "line", "example-eoe");
799  yylplex(argv[0], argv[0], &lib_style);
800  if(yylp_errno) {
801    printf("ERROR occured: [%d] ", yylp_errno);
802    printf(yylp_errlist[yylp_errno], yylplineno);
803    printf("\n");
804  }
805  else if(pi!=NULL) printpi(pi);
806  main_result(argv[0]);
807}
808
809#  endif /* STANDALONE_PARSER */
810#endif /* HAVE_LIBPARSE */
Note: See TracBrowser for help on using the repository browser.