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 fseek(fp, pi->data.s.proc_start, SEEK_SET);
209 if(part==0)
210 { // load help string
211 int i, offset=0;
212 long head = pi->data.s.def_end - pi->data.s.proc_start;
213 procbuflen = pi->data.s.help_end - pi->data.s.help_start;
214 if (procbuflen<5)
215 {
216 fclose(fp);
217 return NULL; // help part does not exist
218 }
219 //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start,
220 // pi->data.s.proc_start, procbuflen);
221 s = (char *)omAlloc(procbuflen+head+3);
222 myfread(s, head, 1, fp);
223 s[head] = '\n';
224 fseek(fp, pi->data.s.help_start, SEEK_SET);
225 myfread(s+head+1, procbuflen, 1, fp);
226 fclose(fp);
227 s[procbuflen+head+1] = '\n';
228 s[procbuflen+head+2] = '\0';
229 offset=0;
230 for(i=0;i<=procbuflen+head+2; i++)
231 {
232 if(s[i]=='\\' &&
233 (s[i+1]=='"' || s[i+1]=='{' || s[i+1]=='}' || s[i+1]=='\\'))
234 {
235 i++;
236 offset++;
237 }
238 if(offset>0) s[i-offset] = s[i];
239 }
240 return(s);
241 }
242 else if(part==1)
243 { // load proc part - must exist
244 procbuflen = pi->data.s.def_end - pi->data.s.proc_start;
245 char *ss=(char *)omAlloc(procbuflen+2);
246 //fgets(buf, sizeof(buf), fp);
247 myfread( ss, procbuflen, 1, fp);
248 char ct;
249 char *e;
250 s=iiProcName(ss,ct,e);
251 char *argstr=NULL;
252 *e=ct;
254
255 assume(pi->data.s.body_end > pi->data.s.body_start);
256
257 procbuflen = pi->data.s.body_end - pi->data.s.body_start;
258 pi->data.s.body = (char *)omAlloc( strlen(argstr)+procbuflen+15+
259 strlen(pi->libname) );
260 //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end,
261 // pi->data.s.body_start, procbuflen);
262 assume(pi->data.s.body != NULL);
263 fseek(fp, pi->data.s.body_start, SEEK_SET);
264 strcpy(pi->data.s.body,argstr);
265 myfread( pi->data.s.body+strlen(argstr), procbuflen, 1, fp);
266 fclose( fp );
268 omFree(argstr);
269 omFree(ss);
270 pi->data.s.body[procbuflen] = '\0';
271 strcat( pi->data.s.body+procbuflen, "\n;return();\n\n" );
272 strcat( pi->data.s.body+procbuflen+13,pi->libname);
273 s=(char *)strchr(pi->data.s.body,'{');
274 if (s!=NULL) *s=' ';
275 return NULL;
276 }
277 else if(part==2)
278 { // example
279 if ( pi->data.s.example_lineno == 0)
280 return NULL; // example part does not exist
281 // load example
282 fseek(fp, pi->data.s.example_start, SEEK_SET);
283 /*char *dummy=*/ (void) fgets(buf, sizeof(buf), fp); // skip line with "example"
284 procbuflen = pi->data.s.proc_end - pi->data.s.example_start - strlen(buf);
285 //Print("Example=%ld-%ld=%d\n", pi->data.s.proc_end,
286 // pi->data.s.example_start, procbuflen);
287 s = (char *)omAlloc(procbuflen+14);
288 myfread(s, procbuflen, 1, fp);
289 s[procbuflen] = '\0';
290 strcat(s+procbuflen-3, "\n;return();\n\n" );
291 p=(char *)strchr(s,'{');
292 if (p!=NULL) *p=' ';
293 return(s);
294 }
295 return NULL;
296}
297
299{
301 int restore_traceit=0;
302 if (traceit_stop
304 {
305 traceit &=(~TRACE_SHOW_LINE);
306 traceit_stop=0;
308 }
309 // see below:
312 newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/,
313 pi, l );
314 BOOLEAN err=yyparse();
315
316 if (sLastPrinted.rtyp!=0)
317 {
319 }
320
322
323 // the access to optionStruct and verboseStruct do not work
324 // on x86_64-Linux for pic-code
325 if ((TEST_V_ALLWARN) &&
326 (t==BT_proc) &&
327 ((save1!=si_opt_1)||(save2!=si_opt_2)) &&
328 (pi->libname!=NULL) && (pi->libname[0]!='\0'))
329 {
330 if ((pi->libname!=NULL) && (pi->libname[0]!='\0'))
331 Warn("option changed in proc %s from %s",pi->procname,pi->libname);
332 else
333 Warn("option changed in proc %s",pi->procname);
334 int i;
335 for (i=0; optionStruct[i].setval!=0; i++)
336 {
337 if ((optionStruct[i].setval & si_opt_1)
338 && (!(optionStruct[i].setval & save1)))
339 {
340 Print(" +%s",optionStruct[i].name);
341 }
342 if (!(optionStruct[i].setval & si_opt_1)
343 && ((optionStruct[i].setval & save1)))
344 {
345 Print(" -%s",optionStruct[i].name);
346 }
347 }
348 for (i=0; verboseStruct[i].setval!=0; i++)
349 {
350 if ((verboseStruct[i].setval & si_opt_2)
351 && (!(verboseStruct[i].setval & save2)))
352 {
353 Print(" +%s",verboseStruct[i].name);
354 }
355 if (!(verboseStruct[i].setval & si_opt_2)
356 && ((verboseStruct[i].setval & save2)))
357 {
358 Print(" -%s",verboseStruct[i].name);
359 }
360 }
361 PrintLn();
362 }
363 return err;
364}
365/*2
366* start a proc
367* parameters are built as exprlist
368* TODO:interrupt
369* return FALSE on success, TRUE if an error occurs
370*/
372{
374 int old_echo=si_echo;
375 BOOLEAN err=FALSE;
376 char save_flags=0;
377
378 /* init febase ======================================== */
379 /* we do not enter this case if filename != NULL !! */
380 if (pn!=NULL)
381 {
382 pi = IDPROC(pn);
383 if(pi!=NULL)
384 {
385 save_flags=pi->trace_flag;
386 if( pi->data.s.body==NULL )
387 {
389 if (pi->data.s.body==NULL) return TRUE;
390 }
391// omUpdateInfo();
392// int m=om_Info.UsedBytes;
393// Print("proc %s, mem=%d\n",IDID(pn),m);
394 }
395 }
396 else return TRUE;
397 /* generate argument list ======================================*/
398 //iiCurrArgs should be NULL here, as the assignment for the parameters
399 // of the prevouis call are already done befor calling another routine
400 if (v!=NULL)
401 {
403 memcpy(iiCurrArgs,v,sizeof(sleftv)); // keeps track of v->next etc.
404 v->Init();
405 }
406 else
407 {
409 }
410 /* start interpreter ======================================*/
411 myynest++;
412 if (myynest > SI_MAX_NEST)
413 {
414 WerrorS("nesting too deep");
415 err=TRUE;
416 }
417 else
418 {
420 err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
422
423 if (iiLocalRing[myynest-1] != currRing)
424 {
426 {
427 //idhdl hn;
428 const char *n;
429 const char *o;
431 if (iiLocalRing[myynest-1]!=NULL)
433 if (oh!=NULL) o=oh->id;
434 else o="none";
435 if (currRing!=NULL)
437 if (nh!=NULL) n=nh->id;
438 else n="none";
439 Werror("ring change during procedure call %s: %s -> %s (level %d)",pi->procname,o,n,myynest);
441 err=TRUE;
442 }
444 }
445 if ((currRing==NULL)
446 && (currRingHdl!=NULL))
448 else
449 if ((currRing!=NULL) &&
451 ||(IDLEV(currRingHdl)>=myynest-1)))
452 {
455 }
456 //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
458#ifndef SING_NDEBUG
459 checkall();
460#endif
461 //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
462 }
463 myynest--;
465 if (pi!=NULL)
466 pi->trace_flag=save_flags;
467// omUpdateInfo();
468// int m=om_Info.UsedBytes;
469// Print("exit %s, mem=%d\n",IDID(pn),m);
470 return err;
471}
472
476
477#ifdef RDEBUG
478static void iiShowLevRings()
479{
480 int i;
481 for (i=0;i<=myynest;i++)
482 {
483 Print("lev %d:",i);
484 if (iiLocalRing[i]==NULL) PrintS("NULL");
485 else Print("%lx",(long)iiLocalRing[i]);
486 PrintLn();
487 }
488 if (currRing==NULL) PrintS("curr:NULL\n");
489 else Print ("curr:%lx\n",(long)currRing);
490}
491#endif /* RDEBUG */
492
493static void iiCheckNest()
494{
495 if (myynest >= iiRETURNEXPR_len-1)
496 {
498 iiRETURNEXPR_len*sizeof(ring),
499 (iiRETURNEXPR_len+16)*sizeof(ring));
500 memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
502 }
503}
505{
506 int err;
508 if(pi->is_static && myynest==0)
509 {
510 Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
511 pi->libname, pi->procname);
512 return TRUE;
513 }
514 iiCheckNest();
516 //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
518 procstack->push(pi->procname);
520 || (pi->trace_flag&TRACE_SHOW_PROC))
521 {
523 Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
524 }
525#ifdef RDEBUG
527#endif
528 switch (pi->language)
529 {
530 default:
531 case LANG_NONE:
532 WerrorS("undefined proc");
533 err=TRUE;
534 break;
535
536 case LANG_SINGULAR:
537 if ((pi->pack!=NULL)&&(currPack!=pi->pack))
538 {
539 currPack=pi->pack;
542 //Print("set pack=%s\n",IDID(currPackHdl));
543 }
544 else if ((pack!=NULL)&&(currPack!=pack))
545 {
546 currPack=pack;
549 //Print("set pack=%s\n",IDID(currPackHdl));
550 }
551 err=iiPStart(pn,args);
552 break;
553 case LANG_C:
555 err = (pi->data.o.function)(res, args);
558 break;
559 }
561 || (pi->trace_flag&TRACE_SHOW_PROC))
562 {
564 Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
565 }
566 //const char *n="NULL";
567 //if (currRingHdl!=NULL) n=IDID(currRingHdl);
568 //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
569#ifdef RDEBUG
571#endif
572 if (err)
573 {
575 //iiRETURNEXPR.Init(); //done by CleanUp
576 }
577 if (iiCurrArgs!=NULL)
578 {
579 if (!err) Warn("too many arguments for %s",IDID(pn));
583 }
584 procstack->pop();
585 if (err)
586 return TRUE;
587 return FALSE;
588}
590{
592 if (currRing!=NULL)
593 {
595 {
596 // clean up things depending on currRingHdl:
599 }
600 // need to define a ring-hdl for currRingHdl
604 }
605}
607{
608 if ((currRing!=NULL)
609 &&(currRing!=save_ring))
610 {
613 idhdl prev=NULL;
614 while((hh!=currRingHdl) && (hh!=NULL)) { prev=hh; hh=hh->next; }
615 if (hh!=NULL)
616 {
617 if (prev==NULL) IDROOT=hh->next;
618 else prev->next=hh->next;
621 }
622 }
625}
626
627void* iiCallLibProc1(const char*n, void *arg, int arg_type, BOOLEAN &err)
628{
629 idhdl h=ggetid(n);
630 if ((h==NULL)
631 || (IDTYP(h)!=PROC_CMD))
632 {
633 err=2;
634 return NULL;
635 }
636 // ring handling
640 // argument:
641 sleftv tmp;
642 tmp.Init();
643 tmp.data=arg;
644 tmp.rtyp=arg_type;
645 // call proc
647 // clean up ring
649 // return
650 if (err==FALSE)
651 {
652 void*r=iiRETURNEXPR.data;
655 return r;
656 }
657 return NULL;
658}
659
660// return NULL on failure
661ideal ii_CallProcId2Id(const char *lib,const char *proc, ideal arg, const ring R)
662{
663 char *plib = iiConvName(lib);
666 if (h==NULL)
667 {
669 if (bo) return NULL;
670 }
673 BOOLEAN err;
676 if (err) return NULL;
677 return I;
678}
679
680int ii_CallProcId2Int(const char *lib,const char *proc, ideal arg, const ring R)
681{
682 char *plib = iiConvName(lib);
685 if (h==NULL)
686 {
688 if (bo) return 0;
689 }
690 BOOLEAN err;
693 int I=(int)(long)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
695 if (err) return 0;
696 return I;
697}
698
699/// args: NULL terminated array of arguments
700/// arg_types: 0 terminated array of corresponding types
701leftv ii_CallLibProcM(const char*n, void **args, int* arg_types, const ring R, BOOLEAN &err)
702{
703 idhdl h=ggetid(n);
704 if ((h==NULL)
705 || (IDTYP(h)!=PROC_CMD))
706 {
707 err=2;
708 return NULL;
709 }
710 // ring handling
715 // argument:
716 if (arg_types[0]!=0)
717 {
718 sleftv tmp;
719 leftv tt=&tmp;
720 int i=1;
721 tmp.Init();
722 tmp.data=args[0];
723 tmp.rtyp=arg_types[0];
724 while(arg_types[i]!=0)
725 {
727 tt=tt->next;
728 tt->rtyp=arg_types[i];
729 tt->data=args[i];
730 i++;
731 }
732 // call proc
734 }
735 else
736 // call proc
738 // clean up ring
740 // return
741 if (err==FALSE)
742 {
744 memcpy(h,&iiRETURNEXPR,sizeof(sleftv));
746 return h;
747 }
748 return NULL;
749}
750/*2
751* start an example (as a proc),
752* destroys the string 'example'
753*/
754BOOLEAN iiEStart(char* example, procinfo *pi)
755{
756 BOOLEAN err;
757 int old_echo=si_echo;
758
759 iiCheckNest();
760 procstack->push(example);
763 {
765 printf("entering example (level %d)\n",myynest);
766 }
767 myynest++;
768
769 err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
770
772 myynest--;
775 {
777 printf("leaving -example- (level %d)\n",myynest);
778 }
780 {
782 {
785 }
786 else
787 {
790 }
791 }
792 procstack->pop();
793 return err;
794}
795
796
797extern "C"
798{
799# define SI_GET_BUILTIN_MOD_INIT0(name) int SI_MOD_INIT0(name)(SModulFunctions*);
801# undef SI_GET_BUILTIN_MOD_INIT0
802};
803
805
807iiGetBuiltinModInit(const char* libname)
808{
809#ifdef HAVE_FLINT
810 if (strcmp(libname,"flint.so")==0) return SI_MOD_INIT0(flint);
811#endif
812# define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
814# undef SI_GET_BUILTIN_MOD_INIT
815
816 return NULL;
817}
818
819
820
821
822/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
823BOOLEAN iiTryLoadLib(leftv v, const char *id)
824{
826 char libnamebuf[1024];
827 size_t len=strlen(id)+5;
828 char *libname = (char *)omAlloc(len);
829 const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
830 int i = 0;
831 // FILE *fp;
832 // package pack;
833 // idhdl packhdl;
835 for(i=0; suffix[i] != NULL; i++)
836 {
837 snprintf(libname,len, "%s%s", id, suffix[i]);
838 *libname = mytolower(*libname);
839 if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
840 {
841 #ifdef HAVE_DYNAMIC_LOADING
842 char libnamebuf[1024];
843 #endif
844
845 if (LT==LT_SINGULAR)
846 LoadResult = iiLibCmd(libname, FALSE, FALSE,TRUE);
847 #ifdef HAVE_DYNAMIC_LOADING
848 else if ((LT==LT_ELF) || (LT==LT_HPUX))
850 #endif
851 else if (LT==LT_BUILTIN)
852 {
854 }
855 if(!LoadResult )
856 {
857 v->name = iiConvName(libname);
858 break;
859 }
860 }
861 }
862 omFree(libname);
863 return LoadResult;
864}
865
866/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
867/* check, if library lib has already been loaded
868 if yes, writes filename of lib into where and returns TRUE,
869 no, returns FALSE
870*/
871BOOLEAN iiLocateLib(const char* lib, char* where)
872{
873 char *plib = iiConvName(lib);
874 idhdl pl = basePack->idroot->get(plib,0);
875 if( (pl!=NULL) && (IDTYP(pl)==PACKAGE_CMD) &&
876 (IDPACKAGE(pl)->language == LANG_SINGULAR))
877 {
878 strncpy(where,IDPACKAGE(pl)->libname,127);
879 return TRUE;
880 }
881 else
882 return FALSE;;
883}
884
886{
887 if (strcmp(newlib,"Singular")==0) return FALSE;
888 char libnamebuf[1024];
889 idhdl pl;
890 char *plib = iiConvName(newlib);
892 // int lines = 1;
894
895 if (fp==NULL)
896 {
897 return TRUE;
898 }
899 pl = basePack->idroot->get(plib,0);
900 if (pl==NULL)
901 {
902 pl = enterid( plib,0, PACKAGE_CMD,
903 &(basePack->idroot), TRUE );
904 IDPACKAGE(pl)->language = LANG_SINGULAR;
905 IDPACKAGE(pl)->libname=omStrDup(newlib);
906 }
907 else
908 {
909 if(IDTYP(pl)!=PACKAGE_CMD)
910 {
912 WarnS("not of type package.");
913 fclose(fp);
914 return TRUE;
915 }
916 if (!force)
917 {
919 return FALSE;
920 }
921 }
923
924 if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
926 return LoadResult;
927}
928/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
929static void iiCleanProcs(idhdl &root)
930{
931 idhdl prev=NULL;
932 loop
933 {
934 if (root==NULL) return;
935 if (IDTYP(root)==PROC_CMD)
936 {
937 procinfo *pi=(procinfo*)IDDATA(root);
938 if ((pi->language == LANG_SINGULAR)
939 && (pi->data.s.body_start == 0L))
940 {
941 // procinfo data incorrect:
942 // - no proc body can start at the beginning of the file
943 killhdl(root);
944 if (prev==NULL)
945 root=IDROOT;
946 else
947 {
948 root=prev;
949 prev=NULL;
950 }
951 continue;
952 }
953 }
954 prev=root;
955 root=IDNEXT(root);
956 }
957}
958static void iiRunInit(package p)
959{
960 idhdl h=p->idroot->get("mod_init",0);
961 if (h==NULL) return;
962 if (IDTYP(h)==PROC_CMD)
963 {
964 int save=yylineno;
965 myynest++;
966 // procinfo *pi=(procinfo*)IDDATA(h);
967 //PrintS("mod_init found\n");
969 myynest--;
971 }
972}
973/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
974BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char*newlib,
976{
980
981 yylpin = fp;
982 #if YYLPDEBUG > 1
983 print_init();
984 #endif
987 else lpverbose=0;
988 // yylplex sets also text_buffer
989 if (text_buffer!=NULL) *text_buffer='\0';
991 if(yylp_errno)
992 {
993 Werror("Library %s: ERROR occurred: in line %d, %d.", newlib, yylplineno,
994 current_pos(0));
996 {
1000 }
1001 else
1003 WerrorS("Cannot load library,... aborting.");
1004 reinit_yylp();
1005 fclose( yylpin );
1007 return TRUE;
1008 }
1009 if (BVERBOSE(V_LOAD_LIB))
1010 Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
1012 {
1013 Warn( "library %s has old format. This format is still accepted,", newlib);
1014 WarnS( "but for functionality you may wish to change to the new");
1015 WarnS( "format. Please refer to the manual for further information.");
1016 }
1017 reinit_yylp();
1018 fclose( yylpin );
1019 fp = NULL;
1020 iiRunInit(IDPACKAGE(pl));
1021
1022 {
1023 libstackv ls;
1024 for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
1025 {
1026 if(ls->to_be_done)
1027 {
1028 ls->to_be_done=FALSE;
1030 ls = ls->pop(newlib);
1031 }
1032 }
1033#if 0
1034 PrintS("--------------------\n");
1035 for(ls = library_stack; ls != NULL; ls = ls->next)
1036 {
1037 Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
1038 ls->to_be_done ? "not loaded" : "loaded");
1039 }
1040 PrintS("--------------------\n");
1041#endif
1042 }
1043
1044 if(fp != NULL) fclose(fp);
1045 return FALSE;
1046}
1047
1048
1049/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1051 const char *procname, int, long pos, BOOLEAN pstatic)
1052{
1053 memset(pi,0,sizeof(*pi));
1054 pi->libname = omStrDup(libname);
1055 pi->procname = omStrDup(procname);
1056 pi->language = LANG_SINGULAR;
1057 pi->ref = 1;
1058 pi->is_static = pstatic;
1059 pi->data.s.proc_start = pos;
1060 return(pi);
1061}
1062
1063/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1064int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1065 BOOLEAN(*func)(leftv res, leftv v))
1066{
1067 procinfov pi;
1068 idhdl h;
1069
1070 #ifndef SING_NDEBUG
1071 int dummy;
1072 if (IsCmd(procname,dummy))
1073 {
1074 Werror(">>%s< is a reserved name",procname);
1075 return 0;
1076 }
1077 #endif
1078
1079 h=IDROOT->get(procname,0);
1080 if ((h!=NULL)
1081 && (IDTYP(h)==PROC_CMD))
1082 {
1083 pi = IDPROC(h);
1084 #if 0
1085 if ((pi->language == LANG_SINGULAR)
1086 &&(BVERBOSE(V_REDEFINE)))
1087 Warn("extend `%s`",procname);
1088 #endif
1089 }
1090 else
1091 {
1092 h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
1093 }
1094 if ( h!= NULL )
1095 {
1096 pi = IDPROC(h);
1097 if((pi->language == LANG_SINGULAR)
1098 ||(pi->language == LANG_NONE))
1099 {
1100 omfree(pi->libname);
1101 pi->libname = omStrDup(libname);
1102 omfree(pi->procname);
1103 pi->procname = omStrDup(procname);
1104 pi->language = LANG_C;
1105 pi->ref = 1;
1106 pi->is_static = pstatic;
1107 pi->data.o.function = func;
1108 }
1109 else if(pi->language == LANG_C)
1110 {
1111 if(pi->data.o.function == func)
1112 {
1113 pi->ref++;
1114 }
1115 else
1116 {
1117 omfree(pi->libname);
1118 pi->libname = omStrDup(libname);
1119 omfree(pi->procname);
1120 pi->procname = omStrDup(procname);
1121 pi->language = LANG_C;
1122 pi->ref = 1;
1123 pi->is_static = pstatic;
1124 pi->data.o.function = func;
1125 }
1126 }
1127 else
1128 Warn("internal error: unknown procedure type %d",pi->language);
1129 if (currPack->language==LANG_SINGULAR) currPack->language=LANG_MIX;
1130 return(1);
1131 }
1132 else
1133 {
1134 WarnS("iiAddCproc: failed.");
1135 }
1136 return(0);
1137}
1138
1139int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic,
1140 BOOLEAN(*func)(leftv res, leftv v))
1141{
1142 int r=iiAddCproc(libname,procname,pstatic,func);
1143 package s=currPack;
1145 if (r) r=iiAddCproc(libname,procname,pstatic,func);
1146 currPack=s;
1147 return r;
1148}
1149
1150/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1151#ifdef HAVE_DYNAMIC_LOADING
1152#include <map>
1153#include <string>
1154#include <pthread.h>
1155
1156THREAD_VAR std::map<std::string, void *> *dyn_modules;
1157
1159 if (dyn_modules == NULL)
1160 return false;
1161 std::string fname = fullname;
1162 return dyn_modules->count(fname) != 0;
1163}
1164
1165void register_dyn_module(char *fullname, void * handle) {
1166 std::string fname = fullname;
1167 if (dyn_modules == NULL)
1168 dyn_modules = new std::map<std::string, void *>();
1169 dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1170}
1171
1173 for (std::map<std::string, void *>::iterator it = dyn_modules->begin();
1174 it != dyn_modules->end();
1175 it++)
1176 {
1177 dynl_close(it->second);
1178 }
1179 delete dyn_modules;
1180 dyn_modules = NULL;
1181}
1183{
1184/*
1185 typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1186 BOOLEAN pstatic,
1187 BOOLEAN(*func)(leftv res, leftv v)));
1188*/
1190 idhdl pl;
1191 char *plib = iiConvName(newlib);
1193 int token;
1194 int l=si_max((int)strlen(fullname),(int)strlen(newlib))+3;
1195 char *FullName=(char*)omAlloc0(l);
1196
1197 if( *fullname != '/' && *fullname != '.' )
1198 snprintf(FullName,l, "./%s", newlib);
1199 else strncpy(FullName, fullname,l);
1200
1201
1202 if(IsCmd(plib, token))
1203 {
1204 Werror("'%s' is resered identifier\n", plib);
1205 goto load_modules_end;
1206 }
1207 pl = basePack->idroot->get(plib,0); /* packages only in top level
1208 (see enterid) */
1209 if ((pl!=NULL)
1210 &&(IDTYP(pl)==PACKAGE_CMD))
1211 {
1212 if(IDPACKAGE(pl)->language==LANG_C)
1213 {
1214 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as package", newlib);
1216 return FALSE;
1217 }
1218 else if(IDPACKAGE(pl)->language==LANG_MIX)
1219 {
1220 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s contain binary parts, cannot load", newlib);
1222 return FALSE;
1223 }
1224 }
1225 else
1226 {
1227 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1228 omFreeBinAddr(plib); /* enterid copied plib*/
1229 IDPACKAGE(pl)->libname=omStrDup(newlib);
1230 }
1231 IDPACKAGE(pl)->language = LANG_C;
1233 {
1234 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
1236 return FALSE;
1237 }
1238 if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1239 {
1240 Werror("dynl_open failed:%s", dynl_error());
1241 Werror("%s not found", newlib);
1242 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1243 goto load_modules_end;
1244 }
1245 else
1246 {
1248
1249 package s=currPack;
1250 currPack=IDPACKAGE(pl);
1251 fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1252 if( fktn!= NULL)
1253 {
1254 sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1255 if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1256 else sModulFunctions.iiAddCproc = iiAddCproc;
1257 int ver=(*fktn)(&sModulFunctions);
1258 if (ver==MAX_TOK)
1259 {
1260 if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1261 }
1262 else
1263 {
1264 Warn("loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,MAX_TOK,ver);
1265 }
1266 currPack->loaded=1;
1267 currPack=s; /* reset currPack to previous */
1269 RET=FALSE;
1270 }
1271 else
1272 {
1273 Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1274 errorreported=0;
1275 if(IDPACKAGE(pl)->idroot==NULL)
1276 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1277 }
1278 }
1279
1282 return RET;
1283}
1284
1293#endif /* HAVE_DYNAMIC_LOADING */
1294/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1296{
1297 int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1298 BOOLEAN(*func)(leftv res, leftv v));
1299/*
1300 typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1301 BOOLEAN pstatic,
1302 BOOLEAN(*func)(leftv res, leftv v)));
1303*/
1304 // SModulFunc_t fktn;
1305 idhdl pl;
1306 char *plib = iiConvName(newlib);
1307 // BOOLEAN RET=TRUE;
1308 // int token;
1309
1310 pl = basePack->idroot->get(plib,0); // search PACKAGE only in Top
1311 if ((pl!=NULL)
1312 &&(IDTYP(pl)==PACKAGE_CMD))
1313 {
1314 if(IDPACKAGE(pl)->language==LANG_C)
1315 {
1316 if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1318 return FALSE;
1319 }
1320 }
1321 else
1322 {
1323 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1324 IDPACKAGE(pl)->libname=omStrDup(newlib);
1325 }
1327 IDPACKAGE(pl)->language = LANG_C;
1328
1329 IDPACKAGE(pl)->handle=(void *)NULL;
1331
1332 package s=currPack;
1333 currPack=IDPACKAGE(pl);
1334 if( init!= NULL)
1335 {
1336 sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1337 if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1338 else sModulFunctions.iiAddCproc = iiAddCproc;
1339 (*init)(&sModulFunctions);
1340 }
1341 if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1342 currPack->loaded=1;
1343 currPack=s;
1344
1345 return FALSE;
1346}
1347/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1348void module_help_main(const char *newlib,const char *help)
1349{
1350 char *plib = iiConvName(newlib);
1351 idhdl pl = basePack->idroot->get(plib,0);
1352 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1353 Werror(">>%s<< is not a package (trying to add package help)",plib);
1354 else
1355 {
1356 package s=currPack;
1357 currPack=IDPACKAGE(pl);
1358 idhdl h=enterid("info",0,STRING_CMD,&IDROOT,FALSE);
1360 currPack=s;
1361 }
1362}
1363void module_help_proc(const char *newlib,const char *p, const char *help)
1364{
1365 char *plib = iiConvName(newlib);
1366 idhdl pl = basePack->idroot->get(plib,0);
1367 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1368 Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1369 else
1370 {
1371 package s=currPack;
1372 currPack=IDPACKAGE(pl);
1373 char buff[SINGULAR_PATH_LENGTH];
1374 buff[SINGULAR_PATH_LENGTH-1]='\0';
1376 strncat(buff,"_help",SINGULAR_PATH_LENGTH-1-strlen(p));
1379 currPack=s;
1380 }
1381}
1382/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1383
1384#ifdef HAVE_DYNAMIC_LOADING
1385// loads a dynamic module from the binary path and returns a named function
1386// returns NULL, if something fails
1387void* binary_module_function(const char* newlib, const char* funcname)
1388{
1389 void* result = NULL;
1390
1391 const char* bin_dir = feGetResource('b');
1392 if (!bin_dir) { return NULL; }
1393
1394 char path_name[MAXPATHLEN];
1396
1397 void* openlib = dynl_open(path_name);
1398 if(!openlib)
1399 {
1400 Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1401 return NULL;
1402 }
1404 if (!result) Werror("%s: %s\n", funcname, dynl_error());
1405
1406 return result;
1407}
1408#endif
1409
1410/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1411static char mytoupper(char c)
1412{
1413 if(c>=97 && c<=(97+26)) c-=32;
1414 return(c);
1415}
1416
1417static char mytolower(char c)
1418{
1419 if(c>=65 && c<=(65+26)) c+=32;
1420 return(c);
1421}
1422
1423/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1424//#if defined(WINNT)
1425//# define FS_SEP '\\'
1426//#else
1427//# define FS_SEP '/'
1428//#endif
1429
1430char *iiConvName(const char *libname)
1431{
1432 char *tmpname = omStrDup(libname);
1433 char *p = strrchr(tmpname, DIR_SEP);
1434 char *r;
1435 if(p==NULL) p = tmpname; else p++;
1436 // p is now the start of the file name (without path)
1437 r=p;
1438 while(isalnum(*r)||(*r=='_')) r++;
1439 // r point the the end of the main part of the filename
1440 *r = '\0';
1441 r = omStrDup(p);
1442 *r = mytoupper(*r);
1443 // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1445
1446 return(r);
1447}
1448
1449/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1450#if 0 /* debug only */
1451void piShowProcList()
1452{
1453 idhdl h;
1454 procinfo *proc;
1455 char *name;
1456
1457 Print( "%-15s %20s %s,%s %s,%s %s,%s\n", "Library", "function",
1458 "line", "start", "line", "body", "line", "example");
1459 for(h = IDROOT; h != NULL; h = IDNEXT(h))
1460 {
1461 if(IDTYP(h) == PROC_CMD)
1462 {
1463 proc = IDPROC(h);
1464 if(strcmp(proc->procname, IDID(h))!=0)
1465 {
1466 name = (char *)omAlloc(strlen(IDID(h))+strlen(proc->procname)+4);
1467 sprintf(name, "%s -> %s", IDID(h), proc->procname);
1468 Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname, name);
1470 }
1471 else
1472 Print( "%d %-15s %20s ", proc->is_static ? 1 : 0, proc->libname,
1473 proc->procname);
1474 if(proc->language==LANG_SINGULAR)
1475 Print("line %-5ld %4d,%-5ld %4d,%-5ld\n",
1476 proc->data.s.proc_start,
1477 proc->data.s.body_lineno, proc->data.s.body_start,
1478 proc->data.s.example_lineno, proc->data.s.example_start);
1479 else if(proc->language==LANG_C)
1480 PrintS("type: object\n");
1481 }
1482 }
1483}
1484#endif
1485
1486/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1487//char *iiLineNo(char *procname, int lineno)
1488//{
1489// char buf[256];
1490// idhdl pn = ggetid(procname);
1491// procinfo *pi = IDPROC(pn);
1492//
1493// snprintf(buf,256, "%s %3d\0", procname, lineno);
1494// //snprintf(buf,256, "%s::%s %3d\0", pi->libname, pi->procname,
1495// // lineno + pi->data.s.body_lineno);
1496// return(buf);
1497//}
1498/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
1499#ifdef HAVE_LIBPARSER
1500void libstack::push(const char */*p*/, char *libn)
1501{
1502 libstackv lp;
1503 if( !iiGetLibStatus(libn))
1504 {
1505 for(lp = this;lp!=NULL;lp=lp->next)
1506 {
1507 if(strcmp(lp->get(), libn)==0) break;
1508 }
1509 if(lp==NULL)
1510 {
1512 ls->next = this;
1513 ls->libname = omStrDup(libn);
1514 ls->to_be_done = TRUE;
1515 if(library_stack != NULL) ls->cnt = library_stack->cnt+1; else ls->cnt = 0;
1516 library_stack = ls;
1517 }
1518 }
1519}
1520
1521libstackv libstack::pop(const char */*p*/)
1522{
1523 libstackv ls = this;
1524 omFree((ADDRESS)ls->libname);
1525 library_stack = ls->next;
1527 return(library_stack);
1528}
1529
1530#endif /* HAVE_LIBPARSER */
1531/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
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:4078
CanonicalForm fp
Definition cfModGcd.cc:4102
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:1500
libstackv pop(const char *p)
Definition iplib.cc:1521
int cnt
Definition subexpr.h:167
void pop()
Definition ipid.cc:813
void push(char *)
Definition ipid.cc:803
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:418
void * data
Definition subexpr.h:88
void CleanUp(ring r=currRing)
Definition subexpr.cc:348
#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:284
@ PROC_CMD
Definition grammar.cc:280
@ RING_CMD
Definition grammar.cc:281
int yyparse(void)
Definition grammar.cc:2111
ideal idCopy(ideal A)
Definition ideals.h:60
int IsCmd(const char *n, int &tok)
Definition iparith.cc:9548
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos=-1)
Definition iparith.cc:9893
idhdl ggetid(const char *n)
Definition ipid.cc:581
void killhdl2(idhdl h, idhdl *ih, ring r)
Definition ipid.cc:445
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition ipid.cc:279
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:414
VAR idhdl currPackHdl
Definition ipid.cc:55
idhdl packFindHdl(package r)
Definition ipid.cc:831
#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:1064
#define SI_MAX_NEST
Definition iplib.cc:27
void yylprestart(FILE *input_file)
bool registered_dyn_module(char *fullname)
Definition iplib.cc:1158
ideal ii_CallProcId2Id(const char *lib, const char *proc, ideal arg, const ring R)
Definition iplib.cc:661
void register_dyn_module(char *fullname, void *handle)
Definition iplib.cc:1165
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:974
VAR int iiRETURNEXPR_len
Definition iplib.cc:475
static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
Definition iplib.cc:606
BOOLEAN iiEStart(char *example, procinfo *pi)
Definition iplib.cc:754
#define SI_GET_BUILTIN_MOD_INIT0(name)
Definition iplib.cc:799
int flint_mod_init(SModulFunctions *psModulFunctions)
Definition misc_ip.cc:1281
BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1182
static void iiCheckNest()
Definition iplib.cc:493
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:1430
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition iplib.cc:885
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:701
void print_init()
Definition libparse.cc:3482
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv args)
Definition iplib.cc:504
BOOLEAN iiTryLoadLib(leftv v, const char *id)
Definition iplib.cc:823
#define MODULE_SUFFIX_STRING
Definition iplib.cc:42
static void iiCleanProcs(idhdl &root)
Definition iplib.cc:929
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1285
int ii_CallProcId2Int(const char *lib, const char *proc, ideal arg, const ring R)
Definition iplib.cc:680
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition iplib.cc:1156
static char mytolower(char c)
Definition iplib.cc:1417
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:1139
static char mytoupper(char c)
Definition iplib.cc:1411
INST_VAR sleftv iiRETURNEXPR
Definition iplib.cc:474
void close_all_dyn_modules()
Definition iplib.cc:1172
#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:1295
EXTERN_VAR int yylplineno
Definition iplib.cc:65
BOOLEAN iiLocateLib(const char *lib, char *where)
Definition iplib.cc:871
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition iplib.cc:807
VAR ring * iiLocalRing
Definition iplib.cc:473
void module_help_main(const char *newlib, const char *help)
Definition iplib.cc:1348
static void iiShowLevRings()
Definition iplib.cc:478
BOOLEAN iiAllStart(procinfov pi, const char *p, feBufferTypes t, int l)
Definition iplib.cc:298
void * iiCallLibProc1(const char *n, void *arg, int arg_type, BOOLEAN &err)
Definition iplib.cc:627
static void iiCallLibProcBegin()
Definition iplib.cc:589
void module_help_proc(const char *newlib, const char *p, const char *help)
Definition iplib.cc:1363
static void iiRunInit(package p)
Definition iplib.cc:958
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:371
void * binary_module_function(const char *newlib, const char *funcname)
Definition iplib.cc:1387
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition iparith.cc:9893
procinfo * iiInitSingularProcinfo(procinfov pi, const char *libname, const char *procname, int, long pos, BOOLEAN pstatic)
Definition iplib.cc:1050
VAR idhdl iiCurrProc
Definition ipshell.cc:81
void iiCheckPack(package &p)
Definition ipshell.cc:1631
void killlocals(int v)
Definition ipshell.cc:386
VAR leftv iiCurrArgs
Definition ipshell.cc:80
idhdl rFindHdl(ring r, idhdl n)
Definition ipshell.cc:1702
void rSetHdl(idhdl h)
Definition ipshell.cc:5128
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:142
#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:841
static void rDecRefCnt(ring r)
Definition ring.h:842
int status int void * buf
Definition si_signals.h:59
#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:149
@ STRING_CMD
Definition tok.h:185
@ MAX_TOK
Definition tok.h:218