source: git/Singular/libparse.l @ 7fd611

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