32 #define SI_MAX_NEST 500 33 #elif defined(__CYGWIN__) 34 #define SI_MAX_NEST 480 36 #define SI_MAX_NEST 1000 39 #if defined(ix86Mac_darwin) || defined(x86_64Mac_darwin) || defined(ppcMac_darwin) 40 # define MODULE_SUFFIX bundle 41 #elif defined(__CYGWIN__) 42 # define MODULE_SUFFIX dll 44 # define MODULE_SUFFIX so 47 #define MODULE_SUFFIX_STRING EXPANDED_STRINGIFY(MODULE_SUFFIX) 50 #ifdef HAVE_DYNAMIC_LOADING 58 const char *procname,
int line,
long pos,
BOOLEAN pstatic=
FALSE);
60 #define NS_LRING (procstack->cRing) 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 ");
226 procbuflen = pi->
data.s.help_end - pi->
data.s.help_start;
234 s = (
char *)
omAlloc(procbuflen+head+3);
238 myfread(s+head+1, procbuflen, 1, fp);
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]==
'\\'))
251 if(offset>0) s[i-
offset] = s[
i];
257 procbuflen = pi->
data.s.def_end - pi->
data.s.proc_start;
258 char *ss=(
char *)
omAlloc(procbuflen+2);
260 myfread( ss, procbuflen, 1, fp);
270 procbuflen = pi->
data.s.body_end - pi->
data.s.body_start;
271 pi->
data.s.body = (
char *)
omAlloc( strlen(argstr)+procbuflen+15+
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)
296 (void) fgets(buf,
sizeof(buf),
fp);
297 procbuflen = pi->
data.s.proc_end - pi->
data.s.example_start - strlen(buf);
300 s = (
char *)
omAlloc(procbuflen+14);
302 s[procbuflen] =
'\0';
303 strcat(s+procbuflen-3,
"\n;return();\n\n" );
304 p=(
char *)strchr(s,
'{');
413 memset(v,0,
sizeof(
sleftv));
431 #ifdef USE_IILOCALRING 445 if (oh!=
NULL) o=oh->id;
451 Werror(
"ring change during procedure call: %s -> %s (level %d)",o,n,myynest);
494 Werror(
"ring change during procedure call: %s -> %s (level %d)",o,n,myynest);
524 #ifdef USE_IILOCALRING 534 #ifdef USE_IILOCALRING 564 #ifdef USE_IILOCALRING 570 iiRETURNEXPR_len+=16;
579 Werror(
"'%s::%s()' is a local procedure and cannot be accessed by an user.",
584 #ifdef USE_IILOCALRING 626 err = (pi->
data.o.function)(res, sl);
627 memcpy(&iiRETURNEXPR,res,
sizeof(iiRETURNEXPR));
650 if (!err)
Warn(
"too many arguments for %s",
IDID(pn));
672 #ifdef USE_IILOCALRING 678 printf(
"entering example (level %d)\n",
myynest);
690 printf(
"leaving -example- (level %d)\n",
myynest);
692 #ifdef USE_IILOCALRING 731 # define SI_GET_BUILTIN_MOD_INIT0(name) int SI_MOD_INIT0(name)(SModulFunctions*); 733 # undef SI_GET_BUILTIN_MOD_INIT0 740 # define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); } 742 # undef SI_GET_BUILTIN_MOD_INIT 755 char *libname = (
char *)
omAlloc(strlen(
id)+5);
756 const char *suffix[] = {
"",
".lib",
".so",
".sl",
NULL };
762 for(i=0; suffix[
i] !=
NULL; i++)
764 sprintf(libname,
"%s%s",
id, suffix[i]);
769 #ifdef HAVE_DYNAMIC_LOADING 770 char libnamebuf[256];
775 #ifdef HAVE_DYNAMIC_LOADING 806 strncpy(where,
IDPACKAGE(pl)->libname,127);
822 FILE *
fp =
feFopen( newlib,
"r", libnamebuf, tellerror );
842 WarnS(
"not of type package.");
846 if (!force)
return FALSE;
848 LoadResult =
iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
862 if (root==
NULL)
return;
867 && (pi->
data.s.body_start == 0L))
888 idhdl h=p->idroot->get(
"mod_init",0);
918 yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
931 Werror(
"Cannot load library,... aborting.");
941 Warn(
"library %s has old format. This format is still accepted,", newlib);
942 Warn(
"but for functionality you may wish to change to the new");
943 Warn(
"format. Please refer to the manual for further information.");
952 for(ls = library_stack; (ls !=
NULL) && (ls != ls_start); )
958 ls = ls->
pop(newlib);
962 PrintS(
"--------------------\n");
963 for(ls = library_stack; ls !=
NULL; ls = ls->
next)
965 Print(
"%s: LIB-stack:(%d), %s %s\n", newlib, ls->
cnt, ls->
get(),
968 PrintS(
"--------------------\n");
972 if(fp !=
NULL) fclose(fp);
979 const char *procname,
int line,
long pos,
BOOLEAN pstatic)
987 pi->
data.s.proc_start = pos;
988 pi->
data.s.def_end = 0L;
989 pi->
data.s.help_start = 0L;
990 pi->
data.s.help_end = 0L;
991 pi->
data.s.body_start = 0L;
992 pi->
data.s.body_end = 0L;
993 pi->
data.s.example_start = 0L;
994 pi->
data.s.proc_lineno = line;
995 pi->
data.s.body_lineno = 0;
996 pi->
data.s.example_lineno = 0;
998 pi->
data.s.help_chksum = 0;
1011 if (
IsCmd(procname,dummy))
1013 Werror(
">>%s< is a reserved name",procname);
1027 pi->
data.o.function = func;
1032 PrintS(
"iiAddCproc: failed.\n");
1043 if (r) r=
iiAddCproc(libname,procname,pstatic,func);
1049 #ifdef HAVE_DYNAMIC_LOADING 1053 WerrorS(
"mod_init: static version can not load modules");
1068 memset(FullName,0,256);
1070 if( *fullname !=
'/' && *fullname !=
'.' )
1071 sprintf(FullName,
"./%s", newlib);
1072 else strncpy(FullName, fullname,255);
1075 if(
IsCmd(plib, token))
1077 Werror(
"'%s' is resered identifier\n", plib);
1078 goto load_modules_end;
1080 pl =
basePack->idroot->get(plib,0);
1093 Warn(
"not of type package.");
1094 goto load_modules_end;
1105 Werror(
"%s not found", newlib);
1107 goto load_modules_end;
1121 int ver=(*fktn)(&sModulFunctions);
1128 Warn(
"// ** loaded %s for a different version of Singular(expected: %d, got %d)",fullname,
MAX_TOK,ver);
1136 Werror(
"mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n",
dynl_error());
1162 pl =
IDROOT->get(plib,0);
1185 (*init)(&sModulFunctions);
1199 Werror(
">>%s<< is not a package (trying to add package help)",plib);
1214 Werror(
">>%s<< is not a package(trying to add help for %s)",plib,p);
1221 strncpy(buff,p,255);
1222 strncat(buff,
"_help",255-strlen(p));
1236 #if defined(HAVE_STATIC) || !defined(HAVE_DYNAMIC_LOADING) 1237 WerrorS(
"static version can not load function from dynamic modules");
1240 if (!bin_dir) {
return NULL; }
1251 result =
dynl_sym(openlib, funcname);
1262 if(c>=97 && c<=(97+26)) c-=32;
1268 if(c>=65 && c<=(65+26)) c+=32;
1282 char *p = strrchr(tmpname,
DIR_SEP);
1284 if(p==
NULL) p = tmpname;
1286 r = (
char *)strchr(p,
'.');
1287 if( r!=
NULL) *r =
'\0';
1298 void piShowProcList()
1304 Print(
"%-15s %20s %s,%s %s,%s %s,%s\n",
"Library",
"function",
1305 "line",
"start",
"line",
"body",
"line",
"example");
1322 Print(
"line %4d,%-5ld %4d,%-5ld %4d,%-5ld\n",
1323 proc->
data.s.proc_lineno, proc->
data.s.proc_start,
1324 proc->
data.s.body_lineno, proc->
data.s.body_start,
1325 proc->
data.s.example_lineno, proc->
data.s.example_start);
1327 Print(
"type: object\n");
1346 #ifdef HAVE_LIBPARSER 1352 for(lp =
this;lp!=
NULL;lp=lp->
next)
1354 if(strcmp(lp->
get(), libn)==0)
break;
1362 if(
this !=
NULL) ls->
cnt = this->cnt+1;
else ls->
cnt = 0;
1372 library_stack = ls->
next;
1374 return(library_stack);
char * iiProcArgs(char *e, BOOLEAN withParenth)
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
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)
procinfo * iiInitSingularProcinfo(procinfov pi, const char *libname, const char *procname, int line, long pos, BOOLEAN pstatic)
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()
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
void * dynl_sym(void *handle, const char *symbol)
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0)}
void WerrorS(const char *s)
void push(const char *p, char *libname)
struct soptionStruct optionStruct[]
libstackv pop(const char *p)
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
static void iiCheckNest()
void * dynl_open(char *filename)
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)
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
struct soptionStruct verboseStruct[]
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)
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)
idhdl rFindHdl(ring r, idhdl n)
#define MODULE_SUFFIX_STRING
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
SModulFunc_t iiGetBuiltinModInit(const char *libname)
void killhdl(idhdl h, package proot)
BOOLEAN iiPStart(idhdl pn, sleftv *v)
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))
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)