source: git/Singular/libparse.l @ 48aa42

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