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
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
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*/
78{
79 idhdl hl;
80
81 char *plib = iiConvName(lib);
82 hl = basePack->idroot->get(plib,0);
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*/
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 }
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 {
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);
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;
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 );
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{
309 int restore_traceit=0;
310 if (traceit_stop
312 {
313 traceit &=(~TRACE_SHOW_LINE);
314 traceit_stop=0;
316 }
317 // see below:
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 {
327 }
328
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 {
417 }
418 /* start interpreter ======================================*/
419 myynest++;
420 if (myynest > SI_MAX_NEST)
421 {
422 WerrorS("nesting too deep");
423 err=TRUE;
424 }
425 else
426 {
428 err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
430
431 if (iiLocalRing[myynest-1] != currRing)
432 {
434 {
435 //idhdl hn;
436 const char *n;
437 const char *o;
439 if (iiLocalRing[myynest-1]!=NULL)
441 if (oh!=NULL) o=oh->id;
442 else o="none";
443 if (currRing!=NULL)
445 if (nh!=NULL) n=nh->id;
446 else n="none";
447 Werror("ring change during procedure call %s: %s -> %s (level %d)",pi->procname,o,n,myynest);
449 err=TRUE;
450 }
452 }
453 if ((currRing==NULL)
454 && (currRingHdl!=NULL))
456 else
457 if ((currRing!=NULL) &&
459 ||(IDLEV(currRingHdl)>=myynest-1)))
460 {
463 }
464 //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
466#ifndef SING_NDEBUG
467 checkall();
468#endif
469 //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
470 }
471 myynest--;
473 if (pi!=NULL)
474 pi->trace_flag=save_flags;
475// omUpdateInfo();
476// int m=om_Info.UsedBytes;
477// Print("exit %s, mem=%d\n",IDID(pn),m);
478 return err;
479}
480
484
485#ifdef RDEBUG
486static void iiShowLevRings()
487{
488 int i;
489 for (i=0;i<=myynest;i++)
490 {
491 Print("lev %d:",i);
492 if (iiLocalRing[i]==NULL) PrintS("NULL");
493 else Print("%lx",(long)iiLocalRing[i]);
494 PrintLn();
495 }
496 if (currRing==NULL) PrintS("curr:NULL\n");
497 else Print ("curr:%lx\n",(long)currRing);
498}
499#endif /* RDEBUG */
500
501static void iiCheckNest()
502{
503 if (myynest >= iiRETURNEXPR_len-1)
504 {
506 iiRETURNEXPR_len*sizeof(ring),
507 (iiRETURNEXPR_len+16)*sizeof(ring));
508 memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
510 }
511}
513{
514 int err;
516 if(pi->is_static && myynest==0)
517 {
518 Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
519 pi->libname, pi->procname);
520 return TRUE;
521 }
522 iiCheckNest();
524 //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
526 procstack->push(pi->procname);
528 || (pi->trace_flag&TRACE_SHOW_PROC))
529 {
531 Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
532 }
533#ifdef RDEBUG
535#endif
536 switch (pi->language)
537 {
538 default:
539 case LANG_NONE:
540 WerrorS("undefined proc");
541 err=TRUE;
542 break;
543
544 case LANG_SINGULAR:
545 if ((pi->pack!=NULL)&&(currPack!=pi->pack))
546 {
547 currPack=pi->pack;
550 //Print("set pack=%s\n",IDID(currPackHdl));
551 }
552 else if ((pack!=NULL)&&(currPack!=pack))
553 {
554 currPack=pack;
557 //Print("set pack=%s\n",IDID(currPackHdl));
558 }
559 err=iiPStart(pn,args);
560 break;
561 case LANG_C:
563 err = (pi->data.o.function)(res, args);
566 break;
567 }
569 || (pi->trace_flag&TRACE_SHOW_PROC))
570 {
572 Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
573 }
574 //const char *n="NULL";
575 //if (currRingHdl!=NULL) n=IDID(currRingHdl);
576 //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
577#ifdef RDEBUG
579#endif
580 if (err)
581 {
583 //iiRETURNEXPR.Init(); //done by CleanUp
584 }
585 if (iiCurrArgs!=NULL)
586 {
587 if (!err) Warn("too many arguments for %s",IDID(pn));
591 }
592 procstack->pop();
593 if (err)
594 return TRUE;
595 return FALSE;
596}
598{
600 if (currRing!=NULL)
601 {
603 {
604 // clean up things depending on currRingHdl:
607 }
608 // need to define a ring-hdl for currRingHdl
612 }
613}
615{
616 if ((currRing!=NULL)
617 &&(currRing!=save_ring))
618 {
620 idhdl prev=NULL;
621 while((hh!=currRingHdl) && (hh!=NULL)) { prev=hh; hh=hh->next; }
622 if ((hh!=NULL)&&(strcmp(IDID(hh)," tmpRing")==0))
623 {
625 if (prev==NULL) IDROOT=hh->next;
626 else prev->next=hh->next;
629 }
630 }
633}
634
635void* iiCallLibProc1(const char*n, void *arg, int arg_type, BOOLEAN &err)
636{
637 idhdl h=ggetid(n);
638 if ((h==NULL)
639 || (IDTYP(h)!=PROC_CMD))
640 {
641 err=2;
642 return NULL;
643 }
644 // ring handling
648 // argument:
649 sleftv tmp;
650 tmp.Init();
651 tmp.data=arg;
652 tmp.rtyp=arg_type;
653 // call proc
655 // clean up ring
657 // return
658 if (err==FALSE)
659 {
660 void*r=iiRETURNEXPR.data;
663 return r;
664 }
665 return NULL;
666}
667
668// return NULL on failure
669ideal ii_CallProcId2Id(const char *lib,const char *proc, ideal arg, const ring R)
670{
671 char *plib = iiConvName(lib);
674 if (h==NULL)
675 {
677 if (bo) return NULL;
678 }
681 BOOLEAN err;
684 if (err) return NULL;
685 return I;
686}
687
688int ii_CallProcId2Int(const char *lib,const char *proc, ideal arg, const ring R)
689{
690 char *plib = iiConvName(lib);
693 if (h==NULL)
694 {
696 if (bo) return 0;
697 }
698 BOOLEAN err;
701 int I=(int)(long)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
703 if (err) return 0;
704 return I;
705}
706
707/// args: NULL terminated array of arguments
708/// arg_types: 0 terminated array of corresponding types
709leftv ii_CallLibProcM(const char*n, void **args, int* arg_types, const ring R, BOOLEAN &err)
710{
711 idhdl h=ggetid(n);
712 if ((h==NULL)
713 || (IDTYP(h)!=PROC_CMD))
714 {
715 err=2;
716 return NULL;
717 }
718 // ring handling
723 // argument:
724 if (arg_types[0]!=0)
725 {
726 sleftv tmp;
727 leftv tt=&tmp;
728 int i=1;
729 tmp.Init();
730 tmp.data=args[0];
731 tmp.rtyp=arg_types[0];
732 while(arg_types[i]!=0)
733 {
735 tt=tt->next;
736 tt->rtyp=arg_types[i];
737 tt->data=args[i];
738 i++;
739 }
740 // call proc
742 }
743 else
744 // call proc
746 // clean up ring
748 // return
749 if (err==FALSE)
750 {
752 memcpy(h,&iiRETURNEXPR,sizeof(sleftv));
754 return h;
755 }
756 return NULL;
757}
758/*2
759* start an example (as a proc),
760* destroys the string 'example'
761*/
762BOOLEAN iiEStart(char* example, procinfo *pi)
763{
764 BOOLEAN err;
765 int old_echo=si_echo;
766
767 iiCheckNest();
768 procstack->push(example);
771 {
773 printf("entering example (level %d)\n",myynest);
774 }
775 myynest++;
776
777 err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
778
780 myynest--;
783 {
785 printf("leaving -example- (level %d)\n",myynest);
786 }
788 {
790 {
793 }
794 else
795 {
798 }
799 }
800 procstack->pop();
801 return err;
802}
803
804
805extern "C"
806{
807# define SI_GET_BUILTIN_MOD_INIT0(name) int SI_MOD_INIT0(name)(SModulFunctions*);
809# undef SI_GET_BUILTIN_MOD_INIT0
810};
811
813
815iiGetBuiltinModInit(const char* libname)
816{
817#ifdef HAVE_FLINT
818 if (strcmp(libname,"flint.so")==0) return SI_MOD_INIT0(flint);
819#endif
820# define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
822# undef SI_GET_BUILTIN_MOD_INIT
823
824 return NULL;
825}
826
827
828
829
830/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
831BOOLEAN iiTryLoadLib(leftv v, const char *id)
832{
834 char libnamebuf[1024];
835 size_t len=strlen(id)+5;
836 char *libname = (char *)omAlloc(len);
837 const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
838 int i = 0;
839 // FILE *fp;
840 // package pack;
841 // idhdl packhdl;
843 for(i=0; suffix[i] != NULL; i++)
844 {
845 snprintf(libname,len, "%s%s", id, suffix[i]);
846 *libname = mytolower(*libname);
847 if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
848 {
849 #ifdef HAVE_DYNAMIC_LOADING
850 char libnamebuf[1024];
851 #endif
852
853 if (LT==LT_SINGULAR)
854 LoadResult = iiLibCmd(libname, FALSE, FALSE,TRUE);
855 #ifdef HAVE_DYNAMIC_LOADING
856 else if ((LT==LT_ELF) || (LT==LT_HPUX))
858 #endif
859 else if (LT==LT_BUILTIN)
860 {
862 }
863 if(!LoadResult )
864 {
865 v->name = iiConvName(libname);
866 break;
867 }
868 }
869 }
870 omFree(libname);
871 return LoadResult;
872}
873
874/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
875/* check, if library lib has already been loaded
876 if yes, writes filename of lib into where and returns TRUE,
877 no, returns FALSE
878*/
879BOOLEAN iiLocateLib(const char* lib, char* where)
880{
881 char *plib = iiConvName(lib);
882 idhdl pl = basePack->idroot->get(plib,0);
883 if( (pl!=NULL) && (IDTYP(pl)==PACKAGE_CMD) &&
884 (IDPACKAGE(pl)->language == LANG_SINGULAR))
885 {
886 strncpy(where,IDPACKAGE(pl)->libname,127);
887 return TRUE;
888 }
889 else
890 return FALSE;;
891}
892
894{
895 if (strcmp(newlib,"Singular")==0) return FALSE;
896 char libnamebuf[1024];
897 idhdl pl;
898 char *plib = iiConvName(newlib);
900 // int lines = 1;
902
903 if (fp==NULL)
904 {
905 return TRUE;
906 }
907 pl = basePack->idroot->get(plib,0);
908 if (pl==NULL)
909 {
910 pl = enterid( plib,0, PACKAGE_CMD,
911 &(basePack->idroot), TRUE );
912 IDPACKAGE(pl)->language = LANG_SINGULAR;
913 IDPACKAGE(pl)->libname=omStrDup(newlib);
914 }
915 else
916 {
917 if(IDTYP(pl)!=PACKAGE_CMD)
918 {
920 WarnS("not of type package.");
921 fclose(fp);
922 return TRUE;
923 }
924 if (!force)
925 {
927 return FALSE;
928 }
929 }
931
932 if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
934 return LoadResult;
935}
936/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
937static void iiCleanProcs(idhdl &root)
938{
939 idhdl prev=NULL;
940 loop
941 {
942 if (root==NULL) return;
943 if (IDTYP(root)==PROC_CMD)
944 {
945 procinfo *pi=(procinfo*)IDDATA(root);
946 if ((pi->language == LANG_SINGULAR)
947 && (pi->data.s.body_start == 0L))
948 {
949 // procinfo data incorrect:
950 // - no proc body can start at the beginning of the file
951 killhdl(root);
952 if (prev==NULL)
953 root=IDROOT;
954 else
955 {
956 root=prev;
957 prev=NULL;
958 }
959 continue;
960 }
961 }
962 prev=root;
963 root=IDNEXT(root);
964 }
965}
966static void iiRunInit(package p)
967{
968 idhdl h=p->idroot->get("mod_init",0);
969 if (h==NULL) return;
970 if (IDTYP(h)==PROC_CMD)
971 {
972 int save=yylineno;
973 myynest++;
974 // procinfo *pi=(procinfo*)IDDATA(h);
975 //PrintS("mod_init found\n");
977 myynest--;
979 }
980}
981/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
982BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char*newlib,
984{
988
989 yylpin = fp;
990 #if YYLPDEBUG > 1
991 print_init();
992 #endif
995 else lpverbose=0;
996 // yylplex sets also text_buffer
997 if (text_buffer!=NULL) *text_buffer='\0';
999 if(yylp_errno)
1000 {
1001 Werror("Library %s: ERROR occurred: in line %d, %d.", newlib, yylplineno,
1002 current_pos(0));
1004 {
1008 }
1009 else
1011 WerrorS("Cannot load library,... aborting.");
1012 reinit_yylp();
1013 fclose( yylpin );
1015 return TRUE;
1016 }
1017 if (BVERBOSE(V_LOAD_LIB))
1018 Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
1020 {
1021 Warn( "library %s has old format. This format is still accepted,", newlib);
1022 WarnS( "but for functionality you may wish to change to the new");
1023 WarnS( "format. Please refer to the manual for further information.");
1024 }
1025 reinit_yylp();
1026 fclose( yylpin );
1027 fp = NULL;
1028 iiRunInit(IDPACKAGE(pl));
1029
1030 {
1031 libstackv ls;
1032 for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
1033 {
1034 if(ls->to_be_done)
1035 {
1036 ls->to_be_done=FALSE;
1038 ls = ls->pop(newlib);
1039 }
1040 }
1041#if 0
1042 PrintS("--------------------\n");
1043 for(ls = library_stack; ls != NULL; ls = ls->next)
1044 {
1045 Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
1046 ls->to_be_done ? "not loaded" : "loaded");
1047 }
1048 PrintS("--------------------\n");
1049#endif
1050 }
1051
1052 if(fp != NULL) fclose(fp);
1053 return FALSE;
1054}
1055
1056
1057/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1059 const char *procname, int, long pos, BOOLEAN pstatic)
1060{
1061 memset(pi,0,sizeof(*pi));
1062 pi->libname = omStrDup(libname);
1063 pi->procname = omStrDup(procname);
1064 pi->language = LANG_SINGULAR;
1065 pi->ref = 1;
1066 pi->is_static = pstatic;
1067 pi->data.s.proc_start = pos;
1068 return(pi);
1069}
1070
1071/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1072int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1073 BOOLEAN(*func)(leftv res, leftv v))
1074{
1075 procinfov pi;
1076 idhdl h;
1077
1078 #ifndef SING_NDEBUG
1079 int dummy;
1080 if (IsCmd(procname,dummy))
1081 {
1082 Werror(">>%s< is a reserved name",procname);
1083 return 0;
1084 }
1085 #endif
1086
1087 h=IDROOT->get(procname,0);
1088 if ((h!=NULL)
1089 && (IDTYP(h)==PROC_CMD))
1090 {
1091 pi = IDPROC(h);
1092 #if 0
1093 if ((pi->language == LANG_SINGULAR)
1094 &&(BVERBOSE(V_REDEFINE)))
1095 Warn("extend `%s`",procname);
1096 #endif
1097 }
1098 else
1099 {
1100 h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
1101 }
1102 if ( h!= NULL )
1103 {
1104 pi = IDPROC(h);
1105 if((pi->language == LANG_SINGULAR)
1106 ||(pi->language == LANG_NONE))
1107 {
1108 omfree(pi->libname);
1109 pi->libname = omStrDup(libname);
1110 omfree(pi->procname);
1111 pi->procname = omStrDup(procname);
1112 pi->language = LANG_C;
1113 pi->ref = 1;
1114 pi->is_static = pstatic;
1115 pi->data.o.function = func;
1116 }
1117 else if(pi->language == LANG_C)
1118 {
1119 if(pi->data.o.function == func)
1120 {
1121 pi->ref++;
1122 }
1123 else
1124 {
1125 omfree(pi->libname);
1126 pi->libname = omStrDup(libname);
1127 omfree(pi->procname);
1128 pi->procname = omStrDup(procname);
1129 pi->language = LANG_C;
1130 pi->ref = 1;
1131 pi->is_static = pstatic;
1132 pi->data.o.function = func;
1133 }
1134 }
1135 else
1136 Warn("internal error: unknown procedure type %d",pi->language);
1137 if (currPack->language==LANG_SINGULAR) currPack->language=LANG_MIX;
1138 return(1);
1139 }
1140 else
1141 {
1142 WarnS("iiAddCproc: failed.");
1143 }
1144 return(0);
1145}
1146
1147int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic,
1148 BOOLEAN(*func)(leftv res, leftv v))
1149{
1150 int r=iiAddCproc(libname,procname,pstatic,func);
1151 package s=currPack;
1153 if (r) r=iiAddCproc(libname,procname,pstatic,func);
1154 currPack=s;
1155 return r;
1156}
1157
1158/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1159#ifdef HAVE_DYNAMIC_LOADING
1160#include <map>
1161#include <string>
1162#include <pthread.h>
1163
1164THREAD_VAR std::map<std::string, void *> *dyn_modules;
1165
1167 if (dyn_modules == NULL)
1168 return false;
1169 std::string fname = fullname;
1170 return dyn_modules->count(fname) != 0;
1171}
1172
1173void register_dyn_module(char *fullname, void * handle) {
1174 std::string fname = fullname;
1175 if (dyn_modules == NULL)
1176 dyn_modules = new std::map<std::string, void *>();
1177 dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1178}
1179
1181 for (std::map<std::string, void *>::iterator it = dyn_modules->begin();
1182 it != dyn_modules->end();
1183 it++)
1184 {
1185 dynl_close(it->second);
1186 }
1187 delete dyn_modules;
1188 dyn_modules = NULL;
1189}
1191{
1192/*
1193 typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1194 BOOLEAN pstatic,
1195 BOOLEAN(*func)(leftv res, leftv v)));
1196*/
1198 idhdl pl;
1199 char *plib = iiConvName(newlib);
1201 int token;
1202 int l=si_max((int)strlen(fullname),(int)strlen(newlib))+3;
1203 char *FullName=(char*)omAlloc0(l);
1204
1205 if( *fullname != '/' && *fullname != '.' )
1206 snprintf(FullName,l, "./%s", newlib);
1207 else strncpy(FullName, fullname,l);
1208
1209
1210 if(IsCmd(plib, token))
1211 {
1212 Werror("'%s' is resered identifier\n", plib);
1213 goto load_modules_end;
1214 }
1215 pl = basePack->idroot->get(plib,0); /* packages only in top level
1216 (see enterid) */
1217 if ((pl!=NULL)
1218 &&(IDTYP(pl)==PACKAGE_CMD))
1219 {
1220 if(IDPACKAGE(pl)->language==LANG_C)
1221 {
1222 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as package", newlib);
1224 return FALSE;
1225 }
1226 else if(IDPACKAGE(pl)->language==LANG_MIX)
1227 {
1228 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s contain binary parts, cannot load", newlib);
1230 return FALSE;
1231 }
1232 }
1233 else
1234 {
1235 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1236 omFreeBinAddr(plib); /* enterid copied plib*/
1237 IDPACKAGE(pl)->libname=omStrDup(newlib);
1238 }
1239 IDPACKAGE(pl)->language = LANG_C;
1241 {
1242 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
1244 return FALSE;
1245 }
1246 if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1247 {
1248 Werror("dynl_open failed:%s", dynl_error());
1249 Werror("%s not found", newlib);
1250 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1251 goto load_modules_end;
1252 }
1253 else
1254 {
1256
1257 package s=currPack;
1258 currPack=IDPACKAGE(pl);
1259 fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1260 if( fktn!= NULL)
1261 {
1262 sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1263 if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1264 else sModulFunctions.iiAddCproc = iiAddCproc;
1265 int ver=(*fktn)(&sModulFunctions);
1266 if (ver==MAX_TOK)
1267 {
1268 if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1269 }
1270 else
1271 {
1272 Warn("loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,MAX_TOK,ver);
1273 }
1274 currPack->loaded=1;
1275 currPack=s; /* reset currPack to previous */
1277 RET=FALSE;
1278 }
1279 else
1280 {
1281 Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1282 errorreported=0;
1283 if(IDPACKAGE(pl)->idroot==NULL)
1284 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1285 }
1286 }
1287
1290 return RET;
1291}
1292
1301#endif /* HAVE_DYNAMIC_LOADING */
1302/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1304{
1305 int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1306 BOOLEAN(*func)(leftv res, leftv v));
1307/*
1308 typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1309 BOOLEAN pstatic,
1310 BOOLEAN(*func)(leftv res, leftv v)));
1311*/
1312 // SModulFunc_t fktn;
1313 idhdl pl;
1314 char *plib = iiConvName(newlib);
1315 // BOOLEAN RET=TRUE;
1316 // int token;
1317
1318 pl = basePack->idroot->get(plib,0); // search PACKAGE only in Top
1319 if ((pl!=NULL)
1320 &&(IDTYP(pl)==PACKAGE_CMD))
1321 {
1322 if(IDPACKAGE(pl)->language==LANG_C)
1323 {
1324 if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1326 return FALSE;
1327 }
1328 }
1329 else
1330 {
1331 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1332 IDPACKAGE(pl)->libname=omStrDup(newlib);
1333 }
1335 IDPACKAGE(pl)->language = LANG_C;
1336
1337 IDPACKAGE(pl)->handle=(void *)NULL;
1339
1340 package s=currPack;
1341 currPack=IDPACKAGE(pl);
1342 if( init!= NULL)
1343 {
1344 sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1345 if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1346 else sModulFunctions.iiAddCproc = iiAddCproc;
1347 (*init)(&sModulFunctions);
1348 }
1349 if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1350 currPack->loaded=1;
1351 currPack=s;
1352
1353 return FALSE;
1354}
1355/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1356void module_help_main(const char *newlib,const char *help)
1357{
1358 char *plib = iiConvName(newlib);
1359 idhdl pl = basePack->idroot->get(plib,0);
1360 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1361 Werror(">>%s<< is not a package (trying to add package help)",plib);
1362 else
1363 {
1364 package s=currPack;
1365 currPack=IDPACKAGE(pl);
1366 idhdl h=enterid("info",0,STRING_CMD,&IDROOT,FALSE);
1368 currPack=s;
1369 }
1370}
1371void module_help_proc(const char *newlib,const char *p, const char *help)
1372{
1373 char *plib = iiConvName(newlib);
1374 idhdl pl = basePack->idroot->get(plib,0);
1375 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1376 Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1377 else
1378 {
1379 package s=currPack;
1380 currPack=IDPACKAGE(pl);
1381 char buff[SINGULAR_PATH_LENGTH];
1382 buff[SINGULAR_PATH_LENGTH-1]='\0';
1384 strncat(buff,"_help",SINGULAR_PATH_LENGTH-1-strlen(p));
1387 currPack=s;
1388 }
1389}
1390/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1391
1392#ifdef HAVE_DYNAMIC_LOADING
1393// loads a dynamic module from the binary path and returns a named function
1394// returns NULL, if something fails
1395void* binary_module_function(const char* newlib, const char* funcname)
1396{
1397 void* result = NULL;
1398
1399 const char* bin_dir = feGetResource('b');
1400 if (!bin_dir) { return NULL; }
1401
1402 char path_name[MAXPATHLEN];
1404
1405 void* openlib = dynl_open(path_name);
1406 if(!openlib)
1407 {
1408 Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1409 return NULL;
1410 }
1412 if (!result) Werror("%s: %s\n", funcname, dynl_error());
1413
1414 return result;
1415}
1416#endif
1417
1418/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1419static char mytoupper(char c)
1420{
1421 if(c>=97 && c<=(97+26)) c-=32;
1422 return(c);
1423}
1424
1425static char mytolower(char c)
1426{
1427 if(c>=65 && c<=(65+26)) c+=32;
1428 return(c);
1429}
1430
1431/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1432//#if defined(WINNT)
1433//# define FS_SEP '\\'
1434//#else
1435//# define FS_SEP '/'
1436//#endif
1437
1438char *iiConvName(const char *libname)
1439{
1440 char *tmpname = omStrDup(libname);
1441 char *p = strrchr(tmpname, DIR_SEP);
1442 char *r;
1443 if(p==NULL) p = tmpname; else p++;
1444 // p is now the start of the file name (without path)
1445 r=p;
1446 while(isalnum(*r)||(*r=='_')) r++;
1447 // r point the the end of the main part of the filename
1448 *r = '\0';
1449 r = omStrDup(p);
1450 *r = mytoupper(*r);
1451 // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1453
1454 return(r);
1455}
1456
1457/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1458#if 0 /* debug only */
1459void piShowProcList()
1460{
1461 idhdl h;
1462 procinfo *proc;
1463 char *name;
1464
1465 Print( "%-15s %20s %s,%s %s,%s %s,%s\n", "Library", "function",
1466 "line", "start", "line", "body", "line", "example");
1467 for(h = IDROOT; h != NULL; h = IDNEXT(h))
1468 {
1469 if(IDTYP(h) == PROC_CMD)
1470 {
1471 proc = IDPROC(h);
1472 if(strcmp(proc->procname, IDID(h))!=0)
1473 {
1474 name = (char *)omAlloc(strlen(IDID(h))+strlen(proc->procname)+4);
1475 snprintf(name, strlen(IDID(h))+strlen(proc->procname)+4,
1476 "%s -> %s", IDID(h), proc->procname);
1477 Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname, name);
1479 }
1480 else
1481 Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname,
1482 proc->procname);
1483 if(proc->language==LANG_SINGULAR)
1484 Print("line %-5ld %4d,%-5ld %4d,%-5ld\n",
1485 proc->data.s.proc_start,
1486 proc->data.s.body_lineno, proc->data.s.body_start,
1487 proc->data.s.example_lineno, proc->data.s.example_start);
1488 else if(proc->language==LANG_C)
1489 PrintS("type: object\n");
1490 }
1491 }
1492}
1493#endif
1494
1495/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1496//char *iiLineNo(char *procname, int lineno)
1497//{
1498// char buf[256];
1499// idhdl pn = ggetid(procname);
1500// procinfo *pi = IDPROC(pn);
1501//
1502// snprintf(buf,256, "%s %3d\0", procname, lineno);
1503// //snprintf(buf,256, "%s::%s %3d\0", pi->libname, pi->procname,
1504// // lineno + pi->data.s.body_lineno);
1505// return(buf);
1506//}
1507/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1508#ifdef HAVE_LIBPARSER
1509void libstack::push(const char */*p*/, char *libn)
1510{
1511 libstackv lp;
1512 if( !iiGetLibStatus(libn))
1513 {
1514 for(lp = this;lp!=NULL;lp=lp->next)
1515 {
1516 if(strcmp(lp->get(), libn)==0) break;
1517 }
1518 if(lp==NULL)
1519 {
1521 ls->next = this;
1522 ls->libname = omStrDup(libn);
1523 ls->to_be_done = TRUE;
1524 if(library_stack != NULL) ls->cnt = library_stack->cnt+1; else ls->cnt = 0;
1525 library_stack = ls;
1526 }
1527 }
1528}
1529
1530libstackv libstack::pop(const char */*p*/)
1531{
1532 libstackv ls = this;
1533 omFree((ADDRESS)ls->libname);
1534 library_stack = ls->next;
1536 return(library_stack);
1537}
1538
1539#endif /* HAVE_LIBPARSER */
1540/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static int si_max(const int a, const int b)
Definition auxiliary.h:124
int BOOLEAN
Definition auxiliary.h:87
#define TRUE
Definition auxiliary.h:100
#define FALSE
Definition auxiliary.h:96
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
char name() const
Definition variable.cc:122
Definition idrec.h:35
idhdl get(const char *s, int lev)
Definition ipid.cc:72
idhdl next
Definition idrec.h:38
void push(const char *p, char *libname)
Definition iplib.cc:1509
libstackv pop(const char *p)
Definition iplib.cc:1530
int cnt
Definition subexpr.h:167
void pop()
Definition ipid.cc:815
void push(char *)
Definition ipid.cc:805
Class used for (list of) interpreter objects.
Definition subexpr.h:83
int rtyp
Definition subexpr.h:91
void Init()
Definition subexpr.h:107
BOOLEAN RingDependend()
Definition subexpr.cc:421
void * data
Definition subexpr.h:88
void CleanUp(ring r=currRing)
Definition subexpr.cc:351
#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
char name(const Variable &v)
Definition factory.h:189
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:9760
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos=-1)
Definition iparith.cc:10105
idhdl ggetid(const char *n)
Definition ipid.cc:583
void killhdl2(idhdl h, idhdl *ih, ring r)
Definition ipid.cc:447
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition ipid.cc:281
VAR package basePack
Definition ipid.cc:58
VAR omBin idrec_bin
Definition ipid.cc:48
VAR proclevel * procstack
Definition ipid.cc:52
VAR idhdl currRingHdl
Definition ipid.cc:59
VAR package currPack
Definition ipid.cc:57
void killhdl(idhdl h, package proot)
Definition ipid.cc:416
VAR idhdl currPackHdl
Definition ipid.cc:55
idhdl packFindHdl(package r)
Definition ipid.cc:833
#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:538
#define IDPROC(a)
Definition ipid.h:140
#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:507
#define IDTYP(a)
Definition ipid.h:119
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:1072
#define SI_MAX_NEST
Definition iplib.cc:27
void yylprestart(FILE *input_file)
bool registered_dyn_module(char *fullname)
Definition iplib.cc:1166
ideal ii_CallProcId2Id(const char *lib, const char *proc, ideal arg, const ring R)
Definition iplib.cc:669
void register_dyn_module(char *fullname, void *handle)
Definition iplib.cc:1173
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:982
VAR int iiRETURNEXPR_len
Definition iplib.cc:483
static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
Definition iplib.cc:614
BOOLEAN iiEStart(char *example, procinfo *pi)
Definition iplib.cc:762
#define SI_GET_BUILTIN_MOD_INIT0(name)
Definition iplib.cc:807
int flint_mod_init(SModulFunctions *psModulFunctions)
Definition misc_ip.cc:1284
BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1190
static void iiCheckNest()
Definition iplib.cc:501
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:1438
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition iplib.cc:893
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:709
void print_init()
Definition libparse.cc:3482
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv args)
Definition iplib.cc:512
BOOLEAN iiTryLoadLib(leftv v, const char *id)
Definition iplib.cc:831
#define MODULE_SUFFIX_STRING
Definition iplib.cc:42
static void iiCleanProcs(idhdl &root)
Definition iplib.cc:937
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1293
int ii_CallProcId2Int(const char *lib, const char *proc, ideal arg, const ring R)
Definition iplib.cc:688
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition iplib.cc:1164
static char mytolower(char c)
Definition iplib.cc:1425
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:1147
static char mytoupper(char c)
Definition iplib.cc:1419
INST_VAR sleftv iiRETURNEXPR
Definition iplib.cc:482
void close_all_dyn_modules()
Definition iplib.cc:1180
#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:1303
EXTERN_VAR int yylplineno
Definition iplib.cc:65
BOOLEAN iiLocateLib(const char *lib, char *where)
Definition iplib.cc:879
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition iplib.cc:815
VAR ring * iiLocalRing
Definition iplib.cc:481
void module_help_main(const char *newlib, const char *help)
Definition iplib.cc:1356
static void iiShowLevRings()
Definition iplib.cc:486
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:635
static void iiCallLibProcBegin()
Definition iplib.cc:597
void module_help_proc(const char *newlib, const char *p, const char *help)
Definition iplib.cc:1371
static void iiRunInit(package p)
Definition iplib.cc:966
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:1395
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition iparith.cc:10105
procinfo * iiInitSingularProcinfo(procinfov pi, const char *libname, const char *procname, int, long pos, BOOLEAN pstatic)
Definition iplib.cc:1058
VAR idhdl iiCurrProc
Definition ipshell.cc:81
void iiCheckPack(package &p)
Definition ipshell.cc:1629
void killlocals(int v)
Definition ipshell.cc:386
VAR leftv iiCurrArgs
Definition ipshell.cc:80
idhdl rFindHdl(ring r, idhdl n)
Definition ipshell.cc:1699
void rSetHdl(idhdl h)
Definition ipshell.cc:5121
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:113
#define assume(x)
Definition mod2.h:387
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:143
#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:15
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:846
static void rDecRefCnt(ring r)
Definition ring.h:847
int status int void * buf
Definition si_signals.h:69
#define R
Definition sirandom.c:27
ip_package * package
Definition structs.h:43
sleftv * leftv
Definition structs.h:57
#define BITSET
Definition structs.h:16
#define loop
Definition structs.h:75
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
@ PACKAGE_CMD
Definition tok.h:150
@ STRING_CMD
Definition tok.h:187
@ MAX_TOK
Definition tok.h:220