23 #define SI_MAX_NEST 500 24 #elif defined(__CYGWIN__) 25 #define SI_MAX_NEST 480 27 #define SI_MAX_NEST 1000 30 #if defined(ix86Mac_darwin) || defined(x86_64Mac_darwin) || defined(ppcMac_darwin) 31 # define MODULE_SUFFIX bundle 32 #elif defined(__CYGWIN__) 33 # define MODULE_SUFFIX dll 35 # define MODULE_SUFFIX so 38 #define MODULE_SUFFIX_STRING EXPANDED_STRINGIFY(MODULE_SUFFIX) 41 #ifdef HAVE_DYNAMIC_LOADING 49 const char *procname,
int line,
long pos,
BOOLEAN pstatic=
FALSE);
52 extern int iiArithAddCmd(
const char *szName,
short nAlias,
short nTokval,
53 short nToktype,
short nPos);
84 return (strcmp(lib,
IDPACKAGE(hl)->libname)==0);
99 while ((*e>
' ') && (*e!=
'(')) e++;
110 while ((*e==
' ') || (*e==
'\t') || (*e==
'(')) e++;
116 return omStrDup(
"parameter list #;");
127 char *argstr=(
char *)
omAlloc(127);
139 if ((*s==
' ')||(*s==
'\t'))
141 else if ((*s==
'\n')&&(*(s+1)==
' '))
148 &&((par!=0) || (*e!=
')'))
152 else if (*e==
')') par--;
153 args_found=args_found || (*e>
' ');
161 if ((
int)strlen(argstr)+12 +(int)strlen(s)>= argstrlen)
164 char *a=(
char *)
omAlloc( argstrlen);
170 if(strncmp(s,
"alias ",6)!=0)
172 strcat(argstr,
"parameter ");
207 procbuflen = pi->
data.s.help_end - pi->
data.s.help_start;
215 s = (
char *)
omAlloc(procbuflen+head+3);
219 myfread(s+head+1, procbuflen, 1, fp);
221 s[procbuflen+head+1] =
'\n';
222 s[procbuflen+head+2] =
'\0';
224 for(i=0;i<=procbuflen+head+2; i++)
227 (s[i+1]==
'"' || s[i+1]==
'{' || s[i+1]==
'}' || s[i+1]==
'\\'))
232 if(offset>0) s[i-
offset] = s[
i];
238 procbuflen = pi->
data.s.def_end - pi->
data.s.proc_start;
239 char *ss=(
char *)
omAlloc(procbuflen+2);
241 myfread( ss, procbuflen, 1, fp);
251 procbuflen = pi->
data.s.body_end - pi->
data.s.body_start;
252 pi->
data.s.body = (
char *)
omAlloc( strlen(argstr)+procbuflen+15+
258 strcpy(pi->
data.s.body,argstr);
259 myfread( pi->
data.s.body+strlen(argstr), procbuflen, 1, fp);
261 procbuflen+=strlen(argstr);
264 pi->
data.s.body[procbuflen] =
'\0';
265 strcat( pi->
data.s.body+procbuflen,
"\n;return();\n\n" );
266 strcat( pi->
data.s.body+procbuflen+13,pi->
libname);
267 s=(
char *)strchr(pi->
data.s.body,
'{');
273 if ( pi->
data.s.example_lineno == 0)
277 (void) fgets(buf,
sizeof(buf),
fp);
278 procbuflen = pi->
data.s.proc_end - pi->
data.s.example_start - strlen(buf);
281 s = (
char *)
omAlloc(procbuflen+14);
283 s[procbuflen] =
'\0';
284 strcat(s+procbuflen-3,
"\n;return();\n\n" );
285 p=(
char *)strchr(s,
'{');
385 memset(v,0,
sizeof(
sleftv));
413 if (oh!=
NULL) o=oh->id;
481 iiRETURNEXPR_len+=16;
490 Werror(
"'%s::%s()' is a local procedure and cannot be accessed by an user.",
535 err = (pi->
data.o.function)(res, sl);
536 memcpy(&iiRETURNEXPR,res,
sizeof(iiRETURNEXPR));
559 if (!err)
Warn(
"too many arguments for %s",
IDID(pn));
605 WarnS(
"internal: lost ring in iiCallLib");
637 void*r=iiRETURNEXPR.
data;
667 tmp.
rtyp=arg_types[0];
668 while(arg_types[i]!=0)
672 tt->
rtyp=arg_types[
i];
687 void*r=iiRETURNEXPR.
data;
709 printf(
"entering example (level %d)\n",
myynest);
721 printf(
"leaving -example- (level %d)\n",
myynest);
743 # define SI_GET_BUILTIN_MOD_INIT0(name) int SI_MOD_INIT0(name)(SModulFunctions*); 745 # undef SI_GET_BUILTIN_MOD_INIT0 752 # define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); } 754 # undef SI_GET_BUILTIN_MOD_INIT 767 char *libname = (
char *)
omAlloc(strlen(
id)+5);
768 const char *suffix[] = {
"",
".lib",
".so",
".sl",
NULL };
774 for(i=0; suffix[
i] !=
NULL; i++)
776 sprintf(libname,
"%s%s",
id, suffix[i]);
781 #ifdef HAVE_DYNAMIC_LOADING 782 char libnamebuf[1024];
787 #ifdef HAVE_DYNAMIC_LOADING 818 strncpy(where,
IDPACKAGE(pl)->libname,127);
834 FILE *
fp =
feFopen( newlib,
"r", libnamebuf, tellerror );
854 WarnS(
"not of type package.");
858 if (!force)
return FALSE;
860 LoadResult =
iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
874 if (root==
NULL)
return;
879 && (pi->
data.s.body_start == 0L))
900 idhdl h=p->idroot->get(
"mod_init",0);
930 yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
943 WerrorS(
"Cannot load library,... aborting.");
953 Warn(
"library %s has old format. This format is still accepted,", newlib);
954 WarnS(
"but for functionality you may wish to change to the new");
955 WarnS(
"format. Please refer to the manual for further information.");
964 for(ls = library_stack; (ls !=
NULL) && (ls != ls_start); )
970 ls = ls->
pop(newlib);
974 PrintS(
"--------------------\n");
975 for(ls = library_stack; ls !=
NULL; ls = ls->
next)
977 Print(
"%s: LIB-stack:(%d), %s %s\n", newlib, ls->
cnt, ls->
get(),
980 PrintS(
"--------------------\n");
984 if(fp !=
NULL) fclose(fp);
991 const char *procname,
int,
long pos,
BOOLEAN pstatic)
993 memset(pi,0,
sizeof(*pi));
999 pi->
data.s.proc_start = pos;
1012 if (
IsCmd(procname,dummy))
1014 Werror(
">>%s< is a reserved name",procname);
1019 h=
IDROOT->get(procname,0);
1026 Warn(
"extend `%s`",procname);
1045 pi->
data.o.function = func;
1049 if(pi->
data.o.function == func)
1062 pi->
data.o.function = func;
1066 Warn(
"internal error: unknown procedure type %d",pi->
language);
1072 WarnS(
"iiAddCproc: failed.");
1080 int r=
iiAddCproc(libname,procname,pstatic,func);
1083 if (r) r=
iiAddCproc(libname,procname,pstatic,func);
1089 #ifdef HAVE_DYNAMIC_LOADING 1093 WerrorS(
"mod_init: static version can not load modules");
1108 memset(FullName,0,256);
1110 if( *fullname !=
'/' && *fullname !=
'.' )
1111 sprintf(FullName,
"./%s", newlib);
1112 else strncpy(FullName, fullname,255);
1115 if(
IsCmd(plib, token))
1117 Werror(
"'%s' is resered identifier\n", plib);
1118 goto load_modules_end;
1120 pl =
basePack->idroot->get(plib,0);
1153 Werror(
"%s not found", newlib);
1155 goto load_modules_end;
1169 int ver=(*fktn)(&sModulFunctions);
1176 Warn(
"loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,
MAX_TOK,ver);
1184 Werror(
"mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n",
dynl_error());
1212 pl =
basePack->idroot->get(plib,0);
1240 (*init)(&sModulFunctions);
1254 Werror(
">>%s<< is not a package (trying to add package help)",plib);
1269 Werror(
">>%s<< is not a package(trying to add help for %s)",plib,p);
1276 strncpy(buff,p,255);
1277 strncat(buff,
"_help",255-strlen(p));
1285 #ifdef HAVE_DYNAMIC_LOADING 1293 if (!bin_dir) {
return NULL; }
1304 result =
dynl_sym(openlib, funcname);
1314 if(c>=97 && c<=(97+26)) c-=32;
1320 if(c>=65 && c<=(65+26)) c+=32;
1334 char *p = strrchr(tmpname,
DIR_SEP);
1336 if(p==NULL) p = tmpname;
else p++;
1339 while(isalnum(*r)||(*r==
'_')) r++;
1352 void piShowProcList()
1358 Print(
"%-15s %20s %s,%s %s,%s %s,%s\n",
"Library",
"function",
1359 "line",
"start",
"line",
"body",
"line",
"example");
1376 Print(
"line %-5ld %4d,%-5ld %4d,%-5ld\n",
1377 proc->
data.s.proc_start,
1378 proc->
data.s.body_lineno, proc->
data.s.body_start,
1379 proc->
data.s.example_lineno, proc->
data.s.example_start);
1381 PrintS(
"type: object\n");
1400 #ifdef HAVE_LIBPARSER 1406 for(lp =
this;lp!=
NULL;lp=lp->
next)
1408 if(strcmp(lp->
get(), libn)==0)
break;
1416 if(library_stack != NULL) ls->
cnt = library_stack->
cnt+1;
else ls->
cnt = 0;
1426 library_stack = ls->
next;
1428 return(library_stack);
char * iiProcArgs(char *e, BOOLEAN withParenth)
const struct soptionStruct optionStruct[]
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
const CanonicalForm int s
#define TRACE_SHOW_LINENO
idhdl ggetid(const char *n)
unsigned char * proc[NUM_PROC]
Class used for (list of) interpreter objects.
BOOLEAN iiGetLibStatus(char *lib)
void module_help_main(const char *newlib, const char *help)
int yylplex(const char *libname, const char *libfile, lib_style_types *lib_style, idhdl pl, BOOLEAN autoexport=FALSE, lp_modes=LOAD_LIB)
static void iiRunInit(package p)
#define omreallocSize(addr, o_size, size)
#define SI_GET_BUILTIN_MOD_INIT(name)
BOOLEAN iiTryLoadLib(leftv v, const char *id)
static void iiShowLevRings()
procinfo * iiInitSingularProcinfo(procinfov pi, const char *libname, const char *procname, int, long pos, BOOLEAN pstatic)
static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
void * dynl_sym(void *handle, const char *symbol)
void WerrorS(const char *s)
void push(const char *p, char *libname)
libstackv pop(const char *p)
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
static void iiCheckNest()
void * dynl_open(char *filename)
void * iiCallLibProc1(const char *n, void *arg, int arg_type, BOOLEAN &err)
BOOLEAN iiPStart(idhdl pn, leftv v)
int dynl_check_opened(char *filename)
void killhdl2(idhdl h, idhdl *ih, ring r)
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
void * binary_module_function(const char *newlib, const char *funcname)
size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream)
int status int void * buf
char * feGetResource(const char id, int warn)
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0) }
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
void PrintS(const char *s)
char * iiProcName(char *buf, char &ct, char *&e)
char name(const Variable &v)
idhdl rFindHdl(ring r, idhdl n)
#define MODULE_SUFFIX_STRING
static void iiCallLibProcBegin()
BOOLEAN iiEStart(char *example, procinfo *pi)
BOOLEAN iiLocateLib(const char *lib, char *where)
#define SI_GET_BUILTIN_MOD_INIT0(name)
BOOLEAN iiAllStart(procinfov pi, char *p, feBufferTypes t, int l)
const Variable & v
< [in] a sqrfree bivariate poly
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv sl)
void * iiCallLibProcM(const char *n, void **args, int *arg_types, BOOLEAN &err)
args: NULL terminated arry of arguments arg_types: 0 terminated array of corresponding types ...
SModulFunc_t iiGetBuiltinModInit(const char *libname)
void killhdl(idhdl h, package proot)
void CleanUp(ring r=currRing)
int(* SModulFunc_t)(SModulFunctions *)
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
void module_help_proc(const char *newlib, const char *p, const char *help)
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
static void iiCleanProcs(idhdl &root)
idhdl packFindHdl(package r)
void yylprestart(FILE *input_file)
void iiCheckPack(package &p)
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
const struct soptionStruct verboseStruct[]
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
#define omFreeBin(addr, bin)
char * iiConvName(const char *libname)
char * iiGetLibProcBuffer(procinfo *pi, int part)
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
void Werror(const char *fmt,...)
const char * dynl_error()
int IsCmd(const char *n, int &tok)
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)