source: git/Singular/iplib.cc @ e7cb20

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