source: git/Singular/iplib.cc @ 3907ab

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