source: git/Singular/iplib.cc @ c4bbf1f

spielwiese
Last change on this file since c4bbf1f was c4bbf1f, checked in by Kai Krüger <krueger@…>, 26 years ago
fixes for HAVE_LIBPARSER not def git-svn-id: file:///usr/local/Singular/svn/trunk@1422 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 21.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: iplib.cc,v 1.19 1998-04-22 10:37:44 krueger Exp $ */
5/*
6* ABSTRACT: interpreter: LIB and help
7*/
8
9//#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
12//#include <ctype.h>
13
14#include "mod2.h"
15#include "tok.h"
16#include "ipid.h"
17#include "mmemory.h"
18#include "febase.h"
19#include "ring.h"
20#include "subexpr.h"
21#include "ipshell.h"
22#include "lists.h"
23#ifdef HAVE_LIBPARSER
24#  include "libparse.h"
25#else /* HAVE_LIBPARSER */
26   procinfo *iiInitSingularProcinfo(procinfov pi, char *libname,
27                                    char *procname, int line, long pos,
28                                    BOOLEAN pstatic = FALSE);
29#endif /* HAVE_LIBPARSER */
30
31char *iiConvName(char *p);
32#ifdef HAVE_LIBPARSER
33void yylprestart (FILE *input_file );
34int current_pos(int i=0);
35extern int yylp_errno;
36extern int yylplineno;
37extern char *yylp_errlist[];
38void print_init();
39libstackv library_stack;
40#endif
41
42/*2
43* find the library of an proc:
44*  => return (pi->libname)
45*/
46char * iiGetLibName(procinfov pi)
47{
48  char *res=NULL;
49
50  res = pi->libname;
51  return res;
52}
53/*2
54* given a line 'proc[ ]+{name}[ \t]*'
55* return a pointer to name and set the end of '\0'
56* changes the input!
57* returns: e: pointer to 'end of name'
58*          ct: changed char at the end of s
59*/
60char* iiProcName(char *buf, char & ct, char* &e)
61{
62  char *s=buf+5;
63  while (*s==' ') s++;
64  e=s+1;
65  while ((*e>' ') && (*e!='(')) e++;
66  ct=*e;
67  *e='\0';
68  return s;
69}
70
71/*2
72* given a line with args, return the argstr
73*/
74char * iiProcArgs(char *e,BOOLEAN withParenth)
75{
76  while ((*e==' ') || (*e=='\t') || (*e=='(')) e++;
77  if (*e<' ')
78  {
79    if (withParenth)
80    {
81      // no argument list, allow list #
82      return mstrdup("parameter list #;");
83    }
84    else
85    {
86      // empty list
87      return mstrdup("");
88    }
89  }
90  BOOLEAN in_args;
91  BOOLEAN args_found;
92  char *s;
93  char *argstr=(char *)AllocL(200);
94  *argstr='\0';
95  do
96  {
97    args_found=FALSE;
98    s=e; // set s to the starting point of the arg
99         // and search for the end
100    while ((*e!=',')&&(*e!=')')&&(*e!='\0'))
101    {
102      args_found=args_found || (*e>' ');
103      e++;
104    }
105    in_args=(*e==',');
106    if (args_found)
107    {
108      *e='\0';
109      // copy the result to argstr
110      strcat(argstr,"parameter ");
111      strcat(argstr,s);
112      strcat(argstr,"; ");
113      e++; // e was pointing to ','
114    }
115  } while (in_args);
116  return argstr;
117}
118
119/*2
120* locate `procname` in lib `libname` and find the part `part`:
121*  part=0: help, between, but excluding the line "proc ..." and "{...":
122*    => return
123*  part=1: body, between "{ ..." and "}", including the 1. line, w/o "{"
124*    => set pi->data.s.body, return NULL
125*  part=2: example, between, but excluding the line "exapmle {..." and "}":
126*    => return
127*/
128char* iiGetLibProcBuffer(procinfo *pi, int part )
129{
130  char buf[256], *s = NULL, *p;
131  long procbuflen;
132
133  FILE * fp = feFopen( pi->libname, "rb", NULL, TRUE );
134  if (fp==NULL)
135  {
136    return NULL;
137  }
138
139  fseek(fp, pi->data.s.proc_start, SEEK_SET);
140  if(part==0)
141  { // load help string
142    procbuflen = pi->data.s.body_start - pi->data.s.proc_start;
143    //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start,
144    //    pi->data.s.proc_start, procbuflen);
145    s = (char *)AllocL(procbuflen);
146    fread(s, procbuflen, 1, fp);
147    s[procbuflen] = '\0';
148    return(s);
149  }
150  if(part==1)
151  { // load proc part
152    procbuflen = pi->data.s.def_end - pi->data.s.proc_start;
153    //fgets(buf, sizeof(buf), fp);
154    fread( buf, procbuflen, 1, fp);
155    char ct;
156    char *e;
157    s=iiProcName(buf,ct,e);
158    char *argstr=NULL;
159    *e=ct;
160    argstr=iiProcArgs(e,TRUE);
161    procbuflen = pi->data.s.body_end - pi->data.s.body_start;
162    pi->data.s.body = (char *)AllocL( strlen(argstr)+procbuflen+15+
163                                      strlen(pi->libname) );
164    //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end,
165    //    pi->data.s.body_start, procbuflen);
166    if (pi->data.s.body==NULL)
167    {
168      Werror( "unable to allocate proc buffer `%s`", pi->procname );
169      return NULL;
170    }
171    fseek(fp, pi->data.s.body_start, SEEK_SET);
172    strcpy(pi->data.s.body,argstr);
173    fread( pi->data.s.body+strlen(argstr), procbuflen, 1, fp);
174    procbuflen+=strlen(argstr);
175    FreeL(argstr);
176    fclose( fp );
177    pi->data.s.body[procbuflen] = '\0';
178    strcat( pi->data.s.body+procbuflen, "\n;return();\n\n" );
179    strcat( pi->data.s.body+procbuflen+13,pi->libname);
180    s=strchr(pi->data.s.body,'{');
181    if (s!=NULL) *s=' ';
182    return NULL;
183  }
184  if(part==2)
185  { // load example
186    fseek(fp, pi->data.s.example_start, SEEK_SET);
187    fgets(buf, sizeof(buf), fp);
188    procbuflen = pi->data.s.proc_end - pi->data.s.example_start - strlen(buf);
189    //Print("Example=%ld-%ld=%d\n", pi->data.s.proc_end,
190    //  pi->data.s.example_start, procbuflen);
191    s = (char *)AllocL(procbuflen+14);
192    fread(s, procbuflen, 1, fp);
193    s[procbuflen] = '\0';
194    strcat(s+procbuflen-3, "\n;return();\n\n" );
195    p=strchr(s,'{');
196    if (p!=NULL) *s=' ';
197    return(s);
198  }
199  return NULL;
200}
201
202/*2
203* start a proc
204* parameters are built as exprlist
205* TODO:interrupt
206* return FALSE on success, TRUE if an error occurs
207*/
208BOOLEAN iiPStart(idhdl pn, sleftv  * v)
209{
210  char * str;
211  BOOLEAN err=FALSE;
212  int old_echo=si_echo;
213
214  /* init febase ======================================== */
215  /* we do not enter this case if filename != NULL !! */
216  if (pn!=NULL)
217  {
218    procinfov pi;
219    pi = IDPROC(pn);
220    if(pi!=NULL)
221    {
222      if( pi->data.s.body==NULL )
223      {
224        iiGetLibProcBuffer(IDPROC(pn));
225        if (IDPROC(pn)->data.s.body==NULL) return TRUE;
226      }
227      newBuffer( mstrdup(IDPROC(pn)->data.s.body), BT_proc,
228                 pi, IDPROC(pn)->data.s.body_lineno );
229    }
230    //else
231    //{ // for security only
232    //  newBuffer( mstrdup(IDSTRING(pn)), BT_proc, IDID(pn) );
233    //}
234  }
235  /* generate argument list ======================================*/
236  if (v!=NULL)
237  {
238    iiCurrArgs=(leftv)Alloc(sizeof(sleftv));
239    memcpy(iiCurrArgs,v,sizeof(sleftv));
240    memset(v,0,sizeof(sleftv));
241  }
242  else
243  {
244    iiCurrArgs=NULL;
245  }
246  /* start interpreter ======================================*/
247  myynest++;
248  //Print("%-*.*s PStart <<%s>>, level:%d\n",2*myynest,2*myynest," ",IDID(pn),myynest);
249  err=yyparse();
250  killlocals(myynest);
251  myynest--;
252  si_echo=old_echo;
253  //Print("%-*.*s PEnd  <<%s>>, level:%d\n",2*myynest,2*myynest," ",IDID(pn),myynest);
254
255  return err;
256}
257
258ring    *iiLocalRing
259#ifdef TEST
260                    =NULL
261#endif
262                   ;
263sleftv  *iiRETURNEXPR
264#ifdef TEST
265                    =NULL
266#endif
267                   ;
268int     iiRETURNEXPR_len=0;
269
270#ifdef RDEBUG
271static void iiShowLevRings()
272{
273  int i;
274  for (i=1;i<=myynest;i++)
275  {
276    Print("lev %d:",i);
277    if (iiLocalRing[i]==NULL) PrintS("NULL");
278    else                      Print("%d",iiLocalRing[i]);
279    Print("\n");
280  }
281  if (currRing==NULL) PrintS("curr:NULL\n");
282  else                Print ("curr:%d\n",currRing->no);
283}
284#endif
285
286static void iiCheckNest()
287{
288  if (myynest >= iiRETURNEXPR_len-1)
289  {
290    iiRETURNEXPR=(sleftv *)ReAlloc(iiRETURNEXPR,
291                                   iiRETURNEXPR_len*sizeof(sleftv),
292                                   (iiRETURNEXPR_len+16)*sizeof(sleftv));
293    iiLocalRing=(ring *)ReAlloc(iiLocalRing,
294                                   iiRETURNEXPR_len*sizeof(ring),
295                                   (iiRETURNEXPR_len+16)*sizeof(ring));
296    iiRETURNEXPR_len+=16;
297  }
298}
299sleftv * iiMake_proc(idhdl pn, sleftv* sl)
300{
301  int err;
302  procinfov pi = IDPROC(pn);
303  if(pi->is_static && myynest==0) {
304    Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
305           pi->libname, pi->procname);
306    return NULL;
307  }
308  iiCheckNest();
309  iiLocalRing[myynest]=currRing;
310  iiRETURNEXPR[myynest+1].Init();
311  if (traceit&TRACE_SHOW_PROC)
312  {
313    if (traceit&TRACE_SHOW_LINENO) PrintLn();
314    Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
315  }
316#ifdef RDEBUG
317  if (traceit&TRACE_SHOW_RINGS) iiShowLevRings();
318#endif
319#if 1
320  if(pi->language == LANG_SINGULAR) err=iiPStart(pn,sl);
321  if(pi->language == LANG_C)
322  {
323    leftv res = (leftv)Alloc0(sizeof(sleftv));
324    err = (pi->data.o.function)(res, sl);
325    iiRETURNEXPR[myynest+1].Copy(res);
326    Free((ADDRESS)res, sizeof(sleftv));
327  }
328#else
329  switch (pi->language)
330  {
331    case LANG_SINGULAR: err=iiPStart(pn,sl); break;
332    case LANG_C: leftv res = (leftv)Alloc0(sizeof(sleftv));
333      err = (pi->data.o.function)(res, sl);
334      iiRETURNEXPR[myynest+1].Copy(res);
335      Free((ADDRESS)res, sizeof(sleftv));
336      break;
337    default: err=TRUE;
338  }
339#endif
340  if (traceit&TRACE_SHOW_PROC)
341  {
342    if (traceit&TRACE_SHOW_LINENO) PrintLn();
343    Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
344  }
345#ifdef RDEBUG
346  if (traceit&TRACE_SHOW_RINGS) iiShowLevRings();
347#endif
348  if (err)
349  {
350    iiRETURNEXPR[myynest+1].CleanUp();
351    iiRETURNEXPR[myynest+1].Init();
352  }
353  if (iiLocalRing[myynest] != currRing)
354  {
355    if (((iiRETURNEXPR[myynest+1].Typ()>BEGIN_RING)
356      && (iiRETURNEXPR[myynest+1].Typ()<END_RING))
357    || ((iiRETURNEXPR[myynest+1].Typ()==LIST_CMD)
358      && (lRingDependend((lists)iiRETURNEXPR[myynest+1].Data()))))
359    {
360      //idhdl hn;
361      char *n;
362      char *o;
363      if (iiLocalRing[myynest]!=NULL) o=rFindHdl(iiLocalRing[myynest],NULL)->id;
364      else                            o="none";
365      if (currRing!=NULL)             n=rFindHdl(currRing,NULL)->id;
366      else                            n="none";
367      Werror("ring change during procedure call: %s -> %s",o,n);
368      iiRETURNEXPR[myynest+1].CleanUp();
369      err=TRUE;
370    }
371    if (iiLocalRing[myynest]!=NULL)
372    {
373      rSetHdl(rFindHdl(iiLocalRing[myynest],NULL),TRUE);
374      iiLocalRing[myynest]=NULL;
375    }
376    else
377    { currRingHdl=NULL; currRing=NULL; }
378  }
379  if (iiCurrArgs!=NULL)
380  {
381    Warn("too many arguments for %s",IDID(pn));
382    iiCurrArgs->CleanUp();
383    Free((ADDRESS)iiCurrArgs,sizeof(sleftv));
384    iiCurrArgs=NULL;
385  }
386  if (err) return NULL;
387  return &iiRETURNEXPR[myynest+1];
388}
389
390/*2
391* start an example (as a proc),
392* destroys the string 'example'
393*/
394BOOLEAN iiEStart(char* example, procinfo *pi)
395{
396  BOOLEAN err;
397  int old_echo=si_echo;
398
399  newBuffer( example, BT_example, pi, pi->data.s.example_lineno );
400  iiCheckNest();
401  iiLocalRing[myynest]=currRing;
402  if (traceit&TRACE_SHOW_PROC)
403  {
404    if (traceit&TRACE_SHOW_LINENO) printf("\n");
405    printf("entering example (level %d)\n",myynest);
406  }
407  myynest++;
408  err=yyparse();
409  killlocals(myynest);
410  myynest--;
411  si_echo=old_echo;
412  if (traceit&TRACE_SHOW_PROC)
413  {
414    if (traceit&TRACE_SHOW_LINENO) printf("\n");
415    printf("leaving  -example- (level %d)\n",myynest);
416  }
417  if (iiLocalRing[myynest] != currRing)
418  {
419    if (iiLocalRing[myynest]!=NULL)
420    {
421      rSetHdl(rFindHdl(iiLocalRing[myynest],NULL),TRUE);
422      iiLocalRing[myynest]=NULL;
423    }
424    else
425    {
426      currRingHdl=NULL;
427      currRing=NULL;
428    }
429  }
430  return err;
431}
432
433BOOLEAN iiLibCmd( char *newlib, BOOLEAN tellerror )
434{
435  char buf[256];
436  char libnamebuf[128];
437  idhdl h,hl;
438  int lines = 1;
439  long pos = 0L;
440  procinfov pi;
441  FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror );
442  if (fp==NULL)
443  {
444    return TRUE;
445  }
446  hl = idroot->get("LIB",0);
447  if (hl==NULL)
448  {
449    hl = enterid( mstrdup("LIB"),0, STRING_CMD, &idroot, FALSE );
450    IDSTRING(hl) = mstrdup(newlib);
451  }
452  else
453  {
454#ifdef TEST
455    if (IDSTRING(hl) != NULL)
456#endif
457    {
458      char *s = (char *)AllocL( strlen(newlib) + strlen(IDSTRING(hl)) + 2 );
459      strcpy(s,IDSTRING(hl));
460      BOOLEAN f=FALSE;
461      if(strchr(s,',')==NULL)
462      {
463        if (strcmp(s,newlib)==0)
464          f=TRUE;
465      }
466      else
467      {
468        char *p=strtok(s,",");
469        do
470        {
471          if(strcmp(p,newlib)==0)
472          {
473            f=TRUE;
474            break;
475          }
476          p=strtok(NULL,",");
477        } while (p!=NULL);
478      }
479      if (f)
480        FreeL(s);
481      else
482      {
483        sprintf( s, "%s,%s", IDSTRING(hl), newlib);
484        FreeL((ADDRESS)IDSTRING(hl));
485        IDSTRING(hl) = s;
486      }
487    }
488#ifdef TEST
489    else
490    {
491      PrintS("## empty LIB string\n");
492      IDSTRING(hl) = mstrdup(newlib);
493    }
494#endif
495  }
496
497#ifdef HAVE_LIBPARSER
498  extern FILE *yylpin;
499  libstackv ls_start = library_stack;
500  lib_style_types lib_style;
501
502  yylpin = fp;
503# if YYLPDEBUG > 1
504  print_init();
505#  endif
506  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loading %s...", libnamebuf);
507  yylplex(newlib, libnamebuf, &lib_style);
508  if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
509    Warn( "library %s has an old format. Please fix it for the next time",
510          newlib);
511  else {
512    if (BVERBOSE(V_LOAD_LIB)) Print("done.\n");
513  }
514  if(yylp_errno) {
515    Werror("Library %s: ERROR occured: in line %d, %d.", newlib, yylplineno,
516         current_pos(0));
517    Werror(yylp_errlist[yylp_errno], yylplineno);
518    Werror("Cannot load library,... aborting.");
519    reinit_yylp();
520    fclose( yylpin );
521    FreeL((ADDRESS)newlib);
522    return TRUE;
523  }
524  reinit_yylp();
525  fclose( yylpin );
526  {
527    libstackv ls;
528    for(ls = library_stack; (ls != NULL) && (ls != ls_start); ) {
529      if(ls->to_be_done) {
530        //Print("// Processing id %d LIB:%s\n", ls->cnt, ls->get());
531        ls->to_be_done=FALSE;
532        iiLibCmd(ls->get());
533        ls = ls->pop(newlib);
534        //Print("Done\n");
535      }
536    }
537#if 0
538    Print("--------------------\n");
539    for(ls = library_stack; ls != NULL; ls = ls->next) {
540      Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
541        ls->to_be_done ? "not loaded" : "loaded");
542    }
543    Print("--------------------\n");
544#endif
545  }
546#else /* HAVE_LIBPARSER */
547  // processing head section
548  if (fgets( buf, sizeof(buf), fp))
549  {
550    if (BVERBOSE(V_LOAD_LIB))
551    {
552      if (strncmp( buf, "// $Id", 5) == 0)
553      {
554        char ver[10];
555        char date[16];
556        ver[0]='?'; ver[1]='.'; ver[2]='?'; ver[3]='\0';
557        date[0]='?'; date[1]='\0';
558        sscanf(buf,"// %*s %*s %10s %16s",ver,date);
559        strcat(libnamebuf,"(");
560        strcat(libnamebuf,ver);
561        strcat(libnamebuf,",");
562        strcat(libnamebuf,date);
563        strcat(libnamebuf,")");
564      }
565      else
566      {
567        strcat(libnamebuf,"(**unknown version**)");
568      }
569      Warn( "loading %s", libnamebuf );
570    }
571  }
572
573  #define IN_HEADER 1
574  #define IN_BODY   2
575  #define IN_EXAMPLE      3
576  #define IN_EXAMPLE_BODY 4
577  #define IN_LIB_HEADER   5
578  int v=-1,otherLines=0,inBlock=IN_LIB_HEADER;
579  do /*while (fgets( buf, sizeof(buf), fp))*/
580  {
581    int  offset;
582    if (buf[0]!='\n')
583    {
584      if ((inBlock==0)||(inBlock==IN_LIB_HEADER))
585      {
586        if (strncmp( buf, "LIB ", 4) == 0)
587        {
588          char *s=buf+5;
589          char *f=strchr(s,'"');
590          if (f!=NULL)
591            *f='\0';
592          else
593            return TRUE;
594          // if (BVERBOSE(V_LOAD_LIB)) Print("// requires %s",s);
595          f=strstr(IDSTRING(hl),s);
596          if (f == NULL)
597          {
598            // if (BVERBOSE(V_LOAD_LIB)) PrintLn();
599            iiLibCmd(mstrdup(s));
600            // if (BVERBOSE(V_LOAD_LIB)) Print( "// loading %s\n", newlib);
601          }
602          //else if (BVERBOSE(V_LOAD_LIB)) PrintS(" -> already loaded\n");
603        }
604        else if (strncmp( buf, "proc ", 5) == 0)
605        {
606          char proc[256];
607          char ct1, *e;
608          sscanf( buf, "proc %s", proc);
609          offset = 2;
610          char *ct=strchr(proc,'(');
611          if (ct!=NULL) { *ct='\0'; offset=3; }
612          sprintf( buf, "LIB:%s", newlib);
613#if 0
614          if(strcmp(proc, "_init")==0)
615          {
616            char *p =  iiConvName(newlib);
617            Print("Init found:%s;\n", p);
618            h = enterid( mstrdup(p), myynest, PROC_CMD, &idroot, FALSE );
619            FreeL((ADDRESS)p);
620          } else
621#endif
622            h = enterid( mstrdup(proc), myynest, PROC_CMD, &idroot, FALSE );
623          if (h!=NULL)
624          {
625            iiInitSingularProcinfo(IDPROC(h),newlib,proc,lines,pos);
626            if (BVERBOSE(V_LOAD_PROC)) Warn( "     proc %s loaded", proc );
627          }
628          inBlock=IN_HEADER;
629        }
630        else if (strncmp( buf, "// ver:", 7) == 0)
631        {
632          v=0;
633          sscanf( buf+7, "%d", &v);
634          if(v!=(SINGULAR_VERSION/100))
635            Warn("version mismatch - library `%s` requires:%d.%d",
636                  newlib,v/1000,(v%1000)/100);
637        }
638        else if (strncmp( buf, "example", 7) == 0)
639        {
640          IDPROC(h)->data.s.example_start = pos;
641          IDPROC(h)->data.s.example_lineno = lines;
642          inBlock=IN_EXAMPLE;
643        }
644        else if (strncmp( buf, "//", 2) != 0)
645        {
646          if (inBlock==0)
647          {
648            otherLines++;
649          }
650        }
651      }
652      else if ((inBlock==IN_HEADER) || (inBlock==IN_EXAMPLE))
653      {
654        if (buf[0]=='{')
655        {
656          if(inBlock==IN_HEADER)
657          {
658            IDPROC(h)->data.s.body_start = pos;
659            IDPROC(h)->data.s.body_lineno = lines-offset;
660            // Print("%s: %d-%d\n", pi->procname, lines, offset);
661          }
662          inBlock=IN_BODY;
663        }
664      }
665      else if ((inBlock==IN_BODY) || (inBlock==IN_EXAMPLE_BODY))
666      {
667        if (buf[0]=='}')
668        {
669          if(IDPROC(h)->data.s.example_start==0)
670            IDPROC(h)->data.s.example_start=pos;
671          if(IDPROC(h)->data.s.body_end==0) IDPROC(h)->data.s.body_end=pos;
672          IDPROC(h)->data.s.proc_end = pos;
673          inBlock=0;
674        }
675      }
676    }
677    lines++;
678    pos = ftell(fp);
679  } while (fgets( buf, sizeof(buf), fp));
680  fclose( fp );
681
682  //if (h!=NULL) IDPROC(h) = pi;
683  if (BVERBOSE(V_DEBUG_LIB))
684  {
685    if (inBlock!=0)
686      Warn("LIB `%s` ends within block",newlib);
687    if (otherLines!=0)
688      Warn("%d lines not recognised in LIB `%s`",otherLines,newlib);
689    if(v==-1)
690      Warn("LIB `%s` has no version flag",newlib);
691  }
692#endif /* HAVE_LIBPARSER */
693  FreeL((ADDRESS)newlib);
694  return FALSE;
695}
696
697procinfo *iiInitSingularProcinfo(procinfov pi, char *libname, char *procname,
698                                 int line, long pos, BOOLEAN pstatic)
699{
700  pi->libname = mstrdup(libname);
701
702  if( strcmp(procname,"_init")==0)
703  {
704    char *p = iiConvName(libname);
705    pi->procname = mstrdup(p);
706    FreeL((ADDRESS)p);
707  } else pi->procname = mstrdup(procname);
708  pi->language = LANG_SINGULAR;
709  pi->ref = 1;
710  pi->is_static = pstatic;
711  pi->data.s.proc_start = pos;
712  pi->data.s.help_start = 0L;
713  pi->data.s.body_start = 0L;
714  pi->data.s.body_end   = 0L;
715  pi->data.s.example_start = 0L;
716  pi->data.s.proc_lineno = line;
717  pi->data.s.body_lineno = 0;
718  pi->data.s.example_lineno = 0;
719  pi->data.s.body = NULL;
720  return(pi);
721}
722
723/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
724char *iiConvName(char *libname)
725{
726  char *p = (char *)AllocL(strlen(libname)+7);
727  char *q = mstrdup(libname);
728  char *r = q;
729  for(; *r!='\0'; r++)
730  {
731    if(*r=='.') *r='_';
732    if(*r==':') *r='_';
733  }
734  sprintf(p, "%s_init\0", q);
735  FreeL((ADDRESS)q);
736  return(p);
737}
738
739/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
740void piShowProcList()
741{
742  idhdl h;
743  procinfo *proc;
744  char *name;
745
746  Print( "%-15s  %20s      %s,%s  %s,%s   %s,%s\n", "Library", "function",
747         "line", "start", "line", "body", "line", "example");
748  for(h = idroot; h != NULL; h = IDNEXT(h))
749  {
750    if(IDTYP(h) == PROC_CMD)
751    {
752      proc = IDPROC(h);
753      if(strcmp(proc->procname, IDID(h))!=0)
754      {
755        name = (char *)AllocL(strlen(IDID(h))+strlen(proc->procname)+4);
756        sprintf(name, "%s -> %s", IDID(h), proc->procname);
757        Print( "%-15s  %20s ", proc->libname, name);
758        FreeL(name);
759      }
760      else
761        Print( "%-15s  %20s ", proc->libname, proc->procname);
762      if(proc->language==LANG_SINGULAR)
763        Print("line %4d,%-5ld  %4d,%-5ld  %4d,%-5ld\n",
764              proc->data.s.proc_lineno, proc->data.s.proc_start,
765              proc->data.s.body_lineno, proc->data.s.body_start,
766              proc->data.s.example_lineno, proc->data.s.example_start);
767      else if(proc->language==LANG_C)
768        Print("type: object\n");
769
770    }
771  }
772}
773
774/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
775//char *iiLineNo(char *procname, int lineno)
776//{
777//  char buf[256];
778//  idhdl pn = ggetid(procname);
779//  procinfo *pi = IDPROC(pn);
780//
781//  sprintf(buf, "%s %3d\0", procname, lineno);
782//  //sprintf(buf, "%s::%s %3d\0", pi->libname, pi->procname,
783//  //  lineno + pi->data.s.body_lineno);
784//  return(buf);
785//}
786/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
787#ifdef HAVE_LIBPARSER
788void libstack::push(char *p, char *libname)
789{
790  idhdl hl = idroot->get("LIB",0);
791  libstackv lp;
792  char *f = NULL;
793  if(hl!=NULL) f = strstr(IDSTRING(hl),libname);
794  if( (hl==NULL) || (f == NULL)) {
795    for(lp = this;lp!=NULL;lp=lp->next) {
796      if(strcmp(lp->get(), libname)==0) break;
797    }
798    if(lp==NULL) {
799      libstackv ls = (libstack *)Alloc0(sizeof(libstack));
800      ls->next = this;
801      ls->libname = mstrdup(libname);
802      ls->to_be_done = TRUE;
803      if(this != NULL) ls->cnt = this->cnt+1; else ls->cnt = 0;
804      library_stack = ls;
805    }
806  }
807}
808
809libstackv libstack::pop(char *p)
810{
811  libstackv ls = this;
812  //FreeL(ls->libname);
813  library_stack = ls->next;
814  Free((ADDRESS)ls, sizeof(libstack));
815  return(library_stack);
816}
817
818#endif /* HAVE_LIBPARSER */
819/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
Note: See TracBrowser for help on using the repository browser.