source: git/Singular/iplib.cc @ f8565a

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