source: git/Singular/iplib.cc @ 42f2ad

spielwiese
Last change on this file since 42f2ad was aee346d, checked in by Hans Schoenemann <hannes@…>, 10 years ago
chg: debug message: also for proc outside of libs
  • Property mode set to 100644
File size: 36.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT: interpreter: LIB and help
6*/
7
8#ifdef HAVE_CONFIG_H
9#include "singularconfig.h"
10#endif /* HAVE_CONFIG_H */
11
12#include <kernel/mod2.h>
13
14#include <Singular/tok.h>
15#include <misc/options.h>
16#include <Singular/ipid.h>
17#include <omalloc/omalloc.h>
18#include <kernel/febase.h>
19#include <polys/monomials/ring.h>
20#include <Singular/subexpr.h>
21#include <Singular/ipshell.h>
22#include <Singular/lists.h>
23
24//#include <stdlib.h>
25#include <stdio.h>
26#include <string.h>
27#include <ctype.h>
28#include <sys/stat.h>
29
30
31#if SIZEOF_LONG == 8
32#define SI_MAX_NEST 500
33#elif defined(ix86_Win)
34#define SI_MAX_NEST 480
35#else
36#define SI_MAX_NEST 1000
37#endif
38
39#if defined(ix86Mac_darwin) || defined(x86_64Mac_darwin) || defined(ppcMac_darwin)
40#  define MODULE_SUFFIX bundle
41#elif defined(ix86_Win)
42#  define MODULE_SUFFIX dll
43#else
44#  define MODULE_SUFFIX so
45#endif
46
47#define MODULE_SUFFIX_STRING EXPANDED_STRINGIFY(MODULE_SUFFIX)
48
49
50#ifdef HAVE_DYNAMIC_LOADING
51BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport);
52#endif
53
54#ifdef HAVE_LIBPARSER
55#  include "libparse.h"
56#else /* HAVE_LIBPARSER */
57procinfo *iiInitSingularProcinfo(procinfov pi, const char *libname,
58              const char *procname, int line, long pos, BOOLEAN pstatic=FALSE);
59#endif /* HAVE_LIBPARSER */
60#define NS_LRING (procstack->cRing)
61
62extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval,
63                         short nToktype, short nPos);
64
65#include <Singular/mod_lib.h>
66
67#ifdef HAVE_LIBPARSER
68void yylprestart (FILE *input_file );
69int current_pos(int i=0);
70extern int yylp_errno;
71extern int yylplineno;
72extern char *yylp_errlist[];
73void print_init();
74libstackv library_stack;
75#endif
76
77//int IsCmd(char *n, int tok);
78char mytolower(char c);
79
80/*2
81* return TRUE if the libray libname is already loaded
82*/
83BOOLEAN iiGetLibStatus(char *lib)
84{
85  idhdl hl;
86
87  char *plib = iiConvName(lib);
88  hl = basePack->idroot->get(plib,0);
89  omFree(plib);
90  if((hl==NULL) ||(IDTYP(hl)!=PACKAGE_CMD))
91  {
92    return FALSE;
93  }
94  return (strcmp(lib,IDPACKAGE(hl)->libname)==0);
95}
96
97/*2
98* find the library of an proc:
99*  => return (pi->libname)
100*/
101char * iiGetLibName(procinfov pi)
102{
103  return pi->libname;
104}
105
106/*2
107* given a line 'proc[ ]+{name}[ \t]*'
108* return a pointer to name and set the end of '\0'
109* changes the input!
110* returns: e: pointer to 'end of name'
111*          ct: changed char at the end of s
112*/
113char* iiProcName(char *buf, char & ct, char* &e)
114{
115  char *s=buf+5;
116  while (*s==' ') s++;
117  e=s+1;
118  while ((*e>' ') && (*e!='(')) e++;
119  ct=*e;
120  *e='\0';
121  return s;
122}
123
124/*2
125* given a line with args, return the argstr
126*/
127char * iiProcArgs(char *e,BOOLEAN withParenth)
128{
129  while ((*e==' ') || (*e=='\t') || (*e=='(')) e++;
130  if (*e<' ')
131  {
132    if (withParenth)
133    {
134      // no argument list, allow list #
135      return omStrDup("parameter list #;");
136    }
137    else
138    {
139      // empty list
140      return omStrDup("");
141    }
142  }
143  BOOLEAN in_args;
144  BOOLEAN args_found;
145  char *s;
146  char *argstr=(char *)omAlloc(127); // see ../omalloc/omTables.inc
147  int argstrlen=127;
148  *argstr='\0';
149  int par=0;
150  do
151  {
152    args_found=FALSE;
153    s=e; // set s to the starting point of the arg
154         // and search for the end
155    while(*s==' ') s++; e=s; // skip leading paces
156    while ((*e!=',')
157    &&((par!=0) || (*e!=')'))
158    &&(*e!='\0'))
159    {
160      if (*e=='(') par++;
161      else if (*e==')') par--;
162      args_found=args_found || (*e>' ');
163      e++;
164    }
165    in_args=(*e==',');
166    if (args_found)
167    {
168      *e='\0';
169      // check for space:
170      if ((int)strlen(argstr)+12 /* parameter + ;*/ +(int)strlen(s)>= argstrlen)
171      {
172        argstrlen*=2;
173        char *a=(char *)omAlloc( argstrlen);
174        strcpy(a,argstr);
175        omFree((ADDRESS)argstr);
176        argstr=a;
177      }
178      // copy the result to argstr
179      if(strncmp(s,"alias ",6)!=0)
180      {
181        strcat(argstr,"parameter ");
182      }
183      strcat(argstr,s);
184      strcat(argstr,"; ");
185      e++; // e was pointing to ','
186    }
187  } while (in_args);
188  return argstr;
189}
190
191/*2
192* locate `procname` in lib `libname` and find the part `part`:
193*  part=0: help, between, but excluding the line "proc ..." and "{...":
194*    => return
195*  part=1: body, between "{ ..." and "}", including the 1. line, w/o "{"
196*    => set pi->data.s.body, return NULL
197*  part=2: example, between, but excluding the line "exapmle {..." and "}":
198*    => return
199*/
200char* iiGetLibProcBuffer(procinfo *pi, int part )
201{
202  char buf[256], *s = NULL, *p;
203  long procbuflen;
204
205  FILE * fp = feFopen( pi->libname, "rb", NULL, TRUE );
206  if (fp==NULL)
207  {
208    return NULL;
209  }
210
211  fseek(fp, pi->data.s.proc_start, SEEK_SET);
212  if(part==0)
213  { // load help string
214    int i, offset=0;
215    long head = pi->data.s.def_end - pi->data.s.proc_start;
216    procbuflen = pi->data.s.help_end - pi->data.s.help_start;
217    if (procbuflen<5)
218    {
219      fclose(fp);
220      return NULL; // help part does not exist
221    }
222    //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start,
223    //    pi->data.s.proc_start, procbuflen);
224    s = (char *)omAlloc(procbuflen+head+3);
225    myfread(s, head, 1, fp);
226    s[head] = '\n';
227    fseek(fp, pi->data.s.help_start, SEEK_SET);
228    myfread(s+head+1, procbuflen, 1, fp);
229    fclose(fp);
230    s[procbuflen+head+1] = '\n';
231    s[procbuflen+head+2] = '\0';
232    offset=0;
233    for(i=0;i<=procbuflen+head+2; i++)
234    {
235      if(s[i]=='\\' &&
236         (s[i+1]=='"' || s[i+1]=='{' || s[i+1]=='}' || s[i+1]=='\\'))
237      {
238        i++;
239        offset++;
240      }
241      if(offset>0) s[i-offset] = s[i];
242    }
243    return(s);
244  }
245  else if(part==1)
246  { // load proc part - must exist
247    procbuflen = pi->data.s.def_end - pi->data.s.proc_start;
248    char *ss=(char *)omAlloc(procbuflen+2);
249    //fgets(buf, sizeof(buf), fp);
250    myfread( ss, procbuflen, 1, fp);
251    char ct;
252    char *e;
253    s=iiProcName(ss,ct,e);
254    char *argstr=NULL;
255    *e=ct;
256    argstr=iiProcArgs(e,TRUE);
257
258    assume(pi->data.s.body_end > pi->data.s.body_start);
259
260    procbuflen = pi->data.s.body_end - pi->data.s.body_start;
261    pi->data.s.body = (char *)omAlloc( strlen(argstr)+procbuflen+15+
262                                      strlen(pi->libname) );
263    //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end,
264    //    pi->data.s.body_start, procbuflen);
265    assume(pi->data.s.body != NULL);
266    fseek(fp, pi->data.s.body_start, SEEK_SET);
267    strcpy(pi->data.s.body,argstr);
268    myfread( pi->data.s.body+strlen(argstr), procbuflen, 1, fp);
269    fclose( fp );
270    procbuflen+=strlen(argstr);
271    omFree(argstr);
272    omFree(ss);
273    pi->data.s.body[procbuflen] = '\0';
274    strcat( pi->data.s.body+procbuflen, "\n;return();\n\n" );
275    strcat( pi->data.s.body+procbuflen+13,pi->libname);
276    s=(char *)strchr(pi->data.s.body,'{');
277    if (s!=NULL) *s=' ';
278    return NULL;
279  }
280  else if(part==2)
281  { // example
282    if ( pi->data.s.example_lineno == 0)
283      return NULL; // example part does not exist
284    // load example
285    fseek(fp, pi->data.s.example_start, SEEK_SET);
286    /*char *dummy=*/ (void) fgets(buf, sizeof(buf), fp); // skip line with "example"
287    procbuflen = pi->data.s.proc_end - pi->data.s.example_start - strlen(buf);
288    //Print("Example=%ld-%ld=%d\n", pi->data.s.proc_end,
289    //  pi->data.s.example_start, procbuflen);
290    s = (char *)omAlloc(procbuflen+14);
291    myfread(s, procbuflen, 1, fp);
292    s[procbuflen] = '\0';
293    strcat(s+procbuflen-3, "\n;return();\n\n" );
294    p=(char *)strchr(s,'{');
295    if (p!=NULL) *p=' ';
296    return(s);
297  }
298  return NULL;
299}
300#ifndef LIBSINGULAR
301// see below:
302struct soptionStruct
303{
304  const char * name;
305  unsigned   setval;
306  unsigned   resetval;
307};
308extern struct soptionStruct optionStruct[];
309extern struct soptionStruct verboseStruct[];
310#endif
311
312BOOLEAN iiAllStart(procinfov pi, char *p,feBufferTypes t, int l)
313{
314  newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/,
315               pi, l );
316  #ifndef LIBSINGULAR
317  // see below:
318  BITSET save1=(test & ~TEST_RINGDEP_OPTS);
319  BITSET save2=verbose;
320  #endif
321  BOOLEAN err=yyparse();
322  if (sLastPrinted.rtyp!=0)
323  {
324    sLastPrinted.CleanUp();
325  }
326  #ifndef LIBSINGULAR
327  // the access to optionStruct and verboseStruct do not work
328  // on x86_64-Linux for pic-code
329  BITSET save11= ( test & ~TEST_RINGDEP_OPTS);
330  if ((TEST_V_ALLWARN) &&
331  (t==BT_proc) &&
332  ((save1!=save11)||(save2!=verbose)) &&
333  (pi->libname!=NULL) && (pi->libname[0]!='\0'))
334  {
335    if ((pi->libname!=NULL) && (pi->libname[0]!='\0'))
336      Warn("option changed in proc %s from %s",pi->procname,pi->libname);
337    else
338      Warn("option changed in proc %s",pi->procname);
339    int i;
340    for (i=0; optionStruct[i].setval!=0; i++)
341    {
342      if ((optionStruct[i].setval & save11)
343      && (!(optionStruct[i].setval & save1)))
344      {
345          Print(" +%s",optionStruct[i].name);
346      }
347      if (!(optionStruct[i].setval & save11)
348      && ((optionStruct[i].setval & save1)))
349      {
350          Print(" -%s",optionStruct[i].name);
351      }
352    }
353    for (i=0; verboseStruct[i].setval!=0; i++)
354    {
355      if ((verboseStruct[i].setval & verbose)
356      && (!(verboseStruct[i].setval & save2)))
357      {
358          Print(" +%s",verboseStruct[i].name);
359      }
360      if (!(verboseStruct[i].setval & verbose)
361      && ((verboseStruct[i].setval & save2)))
362      {
363          Print(" -%s",verboseStruct[i].name);
364      }
365    }
366    PrintLn();
367  }
368  #endif
369  return err;
370}
371/*2
372* start a proc
373* parameters are built as exprlist
374* TODO:interrupt
375* return FALSE on success, TRUE if an error occurs
376*/
377BOOLEAN iiPStart(idhdl pn, sleftv  * v)
378{
379  procinfov pi=NULL;
380  int old_echo=si_echo;
381  BOOLEAN err=FALSE;
382  char save_flags=0;
383
384  /* init febase ======================================== */
385  /* we do not enter this case if filename != NULL !! */
386  if (pn!=NULL)
387  {
388    pi = IDPROC(pn);
389    if(pi!=NULL)
390    {
391      save_flags=pi->trace_flag;
392      if( pi->data.s.body==NULL )
393      {
394        iiGetLibProcBuffer(pi);
395        if (pi->data.s.body==NULL) return TRUE;
396      }
397//      omUpdateInfo();
398//      int m=om_Info.UsedBytes;
399//      Print("proc %s, mem=%d\n",IDID(pn),m);
400    }
401  }
402  else return TRUE;
403  /* generate argument list ======================================*/
404  if (v!=NULL)
405  {
406    iiCurrArgs=(leftv)omAllocBin(sleftv_bin);
407    memcpy(iiCurrArgs,v,sizeof(sleftv));
408    memset(v,0,sizeof(sleftv));
409  }
410  else
411  {
412    iiCurrArgs=NULL;
413  }
414  iiCurrProc=pn;
415  /* start interpreter ======================================*/
416  myynest++;
417  if (myynest > SI_MAX_NEST)
418  {
419    WerrorS("nesting too deep");
420    err=TRUE;
421  }
422  else
423  {
424    err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
425
426    //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
427    killlocals(myynest);
428#ifndef NDEBUG
429    checkall();
430#endif
431    //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
432  }
433  myynest--;
434  si_echo=old_echo;
435  if (pi!=NULL)
436    pi->trace_flag=save_flags;
437//  omUpdateInfo();
438//  int m=om_Info.UsedBytes;
439//  Print("exit %s, mem=%d\n",IDID(pn),m);
440  return err;
441}
442
443#ifdef USE_IILOCALRING
444ring    *iiLocalRing;
445#endif
446sleftv  iiRETURNEXPR;
447int     iiRETURNEXPR_len=0;
448
449#ifdef RDEBUG
450static void iiShowLevRings()
451{
452  int i;
453#ifdef USE_IILOCALRING
454  for (i=0;i<=myynest;i++)
455  {
456    Print("lev %d:",i);
457    if (iiLocalRing[i]==NULL) PrintS("NULL");
458    else                      Print("%lx",(long)iiLocalRing[i]);
459    PrintLn();
460  }
461#endif
462#if  0
463  i=myynest;
464  proclevel *p=procstack;
465  while (p!=NULL)
466  {
467    Print("lev %d:",i);
468    if (p->cRingHdl==NULL) PrintS("NULL");
469    else                   Print("%s",IDID(p->cRingHdl));
470    PrintLn();
471    p=p->next;
472  }
473#endif
474  if (currRing==NULL) PrintS("curr:NULL\n");
475  else                Print ("curr:%lx\n",(long)currRing);
476}
477#endif /* RDEBUG */
478
479static void iiCheckNest()
480{
481  if (myynest >= iiRETURNEXPR_len-1)
482  {
483#ifdef USE_IILOCALRING
484    iiLocalRing=(ring *)omreallocSize(iiLocalRing,
485                                   iiRETURNEXPR_len*sizeof(ring),
486                                   (iiRETURNEXPR_len+16)*sizeof(ring));
487    memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
488#endif
489    iiRETURNEXPR_len+=16;
490  }
491}
492BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv* sl)
493{
494  int err;
495  procinfov pi = IDPROC(pn);
496  if(pi->is_static && myynest==0)
497  {
498    Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
499           pi->libname, pi->procname);
500    return TRUE;
501  }
502  iiCheckNest();
503#ifdef USE_IILOCALRING
504  iiLocalRing[myynest]=currRing;
505  //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
506#endif
507  iiRETURNEXPR.Init();
508  procstack->push(pi->procname);
509  if ((traceit&TRACE_SHOW_PROC)
510  || (pi->trace_flag&TRACE_SHOW_PROC))
511  {
512    if (traceit&TRACE_SHOW_LINENO) PrintLn();
513    Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
514  }
515#ifdef RDEBUG
516  if (traceit&TRACE_SHOW_RINGS) iiShowLevRings();
517#endif
518  switch (pi->language)
519  {
520    default:
521    case LANG_NONE:
522                 WerrorS("undefined proc");
523                 err=TRUE;
524                 break;
525
526    case LANG_SINGULAR:
527                 if ((pi->pack!=NULL)&&(currPack!=pi->pack))
528                 {
529                   currPack=pi->pack;
530                   iiCheckPack(currPack);
531                   currPackHdl=packFindHdl(currPack);
532                   //Print("set pack=%s\n",IDID(currPackHdl));
533                 }
534                 else if ((pack!=NULL)&&(currPack!=pack))
535                 {
536                   currPack=pack;
537                   iiCheckPack(currPack);
538                   currPackHdl=packFindHdl(currPack);
539                   //Print("set pack=%s\n",IDID(currPackHdl));
540                 }
541                 err=iiPStart(pn,sl);
542                 break;
543    case LANG_C:
544                 leftv res = (leftv)omAlloc0Bin(sleftv_bin);
545                 err = (pi->data.o.function)(res, sl);
546                 memcpy(&iiRETURNEXPR,res,sizeof(iiRETURNEXPR));
547                 omFreeBin((ADDRESS)res,  sleftv_bin);
548                 break;
549  }
550  if ((traceit&TRACE_SHOW_PROC)
551  || (pi->trace_flag&TRACE_SHOW_PROC))
552  {
553    if (traceit&TRACE_SHOW_LINENO) PrintLn();
554    Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
555  }
556  //char *n="NULL";
557  //if (currRingHdl!=NULL) n=IDID(currRingHdl);
558  //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
559#ifdef RDEBUG
560  if (traceit&TRACE_SHOW_RINGS) iiShowLevRings();
561#endif
562  if (err)
563  {
564    iiRETURNEXPR.CleanUp();
565    //iiRETURNEXPR.Init(); //done by CleanUp
566  }
567#ifdef USE_IILOCALRING
568#if 0
569  if(procstack->cRing != iiLocalRing[myynest]) Print("iiMake_proc: 1 ring not saved procs:%x, iiLocal:%x\n",procstack->cRing, iiLocalRing[myynest]);
570#endif
571  if (iiLocalRing[myynest] != currRing)
572  {
573    if (currRing!=NULL)
574    {
575      if (((iiRETURNEXPR.Typ()>BEGIN_RING)
576        && (iiRETURNEXPR.Typ()<END_RING))
577      || ((iiRETURNEXPR.Typ()==LIST_CMD)
578        && (lRingDependend((lists)iiRETURNEXPR.Data()))))
579      {
580        //idhdl hn;
581        const char *n;
582        const char *o;
583        idhdl nh=NULL, oh=NULL;
584        if (iiLocalRing[myynest]!=NULL)
585          oh=rFindHdl(iiLocalRing[myynest],NULL, NULL);
586        if (oh!=NULL)          o=oh->id;
587        else                   o="none";
588        if (currRing!=NULL)
589          nh=rFindHdl(currRing,NULL, NULL);
590        if (nh!=NULL)          n=nh->id;
591        else                   n="none";
592        Werror("ring change during procedure call: %s -> %s (level %d)",o,n,myynest);
593        iiRETURNEXPR.CleanUp();
594        err=TRUE;
595      }
596    }
597    currRing=iiLocalRing[myynest];
598  }
599  if ((currRing==NULL)
600  && (currRingHdl!=NULL))
601    currRing=IDRING(currRingHdl);
602  else
603  if ((currRing!=NULL) &&
604    ((currRingHdl==NULL)||(IDRING(currRingHdl)!=currRing)
605     ||(IDLEV(currRingHdl)>=myynest)))
606  {
607    rSetHdl(rFindHdl(currRing,NULL, NULL));
608    iiLocalRing[myynest]=NULL;
609  }
610#else /* USE_IILOCALRING */
611  if (procstack->cRing != currRing)
612  {
613    //if (procstack->cRingHdl!=NULL)
614    //Print("procstack:%s,",IDID(procstack->cRingHdl));
615    //if (currRingHdl!=NULL)
616    //Print(" curr:%s\n",IDID(currRingHdl));
617    //Print("pr:%x, curr: %x\n",procstack->cRing,currRing);
618    if (((iiRETURNEXPR.Typ()>BEGIN_RING)
619      && (iiRETURNEXPR.Typ()<END_RING))
620    || ((iiRETURNEXPR.Typ()==LIST_CMD)
621      && (lRingDependend((lists)iiRETURNEXPR.Data()))))
622    {
623      //idhdl hn;
624      char *n;
625      char *o;
626      if (procstack->cRing!=NULL)
627      {
628        //PrintS("reset ring\n");
629        procstack->cRingHdl=rFindHdl(procstack->cRing,NULL, NULL);
630        if (procstack->cRingHdl==NULL)
631          procstack->cRingHdl=
632           rFindHdl(procstack->cRing,NULL,procstack->currPack->idroot);
633        if (procstack->cRingHdl==NULL)
634          procstack->cRingHdl=
635           rFindHdl(procstack->cRing,NULL,basePack->idroot);
636        o=IDID(procstack->cRingHdl);
637        currRing=procstack->cRing;
638        currRingHdl=procstack->cRingHdl;
639      }
640      else                            o="none";
641      if (currRing!=NULL)             n=IDID(currRingHdl);
642      else                            n="none";
643      if (currRing==NULL)
644      {
645        Werror("ring change during procedure call: %s -> %s",o,n);
646        iiRETURNEXPR.CleanUp();
647        err=TRUE;
648      }
649    }
650    if (procstack->cRingHdl!=NULL)
651    {
652      rSetHdl(procstack->cRingHdl);
653    }
654    else
655    { currRingHdl=NULL; currRing=NULL; }
656  }
657#endif /* USE_IILOCALRING */
658  if (iiCurrArgs!=NULL)
659  {
660    if (!err) Warn("too many arguments for %s",IDID(pn));
661    iiCurrArgs->CleanUp();
662    omFreeBin((ADDRESS)iiCurrArgs, sleftv_bin);
663    iiCurrArgs=NULL;
664  }
665  procstack->pop();
666  if (err)
667    return TRUE;
668  return FALSE;
669}
670
671/*2
672* start an example (as a proc),
673* destroys the string 'example'
674*/
675BOOLEAN iiEStart(char* example, procinfo *pi)
676{
677  BOOLEAN err;
678  int old_echo=si_echo;
679
680  iiCheckNest();
681  procstack->push(example);
682#ifdef USE_IILOCALRING
683  iiLocalRing[myynest]=currRing;
684#endif
685  if (traceit&TRACE_SHOW_PROC)
686  {
687    if (traceit&TRACE_SHOW_LINENO) printf("\n");
688    printf("entering example (level %d)\n",myynest);
689  }
690  myynest++;
691
692  err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
693
694  killlocals(myynest);
695  myynest--;
696  si_echo=old_echo;
697  if (traceit&TRACE_SHOW_PROC)
698  {
699    if (traceit&TRACE_SHOW_LINENO) printf("\n");
700    printf("leaving  -example- (level %d)\n",myynest);
701  }
702#ifdef USE_IILOCALRING
703  if (iiLocalRing[myynest] != currRing)
704  {
705    if (iiLocalRing[myynest]!=NULL)
706    {
707      rSetHdl(rFindHdl(iiLocalRing[myynest],NULL, NULL));
708      iiLocalRing[myynest]=NULL;
709    }
710    else
711    {
712      currRingHdl=NULL;
713      currRing=NULL;
714    }
715  }
716#else /* USE_IILOCALRING */
717#endif /* USE_IILOCALRING */
718  if (NS_LRING != currRing)
719  {
720    if (NS_LRING!=NULL)
721    {
722      idhdl rh=procstack->cRingHdl;
723      if ((rh==NULL)||(IDRING(rh)!=NS_LRING))
724        rh=rFindHdl(NS_LRING,NULL, NULL);
725      rSetHdl(rh);
726    }
727    else
728    {
729      currRingHdl=NULL;
730      currRing=NULL;
731    }
732  }
733//#endif /* USE_IILOCALRING */
734  procstack->pop();
735  return err;
736}
737
738int SI_MOD_INIT(staticdemo)(SModulFunctions*){ PrintS("init of staticdemo\n"); return (0); }
739
740#define SI_GET_BUILTIN_MOD_INIT(name) \
741 if (strcmp(libname, #name ".so") == 0){ int SI_MOD_INIT(name)(SModulFunctions*); return SI_MOD_INIT(name); }
742
743SModulFunc_t
744iiGetBuiltinModInit(const char* libname)
745{
746  SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT)
747
748  return NULL;
749}
750
751
752#undef SI_GET_BUILTIN_MOD_INIT
753
754
755/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
756BOOLEAN iiTryLoadLib(leftv v, const char *id)
757{
758  BOOLEAN LoadResult = TRUE;
759  char libnamebuf[128];
760  char *libname = (char *)omAlloc(strlen(id)+5);
761  const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
762  int i = 0;
763  // FILE *fp;
764  // package pack;
765  // idhdl packhdl;
766  lib_types LT;
767  for(i=0; suffix[i] != NULL; i++)
768  {
769    sprintf(libname, "%s%s", id, suffix[i]);
770    *libname = mytolower(*libname);
771    if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
772    {
773      char *s=omStrDup(libname);
774      char libnamebuf[256];
775
776      if (LT==LT_SINGULAR)
777        LoadResult = iiLibCmd(s, FALSE, FALSE,TRUE);
778      #ifdef HAVE_DYNAMIC_LOADING
779      else if ((LT==LT_ELF) || (LT==LT_HPUX))
780        LoadResult = load_modules(s,libnamebuf,FALSE);
781      #endif
782      else if (LT==LT_BUILTIN)
783      {
784        LoadResult=load_builtin(s,FALSE, iiGetBuiltinModInit(s));
785      }
786      if(!LoadResult )
787      {
788        v->name = iiConvName(libname);
789        break;
790      }
791    }
792  }
793  omFree(libname);
794  return LoadResult;
795}
796
797/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
798/* check, if library lib has already been loaded
799   if yes, writes filename of lib into where and returns TRUE,
800      no, returns FALSE
801*/
802BOOLEAN iiLocateLib(const char* lib, char* where)
803{
804  idhdl hl;
805
806  char *p;
807
808  hl = IDROOT->get("LIB", 0);
809  if (hl == NULL || (p=strstr(IDSTRING(hl), lib)) == NULL) return FALSE;
810  if ((p!=IDSTRING(hl)) && (*(p-1)!=',')) return FALSE;
811
812  if (strstr(IDSTRING(hl), ",") == NULL)
813  {
814    strcpy(where, IDSTRING(hl));
815  }
816  else
817  {
818    char* tmp = omStrDup(IDSTRING(hl));
819    char* tok = strtok(tmp, ",");
820    do
821    {
822      if (strstr(tok, lib) != NULL) break;
823      tok = strtok(NULL, ",");
824    }
825    while (tok != NULL);
826    assume(tok != NULL);
827    strcpy(where, tok);
828    omFree(tmp);
829  }
830  return TRUE;
831}
832
833BOOLEAN iiLibCmd( char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force )
834{
835  char libnamebuf[128];
836  // procinfov pi;
837  // idhdl h;
838  idhdl pl;
839  // idhdl hl;
840  // long pos = 0L;
841  char *plib = iiConvName(newlib);
842  FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror );
843  // int lines = 1;
844  BOOLEAN LoadResult = TRUE;
845
846  if (fp==NULL)
847  {
848    return TRUE;
849  }
850  pl = basePack->idroot->get(plib,0);
851  if (pl==NULL)
852  {
853    pl = enterid( plib,0, PACKAGE_CMD,
854                  &(basePack->idroot), TRUE );
855    IDPACKAGE(pl)->language = LANG_SINGULAR;
856    IDPACKAGE(pl)->libname=omStrDup(newlib);
857  }
858  else
859  {
860    if(IDTYP(pl)!=PACKAGE_CMD)
861    {
862      WarnS("not of type package.");
863      fclose(fp);
864      return TRUE;
865    }
866    if (!force) return FALSE;
867  }
868  LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
869  omFree((ADDRESS)newlib);
870
871  if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
872  omFree((ADDRESS)plib);
873
874 return LoadResult;
875}
876/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
877static void iiCleanProcs(idhdl &root)
878{
879  idhdl prev=NULL;
880  loop
881  {
882    if (root==NULL) return;
883    if (IDTYP(root)==PROC_CMD)
884    {
885      procinfo *pi=(procinfo*)IDDATA(root);
886      if ((pi->language == LANG_SINGULAR)
887      && (pi->data.s.body_start == 0L))
888      {
889        // procinfo data incorrect:
890        // - no proc body can start at the beginning of the file
891        killhdl(root);
892        if (prev==NULL)
893          root=IDROOT;
894        else
895        {
896          root=prev;
897          prev=NULL;
898        }
899        continue;
900      }
901    }
902    prev=root;
903    root=IDNEXT(root);
904  }
905}
906static void iiRunInit(package p)
907{
908  idhdl h=p->idroot->get("mod_init",0);
909  if (h==NULL) return;
910  if (IDTYP(h)==PROC_CMD)
911  {
912    int save=yylineno;
913    myynest++;
914    // procinfo *pi=(procinfo*)IDDATA(h);
915    //PrintS("mod_init found\n");
916    iiMake_proc(h,p,NULL);
917    myynest--;
918    yylineno=save;
919  }
920}
921/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
922BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char*newlib,
923             idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
924{
925  extern FILE *yylpin;
926  libstackv ls_start = library_stack;
927  lib_style_types lib_style;
928
929  yylpin = fp;
930  #if YYLPDEBUG > 1
931  print_init();
932  #endif
933  extern int lpverbose;
934  if (BVERBOSE(V_DEBUG_LIB)) lpverbose=1;
935  else lpverbose=0;
936  // yylplex sets also text_buffer
937  if (text_buffer!=NULL) *text_buffer='\0';
938  yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
939  if(yylp_errno)
940  {
941    Werror("Library %s: ERROR occured: in line %d, %d.", newlib, yylplineno,
942         current_pos(0));
943    if(yylp_errno==YYLP_BAD_CHAR)
944    {
945      Werror(yylp_errlist[yylp_errno], *text_buffer, yylplineno);
946      omFree((ADDRESS)text_buffer);
947      text_buffer=NULL;
948    }
949    else
950      Werror(yylp_errlist[yylp_errno], yylplineno);
951    Werror("Cannot load library,... aborting.");
952    reinit_yylp();
953    fclose( yylpin );
954    iiCleanProcs(IDROOT);
955    return TRUE;
956  }
957  if (BVERBOSE(V_LOAD_LIB))
958    Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
959  if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
960  {
961    Warn( "library %s has old format. This format is still accepted,", newlib);
962    Warn( "but for functionality you may wish to change to the new");
963    Warn( "format. Please refer to the manual for further information.");
964  }
965  reinit_yylp();
966  fclose( yylpin );
967  fp = NULL;
968  iiRunInit(IDPACKAGE(pl));
969
970  {
971    libstackv ls;
972    for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
973    {
974      if(ls->to_be_done)
975      {
976        ls->to_be_done=FALSE;
977        iiLibCmd(ls->get(),autoexport,tellerror,FALSE);
978        ls = ls->pop(newlib);
979      }
980    }
981#if 0
982    PrintS("--------------------\n");
983    for(ls = library_stack; ls != NULL; ls = ls->next)
984    {
985      Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
986        ls->to_be_done ? "not loaded" : "loaded");
987    }
988    PrintS("--------------------\n");
989#endif
990  }
991
992  if(fp != NULL) fclose(fp);
993  return FALSE;
994}
995
996
997/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
998procinfo *iiInitSingularProcinfo(procinfov pi, const char *libname,
999              const char *procname, int line, long pos, BOOLEAN pstatic)
1000{
1001  pi->libname = omStrDup(libname);
1002
1003  if( strcmp(procname,"_init")==0)
1004  {
1005    pi->procname = iiConvName(libname);
1006  }
1007  else
1008    pi->procname = omStrDup(procname);
1009  pi->language = LANG_SINGULAR;
1010  pi->ref = 1;
1011  pi->pack = NULL;
1012  pi->is_static = pstatic;
1013  pi->data.s.proc_start = pos;
1014  pi->data.s.def_end    = 0L;
1015  pi->data.s.help_start = 0L;
1016  pi->data.s.help_end   = 0L;
1017  pi->data.s.body_start = 0L;
1018  pi->data.s.body_end   = 0L;
1019  pi->data.s.example_start = 0L;
1020  pi->data.s.proc_lineno = line;
1021  pi->data.s.body_lineno = 0;
1022  pi->data.s.example_lineno = 0;
1023  pi->data.s.body = NULL;
1024  pi->data.s.help_chksum = 0;
1025  return(pi);
1026}
1027
1028#if 0
1029// TODO!?
1030procinfo *iiInitSingularProcinfo(procinfo* pi, const char *libname,
1031                                 const char *procname, int line, long pos,
1032                                 BOOLEAN pstatic /*= FALSE*/)
1033{
1034  pi->libname = (char *)malloc(strlen(libname)+1);
1035  memcpy(pi->libname, libname, strlen(libname));
1036  *(pi->libname+strlen(libname)) = '\0';
1037
1038  pi->procname = (char *)malloc(strlen(procname)+1);
1039  strcpy(pi->procname, procname/*, strlen(procname)*/);
1040  pi->language = LANG_SINGULAR;
1041  pi->ref = 1;
1042  pi->is_static = pstatic;
1043  pi->data.s.proc_start = pos;
1044  pi->data.s.def_end    = 0L;
1045  pi->data.s.help_start = 0L;
1046  pi->data.s.body_start = 0L;
1047  pi->data.s.body_end   = 0L;
1048  pi->data.s.example_start = 0L;
1049  pi->data.s.proc_lineno = line;
1050  pi->data.s.body_lineno = 0;
1051  pi->data.s.example_lineno = 0;
1052  pi->data.s.body = NULL;
1053  pi->data.s.help_chksum = 0;
1054  return(pi);
1055}
1056#endif
1057
1058/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1059int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1060               BOOLEAN(*func)(leftv res, leftv v))
1061{
1062  procinfov pi;
1063  idhdl h;
1064
1065  #ifndef NDEBUG
1066  int dummy;
1067  if (IsCmd(procname,dummy))
1068  {
1069    Werror(">>%s< is a reserved name",procname);
1070    return 0;
1071  }
1072  #endif
1073
1074  h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
1075  if ( h!= NULL )
1076  {
1077    pi = IDPROC(h);
1078    pi->libname = omStrDup(libname);
1079    pi->procname = omStrDup(procname);
1080    pi->language = LANG_C;
1081    pi->ref = 1;
1082    pi->is_static = pstatic;
1083    pi->data.o.function = func;
1084    return(1);
1085  }
1086  else
1087  {
1088    PrintS("iiAddCproc: failed.\n");
1089  }
1090  return(0);
1091}
1092
1093int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic,
1094               BOOLEAN(*func)(leftv res, leftv v))
1095{
1096  int r=iiAddCproc(libname,procname,pstatic,func);
1097  package s=currPack;
1098  currPack=basePack;
1099  if (r) r=iiAddCproc(libname,procname,pstatic,func);
1100  currPack=s;
1101  return r;
1102}
1103
1104/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1105#ifdef HAVE_DYNAMIC_LOADING
1106BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
1107{
1108#ifdef HAVE_STATIC
1109  WerrorS("mod_init: static version can not load modules");
1110  return TRUE;
1111#else
1112/*
1113  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1114                               BOOLEAN pstatic,
1115                               BOOLEAN(*func)(leftv res, leftv v)));
1116*/
1117  SModulFunc_t fktn;
1118  idhdl pl;
1119  char *plib = iiConvName(newlib);
1120  BOOLEAN RET=TRUE;
1121  int token;
1122  char FullName[256];
1123
1124  memset(FullName,0,256);
1125
1126  if( *fullname != '/' &&  *fullname != '.' )
1127    sprintf(FullName, "./%s", newlib);
1128  else strncpy(FullName, fullname,255);
1129
1130
1131  if(IsCmd(plib, token))
1132  {
1133    Werror("'%s' is resered identifier\n", plib);
1134    goto load_modules_end;
1135  }
1136  pl = IDROOT->get(plib,0);
1137  if (pl==NULL)
1138  {
1139    pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
1140                  TRUE );
1141    IDPACKAGE(pl)->language = LANG_C;
1142    IDPACKAGE(pl)->libname=omStrDup(newlib);
1143  }
1144  else
1145  {
1146    if(IDTYP(pl)!=PACKAGE_CMD)
1147    {
1148      Warn("not of type package.");
1149      goto load_modules_end;
1150    }
1151  }
1152  if (dynl_check_opened(FullName)) {
1153    if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded", fullname);
1154    return FALSE;
1155  }
1156  if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1157  {
1158    Werror("dynl_open failed:%s", dynl_error());
1159    Werror("%s not found", newlib);
1160    goto load_modules_end;
1161  }
1162  else
1163  {
1164    SModulFunctions sModulFunctions;
1165
1166    package s=currPack;
1167    currPack=IDPACKAGE(pl);
1168    fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1169    if( fktn!= NULL)
1170    {
1171      sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1172      if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1173      else            sModulFunctions.iiAddCproc = iiAddCproc;
1174      (*fktn)(&sModulFunctions);
1175    }
1176    else Werror("mod_init: %s\n", dynl_error());
1177    if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s \n", fullname);
1178    currPack->loaded=1;
1179    currPack=s;
1180  }
1181  RET=FALSE;
1182
1183  load_modules_end:
1184  return RET;
1185#endif /*STATIC */
1186}
1187#endif /* HAVE_DYNAMIC_LOADING */
1188/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1189BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
1190{
1191  int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1192                 BOOLEAN(*func)(leftv res, leftv v));
1193/*
1194  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1195                               BOOLEAN pstatic,
1196                               BOOLEAN(*func)(leftv res, leftv v)));
1197*/
1198  // SModulFunc_t fktn;
1199  idhdl pl;
1200  char *plib = iiConvName(newlib);
1201  // BOOLEAN RET=TRUE;
1202  // int token;
1203
1204  pl = IDROOT->get(plib,0);
1205  if (pl!=NULL)
1206  {
1207    if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1208    omFree(plib);
1209    return FALSE;
1210  }
1211
1212  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
1213                TRUE );
1214  IDPACKAGE(pl)->language = LANG_C;
1215  IDPACKAGE(pl)->libname=omStrDup(newlib);
1216
1217  IDPACKAGE(pl)->handle=(void *)NULL;
1218  SModulFunctions sModulFunctions;
1219
1220  package s=currPack;
1221  currPack=IDPACKAGE(pl);
1222  if( init!= NULL)
1223  {
1224    sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1225    if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1226    else            sModulFunctions.iiAddCproc = iiAddCproc;
1227    (*init)(&sModulFunctions);
1228  }
1229  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1230  currPack->loaded=1;
1231  currPack=s;
1232
1233  return FALSE;
1234}
1235/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1236void module_help_main(const char *newlib,const char *help)
1237{
1238  char *plib = iiConvName(newlib);
1239  idhdl pl = basePack->idroot->get(plib,0);
1240  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1241    Werror(">>%s<< is not a package (trying to add package help)",plib);
1242  else
1243  {
1244    package s=currPack;
1245    currPack=IDPACKAGE(pl);
1246    idhdl h=enterid(omStrDup("info"),0,STRING_CMD,&IDROOT,FALSE);
1247    IDSTRING(h)=omStrDup(help);
1248    currPack=s;
1249  }
1250}
1251void module_help_proc(const char *newlib,const char *p, const char *help)
1252{
1253  char *plib = iiConvName(newlib);
1254  idhdl pl = basePack->idroot->get(plib,0);
1255  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1256    Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1257  else
1258  {
1259    package s=currPack;
1260    currPack=IDPACKAGE(pl);
1261    char buff[256];
1262    buff[255]='\0';
1263    strncpy(buff,p,255);
1264    strncat(buff,"_help",255-strlen(p));
1265    idhdl h=enterid(omStrDup(buff),0,STRING_CMD,&IDROOT,FALSE);
1266    IDSTRING(h)=omStrDup(help);
1267    currPack=s;
1268  }
1269}
1270/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1271
1272// loads a dynamic module from the binary path and returns a named function
1273// returns NULL, if something fails
1274void* binary_module_function(const char* newlib, const char* funcname)
1275{
1276  void* result = NULL;
1277
1278#if defined(HAVE_STATIC) || !defined(HAVE_DYNAMIC_LOADING)
1279  WerrorS("static version can not load function from dynamic modules");
1280#else
1281  const char* bin_dir = feGetResource('b');
1282  if (!bin_dir)  { return NULL; }
1283
1284  char path_name[MAXPATHLEN];
1285  sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING);
1286
1287  void* openlib = dynl_open(path_name);
1288  if(!openlib)
1289  {
1290    Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1291    return NULL;
1292  }
1293  result = dynl_sym(openlib, funcname);
1294  if (!result) Werror("%s: %s\n", funcname, dynl_error());
1295#endif
1296
1297  return result;
1298}
1299
1300
1301/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1302char mytoupper(char c)
1303{
1304  if(c>=97 && c<=(97+26)) c-=32;
1305  return(c);
1306}
1307
1308char mytolower(char c)
1309{
1310  if(c>=65 && c<=(65+26)) c+=32;
1311  return(c);
1312}
1313
1314/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1315//#if defined(WINNT)
1316//#  define  FS_SEP '\\'
1317//#else
1318//#  define FS_SEP '/'
1319//#endif
1320
1321char *iiConvName(const char *libname)
1322{
1323  char *tmpname = omStrDup(libname);
1324  char *p = strrchr(tmpname, DIR_SEP);
1325  char *r;
1326  if(p==NULL) p = tmpname;
1327  else p++;
1328  r = (char *)strchr(p, '.');
1329  if( r!= NULL) *r = '\0';
1330  r = omStrDup(p);
1331  *r = mytoupper(*r);
1332  // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1333  omFree((ADDRESS)tmpname);
1334
1335  return(r);
1336}
1337
1338/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1339#if 0 /* debug only */
1340void piShowProcList()
1341{
1342  idhdl h;
1343  procinfo *proc;
1344  char *name;
1345
1346  Print( "%-15s  %20s      %s,%s  %s,%s   %s,%s\n", "Library", "function",
1347         "line", "start", "line", "body", "line", "example");
1348  for(h = IDROOT; h != NULL; h = IDNEXT(h))
1349  {
1350    if(IDTYP(h) == PROC_CMD)
1351    {
1352      proc = IDPROC(h);
1353      if(strcmp(proc->procname, IDID(h))!=0)
1354      {
1355        name = (char *)omAlloc(strlen(IDID(h))+strlen(proc->procname)+4);
1356        sprintf(name, "%s -> %s", IDID(h), proc->procname);
1357        Print( "%d %-15s  %20s ", proc->is_static ? 1 : 0, proc->libname, name);
1358        omFree((ADDRESS)name);
1359      }
1360      else
1361        Print( "%d %-15s  %20s ", proc->is_static ? 1 : 0, proc->libname,
1362               proc->procname);
1363      if(proc->language==LANG_SINGULAR)
1364        Print("line %4d,%-5ld  %4d,%-5ld  %4d,%-5ld\n",
1365              proc->data.s.proc_lineno, proc->data.s.proc_start,
1366              proc->data.s.body_lineno, proc->data.s.body_start,
1367              proc->data.s.example_lineno, proc->data.s.example_start);
1368      else if(proc->language==LANG_C)
1369        Print("type: object\n");
1370    }
1371  }
1372}
1373#endif
1374
1375/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1376//char *iiLineNo(char *procname, int lineno)
1377//{
1378//  char buf[256];
1379//  idhdl pn = ggetid(procname);
1380//  procinfo *pi = IDPROC(pn);
1381//
1382//  sprintf(buf, "%s %3d\0", procname, lineno);
1383//  //sprintf(buf, "%s::%s %3d\0", pi->libname, pi->procname,
1384//  //  lineno + pi->data.s.body_lineno);
1385//  return(buf);
1386//}
1387/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1388#ifdef HAVE_LIBPARSER
1389void libstack::push(const char */*p*/, char *libn)
1390{
1391  libstackv lp;
1392  if( !iiGetLibStatus(libn))
1393  {
1394    for(lp = this;lp!=NULL;lp=lp->next)
1395    {
1396      if(strcmp(lp->get(), libn)==0) break;
1397    }
1398    if(lp==NULL)
1399    {
1400      libstackv ls = (libstack *)omAlloc0Bin(libstack_bin);
1401      ls->next = this;
1402      ls->libname = omStrDup(libn);
1403      ls->to_be_done = TRUE;
1404      if(this != NULL) ls->cnt = this->cnt+1; else ls->cnt = 0;
1405      library_stack = ls;
1406    }
1407  }
1408}
1409
1410libstackv libstack::pop(const char */*p*/)
1411{
1412  libstackv ls = this;
1413  //omFree((ADDRESS)ls->libname);
1414  library_stack = ls->next;
1415  omFreeBin((ADDRESS)ls,  libstack_bin);
1416  return(library_stack);
1417}
1418
1419#endif /* HAVE_LIBPARSER */
1420/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
Note: See TracBrowser for help on using the repository browser.