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

spielwiese
Last change on this file since 42d464 was 989d6b, checked in by Oleksandr Motsak <motsak@…>, 10 years ago
Minor fixes + cleanup
  • Property mode set to 100644
File size: 36.2 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    Warn("option changed in proc %s from %s",pi->procname,pi->libname);
336    int i;
337    for (i=0; optionStruct[i].setval!=0; i++)
338    {
339      if ((optionStruct[i].setval & save11)
340      && (!(optionStruct[i].setval & save1)))
341      {
342          Print(" +%s",optionStruct[i].name);
343      }
344      if (!(optionStruct[i].setval & save11)
345      && ((optionStruct[i].setval & save1)))
346      {
347          Print(" -%s",optionStruct[i].name);
348      }
349    }
350    for (i=0; verboseStruct[i].setval!=0; i++)
351    {
352      if ((verboseStruct[i].setval & verbose)
353      && (!(verboseStruct[i].setval & save2)))
354      {
355          Print(" +%s",verboseStruct[i].name);
356      }
357      if (!(verboseStruct[i].setval & verbose)
358      && ((verboseStruct[i].setval & save2)))
359      {
360          Print(" -%s",verboseStruct[i].name);
361      }
362    }
363    PrintLn();
364  }
365  #endif
366  return err;
367}
368/*2
369* start a proc
370* parameters are built as exprlist
371* TODO:interrupt
372* return FALSE on success, TRUE if an error occurs
373*/
374BOOLEAN iiPStart(idhdl pn, sleftv  * v)
375{
376  procinfov pi=NULL;
377  int old_echo=si_echo;
378  BOOLEAN err=FALSE;
379  char save_flags=0;
380
381  /* init febase ======================================== */
382  /* we do not enter this case if filename != NULL !! */
383  if (pn!=NULL)
384  {
385    pi = IDPROC(pn);
386    if(pi!=NULL)
387    {
388      save_flags=pi->trace_flag;
389      if( pi->data.s.body==NULL )
390      {
391        iiGetLibProcBuffer(pi);
392        if (pi->data.s.body==NULL) return TRUE;
393      }
394//      omUpdateInfo();
395//      int m=om_Info.UsedBytes;
396//      Print("proc %s, mem=%d\n",IDID(pn),m);
397    }
398  }
399  else return TRUE;
400  /* generate argument list ======================================*/
401  if (v!=NULL)
402  {
403    iiCurrArgs=(leftv)omAllocBin(sleftv_bin);
404    memcpy(iiCurrArgs,v,sizeof(sleftv));
405    memset(v,0,sizeof(sleftv));
406  }
407  else
408  {
409    iiCurrArgs=NULL;
410  }
411  iiCurrProc=pn;
412  /* start interpreter ======================================*/
413  myynest++;
414  if (myynest > SI_MAX_NEST)
415  {
416    WerrorS("nesting too deep");
417    err=TRUE;
418  }
419  else
420  {
421    err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
422
423    //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
424    killlocals(myynest);
425#ifndef NDEBUG
426    checkall();
427#endif
428    //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
429  }
430  myynest--;
431  si_echo=old_echo;
432  if (pi!=NULL)
433    pi->trace_flag=save_flags;
434//  omUpdateInfo();
435//  int m=om_Info.UsedBytes;
436//  Print("exit %s, mem=%d\n",IDID(pn),m);
437  return err;
438}
439
440#ifdef USE_IILOCALRING
441ring    *iiLocalRing;
442#endif
443sleftv  iiRETURNEXPR;
444int     iiRETURNEXPR_len=0;
445
446#ifdef RDEBUG
447static void iiShowLevRings()
448{
449  int i;
450#ifdef USE_IILOCALRING
451  for (i=0;i<=myynest;i++)
452  {
453    Print("lev %d:",i);
454    if (iiLocalRing[i]==NULL) PrintS("NULL");
455    else                      Print("%lx",(long)iiLocalRing[i]);
456    PrintLn();
457  }
458#endif
459#if  0
460  i=myynest;
461  proclevel *p=procstack;
462  while (p!=NULL)
463  {
464    Print("lev %d:",i);
465    if (p->cRingHdl==NULL) PrintS("NULL");
466    else                   Print("%s",IDID(p->cRingHdl));
467    PrintLn();
468    p=p->next;
469  }
470#endif
471  if (currRing==NULL) PrintS("curr:NULL\n");
472  else                Print ("curr:%lx\n",(long)currRing);
473}
474#endif /* RDEBUG */
475
476static void iiCheckNest()
477{
478  if (myynest >= iiRETURNEXPR_len-1)
479  {
480#ifdef USE_IILOCALRING
481    iiLocalRing=(ring *)omreallocSize(iiLocalRing,
482                                   iiRETURNEXPR_len*sizeof(ring),
483                                   (iiRETURNEXPR_len+16)*sizeof(ring));
484    memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
485#endif
486    iiRETURNEXPR_len+=16;
487  }
488}
489BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv* sl)
490{
491  int err;
492  procinfov pi = IDPROC(pn);
493  if(pi->is_static && myynest==0)
494  {
495    Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
496           pi->libname, pi->procname);
497    return TRUE;
498  }
499  iiCheckNest();
500#ifdef USE_IILOCALRING
501  iiLocalRing[myynest]=currRing;
502  //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
503#endif
504  iiRETURNEXPR.Init();
505  procstack->push(pi->procname);
506  if ((traceit&TRACE_SHOW_PROC)
507  || (pi->trace_flag&TRACE_SHOW_PROC))
508  {
509    if (traceit&TRACE_SHOW_LINENO) PrintLn();
510    Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
511  }
512#ifdef RDEBUG
513  if (traceit&TRACE_SHOW_RINGS) iiShowLevRings();
514#endif
515  switch (pi->language)
516  {
517    default:
518    case LANG_NONE:
519                 WerrorS("undefined proc");
520                 err=TRUE;
521                 break;
522
523    case LANG_SINGULAR:
524                 if ((pi->pack!=NULL)&&(currPack!=pi->pack))
525                 {
526                   currPack=pi->pack;
527                   iiCheckPack(currPack);
528                   currPackHdl=packFindHdl(currPack);
529                   //Print("set pack=%s\n",IDID(currPackHdl));
530                 }
531                 else if ((pack!=NULL)&&(currPack!=pack))
532                 {
533                   currPack=pack;
534                   iiCheckPack(currPack);
535                   currPackHdl=packFindHdl(currPack);
536                   //Print("set pack=%s\n",IDID(currPackHdl));
537                 }
538                 err=iiPStart(pn,sl);
539                 break;
540    case LANG_C:
541                 leftv res = (leftv)omAlloc0Bin(sleftv_bin);
542                 err = (pi->data.o.function)(res, sl);
543                 memcpy(&iiRETURNEXPR,res,sizeof(iiRETURNEXPR));
544                 omFreeBin((ADDRESS)res,  sleftv_bin);
545                 break;
546  }
547  if ((traceit&TRACE_SHOW_PROC)
548  || (pi->trace_flag&TRACE_SHOW_PROC))
549  {
550    if (traceit&TRACE_SHOW_LINENO) PrintLn();
551    Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
552  }
553  //char *n="NULL";
554  //if (currRingHdl!=NULL) n=IDID(currRingHdl);
555  //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
556#ifdef RDEBUG
557  if (traceit&TRACE_SHOW_RINGS) iiShowLevRings();
558#endif
559  if (err)
560  {
561    iiRETURNEXPR.CleanUp();
562    //iiRETURNEXPR.Init(); //done by CleanUp
563  }
564#ifdef USE_IILOCALRING
565#if 0
566  if(procstack->cRing != iiLocalRing[myynest]) Print("iiMake_proc: 1 ring not saved procs:%x, iiLocal:%x\n",procstack->cRing, iiLocalRing[myynest]);
567#endif
568  if (iiLocalRing[myynest] != currRing)
569  {
570    if (currRing!=NULL)
571    {
572      if (((iiRETURNEXPR.Typ()>BEGIN_RING)
573        && (iiRETURNEXPR.Typ()<END_RING))
574      || ((iiRETURNEXPR.Typ()==LIST_CMD)
575        && (lRingDependend((lists)iiRETURNEXPR.Data()))))
576      {
577        //idhdl hn;
578        const char *n;
579        const char *o;
580        idhdl nh=NULL, oh=NULL;
581        if (iiLocalRing[myynest]!=NULL)
582          oh=rFindHdl(iiLocalRing[myynest],NULL, NULL);
583        if (oh!=NULL)          o=oh->id;
584        else                   o="none";
585        if (currRing!=NULL)
586          nh=rFindHdl(currRing,NULL, NULL);
587        if (nh!=NULL)          n=nh->id;
588        else                   n="none";
589        Werror("ring change during procedure call: %s -> %s (level %d)",o,n,myynest);
590        iiRETURNEXPR.CleanUp();
591        err=TRUE;
592      }
593    }
594    currRing=iiLocalRing[myynest];
595  }
596  if ((currRing==NULL)
597  && (currRingHdl!=NULL))
598    currRing=IDRING(currRingHdl);
599  else
600  if ((currRing!=NULL) &&
601    ((currRingHdl==NULL)||(IDRING(currRingHdl)!=currRing)
602     ||(IDLEV(currRingHdl)>=myynest)))
603  {
604    rSetHdl(rFindHdl(currRing,NULL, NULL));
605    iiLocalRing[myynest]=NULL;
606  }
607#else /* USE_IILOCALRING */
608  if (procstack->cRing != currRing)
609  {
610    //if (procstack->cRingHdl!=NULL)
611    //Print("procstack:%s,",IDID(procstack->cRingHdl));
612    //if (currRingHdl!=NULL)
613    //Print(" curr:%s\n",IDID(currRingHdl));
614    //Print("pr:%x, curr: %x\n",procstack->cRing,currRing);
615    if (((iiRETURNEXPR.Typ()>BEGIN_RING)
616      && (iiRETURNEXPR.Typ()<END_RING))
617    || ((iiRETURNEXPR.Typ()==LIST_CMD)
618      && (lRingDependend((lists)iiRETURNEXPR.Data()))))
619    {
620      //idhdl hn;
621      char *n;
622      char *o;
623      if (procstack->cRing!=NULL)
624      {
625        //PrintS("reset ring\n");
626        procstack->cRingHdl=rFindHdl(procstack->cRing,NULL, NULL);
627        if (procstack->cRingHdl==NULL)
628          procstack->cRingHdl=
629           rFindHdl(procstack->cRing,NULL,procstack->currPack->idroot);
630        if (procstack->cRingHdl==NULL)
631          procstack->cRingHdl=
632           rFindHdl(procstack->cRing,NULL,basePack->idroot);
633        o=IDID(procstack->cRingHdl);
634        currRing=procstack->cRing;
635        currRingHdl=procstack->cRingHdl;
636      }
637      else                            o="none";
638      if (currRing!=NULL)             n=IDID(currRingHdl);
639      else                            n="none";
640      if (currRing==NULL)
641      {
642        Werror("ring change during procedure call: %s -> %s",o,n);
643        iiRETURNEXPR.CleanUp();
644        err=TRUE;
645      }
646    }
647    if (procstack->cRingHdl!=NULL)
648    {
649      rSetHdl(procstack->cRingHdl);
650    }
651    else
652    { currRingHdl=NULL; currRing=NULL; }
653  }
654#endif /* USE_IILOCALRING */
655  if (iiCurrArgs!=NULL)
656  {
657    if (!err) Warn("too many arguments for %s",IDID(pn));
658    iiCurrArgs->CleanUp();
659    omFreeBin((ADDRESS)iiCurrArgs, sleftv_bin);
660    iiCurrArgs=NULL;
661  }
662  procstack->pop();
663  if (err)
664    return TRUE;
665  return FALSE;
666}
667
668/*2
669* start an example (as a proc),
670* destroys the string 'example'
671*/
672BOOLEAN iiEStart(char* example, procinfo *pi)
673{
674  BOOLEAN err;
675  int old_echo=si_echo;
676
677  iiCheckNest();
678  procstack->push(example);
679#ifdef USE_IILOCALRING
680  iiLocalRing[myynest]=currRing;
681#endif
682  if (traceit&TRACE_SHOW_PROC)
683  {
684    if (traceit&TRACE_SHOW_LINENO) printf("\n");
685    printf("entering example (level %d)\n",myynest);
686  }
687  myynest++;
688
689  err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
690
691  killlocals(myynest);
692  myynest--;
693  si_echo=old_echo;
694  if (traceit&TRACE_SHOW_PROC)
695  {
696    if (traceit&TRACE_SHOW_LINENO) printf("\n");
697    printf("leaving  -example- (level %d)\n",myynest);
698  }
699#ifdef USE_IILOCALRING
700  if (iiLocalRing[myynest] != currRing)
701  {
702    if (iiLocalRing[myynest]!=NULL)
703    {
704      rSetHdl(rFindHdl(iiLocalRing[myynest],NULL, NULL));
705      iiLocalRing[myynest]=NULL;
706    }
707    else
708    {
709      currRingHdl=NULL;
710      currRing=NULL;
711    }
712  }
713#else /* USE_IILOCALRING */
714#endif /* USE_IILOCALRING */
715  if (NS_LRING != currRing)
716  {
717    if (NS_LRING!=NULL)
718    {
719      idhdl rh=procstack->cRingHdl;
720      if ((rh==NULL)||(IDRING(rh)!=NS_LRING))
721        rh=rFindHdl(NS_LRING,NULL, NULL);
722      rSetHdl(rh);
723    }
724    else
725    {
726      currRingHdl=NULL;
727      currRing=NULL;
728    }
729  }
730//#endif /* USE_IILOCALRING */
731  procstack->pop();
732  return err;
733}
734
735int SI_MOD_INIT(staticdemo)(SModulFunctions*){ PrintS("init of staticdemo\n"); return (0); }
736
737#define SI_GET_BUILTIN_MOD_INIT(name) \
738 if (strcmp(libname, #name ".so") == 0){ int SI_MOD_INIT(name)(SModulFunctions*); return SI_MOD_INIT(name); }
739
740SModulFunc_t
741iiGetBuiltinModInit(const char* libname)
742{
743  SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT)
744
745  return NULL;
746}
747
748
749#undef SI_GET_BUILTIN_MOD_INIT
750
751
752/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
753BOOLEAN iiTryLoadLib(leftv v, const char *id)
754{
755  BOOLEAN LoadResult = TRUE;
756  char libnamebuf[128];
757  char *libname = (char *)omAlloc(strlen(id)+5);
758  const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
759  int i = 0;
760  // FILE *fp;
761  // package pack;
762  // idhdl packhdl;
763  lib_types LT;
764  for(i=0; suffix[i] != NULL; i++)
765  {
766    sprintf(libname, "%s%s", id, suffix[i]);
767    *libname = mytolower(*libname);
768    if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
769    {
770      char *s=omStrDup(libname);
771      char libnamebuf[256];
772
773      if (LT==LT_SINGULAR)
774        LoadResult = iiLibCmd(s, FALSE, FALSE,TRUE);
775      #ifdef HAVE_DYNAMIC_LOADING
776      else if ((LT==LT_ELF) || (LT==LT_HPUX))
777        LoadResult = load_modules(s,libnamebuf,FALSE);
778      #endif
779      else if (LT==LT_BUILTIN)
780      {
781        LoadResult=load_builtin(s,FALSE, iiGetBuiltinModInit(s));
782      }
783      if(!LoadResult )
784      {
785        v->name = iiConvName(libname);
786        break;
787      }
788    }
789  }
790  omFree(libname);
791  return LoadResult;
792}
793
794/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
795/* check, if library lib has already been loaded
796   if yes, writes filename of lib into where and returns TRUE,
797      no, returns FALSE
798*/
799BOOLEAN iiLocateLib(const char* lib, char* where)
800{
801  idhdl hl;
802
803  char *p;
804
805  hl = IDROOT->get("LIB", 0);
806  if (hl == NULL || (p=strstr(IDSTRING(hl), lib)) == NULL) return FALSE;
807  if ((p!=IDSTRING(hl)) && (*(p-1)!=',')) return FALSE;
808
809  if (strstr(IDSTRING(hl), ",") == NULL)
810  {
811    strcpy(where, IDSTRING(hl));
812  }
813  else
814  {
815    char* tmp = omStrDup(IDSTRING(hl));
816    char* tok = strtok(tmp, ",");
817    do
818    {
819      if (strstr(tok, lib) != NULL) break;
820      tok = strtok(NULL, ",");
821    }
822    while (tok != NULL);
823    assume(tok != NULL);
824    strcpy(where, tok);
825    omFree(tmp);
826  }
827  return TRUE;
828}
829
830BOOLEAN iiLibCmd( char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force )
831{
832  char libnamebuf[128];
833  // procinfov pi;
834  // idhdl h;
835  idhdl pl;
836  // idhdl hl;
837  // long pos = 0L;
838  char *plib = iiConvName(newlib);
839  FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror );
840  // int lines = 1;
841  BOOLEAN LoadResult = TRUE;
842
843  if (fp==NULL)
844  {
845    return TRUE;
846  }
847  pl = basePack->idroot->get(plib,0);
848  if (pl==NULL)
849  {
850    pl = enterid( plib,0, PACKAGE_CMD,
851                  &(basePack->idroot), TRUE );
852    IDPACKAGE(pl)->language = LANG_SINGULAR;
853    IDPACKAGE(pl)->libname=omStrDup(newlib);
854  }
855  else
856  {
857    if(IDTYP(pl)!=PACKAGE_CMD)
858    {
859      WarnS("not of type package.");
860      fclose(fp);
861      return TRUE;
862    }
863    if (!force) return FALSE;
864  }
865  LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
866  omFree((ADDRESS)newlib);
867
868  if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
869  omFree((ADDRESS)plib);
870
871 return LoadResult;
872}
873/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
874static void iiCleanProcs(idhdl &root)
875{
876  idhdl prev=NULL;
877  loop
878  {
879    if (root==NULL) return;
880    if (IDTYP(root)==PROC_CMD)
881    {
882      procinfo *pi=(procinfo*)IDDATA(root);
883      if ((pi->language == LANG_SINGULAR)
884      && (pi->data.s.body_start == 0L))
885      {
886        // procinfo data incorrect:
887        // - no proc body can start at the beginning of the file
888        killhdl(root);
889        if (prev==NULL)
890          root=IDROOT;
891        else
892        {
893          root=prev;
894          prev=NULL;
895        }
896        continue;
897      }
898    }
899    prev=root;
900    root=IDNEXT(root);
901  }
902}
903static void iiRunInit(package p)
904{
905  idhdl h=p->idroot->get("mod_init",0);
906  if (h==NULL) return;
907  if (IDTYP(h)==PROC_CMD)
908  {
909    int save=yylineno;
910    myynest++;
911    // procinfo *pi=(procinfo*)IDDATA(h);
912    //PrintS("mod_init found\n");
913    iiMake_proc(h,p,NULL);
914    myynest--;
915    yylineno=save;
916  }
917}
918/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
919BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char*newlib,
920             idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
921{
922  extern FILE *yylpin;
923  libstackv ls_start = library_stack;
924  lib_style_types lib_style;
925
926  yylpin = fp;
927  #if YYLPDEBUG > 1
928  print_init();
929  #endif
930  extern int lpverbose;
931  if (BVERBOSE(V_DEBUG_LIB)) lpverbose=1;
932  else lpverbose=0;
933  // yylplex sets also text_buffer
934  if (text_buffer!=NULL) *text_buffer='\0';
935  yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
936  if(yylp_errno)
937  {
938    Werror("Library %s: ERROR occured: in line %d, %d.", newlib, yylplineno,
939         current_pos(0));
940    if(yylp_errno==YYLP_BAD_CHAR)
941    {
942      Werror(yylp_errlist[yylp_errno], *text_buffer, yylplineno);
943      omFree((ADDRESS)text_buffer);
944      text_buffer=NULL;
945    }
946    else
947      Werror(yylp_errlist[yylp_errno], yylplineno);
948    Werror("Cannot load library,... aborting.");
949    reinit_yylp();
950    fclose( yylpin );
951    iiCleanProcs(IDROOT);
952    return TRUE;
953  }
954  if (BVERBOSE(V_LOAD_LIB))
955    Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
956  if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
957  {
958    Warn( "library %s has old format. This format is still accepted,", newlib);
959    Warn( "but for functionality you may wish to change to the new");
960    Warn( "format. Please refer to the manual for further information.");
961  }
962  reinit_yylp();
963  fclose( yylpin );
964  fp = NULL;
965  iiRunInit(IDPACKAGE(pl));
966
967  {
968    libstackv ls;
969    for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
970    {
971      if(ls->to_be_done)
972      {
973        ls->to_be_done=FALSE;
974        iiLibCmd(ls->get(),autoexport,tellerror,FALSE);
975        ls = ls->pop(newlib);
976      }
977    }
978#if 0
979    PrintS("--------------------\n");
980    for(ls = library_stack; ls != NULL; ls = ls->next)
981    {
982      Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
983        ls->to_be_done ? "not loaded" : "loaded");
984    }
985    PrintS("--------------------\n");
986#endif
987  }
988
989  if(fp != NULL) fclose(fp);
990  return FALSE;
991}
992
993
994/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
995procinfo *iiInitSingularProcinfo(procinfov pi, const char *libname,
996              const char *procname, int line, long pos, BOOLEAN pstatic)
997{
998  pi->libname = omStrDup(libname);
999
1000  if( strcmp(procname,"_init")==0)
1001  {
1002    pi->procname = iiConvName(libname);
1003  }
1004  else
1005    pi->procname = omStrDup(procname);
1006  pi->language = LANG_SINGULAR;
1007  pi->ref = 1;
1008  pi->pack = NULL;
1009  pi->is_static = pstatic;
1010  pi->data.s.proc_start = pos;
1011  pi->data.s.def_end    = 0L;
1012  pi->data.s.help_start = 0L;
1013  pi->data.s.help_end   = 0L;
1014  pi->data.s.body_start = 0L;
1015  pi->data.s.body_end   = 0L;
1016  pi->data.s.example_start = 0L;
1017  pi->data.s.proc_lineno = line;
1018  pi->data.s.body_lineno = 0;
1019  pi->data.s.example_lineno = 0;
1020  pi->data.s.body = NULL;
1021  pi->data.s.help_chksum = 0;
1022  return(pi);
1023}
1024
1025#if 0
1026// TODO!?
1027procinfo *iiInitSingularProcinfo(procinfo* pi, const char *libname,
1028                                 const char *procname, int line, long pos,
1029                                 BOOLEAN pstatic /*= FALSE*/)
1030{
1031  pi->libname = (char *)malloc(strlen(libname)+1);
1032  memcpy(pi->libname, libname, strlen(libname));
1033  *(pi->libname+strlen(libname)) = '\0';
1034
1035  pi->procname = (char *)malloc(strlen(procname)+1);
1036  strcpy(pi->procname, procname/*, strlen(procname)*/);
1037  pi->language = LANG_SINGULAR;
1038  pi->ref = 1;
1039  pi->is_static = pstatic;
1040  pi->data.s.proc_start = pos;
1041  pi->data.s.def_end    = 0L;
1042  pi->data.s.help_start = 0L;
1043  pi->data.s.body_start = 0L;
1044  pi->data.s.body_end   = 0L;
1045  pi->data.s.example_start = 0L;
1046  pi->data.s.proc_lineno = line;
1047  pi->data.s.body_lineno = 0;
1048  pi->data.s.example_lineno = 0;
1049  pi->data.s.body = NULL;
1050  pi->data.s.help_chksum = 0;
1051  return(pi);
1052}
1053#endif
1054
1055/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1056int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1057               BOOLEAN(*func)(leftv res, leftv v))
1058{
1059  procinfov pi;
1060  idhdl h;
1061
1062  #ifndef NDEBUG
1063  int dummy;
1064  if (IsCmd(procname,dummy))
1065  {
1066    Werror(">>%s< is a reserved name",procname);
1067    return 0;
1068  }
1069  #endif
1070
1071  h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
1072  if ( h!= NULL )
1073  {
1074    pi = IDPROC(h);
1075    pi->libname = omStrDup(libname);
1076    pi->procname = omStrDup(procname);
1077    pi->language = LANG_C;
1078    pi->ref = 1;
1079    pi->is_static = pstatic;
1080    pi->data.o.function = func;
1081    return(1);
1082  }
1083  else
1084  {
1085    PrintS("iiAddCproc: failed.\n");
1086  }
1087  return(0);
1088}
1089
1090int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic,
1091               BOOLEAN(*func)(leftv res, leftv v))
1092{
1093  int r=iiAddCproc(libname,procname,pstatic,func);
1094  package s=currPack;
1095  currPack=basePack;
1096  if (r) r=iiAddCproc(libname,procname,pstatic,func);
1097  currPack=s;
1098  return r;
1099}
1100
1101/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1102#ifdef HAVE_DYNAMIC_LOADING
1103BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
1104{
1105#ifdef HAVE_STATIC
1106  WerrorS("mod_init: static version can not load modules");
1107  return TRUE;
1108#else
1109/*
1110  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1111                               BOOLEAN pstatic,
1112                               BOOLEAN(*func)(leftv res, leftv v)));
1113*/
1114  SModulFunc_t fktn;
1115  idhdl pl;
1116  char *plib = iiConvName(newlib);
1117  BOOLEAN RET=TRUE;
1118  int token;
1119  char FullName[256];
1120
1121  memset(FullName,0,256);
1122
1123  if( *fullname != '/' &&  *fullname != '.' )
1124    sprintf(FullName, "./%s", newlib);
1125  else strncpy(FullName, fullname,255);
1126
1127
1128  if(IsCmd(plib, token))
1129  {
1130    Werror("'%s' is resered identifier\n", plib);
1131    goto load_modules_end;
1132  }
1133  pl = IDROOT->get(plib,0);
1134  if (pl==NULL)
1135  {
1136    pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
1137                  TRUE );
1138    IDPACKAGE(pl)->language = LANG_C;
1139    IDPACKAGE(pl)->libname=omStrDup(newlib);
1140  }
1141  else
1142  {
1143    if(IDTYP(pl)!=PACKAGE_CMD)
1144    {
1145      Warn("not of type package.");
1146      goto load_modules_end;
1147    }
1148  }
1149  if (dynl_check_opened(FullName)) {
1150    if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded", fullname);
1151    return FALSE;
1152  }
1153  if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1154  {
1155    Werror("dynl_open failed:%s", dynl_error());
1156    Werror("%s not found", newlib);
1157    goto load_modules_end;
1158  }
1159  else
1160  {
1161    SModulFunctions sModulFunctions;
1162
1163    package s=currPack;
1164    currPack=IDPACKAGE(pl);
1165    fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1166    if( fktn!= NULL)
1167    {
1168      sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1169      if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1170      else            sModulFunctions.iiAddCproc = iiAddCproc;
1171      (*fktn)(&sModulFunctions);
1172    }
1173    else Werror("mod_init: %s\n", dynl_error());
1174    if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s \n", fullname);
1175    currPack->loaded=1;
1176    currPack=s;
1177  }
1178  RET=FALSE;
1179
1180  load_modules_end:
1181  return RET;
1182#endif /*STATIC */
1183}
1184#endif /* HAVE_DYNAMIC_LOADING */
1185/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1186BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
1187{
1188  int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1189                 BOOLEAN(*func)(leftv res, leftv v));
1190/*
1191  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1192                               BOOLEAN pstatic,
1193                               BOOLEAN(*func)(leftv res, leftv v)));
1194*/
1195  // SModulFunc_t fktn;
1196  idhdl pl;
1197  char *plib = iiConvName(newlib);
1198  // BOOLEAN RET=TRUE;
1199  // int token;
1200
1201  pl = IDROOT->get(plib,0);
1202  if (pl!=NULL)
1203  {
1204    if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1205    omFree(plib);
1206    return FALSE;
1207  }
1208
1209  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
1210                TRUE );
1211  IDPACKAGE(pl)->language = LANG_C;
1212  IDPACKAGE(pl)->libname=omStrDup(newlib);
1213
1214  IDPACKAGE(pl)->handle=(void *)NULL;
1215  SModulFunctions sModulFunctions;
1216
1217  package s=currPack;
1218  currPack=IDPACKAGE(pl);
1219  if( init!= NULL)
1220  {
1221    sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1222    if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1223    else            sModulFunctions.iiAddCproc = iiAddCproc;
1224    (*init)(&sModulFunctions);
1225  }
1226  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1227  currPack->loaded=1;
1228  currPack=s;
1229
1230  return FALSE;
1231}
1232/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1233void module_help_main(const char *newlib,const char *help)
1234{
1235  char *plib = iiConvName(newlib);
1236  idhdl pl = basePack->idroot->get(plib,0);
1237  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1238    Werror(">>%s<< is not a package (trying to add package help)",plib);
1239  else
1240  {
1241    package s=currPack;
1242    currPack=IDPACKAGE(pl);
1243    idhdl h=enterid(omStrDup("info"),0,STRING_CMD,&IDROOT,FALSE);
1244    IDSTRING(h)=omStrDup(help);
1245    currPack=s;
1246  }
1247}
1248void module_help_proc(const char *newlib,const char *p, const char *help)
1249{
1250  char *plib = iiConvName(newlib);
1251  idhdl pl = basePack->idroot->get(plib,0);
1252  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1253    Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1254  else
1255  {
1256    package s=currPack;
1257    currPack=IDPACKAGE(pl);
1258    char buff[256];
1259    buff[255]='\0';
1260    strncpy(buff,p,255);
1261    strncat(buff,"_help",255-strlen(p));
1262    idhdl h=enterid(omStrDup(buff),0,STRING_CMD,&IDROOT,FALSE);
1263    IDSTRING(h)=omStrDup(help);
1264    currPack=s;
1265  }
1266}
1267/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1268
1269// loads a dynamic module from the binary path and returns a named function
1270// returns NULL, if something fails
1271void* binary_module_function(const char* newlib, const char* funcname)
1272{
1273  void* result = NULL;
1274
1275#if defined(HAVE_STATIC) || !defined(HAVE_DYNAMIC_LOADING)
1276  WerrorS("static version can not load function from dynamic modules");
1277#else
1278  const char* bin_dir = feGetResource('b');
1279  if (!bin_dir)  { return NULL; }
1280
1281  char path_name[MAXPATHLEN];
1282  sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING);
1283
1284  void* openlib = dynl_open(path_name);
1285  if(!openlib)
1286  {
1287    Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1288    return NULL;
1289  }
1290  result = dynl_sym(openlib, funcname);
1291  if (!result) Werror("%s: %s\n", funcname, dynl_error());
1292#endif
1293
1294  return result;
1295}
1296
1297
1298/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1299char mytoupper(char c)
1300{
1301  if(c>=97 && c<=(97+26)) c-=32;
1302  return(c);
1303}
1304
1305char mytolower(char c)
1306{
1307  if(c>=65 && c<=(65+26)) c+=32;
1308  return(c);
1309}
1310
1311/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1312//#if defined(WINNT)
1313//#  define  FS_SEP '\\'
1314//#else
1315//#  define FS_SEP '/'
1316//#endif
1317
1318char *iiConvName(const char *libname)
1319{
1320  char *tmpname = omStrDup(libname);
1321  char *p = strrchr(tmpname, DIR_SEP);
1322  char *r;
1323  if(p==NULL) p = tmpname;
1324  else p++;
1325  r = (char *)strchr(p, '.');
1326  if( r!= NULL) *r = '\0';
1327  r = omStrDup(p);
1328  *r = mytoupper(*r);
1329  // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1330  omFree((ADDRESS)tmpname);
1331
1332  return(r);
1333}
1334
1335/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1336#if 0 /* debug only */
1337void piShowProcList()
1338{
1339  idhdl h;
1340  procinfo *proc;
1341  char *name;
1342
1343  Print( "%-15s  %20s      %s,%s  %s,%s   %s,%s\n", "Library", "function",
1344         "line", "start", "line", "body", "line", "example");
1345  for(h = IDROOT; h != NULL; h = IDNEXT(h))
1346  {
1347    if(IDTYP(h) == PROC_CMD)
1348    {
1349      proc = IDPROC(h);
1350      if(strcmp(proc->procname, IDID(h))!=0)
1351      {
1352        name = (char *)omAlloc(strlen(IDID(h))+strlen(proc->procname)+4);
1353        sprintf(name, "%s -> %s", IDID(h), proc->procname);
1354        Print( "%d %-15s  %20s ", proc->is_static ? 1 : 0, proc->libname, name);
1355        omFree((ADDRESS)name);
1356      }
1357      else
1358        Print( "%d %-15s  %20s ", proc->is_static ? 1 : 0, proc->libname,
1359               proc->procname);
1360      if(proc->language==LANG_SINGULAR)
1361        Print("line %4d,%-5ld  %4d,%-5ld  %4d,%-5ld\n",
1362              proc->data.s.proc_lineno, proc->data.s.proc_start,
1363              proc->data.s.body_lineno, proc->data.s.body_start,
1364              proc->data.s.example_lineno, proc->data.s.example_start);
1365      else if(proc->language==LANG_C)
1366        Print("type: object\n");
1367    }
1368  }
1369}
1370#endif
1371
1372/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1373//char *iiLineNo(char *procname, int lineno)
1374//{
1375//  char buf[256];
1376//  idhdl pn = ggetid(procname);
1377//  procinfo *pi = IDPROC(pn);
1378//
1379//  sprintf(buf, "%s %3d\0", procname, lineno);
1380//  //sprintf(buf, "%s::%s %3d\0", pi->libname, pi->procname,
1381//  //  lineno + pi->data.s.body_lineno);
1382//  return(buf);
1383//}
1384/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1385#ifdef HAVE_LIBPARSER
1386void libstack::push(const char */*p*/, char *libn)
1387{
1388  libstackv lp;
1389  if( !iiGetLibStatus(libn))
1390  {
1391    for(lp = this;lp!=NULL;lp=lp->next)
1392    {
1393      if(strcmp(lp->get(), libn)==0) break;
1394    }
1395    if(lp==NULL)
1396    {
1397      libstackv ls = (libstack *)omAlloc0Bin(libstack_bin);
1398      ls->next = this;
1399      ls->libname = omStrDup(libn);
1400      ls->to_be_done = TRUE;
1401      if(this != NULL) ls->cnt = this->cnt+1; else ls->cnt = 0;
1402      library_stack = ls;
1403    }
1404  }
1405}
1406
1407libstackv libstack::pop(const char */*p*/)
1408{
1409  libstackv ls = this;
1410  //omFree((ADDRESS)ls->libname);
1411  library_stack = ls->next;
1412  omFreeBin((ADDRESS)ls,  libstack_bin);
1413  return(library_stack);
1414}
1415
1416#endif /* HAVE_LIBPARSER */
1417/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
Note: See TracBrowser for help on using the repository browser.