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  char libnamebuf[256];
770 
771  if (LT==LT_SINGULAR)
772  LoadResult = iiLibCmd(s, FALSE, FALSE,TRUE);
773  #ifdef HAVE_DYNAMIC_LOADING
774  else if ((LT==LT_ELF) || (LT==LT_HPUX))
775  LoadResult = load_modules(s,libnamebuf,FALSE);
776  #endif
777  else if (LT==LT_BUILTIN)
778  {
779  LoadResult=load_builtin(s,FALSE, iiGetBuiltinModInit(s));
780  }
781  if(!LoadResult )
782  {
783  v->name = iiConvName(libname);
784  break;
785  }
786  }
787  }
788  omFree(libname);
789  return LoadResult;
790 }
791 
792 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
793 /* check, if library lib has already been loaded
794  if yes, writes filename of lib into where and returns TRUE,
795  no, returns FALSE
796 */
797 BOOLEAN iiLocateLib(const char* lib, char* where)
798 {
799  char *plib = iiConvName(lib);
800  idhdl pl = basePack->idroot->get(plib,0);
801  if( (pl!=NULL) && (IDTYP(pl)==PACKAGE_CMD) &&
802  (IDPACKAGE(pl)->language == LANG_SINGULAR))
803  {
804  strncpy(where,IDPACKAGE(pl)->libname,127);
805  return TRUE;
806  }
807  else
808  return FALSE;;
809 }
810 
811 BOOLEAN iiLibCmd( char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force )
812 {
813  char libnamebuf[128];
814  // procinfov pi;
815  // idhdl h;
816  idhdl pl;
817  // idhdl hl;
818  // long pos = 0L;
819  char *plib = iiConvName(newlib);
820  FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror );
821  // int lines = 1;
822  BOOLEAN LoadResult = TRUE;
823 
824  if (fp==NULL)
825  {
826  return TRUE;
827  }
828  pl = basePack->idroot->get(plib,0);
829  if (pl==NULL)
830  {
831  pl = enterid( plib,0, PACKAGE_CMD,
832  &(basePack->idroot), TRUE );
833  IDPACKAGE(pl)->language = LANG_SINGULAR;
834  IDPACKAGE(pl)->libname=omStrDup(newlib);
835  }
836  else
837  {
838  if(IDTYP(pl)!=PACKAGE_CMD)
839  {
840  WarnS("not of type package.");
841  fclose(fp);
842  return TRUE;
843  }
844  if (!force) return FALSE;
845  }
846  LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
847  omFree((ADDRESS)newlib);
848 
849  if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
850  omFree((ADDRESS)plib);
851 
852  return LoadResult;
853 }
854 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
855 static void iiCleanProcs(idhdl &root)
856 {
857  idhdl prev=NULL;
858  loop
859  {
860  if (root==NULL) return;
861  if (IDTYP(root)==PROC_CMD)
862  {
863  procinfo *pi=(procinfo*)IDDATA(root);
864  if ((pi->language == LANG_SINGULAR)
865  && (pi->data.s.body_start == 0L))
866  {
867  // procinfo data incorrect:
868  // - no proc body can start at the beginning of the file
869  killhdl(root);
870  if (prev==NULL)
871  root=IDROOT;
872  else
873  {
874  root=prev;
875  prev=NULL;
876  }
877  continue;
878  }
879  }
880  prev=root;
881  root=IDNEXT(root);
882  }
883 }
884 static void iiRunInit(package p)
885 {
886  idhdl h=p->idroot->get("mod_init",0);
887  if (h==NULL) return;
888  if (IDTYP(h)==PROC_CMD)
889  {
890  int save=yylineno;
891  myynest++;
892  // procinfo *pi=(procinfo*)IDDATA(h);
893  //PrintS("mod_init found\n");
894  iiMake_proc(h,p,NULL);
895  myynest--;
896  yylineno=save;
897  }
898 }
899 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
900 BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char*newlib,
901  idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
902 {
903  extern FILE *yylpin;
904  libstackv ls_start = library_stack;
905  lib_style_types lib_style;
906 
907  yylpin = fp;
908  #if YYLPDEBUG > 1
909  print_init();
910  #endif
911  extern int lpverbose;
912  if (BVERBOSE(V_DEBUG_LIB)) lpverbose=1;
913  else lpverbose=0;
914  // yylplex sets also text_buffer
915  if (text_buffer!=NULL) *text_buffer='\0';
916  yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
917  if(yylp_errno)
918  {
919  Werror("Library %s: ERROR occured: in line %d, %d.", newlib, yylplineno,
920  current_pos(0));
922  {
925  text_buffer=NULL;
926  }
927  else
929  Werror("Cannot load library,... aborting.");
930  reinit_yylp();
931  fclose( yylpin );
933  return TRUE;
934  }
935  if (BVERBOSE(V_LOAD_LIB))
936  Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
937  if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
938  {
939  Warn( "library %s has old format. This format is still accepted,", newlib);
940  Warn( "but for functionality you may wish to change to the new");
941  Warn( "format. Please refer to the manual for further information.");
942  }
943  reinit_yylp();
944  fclose( yylpin );
945  fp = NULL;
946  iiRunInit(IDPACKAGE(pl));
947 
948  {
949  libstackv ls;
950  for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
951  {
952  if(ls->to_be_done)
953  {
954  ls->to_be_done=FALSE;
955  iiLibCmd(ls->get(),autoexport,tellerror,FALSE);
956  ls = ls->pop(newlib);
957  }
958  }
959 #if 0
960  PrintS("--------------------\n");
961  for(ls = library_stack; ls != NULL; ls = ls->next)
962  {
963  Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
964  ls->to_be_done ? "not loaded" : "loaded");
965  }
966  PrintS("--------------------\n");
967 #endif
968  }
969 
970  if(fp != NULL) fclose(fp);
971  return FALSE;
972 }
973 
974 
975 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
977  const char *procname, int line, long pos, BOOLEAN pstatic)
978 {
979  pi->libname = omStrDup(libname);
980  pi->procname = omStrDup(procname);
981  pi->language = LANG_SINGULAR;
982  pi->ref = 1;
983  pi->pack = NULL;
984  pi->is_static = pstatic;
985  pi->data.s.proc_start = pos;
986  pi->data.s.def_end = 0L;
987  pi->data.s.help_start = 0L;
988  pi->data.s.help_end = 0L;
989  pi->data.s.body_start = 0L;
990  pi->data.s.body_end = 0L;
991  pi->data.s.example_start = 0L;
992  pi->data.s.proc_lineno = line;
993  pi->data.s.body_lineno = 0;
994  pi->data.s.example_lineno = 0;
995  pi->data.s.body = NULL;
996  pi->data.s.help_chksum = 0;
997  return(pi);
998 }
999 
1000 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1001 int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1002  BOOLEAN(*func)(leftv res, leftv v))
1003 {
1004  procinfov pi;
1005  idhdl h;
1006 
1007  #ifndef SING_NDEBUG
1008  int dummy;
1009  if (IsCmd(procname,dummy))
1010  {
1011  Werror(">>%s< is a reserved name",procname);
1012  return 0;
1013  }
1014  #endif
1015 
1016  h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
1017  if ( h!= NULL )
1018  {
1019  pi = IDPROC(h);
1020  pi->libname = omStrDup(libname);
1021  pi->procname = omStrDup(procname);
1022  pi->language = LANG_C;
1023  pi->ref = 1;
1024  pi->is_static = pstatic;
1025  pi->data.o.function = func;
1026  return(1);
1027  }
1028  else
1029  {
1030  PrintS("iiAddCproc: failed.\n");
1031  }
1032  return(0);
1033 }
1034 
1035 int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic,
1036  BOOLEAN(*func)(leftv res, leftv v))
1037 {
1038  int r=iiAddCproc(libname,procname,pstatic,func);
1039  package s=currPack;
1041  if (r) r=iiAddCproc(libname,procname,pstatic,func);
1042  currPack=s;
1043  return r;
1044 }
1045 
1046 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1047 #ifdef HAVE_DYNAMIC_LOADING
1048 BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
1049 {
1050 #ifdef HAVE_STATIC
1051  WerrorS("mod_init: static version can not load modules");
1052  return TRUE;
1053 #else
1054 /*
1055  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1056  BOOLEAN pstatic,
1057  BOOLEAN(*func)(leftv res, leftv v)));
1058 */
1059  SModulFunc_t fktn;
1060  idhdl pl;
1061  char *plib = iiConvName(newlib);
1062  BOOLEAN RET=TRUE;
1063  int token;
1064  char FullName[256];
1065 
1066  memset(FullName,0,256);
1067 
1068  if( *fullname != '/' && *fullname != '.' )
1069  sprintf(FullName, "./%s", newlib);
1070  else strncpy(FullName, fullname,255);
1071 
1072 
1073  if(IsCmd(plib, token))
1074  {
1075  Werror("'%s' is resered identifier\n", plib);
1076  goto load_modules_end;
1077  }
1078  pl = basePack->idroot->get(plib,0); /* packages only in top level
1079  (see enterid) */
1080  if (pl==NULL)
1081  {
1082  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
1083  TRUE );
1084  IDPACKAGE(pl)->language = LANG_C;
1085  IDPACKAGE(pl)->libname=omStrDup(newlib);
1086  }
1087  else
1088  {
1089  if(IDTYP(pl)!=PACKAGE_CMD)
1090  {
1091  Warn("not of type package.");
1092  goto load_modules_end;
1093  }
1094  }
1095  if (dynl_check_opened(FullName))
1096  {
1097  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded", fullname);
1098  return FALSE;
1099  }
1100  if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1101  {
1102  Werror("dynl_open failed:%s", dynl_error());
1103  Werror("%s not found", newlib);
1104  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1105  goto load_modules_end;
1106  }
1107  else
1108  {
1109  SModulFunctions sModulFunctions;
1110 
1111  package s=currPack;
1112  currPack=IDPACKAGE(pl);
1113  fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1114  if( fktn!= NULL)
1115  {
1116  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1117  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1118  else sModulFunctions.iiAddCproc = iiAddCproc;
1119  int ver=(*fktn)(&sModulFunctions);
1120  if (ver==MAX_TOK)
1121  {
1122  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1123  }
1124  else
1125  {
1126  Warn("// ** loaded %s for a different version of Singular(expected: %d, got %d)",fullname,MAX_TOK,ver);
1127  }
1128  currPack->loaded=1;
1129  currPack=s;
1130  RET=FALSE;
1131  }
1132  else
1133  {
1134  Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1135  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1136  }
1137  }
1138 
1139  load_modules_end:
1140  return RET;
1141 #endif /*STATIC */
1142 }
1143 #endif /* HAVE_DYNAMIC_LOADING */
1144 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1145 BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
1146 {
1147  int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1148  BOOLEAN(*func)(leftv res, leftv v));
1149 /*
1150  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1151  BOOLEAN pstatic,
1152  BOOLEAN(*func)(leftv res, leftv v)));
1153 */
1154  // SModulFunc_t fktn;
1155  idhdl pl;
1156  char *plib = iiConvName(newlib);
1157  // BOOLEAN RET=TRUE;
1158  // int token;
1159 
1160  pl = IDROOT->get(plib,0);
1161  if (pl!=NULL)
1162  {
1163  if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1164  omFree(plib);
1165  return FALSE;
1166  }
1167 
1168  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
1169  TRUE );
1170  IDPACKAGE(pl)->language = LANG_C;
1171  IDPACKAGE(pl)->libname=omStrDup(newlib);
1172 
1173  IDPACKAGE(pl)->handle=(void *)NULL;
1174  SModulFunctions sModulFunctions;
1175 
1176  package s=currPack;
1177  currPack=IDPACKAGE(pl);
1178  if( init!= NULL)
1179  {
1180  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1181  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1182  else sModulFunctions.iiAddCproc = iiAddCproc;
1183  (*init)(&sModulFunctions);
1184  }
1185  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1186  currPack->loaded=1;
1187  currPack=s;
1188 
1189  return FALSE;
1190 }
1191 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1192 void module_help_main(const char *newlib,const char *help)
1193 {
1194  char *plib = iiConvName(newlib);
1195  idhdl pl = basePack->idroot->get(plib,0);
1196  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1197  Werror(">>%s<< is not a package (trying to add package help)",plib);
1198  else
1199  {
1200  package s=currPack;
1201  currPack=IDPACKAGE(pl);
1203  IDSTRING(h)=omStrDup(help);
1204  currPack=s;
1205  }
1206 }
1207 void module_help_proc(const char *newlib,const char *p, const char *help)
1208 {
1209  char *plib = iiConvName(newlib);
1210  idhdl pl = basePack->idroot->get(plib,0);
1211  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1212  Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1213  else
1214  {
1215  package s=currPack;
1216  currPack=IDPACKAGE(pl);
1217  char buff[256];
1218  buff[255]='\0';
1219  strncpy(buff,p,255);
1220  strncat(buff,"_help",255-strlen(p));
1222  IDSTRING(h)=omStrDup(help);
1223  currPack=s;
1224  }
1225 }
1226 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1227 
1228 // loads a dynamic module from the binary path and returns a named function
1229 // returns NULL, if something fails
1230 void* binary_module_function(const char* newlib, const char* funcname)
1231 {
1232  void* result = NULL;
1233 
1234 #if defined(HAVE_STATIC) || !defined(HAVE_DYNAMIC_LOADING)
1235  WerrorS("static version can not load function from dynamic modules");
1236 #else
1237  const char* bin_dir = feGetResource('b');
1238  if (!bin_dir) { return NULL; }
1239 
1240  char path_name[MAXPATHLEN];
1241  sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING);
1242 
1243  void* openlib = dynl_open(path_name);
1244  if(!openlib)
1245  {
1246  Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1247  return NULL;
1248  }
1249  result = dynl_sym(openlib, funcname);
1250  if (!result) Werror("%s: %s\n", funcname, dynl_error());
1251 #endif
1252 
1253  return result;
1254 }
1255 
1256 
1257 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1258 char mytoupper(char c)
1259 {
1260  if(c>=97 && c<=(97+26)) c-=32;
1261  return(c);
1262 }
1263 
1264 char mytolower(char c)
1265 {
1266  if(c>=65 && c<=(65+26)) c+=32;
1267  return(c);
1268 }
1269 
1270 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1271 //#if defined(WINNT)
1272 //# define FS_SEP '\\'
1273 //#else
1274 //# define FS_SEP '/'
1275 //#endif
1276 
1277 char *iiConvName(const char *libname)
1278 {
1279  char *tmpname = omStrDup(libname);
1280  char *p = strrchr(tmpname, DIR_SEP);
1281  char *r;
1282  if(p==NULL) p = tmpname;
1283  else p++;
1284  r = (char *)strchr(p, '.');
1285  if( r!= NULL) *r = '\0';
1286  r = omStrDup(p);
1287  *r = mytoupper(*r);
1288  // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1289  omFree((ADDRESS)tmpname);
1290 
1291  return(r);
1292 }
1293 
1294 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1295 #if 0 /* debug only */
1296 void piShowProcList()
1297 {
1298  idhdl h;
1299  procinfo *proc;
1300  char *name;
1301 
1302  Print( "%-15s %20s %s,%s %s,%s %s,%s\n", "Library", "function",
1303  "line", "start", "line", "body", "line", "example");
1304  for(h = IDROOT; h != NULL; h = IDNEXT(h))
1305  {
1306  if(IDTYP(h) == PROC_CMD)
1307  {
1308  proc = IDPROC(h);
1309  if(strcmp(proc->procname, IDID(h))!=0)
1310  {
1311  name = (char *)omAlloc(strlen(IDID(h))+strlen(proc->procname)+4);
1312  sprintf(name, "%s -> %s", IDID(h), proc->procname);
1313  Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname, name);
1314  omFree((ADDRESS)name);
1315  }
1316  else
1317  Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname,
1318  proc->procname);
1319  if(proc->language==LANG_SINGULAR)
1320  Print("line %4d,%-5ld %4d,%-5ld %4d,%-5ld\n",
1321  proc->data.s.proc_lineno, proc->data.s.proc_start,
1322  proc->data.s.body_lineno, proc->data.s.body_start,
1323  proc->data.s.example_lineno, proc->data.s.example_start);
1324  else if(proc->language==LANG_C)
1325  Print("type: object\n");
1326  }
1327  }
1328 }
1329 #endif
1330 
1331 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1332 //char *iiLineNo(char *procname, int lineno)
1333 //{
1334 // char buf[256];
1335 // idhdl pn = ggetid(procname);
1336 // procinfo *pi = IDPROC(pn);
1337 //
1338 // sprintf(buf, "%s %3d\0", procname, lineno);
1339 // //sprintf(buf, "%s::%s %3d\0", pi->libname, pi->procname,
1340 // // lineno + pi->data.s.body_lineno);
1341 // return(buf);
1342 //}
1343 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1344 #ifdef HAVE_LIBPARSER
1345 void libstack::push(const char */*p*/, char *libn)
1346 {
1347  libstackv lp;
1348  if( !iiGetLibStatus(libn))
1349  {
1350  for(lp = this;lp!=NULL;lp=lp->next)
1351  {
1352  if(strcmp(lp->get(), libn)==0) break;
1353  }
1354  if(lp==NULL)
1355  {
1357  ls->next = this;
1358  ls->libname = omStrDup(libn);
1359  ls->to_be_done = TRUE;
1360  if(this != NULL) ls->cnt = this->cnt+1; else ls->cnt = 0;
1361  library_stack = ls;
1362  }
1363  }
1364 }
1365 
1366 libstackv libstack::pop(const char */*p*/)
1367 {
1368  libstackv ls = this;
1369  //omFree((ADDRESS)ls->libname);
1370  library_stack = ls->next;
1372  return(library_stack);
1373 }
1374 
1375 #endif /* HAVE_LIBPARSER */
1376 /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
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:1145
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:1035
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:322
#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:1258
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:1192
idhdl currPackHdl
Definition: ipid.cc:60
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:976
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:884
#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:167
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:57
static void iiShowLevRings()
Definition: iplib.cc:531
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#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:23
char * get()
Definition: subexpr.h:170
void push(const char *p, char *libname)
Definition: iplib.cc:1345
struct soptionStruct optionStruct[]
Definition: misc_ip.cc:521
#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:1366
#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:811
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:400
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:256
#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:551
BOOLEAN RingDependend()
Definition: subexpr.cc:375
char * libname
Definition: subexpr.h:55
void * binary_module_function(const char *newlib, const char *funcname)
Definition: iplib.cc:1230
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:194
void checkall()
Definition: misc_ip.cc:1016
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:64
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:46
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:1264
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1565
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:797
#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
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:738
void killhdl(idhdl h, package proot)
Definition: ipid.cc:369
package basePack
Definition: ipid.cc:63
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:62
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:307
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:1207
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:900
static void iiCleanProcs(idhdl &root)
Definition: iplib.cc:855
idhdl packFindHdl(package r)
Definition: ipid.cc:729
void yylprestart(FILE *input_file)
void iiCheckPack(package &p)
Definition: ipshell.cc:1504
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:1001
#define IDDATA(a)
Definition: ipid.h:125
void rSetHdl(idhdl h)
Definition: ipshell.cc:4696
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
void push(char *)
Definition: ipid.cc:699
void pop()
Definition: ipid.cc:711
const char * name
Definition: iplib.cc:314
char * iiConvName(const char *libname)
Definition: iplib.cc:1277
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:1048
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:8722
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:9062