source: git/Singular/iplib.cc @ e5ba1d

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