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