source: git/Singular/libparse.l @ 97f92a

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