Macros | Functions | Variables
iplib.cc File Reference
#include <kernel/mod2.h>
#include <Singular/tok.h>
#include <misc/options.h>
#include <Singular/ipid.h>
#include <omalloc/omalloc.h>
#include <polys/monomials/ring.h>
#include <Singular/subexpr.h>
#include <Singular/ipshell.h>
#include <Singular/fevoices.h>
#include <Singular/lists.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include "libparse.h"
#include <Singular/mod_lib.h>

Go to the source code of this file.

Macros

#define SI_MAX_NEST   500
 
#define MODULE_SUFFIX   so
 
#define MODULE_SUFFIX_STRING   EXPANDED_STRINGIFY(MODULE_SUFFIX)
 
#define SI_GET_BUILTIN_MOD_INIT0(name)   int SI_MOD_INIT0(name)(SModulFunctions*);
 
#define SI_GET_BUILTIN_MOD_INIT(name)   if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(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 ()
 
char mytolower (char c)
 
BOOLEAN iiGetLibStatus (char *lib)
 
char * iiGetLibName (procinfov pi)
 
char * iiProcName (char *buf, char &ct, char *&e)
 
char * iiProcArgs (char *e, BOOLEAN withParenth)
 
char * iiGetLibProcBuffer (procinfo *pi, int part)
 
BOOLEAN iiAllStart (procinfov pi, char *p, feBufferTypes t, int l)
 
BOOLEAN iiPStart (idhdl pn, sleftv *v)
 
static void iiShowLevRings ()
 
static void iiCheckNest ()
 
BOOLEAN iiMake_proc (idhdl pn, package pack, sleftv *sl)
 
BOOLEAN iiEStart (char *example, procinfo *pi)
 
 SI_FOREACH_BUILTIN (SI_GET_BUILTIN_MOD_INIT0) }
 
SModulFunc_t iiGetBuiltinModInit (const char *libname)
 
BOOLEAN iiTryLoadLib (leftv v, const char *id)
 
BOOLEAN iiLocateLib (const char *lib, char *where)
 
BOOLEAN iiLibCmd (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))
 
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)
 
char mytoupper (char c)
 
char * iiConvName (const char *libname)
 

Variables

int yylp_errno
 
int yylplineno
 
char * yylp_errlist []
 
libstackv library_stack
 
ring * iiLocalRing
 
sleftv iiRETURNEXPR
 
int iiRETURNEXPR_len =0
 

Macro Definition Documentation

§ MODULE_SUFFIX

#define MODULE_SUFFIX   so

Definition at line 45 of file iplib.cc.

§ MODULE_SUFFIX_STRING

#define MODULE_SUFFIX_STRING   EXPANDED_STRINGIFY(MODULE_SUFFIX)

Definition at line 48 of file iplib.cc.

§ SI_GET_BUILTIN_MOD_INIT

#define SI_GET_BUILTIN_MOD_INIT (   name)    if (strcmp(libname, #name ".so") == 0){ return SI_MOD_INIT0(name); }

§ SI_GET_BUILTIN_MOD_INIT0

#define SI_GET_BUILTIN_MOD_INIT0 (   name)    int SI_MOD_INIT0(name)(SModulFunctions*);

Definition at line 636 of file iplib.cc.

§ SI_MAX_NEST

#define SI_MAX_NEST   500

Definition at line 33 of file iplib.cc.

Function Documentation

§ binary_module_function()

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

Definition at line 1147 of file iplib.cc.

1148 {
1149  void* result = NULL;
1150 
1151  const char* bin_dir = feGetResource('b');
1152  if (!bin_dir) { return NULL; }
1153 
1154  char path_name[MAXPATHLEN];
1155  sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING);
1156 
1157  void* openlib = dynl_open(path_name);
1158  if(!openlib)
1159  {
1160  Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1161  return NULL;
1162  }
1163  result = dynl_sym(openlib, funcname);
1164  if (!result) Werror("%s: %s\n", funcname, dynl_error());
1165 
1166  return result;
1167 }
#define MAXPATHLEN
Definition: omRet2Info.c:22
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:167
void * dynl_open(char *filename)
Definition: mod_raw.cc:153
char * feGetResource(const char id, int warn)
Definition: feResource.cc:155
#define DIR_SEPP
Definition: feResource.h:7
#define MODULE_SUFFIX_STRING
Definition: iplib.cc:48
#define NULL
Definition: omList.c:10
void Werror(const char *fmt,...)
Definition: reporter.cc:189
return result
Definition: facAbsBiFact.cc:76
const char * dynl_error()
Definition: mod_raw.cc:183

§ current_pos()

int current_pos ( int  i = 0)

Definition at line 3344 of file libparse.cc.

3345 {
3346  return(i+offset+(int)(yytext-yylp_buffer_start));
3347 }
#define yytext
Definition: libparse.cc:16
int i
Definition: cfEzgcd.cc:123
char * yylp_buffer_start
Definition: libparse.cc:1100
int offset
Definition: libparse.cc:1091

§ iiAddCproc()

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

Definition at line 897 of file iplib.cc.

899 {
900  procinfov pi;
901  idhdl h;
902 
903  #ifndef SING_NDEBUG
904  int dummy;
905  if (IsCmd(procname,dummy))
906  {
907  Werror(">>%s< is a reserved name",procname);
908  return 0;
909  }
910  #endif
911 
912  h=IDROOT->get(procname,0);
913  if ((h!=NULL)
914  && (IDTYP(h)==PROC_CMD))
915  {
916  pi = IDPROC(h);
917  if ((pi->language == LANG_SINGULAR)
918  &&(BVERBOSE(V_REDEFINE)))
919  Warn("extend `%s`",procname);
920  }
921  else
922  {
923  h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
924  }
925  if ( h!= NULL )
926  {
927  pi = IDPROC(h);
928  omfree(pi->libname);
929  pi->libname = omStrDup(libname);
930  omfree(pi->procname);
931  pi->procname = omStrDup(procname);
932  pi->language = LANG_C;
933  pi->ref = 1;
934  pi->is_static = pstatic;
935  pi->data.o.function = func;
936  return(1);
937  }
938  else
939  {
940  WarnS("iiAddCproc: failed.");
941  }
942  return(0);
943 }
language_defs language
Definition: subexpr.h:58
#define IDROOT
Definition: ipid.h:20
#define TRUE
Definition: auxiliary.h:99
short ref
Definition: subexpr.h:59
#define WarnS
Definition: emacs.cc:81
Definition: idrec.h:34
char * procname
Definition: subexpr.h:56
Definition: subexpr.h:21
#define IDTYP(a)
Definition: ipid.h:116
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:261
char * libname
Definition: subexpr.h:55
#define omfree(addr)
Definition: omAllocDecl.h:237
procinfodata data
Definition: subexpr.h:62
#define BVERBOSE(a)
Definition: options.h:33
char is_static
Definition: subexpr.h:60
#define IDPROC(a)
Definition: ipid.h:137
#define pi
Definition: libparse.cc:1143
#define NULL
Definition: omList.c:10
static Poly * h
Definition: janet.cc:978
#define V_REDEFINE
Definition: options.h:43
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:8688
#define Warn
Definition: emacs.cc:80
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ iiAddCprocTop()

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

Definition at line 945 of file iplib.cc.

947 {
948  int r=iiAddCproc(libname,procname,pstatic,func);
949  package s=currPack;
951  if (r) r=iiAddCproc(libname,procname,pstatic,func);
952  currPack=s;
953  return r;
954 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const ring r
Definition: syzextra.cc:208
package basePack
Definition: ipid.cc:64
package currPack
Definition: ipid.cc:63
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:897

§ iiAllStart()

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

Definition at line 311 of file iplib.cc.

312 {
313  // see below:
314  BITSET save1=si_opt_1;
315  BITSET save2=si_opt_2;
316  newBuffer( omStrDup(p /*pi->data.s.body*/), t /*BT_proc*/,
317  pi, l );
318  BOOLEAN err=yyparse();
319  if (sLastPrinted.rtyp!=0)
320  {
322  }
323  // the access to optionStruct and verboseStruct do not work
324  // on x86_64-Linux for pic-code
325  if ((TEST_V_ALLWARN) &&
326  (t==BT_proc) &&
327  ((save1!=si_opt_1)||(save2!=si_opt_2)) &&
328  (pi->libname!=NULL) && (pi->libname[0]!='\0'))
329  {
330  if ((pi->libname!=NULL) && (pi->libname[0]!='\0'))
331  Warn("option changed in proc %s from %s",pi->procname,pi->libname);
332  else
333  Warn("option changed in proc %s",pi->procname);
334  int i;
335  for (i=0; optionStruct[i].setval!=0; i++)
336  {
337  if ((optionStruct[i].setval & si_opt_1)
338  && (!(optionStruct[i].setval & save1)))
339  {
340  Print(" +%s",optionStruct[i].name);
341  }
342  if (!(optionStruct[i].setval & si_opt_1)
343  && ((optionStruct[i].setval & save1)))
344  {
345  Print(" -%s",optionStruct[i].name);
346  }
347  }
348  for (i=0; verboseStruct[i].setval!=0; i++)
349  {
350  if ((verboseStruct[i].setval & si_opt_2)
351  && (!(verboseStruct[i].setval & save2)))
352  {
353  Print(" +%s",verboseStruct[i].name);
354  }
355  if (!(verboseStruct[i].setval & si_opt_2)
356  && ((verboseStruct[i].setval & save2)))
357  {
358  Print(" -%s",verboseStruct[i].name);
359  }
360  }
361  PrintLn();
362  }
363  return err;
364 }
const struct soptionStruct optionStruct[]
Definition: misc_ip.cc:516
unsigned si_opt_1
Definition: options.c:5
void PrintLn()
Definition: reporter.cc:310
#define Print
Definition: emacs.cc:83
return P p
Definition: myNF.cc:203
unsigned setval
Definition: ipid.h:152
#define BITSET
Definition: structs.h:18
char * procname
Definition: subexpr.h:56
char * libname
Definition: subexpr.h:55
int i
Definition: cfEzgcd.cc:123
char name(const Variable &v)
Definition: factory.h:178
int yyparse(void)
Definition: grammar.cc:2101
#define NULL
Definition: omList.c:10
int rtyp
Definition: subexpr.h:92
sleftv sLastPrinted
Definition: subexpr.cc:55
void CleanUp(ring r=currRing)
Definition: subexpr.cc:335
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:171
const struct soptionStruct verboseStruct[]
Definition: misc_ip.cc:546
unsigned si_opt_2
Definition: options.c:6
int BOOLEAN
Definition: auxiliary.h:86
#define TEST_V_ALLWARN
Definition: options.h:135
int l
Definition: cfEzgcd.cc:94
#define Warn
Definition: emacs.cc:80
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ iiArithAddCmd()

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

Definition at line 9026 of file iparith.cc.

9033 {
9034  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
9035  // nTokval, nToktype, nPos);
9036  if(nPos>=0)
9037  {
9038  // no checks: we rely on a correct generated code in iparith.inc
9039  assume((unsigned)nPos < sArithBase.nCmdAllocated);
9040  assume(szName!=NULL);
9041  sArithBase.sCmds[nPos].name = omStrDup(szName);
9042  sArithBase.sCmds[nPos].alias = nAlias;
9043  sArithBase.sCmds[nPos].tokval = nTokval;
9044  sArithBase.sCmds[nPos].toktype = nToktype;
9045  sArithBase.nCmdUsed++;
9046  //if(nTokval>0) sArithBase.nLastIdentifier++;
9047  }
9048  else
9049  {
9050  if(szName==NULL) return -1;
9051  int nIndex = iiArithFindCmd(szName);
9052  if(nIndex>=0)
9053  {
9054  Print("'%s' already exists at %d\n", szName, nIndex);
9055  return -1;
9056  }
9057 
9059  {
9060  /* needs to create new slots */
9061  unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
9062  sArithBase.sCmds = (cmdnames *)omRealloc(sArithBase.sCmds, nSize);
9063  if(sArithBase.sCmds==NULL) return -1;
9065  }
9066  /* still free slots available */
9067  sArithBase.sCmds[sArithBase.nCmdUsed].name = omStrDup(szName);
9068  sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias;
9069  sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval;
9070  sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
9071  sArithBase.nCmdUsed++;
9072 
9073  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9074  (&_gentable_sort_cmds));
9077  {
9078  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9079  }
9080  //Print("L=%d\n", sArithBase.nLastIdentifier);
9081  }
9082  return 0;
9083 }
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition: iparith.cc:8859
#define Print
Definition: emacs.cc:83
unsigned nCmdAllocated
number of commands-slots allocated
Definition: iparith.cc:197
#define assume(x)
Definition: mod2.h:403
unsigned nLastIdentifier
valid indentifieres are slot 1..nLastIdentifier
Definition: iparith.cc:198
#define NULL
Definition: omList.c:10
unsigned nCmdUsed
number of commands used
Definition: iparith.cc:196
#define nSize(n)
Definition: numbers.h:39
static SArithBase sArithBase
Base entry for arithmetic.
Definition: iparith.cc:206
int iiArithFindCmd(const char *szName)
Definition: iparith.cc:8931
cmdnames * sCmds
array of existing commands
Definition: iparith.cc:191
#define omRealloc(addr, size)
Definition: omAllocDecl.h:225
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ iiCheckNest()

static void iiCheckNest ( )
static

Definition at line 490 of file iplib.cc.

491 {
492  if (myynest >= iiRETURNEXPR_len-1)
493  {
495  iiRETURNEXPR_len*sizeof(ring),
496  (iiRETURNEXPR_len+16)*sizeof(ring));
497  memset(&(iiLocalRing[iiRETURNEXPR_len]),0,16*sizeof(ring));
498  iiRETURNEXPR_len+=16;
499  }
500 }
int iiRETURNEXPR_len
Definition: iplib.cc:472
#define omreallocSize(addr, o_size, size)
Definition: omAllocDecl.h:231
int myynest
Definition: febase.cc:46
ring * iiLocalRing
Definition: iplib.cc:470

§ iiCleanProcs()

static void iiCleanProcs ( idhdl root)
static

Definition at line 762 of file iplib.cc.

763 {
764  idhdl prev=NULL;
765  loop
766  {
767  if (root==NULL) return;
768  if (IDTYP(root)==PROC_CMD)
769  {
770  procinfo *pi=(procinfo*)IDDATA(root);
771  if ((pi->language == LANG_SINGULAR)
772  && (pi->data.s.body_start == 0L))
773  {
774  // procinfo data incorrect:
775  // - no proc body can start at the beginning of the file
776  killhdl(root);
777  if (prev==NULL)
778  root=IDROOT;
779  else
780  {
781  root=prev;
782  prev=NULL;
783  }
784  continue;
785  }
786  }
787  prev=root;
788  root=IDNEXT(root);
789  }
790 }
loop
Definition: myNF.cc:98
#define IDNEXT(a)
Definition: ipid.h:115
language_defs language
Definition: subexpr.h:58
#define IDROOT
Definition: ipid.h:20
Definition: idrec.h:34
#define IDTYP(a)
Definition: ipid.h:116
procinfodata data
Definition: subexpr.h:62
#define pi
Definition: libparse.cc:1143
#define NULL
Definition: omList.c:10
void killhdl(idhdl h, package proot)
Definition: ipid.cc:380
#define IDDATA(a)
Definition: ipid.h:123

§ iiConvName()

char* iiConvName ( const char *  libname)

Definition at line 1190 of file iplib.cc.

1191 {
1192  char *tmpname = omStrDup(libname);
1193  char *p = strrchr(tmpname, DIR_SEP);
1194  char *r;
1195  if(p==NULL) p = tmpname;
1196  else p++;
1197  r = (char *)strchr(p, '.');
1198  if( r!= NULL) *r = '\0';
1199  r = omStrDup(p);
1200  *r = mytoupper(*r);
1201  // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1202  omFree((ADDRESS)tmpname);
1203 
1204  return(r);
1205 }
char mytoupper(char c)
Definition: iplib.cc:1171
return P p
Definition: myNF.cc:203
void * ADDRESS
Definition: auxiliary.h:116
#define DIR_SEP
Definition: feResource.h:6
const ring r
Definition: syzextra.cc:208
#define omFree(addr)
Definition: omAllocDecl.h:261
#define NULL
Definition: omList.c:10
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ iiEStart()

BOOLEAN iiEStart ( char *  example,
procinfo pi 
)

Definition at line 591 of file iplib.cc.

592 {
593  BOOLEAN err;
594  int old_echo=si_echo;
595 
596  iiCheckNest();
597  procstack->push(example);
600  {
601  if (traceit&TRACE_SHOW_LINENO) printf("\n");
602  printf("entering example (level %d)\n",myynest);
603  }
604  myynest++;
605 
606  err=iiAllStart(pi,example,BT_example,(pi != NULL ? pi->data.s.example_lineno: 0));
607 
609  myynest--;
610  si_echo=old_echo;
611  if (traceit&TRACE_SHOW_PROC)
612  {
613  if (traceit&TRACE_SHOW_LINENO) printf("\n");
614  printf("leaving -example- (level %d)\n",myynest);
615  }
616  if (iiLocalRing[myynest] != currRing)
617  {
618  if (iiLocalRing[myynest]!=NULL)
619  {
622  }
623  else
624  {
626  currRing=NULL;
627  }
628  }
629  procstack->pop();
630  return err;
631 }
#define TRACE_SHOW_LINENO
Definition: reporter.h:30
proclevel * procstack
Definition: ipid.cc:58
int traceit
Definition: febase.cc:47
static void iiCheckNest()
Definition: iplib.cc:490
int myynest
Definition: febase.cc:46
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
void killlocals(int v)
Definition: ipshell.cc:380
procinfodata data
Definition: subexpr.h:62
idhdl currRingHdl
Definition: ipid.cc:65
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1572
BOOLEAN iiAllStart(procinfov pi, char *p, feBufferTypes t, int l)
Definition: iplib.cc:311
ring * iiLocalRing
Definition: iplib.cc:470
#define NULL
Definition: omList.c:10
#define TRACE_SHOW_PROC
Definition: reporter.h:28
void rSetHdl(idhdl h)
Definition: ipshell.cc:5021
void push(char *)
Definition: ipid.cc:710
void pop()
Definition: ipid.cc:720
int BOOLEAN
Definition: auxiliary.h:86
int si_echo
Definition: febase.cc:41

§ iiGetBuiltinModInit()

SModulFunc_t iiGetBuiltinModInit ( const char *  libname)

Definition at line 643 of file iplib.cc.

644 {
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
648 
649  return NULL;
650 }
#define SI_GET_BUILTIN_MOD_INIT(name)
SI_FOREACH_BUILTIN(SI_GET_BUILTIN_MOD_INIT0) }
#define NULL
Definition: omList.c:10

§ iiGetLibName()

char* iiGetLibName ( procinfov  pi)

Definition at line 101 of file iplib.cc.

102 {
103  return pi->libname;
104 }
char * libname
Definition: subexpr.h:55

§ iiGetLibProcBuffer()

char* iiGetLibProcBuffer ( procinfo pi,
int  part 
)

Definition at line 210 of file iplib.cc.

211 {
212  char buf[256], *s = NULL, *p;
213  long procbuflen;
214 
215  FILE * fp = feFopen( pi->libname, "rb", NULL, TRUE );
216  if (fp==NULL)
217  {
218  return NULL;
219  }
220 
221  fseek(fp, pi->data.s.proc_start, SEEK_SET);
222  if(part==0)
223  { // load help string
224  int i, offset=0;
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;
227  if (procbuflen<5)
228  {
229  fclose(fp);
230  return NULL; // help part does not exist
231  }
232  //Print("Help=%ld-%ld=%d\n", pi->data.s.body_start,
233  // pi->data.s.proc_start, procbuflen);
234  s = (char *)omAlloc(procbuflen+head+3);
235  myfread(s, head, 1, fp);
236  s[head] = '\n';
237  fseek(fp, pi->data.s.help_start, SEEK_SET);
238  myfread(s+head+1, procbuflen, 1, fp);
239  fclose(fp);
240  s[procbuflen+head+1] = '\n';
241  s[procbuflen+head+2] = '\0';
242  offset=0;
243  for(i=0;i<=procbuflen+head+2; i++)
244  {
245  if(s[i]=='\\' &&
246  (s[i+1]=='"' || s[i+1]=='{' || s[i+1]=='}' || s[i+1]=='\\'))
247  {
248  i++;
249  offset++;
250  }
251  if(offset>0) s[i-offset] = s[i];
252  }
253  return(s);
254  }
255  else if(part==1)
256  { // load proc part - must exist
257  procbuflen = pi->data.s.def_end - pi->data.s.proc_start;
258  char *ss=(char *)omAlloc(procbuflen+2);
259  //fgets(buf, sizeof(buf), fp);
260  myfread( ss, procbuflen, 1, fp);
261  char ct;
262  char *e;
263  s=iiProcName(ss,ct,e);
264  char *argstr=NULL;
265  *e=ct;
266  argstr=iiProcArgs(e,TRUE);
267 
268  assume(pi->data.s.body_end > pi->data.s.body_start);
269 
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) );
273  //Print("Body=%ld-%ld=%d\n", pi->data.s.body_end,
274  // pi->data.s.body_start, procbuflen);
275  assume(pi->data.s.body != NULL);
276  fseek(fp, pi->data.s.body_start, SEEK_SET);
277  strcpy(pi->data.s.body,argstr);
278  myfread( pi->data.s.body+strlen(argstr), procbuflen, 1, fp);
279  fclose( fp );
280  procbuflen+=strlen(argstr);
281  omFree(argstr);
282  omFree(ss);
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,'{');
287  if (s!=NULL) *s=' ';
288  return NULL;
289  }
290  else if(part==2)
291  { // example
292  if ( pi->data.s.example_lineno == 0)
293  return NULL; // example part does not exist
294  // load example
295  fseek(fp, pi->data.s.example_start, SEEK_SET);
296  /*char *dummy=*/ (void) fgets(buf, sizeof(buf), fp); // skip line with "example"
297  procbuflen = pi->data.s.proc_end - pi->data.s.example_start - strlen(buf);
298  //Print("Example=%ld-%ld=%d\n", pi->data.s.proc_end,
299  // pi->data.s.example_start, procbuflen);
300  s = (char *)omAlloc(procbuflen+14);
301  myfread(s, procbuflen, 1, fp);
302  s[procbuflen] = '\0';
303  strcat(s+procbuflen-3, "\n;return();\n\n" );
304  p=(char *)strchr(s,'{');
305  if (p!=NULL) *p=' ';
306  return(s);
307  }
308  return NULL;
309 }
char * iiProcArgs(char *e, BOOLEAN withParenth)
Definition: iplib.cc:127
const CanonicalForm int s
Definition: facAbsFact.cc:55
CanonicalForm fp
Definition: cfModGcd.cc:4043
return P p
Definition: myNF.cc:203
#define TRUE
Definition: auxiliary.h:99
#define omAlloc(size)
Definition: omAllocDecl.h:210
char * libname
Definition: subexpr.h:55
#define omFree(addr)
Definition: omAllocDecl.h:261
#define assume(x)
Definition: mod2.h:403
size_t myfread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Definition: feFopen.cc:195
int status int void * buf
Definition: si_signals.h:59
procinfodata data
Definition: subexpr.h:62
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
int i
Definition: cfEzgcd.cc:123
char * iiProcName(char *buf, char &ct, char *&e)
Definition: iplib.cc:113
#define NULL
Definition: omList.c:10
CanonicalForm head(const CanonicalForm &f)
#define SEEK_SET
Definition: mod2.h:123
int offset
Definition: libparse.cc:1091

§ iiGetLibStatus()

BOOLEAN iiGetLibStatus ( char *  lib)

Definition at line 83 of file iplib.cc.

84 {
85  idhdl hl;
86 
87  char *plib = iiConvName(lib);
88  hl = basePack->idroot->get(plib,0);
89  omFree(plib);
90  if((hl==NULL) ||(IDTYP(hl)!=PACKAGE_CMD))
91  {
92  return FALSE;
93  }
94  return (strcmp(lib,IDPACKAGE(hl)->libname)==0);
95 }
#define FALSE
Definition: auxiliary.h:95
Definition: idrec.h:34
#define IDPACKAGE(a)
Definition: ipid.h:136
#define IDTYP(a)
Definition: ipid.h:116
#define omFree(addr)
Definition: omAllocDecl.h:261
#define NULL
Definition: omList.c:10
package basePack
Definition: ipid.cc:64
char * iiConvName(const char *libname)
Definition: iplib.cc:1190

§ iiInitSingularProcinfo()

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

Definition at line 883 of file iplib.cc.

885 {
886  memset(pi,0,sizeof(*pi));
887  pi->libname = omStrDup(libname);
888  pi->procname = omStrDup(procname);
889  pi->language = LANG_SINGULAR;
890  pi->ref = 1;
891  pi->is_static = pstatic;
892  pi->data.s.proc_start = pos;
893  return(pi);
894 }
language_defs language
Definition: subexpr.h:58
short ref
Definition: subexpr.h:59
char * procname
Definition: subexpr.h:56
char * libname
Definition: subexpr.h:55
procinfodata data
Definition: subexpr.h:62
char is_static
Definition: subexpr.h:60
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ iiLibCmd()

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

Definition at line 718 of file iplib.cc.

719 {
720  char libnamebuf[128];
721  // procinfov pi;
722  // idhdl h;
723  idhdl pl;
724  // idhdl hl;
725  // long pos = 0L;
726  char *plib = iiConvName(newlib);
727  FILE * fp = feFopen( newlib, "r", libnamebuf, tellerror );
728  // int lines = 1;
729  BOOLEAN LoadResult = TRUE;
730 
731  if (fp==NULL)
732  {
733  return TRUE;
734  }
735  pl = basePack->idroot->get(plib,0);
736  if (pl==NULL)
737  {
738  pl = enterid( plib,0, PACKAGE_CMD,
739  &(basePack->idroot), TRUE );
740  IDPACKAGE(pl)->language = LANG_SINGULAR;
741  IDPACKAGE(pl)->libname=omStrDup(newlib);
742  }
743  else
744  {
745  if(IDTYP(pl)!=PACKAGE_CMD)
746  {
747  WarnS("not of type package.");
748  fclose(fp);
749  return TRUE;
750  }
751  if (!force) return FALSE;
752  }
753  LoadResult = iiLoadLIB(fp, libnamebuf, newlib, pl, autoexport, tellerror);
754  omFree((ADDRESS)newlib);
755 
756  if(!LoadResult) IDPACKAGE(pl)->loaded = TRUE;
757  omFree((ADDRESS)plib);
758 
759  return LoadResult;
760 }
CanonicalForm fp
Definition: cfModGcd.cc:4043
#define FALSE
Definition: auxiliary.h:95
#define TRUE
Definition: auxiliary.h:99
void * ADDRESS
Definition: auxiliary.h:116
#define WarnS
Definition: emacs.cc:81
Definition: idrec.h:34
#define IDPACKAGE(a)
Definition: ipid.h:136
#define IDTYP(a)
Definition: ipid.h:116
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:261
#define omFree(addr)
Definition: omAllocDecl.h:261
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
#define NULL
Definition: omList.c:10
package basePack
Definition: ipid.cc:64
char libnamebuf[128]
Definition: libparse.cc:1096
BOOLEAN iiLoadLIB(FILE *fp, const char *libnamebuf, const char *newlib, idhdl pl, BOOLEAN autoexport, BOOLEAN tellerror)
Definition: iplib.cc:807
char * iiConvName(const char *libname)
Definition: iplib.cc:1190
int BOOLEAN
Definition: auxiliary.h:86
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ iiLoadLIB()

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

Definition at line 807 of file iplib.cc.

809 {
810  extern FILE *yylpin;
811  libstackv ls_start = library_stack;
812  lib_style_types lib_style;
813 
814  yylpin = fp;
815  #if YYLPDEBUG > 1
816  print_init();
817  #endif
818  extern int lpverbose;
819  if (BVERBOSE(V_DEBUG_LIB)) lpverbose=1;
820  else lpverbose=0;
821  // yylplex sets also text_buffer
822  if (text_buffer!=NULL) *text_buffer='\0';
823  yylplex(newlib, libnamebuf, &lib_style, pl, autoexport);
824  if(yylp_errno)
825  {
826  Werror("Library %s: ERROR occurred: in line %d, %d.", newlib, yylplineno,
827  current_pos(0));
829  {
833  }
834  else
836  WerrorS("Cannot load library,... aborting.");
837  reinit_yylp();
838  fclose( yylpin );
840  return TRUE;
841  }
842  if (BVERBOSE(V_LOAD_LIB))
843  Print( "// ** loaded %s %s\n", libnamebuf, text_buffer);
844  if( (lib_style == OLD_LIBSTYLE) && (BVERBOSE(V_LOAD_LIB)))
845  {
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.");
849  }
850  reinit_yylp();
851  fclose( yylpin );
852  fp = NULL;
853  iiRunInit(IDPACKAGE(pl));
854 
855  {
856  libstackv ls;
857  for(ls = library_stack; (ls != NULL) && (ls != ls_start); )
858  {
859  if(ls->to_be_done)
860  {
861  ls->to_be_done=FALSE;
862  iiLibCmd(ls->get(),autoexport,tellerror,FALSE);
863  ls = ls->pop(newlib);
864  }
865  }
866 #if 0
867  PrintS("--------------------\n");
868  for(ls = library_stack; ls != NULL; ls = ls->next)
869  {
870  Print("%s: LIB-stack:(%d), %s %s\n", newlib, ls->cnt, ls->get(),
871  ls->to_be_done ? "not loaded" : "loaded");
872  }
873  PrintS("--------------------\n");
874 #endif
875  }
876 
877  if(fp != NULL) fclose(fp);
878  return FALSE;
879 }
int cnt
Definition: subexpr.h:167
#define Print
Definition: emacs.cc:83
CanonicalForm fp
Definition: cfModGcd.cc:4043
int yylplex(const char *libname, const char *libfile, lib_style_types *lib_style, idhdl pl, BOOLEAN autoexport=FALSE, lp_modes=LOAD_LIB)
libstackv next
Definition: subexpr.h:164
#define FALSE
Definition: auxiliary.h:95
static void iiRunInit(package p)
Definition: iplib.cc:791
#define V_LOAD_LIB
Definition: options.h:45
#define IDROOT
Definition: ipid.h:20
BOOLEAN to_be_done
Definition: subexpr.h:166
#define TRUE
Definition: auxiliary.h:99
void print_init()
Definition: libparse.cc:3480
void * ADDRESS
Definition: auxiliary.h:116
void WerrorS(const char *s)
Definition: feFopen.cc:24
char * get()
Definition: subexpr.h:170
#define V_DEBUG_LIB
Definition: options.h:46
libstackv pop(const char *p)
Definition: iplib.cc:1279
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:718
#define IDPACKAGE(a)
Definition: ipid.h:136
#define YYLP_BAD_CHAR
Definition: libparse.h:93
int lpverbose
Definition: libparse.cc:1104
int yylp_errno
Definition: libparse.cc:1128
#define omFree(addr)
Definition: omAllocDecl.h:261
char * yylp_errlist[]
Definition: libparse.cc:1112
void PrintS(const char *s)
Definition: reporter.cc:284
#define BVERBOSE(a)
Definition: options.h:33
#define NULL
Definition: omList.c:10
char * text_buffer
Definition: libparse.cc:1097
int current_pos(int i=0)
Definition: libparse.cc:3344
lib_style_types
Definition: libparse.h:9
char libnamebuf[128]
Definition: libparse.cc:1096
static void iiCleanProcs(idhdl &root)
Definition: iplib.cc:762
void Werror(const char *fmt,...)
Definition: reporter.cc:189
libstackv library_stack
Definition: iplib.cc:74
int yylplineno
Definition: libparse.cc:1102
#define Warn
Definition: emacs.cc:80
void reinit_yylp()
Definition: libparse.cc:3374

§ iiLocateLib()

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

Definition at line 704 of file iplib.cc.

705 {
706  char *plib = iiConvName(lib);
707  idhdl pl = basePack->idroot->get(plib,0);
708  if( (pl!=NULL) && (IDTYP(pl)==PACKAGE_CMD) &&
709  (IDPACKAGE(pl)->language == LANG_SINGULAR))
710  {
711  strncpy(where,IDPACKAGE(pl)->libname,127);
712  return TRUE;
713  }
714  else
715  return FALSE;;
716 }
#define FALSE
Definition: auxiliary.h:95
#define TRUE
Definition: auxiliary.h:99
Definition: idrec.h:34
#define IDPACKAGE(a)
Definition: ipid.h:136
#define IDTYP(a)
Definition: ipid.h:116
#define NULL
Definition: omList.c:10
package basePack
Definition: ipid.cc:64
char * iiConvName(const char *libname)
Definition: iplib.cc:1190

§ iiMake_proc()

BOOLEAN iiMake_proc ( idhdl  pn,
package  pack,
sleftv sl 
)

Definition at line 501 of file iplib.cc.

502 {
503  int err;
504  procinfov pi = IDPROC(pn);
505  if(pi->is_static && myynest==0)
506  {
507  Werror("'%s::%s()' is a local procedure and cannot be accessed by an user.",
508  pi->libname, pi->procname);
509  return TRUE;
510  }
511  iiCheckNest();
513  //Print("currRing(%d):%s(%x) in %s\n",myynest,IDID(currRingHdl),currRing,IDID(pn));
514  iiRETURNEXPR.Init();
515  procstack->push(pi->procname);
517  || (pi->trace_flag&TRACE_SHOW_PROC))
518  {
520  Print("entering%-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
521  }
522 #ifdef RDEBUG
524 #endif
525  switch (pi->language)
526  {
527  default:
528  case LANG_NONE:
529  WerrorS("undefined proc");
530  err=TRUE;
531  break;
532 
533  case LANG_SINGULAR:
534  if ((pi->pack!=NULL)&&(currPack!=pi->pack))
535  {
536  currPack=pi->pack;
539  //Print("set pack=%s\n",IDID(currPackHdl));
540  }
541  else if ((pack!=NULL)&&(currPack!=pack))
542  {
543  currPack=pack;
546  //Print("set pack=%s\n",IDID(currPackHdl));
547  }
548  err=iiPStart(pn,sl);
549  break;
550  case LANG_C:
552  err = (pi->data.o.function)(res, sl);
553  memcpy(&iiRETURNEXPR,res,sizeof(iiRETURNEXPR));
555  break;
556  }
557  if ((traceit&TRACE_SHOW_PROC)
558  || (pi->trace_flag&TRACE_SHOW_PROC))
559  {
560  if (traceit&TRACE_SHOW_LINENO) PrintLn();
561  Print("leaving %-*.*s %s (level %d)\n",myynest*2,myynest*2," ",IDID(pn),myynest);
562  }
563  //const char *n="NULL";
564  //if (currRingHdl!=NULL) n=IDID(currRingHdl);
565  //Print("currRing(%d):%s(%x) after %s\n",myynest,n,currRing,IDID(pn));
566 #ifdef RDEBUG
567  if (traceit&TRACE_SHOW_RINGS) iiShowLevRings();
568 #endif
569  if (err)
570  {
572  //iiRETURNEXPR.Init(); //done by CleanUp
573  }
574  if (iiCurrArgs!=NULL)
575  {
576  if (!err) Warn("too many arguments for %s",IDID(pn));
577  iiCurrArgs->CleanUp();
580  }
581  procstack->pop();
582  if (err)
583  return TRUE;
584  return FALSE;
585 }
#define TRACE_SHOW_LINENO
Definition: reporter.h:30
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
#define TRACE_SHOW_RINGS
Definition: reporter.h:35
void PrintLn()
Definition: reporter.cc:310
#define Print
Definition: emacs.cc:83
package pack
Definition: subexpr.h:57
idhdl currPackHdl
Definition: ipid.cc:61
#define IDID(a)
Definition: ipid.h:119
#define FALSE
Definition: auxiliary.h:95
sleftv iiRETURNEXPR
Definition: iplib.cc:471
language_defs language
Definition: subexpr.h:58
proclevel * procstack
Definition: ipid.cc:58
static void iiShowLevRings()
Definition: iplib.cc:475
#define TRUE
Definition: auxiliary.h:99
void Init()
Definition: subexpr.h:108
void * ADDRESS
Definition: auxiliary.h:116
sleftv * leftv
Definition: structs.h:60
void WerrorS(const char *s)
Definition: feFopen.cc:24
int traceit
Definition: febase.cc:47
static void iiCheckNest()
Definition: iplib.cc:490
char * procname
Definition: subexpr.h:56
poly res
Definition: myNF.cc:322
Definition: subexpr.h:21
int myynest
Definition: febase.cc:46
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
char * libname
Definition: subexpr.h:55
procinfodata data
Definition: subexpr.h:62
omBin sleftv_bin
Definition: subexpr.cc:50
char is_static
Definition: subexpr.h:60
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
#define IDPROC(a)
Definition: ipid.h:137
#define pi
Definition: libparse.cc:1143
ring * iiLocalRing
Definition: iplib.cc:470
#define NULL
Definition: omList.c:10
BOOLEAN iiPStart(idhdl pn, sleftv *v)
Definition: iplib.cc:371
package currPack
Definition: ipid.cc:63
leftv iiCurrArgs
Definition: ipshell.cc:80
void CleanUp(ring r=currRing)
Definition: subexpr.cc:335
#define TRACE_SHOW_PROC
Definition: reporter.h:28
idhdl packFindHdl(package r)
Definition: ipid.cc:738
void iiCheckPack(package &p)
Definition: ipshell.cc:1513
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
void push(char *)
Definition: ipid.cc:710
void pop()
Definition: ipid.cc:720
char trace_flag
Definition: subexpr.h:61
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define Warn
Definition: emacs.cc:80

§ iiProcArgs()

char* iiProcArgs ( char *  e,
BOOLEAN  withParenth 
)

Definition at line 127 of file iplib.cc.

128 {
129  while ((*e==' ') || (*e=='\t') || (*e=='(')) e++;
130  if (*e<' ')
131  {
132  if (withParenth)
133  {
134  // no argument list, allow list #
135  return omStrDup("parameter list #;");
136  }
137  else
138  {
139  // empty list
140  return omStrDup("");
141  }
142  }
143  BOOLEAN in_args;
144  BOOLEAN args_found;
145  char *s;
146  char *argstr=(char *)omAlloc(127); // see ../omalloc/omTables.inc
147  int argstrlen=127;
148  *argstr='\0';
149  int par=0;
150  do
151  {
152  args_found=FALSE;
153  s=e; // set s to the starting point of the arg
154  // and search for the end
155  // skip leading spaces:
156  loop
157  {
158  if ((*s==' ')||(*s=='\t'))
159  s++;
160  else if ((*s=='\n')&&(*(s+1)==' '))
161  s+=2;
162  else // start of new arg or \0 or )
163  break;
164  }
165  e=s;
166  while ((*e!=',')
167  &&((par!=0) || (*e!=')'))
168  &&(*e!='\0'))
169  {
170  if (*e=='(') par++;
171  else if (*e==')') par--;
172  args_found=args_found || (*e>' ');
173  e++;
174  }
175  in_args=(*e==',');
176  if (args_found)
177  {
178  *e='\0';
179  // check for space:
180  if ((int)strlen(argstr)+12 /* parameter + ;*/ +(int)strlen(s)>= argstrlen)
181  {
182  argstrlen*=2;
183  char *a=(char *)omAlloc( argstrlen);
184  strcpy(a,argstr);
185  omFree((ADDRESS)argstr);
186  argstr=a;
187  }
188  // copy the result to argstr
189  if(strncmp(s,"alias ",6)!=0)
190  {
191  strcat(argstr,"parameter ");
192  }
193  strcat(argstr,s);
194  strcat(argstr,"; ");
195  e++; // e was pointing to ','
196  }
197  } while (in_args);
198  return argstr;
199 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
loop
Definition: myNF.cc:98
#define FALSE
Definition: auxiliary.h:95
void * ADDRESS
Definition: auxiliary.h:116
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
int BOOLEAN
Definition: auxiliary.h:86
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ iiProcName()

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

Definition at line 113 of file iplib.cc.

114 {
115  char *s=buf+5;
116  while (*s==' ') s++;
117  e=s+1;
118  while ((*e>' ') && (*e!='(')) e++;
119  ct=*e;
120  *e='\0';
121  return s;
122 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
int status int void * buf
Definition: si_signals.h:59

§ iiPStart()

BOOLEAN iiPStart ( idhdl  pn,
sleftv v 
)

Definition at line 371 of file iplib.cc.

372 {
373  procinfov pi=NULL;
374  int old_echo=si_echo;
375  BOOLEAN err=FALSE;
376  char save_flags=0;
377 
378  /* init febase ======================================== */
379  /* we do not enter this case if filename != NULL !! */
380  if (pn!=NULL)
381  {
382  pi = IDPROC(pn);
383  if(pi!=NULL)
384  {
385  save_flags=pi->trace_flag;
386  if( pi->data.s.body==NULL )
387  {
388  iiGetLibProcBuffer(pi);
389  if (pi->data.s.body==NULL) return TRUE;
390  }
391 // omUpdateInfo();
392 // int m=om_Info.UsedBytes;
393 // Print("proc %s, mem=%d\n",IDID(pn),m);
394  }
395  }
396  else return TRUE;
397  /* generate argument list ======================================*/
398  if (v!=NULL)
399  {
401  memcpy(iiCurrArgs,v,sizeof(sleftv));
402  memset(v,0,sizeof(sleftv));
403  }
404  else
405  {
407  }
408  iiCurrProc=pn;
409  /* start interpreter ======================================*/
410  myynest++;
411  if (myynest > SI_MAX_NEST)
412  {
413  WerrorS("nesting too deep");
414  err=TRUE;
415  }
416  else
417  {
418  err=iiAllStart(pi,pi->data.s.body,BT_proc,pi->data.s.body_lineno-(v!=NULL));
419 
420  if (iiLocalRing[myynest-1] != currRing)
421  {
423  {
424  //idhdl hn;
425  const char *n;
426  const char *o;
427  idhdl nh=NULL, oh=NULL;
428  if (iiLocalRing[myynest-1]!=NULL)
430  if (oh!=NULL) o=oh->id;
431  else o="none";
432  if (currRing!=NULL)
433  nh=rFindHdl(currRing,NULL);
434  if (nh!=NULL) n=nh->id;
435  else n="none";
436  Werror("ring change during procedure call: %s -> %s (level %d)",o,n,myynest);
438  err=TRUE;
439  }
441  }
442  if ((currRing==NULL)
443  && (currRingHdl!=NULL))
445  else
446  if ((currRing!=NULL) &&
448  ||(IDLEV(currRingHdl)>=myynest-1)))
449  {
452  }
453  //Print("kill locals for %s (level %d)\n",IDID(pn),myynest);
455 #ifndef SING_NDEBUG
456  checkall();
457 #endif
458  //Print("end kill locals for %s (%d)\n",IDID(pn),myynest);
459  }
460  myynest--;
461  si_echo=old_echo;
462  if (pi!=NULL)
463  pi->trace_flag=save_flags;
464 // omUpdateInfo();
465 // int m=om_Info.UsedBytes;
466 // Print("exit %s, mem=%d\n",IDID(pn),m);
467  return err;
468 }
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
#define FALSE
Definition: auxiliary.h:95
sleftv iiRETURNEXPR
Definition: iplib.cc:471
#define TRUE
Definition: auxiliary.h:99
sleftv * leftv
Definition: structs.h:60
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: idrec.h:34
idhdl iiCurrProc
Definition: ipshell.cc:81
#define SI_MAX_NEST
Definition: iplib.cc:33
int myynest
Definition: febase.cc:46
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
BOOLEAN RingDependend()
Definition: subexpr.cc:405
void killlocals(int v)
Definition: ipshell.cc:380
procinfodata data
Definition: subexpr.h:62
idhdl currRingHdl
Definition: ipid.cc:65
omBin sleftv_bin
Definition: subexpr.cc:50
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1572
#define IDLEV(a)
Definition: ipid.h:118
BOOLEAN iiAllStart(procinfov pi, char *p, feBufferTypes t, int l)
Definition: iplib.cc:311
#define IDPROC(a)
Definition: ipid.h:137
#define pi
Definition: libparse.cc:1143
ring * iiLocalRing
Definition: iplib.cc:470
#define NULL
Definition: omList.c:10
#define IDRING(a)
Definition: ipid.h:124
leftv iiCurrArgs
Definition: ipshell.cc:80
void CleanUp(ring r=currRing)
Definition: subexpr.cc:335
const char * id
Definition: idrec.h:39
void rSetHdl(idhdl h)
Definition: ipshell.cc:5021
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:210
int BOOLEAN
Definition: auxiliary.h:86
char trace_flag
Definition: subexpr.h:61
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int si_echo
Definition: febase.cc:41

§ iiRunInit()

static void iiRunInit ( package  p)
static

Definition at line 791 of file iplib.cc.

792 {
793  idhdl h=p->idroot->get("mod_init",0);
794  if (h==NULL) return;
795  if (IDTYP(h)==PROC_CMD)
796  {
797  int save=yylineno;
798  myynest++;
799  // procinfo *pi=(procinfo*)IDDATA(h);
800  //PrintS("mod_init found\n");
801  iiMake_proc(h,p,NULL);
802  myynest--;
803  yylineno=save;
804  }
805 }
int yylineno
Definition: febase.cc:45
return P p
Definition: myNF.cc:203
Definition: idrec.h:34
int myynest
Definition: febase.cc:46
#define IDTYP(a)
Definition: ipid.h:116
BOOLEAN iiMake_proc(idhdl pn, package pack, sleftv *sl)
Definition: iplib.cc:501
#define NULL
Definition: omList.c:10
static Poly * h
Definition: janet.cc:978

§ iiShowLevRings()

static void iiShowLevRings ( )
static

Definition at line 475 of file iplib.cc.

476 {
477  int i;
478  for (i=0;i<=myynest;i++)
479  {
480  Print("lev %d:",i);
481  if (iiLocalRing[i]==NULL) PrintS("NULL");
482  else Print("%lx",(long)iiLocalRing[i]);
483  PrintLn();
484  }
485  if (currRing==NULL) PrintS("curr:NULL\n");
486  else Print ("curr:%lx\n",(long)currRing);
487 }
void PrintLn()
Definition: reporter.cc:310
#define Print
Definition: emacs.cc:83
int myynest
Definition: febase.cc:46
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:10
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:284
ring * iiLocalRing
Definition: iplib.cc:470
#define NULL
Definition: omList.c:10

§ iiTryLoadLib()

BOOLEAN iiTryLoadLib ( leftv  v,
const char *  id 
)

Definition at line 656 of file iplib.cc.

657 {
658  BOOLEAN LoadResult = TRUE;
659  char libnamebuf[128];
660  char *libname = (char *)omAlloc(strlen(id)+5);
661  const char *suffix[] = { "", ".lib", ".so", ".sl", NULL };
662  int i = 0;
663  // FILE *fp;
664  // package pack;
665  // idhdl packhdl;
666  lib_types LT;
667  for(i=0; suffix[i] != NULL; i++)
668  {
669  sprintf(libname, "%s%s", id, suffix[i]);
670  *libname = mytolower(*libname);
671  if((LT = type_of_LIB(libname, libnamebuf)) > LT_NOTFOUND)
672  {
673  char *s=omStrDup(libname);
674  #ifdef HAVE_DYNAMIC_LOADING
675  char libnamebuf[256];
676  #endif
677 
678  if (LT==LT_SINGULAR)
679  LoadResult = iiLibCmd(s, FALSE, FALSE,TRUE);
680  #ifdef HAVE_DYNAMIC_LOADING
681  else if ((LT==LT_ELF) || (LT==LT_HPUX))
682  LoadResult = load_modules(s,libnamebuf,FALSE);
683  #endif
684  else if (LT==LT_BUILTIN)
685  {
686  LoadResult=load_builtin(s,FALSE, iiGetBuiltinModInit(s));
687  }
688  if(!LoadResult )
689  {
690  v->name = iiConvName(libname);
691  break;
692  }
693  }
694  }
695  omFree(libname);
696  return LoadResult;
697 }
BOOLEAN load_builtin(const char *newlib, BOOLEAN autoexport, SModulFunc_t init)
Definition: iplib.cc:1056
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:95
Definition: mod_raw.h:16
#define TRUE
Definition: auxiliary.h:99
lib_types type_of_LIB(const char *newlib, char *libnamebuf)
Definition: mod_lib.cc:24
#define omAlloc(size)
Definition: omAllocDecl.h:210
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:718
const char * name
Definition: subexpr.h:88
#define omFree(addr)
Definition: omAllocDecl.h:261
int i
Definition: cfEzgcd.cc:123
lib_types
Definition: mod_raw.h:16
char mytolower(char c)
Definition: iplib.cc:1177
#define NULL
Definition: omList.c:10
SModulFunc_t iiGetBuiltinModInit(const char *libname)
Definition: iplib.cc:643
char libnamebuf[128]
Definition: libparse.cc:1096
char * iiConvName(const char *libname)
Definition: iplib.cc:1190
int BOOLEAN
Definition: auxiliary.h:86
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:958
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ load_builtin()

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

Definition at line 1056 of file iplib.cc.

1057 {
1058  int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1059  BOOLEAN(*func)(leftv res, leftv v));
1060 /*
1061  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1062  BOOLEAN pstatic,
1063  BOOLEAN(*func)(leftv res, leftv v)));
1064 */
1065  // SModulFunc_t fktn;
1066  idhdl pl;
1067  char *plib = iiConvName(newlib);
1068  // BOOLEAN RET=TRUE;
1069  // int token;
1070 
1071  pl = basePack->idroot->get(plib,0); // search PACKAGE only in Top
1072  if ((pl!=NULL)
1073  &&(IDTYP(pl)==PACKAGE_CMD))
1074  {
1075  if(IDPACKAGE(pl)->language==LANG_C)
1076  {
1077  if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1078  omFree(plib);
1079  return FALSE;
1080  }
1081  }
1082  else
1083  {
1084  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1085  IDPACKAGE(pl)->libname=omStrDup(newlib);
1086  }
1087  IDPACKAGE(pl)->language = LANG_C;
1088 
1089  IDPACKAGE(pl)->handle=(void *)NULL;
1090  SModulFunctions sModulFunctions;
1091 
1092  package s=currPack;
1093  currPack=IDPACKAGE(pl);
1094  if( init!= NULL)
1095  {
1096  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1097  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1098  else sModulFunctions.iiAddCproc = iiAddCproc;
1099  (*init)(&sModulFunctions);
1100  }
1101  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1102  currPack->loaded=1;
1103  currPack=s;
1104 
1105  return FALSE;
1106 }
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:945
const CanonicalForm int s
Definition: facAbsFact.cc:55
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:95
#define V_LOAD_LIB
Definition: options.h:45
#define IDROOT
Definition: ipid.h:20
#define TRUE
Definition: auxiliary.h:99
Definition: idrec.h:34
poly res
Definition: myNF.cc:322
Definition: subexpr.h:21
#define IDPACKAGE(a)
Definition: ipid.h:136
#define IDTYP(a)
Definition: ipid.h:116
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:261
#define omFree(addr)
Definition: omAllocDecl.h:261
#define BVERBOSE(a)
Definition: options.h:33
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
#define NULL
Definition: omList.c:10
package basePack
Definition: ipid.cc:64
package currPack
Definition: ipid.cc:63
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: ipid.h:71
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:897
char * iiConvName(const char *libname)
Definition: iplib.cc:1190
int BOOLEAN
Definition: auxiliary.h:86
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: ipid.h:73
#define Warn
Definition: emacs.cc:80
#define omStrDup(s)
Definition: omAllocDecl.h:263
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: iparith.cc:9026

§ load_modules()

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

Definition at line 958 of file iplib.cc.

959 {
960 #ifdef HAVE_STATIC
961  WerrorS("mod_init: static version can not load modules");
962  return TRUE;
963 #else
964 /*
965  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
966  BOOLEAN pstatic,
967  BOOLEAN(*func)(leftv res, leftv v)));
968 */
969  SModulFunc_t fktn;
970  idhdl pl;
971  char *plib = iiConvName(newlib);
972  BOOLEAN RET=TRUE;
973  int token;
974  char FullName[256];
975 
976  memset(FullName,0,256);
977 
978  if( *fullname != '/' && *fullname != '.' )
979  sprintf(FullName, "./%s", newlib);
980  else strncpy(FullName, fullname,255);
981 
982 
983  if(IsCmd(plib, token))
984  {
985  Werror("'%s' is resered identifier\n", plib);
986  goto load_modules_end;
987  }
988  pl = basePack->idroot->get(plib,0); /* packages only in top level
989  (see enterid) */
990  if ((pl!=NULL)
991  &&(IDTYP(pl)==PACKAGE_CMD))
992  {
993  if(IDPACKAGE(pl)->language==LANG_C)
994  {
995  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as package", newlib);
996  omFree(plib);
997  return FALSE;
998  }
999  }
1000  else
1001  {
1002  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT, TRUE );
1003  IDPACKAGE(pl)->libname=omStrDup(newlib);
1004  }
1005  IDPACKAGE(pl)->language = LANG_C;
1006  if (dynl_check_opened(FullName))
1007  {
1008  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded as C library", fullname);
1009  return FALSE;
1010  }
1011  if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1012  {
1013  Werror("dynl_open failed:%s", dynl_error());
1014  Werror("%s not found", newlib);
1015  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1016  goto load_modules_end;
1017  }
1018  else
1019  {
1020  SModulFunctions sModulFunctions;
1021 
1022  package s=currPack;
1023  currPack=IDPACKAGE(pl);
1024  fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1025  if( fktn!= NULL)
1026  {
1027  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1028  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1029  else sModulFunctions.iiAddCproc = iiAddCproc;
1030  int ver=(*fktn)(&sModulFunctions);
1031  if (ver==MAX_TOK)
1032  {
1033  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1034  }
1035  else
1036  {
1037  Warn("loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,MAX_TOK,ver);
1038  }
1039  currPack->loaded=1;
1040  currPack=s;
1041  RET=FALSE;
1042  }
1043  else
1044  {
1045  Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1046  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1047  }
1048  }
1049 
1050  load_modules_end:
1051  return RET;
1052 #endif /*STATIC */
1053 }
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:945
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:95
#define V_LOAD_LIB
Definition: options.h:45
Definition: tok.h:215
#define IDROOT
Definition: ipid.h:20
#define TRUE
Definition: auxiliary.h:99
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:167
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: idrec.h:34
void * dynl_open(char *filename)
Definition: mod_raw.cc:153
int dynl_check_opened(char *filename)
Definition: mod_raw.cc:146
Definition: subexpr.h:21
#define IDPACKAGE(a)
Definition: ipid.h:136
#define IDTYP(a)
Definition: ipid.h:116
void killhdl2(idhdl h, idhdl *ih, ring r)
Definition: ipid.cc:411
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:261
#define omFree(addr)
Definition: omAllocDecl.h:261
#define BVERBOSE(a)
Definition: options.h:33
#define NULL
Definition: omList.c:10
package basePack
Definition: ipid.cc:64
package currPack
Definition: ipid.cc:63
int(* SModulFunc_t)(SModulFunctions *)
Definition: ipid.h:82
int(* iiAddCproc)(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: ipid.h:71
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:897
char * iiConvName(const char *libname)
Definition: iplib.cc:1190
int BOOLEAN
Definition: auxiliary.h:86
int(* iiArithAddCmd)(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: ipid.h:73
void Werror(const char *fmt,...)
Definition: reporter.cc:189
const char * dynl_error()
Definition: mod_raw.cc:183
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:8688
#define Warn
Definition: emacs.cc:80
#define omStrDup(s)
Definition: omAllocDecl.h:263
int iiArithAddCmd(const char *szName, short nAlias, short nTokval, short nToktype, short nPos)
Definition: iparith.cc:9026

§ module_help_main()

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

Definition at line 1108 of file iplib.cc.

1109 {
1110  char *plib = iiConvName(newlib);
1111  idhdl pl = basePack->idroot->get(plib,0);
1112  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1113  Werror(">>%s<< is not a package (trying to add package help)",plib);
1114  else
1115  {
1116  package s=currPack;
1117  currPack=IDPACKAGE(pl);
1119  IDSTRING(h)=omStrDup(help);
1120  currPack=s;
1121  }
1122 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:95
#define IDROOT
Definition: ipid.h:20
Definition: idrec.h:34
#define IDPACKAGE(a)
Definition: ipid.h:136
#define IDTYP(a)
Definition: ipid.h:116
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:261
#define IDSTRING(a)
Definition: ipid.h:133
#define help
Definition: libparse.cc:1228
#define NULL
Definition: omList.c:10
package basePack
Definition: ipid.cc:64
package currPack
Definition: ipid.cc:63
char * iiConvName(const char *libname)
Definition: iplib.cc:1190
static Poly * h
Definition: janet.cc:978
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ module_help_proc()

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

Definition at line 1123 of file iplib.cc.

1124 {
1125  char *plib = iiConvName(newlib);
1126  idhdl pl = basePack->idroot->get(plib,0);
1127  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1128  Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1129  else
1130  {
1131  package s=currPack;
1132  currPack=IDPACKAGE(pl);
1133  char buff[256];
1134  buff[255]='\0';
1135  strncpy(buff,p,255);
1136  strncat(buff,"_help",255-strlen(p));
1138  IDSTRING(h)=omStrDup(help);
1139  currPack=s;
1140  }
1141 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:95
return P p
Definition: myNF.cc:203
#define IDROOT
Definition: ipid.h:20
Definition: idrec.h:34
#define IDPACKAGE(a)
Definition: ipid.h:136
#define IDTYP(a)
Definition: ipid.h:116
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:261
#define IDSTRING(a)
Definition: ipid.h:133
#define help
Definition: libparse.cc:1228
#define NULL
Definition: omList.c:10
package basePack
Definition: ipid.cc:64
package currPack
Definition: ipid.cc:63
char * iiConvName(const char *libname)
Definition: iplib.cc:1190
static Poly * h
Definition: janet.cc:978
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ mytolower()

char mytolower ( char  c)

Definition at line 1177 of file iplib.cc.

1178 {
1179  if(c>=65 && c<=(65+26)) c+=32;
1180  return(c);
1181 }

§ mytoupper()

char mytoupper ( char  c)

Definition at line 1171 of file iplib.cc.

1172 {
1173  if(c>=97 && c<=(97+26)) c-=32;
1174  return(c);
1175 }

§ print_init()

void print_init ( )

Definition at line 3480 of file libparse.cc.

3481 {
3482  printf("Init=%d\n", yy_init);
3483 }
static int yy_init
Definition: libparse.cc:238

§ SI_FOREACH_BUILTIN()

SI_FOREACH_BUILTIN ( SI_GET_BUILTIN_MOD_INIT0  )

§ yylprestart()

void yylprestart ( FILE *  input_file)

Variable Documentation

§ iiLocalRing

ring* iiLocalRing

Definition at line 470 of file iplib.cc.

§ iiRETURNEXPR

sleftv iiRETURNEXPR

Definition at line 471 of file iplib.cc.

§ iiRETURNEXPR_len

int iiRETURNEXPR_len =0

Definition at line 472 of file iplib.cc.

§ library_stack

libstackv library_stack

Definition at line 74 of file iplib.cc.

§ yylp_errlist

char* yylp_errlist[]

Definition at line 1112 of file libparse.cc.

§ yylp_errno

int yylp_errno

Definition at line 1128 of file libparse.cc.

§ yylplineno

int yylplineno

Definition at line 1102 of file libparse.cc.