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