source: git/Singular/iplib.cc @ 237216

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