My Project
Loading...
Searching...
No Matches
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#include "kernel/mod2.h"
9
10#include "Singular/tok.h"
11#include "misc/options.h"
12#include "Singular/ipid.h"
14#include "Singular/subexpr.h"
15#include "Singular/ipid.h"
16#include "Singular/ipshell.h"
17#include "Singular/fevoices.h"
18#include "Singular/lists.h"
19
20#ifndef SINGULAR_PATH_LENGTH
21#define SINGULAR_PATH_LENGTH 512
22#endif
23
24#include <ctype.h>
25
26#if SIZEOF_LONG == 8
27#define SI_MAX_NEST 500
28#elif defined(__CYGWIN__)
29#define SI_MAX_NEST 480
30#else
31#define SI_MAX_NEST 1000
32#endif
33
34#if defined(ix86Mac_darwin) || defined(x86_64Mac_darwin) || defined(ppcMac_darwin)
35# define MODULE_SUFFIX bundle
36#elif defined(__CYGWIN__)
37# define MODULE_SUFFIX dll
38#else
39# define MODULE_SUFFIX so
40#endif
41
42#define MODULE_SUFFIX_STRING EXPANDED_STRINGIFY(MODULE_SUFFIX)
43
44
45#ifdef HAVE_DYNAMIC_LOADING
46BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport);
47#endif
48
49#ifdef HAVE_LIBPARSER
50# include "libparse.h"
51#else /* HAVE_LIBPARSER */
52procinfo *iiInitSingularProcinfo(procinfov pi, const char *libname,
53 const char *procname, int line, long pos, BOOLEAN pstatic=FALSE);
54#endif /* HAVE_LIBPARSER */
55
56extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval,
57 short nToktype, short nPos);
58
59#include "Singular/mod_lib.h"
60
61#ifdef HAVE_LIBPARSER
62void yylprestart (FILE *input_file );
63int current_pos(int i=0);
66extern const char *yylp_errlist[];
67void print_init();
69#endif
70
71//int IsCmd(char *n, int tok);
72static char mytolower(char c);
73
74/*2
75* return TRUE if the libray libname is already loaded
76*/
77BOOLEAN iiGetLibStatus(const char *lib)
78{
79 idhdl hl;
80
81 char *plib = iiConvName(lib);
82 hl = basePack->idroot->get(plib,0);
83 omFreeBinAddr(plib);
84 if((hl==NULL) ||(IDTYP(hl)!=PACKAGE_CMD))
85 {
86 return FALSE;
87 }
88 if ((IDPACKAGE(hl)->language!=LANG_C)&&(IDPACKAGE(hl)->libname!=NULL))
89 return (strcmp(lib,IDPACKAGE(hl)->libname)==0);
90 return FALSE;
91}
92
93/*2
94* given a line 'proc[ ]+{name}[ \t]*'
95* return a pointer to name and set the end of '\0'
96* changes the input!
97* returns: e: pointer to 'end of name'
98* ct: changed char at the end of s
99*/
100char* iiProcName(char *buf, char & ct, char* &e)
101{
102 char *s=buf+5;
103 while (*s==' ') s++;
104 e=s+1;
105 while ((*e>' ') && (*e!='(')) e++;
106 ct=*e;
107 *e='\0';
108 return s;
109}
110
111/*2
112* given a line with args, return the argstr
113*/
114char * iiProcArgs(char *e,BOOLEAN withParenth)
115{
116 while ((*e==' ') || (*e=='\t') || (*e=='(')) e++;
117 if (*e<' ')
118 {
119 if (withParenth)
120 {
121 // no argument list, allow list #
122 return omStrDup("parameter list #;");
123 }
124 else
125 {
126 // empty list
127 return omStrDup("");
128 }
129 }
130 BOOLEAN in_args;
131 BOOLEAN args_found;
132 char *s;
133 char *argstr=(char *)omAlloc(127); // see ../omalloc/omTables.inc
134 int argstrlen=127;
135 *argstr='\0';
136 int par=0;
137 do
138 {
139 args_found=FALSE;
140 s=e; // set s to the starting point of the arg
141 // and search for the end
142 // skip leading spaces:
143 loop
144 {
145 if ((*s==' ')||(*s=='\t'))
146 s++;
147 else if ((*s=='\n')&&(*(s+1)==' '))
148 s+=2;
149 else // start of new arg or \0 or )
150 break;
151 }
152 e=s;
153 while ((*e!=',')
154 &&((par!=0) || (*e!=')'))
155 &&(*e!='\0'))
156 {
157 if (*e=='(') par++;
158 else if (*e==')') par--;
159 args_found=args_found || (*e>' ');
160 e++;
161 }
162 in_args=(*e==',');
163 if (args_found)
164 {
165 *e='\0';
166 // check for space:
167 if ((int)strlen(argstr)+12 /* parameter + ;*/ +(int)strlen(s)>= argstrlen)
168 {
169 argstrlen*=2;
170 char *a=(char *)omAlloc( argstrlen);
171 strcpy(a,argstr);
172 omFree((ADDRESS)argstr);
173 argstr=a;
174 }
175 // copy the result to argstr
176 if(strncmp(s,"alias ",6)!=0)
177 {
178 strcat(argstr,"parameter ");
179 }
180 strcat(argstr,s);
181 strcat(argstr,"; ");
182 e++; // e was pointing to ','
183 }
184 } while (in_args);
185 return argstr;
186}
187
188/*2
189* locate `procname` in lib `libname` and find the part `part`:
190* part=0: help, between, but excluding the line "proc ..." and "{...":
191* => return
192* part=1: body, between "{ ..." and "}", including the 1. line, w/o "{"
193* => set pi->data.s.body, return NULL
194* part=2: example, between, but excluding the line "exapmle {..." and "}":
195* => return
196*/
198{
199 char buf[SINGULAR_PATH_LENGTH], *s = NULL, *p;
200 long procbuflen;
201
202 FILE * fp = feFopen( pi->libname, "rb", NULL, TRUE );
203 if (fp==NULL)
204 {
205 return NULL;
206 }
207
208 int res=fseek(fp, pi->data.s.proc_start, SEEK_SET);
209 if (res==1) return NULL;
210 if(part==0)
211 { // load help string
212 int i, offset=0;
213 long head = pi->data.s.def_end - pi->data.s.proc_start;
214 procbuflen = pi->data.s.help_end - pi->data.s.help_start;
215 if (procbuflen<5)
216 {
217 fclose(fp);
218 return NULL; // help part does not exist
219 }
220 //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start,
221 // pi->data.s.proc_start, procbuflen);
222 s = (char *)omAlloc(procbuflen+head+3);
223 res=myfread(s, head, 1, fp);
224 if (res<=0) /* error*/ { omFree(s); return NULL; }
225 s[head] = '\n';
226 int res=fseek(fp, pi->data.s.help_start, SEEK_SET);
227 if (res==-1) /*error*/ { omFree(s); return NULL; }
228 res=myfread(s+head+1, procbuflen, 1, fp);
229 if (res<=0) /* error*/ { omFree(s); return NULL; }
230 fclose(fp);
231 s[procbuflen+head+1] = '\n';
232 s[procbuflen+head+2] = '\0';
233 offset=0;
234 for(i=0;i<=procbuflen+head+2; i++)
235 {
236 if(s[i]=='\\' &&
237 (s[i+1]=='"' || s[i+1]=='{' || s[i+1]=='}' || s[i+1]=='\\'))
238 {
239 i++;
240 offset++;
241 }
242 if(offset>0) s[i-offset] = s[i];
243 }
244 return(s);
245 }
246 else if(part==1)
247 { // load proc part - must exist
248 procbuflen = pi->data.s.def_end - pi->data.s.proc_start;
249 char *ss=(char *)omAlloc(procbuflen+2);
250 //fgets(buf, sizeof(buf), fp);
251 myfread( ss, procbuflen, 1, fp);
252 char ct;
253 char *e;
254 s=iiProcName(ss,ct,e);
255 char *argstr=NULL;
256 *e=ct;
257 argstr=iiProcArgs(e,TRUE);
258
259 assume(pi->data.s.body_end > pi->data.s.body_start);
260
261 procbuflen = pi->data.s.body_end - pi->data.s.body_start;
262 pi->data.s.body = (char *)omAlloc( strlen(argstr)+procbuflen+15+
263 strlen(pi->libname) );
264 //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end,
265 // pi->data.s.body_start, procbuflen);
266 assume(pi->data.s.body != NULL);
267 fseek(fp, pi->data.s.body_start, SEEK_SET);
268 strcpy(pi->data.s.body,argstr);
269 myfread( pi->data.s.body+strlen(argstr), procbuflen, 1, fp);
270 fclose( fp );
271 procbuflen+=strlen(argstr);
272 omFree(argstr);
273 omFree(ss);
274 pi->data.s.body[procbuflen] = '\0';
275 strcat( pi->data.s.body+procbuflen, "\n;return();\n\n" );
276 strcat( pi->data.s.body+procbuflen+13,pi->libname);
277 s=(char *)strchr(pi->data.s.body,'{');
278 if (s!=NULL) *s=' ';
279 return NULL;
280 }
281 else if(part==2)
282 { // example
283 if ( pi->data.s.example_lineno == 0)
284 return NULL; // example part does not exist
285 // load example
286 fseek(fp, pi->data.s.example_start, SEEK_SET);
287 char* res=fgets(buf, sizeof(buf), fp); // skip line with "example"
288 if (res==NULL) /*error or eof*/
289 {
290 return omStrDup("");
291 }
292 procbuflen = pi->data.s.proc_end - pi->data.s.example_start - strlen(buf);
293 //Print("Example=%ld-%ld=%d\n", pi->data.s.proc_end,
294 // pi->data.s.example_start, procbuflen);
295 s = (char *)omAlloc(procbuflen+14);
296 myfread(s, procbuflen, 1, fp);
297 s[procbuflen] = '\0';
298 strcat(s+procbuflen-3, "\n;return();\n\n" );
299 p=(char *)strchr(s,'{');
300 if (p!=NULL) *p=' ';
301 return(s);
302 }
303 return NULL;
304}
305
307{
308 int save_trace=traceit;
309 int restore_traceit=0;
310 if (traceit_stop
312 {
314 traceit_stop=0;
315 restore_traceit=1;
316 }
317 // see below:
318 BITSET save1=si_opt_1;
319 BITSET save2=si_opt_2;
320 newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/,
321 pi, l );
322 BOOLEAN err=yyparse();
323
324 if (sLastPrinted.rtyp!=0)
325 {
326 sLastPrinted.CleanUp();
327 }
328
329 if (restore_traceit) traceit=save_trace;
330
331 // the access to optionStruct and verboseStruct do not work
332 // on x86_64-Linux for pic-code
333 if ((TEST_V_ALLWARN) &&
334 (t==BT_proc) &&
335 ((save1!=si_opt_1)||(save2!=si_opt_2)) &&
336 (pi->libname!=NULL) && (pi->libname[0]!='\0'))
337 {
338 if ((pi->libname!=NULL) && (pi->libname[0]!='\0'))
339 Warn("option changed in proc %s from %s",pi->procname,pi->libname);
340 else
341 Warn("option changed in proc %s",pi->procname);
342 int i;
343 for (i=0; optionStruct[i].setval!=0; i++)
344 {
345 if ((optionStruct[i].setval & si_opt_1)
346 && (!(optionStruct[i].setval & save1)))
347 {
348 Print(" +%s",optionStruct[i].name);
349 }
350 if (!(optionStruct[i].setval & si_opt_1)
351 && ((optionStruct[i].setval & save1)))
352 {
353 Print(" -%s",optionStruct[i].name);
354 }
355 }
356 for (i=0; verboseStruct[i].setval!=0; i++)
357 {
358 if ((verboseStruct[i].setval & si_opt_2)
359 && (!(verboseStruct[i].setval & save2)))
360 {
361 Print(" +%s",verboseStruct[i].name);
362 }
363 if (!(verboseStruct[i].setval & si_opt_2)
364 && ((verboseStruct[i].setval & save2)))
365 {
366 Print(" -%s",verboseStruct[i].name);
367 }
368 }
369 PrintLn();
370 }
371 return err;
372}
373/*2
374* start a proc
375* parameters are built as exprlist
376* TODO:interrupt
377* return FALSE on success, TRUE if an error occurs
378*/
380{
382 int old_echo=si_echo;
383 BOOLEAN err=FALSE;
384 char save_flags=0;
385
386 /* init febase ======================================== */
387 /* we do not enter this case if filename != NULL !! */
388 if (pn!=NULL)
389 {
390 pi = IDPROC(pn);
391 if(pi!=NULL)
392 {
393 save_flags=pi->trace_flag;
394 if( pi->data.s.body==NULL )
395 {
397 if (pi->data.s.body==NULL) return TRUE;
398 }
399// omUpdateInfo();
400// int m=om_Info.UsedBytes;
401// Print("proc %s, mem=%d\n",IDID(pn),m);
402 }
403 }
404 else return TRUE;
405 /* generate argument list ======================================*/
406 //iiCurrArgs should be NULL here, as the assignment for the parameters
407 // of the prevouis call are already done befor calling another routine
408 if (v!=NULL)
409 {
411 memcpy(iiCurrArgs,v,sizeof(sleftv)); // keeps track of v->next etc.
412 v->Init();
413 }
414 else
415 {
418 }
419 /* start interpreter ======================================*/
420 myynest++;
421 if (myynest > SI_MAX_NEST)
422 {
423 WerrorS("nesting too deep");
424 err=TRUE;
425 }
426 else
427 {
428 iiCurrProc=pn;
429 err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
431
432 if (iiLocalRing[myynest-1] != currRing)
433 {
434 if (iiRETURNEXPR.RingDependend())
435 {
436 //idhdl hn;
437 const char *n;
438 const char *o;
439 idhdl nh=NULL, oh=NULL;
440 if (iiLocalRing[myynest-1]!=NULL)
442 if (oh!=NULL) o=oh->id;
443 else o="none";
444 if (currRing!=NULL)
446 if (nh!=NULL) n=nh->id;
447 else n="none";
448 Werror("ring change during procedure call %s: %s -> %s (level %d)",pi->procname,o,n,myynest);
449 iiRETURNEXPR.CleanUp();
450 err=TRUE;
451 }
453 }
454 if ((currRing==NULL)
455 && (currRingHdl!=NULL))
457 else
458 if ((currRing!=NULL) &&
460 ||(IDLEV(currRingHdl)>=myynest-1)))
461 {
464 }
465 //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
467#ifndef SING_NDEBUG
468 checkall();
469#endif
470 //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
471 }
472 myynest--;
473 si_echo=old_echo;
474 if (pi!=NULL)
475 pi->trace_flag=save_flags;
476// omUpdateInfo();
477// int m=om_Info.UsedBytes;
478// Print("exit %s, mem=%d\n",IDID(pn),m);
479 return err;
480}
481
485
486#ifdef RDEBUG
487static void iiShowLevRings()
488{
489 int i;
490 for (i=0;i<=myynest;i++)
491 {
492 Print("lev %d:",i);
493 if (iiLocalRing[i]==NULL) PrintS("NULL");
494 else Print("%lx",(long)iiLocalRing[i]);
495 PrintLn();
496 }
497 if (currRing==NULL) PrintS("curr:NULL\n");
498 else Print ("curr:%lx\n",(long)currRing);
499}
500#endif /* RDEBUG */
501
502static void iiCheckNest()
503{
504 if (myynest >= iiRETURNEXPR_len-1)
505 {
507 iiRETURNEXPR_len*sizeof(ring),
508 (iiRETURNEXPR_len+16)*sizeof(ring));
509 memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
511 }
512}
514{
515 int err;
516 procinfov pi = IDPROC(pn);
517 if(pi->is_static && myynest==0)
518 {
519 Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
520 pi->libname, pi->procname);
521 return TRUE;
522 }
523 iiCheckNest();
525 //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
526 iiRETURNEXPR.Init();
527 procstack->push(pi->procname);
529 || (pi->trace_flag&TRACE_SHOW_PROC))
530 {
532 Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
533 }
534#ifdef RDEBUG
536#endif
537 switch (pi->language)
538 {
539 default:
540 case LANG_NONE:
541 WerrorS("undefined proc");
542 err=TRUE;
543 break;
544
545 case LANG_SINGULAR:
546 if ((pi->pack!=NULL)&&(currPack!=pi->pack))
547 {
548 currPack=pi->pack;
551 //Print("set pack=%s\n",IDID(currPackHdl));
552 }
553 else if ((pack!=NULL)&&(currPack!=pack))
554 {
555 currPack=pack;
558 //Print("set pack=%s\n",IDID(currPackHdl));
559 }
560 err=iiPStart(pn,args);
561 break;
562 case LANG_C:
564 err = (pi->data.o.function)(res, args);
565 memcpy(&iiRETURNEXPR,res,sizeof(iiRETURNEXPR));
567 break;
568 }
570 || (pi->trace_flag&TRACE_SHOW_PROC))
571 {
573 Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
574 }
575 //const char *n="NULL";
576 //if (currRingHdl!=NULL) n=IDID(currRingHdl);
577 //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
578#ifdef RDEBUG
580#endif
581 if (err)
582 {
583 iiRETURNEXPR.CleanUp();
584 //iiRETURNEXPR.Init(); //done by CleanUp
585 }
586 if (iiCurrArgs!=NULL)
587 {
588 if (!err) Warn("too many arguments for %s",IDID(pn));
589 iiCurrArgs->CleanUp();
592 }
593 procstack->pop();
594 if (err)
595 return TRUE;
596 return FALSE;
597}
599{
600 idhdl tmp_ring=NULL;
601 if (currRing!=NULL)
602 {
604 {
605 // clean up things depending on currRingHdl:
607 sLastPrinted.Init();
608 }
609 // need to define a ring-hdl for currRingHdl
610 tmp_ring=enterid(" tmpRing",myynest,RING_CMD,&IDROOT,FALSE);
611 IDRING(tmp_ring)=rIncRefCnt(currRing);
612 rSetHdl(tmp_ring);
613 }
614}
615static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
616{
617 if ((currRing!=NULL)
618 &&(currRing!=save_ring))
619 {
620 idhdl hh=IDROOT;
621 idhdl prev=NULL;
622 while((hh!=currRingHdl) && (hh!=NULL)) { prev=hh; hh=hh->next; }
623 if ((hh!=NULL)&&(strcmp(IDID(hh)," tmpRing")==0))
624 {
626 if (prev==NULL) IDROOT=hh->next;
627 else prev->next=hh->next;
628 omFree((ADDRESS)IDID(hh));
630 }
631 }
632 currRingHdl=save_ringhdl;
633 currRing=save_ring;
634}
635
636void* iiCallLibProc1(const char*n, void *arg, int arg_type, BOOLEAN &err)
637{
638 idhdl h=ggetid(n);
639 if ((h==NULL)
640 || (IDTYP(h)!=PROC_CMD))
641 {
642 err=2;
643 return NULL;
644 }
645 // ring handling
646 idhdl save_ringhdl=currRingHdl;
647 ring save_ring=currRing;
649 // argument:
650 sleftv tmp;
651 tmp.Init();
652 tmp.data=arg;
653 tmp.rtyp=arg_type;
654 // call proc
655 err=iiMake_proc(h,currPack,&tmp);
656 // clean up ring
657 iiCallLibProcEnd(save_ringhdl,save_ring);
658 // return
659 if (err==FALSE)
660 {
661 void*r=iiRETURNEXPR.data;
662 iiRETURNEXPR.data=NULL;
663 iiRETURNEXPR.CleanUp();
664 return r;
665 }
666 return NULL;
667}
668
669// return NULL on failure
670ideal ii_CallProcId2Id(const char *lib,const char *proc, ideal arg, const ring R)
671{
672 char *plib = iiConvName(lib);
673 idhdl h=ggetid(plib);
674 omFreeBinAddr(plib);
675 if (h==NULL)
676 {
678 if (bo) return NULL;
679 }
680 ring oldR=currRing;
682 BOOLEAN err;
683 ideal I=(ideal)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
684 rChangeCurrRing(oldR);
685 if (err) return NULL;
686 return I;
687}
688
689int ii_CallProcId2Int(const char *lib,const char *proc, ideal arg, const ring R)
690{
691 char *plib = iiConvName(lib);
692 idhdl h=ggetid(plib);
693 omFreeBinAddr(plib);
694 if (h==NULL)
695 {
697 if (bo) return 0;
698 }
699 BOOLEAN err;
700 ring oldR=currRing;
702 int I=(int)(long)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
703 rChangeCurrRing(oldR);
704 if (err) return 0;
705 return I;
706}
707
708/// args: NULL terminated array of arguments
709/// arg_types: 0 terminated array of corresponding types
710leftv ii_CallLibProcM(const char*n, void **args, int* arg_types, const ring R, BOOLEAN &err)
711{
712 idhdl h=ggetid(n);
713 if ((h==NULL)
714 || (IDTYP(h)!=PROC_CMD))
715 {
716 err=2;
717 return NULL;
718 }
719 // ring handling
720 idhdl save_ringhdl=currRingHdl;
721 ring save_ring=currRing;
724 // argument:
725 if (arg_types[0]!=0)
726 {
727 sleftv tmp;
728 leftv tt=&tmp;
729 int i=1;
730 tmp.Init();
731 tmp.data=args[0];
732 tmp.rtyp=arg_types[0];
733 while(arg_types[i]!=0)
734 {
736 tt=tt->next;
737 tt->rtyp=arg_types[i];
738 tt->data=args[i];
739 i++;
740 }
741 // call proc
742 err=iiMake_proc(h,currPack,&tmp);
743 }
744 else
745 // call proc
747 // clean up ring
748 iiCallLibProcEnd(save_ringhdl,save_ring);
749 // return
750 if (err==FALSE)
751 {
753 memcpy(h,&iiRETURNEXPR,sizeof(sleftv));
754 iiRETURNEXPR.Init();
755 return h;
756 }
757 return NULL;
758}
759/*2
760* start an example (as a proc),
761* destroys the string 'example'
762*/
763BOOLEAN iiEStart(char* example, procinfo *pi)
764{
765 BOOLEAN err;
766 int old_echo=si_echo;
767
768 iiCheckNest();
769 procstack->push(example);
772 {
773 if (traceit&TRACE_SHOW_LINENO) printf("\n");
774 printf("entering example (level %d)\n",myynest);
775 }
776 myynest++;
777
778 err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
779
781 myynest--;
782 si_echo=old_echo;
784 {
785 if (traceit&TRACE_SHOW_LINENO) printf("\n");
786 printf("leaving -example- (level %d)\n",myynest);
787 }
789 {
791 {
794 }
795 else
796 {
799 }
800 }
801 procstack->pop();
802 return err;
803}
804
805
806extern "C"
807{
808# define SI_GET_BUILTIN_MOD_INIT0(name) int SI_MOD_INIT0(name)(SModulFunctions*);
810# undef SI_GET_BUILTIN_MOD_INIT0
811};
812
813extern "C" int flint_mod_init(SModulFunctions* psModulFunctions);
814
816iiGetBuiltinModInit(const char* libname)
817{
818#ifdef HAVE_FLINT
819 if (strcmp(libname,"flint.so")==0) return SI_MOD_INIT0(flint);
820#endif
821# define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
823# undef SI_GET_BUILTIN_MOD_INIT
824
825 return NULL;
826}
827
828
829
830
831/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
832BOOLEAN iiTryLoadLib(leftv v, const char *id)
833{
834 BOOLEAN LoadResult = TRUE;
835 char libnamebuf[1024];
836 size_t len=strlen(id)+5;
837 char *libname = (char *)omAlloc(len);
838 const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
839 int i = 0;
840 // FILE *fp;
841 // package pack;
842 // idhdl packhdl;
843 lib_types LT;
844 for(i=0; suffix[i] != NULL; i++)
845 {
846 snprintf(libname,len, "%s%s", id, suffix[i]);
847 *libname = mytolower(*libname);
848 if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
849 {
850 #ifdef HAVE_DYNAMIC_LOADING
851 char libnamebuf[1024];
852 #endif
853
854 if (LT==LT_SINGULAR)
855 LoadResult = iiLibCmd(libname, FALSE, FALSE,TRUE);
856 #ifdef HAVE_DYNAMIC_LOADING
857 else if ((LT==LT_ELF) || (LT==LT_HPUX))
858 LoadResult = load_modules(libname,libnamebuf,FALSE);
859 #endif
860 else if (LT==LT_BUILTIN)
861 {
862 LoadResult=load_builtin(libname,FALSE, iiGetBuiltinModInit(libname));
863 }
864 if(!LoadResult )
865 {
866 v->name = iiConvName(libname);
867 break;
868 }
869 }
870 }
871 omFree(libname);
872 return LoadResult;
873}
874
875/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
876/* check, if library lib has already been loaded
877 if yes, writes filename of lib into where and returns TRUE,
878 no, returns FALSE
879*/
880BOOLEAN iiLocateLib(const char* lib, char* where)
881{
882 char *plib = iiConvName(lib);
883 idhdl pl = basePack->idroot->get(plib,0);
884 if( (pl!=NULL) && (IDTYP(pl)==PACKAGE_CMD) &&
885 (IDPACKAGE(pl)->language == LANG_SINGULAR))
886 {
887 strncpy(where,IDPACKAGE(pl)->libname,127);
888 return TRUE;
889 }
890 else
891 return FALSE;;
892}
893
894BOOLEAN iiLibCmd( const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force )
895{
896 if (strcmp(newlib,"Singular")==0) return FALSE;
897 char libnamebuf[1024];
898 idhdl pl;
899 char *plib = iiConvName(newlib);
900 FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror );
901 // int lines = 1;
902 BOOLEAN LoadResult = TRUE;
903
904 if (fp==NULL)
905 {
906 return TRUE;
907 }
908 pl = basePack->idroot->get(plib,0);
909 if (pl==NULL)
910 {
911 pl = enterid( plib,0, PACKAGE_CMD,
912 &(basePack->idroot), TRUE );
913 IDPACKAGE(pl)->language = LANG_SINGULAR;
914 IDPACKAGE(pl)->libname=omStrDup(newlib);
915 }
916 else
917 {
918 if(IDTYP(pl)!=PACKAGE_CMD)
919 {
920 omFreeBinAddr(plib);
921 WarnS("not of type package.");
922 fclose(fp);
923 return TRUE;
924 }
925 if (!force)
926 {
927 omFreeBinAddr(plib);
928 return FALSE;
929 }
930 }
931 LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
932
933 if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
934 omFree((ADDRESS)plib);
935 return LoadResult;
936}
937/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
938static void iiCleanProcs(idhdl &root)
939{
940 idhdl prev=NULL;
941 loop
942 {
943 if (root==NULL) return;
944 if (IDTYP(root)==PROC_CMD)
945 {
946 procinfo *pi=(procinfo*)IDDATA(root);
947 if ((pi->language == LANG_SINGULAR)
948 && (pi->data.s.body_start == 0L))
949 {
950 // procinfo data incorrect:
951 // - no proc body can start at the beginning of the file
952 killhdl(root);
953 if (prev==NULL)
954 root=IDROOT;
955 else
956 {
957 root=prev;
958 prev=NULL;
959 }
960 continue;
961 }
962 }
963 prev=root;
964 root=IDNEXT(root);
965 }
966}
967static void iiRunInit(package p)
968{
969 idhdl h=p->idroot->get("mod_init",0);
970 if (h==NULL) return;
971 if (IDTYP(h)==PROC_CMD)
972 {
973 int save=yylineno;
974 myynest++;
975 // procinfo *pi=(procinfo*)IDDATA(h);
976 //PrintS("mod_init found\n");
978 myynest--;
979 yylineno=save;
980 }
981}
982/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
983BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char*newlib,
984 idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
985{
986 EXTERN_VAR FILE *yylpin;
987 libstackv ls_start = library_stack;
988 lib_style_types lib_style;
989
990 yylpin = fp;
991 #if YYLPDEBUG > 1
992 print_init();
993 #endif
996 else lpverbose=0;
997 // yylplex sets also text_buffer
998 if (text_buffer!=NULL) *text_buffer='\0';
999 yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
1000 if(yylp_errno)
1001 {
1002 Werror("Library %s: ERROR occurred: in line %d, %d.", newlib, yylplineno,
1003 current_pos(0));
1005 {
1009 }
1010 else
1012 WerrorS("Cannot load library,... aborting.");
1013 reinit_yylp();
1014 fclose( yylpin );
1016 return TRUE;
1017 }
1018 if (BVERBOSE(V_LOAD_LIB))
1019 Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
1020 if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
1021 {
1022 Warn( "library %s has old format. This format is still accepted,", newlib);
1023 WarnS( "but for functionality you may wish to change to the new");
1024 WarnS( "format. Please refer to the manual for further information.");
1025 }
1026 reinit_yylp();
1027 fclose( yylpin );
1028 fp = NULL;
1029 iiRunInit(IDPACKAGE(pl));
1030
1031 {
1032 libstackv ls;
1033 for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
1034 {
1035 if(ls->to_be_done)
1036 {
1037 ls->to_be_done=FALSE;
1038 iiLibCmd(ls->get(),autoexport,tellerror,FALSE);
1039 ls = ls->pop(newlib);
1040 }
1041 }
1042#if 0
1043 PrintS("--------------------\n");
1044 for(ls = library_stack; ls != NULL; ls = ls->next)
1045 {
1046 Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
1047 ls->to_be_done ? "not loaded" : "loaded");
1048 }
1049 PrintS("--------------------\n");
1050#endif
1051 }
1052
1053 if(fp != NULL) fclose(fp);
1054 return FALSE;
1055}
1056
1057
1058/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1060 const char *procname, int, long pos, BOOLEAN pstatic)
1061{
1062 memset(pi,0,sizeof(*pi));
1063 pi->libname = omStrDup(libname);
1064 pi->procname = omStrDup(procname);
1065 pi->language = LANG_SINGULAR;
1066 pi->ref = 1;
1067 pi->is_static = pstatic;
1068 pi->data.s.proc_start = pos;
1069 return(pi);
1070}
1071
1072/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1073int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1074 BOOLEAN(*func)(leftv res, leftv v))
1075{
1076 procinfov pi;
1077 idhdl h;
1078
1079 #ifndef SING_NDEBUG
1080 int dummy;
1081 if (IsCmd(procname,dummy))
1082 {
1083 Werror(">>%s< is a reserved name",procname);
1084 return 0;
1085 }
1086 #endif
1087
1088 h=IDROOT->get(procname,0);
1089 if ((h!=NULL)
1090 && (IDTYP(h)==PROC_CMD))
1091 {
1092 pi = IDPROC(h);
1093 #if 0
1094 if ((pi->language == LANG_SINGULAR)
1095 &&(BVERBOSE(V_REDEFINE)))
1096 Warn("extend `%s`",procname);
1097 #endif
1098 }
1099 else
1100 {
1101 h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
1102 }
1103 if ( h!= NULL )
1104 {
1105 pi = IDPROC(h);
1106 if((pi->language == LANG_SINGULAR)
1107 ||(pi->language == LANG_NONE))
1108 {
1109 omfree(pi->libname);
1110 pi->libname = omStrDup(libname);
1111 omfree(pi->procname);
1112 pi->procname = omStrDup(procname);
1113 pi->language = LANG_C;
1114 pi->ref = 1;
1115 pi->is_static = pstatic;
1116 pi->data.o.function = func;
1117 }
1118 else if(pi->language == LANG_C)
1119 {
1120 if(pi->data.o.function == func)
1121 {
1122 pi->ref++;
1123 }
1124 else
1125 {
1126 omfree(pi->libname);
1127 pi->libname = omStrDup(libname);
1128 omfree(pi->procname);
1129 pi->procname = omStrDup(procname);
1130 pi->language = LANG_C;
1131 pi->ref = 1;
1132 pi->is_static = pstatic;
1133 pi->data.o.function = func;
1134 }
1135 }
1136 else
1137 Warn("internal error: unknown procedure type %d",pi->language);
1138 if (currPack->language==LANG_SINGULAR) currPack->language=LANG_MIX;
1139 return(1);
1140 }
1141 else
1142 {
1143 WarnS("iiAddCproc: failed.");
1144 }
1145 return(0);
1146}
1147
1148int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic,
1149 BOOLEAN(*func)(leftv res, leftv v))
1150{
1151 int r=iiAddCproc(libname,procname,pstatic,func);
1152 package s=currPack;
1154 if (r) r=iiAddCproc(libname,procname,pstatic,func);
1155 currPack=s;
1156 return r;
1157}
1158
1159/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1160#ifdef HAVE_DYNAMIC_LOADING
1161#include <map>
1162#include <string>
1163#include <pthread.h>
1164
1165THREAD_VAR std::map<std::string, void *> *dyn_modules;
1166
1167bool registered_dyn_module(char *fullname) {
1168 if (dyn_modules == NULL)
1169 return false;
1170 std::string fname = fullname;
1171 return dyn_modules->count(fname) != 0;
1172}
1173
1174void register_dyn_module(char *fullname, void * handle) {
1175 std::string fname = fullname;
1176 if (dyn_modules == NULL)
1177 dyn_modules = new std::map<std::string, void *>();
1178 dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1179}
1180
1182 for (std::map<std::string, void *>::iterator it = dyn_modules->begin();
1183 it != dyn_modules->end();
1184 it++)
1185 {
1186 dynl_close(it->second);
1187 }
1188 delete dyn_modules;
1189 dyn_modules = NULL;
1190}
1191BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
1192{
1193/*
1194 typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1195 BOOLEAN pstatic,
1196 BOOLEAN(*func)(leftv res, leftv v)));
1197*/
1198 SModulFunc_t fktn;
1199 idhdl pl;
1200 char *plib = iiConvName(newlib);
1201 BOOLEAN RET=TRUE;
1202 int token;
1203 int l=si_max((int)strlen(fullname),(int)strlen(newlib))+3;
1204 char *FullName=(char*)omAlloc0(l);
1205
1206 if( *fullname != '/' && *fullname != '.' )
1207 snprintf(FullName,l, "./%s", newlib);
1208 else strncpy(FullName, fullname,l);
1209
1210
1211 if(IsCmd(plib, token))
1212 {
1213 Werror("'%s' is resered identifier\n", plib);
1214 goto load_modules_end;
1215 }
1216 pl = basePack->idroot->get(plib,0); /* packages only in top level
1217 (see enterid) */
1218 if ((pl!=NULL)
1219 &&(IDTYP(pl)==PACKAGE_CMD))
1220 {
1221 if(IDPACKAGE(pl)->language==LANG_C)
1222 {
1223 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as package", newlib);
1224 omFreeBinAddr(plib);
1225 return FALSE;
1226 }
1227 else if(IDPACKAGE(pl)->language==LANG_MIX)
1228 {
1229 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s contain binary parts, cannot load", newlib);
1230 omFreeBinAddr(plib);
1231 return FALSE;
1232 }
1233 }
1234 else
1235 {
1236 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1237 omFreeBinAddr(plib); /* enterid copied plib*/
1238 IDPACKAGE(pl)->libname=omStrDup(newlib);
1239 }
1240 IDPACKAGE(pl)->language = LANG_C;
1241 if (dynl_check_opened(FullName))
1242 {
1243 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
1244 omFreeSize(FullName,l);
1245 return FALSE;
1246 }
1247 if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1248 {
1249 Werror("dynl_open failed:%s", dynl_error());
1250 Werror("%s not found", newlib);
1251 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1252 goto load_modules_end;
1253 }
1254 else
1255 {
1256 SModulFunctions sModulFunctions;
1257
1258 package s=currPack;
1259 currPack=IDPACKAGE(pl);
1260 fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1261 if( fktn!= NULL)
1262 {
1263 sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1264 if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1265 else sModulFunctions.iiAddCproc = iiAddCproc;
1266 int ver=(*fktn)(&sModulFunctions);
1267 if (ver==MAX_TOK)
1268 {
1269 if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1270 }
1271 else
1272 {
1273 Warn("loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,MAX_TOK,ver);
1274 }
1275 currPack->loaded=1;
1276 currPack=s; /* reset currPack to previous */
1277 register_dyn_module(fullname, IDPACKAGE(pl)->handle);
1278 RET=FALSE;
1279 }
1280 else
1281 {
1282 Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1283 errorreported=0;
1284 if(IDPACKAGE(pl)->idroot==NULL)
1285 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1286 }
1287 }
1288
1289 load_modules_end:
1290 omFreeSize(FullName,l);
1291 return RET;
1292}
1293
1294BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
1295{
1296 GLOBAL_VAR static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1297 pthread_mutex_lock(&mutex);
1298 BOOLEAN r = load_modules_aux(newlib, fullname, autoexport);
1299 pthread_mutex_unlock(&mutex);
1300 return r;
1301}
1302#endif /* HAVE_DYNAMIC_LOADING */
1303/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1304BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
1305{
1306 int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1307 BOOLEAN(*func)(leftv res, leftv v));
1308/*
1309 typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1310 BOOLEAN pstatic,
1311 BOOLEAN(*func)(leftv res, leftv v)));
1312*/
1313 // SModulFunc_t fktn;
1314 idhdl pl;
1315 char *plib = iiConvName(newlib);
1316 // BOOLEAN RET=TRUE;
1317 // int token;
1318
1319 pl = basePack->idroot->get(plib,0); // search PACKAGE only in Top
1320 if ((pl!=NULL)
1321 &&(IDTYP(pl)==PACKAGE_CMD))
1322 {
1323 if(IDPACKAGE(pl)->language==LANG_C)
1324 {
1325 if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1326 omFreeBinAddr(plib);
1327 return FALSE;
1328 }
1329 }
1330 else
1331 {
1332 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1333 IDPACKAGE(pl)->libname=omStrDup(newlib);
1334 }
1335 omFreeBinAddr(plib);
1336 IDPACKAGE(pl)->language = LANG_C;
1337
1338 IDPACKAGE(pl)->handle=(void *)NULL;
1339 SModulFunctions sModulFunctions;
1340
1341 package s=currPack;
1342 currPack=IDPACKAGE(pl);
1343 if( init!= NULL)
1344 {
1345 sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1346 if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1347 else sModulFunctions.iiAddCproc = iiAddCproc;
1348 (*init)(&sModulFunctions);
1349 }
1350 if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1351 currPack->loaded=1;
1352 currPack=s;
1353
1354 return FALSE;
1355}
1356/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1357void module_help_main(const char *newlib,const char *help)
1358{
1359 char *plib = iiConvName(newlib);
1360 idhdl pl = basePack->idroot->get(plib,0);
1361 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1362 Werror(">>%s<< is not a package (trying to add package help)",plib);
1363 else
1364 {
1365 package s=currPack;
1366 currPack=IDPACKAGE(pl);
1367 idhdl h=enterid("info",0,STRING_CMD,&IDROOT,FALSE);
1369 currPack=s;
1370 }
1371}
1372void module_help_proc(const char *newlib,const char *p, const char *help)
1373{
1374 char *plib = iiConvName(newlib);
1375 idhdl pl = basePack->idroot->get(plib,0);
1376 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1377 Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1378 else
1379 {
1380 package s=currPack;
1381 currPack=IDPACKAGE(pl);
1382 char buff[SINGULAR_PATH_LENGTH];
1383 buff[SINGULAR_PATH_LENGTH-1]='\0';
1384 strncpy(buff,p,SINGULAR_PATH_LENGTH-1);
1385 strncat(buff,"_help",SINGULAR_PATH_LENGTH-1-strlen(p));
1388 currPack=s;
1389 }
1390}
1391/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1392
1393#ifdef HAVE_DYNAMIC_LOADING
1394// loads a dynamic module from the binary path and returns a named function
1395// returns NULL, if something fails
1396void* binary_module_function(const char* newlib, const char* funcname)
1397{
1398 void* result = NULL;
1399
1400 const char* bin_dir = feGetResource('b');
1401 if (!bin_dir) { return NULL; }
1402
1403 char path_name[MAXPATHLEN];
1404 snprintf(path_name,MAXPATHLEN, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING);
1405
1406 void* openlib = dynl_open(path_name);
1407 if(!openlib)
1408 {
1409 Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1410 return NULL;
1411 }
1412 result = dynl_sym(openlib, funcname);
1413 if (!result) Werror("%s: %s\n", funcname, dynl_error());
1414
1415 return result;
1416}
1417#endif
1418
1419/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1420static char mytoupper(char c)
1421{
1422 if(c>=97 && c<=(97+26)) c-=32;
1423 return(c);
1424}
1425
1426static char mytolower(char c)
1427{
1428 if(c>=65 && c<=(65+26)) c+=32;
1429 return(c);
1430}
1431
1432/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1433//#if defined(WINNT)
1434//# define FS_SEP '\\'
1435//#else
1436//# define FS_SEP '/'
1437//#endif
1438
1439char *iiConvName(const char *libname)
1440{
1441 char *tmpname = omStrDup(libname);
1442 char *p = strrchr(tmpname, DIR_SEP);
1443 char *r;
1444 if(p==NULL) p = tmpname; else p++;
1445 // p is now the start of the file name (without path)
1446 r=p;
1447 while(isalnum(*r)||(*r=='_')) r++;
1448 // r point the the end of the main part of the filename
1449 *r = '\0';
1450 r = omStrDup(p);
1451 *r = mytoupper(*r);
1452 // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1453 omFree((ADDRESS)tmpname);
1454
1455 return(r);
1456}
1457
1458/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1459#if 0 /* debug only */
1460void piShowProcList()
1461{
1462 idhdl h;
1463 procinfo *proc;
1464 char *name;
1465
1466 Print( "%-15s %20s %s,%s %s,%s %s,%s\n", "Library", "function",
1467 "line", "start", "line", "body", "line", "example");
1468 for(h = IDROOT; h != NULL; h = IDNEXT(h))
1469 {
1470 if(IDTYP(h) == PROC_CMD)
1471 {
1472 proc = IDPROC(h);
1473 if(strcmp(proc->procname, IDID(h))!=0)
1474 {
1475 name = (char *)omAlloc(strlen(IDID(h))+strlen(proc->procname)+4);
1476 snprintf(name, strlen(IDID(h))+strlen(proc->procname)+4,
1477 "%s -> %s", IDID(h), proc->procname);
1478 Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname, name);
1480 }
1481 else
1482 Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname,
1483 proc->procname);
1484 if(proc->language==LANG_SINGULAR)
1485 Print("line %-5ld %4d,%-5ld %4d,%-5ld\n",
1486 proc->data.s.proc_start,
1487 proc->data.s.body_lineno, proc->data.s.body_start,
1488 proc->data.s.example_lineno, proc->data.s.example_start);
1489 else if(proc->language==LANG_C)
1490 PrintS("type: object\n");
1491 }
1492 }
1493}
1494#endif
1495
1496/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1497//char *iiLineNo(char *procname, int lineno)
1498//{
1499// char buf[256];
1500// idhdl pn = ggetid(procname);
1501// procinfo *pi = IDPROC(pn);
1502//
1503// snprintf(buf,256, "%s %3d\0", procname, lineno);
1504// //snprintf(buf,256, "%s::%s %3d\0", pi->libname, pi->procname,
1505// // lineno + pi->data.s.body_lineno);
1506// return(buf);
1507//}
1508/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1509#ifdef HAVE_LIBPARSER
1510void libstack::push(const char */*p*/, char *libn)
1511{
1512 libstackv lp;
1513 if( !iiGetLibStatus(libn))
1514 {
1515 for(lp = this;lp!=NULL;lp=lp->next)
1516 {
1517 if(strcmp(lp->get(), libn)==0) break;
1518 }
1519 if(lp==NULL)
1520 {
1522 ls->next = this;
1523 ls->libname = omStrDup(libn);
1524 ls->to_be_done = TRUE;
1525 if(library_stack != NULL) ls->cnt = library_stack->cnt+1; else ls->cnt = 0;
1526 library_stack = ls;
1527 }
1528 }
1529}
1530
1531libstackv libstack::pop(const char */*p*/)
1532{
1533 libstackv ls = this;
1534 omFree((ADDRESS)ls->libname);
1535 library_stack = ls->next;
1537 return(library_stack);
1538}
1539
1540#endif /* HAVE_LIBPARSER */
1541/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
#define BITSET
Definition auxiliary.h:85
static int si_max(const int a, const int b)
Definition auxiliary.h:125
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
void * ADDRESS
Definition auxiliary.h:120
CanonicalForm head(const CanonicalForm &f)
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
int p
Definition cfModGcd.cc:4086
CanonicalForm fp
Definition cfModGcd.cc:4110
unsigned char * proc[NUM_PROC]
Definition checklibs.c:16
idhdl next
Definition idrec.h:38
const char * id
Definition idrec.h:39
void push(const char *p, char *libname)
Definition iplib.cc:1510
char * get()
Definition subexpr.h:170
libstackv next
Definition subexpr.h:164
libstackv pop(const char *p)
Definition iplib.cc:1531
int cnt
Definition subexpr.h:167
char * libname
Definition subexpr.h:165
BOOLEAN to_be_done
Definition subexpr.h:166
Class used for (list of) interpreter objects.
Definition subexpr.h:83
int rtyp
Definition subexpr.h:91
void Init()
Definition subexpr.h:107
leftv next
Definition subexpr.h:86
void * data
Definition subexpr.h:88
#define Print
Definition emacs.cc:80
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
return result
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition feFopen.cc:47
VAR short errorreported
Definition feFopen.cc:23
void WerrorS(const char *s)
Definition feFopen.cc:24
size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition feFopen.cc:195
char * feGetResource(const char id, int warn)
#define DIR_SEPP
Definition feResource.h:7
#define DIR_SEP
Definition feResource.h:6
VAR int yylineno
Definition febase.cc:40
VAR int si_echo
Definition febase.cc:35
VAR int myynest
Definition febase.cc:41
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition fevoices.cc:166
feBufferTypes
Definition fevoices.h:17
@ BT_example
Definition fevoices.h:21
@ BT_proc
Definition fevoices.h:20
#define THREAD_VAR
Definition globaldefs.h:12
#define GLOBAL_VAR
Definition globaldefs.h:11
#define EXTERN_VAR
Definition globaldefs.h:6
#define INST_VAR
Definition globaldefs.h:8
#define VAR
Definition globaldefs.h:5
@ IDEAL_CMD
Definition grammar.cc:285
@ PROC_CMD
Definition grammar.cc:281
@ RING_CMD
Definition grammar.cc:282
int yyparse(void)
Definition grammar.cc:2149
ideal idCopy(ideal A)
Definition ideals.h:60
int IsCmd(const char *n, int &tok)
Definition iparith.cc:9738
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos=-1)
Definition iparith.cc:10083
idhdl ggetid(const char *n)
Definition ipid.cc:558
void killhdl2(idhdl h, idhdl *ih, ring r)
Definition ipid.cc:422
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition ipid.cc:256
VAR package basePack
Definition ipid.cc:56
VAR omBin idrec_bin
Definition ipid.cc:48
VAR proclevel * procstack
Definition ipid.cc:50
VAR idhdl currRingHdl
Definition ipid.cc:57
VAR package currPack
Definition ipid.cc:55
void killhdl(idhdl h, package proot)
Definition ipid.cc:391
VAR idhdl currPackHdl
Definition ipid.cc:53
idhdl packFindHdl(package r)
Definition ipid.cc:808
#define IDSTRING(a)
Definition ipid.h:136
#define IDNEXT(a)
Definition ipid.h:118
EXTERN_VAR omBin sleftv_bin
Definition ipid.h:145
#define IDDATA(a)
Definition ipid.h:126
const struct soptionStruct verboseStruct[]
Definition misc_ip.cc:539
#define IDPROC(a)
Definition ipid.h:140
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition ipid.h:72
#define IDID(a)
Definition ipid.h:122
#define IDROOT
Definition ipid.h:19
#define IDPACKAGE(a)
Definition ipid.h:139
#define IDLEV(a)
Definition ipid.h:121
int(* SModulFunc_t)(SModulFunctions *)
Definition ipid.h:81
#define IDRING(a)
Definition ipid.h:127
const struct soptionStruct optionStruct[]
Definition misc_ip.cc:508
#define IDTYP(a)
Definition ipid.h:119
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition ipid.h:70
char * iiProcName(char *buf, char &ct, char *&e)
Definition iplib.cc:100
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition iplib.cc:1073
#define SI_MAX_NEST
Definition iplib.cc:27
void yylprestart(FILE *input_file)
bool registered_dyn_module(char *fullname)
Definition iplib.cc:1167
ideal ii_CallProcId2Id(const char *lib, const char *proc, ideal arg, const ring R)
Definition iplib.cc:670
void register_dyn_module(char *fullname, void *handle)
Definition iplib.cc:1174
char * iiProcArgs(char *e, BOOLEAN withParenth)
Definition iplib.cc:114
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
Definition iplib.cc:983
VAR int iiRETURNEXPR_len
Definition iplib.cc:484
static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
Definition iplib.cc:615
BOOLEAN iiEStart(char *example, procinfo *pi)
Definition iplib.cc:763
#define SI_GET_BUILTIN_MOD_INIT0(name)
Definition iplib.cc:808
int flint_mod_init(SModulFunctions *psModulFunctions)
Definition misc_ip.cc:1272
BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1191
static void iiCheckNest()
Definition iplib.cc:502
int current_pos(int i=0)
Definition libparse.cc:3346
#define SI_GET_BUILTIN_MOD_INIT(name)
char * iiConvName(const char *libname)
Definition iplib.cc:1439
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition iplib.cc:894
BOOLEAN iiGetLibStatus(const char *lib)
Definition iplib.cc:77
leftv ii_CallLibProcM(const char *n, void **args, int *arg_types, const ring R, BOOLEAN &err)
args: NULL terminated array of arguments arg_types: 0 terminated array of corresponding types
Definition iplib.cc:710
void print_init()
Definition libparse.cc:3482
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv args)
Definition iplib.cc:513
BOOLEAN iiTryLoadLib(leftv v, const char *id)
Definition iplib.cc:832
#define MODULE_SUFFIX_STRING
Definition iplib.cc:42
static void iiCleanProcs(idhdl &root)
Definition iplib.cc:938
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1294
int ii_CallProcId2Int(const char *lib, const char *proc, ideal arg, const ring R)
Definition iplib.cc:689
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition iplib.cc:1165
static char mytolower(char c)
Definition iplib.cc:1426
VAR libstackv library_stack
Definition iplib.cc:68
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition iplib.cc:1148
static char mytoupper(char c)
Definition iplib.cc:1420
INST_VAR sleftv iiRETURNEXPR
Definition iplib.cc:483
void close_all_dyn_modules()
Definition iplib.cc:1181
#define SINGULAR_PATH_LENGTH
Definition iplib.cc:21
const char * yylp_errlist[]
Definition libparse.cc:1114
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
Definition iplib.cc:1304
EXTERN_VAR int yylplineno
Definition iplib.cc:65
BOOLEAN iiLocateLib(const char *lib, char *where)
Definition iplib.cc:880
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition iplib.cc:816
VAR ring * iiLocalRing
Definition iplib.cc:482
void module_help_main(const char *newlib, const char *help)
Definition iplib.cc:1357
static void iiShowLevRings()
Definition iplib.cc:487
BOOLEAN iiAllStart(procinfov pi, const char *p, feBufferTypes t, int l)
Definition iplib.cc:306
void * iiCallLibProc1(const char *n, void *arg, int arg_type, BOOLEAN &err)
Definition iplib.cc:636
static void iiCallLibProcBegin()
Definition iplib.cc:598
void module_help_proc(const char *newlib, const char *p, const char *help)
Definition iplib.cc:1372
static void iiRunInit(package p)
Definition iplib.cc:967
EXTERN_VAR int yylp_errno
Definition iplib.cc:64
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition iplib.cc:197
BOOLEAN iiPStart(idhdl pn, leftv v)
Definition iplib.cc:379
void * binary_module_function(const char *newlib, const char *funcname)
Definition iplib.cc:1396
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition iparith.cc:10083
procinfo * iiInitSingularProcinfo(procinfov pi, const char *libname, const char *procname, int, long pos, BOOLEAN pstatic)
Definition iplib.cc:1059
VAR idhdl iiCurrProc
Definition ipshell.cc:82
void iiCheckPack(package &p)
Definition ipshell.cc:1625
void killlocals(int v)
Definition ipshell.cc:387
VAR leftv iiCurrArgs
Definition ipshell.cc:81
idhdl rFindHdl(ring r, idhdl n)
Definition ipshell.cc:1695
void rSetHdl(idhdl h)
Definition ipshell.cc:5122
STATIC_VAR int offset
Definition janet.cc:29
STATIC_VAR Poly * h
Definition janet.cc:971
#define pi
Definition libparse.cc:1145
#define help
Definition libparse.cc:1230
void reinit_yylp()
Definition libparse.cc:3376
VAR char * text_buffer
Definition libparse.cc:1099
VAR int lpverbose
Definition libparse.cc:1106
VAR char libnamebuf[1024]
Definition libparse.cc:1098
lib_style_types
Definition libparse.h:9
@ OLD_LIBSTYLE
Definition libparse.h:9
#define YYLP_BAD_CHAR
Definition libparse.h:93
int yylplex(const char *libname, const char *libfile, lib_style_types *lib_style, idhdl pl, BOOLEAN autoexport=FALSE, lp_modes=LOAD_LIB)
#define SEEK_SET
Definition mod2.h:115
#define assume(x)
Definition mod2.h:389
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
Definition mod_lib.cc:27
#define SI_MOD_INIT0(name)
Definition mod_lib.h:4
#define SI_FOREACH_BUILTIN(add)
Data for type_of_LIB to determine built-in modules, use add(name) to add built-in library to macro.
Definition mod_lib.h:17
int dynl_check_opened(char *filename)
Definition mod_raw.cc:135
const char * dynl_error()
Definition mod_raw.cc:175
int dynl_close(void *handle)
Definition mod_raw.cc:170
void * dynl_sym(void *handle, const char *symbol)
Definition mod_raw.cc:159
void * dynl_open(char *filename)
Definition mod_raw.cc:142
lib_types
Definition mod_raw.h:16
@ LT_HPUX
Definition mod_raw.h:16
@ LT_SINGULAR
Definition mod_raw.h:16
@ LT_BUILTIN
Definition mod_raw.h:16
@ LT_ELF
Definition mod_raw.h:16
@ LT_NOTFOUND
Definition mod_raw.h:16
#define omStrDup(s)
#define omfree(addr)
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omreallocSize(addr, o_size, size)
#define omAllocBin(bin)
#define omAlloc0Bin(bin)
#define omFree(addr)
#define omAlloc0(size)
#define omFreeBin(addr, bin)
#define omFreeBinAddr(addr)
#define NULL
Definition omList.c:12
#define MAXPATHLEN
Definition omRet2Info.c:22
VAR unsigned si_opt_2
Definition options.c:6
VAR unsigned si_opt_1
Definition options.c:5
#define BVERBOSE(a)
Definition options.h:35
#define TEST_V_ALLWARN
Definition options.h:145
#define V_DEBUG_LIB
Definition options.h:48
#define V_REDEFINE
Definition options.h:45
#define V_LOAD_LIB
Definition options.h:47
void rChangeCurrRing(ring r)
Definition polys.cc:16
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
void PrintS(const char *s)
Definition reporter.cc:284
void PrintLn()
Definition reporter.cc:310
void Werror(const char *fmt,...)
Definition reporter.cc:189
#define TRACE_SHOW_LINENO
Definition reporter.h:31
#define TRACE_SHOW_LINE
Definition reporter.h:33
EXTERN_VAR int traceit
Definition reporter.h:24
EXTERN_VAR int traceit_stop
Definition reporter.h:25
#define TRACE_SHOW_PROC
Definition reporter.h:29
#define TRACE_SHOW_RINGS
Definition reporter.h:36
static ring rIncRefCnt(ring r)
Definition ring.h:849
static void rDecRefCnt(ring r)
Definition ring.h:850
idrec * idhdl
Definition ring.h:22
int status int void * buf
Definition si_signals.h:69
#define R
Definition sirandom.c:27
ip_package * package
Definition structs.h:39
sleftv * leftv
Definition structs.h:53
#define loop
Definition structs.h:71
procinfo * procinfov
Definition structs.h:56
INST_VAR sleftv sLastPrinted
Definition subexpr.cc:46
EXTERN_VAR omBin libstack_bin
Definition subexpr.h:176
@ LANG_SINGULAR
Definition subexpr.h:22
@ LANG_NONE
Definition subexpr.h:22
@ LANG_MIX
Definition subexpr.h:22
@ LANG_C
Definition subexpr.h:22
libstack * libstackv
Definition subexpr.h:159
int name
New type name for int.
@ PACKAGE_CMD
Definition tok.h:150
@ STRING_CMD
Definition tok.h:187
@ MAX_TOK
Definition tok.h:220