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 line, 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 1137 of file iplib.cc.

1138 {
1139  void* result = NULL;
1140 
1141 #if defined(HAVE_STATIC) || !defined(HAVE_DYNAMIC_LOADING)
1142  WerrorS("static version can not load function from dynamic modules");
1143 #else
1144  const char* bin_dir = feGetResource('b');
1145  if (!bin_dir) { return NULL; }
1146 
1147  char path_name[MAXPATHLEN];
1148  sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, newlib, MODULE_SUFFIX_STRING);
1149 
1150  void* openlib = dynl_open(path_name);
1151  if(!openlib)
1152  {
1153  Werror("dynl_open of %s failed:%s", path_name, dynl_error());
1154  return NULL;
1155  }
1156  result = dynl_sym(openlib, funcname);
1157  if (!result) Werror("%s: %s\n", funcname, dynl_error());
1158 #endif
1159 
1160  return result;
1161 }
#define MAXPATHLEN
Definition: omRet2Info.c:22
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:167
void WerrorS(const char *s)
Definition: feFopen.cc:24
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 908 of file iplib.cc.

910 {
911  procinfov pi;
912  idhdl h;
913 
914  #ifndef SING_NDEBUG
915  int dummy;
916  if (IsCmd(procname,dummy))
917  {
918  Werror(">>%s< is a reserved name",procname);
919  return 0;
920  }
921  #endif
922 
923  h = enterid(procname,0, PROC_CMD, &IDROOT, TRUE);
924  if ( h!= NULL )
925  {
926  pi = IDPROC(h);
927  pi->libname = omStrDup(libname);
928  pi->procname = omStrDup(procname);
929  pi->language = LANG_C;
930  pi->ref = 1;
931  pi->is_static = pstatic;
932  pi->data.o.function = func;
933  return(1);
934  }
935  else
936  {
937  PrintS("iiAddCproc: failed.\n");
938  }
939  return(0);
940 }
language_defs language
Definition: subexpr.h:59
#define IDROOT
Definition: ipid.h:20
#define TRUE
Definition: auxiliary.h:101
short ref
Definition: subexpr.h:60
Definition: idrec.h:34
char * procname
Definition: subexpr.h:57
Definition: subexpr.h:21
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:259
char * libname
Definition: subexpr.h:56
procinfodata data
Definition: subexpr.h:63
void PrintS(const char *s)
Definition: reporter.cc:284
char is_static
Definition: subexpr.h:61
#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
void Werror(const char *fmt,...)
Definition: reporter.cc:189
int IsCmd(const char *n, int &tok)
Definition: iparith.cc:8830
#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 942 of file iplib.cc.

944 {
945  int r=iiAddCproc(libname,procname,pstatic,func);
946  package s=currPack;
948  if (r) r=iiAddCproc(libname,procname,pstatic,func);
949  currPack=s;
950  return r;
951 }
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:908

§ 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:57
char * libname
Definition: subexpr.h:56
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:93
sleftv sLastPrinted
Definition: subexpr.cc:55
void CleanUp(ring r=currRing)
Definition: subexpr.cc:320
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:88
#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 9171 of file iparith.cc.

9178 {
9179  //printf("AddCmd(%s, %d, %d, %d, %d)\n", szName, nAlias,
9180  // nTokval, nToktype, nPos);
9181  if(nPos>=0)
9182  {
9183  // no checks: we rely on a correct generated code in iparith.inc
9185  assume(szName!=NULL);
9186  sArithBase.sCmds[nPos].name = omStrDup(szName);
9187  sArithBase.sCmds[nPos].alias = nAlias;
9188  sArithBase.sCmds[nPos].tokval = nTokval;
9189  sArithBase.sCmds[nPos].toktype = nToktype;
9190  sArithBase.nCmdUsed++;
9191  //if(nTokval>0) sArithBase.nLastIdentifier++;
9192  }
9193  else
9194  {
9195  if(szName==NULL) return -1;
9196  int nIndex = iiArithFindCmd(szName);
9197  if(nIndex>=0)
9198  {
9199  Print("'%s' already exists at %d\n", szName, nIndex);
9200  return -1;
9201  }
9202 
9204  {
9205  /* needs to create new slots */
9206  unsigned long nSize = (sArithBase.nCmdAllocated+1)*sizeof(cmdnames);
9207  sArithBase.sCmds = (cmdnames *)omRealloc(sArithBase.sCmds, nSize);
9208  if(sArithBase.sCmds==NULL) return -1;
9210  }
9211  /* still free slots available */
9212  sArithBase.sCmds[sArithBase.nCmdUsed].name = omStrDup(szName);
9213  sArithBase.sCmds[sArithBase.nCmdUsed].alias = nAlias;
9214  sArithBase.sCmds[sArithBase.nCmdUsed].tokval = nTokval;
9215  sArithBase.sCmds[sArithBase.nCmdUsed].toktype = nToktype;
9216  sArithBase.nCmdUsed++;
9217 
9218  qsort(sArithBase.sCmds, sArithBase.nCmdUsed, sizeof(cmdnames),
9219  (&_gentable_sort_cmds));
9222  {
9223  if(sArithBase.sCmds[sArithBase.nLastIdentifier].tokval>=0) break;
9224  }
9225  //Print("L=%d\n", sArithBase.nLastIdentifier);
9226  }
9227  return 0;
9228 }
static int _gentable_sort_cmds(const void *a, const void *b)
compares to entry of cmdsname-list
Definition: iparith.cc:9004
#define Print
Definition: emacs.cc:83
int nCmdAllocated
number of commands-slots allocated
Definition: iparith.cc:197
#define assume(x)
Definition: mod2.h:403
int nLastIdentifier
valid indentifieres are slot 1..nLastIdentifier
Definition: iparith.cc:198
int nCmdUsed
number of commands used
Definition: iparith.cc:196
#define NULL
Definition: omList.c:10
#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:9076
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:59
#define IDROOT
Definition: ipid.h:20
Definition: idrec.h:34
#define IDTYP(a)
Definition: ipid.h:116
procinfodata data
Definition: subexpr.h:63
#define pi
Definition: libparse.cc:1143
#define NULL
Definition: omList.c:10
void killhdl(idhdl h, package proot)
Definition: ipid.cc:372
#define IDDATA(a)
Definition: ipid.h:123

§ iiConvName()

char* iiConvName ( const char *  libname)

Definition at line 1184 of file iplib.cc.

1185 {
1186  char *tmpname = omStrDup(libname);
1187  char *p = strrchr(tmpname, DIR_SEP);
1188  char *r;
1189  if(p==NULL) p = tmpname;
1190  else p++;
1191  r = (char *)strchr(p, '.');
1192  if( r!= NULL) *r = '\0';
1193  r = omStrDup(p);
1194  *r = mytoupper(*r);
1195  // printf("iiConvName: '%s' '%s' => '%s'\n", libname, tmpname, r);
1196  omFree((ADDRESS)tmpname);
1197 
1198  return(r);
1199 }
char mytoupper(char c)
Definition: iplib.cc:1165
return P p
Definition: myNF.cc:203
void * ADDRESS
Definition: auxiliary.h:118
#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:376
procinfodata data
Definition: subexpr.h:63
idhdl currRingHdl
Definition: ipid.cc:65
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1568
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:5017
void push(char *)
Definition: ipid.cc:702
void pop()
Definition: ipid.cc:712
int BOOLEAN
Definition: auxiliary.h:88
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:56

§ 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:101
#define omAlloc(size)
Definition: omAllocDecl.h:210
char * libname
Definition: subexpr.h:56
#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:63
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:97
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:1184

§ iiInitSingularProcinfo()

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

Definition at line 883 of file iplib.cc.

885 {
886  pi->libname = omStrDup(libname);
887  pi->procname = omStrDup(procname);
888  pi->language = LANG_SINGULAR;
889  pi->ref = 1;
890  pi->pack = NULL;
891  pi->is_static = pstatic;
892  pi->data.s.proc_start = pos;
893  pi->data.s.def_end = 0L;
894  pi->data.s.help_start = 0L;
895  pi->data.s.help_end = 0L;
896  pi->data.s.body_start = 0L;
897  pi->data.s.body_end = 0L;
898  pi->data.s.example_start = 0L;
899  pi->data.s.proc_lineno = line;
900  pi->data.s.body_lineno = 0;
901  pi->data.s.example_lineno = 0;
902  pi->data.s.body = NULL;
903  pi->data.s.help_chksum = 0;
904  return(pi);
905 }
package pack
Definition: subexpr.h:58
language_defs language
Definition: subexpr.h:59
short ref
Definition: subexpr.h:60
char * procname
Definition: subexpr.h:57
char * libname
Definition: subexpr.h:56
procinfodata data
Definition: subexpr.h:63
char is_static
Definition: subexpr.h:61
#define NULL
Definition: omList.c:10
#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:97
#define TRUE
Definition: auxiliary.h:101
void * ADDRESS
Definition: auxiliary.h:118
#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:259
#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:1184
int BOOLEAN
Definition: auxiliary.h:88
#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:168
#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:165
#define FALSE
Definition: auxiliary.h:97
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:167
#define TRUE
Definition: auxiliary.h:101
void print_init()
Definition: libparse.cc:3480
void * ADDRESS
Definition: auxiliary.h:118
void WerrorS(const char *s)
Definition: feFopen.cc:24
char * get()
Definition: subexpr.h:171
#define V_DEBUG_LIB
Definition: options.h:46
libstackv pop(const char *p)
Definition: iplib.cc:1273
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:97
#define TRUE
Definition: auxiliary.h:101
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:1184

§ 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:84
#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:58
idhdl currPackHdl
Definition: ipid.cc:61
#define IDID(a)
Definition: ipid.h:119
#define FALSE
Definition: auxiliary.h:97
sleftv iiRETURNEXPR
Definition: iplib.cc:471
language_defs language
Definition: subexpr.h:59
proclevel * procstack
Definition: ipid.cc:58
static void iiShowLevRings()
Definition: iplib.cc:475
#define TRUE
Definition: auxiliary.h:101
void Init()
Definition: subexpr.h:109
void * ADDRESS
Definition: auxiliary.h:118
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:57
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:56
procinfodata data
Definition: subexpr.h:63
omBin sleftv_bin
Definition: subexpr.cc:50
char is_static
Definition: subexpr.h:61
#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:78
void CleanUp(ring r=currRing)
Definition: subexpr.cc:320
#define TRACE_SHOW_PROC
Definition: reporter.h:28
idhdl packFindHdl(package r)
Definition: ipid.cc:730
void iiCheckPack(package &p)
Definition: ipshell.cc:1509
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259
void push(char *)
Definition: ipid.cc:702
void pop()
Definition: ipid.cc:712
char trace_flag
Definition: subexpr.h:62
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:97
void * ADDRESS
Definition: auxiliary.h:118
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
int BOOLEAN
Definition: auxiliary.h:88
#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:84
#define FALSE
Definition: auxiliary.h:97
sleftv iiRETURNEXPR
Definition: iplib.cc:471
#define TRUE
Definition: auxiliary.h:101
sleftv * leftv
Definition: structs.h:60
void WerrorS(const char *s)
Definition: feFopen.cc:24
Definition: idrec.h:34
idhdl iiCurrProc
Definition: ipshell.cc:79
#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:391
void killlocals(int v)
Definition: ipshell.cc:376
procinfodata data
Definition: subexpr.h:63
idhdl currRingHdl
Definition: ipid.cc:65
omBin sleftv_bin
Definition: subexpr.cc:50
idhdl rFindHdl(ring r, idhdl n)
Definition: ipshell.cc:1568
#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:78
void CleanUp(ring r=currRing)
Definition: subexpr.cc:320
const char * id
Definition: idrec.h:39
void rSetHdl(idhdl h)
Definition: ipshell.cc:5017
char * iiGetLibProcBuffer(procinfo *pi, int part)
Definition: iplib.cc:210
int BOOLEAN
Definition: auxiliary.h:88
char trace_flag
Definition: subexpr.h:62
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:1052
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:97
Definition: mod_raw.h:16
#define TRUE
Definition: auxiliary.h:101
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:89
#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:1171
#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:1184
int BOOLEAN
Definition: auxiliary.h:88
BOOLEAN load_modules(const char *newlib, char *fullname, BOOLEAN autoexport)
Definition: iplib.cc:955
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ load_builtin()

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

Definition at line 1052 of file iplib.cc.

1053 {
1054  int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic,
1055  BOOLEAN(*func)(leftv res, leftv v));
1056 /*
1057  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
1058  BOOLEAN pstatic,
1059  BOOLEAN(*func)(leftv res, leftv v)));
1060 */
1061  // SModulFunc_t fktn;
1062  idhdl pl;
1063  char *plib = iiConvName(newlib);
1064  // BOOLEAN RET=TRUE;
1065  // int token;
1066 
1067  pl = IDROOT->get(plib,0);
1068  if (pl!=NULL)
1069  {
1070  if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1071  omFree(plib);
1072  return FALSE;
1073  }
1074 
1075  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
1076  TRUE );
1077  IDPACKAGE(pl)->language = LANG_C;
1078  IDPACKAGE(pl)->libname=omStrDup(newlib);
1079 
1080  IDPACKAGE(pl)->handle=(void *)NULL;
1081  SModulFunctions sModulFunctions;
1082 
1083  package s=currPack;
1084  currPack=IDPACKAGE(pl);
1085  if( init!= NULL)
1086  {
1087  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1088  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1089  else sModulFunctions.iiAddCproc = iiAddCproc;
1090  (*init)(&sModulFunctions);
1091  }
1092  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded (builtin) %s \n", newlib);
1093  currPack->loaded=1;
1094  currPack=s;
1095 
1096  return FALSE;
1097 }
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:942
const CanonicalForm int s
Definition: facAbsFact.cc:55
Class used for (list of) interpreter objects.
Definition: subexpr.h:84
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:97
#define V_LOAD_LIB
Definition: options.h:45
#define IDROOT
Definition: ipid.h:20
#define TRUE
Definition: auxiliary.h:101
Definition: idrec.h:34
poly res
Definition: myNF.cc:322
Definition: subexpr.h:21
#define IDPACKAGE(a)
Definition: ipid.h:136
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:259
#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 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:908
char * iiConvName(const char *libname)
Definition: iplib.cc:1184
int BOOLEAN
Definition: auxiliary.h:88
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:9171

§ load_modules()

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

Definition at line 955 of file iplib.cc.

956 {
957 #ifdef HAVE_STATIC
958  WerrorS("mod_init: static version can not load modules");
959  return TRUE;
960 #else
961 /*
962  typedef int (*fktn_t)(int(*iiAddCproc)(const char *libname, const char *procname,
963  BOOLEAN pstatic,
964  BOOLEAN(*func)(leftv res, leftv v)));
965 */
966  SModulFunc_t fktn;
967  idhdl pl;
968  char *plib = iiConvName(newlib);
969  BOOLEAN RET=TRUE;
970  int token;
971  char FullName[256];
972 
973  memset(FullName,0,256);
974 
975  if( *fullname != '/' && *fullname != '.' )
976  sprintf(FullName, "./%s", newlib);
977  else strncpy(FullName, fullname,255);
978 
979 
980  if(IsCmd(plib, token))
981  {
982  Werror("'%s' is resered identifier\n", plib);
983  goto load_modules_end;
984  }
985  pl = basePack->idroot->get(plib,0); /* packages only in top level
986  (see enterid) */
987  if (pl==NULL)
988  {
989  pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
990  TRUE );
991  IDPACKAGE(pl)->language = LANG_C;
992  IDPACKAGE(pl)->libname=omStrDup(newlib);
993  }
994  else
995  {
996  if(IDTYP(pl)!=PACKAGE_CMD)
997  {
998  Warn("not of type package.");
999  goto load_modules_end;
1000  }
1001  }
1002  if (dynl_check_opened(FullName))
1003  {
1004  if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded", fullname);
1005  return FALSE;
1006  }
1007  if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
1008  {
1009  Werror("dynl_open failed:%s", dynl_error());
1010  Werror("%s not found", newlib);
1011  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1012  goto load_modules_end;
1013  }
1014  else
1015  {
1016  SModulFunctions sModulFunctions;
1017 
1018  package s=currPack;
1019  currPack=IDPACKAGE(pl);
1020  fktn = (SModulFunc_t)dynl_sym(IDPACKAGE(pl)->handle, "mod_init");
1021  if( fktn!= NULL)
1022  {
1023  sModulFunctions.iiArithAddCmd = iiArithAddCmd;
1024  if (autoexport) sModulFunctions.iiAddCproc = iiAddCprocTop;
1025  else sModulFunctions.iiAddCproc = iiAddCproc;
1026  int ver=(*fktn)(&sModulFunctions);
1027  if (ver==MAX_TOK)
1028  {
1029  if (BVERBOSE(V_LOAD_LIB)) Print( "// ** loaded %s\n", fullname);
1030  }
1031  else
1032  {
1033  Warn("loaded %s for a different version of Singular(expected MAX_TOK: %d, got %d)",fullname,MAX_TOK,ver);
1034  }
1035  currPack->loaded=1;
1036  currPack=s;
1037  RET=FALSE;
1038  }
1039  else
1040  {
1041  Werror("mod_init not found:: %s\nThis is probably not a dynamic module for Singular!\n", dynl_error());
1042  killhdl2(pl,&(basePack->idroot),NULL); // remove package
1043  }
1044  }
1045 
1046  load_modules_end:
1047  return RET;
1048 #endif /*STATIC */
1049 }
int iiAddCprocTop(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:942
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:97
#define V_LOAD_LIB
Definition: options.h:45
Definition: tok.h:213
#define IDROOT
Definition: ipid.h:20
#define TRUE
Definition: auxiliary.h:101
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:403
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:259
#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:908
char * iiConvName(const char *libname)
Definition: iplib.cc:1184
int BOOLEAN
Definition: auxiliary.h:88
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:8830
#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:9171

§ module_help_main()

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

Definition at line 1099 of file iplib.cc.

1100 {
1101  char *plib = iiConvName(newlib);
1102  idhdl pl = basePack->idroot->get(plib,0);
1103  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1104  Werror(">>%s<< is not a package (trying to add package help)",plib);
1105  else
1106  {
1107  package s=currPack;
1108  currPack=IDPACKAGE(pl);
1110  IDSTRING(h)=omStrDup(help);
1111  currPack=s;
1112  }
1113 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:97
#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:259
#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:1184
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 1114 of file iplib.cc.

1115 {
1116  char *plib = iiConvName(newlib);
1117  idhdl pl = basePack->idroot->get(plib,0);
1118  if ((pl==NULL)||(IDTYP(pl)!=PACKAGE_CMD))
1119  Werror(">>%s<< is not a package(trying to add help for %s)",plib,p);
1120  else
1121  {
1122  package s=currPack;
1123  currPack=IDPACKAGE(pl);
1124  char buff[256];
1125  buff[255]='\0';
1126  strncpy(buff,p,255);
1127  strncat(buff,"_help",255-strlen(p));
1129  IDSTRING(h)=omStrDup(help);
1130  currPack=s;
1131  }
1132 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define FALSE
Definition: auxiliary.h:97
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:259
#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:1184
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 1171 of file iplib.cc.

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

§ mytoupper()

char mytoupper ( char  c)

Definition at line 1165 of file iplib.cc.

1166 {
1167  if(c>=97 && c<=(97+26)) c-=32;
1168  return(c);
1169 }

§ 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.