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 ");
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,
'{');
402 memset(v,0,
sizeof(
sleftv));
430 if (oh!=
NULL) o=oh->id;
436 Werror(
"ring change during procedure call: %s -> %s (level %d)",o,n,
myynest);
498 iiRETURNEXPR_len+=16;
507 Werror(
"'%s::%s()' is a local procedure and cannot be accessed by an user.",
552 err = (pi->
data.o.function)(res, sl);
553 memcpy(&iiRETURNEXPR,res,
sizeof(iiRETURNEXPR));
576 if (!err)
Warn(
"too many arguments for %s",
IDID(pn));
602 printf(
"entering example (level %d)\n",
myynest);
614 printf(
"leaving -example- (level %d)\n",
myynest);
636 # define SI_GET_BUILTIN_MOD_INIT0(name) int SI_MOD_INIT0(name)(SModulFunctions*); 638 # undef SI_GET_BUILTIN_MOD_INIT0 645 # define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); } 647 # undef SI_GET_BUILTIN_MOD_INIT 660 char *libname = (
char *)
omAlloc(strlen(
id)+5);
661 const char *suffix[] = {
"",
".lib",
".so",
".sl",
NULL };
667 for(i=0; suffix[
i] !=
NULL; i++)
669 sprintf(libname,
"%s%s",
id, suffix[i]);
674 #ifdef HAVE_DYNAMIC_LOADING 675 char libnamebuf[256];
680 #ifdef HAVE_DYNAMIC_LOADING 711 strncpy(where,
IDPACKAGE(pl)->libname,127);
727 FILE *
fp =
feFopen( newlib,
"r", libnamebuf, tellerror );
747 WarnS(
"not of type package.");
751 if (!force)
return FALSE;
753 LoadResult =
iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
767 if (root==
NULL)
return;
772 && (pi->
data.s.body_start == 0L))
793 idhdl h=p->idroot->get(
"mod_init",0);
823 yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
836 WerrorS(
"Cannot load library,... aborting.");
846 Warn(
"library %s has old format. This format is still accepted,", newlib);
847 Warn(
"but for functionality you may wish to change to the new");
848 Warn(
"format. Please refer to the manual for further information.");
857 for(ls = library_stack; (ls !=
NULL) && (ls != ls_start); )
863 ls = ls->
pop(newlib);
867 PrintS(
"--------------------\n");
868 for(ls = library_stack; ls !=
NULL; ls = ls->
next)
870 Print(
"%s: LIB-stack:(%d), %s %s\n", newlib, ls->
cnt, ls->
get(),
873 PrintS(
"--------------------\n");
877 if(fp !=
NULL) fclose(fp);
884 const char *procname,
int line,
long pos,
BOOLEAN pstatic)
892 pi->
data.s.proc_start = pos;
893 pi->
data.s.def_end = 0L;
894 pi->
data.s.help_start = 0L;
895 pi->
data.s.help_end = 0L;
896 pi->
data.s.body_start = 0L;
897 pi->
data.s.body_end = 0L;
898 pi->
data.s.example_start = 0L;
899 pi->
data.s.proc_lineno = line;
900 pi->
data.s.body_lineno = 0;
901 pi->
data.s.example_lineno = 0;
903 pi->
data.s.help_chksum = 0;
916 if (
IsCmd(procname,dummy))
918 Werror(
">>%s< is a reserved name",procname);
932 pi->
data.o.function = func;
937 PrintS(
"iiAddCproc: failed.\n");
948 if (r) r=
iiAddCproc(libname,procname,pstatic,func);
954 #ifdef HAVE_DYNAMIC_LOADING 958 WerrorS(
"mod_init: static version can not load modules");
973 memset(FullName,0,256);
975 if( *fullname !=
'/' && *fullname !=
'.' )
976 sprintf(FullName,
"./%s", newlib);
977 else strncpy(FullName, fullname,255);
980 if(
IsCmd(plib, token))
982 Werror(
"'%s' is resered identifier\n", plib);
983 goto load_modules_end;
998 Warn(
"not of type package.");
999 goto load_modules_end;
1010 Werror(
"%s not found", newlib);
1012 goto load_modules_end;
1026 int ver=(*fktn)(&sModulFunctions);
1033 Warn(
"loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,
MAX_TOK,ver);
1041 Werror(
"mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n",
dynl_error());
1067 pl =
IDROOT->get(plib,0);
1090 (*init)(&sModulFunctions);
1104 Werror(
">>%s<< is not a package (trying to add package help)",plib);
1119 Werror(
">>%s<< is not a package(trying to add help for %s)",plib,p);
1126 strncpy(buff,p,255);
1127 strncat(buff,
"_help",255-strlen(p));
1141 #if defined(HAVE_STATIC) || !defined(HAVE_DYNAMIC_LOADING) 1142 WerrorS(
"static version can not load function from dynamic modules");
1145 if (!bin_dir) {
return NULL; }
1156 result =
dynl_sym(openlib, funcname);
1167 if(c>=97 && c<=(97+26)) c-=32;
1173 if(c>=65 && c<=(65+26)) c+=32;
1187 char *p = strrchr(tmpname,
DIR_SEP);
1189 if(p==
NULL) p = tmpname;
1191 r = (
char *)strchr(p,
'.');
1192 if( r!=
NULL) *r =
'\0';
1203 void piShowProcList()
1209 Print(
"%-15s %20s %s,%s %s,%s %s,%s\n",
"Library",
"function",
1210 "line",
"start",
"line",
"body",
"line",
"example");
1227 Print(
"line %4d,%-5ld %4d,%-5ld %4d,%-5ld\n",
1228 proc->
data.s.proc_lineno, proc->
data.s.proc_start,
1229 proc->
data.s.body_lineno, proc->
data.s.body_start,
1230 proc->
data.s.example_lineno, proc->
data.s.example_start);
1232 PrintS(
"type: object\n");
1251 #ifdef HAVE_LIBPARSER 1257 for(lp =
this;lp!=
NULL;lp=lp->
next)
1259 if(strcmp(lp->
get(), libn)==0)
break;
1267 if(
this !=
NULL) ls->
cnt = this->cnt+1;
else ls->
cnt = 0;
1277 library_stack = ls->
next;
1279 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
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)
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)
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)
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)
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
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))
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)