33 #define SI_MAX_NEST 500 34 #elif defined(__CYGWIN__) 35 #define SI_MAX_NEST 480 37 #define SI_MAX_NEST 1000 40 #if defined(ix86Mac_darwin) || defined(x86_64Mac_darwin) || defined(ppcMac_darwin) 41 # define MODULE_SUFFIX bundle 42 #elif defined(__CYGWIN__) 43 # define MODULE_SUFFIX dll 45 # define MODULE_SUFFIX so 48 #define MODULE_SUFFIX_STRING EXPANDED_STRINGIFY(MODULE_SUFFIX) 51 #ifdef HAVE_DYNAMIC_LOADING 59 const char *procname,
int line,
long pos,
BOOLEAN pstatic=
FALSE);
62 extern int iiArithAddCmd(
const char *szName,
short nAlias,
short nTokval,
63 short nToktype,
short nPos);
94 return (strcmp(lib,
IDPACKAGE(hl)->libname)==0);
118 while ((*e>
' ') && (*e!=
'(')) e++;
129 while ((*e==
' ') || (*e==
'\t') || (*e==
'(')) e++;
135 return omStrDup(
"parameter list #;");
146 char *argstr=(
char *)
omAlloc(127);
158 if ((*
s==
' ')||(*
s==
'\t'))
160 else if ((*
s==
'\n')&&(*(
s+1)==
' '))
167 &&((par!=0) || (*e!=
')'))
171 else if (*e==
')') par--;
172 args_found=args_found || (*e>
' ');
180 if ((
int)strlen(argstr)+12 +(int)strlen(
s)>= argstrlen)
183 char *
a=(
char *)
omAlloc( argstrlen);
189 if(strncmp(
s,
"alias ",6)!=0)
191 strcat(argstr,
"parameter ");
225 long head =
pi->data.s.def_end -
pi->data.s.proc_start;
226 procbuflen =
pi->data.s.help_end -
pi->data.s.help_start;
240 s[procbuflen+
head+1] =
'\n';
241 s[procbuflen+
head+2] =
'\0';
243 for(
i=0;
i<=procbuflen+
head+2;
i++)
246 (
s[
i+1]==
'"' ||
s[
i+1]==
'{' ||
s[
i+1]==
'}' ||
s[
i+1]==
'\\'))
257 procbuflen =
pi->data.s.def_end -
pi->data.s.proc_start;
258 char *ss=(
char *)
omAlloc(procbuflen+2);
268 assume(
pi->data.s.body_end >
pi->data.s.body_start);
270 procbuflen =
pi->data.s.body_end -
pi->data.s.body_start;
271 pi->data.s.body = (
char *)
omAlloc( strlen(argstr)+procbuflen+15+
272 strlen(
pi->libname) );
277 strcpy(
pi->data.s.body,argstr);
278 myfread(
pi->data.s.body+strlen(argstr), procbuflen, 1,
fp);
280 procbuflen+=strlen(argstr);
283 pi->data.s.body[procbuflen] =
'\0';
284 strcat(
pi->data.s.body+procbuflen,
"\n;return();\n\n" );
285 strcat(
pi->data.s.body+procbuflen+13,
pi->libname);
286 s=(
char *)strchr(
pi->data.s.body,
'{');
292 if (
pi->data.s.example_lineno == 0)
297 procbuflen =
pi->data.s.proc_end -
pi->data.s.example_start - strlen(
buf);
302 s[procbuflen] =
'\0';
303 strcat(
s+procbuflen-3,
"\n;return();\n\n" );
304 p=(
char *)strchr(
s,
'{');
328 (
pi->libname!=
NULL) && (
pi->libname[0]!=
'\0'))
330 if ((
pi->libname!=
NULL) && (
pi->libname[0]!=
'\0'))
331 Warn(
"option changed in proc %s from %s",
pi->procname,
pi->libname);
333 Warn(
"option changed in proc %s",
pi->procname);
385 save_flags=
pi->trace_flag;
386 if(
pi->data.s.body==
NULL )
432 if (oh!=
NULL) o=oh->id;
438 Werror(
"ring change during procedure call %s: %s -> %s (level %d)",
pi->procname,o,n,
myynest);
465 pi->trace_flag=save_flags;
509 Werror(
"'%s::%s()' is a local procedure and cannot be accessed by an user.",
510 pi->libname,
pi->procname);
527 switch (
pi->language)
554 err = (
pi->data.o.function)(
res, sl);
578 if (!err)
Warn(
"too many arguments for %s",
IDID(pn));
624 WarnS(
"internal: lost ring in iiCallLib");
686 tmp.
rtyp=arg_types[0];
687 while(arg_types[
i]!=0)
691 tt->
rtyp=arg_types[
i];
728 printf(
"entering example (level %d)\n",
myynest);
740 printf(
"leaving -example- (level %d)\n",
myynest);
762 # define SI_GET_BUILTIN_MOD_INIT0(name) int SI_MOD_INIT0(name)(SModulFunctions*); 764 # undef SI_GET_BUILTIN_MOD_INIT0 771 # define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); } 773 # undef SI_GET_BUILTIN_MOD_INIT 786 char *libname = (
char *)
omAlloc(strlen(
id)+5);
787 const char *suffix[] = {
"",
".lib",
".so",
".sl",
NULL };
793 for(
i=0; suffix[
i] !=
NULL;
i++)
795 sprintf(libname,
"%s%s",
id, suffix[
i]);
800 #ifdef HAVE_DYNAMIC_LOADING 806 #ifdef HAVE_DYNAMIC_LOADING 837 strncpy(where,
IDPACKAGE(pl)->libname,127);
873 WarnS(
"not of type package.");
877 if (!force)
return FALSE;
893 if (root==
NULL)
return;
898 && (
pi->data.s.body_start == 0L))
919 idhdl h=
p->idroot->get(
"mod_init",0);
962 WerrorS(
"Cannot load library,... aborting.");
972 Warn(
"library %s has old format. This format is still accepted,", newlib);
973 Warn(
"but for functionality you may wish to change to the new");
974 Warn(
"format. Please refer to the manual for further information.");
989 ls = ls->
pop(newlib);
993 PrintS(
"--------------------\n");
996 Print(
"%s: LIB-stack:(%d), %s %s\n", newlib, ls->
cnt, ls->
get(),
999 PrintS(
"--------------------\n");
1010 const char *procname,
int,
long pos,
BOOLEAN pstatic)
1012 memset(
pi,0,
sizeof(*
pi));
1017 pi->is_static = pstatic;
1018 pi->data.s.proc_start = pos;
1031 if (
IsCmd(procname,dummy))
1033 Werror(
">>%s< is a reserved name",procname);
1045 Warn(
"extend `%s`",procname);
1063 pi->is_static = pstatic;
1064 pi->data.o.function = func;
1068 if(
pi->data.o.function == func)
1080 pi->is_static = pstatic;
1081 pi->data.o.function = func;
1085 Warn(
"internal error: unknown procedure type %d",
pi->language);
1090 WarnS(
"iiAddCproc: failed.");
1107 #ifdef HAVE_DYNAMIC_LOADING 1111 WerrorS(
"mod_init: static version can not load modules");
1126 memset(FullName,0,256);
1128 if( *fullname !=
'/' && *fullname !=
'.' )
1129 sprintf(FullName,
"./%s", newlib);
1130 else strncpy(FullName, fullname,255);
1133 if(
IsCmd(plib, token))
1135 Werror(
"'%s' is resered identifier\n", plib);
1136 goto load_modules_end;
1138 pl =
basePack->idroot->get(plib,0);
1164 Werror(
"%s not found", newlib);
1166 goto load_modules_end;
1180 int ver=(*fktn)(&sModulFunctions);
1187 Warn(
"loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,
MAX_TOK,ver);
1195 Werror(
"mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n",
dynl_error());
1221 pl =
basePack->idroot->get(plib,0);
1249 (*init)(&sModulFunctions);
1263 Werror(
">>%s<< is not a package (trying to add package help)",plib);
1278 Werror(
">>%s<< is not a package(trying to add help for %s)",plib,
p);
1285 strncpy(buff,
p,255);
1286 strncat(buff,
"_help",255-strlen(
p));
1294 #ifdef HAVE_DYNAMIC_LOADING 1302 if (!bin_dir) {
return NULL; }
1323 if(c>=97 && c<=(97+26)) c-=32;
1329 if(c>=65 && c<=(65+26)) c+=32;
1343 char *
p = strrchr(tmpname,
DIR_SEP);
1347 r = (
char *)strchr(
p,
'.');
1359 void piShowProcList()
1365 Print(
"%-15s %20s %s,%s %s,%s %s,%s\n",
"Library",
"function",
1366 "line",
"start",
"line",
"body",
"line",
"example");
1380 Print(
"%d %-15s %20s ",
proc->is_static ? 1 : 0,
proc->libname,
1383 Print(
"line %-5ld %4d,%-5ld %4d,%-5ld\n",
1384 proc->data.s.proc_start,
1385 proc->data.s.body_lineno,
proc->data.s.body_start,
1386 proc->data.s.example_lineno,
proc->data.s.example_start);
1388 PrintS(
"type: object\n");
1407 #ifdef HAVE_LIBPARSER 1413 for(lp =
this;lp!=
NULL;lp=lp->
next)
1415 if(strcmp(lp->
get(), libn)==0)
break;
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)
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
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 *)
char * iiGetLibName(procinfov pi)
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)