My Project
Loading...
Searching...
No Matches
iplib.cc File Reference
#include "kernel/mod2.h"
#include "Singular/tok.h"
#include "misc/options.h"
#include "Singular/ipid.h"
#include "polys/monomials/ring.h"
#include "Singular/subexpr.h"
#include "Singular/ipshell.h"
#include "Singular/fevoices.h"
#include "Singular/lists.h"
#include <ctype.h>
#include "libparse.h"
#include "Singular/mod_lib.h"
#include <map>
#include <string>
#include <pthread.h>

Go to the source code of this file.

Macros

#define SINGULAR_PATH_LENGTH   512
 
#define SI_MAX_NEST   500
 
#define MODULE_SUFFIX   so
 
#define MODULE_SUFFIX_STRING   EXPANDED_STRINGIFY(MODULE_SUFFIX)
 
#define SI_GET_BUILTIN_MOD_INIT0(name)
 
#define SI_GET_BUILTIN_MOD_INIT(name)
 

Functions

BOOLEAN load_modules (const char *newlib, char *fullname, BOOLEAN autoexport)
 
int iiArithAddCmd (const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
 
void yylprestart (FILE *input_file)
 
int current_pos (int i=0)
 
void print_init ()
 
static char mytolower (char c)
 
BOOLEAN iiGetLibStatus (const char *lib)
 
char * iiProcName (char *buf, char &ct, char *&e)
 
char * iiProcArgs (char *e, BOOLEAN withParenth)
 
char * iiGetLibProcBuffer (procinfo *pi, int part)
 
BOOLEAN iiAllStart (procinfov pi, const char *p, feBufferTypes t, int l)
 
BOOLEAN iiPStart (idhdl pn, leftv v)
 
static void iiShowLevRings ()
 
static void iiCheckNest ()
 
BOOLEAN iiMake_proc (idhdl pn, package pack, leftv args)
 
static void iiCallLibProcBegin ()
 
static void iiCallLibProcEnd (idhdl save_ringhdl, ring save_ring)
 
void * iiCallLibProc1 (const char *n, void *arg, int arg_type, BOOLEAN &err)
 
ideal ii_CallProcId2Id (const char *lib, const char *proc, ideal arg, const ring R)
 
int ii_CallProcId2Int (const char *lib, const char *proc, ideal arg, const ring R)
 
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
 
BOOLEAN iiEStart (char *example, procinfo *pi)
 
 SI_FOREACH_BUILTIN (SI_GET_BUILTIN_MOD_INIT0) }
 
int flint_mod_init (SModulFunctions *psModulFunctions)
 
SModulFunc_t iiGetBuiltinModInit (const char *libname)
 
BOOLEAN iiTryLoadLib (leftv v, const char *id)
 
BOOLEAN iiLocateLib (const char *lib, char *where)
 
BOOLEAN iiLibCmd (const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
 
static void iiCleanProcs (idhdl &root)
 
static void iiRunInit (package p)
 
BOOLEAN iiLoadLIB (FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
 
procinfoiiInitSingularProcinfo (procinfov pi, const char *libname, const char *procname, int, long pos, BOOLEAN pstatic)
 
int iiAddCproc (const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
 
int iiAddCprocTop (const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
 
bool registered_dyn_module (char *fullname)
 
void register_dyn_module (char *fullname, void *handle)
 
void close_all_dyn_modules ()
 
BOOLEAN load_modules_aux (const char *newlib, char *fullname, BOOLEAN autoexport)
 
BOOLEAN load_builtin (const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
 
void module_help_main (const char *newlib, const char *help)
 
void module_help_proc (const char *newlib, const char *p, const char *help)
 
void * binary_module_function (const char *newlib, const char *funcname)
 
static char mytoupper (char c)
 
char * iiConvName (const char *libname)
 

Variables

EXTERN_VAR int yylp_errno
 
EXTERN_VAR int yylplineno
 
const char * yylp_errlist []
 
VAR libstackv library_stack
 
VAR ring * iiLocalRing
 
INST_VAR sleftv iiRETURNEXPR
 
VAR int iiRETURNEXPR_len =0
 
THREAD_VAR std::map< std::string, void * > * dyn_modules
 

Macro Definition Documentation

◆ MODULE_SUFFIX

#define MODULE_SUFFIX   so

Definition at line 39 of file iplib.cc.

◆ MODULE_SUFFIX_STRING

#define MODULE_SUFFIX_STRING   EXPANDED_STRINGIFY(MODULE_SUFFIX)

Definition at line 42 of file iplib.cc.

◆ SI_GET_BUILTIN_MOD_INIT

#define SI_GET_BUILTIN_MOD_INIT ( name)
Value:
if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
#define SI_MOD_INIT0(name)
Definition mod_lib.h:4
int name
New type name for int.

◆ SI_GET_BUILTIN_MOD_INIT0

#define SI_GET_BUILTIN_MOD_INIT0 ( name)
Value:

Definition at line 808 of file iplib.cc.

◆ SI_MAX_NEST

#define SI_MAX_NEST   500

Definition at line 27 of file iplib.cc.

◆ SINGULAR_PATH_LENGTH

#define SINGULAR_PATH_LENGTH   512

Definition at line 21 of file iplib.cc.

Function Documentation

◆ binary_module_function()

void * binary_module_function ( const char * newlib,
const char * funcname )

Definition at line 1396 of file iplib.cc.

1397{
1398 void* result = NULL;
1399
1400 const char* bin_dir = feGetResource('b');
1401 if (!bin_dir) { return NULL; }
1402
1403 char path_name[MAXPATHLEN];
1404 snprintf(path_name,MAXPATHLEN, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING);
1405
1406 void* openlib = dynl_open(path_name);
1407 if(!openlib)
1408 {
1409 Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1410 return NULL;
1411 }
1412 result = dynl_sym(openlib, funcname);
1413 if (!result) Werror("%s: %s\n", funcname, dynl_error());
1414
1415 return result;
1416}
return result
char * feGetResource(const char id, int warn)
#define DIR_SEPP
Definition feResource.h:7
#define MODULE_SUFFIX_STRING
Definition iplib.cc:42
const char * dynl_error()
Definition mod_raw.cc:175
void * dynl_sym(void *handle, const char *symbol)
Definition mod_raw.cc:159
void * dynl_open(char *filename)
Definition mod_raw.cc:142
#define NULL
Definition omList.c:12
#define MAXPATHLEN
Definition omRet2Info.c:22
void Werror(const char *fmt,...)
Definition reporter.cc:189

◆ close_all_dyn_modules()

void close_all_dyn_modules ( )

Definition at line 1181 of file iplib.cc.

1181 {
1182 for (std::map<std::string, void *>::iterator it = dyn_modules->begin();
1183 it != dyn_modules->end();
1184 it++)
1185 {
1186 dynl_close(it->second);
1187 }
1188 delete dyn_modules;
1189 dyn_modules = NULL;
1190}
THREAD_VAR std::map< std::string, void * > * dyn_modules
Definition iplib.cc:1165
int dynl_close(void *handle)
Definition mod_raw.cc:170

◆ current_pos()

int current_pos ( int i = 0)

Definition at line 3346 of file libparse.cc.

3347{
3348 return(i+offset+(int)(yytext-yylp_buffer_start));
3349}
int i
Definition cfEzgcd.cc:132
STATIC_VAR int offset
Definition janet.cc:29
VAR char * yylp_buffer_start
Definition libparse.cc:1102
#define yytext
Definition libparse.cc:16

◆ flint_mod_init()

int flint_mod_init ( SModulFunctions * psModulFunctions)

Definition at line 1272 of file misc_ip.cc.

1273{
1274 package save=currPack;
1277 if (n_FlintQ!=n_unknown)
1278 {
1279 iiAddCproc("kernel","flintQp",FALSE,ii_FlintQ_init);
1281 }
1282#if __FLINT_RELEASE >= 20503
1283 iiAddCproc("kernel","flintQ",FALSE,ii_FlintQrat_init);
1285#endif
1287 if (n_FlintZn!=n_unknown)
1288 {
1289 iiAddCproc("kernel","flintZn",FALSE,ii_FlintZn_init);
1291 }
1292 currPack=save;
1293 return MAX_TOK;
1294}
#define FALSE
Definition auxiliary.h:97
@ n_unknown
Definition coeffs.h:28
BOOLEAN flintQ_InitChar(coeffs cf, void *infoStruct)
Definition flintcf_Q.cc:636
coeffs flintQInitCfByName(char *s, n_coeffType n)
Definition flintcf_Q.cc:608
BOOLEAN flintZn_InitChar(coeffs cf, void *infoStruct)
coeffs flintZnInitCfByName(char *s, n_coeffType n)
VAR package basePack
Definition ipid.cc:56
VAR package currPack
Definition ipid.cc:55
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition iplib.cc:1073
static BOOLEAN ii_FlintQ_init(leftv res, leftv a)
Definition misc_ip.cc:1227
STATIC_VAR n_coeffType n_FlintQ
Definition misc_ip.cc:1211
static BOOLEAN ii_FlintZn_init(leftv res, leftv a)
Definition misc_ip.cc:1213
STATIC_VAR n_coeffType n_FlintZn
Definition misc_ip.cc:1210
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
Definition numbers.cc:624
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition numbers.cc:583
@ MAX_TOK
Definition tok.h:220

◆ ii_CallLibProcM()

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 at line 710 of file iplib.cc.

711{
712 idhdl h=ggetid(n);
713 if ((h==NULL)
714 || (IDTYP(h)!=PROC_CMD))
715 {
716 err=2;
717 return NULL;
718 }
719 // ring handling
720 idhdl save_ringhdl=currRingHdl;
721 ring save_ring=currRing;
724 // argument:
725 if (arg_types[0]!=0)
726 {
727 sleftv tmp;
728 leftv tt=&tmp;
729 int i=1;
730 tmp.Init();
731 tmp.data=args[0];
732 tmp.rtyp=arg_types[0];
733 while(arg_types[i]!=0)
734 {
736 tt=tt->next;
737 tt->rtyp=arg_types[i];
738 tt->data=args[i];
739 i++;
740 }
741 // call proc
742 err=iiMake_proc(h,currPack,&tmp);
743 }
744 else
745 // call proc
747 // clean up ring
748 iiCallLibProcEnd(save_ringhdl,save_ring);
749 // return
750 if (err==FALSE)
751 {
753 memcpy(h,&iiRETURNEXPR,sizeof(sleftv));
754 iiRETURNEXPR.Init();
755 return h;
756 }
757 return NULL;
758}
Class used for (list of) interpreter objects.
Definition subexpr.h:83
int rtyp
Definition subexpr.h:91
void Init()
Definition subexpr.h:107
leftv next
Definition subexpr.h:86
void * data
Definition subexpr.h:88
@ PROC_CMD
Definition grammar.cc:281
idhdl ggetid(const char *n)
Definition ipid.cc:558
VAR idhdl currRingHdl
Definition ipid.cc:57
EXTERN_VAR omBin sleftv_bin
Definition ipid.h:145
#define IDTYP(a)
Definition ipid.h:119
static void iiCallLibProcEnd(idhdl save_ringhdl, ring save_ring)
Definition iplib.cc:615
BOOLEAN iiMake_proc(idhdl pn, package pack, leftv args)
Definition iplib.cc:513
INST_VAR sleftv iiRETURNEXPR
Definition iplib.cc:483
static void iiCallLibProcBegin()
Definition iplib.cc:598
STATIC_VAR Poly * h
Definition janet.cc:971
#define omAllocBin(bin)
#define omAlloc0Bin(bin)
void rChangeCurrRing(ring r)
Definition polys.cc:16
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
idrec * idhdl
Definition ring.h:22
#define R
Definition sirandom.c:27
sleftv * leftv
Definition structs.h:53

◆ ii_CallProcId2Id()

ideal ii_CallProcId2Id ( const char * lib,
const char * proc,
ideal arg,
const ring R )

Definition at line 670 of file iplib.cc.

671{
672 char *plib = iiConvName(lib);
673 idhdl h=ggetid(plib);
674 omFreeBinAddr(plib);
675 if (h==NULL)
676 {
678 if (bo) return NULL;
679 }
680 ring oldR=currRing;
682 BOOLEAN err;
683 ideal I=(ideal)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
684 rChangeCurrRing(oldR);
685 if (err) return NULL;
686 return I;
687}
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
unsigned char * proc[NUM_PROC]
Definition checklibs.c:16
@ IDEAL_CMD
Definition grammar.cc:285
ideal idCopy(ideal A)
Definition ideals.h:60
char * iiConvName(const char *libname)
Definition iplib.cc:1439
BOOLEAN iiLibCmd(const char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition iplib.cc:894
void * iiCallLibProc1(const char *n, void *arg, int arg_type, BOOLEAN &err)
Definition iplib.cc:636
#define omFreeBinAddr(addr)

◆ ii_CallProcId2Int()

int ii_CallProcId2Int ( const char * lib,
const char * proc,
ideal arg,
const ring R )

Definition at line 689 of file iplib.cc.

690{
691 char *plib = iiConvName(lib);
692 idhdl h=ggetid(plib);
693 omFreeBinAddr(plib);
694 if (h==NULL)
695 {
697 if (bo) return 0;
698 }
699 BOOLEAN err;
700 ring oldR=currRing;
702 int I=(int)(long)iiCallLibProc1(proc,idCopy(arg),IDEAL_CMD,err);
703 rChangeCurrRing(oldR);
704 if (err) return 0;
705 return I;
706}

◆ iiAddCproc()

int iiAddCproc ( const char * libname,
const char * procname,
BOOLEAN pstatic,
BOOLEAN(* func )(leftv res, leftv v) )

Definition at line 1073 of file iplib.cc.

1075{
1076 procinfov pi;
1077 idhdl h;
1078
1079 #ifndef SING_NDEBUG
1080 int dummy;
1081 if (IsCmd(procname,dummy))
1082 {
1083 Werror(">>%s< is a reserved name",procname);
1084 return 0;
1085 }
1086 #endif
1087
1088 h=IDROOT->get(procname,0);
1089 if ((h!=NULL)
1090 && (IDTYP(h)==PROC_CMD))
1091 {
1092 pi = IDPROC(h);
1093 #if 0
1094 if ((pi->language == LANG_SINGULAR)
1095 &&(BVERBOSE(V_REDEFINE)))
1096 Warn("extend `%s`",procname);
1097 #endif
1098 }
1099 else
1100 {
1101 h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
1102 }
1103 if ( h!= NULL )
1104 {
1105 pi = IDPROC(h);
1106 if((pi->language == LANG_SINGULAR)
1107 ||(pi->language == LANG_NONE))
1108 {
1109 omfree(pi->libname);
1110 pi->libname = omStrDup(libname);
1111 omfree(pi->procname);
1112 pi->procname = omStrDup(procname);
1113 pi->language = LANG_C;
1114 pi->ref = 1;
1115 pi->is_static = pstatic;
1116 pi->data.o.function = func;
1117 }
1118 else if(pi->language == LANG_C)
1119 {
1120 if(pi->data.o.function == func)
1121 {
1122 pi->ref++;
1123 }
1124 else
1125 {
1126 omfree(pi->libname);
1127 pi->libname = omStrDup(libname);
1128 omfree(pi->procname);
1129 pi->procname = omStrDup(procname);
1130 pi->language = LANG_C;
1131 pi->ref = 1;
1132 pi->is_static = pstatic;
1133 pi->data.o.function = func;
1134 }
1135 }
1136 else
1137 Warn("internal error: unknown procedure type %d",pi->language);
1138 if (currPack->language==LANG_SINGULAR) currPack->language=LANG_MIX;
1139 return(1);
1140 }
1141 else
1142 {
1143 WarnS("iiAddCproc: failed.");
1144 }
1145 return(0);
1146}
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
int IsCmd(const char *n, int &tok)
Definition iparith.cc:9738
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition ipid.cc:256
#define IDPROC(a)
Definition ipid.h:140
#define IDROOT
Definition ipid.h:19
#define pi
Definition libparse.cc:1145
#define omStrDup(s)
#define omfree(addr)
#define BVERBOSE(a)
Definition options.h:35
#define V_REDEFINE
Definition options.h:45
procinfo * procinfov
Definition structs.h:56
@ LANG_SINGULAR
Definition subexpr.h:22
@ LANG_NONE
Definition subexpr.h:22
@ LANG_MIX
Definition subexpr.h:22
@ LANG_C
Definition subexpr.h:22

◆ iiAddCprocTop()

int iiAddCprocTop ( const char * libname,
const char * procname,
BOOLEAN pstatic,
BOOLEAN(* func )(leftv res, leftv v) )

Definition at line 1148 of file iplib.cc.

1150{
1151 int r=iiAddCproc(libname,procname,pstatic,func);
1152 package s=currPack;
1154 if (r) r=iiAddCproc(libname,procname,pstatic,func);
1155 currPack=s;
1156 return r;
1157}
const CanonicalForm int s
Definition facAbsFact.cc:51

◆ iiAllStart()

BOOLEAN iiAllStart ( procinfov pi,
const char * p,
feBufferTypes t,
int l )

Definition at line 306 of file iplib.cc.

307{
308 int save_trace=traceit;
309 int restore_traceit=0;
310 if (traceit_stop
312 {
314 traceit_stop=0;
315 restore_traceit=1;
316 }
317 // see below:
318 BITSET save1=si_opt_1;
319 BITSET save2=si_opt_2;
320 newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/,
321 pi, l );
322 BOOLEAN err=yyparse();
323
324 if (sLastPrinted.rtyp!=0)
325 {
326 sLastPrinted.CleanUp();
327 }
328
329 if (restore_traceit) traceit=save_trace;
330
331 // the access to optionStruct and verboseStruct do not work
332 // on x86_64-Linux for pic-code
333 if ((TEST_V_ALLWARN) &&
334 (t==BT_proc) &&
335 ((save1!=si_opt_1)||(save2!=si_opt_2)) &&
336 (pi->libname!=NULL) && (pi->libname[0]!='\0'))
337 {
338 if ((pi->libname!=NULL) && (pi->libname[0]!='\0'))
339 Warn("option changed in proc %s from %s",pi->procname,pi->libname);
340 else
341 Warn("option changed in proc %s",pi->procname);
342 int i;
343 for (i=0; optionStruct[i].setval!=0; i++)
344 {
345 if ((optionStruct[i].setval & si_opt_1)
346 && (!(optionStruct[i].setval & save1)))
347 {
348 Print(" +%s",optionStruct[i].name);
349 }
350 if (!(optionStruct[i].setval & si_opt_1)
351 && ((optionStruct[i].setval & save1)))
352 {
353 Print(" -%s",optionStruct[i].name);
354 }
355 }
356 for (i=0; verboseStruct[i].setval!=0; i++)
357 {
358 if ((verboseStruct[i].setval & si_opt_2)
359 && (!(verboseStruct[i].setval & save2)))
360 {
361 Print(" +%s",verboseStruct[i].name);
362 }
363 if (!(verboseStruct[i].setval & si_opt_2)
364 && ((verboseStruct[i].setval & save2)))
365 {
366 Print(" -%s",verboseStruct[i].name);
367 }
368 }
369 PrintLn();
370 }
371 return err;
372}
#define BITSET
Definition auxiliary.h:85
int l
Definition cfEzgcd.cc:100
int p
Definition cfModGcd.cc:4086
#define Print
Definition emacs.cc:80
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition fevoices.cc:166
@ BT_proc
Definition fevoices.h:20
int yyparse(void)
Definition grammar.cc:2149
const struct soptionStruct verboseStruct[]
Definition misc_ip.cc:539
const struct soptionStruct optionStruct[]
Definition misc_ip.cc:508
VAR unsigned si_opt_2
Definition options.c:6
VAR unsigned si_opt_1
Definition options.c:5
#define TEST_V_ALLWARN
Definition options.h:145
void PrintLn()
Definition reporter.cc:310
#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
INST_VAR sleftv sLastPrinted
Definition subexpr.cc:46

◆ iiArithAddCmd()

int iiArithAddCmd ( const char * szName,
short nAlias,
short nTokval,
short nToktype,
short nPos )
extern

Definition at line 10083 of file iparith.cc.

10090{
10091 //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
10092 // nTokval, nToktype, nPos);
10093 if(nPos>=0)
10094 {
10095 // no checks: we rely on a correct generated code in iparith.inc
10096 assume((unsigned)nPos < sArithBase.nCmdAllocated);
10097 assume(szName!=NULL);
10098 sArithBase.sCmds[nPos].name = omStrDup(szName);
10099 sArithBase.sCmds[nPos].alias = nAlias;
10100 sArithBase.sCmds[nPos].tokval = nTokval;
10101 sArithBase.sCmds[nPos].toktype = nToktype;
10102 sArithBase.nCmdUsed++;
10103 //if(nTokval>0) sArithBase.nLastIdentifier++;
10104 }
10105 else
10106 {
10107 if(szName==NULL) return -1;
10108 int nIndex = iiArithFindCmd(szName);
10109 if(nIndex>=0)
10110 {
10111 Print("'%s' already exists at %d\n", szName, nIndex);
10112 return -1;
10113 }
10114
10115 if(sArithBase.nCmdUsed>=sArithBase.nCmdAllocated)
10116 {
10117 /* needs to create new slots */
10118 unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
10119 sArithBase.sCmds = (cmdnames *)omRealloc(sArithBase.sCmds, nSize);
10120 if(sArithBase.sCmds==NULL) return -1;
10121 sArithBase.nCmdAllocated++;
10122 }
10123 /* still free slots available */
10124 sArithBase.sCmds[sArithBase.nCmdUsed].name = omStrDup(szName);
10125 sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias;
10126 sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval;
10127 sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
10128 sArithBase.nCmdUsed++;
10129
10130 qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
10132 for(sArithBase.nLastIdentifier=sArithBase.nCmdUsed-1;
10133 sArithBase.nLastIdentifier>0; sArithBase.nLastIdentifier--)
10134 {
10135 if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
10136 }
10137 //Print("L=%d\n", sArithBase.nLastIdentifier);
10138 }
10139 return 0;
10140}
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition gentable.cc:191
int iiArithFindCmd(const char *szName)
Definition iparith.cc:9988
STATIC_VAR SArithBase sArithBase
Base entry for arithmetic.
Definition iparith.cc:197
#define assume(x)
Definition mod2.h:389
#define nSize(n)
Definition numbers.h:39
#define omRealloc(addr, size)

◆ iiCallLibProc1()

void * iiCallLibProc1 ( const char * n,
void * arg,
int arg_type,
BOOLEAN & err )

Definition at line 636 of file iplib.cc.

637{
638 idhdl h=ggetid(n);
639 if ((h==NULL)
640 || (IDTYP(h)!=PROC_CMD))
641 {
642 err=2;
643 return NULL;
644 }
645 // ring handling
646 idhdl save_ringhdl=currRingHdl;
647 ring save_ring=currRing;
649 // argument:
650 sleftv tmp;
651 tmp.Init();
652 tmp.data=arg;
653 tmp.rtyp=arg_type;
654 // call proc
655 err=iiMake_proc(h,currPack,&tmp);
656 // clean up ring
657 iiCallLibProcEnd(save_ringhdl,save_ring);
658 // return
659 if (err==FALSE)
660 {
661 void*r=iiRETURNEXPR.data;
662 iiRETURNEXPR.data=NULL;
663 iiRETURNEXPR.CleanUp();
664 return r;
665 }
666 return NULL;
667}

◆ iiCallLibProcBegin()

static void iiCallLibProcBegin ( )
static

Definition at line 598 of file iplib.cc.

599{
600 idhdl tmp_ring=NULL;
601 if (currRing!=NULL)
602 {
604 {
605 // clean up things depending on currRingHdl:
607 sLastPrinted.Init();
608 }
609 // need to define a ring-hdl for currRingHdl
610 tmp_ring=enterid(" tmpRing",myynest,RING_CMD,&IDROOT,FALSE);
611 IDRING(tmp_ring)=rIncRefCnt(currRing);
612 rSetHdl(tmp_ring);
613 }
614}
VAR int myynest
Definition febase.cc:41
@ RING_CMD
Definition grammar.cc:282
#define IDRING(a)
Definition ipid.h:127
void rSetHdl(idhdl h)
Definition ipshell.cc:5122
static ring rIncRefCnt(ring r)
Definition ring.h:849

◆ iiCallLibProcEnd()

static void iiCallLibProcEnd ( idhdl save_ringhdl,
ring save_ring )
static

Definition at line 615 of file iplib.cc.

616{
617 if ((currRing!=NULL)
618 &&(currRing!=save_ring))
619 {
620 idhdl hh=IDROOT;
621 idhdl prev=NULL;
622 while((hh!=currRingHdl) && (hh!=NULL)) { prev=hh; hh=hh->next; }
623 if ((hh!=NULL)&&(strcmp(IDID(hh)," tmpRing")==0))
624 {
626 if (prev==NULL) IDROOT=hh->next;
627 else prev->next=hh->next;
628 omFree((ADDRESS)IDID(hh));
630 }
631 }
632 currRingHdl=save_ringhdl;
633 currRing=save_ring;
634}
void * ADDRESS
Definition auxiliary.h:120
idhdl next
Definition idrec.h:38
VAR omBin idrec_bin
Definition ipid.cc:48
#define IDID(a)
Definition ipid.h:122
#define omFree(addr)
#define omFreeBin(addr, bin)
static void rDecRefCnt(ring r)
Definition ring.h:850

◆ iiCheckNest()

static void iiCheckNest ( )
static

Definition at line 502 of file iplib.cc.

503{
504 if (myynest >= iiRETURNEXPR_len-1)
505 {
507 iiRETURNEXPR_len*sizeof(ring),
508 (iiRETURNEXPR_len+16)*sizeof(ring));
509 memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
511 }
512}
VAR int iiRETURNEXPR_len
Definition iplib.cc:484
VAR ring * iiLocalRing
Definition iplib.cc:482
#define omreallocSize(addr, o_size, size)

◆ iiCleanProcs()

static void iiCleanProcs ( idhdl & root)
static

Definition at line 938 of file iplib.cc.

939{
940 idhdl prev=NULL;
941 loop
942 {
943 if (root==NULL) return;
944 if (IDTYP(root)==PROC_CMD)
945 {
946 procinfo *pi=(procinfo*)IDDATA(root);
947 if ((pi->language == LANG_SINGULAR)
948 && (pi->data.s.body_start == 0L))
949 {
950 // procinfo data incorrect:
951 // - no proc body can start at the beginning of the file
952 killhdl(root);
953 if (prev==NULL)
954 root=IDROOT;
955 else
956 {
957 root=prev;
958 prev=NULL;
959 }
960 continue;
961 }
962 }
963 prev=root;
964 root=IDNEXT(root);
965 }
966}
void killhdl(idhdl h, package proot)
Definition ipid.cc:391
#define IDNEXT(a)
Definition ipid.h:118
#define IDDATA(a)
Definition ipid.h:126
#define loop
Definition structs.h:71

◆ iiConvName()

char * iiConvName ( const char * libname)

Definition at line 1439 of file iplib.cc.

1440{
1441 char *tmpname = omStrDup(libname);
1442 char *p = strrchr(tmpname, DIR_SEP);
1443 char *r;
1444 if(p==NULL) p = tmpname; else p++;
1445 // p is now the start of the file name (without path)
1446 r=p;
1447 while(isalnum(*r)||(*r=='_')) r++;
1448 // r point the the end of the main part of the filename
1449 *r = '\0';
1450 r = omStrDup(p);
1451 *r = mytoupper(*r);
1452 // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1453 omFree((ADDRESS)tmpname);
1454
1455 return(r);
1456}
#define DIR_SEP
Definition feResource.h:6
static char mytoupper(char c)
Definition iplib.cc:1420

◆ iiEStart()

BOOLEAN iiEStart ( char * example,
procinfo * pi )

Definition at line 763 of file iplib.cc.

764{
765 BOOLEAN err;
766 int old_echo=si_echo;
767
768 iiCheckNest();
769 procstack->push(example);
772 {
773 if (traceit&TRACE_SHOW_LINENO) printf("\n");
774 printf("entering example (level %d)\n",myynest);
775 }
776 myynest++;
777
778 err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
779
781 myynest--;
782 si_echo=old_echo;
784 {
785 if (traceit&TRACE_SHOW_LINENO) printf("\n");
786 printf("leaving -example- (level %d)\n",myynest);
787 }
789 {
791 {
794 }
795 else
796 {
799 }
800 }
801 procstack->pop();
802 return err;
803}
VAR int si_echo
Definition febase.cc:35
@ BT_example
Definition fevoices.h:21
VAR proclevel * procstack
Definition ipid.cc:50
static void iiCheckNest()
Definition iplib.cc:502
BOOLEAN iiAllStart(procinfov pi, const char *p, feBufferTypes t, int l)
Definition iplib.cc:306
void killlocals(int v)
Definition ipshell.cc:387
idhdl rFindHdl(ring r, idhdl n)
Definition ipshell.cc:1695
#define TRACE_SHOW_LINENO
Definition reporter.h:31
#define TRACE_SHOW_PROC
Definition reporter.h:29

◆ iiGetBuiltinModInit()

SModulFunc_t iiGetBuiltinModInit ( const char * libname)

Definition at line 816 of file iplib.cc.

817{
818#ifdef HAVE_FLINT
819 if (strcmp(libname,"flint.so")==0) return SI_MOD_INIT0(flint);
820#endif
821# define SI_GET_BUILTIN_MOD_INIT(name) if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }
823# undef SI_GET_BUILTIN_MOD_INIT
824
825 return NULL;
826}
#define SI_GET_BUILTIN_MOD_INIT(name)
#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

◆ iiGetLibProcBuffer()

char * iiGetLibProcBuffer ( procinfo * pi,
int part )

Definition at line 197 of file iplib.cc.

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 int res=fseek(fp, pi->data.s.proc_start, SEEK_SET);
209 if (res==1) return NULL;
210 if(part==0)
211 { // load help string
212 int i, offset=0;
213 long head = pi->data.s.def_end - pi->data.s.proc_start;
214 procbuflen = pi->data.s.help_end - pi->data.s.help_start;
215 if (procbuflen<5)
216 {
217 fclose(fp);
218 return NULL; // help part does not exist
219 }
220 //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start,
221 // pi->data.s.proc_start, procbuflen);
222 s = (char *)omAlloc(procbuflen+head+3);
223 res=myfread(s, head, 1, fp);
224 if (res<=0) /* error*/ { omFree(s); return NULL; }
225 s[head] = '\n';
226 int res=fseek(fp, pi->data.s.help_start, SEEK_SET);
227 if (res==-1) /*error*/ { omFree(s); return NULL; }
228 res=myfread(s+head+1, procbuflen, 1, fp);
229 if (res<=0) /* error*/ { omFree(s); return NULL; }
230 fclose(fp);
231 s[procbuflen+head+1] = '\n';
232 s[procbuflen+head+2] = '\0';
233 offset=0;
234 for(i=0;i<=procbuflen+head+2; i++)
235 {
236 if(s[i]=='\\' &&
237 (s[i+1]=='"' || s[i+1]=='{' || s[i+1]=='}' || s[i+1]=='\\'))
238 {
239 i++;
240 offset++;
241 }
242 if(offset>0) s[i-offset] = s[i];
243 }
244 return(s);
245 }
246 else if(part==1)
247 { // load proc part - must exist
248 procbuflen = pi->data.s.def_end - pi->data.s.proc_start;
249 char *ss=(char *)omAlloc(procbuflen+2);
250 //fgets(buf, sizeof(buf), fp);
251 myfread( ss, procbuflen, 1, fp);
252 char ct;
253 char *e;
254 s=iiProcName(ss,ct,e);
255 char *argstr=NULL;
256 *e=ct;
257 argstr=iiProcArgs(e,TRUE);
258
259 assume(pi->data.s.body_end > pi->data.s.body_start);
260
261 procbuflen = pi->data.s.body_end - pi->data.s.body_start;
262 pi->data.s.body = (char *)omAlloc( strlen(argstr)+procbuflen+15+
263 strlen(pi->libname) );
264 //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end,
265 // pi->data.s.body_start, procbuflen);
266 assume(pi->data.s.body != NULL);
267 fseek(fp, pi->data.s.body_start, SEEK_SET);
268 strcpy(pi->data.s.body,argstr);
269 myfread( pi->data.s.body+strlen(argstr), procbuflen, 1, fp);
270 fclose( fp );
271 procbuflen+=strlen(argstr);
272 omFree(argstr);
273 omFree(ss);
274 pi->data.s.body[procbuflen] = '\0';
275 strcat( pi->data.s.body+procbuflen, "\n;return();\n\n" );
276 strcat( pi->data.s.body+procbuflen+13,pi->libname);
277 s=(char *)strchr(pi->data.s.body,'{');
278 if (s!=NULL) *s=' ';
279 return NULL;
280 }
281 else if(part==2)
282 { // example
283 if ( pi->data.s.example_lineno == 0)
284 return NULL; // example part does not exist
285 // load example
286 fseek(fp, pi->data.s.example_start, SEEK_SET);
287 char* res=fgets(buf, sizeof(buf), fp); // skip line with "example"
288 if (res==NULL) /*error or eof*/
289 {
290 return omStrDup("");
291 }
292 procbuflen = pi->data.s.proc_end - pi->data.s.example_start - strlen(buf);
293 //Print("Example=%ld-%ld=%d\n", pi->data.s.proc_end,
294 // pi->data.s.example_start, procbuflen);
295 s = (char *)omAlloc(procbuflen+14);
296 myfread(s, procbuflen, 1, fp);
297 s[procbuflen] = '\0';
298 strcat(s+procbuflen-3, "\n;return();\n\n" );
299 p=(char *)strchr(s,'{');
300 if (p!=NULL) *p=' ';
301 return(s);
302 }
303 return NULL;
304}
CanonicalForm head(const CanonicalForm &f)
CanonicalForm fp
Definition cfModGcd.cc:4110
CanonicalForm res
Definition facAbsFact.cc:60
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition feFopen.cc:47
size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition feFopen.cc:195
char * iiProcName(char *buf, char &ct, char *&e)
Definition iplib.cc:100
char * iiProcArgs(char *e, BOOLEAN withParenth)
Definition iplib.cc:114
#define SINGULAR_PATH_LENGTH
Definition iplib.cc:21
#define SEEK_SET
Definition mod2.h:115
#define omAlloc(size)
int status int void * buf
Definition si_signals.h:69

◆ iiGetLibStatus()

BOOLEAN iiGetLibStatus ( const char * lib)

Definition at line 77 of file iplib.cc.

78{
79 idhdl hl;
80
81 char *plib = iiConvName(lib);
82 hl = basePack->idroot->get(plib,0);
83 omFreeBinAddr(plib);
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}
#define IDPACKAGE(a)
Definition ipid.h:139
@ PACKAGE_CMD
Definition tok.h:150

◆ iiInitSingularProcinfo()

procinfo * iiInitSingularProcinfo ( procinfov pi,
const char * libname,
const char * procname,
int ,
long pos,
BOOLEAN pstatic )

Definition at line 1059 of file iplib.cc.

1061{
1062 memset(pi,0,sizeof(*pi));
1063 pi->libname = omStrDup(libname);
1064 pi->procname = omStrDup(procname);
1065 pi->language = LANG_SINGULAR;
1066 pi->ref = 1;
1067 pi->is_static = pstatic;
1068 pi->data.s.proc_start = pos;
1069 return(pi);
1070}

◆ iiLibCmd()

BOOLEAN iiLibCmd ( const char * newlib,
BOOLEAN autoexport,
BOOLEAN tellerror,
BOOLEAN force )

Definition at line 894 of file iplib.cc.

895{
896 if (strcmp(newlib,"Singular")==0) return FALSE;
897 char libnamebuf[1024];
898 idhdl pl;
899 char *plib = iiConvName(newlib);
900 FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror );
901 // int lines = 1;
902 BOOLEAN LoadResult = TRUE;
903
904 if (fp==NULL)
905 {
906 return TRUE;
907 }
908 pl = basePack->idroot->get(plib,0);
909 if (pl==NULL)
910 {
911 pl = enterid( plib,0, PACKAGE_CMD,
912 &(basePack->idroot), TRUE );
913 IDPACKAGE(pl)->language = LANG_SINGULAR;
914 IDPACKAGE(pl)->libname=omStrDup(newlib);
915 }
916 else
917 {
918 if(IDTYP(pl)!=PACKAGE_CMD)
919 {
920 omFreeBinAddr(plib);
921 WarnS("not of type package.");
922 fclose(fp);
923 return TRUE;
924 }
925 if (!force)
926 {
927 omFreeBinAddr(plib);
928 return FALSE;
929 }
930 }
931 LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
932
933 if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
934 omFree((ADDRESS)plib);
935 return LoadResult;
936}
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
Definition iplib.cc:983
VAR char libnamebuf[1024]
Definition libparse.cc:1098

◆ iiLoadLIB()

BOOLEAN iiLoadLIB ( FILE * fp,
const char * libnamebuf,
const char * newlib,
idhdl pl,
BOOLEAN autoexport,
BOOLEAN tellerror )

Definition at line 983 of file iplib.cc.

985{
986 EXTERN_VAR FILE *yylpin;
987 libstackv ls_start = library_stack;
988 lib_style_types lib_style;
989
990 yylpin = fp;
991 #if YYLPDEBUG > 1
992 print_init();
993 #endif
996 else lpverbose=0;
997 // yylplex sets also text_buffer
998 if (text_buffer!=NULL) *text_buffer='\0';
999 yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
1000 if(yylp_errno)
1001 {
1002 Werror("Library %s: ERROR occurred: in line %d, %d.", newlib, yylplineno,
1003 current_pos(0));
1005 {
1009 }
1010 else
1012 WerrorS("Cannot load library,... aborting.");
1013 reinit_yylp();
1014 fclose( yylpin );
1016 return TRUE;
1017 }
1018 if (BVERBOSE(V_LOAD_LIB))
1019 Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
1020 if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
1021 {
1022 Warn( "library %s has old format. This format is still accepted,", newlib);
1023 WarnS( "but for functionality you may wish to change to the new");
1024 WarnS( "format. Please refer to the manual for further information.");
1025 }
1026 reinit_yylp();
1027 fclose( yylpin );
1028 fp = NULL;
1029 iiRunInit(IDPACKAGE(pl));
1030
1031 {
1032 libstackv ls;
1033 for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
1034 {
1035 if(ls->to_be_done)
1036 {
1037 ls->to_be_done=FALSE;
1038 iiLibCmd(ls->get(),autoexport,tellerror,FALSE);
1039 ls = ls->pop(newlib);
1040 }
1041 }
1042#if 0
1043 PrintS("--------------------\n");
1044 for(ls = library_stack; ls != NULL; ls = ls->next)
1045 {
1046 Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
1047 ls->to_be_done ? "not loaded" : "loaded");
1048 }
1049 PrintS("--------------------\n");
1050#endif
1051 }
1052
1053 if(fp != NULL) fclose(fp);
1054 return FALSE;
1055}
char * get()
Definition subexpr.h:170
libstackv next
Definition subexpr.h:164
libstackv pop(const char *p)
Definition iplib.cc:1531
int cnt
Definition subexpr.h:167
BOOLEAN to_be_done
Definition subexpr.h:166
void WerrorS(const char *s)
Definition feFopen.cc:24
#define EXTERN_VAR
Definition globaldefs.h:6
int current_pos(int i=0)
Definition libparse.cc:3346
void print_init()
Definition libparse.cc:3482
static void iiCleanProcs(idhdl &root)
Definition iplib.cc:938
VAR libstackv library_stack
Definition iplib.cc:68
const char * yylp_errlist[]
Definition libparse.cc:1114
EXTERN_VAR int yylplineno
Definition iplib.cc:65
static void iiRunInit(package p)
Definition iplib.cc:967
EXTERN_VAR int yylp_errno
Definition iplib.cc:64
void reinit_yylp()
Definition libparse.cc:3376
VAR char * text_buffer
Definition libparse.cc:1099
VAR int lpverbose
Definition libparse.cc:1106
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 V_DEBUG_LIB
Definition options.h:48
#define V_LOAD_LIB
Definition options.h:47
void PrintS(const char *s)
Definition reporter.cc:284
libstack * libstackv
Definition subexpr.h:159

◆ iiLocateLib()

BOOLEAN iiLocateLib ( const char * lib,
char * where )

Definition at line 880 of file iplib.cc.

881{
882 char *plib = iiConvName(lib);
883 idhdl pl = basePack->idroot->get(plib,0);
884 if( (pl!=NULL) && (IDTYP(pl)==PACKAGE_CMD) &&
885 (IDPACKAGE(pl)->language == LANG_SINGULAR))
886 {
887 strncpy(where,IDPACKAGE(pl)->libname,127);
888 return TRUE;
889 }
890 else
891 return FALSE;;
892}

◆ iiMake_proc()

BOOLEAN iiMake_proc ( idhdl pn,
package pack,
leftv args )

Definition at line 513 of file iplib.cc.

514{
515 int err;
516 procinfov pi = IDPROC(pn);
517 if(pi->is_static && myynest==0)
518 {
519 Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
520 pi->libname, pi->procname);
521 return TRUE;
522 }
523 iiCheckNest();
525 //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
526 iiRETURNEXPR.Init();
527 procstack->push(pi->procname);
529 || (pi->trace_flag&TRACE_SHOW_PROC))
530 {
532 Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
533 }
534#ifdef RDEBUG
536#endif
537 switch (pi->language)
538 {
539 default:
540 case LANG_NONE:
541 WerrorS("undefined proc");
542 err=TRUE;
543 break;
544
545 case LANG_SINGULAR:
546 if ((pi->pack!=NULL)&&(currPack!=pi->pack))
547 {
548 currPack=pi->pack;
551 //Print("set pack=%s\n",IDID(currPackHdl));
552 }
553 else if ((pack!=NULL)&&(currPack!=pack))
554 {
555 currPack=pack;
558 //Print("set pack=%s\n",IDID(currPackHdl));
559 }
560 err=iiPStart(pn,args);
561 break;
562 case LANG_C:
564 err = (pi->data.o.function)(res, args);
565 memcpy(&iiRETURNEXPR,res,sizeof(iiRETURNEXPR));
567 break;
568 }
570 || (pi->trace_flag&TRACE_SHOW_PROC))
571 {
573 Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
574 }
575 //const char *n="NULL";
576 //if (currRingHdl!=NULL) n=IDID(currRingHdl);
577 //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
578#ifdef RDEBUG
580#endif
581 if (err)
582 {
583 iiRETURNEXPR.CleanUp();
584 //iiRETURNEXPR.Init(); //done by CleanUp
585 }
586 if (iiCurrArgs!=NULL)
587 {
588 if (!err) Warn("too many arguments for %s",IDID(pn));
589 iiCurrArgs->CleanUp();
592 }
593 procstack->pop();
594 if (err)
595 return TRUE;
596 return FALSE;
597}
VAR idhdl currPackHdl
Definition ipid.cc:53
idhdl packFindHdl(package r)
Definition ipid.cc:808
static void iiShowLevRings()
Definition iplib.cc:487
BOOLEAN iiPStart(idhdl pn, leftv v)
Definition iplib.cc:379
void iiCheckPack(package &p)
Definition ipshell.cc:1625
VAR leftv iiCurrArgs
Definition ipshell.cc:81
#define TRACE_SHOW_RINGS
Definition reporter.h:36

◆ iiProcArgs()

char * iiProcArgs ( char * e,
BOOLEAN withParenth )

Definition at line 114 of file iplib.cc.

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 }
130 BOOLEAN in_args;
131 BOOLEAN args_found;
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 {
139 args_found=FALSE;
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);
172 omFree((ADDRESS)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}

◆ iiProcName()

char * iiProcName ( char * buf,
char & ct,
char *& e )

Definition at line 100 of file iplib.cc.

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}

◆ iiPStart()

BOOLEAN iiPStart ( idhdl pn,
leftv v )

Definition at line 379 of file iplib.cc.

380{
382 int old_echo=si_echo;
383 BOOLEAN err=FALSE;
384 char save_flags=0;
385
386 /* init febase ======================================== */
387 /* we do not enter this case if filename != NULL !! */
388 if (pn!=NULL)
389 {
390 pi = IDPROC(pn);
391 if(pi!=NULL)
392 {
393 save_flags=pi->trace_flag;
394 if( pi->data.s.body==NULL )
395 {
397 if (pi->data.s.body==NULL) return TRUE;
398 }
399// omUpdateInfo();
400// int m=om_Info.UsedBytes;
401// Print("proc %s, mem=%d\n",IDID(pn),m);
402 }
403 }
404 else return TRUE;
405 /* generate argument list ======================================*/
406 //iiCurrArgs should be NULL here, as the assignment for the parameters
407 // of the prevouis call are already done befor calling another routine
408 if (v!=NULL)
409 {
411 memcpy(iiCurrArgs,v,sizeof(sleftv)); // keeps track of v->next etc.
412 v->Init();
413 }
414 else
415 {
418 }
419 /* start interpreter ======================================*/
420 myynest++;
421 if (myynest > SI_MAX_NEST)
422 {
423 WerrorS("nesting too deep");
424 err=TRUE;
425 }
426 else
427 {
428 iiCurrProc=pn;
429 err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
431
432 if (iiLocalRing[myynest-1] != currRing)
433 {
434 if (iiRETURNEXPR.RingDependend())
435 {
436 //idhdl hn;
437 const char *n;
438 const char *o;
439 idhdl nh=NULL, oh=NULL;
440 if (iiLocalRing[myynest-1]!=NULL)
442 if (oh!=NULL) o=oh->id;
443 else o="none";
444 if (currRing!=NULL)
446 if (nh!=NULL) n=nh->id;
447 else n="none";
448 Werror("ring change during procedure call %s: %s -> %s (level %d)",pi->procname,o,n,myynest);
449 iiRETURNEXPR.CleanUp();
450 err=TRUE;
451 }
453 }
454 if ((currRing==NULL)
455 && (currRingHdl!=NULL))
457 else
458 if ((currRing!=NULL) &&
460 ||(IDLEV(currRingHdl)>=myynest-1)))
461 {
464 }
465 //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
467#ifndef SING_NDEBUG
468 checkall();
469#endif
470 //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
471 }
472 myynest--;
473 si_echo=old_echo;
474 if (pi!=NULL)
475 pi->trace_flag=save_flags;
476// omUpdateInfo();
477// int m=om_Info.UsedBytes;
478// Print("exit %s, mem=%d\n",IDID(pn),m);
479 return err;
480}
const char * id
Definition idrec.h:39
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
#define IDLEV(a)
Definition ipid.h:121
#define SI_MAX_NEST
Definition iplib.cc:27
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition iplib.cc:197
VAR idhdl iiCurrProc
Definition ipshell.cc:82

◆ iiRunInit()

static void iiRunInit ( package p)
static

Definition at line 967 of file iplib.cc.

968{
969 idhdl h=p->idroot->get("mod_init",0);
970 if (h==NULL) return;
971 if (IDTYP(h)==PROC_CMD)
972 {
973 int save=yylineno;
974 myynest++;
975 // procinfo *pi=(procinfo*)IDDATA(h);
976 //PrintS("mod_init found\n");
978 myynest--;
979 yylineno=save;
980 }
981}
VAR int yylineno
Definition febase.cc:40

◆ iiShowLevRings()

static void iiShowLevRings ( )
static

Definition at line 487 of file iplib.cc.

488{
489 int i;
490 for (i=0;i<=myynest;i++)
491 {
492 Print("lev %d:",i);
493 if (iiLocalRing[i]==NULL) PrintS("NULL");
494 else Print("%lx",(long)iiLocalRing[i]);
495 PrintLn();
496 }
497 if (currRing==NULL) PrintS("curr:NULL\n");
498 else Print ("curr:%lx\n",(long)currRing);
499}

◆ iiTryLoadLib()

BOOLEAN iiTryLoadLib ( leftv v,
const char * id )

Definition at line 832 of file iplib.cc.

833{
834 BOOLEAN LoadResult = TRUE;
835 char libnamebuf[1024];
836 size_t len=strlen(id)+5;
837 char *libname = (char *)omAlloc(len);
838 const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
839 int i = 0;
840 // FILE *fp;
841 // package pack;
842 // idhdl packhdl;
843 lib_types LT;
844 for(i=0; suffix[i] != NULL; i++)
845 {
846 snprintf(libname,len, "%s%s", id, suffix[i]);
847 *libname = mytolower(*libname);
848 if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
849 {
850 #ifdef HAVE_DYNAMIC_LOADING
851 char libnamebuf[1024];
852 #endif
853
854 if (LT==LT_SINGULAR)
855 LoadResult = iiLibCmd(libname, FALSE, FALSE,TRUE);
856 #ifdef HAVE_DYNAMIC_LOADING
857 else if ((LT==LT_ELF) || (LT==LT_HPUX))
858 LoadResult = load_modules(libname,libnamebuf,FALSE);
859 #endif
860 else if (LT==LT_BUILTIN)
861 {
862 LoadResult=load_builtin(libname,FALSE, iiGetBuiltinModInit(libname));
863 }
864 if(!LoadResult )
865 {
866 v->name = iiConvName(libname);
867 break;
868 }
869 }
870 }
871 omFree(libname);
872 return LoadResult;
873}
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1294
static char mytolower(char c)
Definition iplib.cc:1426
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
Definition iplib.cc:1304
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition iplib.cc:816
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
Definition mod_lib.cc:27
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

◆ load_builtin()

BOOLEAN load_builtin ( const char * newlib,
BOOLEAN autoexport,
SModulFunc_t init )

Definition at line 1304 of file iplib.cc.

1305{
1306 int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1307 BOOLEAN(*func)(leftv res, leftv v));
1308/*
1309 typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1310 BOOLEAN pstatic,
1311 BOOLEAN(*func)(leftv res, leftv v)));
1312*/
1313 // SModulFunc_t fktn;
1314 idhdl pl;
1315 char *plib = iiConvName(newlib);
1316 // BOOLEAN RET=TRUE;
1317 // int token;
1318
1319 pl = basePack->idroot->get(plib,0); // search PACKAGE only in Top
1320 if ((pl!=NULL)
1321 &&(IDTYP(pl)==PACKAGE_CMD))
1322 {
1323 if(IDPACKAGE(pl)->language==LANG_C)
1324 {
1325 if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1326 omFreeBinAddr(plib);
1327 return FALSE;
1328 }
1329 }
1330 else
1331 {
1332 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1333 IDPACKAGE(pl)->libname=omStrDup(newlib);
1334 }
1335 omFreeBinAddr(plib);
1336 IDPACKAGE(pl)->language = LANG_C;
1337
1338 IDPACKAGE(pl)->handle=(void *)NULL;
1339 SModulFunctions sModulFunctions;
1340
1341 package s=currPack;
1342 currPack=IDPACKAGE(pl);
1343 if( init!= NULL)
1344 {
1345 sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1346 if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1347 else sModulFunctions.iiAddCproc = iiAddCproc;
1348 (*init)(&sModulFunctions);
1349 }
1350 if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1351 currPack->loaded=1;
1352 currPack=s;
1353
1354 return FALSE;
1355}
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos=-1)
Definition iparith.cc:10083
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition ipid.h:72
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition ipid.h:70
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition iplib.cc:1148

◆ load_modules()

BOOLEAN load_modules ( const char * newlib,
char * fullname,
BOOLEAN autoexport )

Definition at line 1294 of file iplib.cc.

1295{
1296 GLOBAL_VAR static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
1297 pthread_mutex_lock(&mutex);
1298 BOOLEAN r = load_modules_aux(newlib, fullname, autoexport);
1299 pthread_mutex_unlock(&mutex);
1300 return r;
1301}
#define GLOBAL_VAR
Definition globaldefs.h:11
BOOLEAN load_modules_aux(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition iplib.cc:1191

◆ load_modules_aux()

BOOLEAN load_modules_aux ( const char * newlib,
char * fullname,
BOOLEAN autoexport )

Definition at line 1191 of file iplib.cc.

1192{
1193/*
1194 typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1195 BOOLEAN pstatic,
1196 BOOLEAN(*func)(leftv res, leftv v)));
1197*/
1198 SModulFunc_t fktn;
1199 idhdl pl;
1200 char *plib = iiConvName(newlib);
1201 BOOLEAN RET=TRUE;
1202 int token;
1203 int l=si_max((int)strlen(fullname),(int)strlen(newlib))+3;
1204 char *FullName=(char*)omAlloc0(l);
1205
1206 if( *fullname != '/' && *fullname != '.' )
1207 snprintf(FullName,l, "./%s", newlib);
1208 else strncpy(FullName, fullname,l);
1209
1210
1211 if(IsCmd(plib, token))
1212 {
1213 Werror("'%s' is resered identifier\n", plib);
1214 goto load_modules_end;
1215 }
1216 pl = basePack->idroot->get(plib,0); /* packages only in top level
1217 (see enterid) */
1218 if ((pl!=NULL)
1219 &&(IDTYP(pl)==PACKAGE_CMD))
1220 {
1221 if(IDPACKAGE(pl)->language==LANG_C)
1222 {
1223 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as package", newlib);
1224 omFreeBinAddr(plib);
1225 return FALSE;
1226 }
1227 else if(IDPACKAGE(pl)->language==LANG_MIX)
1228 {
1229 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s contain binary parts, cannot load", newlib);
1230 omFreeBinAddr(plib);
1231 return FALSE;
1232 }
1233 }
1234 else
1235 {
1236 pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1237 omFreeBinAddr(plib); /* enterid copied plib*/
1238 IDPACKAGE(pl)->libname=omStrDup(newlib);
1239 }
1240 IDPACKAGE(pl)->language = LANG_C;
1241 if (dynl_check_opened(FullName))
1242 {
1243 if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
1244 omFreeSize(FullName,l);
1245 return FALSE;
1246 }
1247 if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1248 {
1249 Werror("dynl_open failed:%s", dynl_error());
1250 Werror("%s not found", newlib);
1251 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1252 goto load_modules_end;
1253 }
1254 else
1255 {
1256 SModulFunctions sModulFunctions;
1257
1258 package s=currPack;
1259 currPack=IDPACKAGE(pl);
1260 fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1261 if( fktn!= NULL)
1262 {
1263 sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1264 if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1265 else sModulFunctions.iiAddCproc = iiAddCproc;
1266 int ver=(*fktn)(&sModulFunctions);
1267 if (ver==MAX_TOK)
1268 {
1269 if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1270 }
1271 else
1272 {
1273 Warn("loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,MAX_TOK,ver);
1274 }
1275 currPack->loaded=1;
1276 currPack=s; /* reset currPack to previous */
1277 register_dyn_module(fullname, IDPACKAGE(pl)->handle);
1278 RET=FALSE;
1279 }
1280 else
1281 {
1282 Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1283 errorreported=0;
1284 if(IDPACKAGE(pl)->idroot==NULL)
1285 killhdl2(pl,&(basePack->idroot),NULL); // remove package
1286 }
1287 }
1288
1289 load_modules_end:
1290 omFreeSize(FullName,l);
1291 return RET;
1292}
static int si_max(const int a, const int b)
Definition auxiliary.h:125
VAR short errorreported
Definition feFopen.cc:23
void killhdl2(idhdl h, idhdl *ih, ring r)
Definition ipid.cc:422
int(* SModulFunc_t)(SModulFunctions *)
Definition ipid.h:81
void register_dyn_module(char *fullname, void *handle)
Definition iplib.cc:1174
int dynl_check_opened(char *filename)
Definition mod_raw.cc:135
#define omFreeSize(addr, size)
#define omAlloc0(size)

◆ module_help_main()

void module_help_main ( const char * newlib,
const char * help )

Definition at line 1357 of file iplib.cc.

1358{
1359 char *plib = iiConvName(newlib);
1360 idhdl pl = basePack->idroot->get(plib,0);
1361 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1362 Werror(">>%s<< is not a package (trying to add package help)",plib);
1363 else
1364 {
1365 package s=currPack;
1366 currPack=IDPACKAGE(pl);
1367 idhdl h=enterid("info",0,STRING_CMD,&IDROOT,FALSE);
1369 currPack=s;
1370 }
1371}
#define IDSTRING(a)
Definition ipid.h:136
#define help
Definition libparse.cc:1230
@ STRING_CMD
Definition tok.h:187

◆ module_help_proc()

void module_help_proc ( const char * newlib,
const char * p,
const char * help )

Definition at line 1372 of file iplib.cc.

1373{
1374 char *plib = iiConvName(newlib);
1375 idhdl pl = basePack->idroot->get(plib,0);
1376 if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1377 Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1378 else
1379 {
1380 package s=currPack;
1381 currPack=IDPACKAGE(pl);
1382 char buff[SINGULAR_PATH_LENGTH];
1383 buff[SINGULAR_PATH_LENGTH-1]='\0';
1384 strncpy(buff,p,SINGULAR_PATH_LENGTH-1);
1385 strncat(buff,"_help",SINGULAR_PATH_LENGTH-1-strlen(p));
1388 currPack=s;
1389 }
1390}

◆ mytolower()

static char mytolower ( char c)
static

Definition at line 1426 of file iplib.cc.

1427{
1428 if(c>=65 && c<=(65+26)) c+=32;
1429 return(c);
1430}

◆ mytoupper()

static char mytoupper ( char c)
static

Definition at line 1420 of file iplib.cc.

1421{
1422 if(c>=97 && c<=(97+26)) c-=32;
1423 return(c);
1424}

◆ print_init()

void print_init ( )

Definition at line 3482 of file libparse.cc.

3483{
3484 printf("Init=%d\n", yy_init);
3485}
STATIC_VAR int yy_init
Definition libparse.cc:240

◆ register_dyn_module()

void register_dyn_module ( char * fullname,
void * handle )

Definition at line 1174 of file iplib.cc.

1174 {
1175 std::string fname = fullname;
1176 if (dyn_modules == NULL)
1177 dyn_modules = new std::map<std::string, void *>();
1178 dyn_modules->insert(std::pair<std::string, void *>(fname, handle));
1179}

◆ registered_dyn_module()

bool registered_dyn_module ( char * fullname)

Definition at line 1167 of file iplib.cc.

1167 {
1168 if (dyn_modules == NULL)
1169 return false;
1170 std::string fname = fullname;
1171 return dyn_modules->count(fname) != 0;
1172}

◆ SI_FOREACH_BUILTIN()

SI_FOREACH_BUILTIN ( SI_GET_BUILTIN_MOD_INIT0 )

◆ yylprestart()

void yylprestart ( FILE * input_file)

Variable Documentation

◆ dyn_modules

THREAD_VAR std::map<std::string, void *>* dyn_modules

Definition at line 1165 of file iplib.cc.

◆ iiLocalRing

VAR ring* iiLocalRing

Definition at line 482 of file iplib.cc.

◆ iiRETURNEXPR

INST_VAR sleftv iiRETURNEXPR

Definition at line 483 of file iplib.cc.

◆ iiRETURNEXPR_len

VAR int iiRETURNEXPR_len =0

Definition at line 484 of file iplib.cc.

◆ library_stack

VAR libstackv library_stack

Definition at line 68 of file iplib.cc.

◆ yylp_errlist

const char* yylp_errlist[]
extern

Definition at line 1114 of file libparse.cc.

1114 {
1115 "",
1116 "missing close bracket ')' for proc definition in line %d.", /* 1 */
1117 "missing close bracket ')' for procbody in line %d.", /* 2 */
1118 "missing close bracket ']' for procbody in line %d.", /* 3 */
1119 "too many ')' closed brackets in line %d.", /* 4 */
1120 "too many ']' closed brackets in line %d.", /* 5 */
1121 "missing close bracket ')' for example in line %d.", /* 6 */
1122 "missing close bracket ']' for example in line %d.", /* 7 */
1123 "cannot assign character '%c' in line %d to any group.", /* 8 */
1124 "there must be a quote missing somewhere before line %d.", /* 9 */
1125 "missing close bracket '}' at end of library in line %d.", /* 10 */
1126 "missing close bracket ')' at end of library in line %d.", /* 11 */
1127 "missing close bracket ']' at end of library in line %d.", /* 12 */
1128 NULL
1129};

◆ yylp_errno

EXTERN_VAR int yylp_errno

Definition at line 64 of file iplib.cc.

◆ yylplineno

EXTERN_VAR int yylplineno

Definition at line 65 of file iplib.cc.