source: git/Singular/iplib.cc @ 9875202

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