Functions
tesths.cc File Reference
#include <kernel/mod2.h>
#include <omalloc/omalloc.h>
#include <misc/auxiliary.h>
#include <misc/options.h>
#include <factory/factory.h>
#include <kernel/oswrapper/feread.h>
#include <Singular/fevoices.h>
#include <kernel/oswrapper/timer.h>
#include "ipshell.h"
#include "cntrlc.h"
#include "links/silink.h"
#include "ipid.h"
#include "sdb.h"
#include "feOpt.h"
#include "distrib.h"
#include "mmalloc.h"
#include "tok.h"
#include "fegetopt.h"
#include <Singular/countedref.h>
#include <Singular/pyobject_setup.h>
#include <unistd.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>

Go to the source code of this file.

Functions

int siInit (char *)
 
int mmInit (void)
 
int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 69 of file tesths.cc.

72 {
73  mmInit();
74  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
75  omInitRet_2_Info(argv[0]);
77 
78  siInit(argv[0]);
79  init_signals();
80 
81  // parse command line options
82  int optc, option_index;
83  const char* errormsg;
84  while((optc = fe_getopt_long(argc, argv,
85  SHORT_OPTS_STRING, feOptSpec, &option_index))
86  != EOF)
87  {
88  if (optc == '?' || optc == 0)
89  {
90  fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
91  exit(1);
92  }
93 
94  if (optc != LONG_OPTION_RETURN)
95  option_index = feGetOptIndex(optc);
96 
97  assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
98 
99  if (fe_optarg == NULL &&
100  (feOptSpec[option_index].type == feOptBool ||
101  feOptSpec[option_index].has_arg == optional_argument))
102  errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
103  else
104  errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
105 
106  if (errormsg)
107  {
108  if (fe_optarg == NULL)
109  fprintf(stderr, "Error: Option '--%s' %s\n",
110  feOptSpec[option_index].name, errormsg);
111  else
112  fprintf(stderr, "Error: Option '--%s=%s' %s\n",
113  feOptSpec[option_index].name, fe_optarg, errormsg);
114  fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
115  exit(1);
116  }
117  if (optc == 'h') exit(0);
118  switch(option_index)
119  {
120  case FE_OPT_DUMP_VERSIONTUPLE:
121  exit(0);
122  break;
123  default: ;
124  }
125  }
126 
127  /* say hello */
128 
129  if (TEST_V_QUIET)
130  {
131  (printf)(
132 " SINGULAR /"
133 #ifndef MAKE_DISTRIBUTION
134 " Development"
135 #endif
136 "\n"
137 " A Computer Algebra System for Polynomial Computations / version %s\n"
138 " 0<\n"
139 " by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n"
140 "FB Mathematik der Universitaet, D-67653 Kaiserslautern \\ Debian " DEB_PKG_VERSION "\n"
141 , VERSION, VERSION_DATE);
142  if (feOptValue(FE_OPT_NO_SHELL)) Warn("running in restricted mode:"
143  " shell invocation and links are disallowed");
144  }
145  else
146  {
147  if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
148 #ifdef HAVE_SDB
149  sdb_flags = 0;
150 #endif
151  dup2(1,2);
152  /* alternative:
153  * memcpy(stderr,stdout,sizeof(FILE));
154  */
155  }
156 
157 #ifdef SINGULAR_PYOBJECT_SETUP_H
158  pyobject_setup();
159 #endif
160 #ifdef SI_COUNTEDREF_AUTOLOAD
161  countedref_init();
162 #endif
163 // #ifdef HAVE_FANS
164 // bbcone_setup();
165 // bbpolytope_setup();
166 // bbfan_setup();
167 // gitfan_setup();
168 // #endif /* HAVE_FANS */
169  errorreported = 0;
170 
171  // -- example for "static" modules ------
172  //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
173  //module_help_main("huhu.so","Help for huhu\nhaha\n");
174  //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
175  setjmp(si_start_jmpbuf);
176 
177  // Now, put things on the stack of stuff to do
178  // Last thing to do is to execute given scripts
179  if (fe_optind < argc)
180  {
181  int i = argc - 1;
182  FILE *fd;
183  while (i >= fe_optind)
184  {
185  if ((fd = feFopen(argv[i], "r")) == NULL)
186  {
187  Warn("Can not open %s", argv[i]);
188  }
189  else
190  {
191  fclose(fd);
192  newFile(argv[i]);
193  }
194  i--;
195  }
196  }
197  else
198  {
200  }
201 
202  // before scripts, we execute -c, if it was given
203  if (feOptValue(FE_OPT_EXECUTE) != NULL)
204  newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
205 
206  // first thing, however, is to load .singularrc from Singularpath
207  // and cwd/$HOME (in that order).
208  if (! feOptValue(FE_OPT_NO_RC))
209  {
210  char buf[MAXPATHLEN];
211  FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
212  if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
213  if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
214 
215  if (rc != NULL)
216  {
217  if (BVERBOSE(V_LOAD_LIB))
218  Print("// ** executing %s\n", buf);
219  fclose(rc);
220  newFile(buf);
221  }
222  }
223 
224  /* start shell */
226  {
228  char *linkname=(char*) feOptValue(FE_OPT_LINK);
229  if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
230  {
231  return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
232  //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
233  //exit(0);
234  }
235  }
236  setjmp(si_start_jmpbuf);
237  yyparse();
238  m2_end(0);
239  return 0;
240 }
feOptIndex
Definition: feOptGen.h:15
jmp_buf si_start_jmpbuf
Definition: cntrlc.cc:108
int status int fd
Definition: si_signals.h:58
#define TEST_V_QUIET
Definition: options.h:127
#define optional_argument
Definition: fegetopt.h:101
char *(* fe_fgets_stdin)(const char *pr, char *s, int size)
Definition: feread.cc:33
void pyobject_setup()
initialize blackbox support for pyobject; functionilty os autoloaded on demand
#define MAXPATHLEN
Definition: omRet2Info.c:22
int sdb_flags
Definition: sdb.cc:32
#define Print
Definition: emacs.cc:83
char * fe_optarg
Definition: fegetopt.c:96
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
#define omInitGetBackTrace()
#define V_LOAD_LIB
Definition: options.h:45
void omInitRet_2_Info(const char *argv0)
Definition: omRet2Info.c:34
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:418
void m2_end(int i)
Definition: misc_ip.cc:1074
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
Definition: cf_defs.h:36
#define TRUE
Definition: auxiliary.h:144
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition: feOpt.cc:153
int fe_getopt_long(int argc, char *const *argv, const char *options, const struct fe_option *long_options, int *opt_index)
Definition: fegetopt.c:666
#define MAKE_DISTRIBUTION
Definition: distrib.h:1
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:78
Voice * feInitStdin(Voice *pp)
Definition: fevoices.cc:635
#define assume(x)
Definition: mod2.h:405
int mmInit(void)
Definition: tesths.cc:55
int status int void * buf
Definition: si_signals.h:58
struct fe_option feOptSpec[]
int siInit(char *)
Definition: misc_ip.cc:1194
void On(int sw)
switches
#define DIR_SEPP
Definition: feResource.h:7
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:46
void countedref_init()
Definition: countedref.h:458
int i
Definition: cfEzgcd.cc:123
int yyparse(void)
Definition: grammar.cc:2168
short errorreported
Definition: feFopen.cc:22
char * feArgv0
Definition: feResource.cc:19
#define BVERBOSE(a)
Definition: options.h:33
char name(const Variable &v)
Definition: variable.h:95
#define NULL
Definition: omList.c:10
#define VERSION
Definition: mod2.h:21
#define LONG_OPTION_RETURN
Definition: feOptTab.h:4
Voice * currentVoice
Definition: fevoices.cc:55
void init_signals()
Definition: cntrlc.cc:575
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:169
BOOLEAN newFile(char *fname, FILE *f)
Definition: fevoices.cc:127
feOptIndex feGetOptIndex(const char *name)
Definition: feOpt.cc:104
int fe_optind
Definition: fegetopt.c:111
const char SHORT_OPTS_STRING[]
Definition: feOpt.cc:29
#define Warn
Definition: emacs.cc:80
#define omStrDup(s)
Definition: omAllocDecl.h:263
int mmInit ( void  )

Definition at line 55 of file tesths.cc.

56 {
57 #if defined(OMALLOC_USES_MALLOC) || defined(X_OMALLOC)
58  /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
59  /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
60  /* do not rely on the default in Singular as libsingular may be different */
61  mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc);
62 #else
63  mp_set_memory_functions(malloc,reallocSize,freeSize);
64 #endif
65  return 1;
66 }
void omFreeSizeFunc(void *addr, size_t size)
void * omReallocSizeFunc(void *old_addr, size_t old_size, size_t new_size)
void * malloc(size_t size)
Definition: omalloc.c:98
#define freeSize
Definition: omAllocFunc.c:13
#define reallocSize
Definition: omAllocFunc.c:15
void * omMallocFunc(size_t size)
int siInit ( char *  )

Definition at line 1194 of file misc_ip.cc.

1195 {
1196 // factory default settings: -----------------------------------------------
1197  On(SW_USE_EZGCD);
1199  //On(SW_USE_FF_MOD_GCD);
1200  On(SW_USE_EZGCD_P);
1201  On(SW_USE_QGCD);
1202  Off(SW_USE_NTL_SORT); // may be changed by an command line option
1204 
1205 // memory initialization: -----------------------------------------------
1206  om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc;
1207 #ifndef OM_NDEBUG
1208 #ifndef __OPTIMIZE__
1209  om_Opts.ErrorHook = dErrorBreak;
1210 #else
1211  om_Opts.Keep = 0; /* !OM_NDEBUG, __OPTIMIZE__*/
1212 #endif
1213 #else
1214  om_Opts.Keep = 0; /* OM_NDEBUG */
1215 #endif
1216  omInitInfo();
1217 
1218 // options ---------------------------------------------------------------
1219  si_opt_1=0;
1220 // interpreter tables etc.: -----------------------------------------------
1221  memset(&sLastPrinted,0,sizeof(sleftv));
1223 
1224  extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc
1225 
1226  basePack=(package)omAlloc0(sizeof(*basePack));
1228  idhdl h;
1229  h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
1230  IDPACKAGE(h)->language = LANG_TOP;
1231  IDPACKAGE(h)=basePack;
1232  currPackHdl=h;
1233  basePackHdl=h;
1234 
1235  coeffs_BIGINT = nInitChar(n_Q,(void*)1);
1236 
1237 #if 1
1238  // def HAVE_POLYEXTENSIONS
1239  if(TRUE)
1240  {
1242  assume(type == n_algExt);
1243 
1244  type = nRegister(n_transExt, ntInitChar);
1245  assume(type == n_transExt);
1246 
1247  (void)type;
1248  }
1249 #endif
1250 
1251 // random generator: -----------------------------------------------
1252  int t=initTimer();
1253  if (t==0) t=1;
1254  initRTimer();
1255  siSeed=t;
1256  factoryseed(t);
1257  siRandomStart=t;
1258  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
1259 
1260 // ressource table: ----------------------------------------------------
1261  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
1262  // hack such that all shared' libs in the bindir are loaded correctly
1264 
1265 // singular links: --------------------------------------------------
1266  slStandardInit();
1267  myynest=0;
1268 // semapohore 0 -----------------------------------------------------
1269  int cpus=2;
1270  int cpu_n;
1271  #ifdef _SC_NPROCESSORS_ONLN
1272  if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n;
1273  #elif defined(_SC_NPROCESSORS_CONF)
1274  if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n;
1275  #endif
1276  feSetOptValue(FE_OPT_CPUS, cpus);
1277 
1278 #ifdef SINGULAR_4_1
1279 // default coeffs
1280  {
1281  idhdl h;
1282  h=enterid(omStrDup("QQ"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1283  IDDATA(h)=(char*)nInitChar(n_Q,NULL);
1284  h=enterid(omStrDup("ZZ"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1285  IDDATA(h)=(char*)nInitChar(n_Z,NULL);
1286  //h=enterid(omStrDup("RR"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1287  //IDDATA(h)=(char*)nInitChar(n_R,NULL);
1288  //h=enterid(omStrDup("CC"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1289  //IDDATA(h)=(char*)nInitChar(n_long_C,NULL);
1291  if (t!=n_unknown)
1292  {
1293  h=enterid(omStrDup("AE"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1294  IDDATA(h)=(char*)nInitChar(t,NULL);
1295  }
1297  if (t!=n_unknown)
1298  {
1299  h=enterid(omStrDup("QAE"),0/*level*/, CRING_CMD,&(basePack->idroot),FALSE /*init*/,FALSE /*search*/);
1300  IDDATA(h)=(char*)nInitChar(t,NULL);
1301  }
1303  if (n_pAE!=n_unknown)
1304  {
1305  iiAddCproc("kernel","pAE",FALSE,ii_pAE_init);
1306  }
1307  }
1308 #endif
1309 // loading standard.lib -----------------------------------------------
1310  if (! feOptValue(FE_OPT_NO_STDLIB))
1311  {
1312  BITSET save1,save2;
1313  SI_SAVE_OPT(save1,save2);
1314  si_opt_2 &= ~Sy_bit(V_LOAD_LIB);
1315  iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
1316  SI_RESTORE_OPT(save1,save2);
1317  }
1318  errorreported = 0;
1319 }
int iiInitArithmetic()
initialisation of arithmetic structured data
Definition: iparith.cc:8898
ip_package * package
Definition: structs.h:46
void omSingOutOfMemoryFunc()
Definition: misc_ip.cc:1164
unsigned si_opt_1
Definition: options.c:5
BOOLEAN n_AEInitChar(coeffs r, void *)
Definition: OPAE.cc:339
void factoryseed(int s)
random seed initializer
Definition: cf_random.cc:176
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
void Off(int sw)
switches
idhdl currPackHdl
Definition: ipid.cc:60
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: algext.cc:1389
used for all transcendental extensions, i.e., the top-most extension in an extension tower is transce...
Definition: coeffs.h:37
#define FALSE
Definition: auxiliary.h:140
#define V_LOAD_LIB
Definition: options.h:45
static const int SW_USE_EZGCD_P
set to 1 to use EZGCD over F_q
Definition: cf_defs.h:34
rational (GMP) numbers
Definition: coeffs.h:30
BOOLEAN n_QAEInitChar(coeffs r, void *)
Definition: OPAEQ.cc:331
#define IDROOT
Definition: ipid.h:20
int siRandomStart
Definition: cntrlc.cc:109
static const int SW_USE_NTL_SORT
set to 1 to sort factors in a factorization
Definition: cf_defs.h:36
#define TRUE
Definition: auxiliary.h:144
void * value
Definition: fegetopt.h:93
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition: feOpt.cc:153
void feInitResources(const char *argv0)
Definition: feResource.cc:164
void WerrorS(const char *s)
Definition: feFopen.cc:23
void initRTimer()
Definition: timer.cc:158
static n_coeffType n_pAE
Definition: misc_ip.cc:1175
idhdl basePackHdl
Definition: ipid.cc:61
#define BITSET
Definition: structs.h:17
coeffs coeffs_BIGINT
Definition: ipid.cc:53
#define Sy_bit(x)
Definition: options.h:30
BOOLEAN iiLibCmd(char *newlib, BOOLEAN autoexport, BOOLEAN tellerror, BOOLEAN force)
Definition: iplib.cc:801
Definition: idrec.h:34
omOpts_t om_Opts
Definition: omOpts.c:11
#define IDPACKAGE(a)
Definition: ipid.h:138
int myynest
Definition: febase.cc:46
idhdl enterid(const char *s, int lev, int t, idhdl *root, BOOLEAN init, BOOLEAN search)
Definition: ipid.cc:256
Definition: tok.h:56
#define SI_RESTORE_OPT(A, B)
Definition: options.h:22
void omInitInfo()
Definition: omStats.c:17
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
Definition: numbers.cc:507
#define assume(x)
Definition: mod2.h:405
struct fe_option feOptSpec[]
only used if HAVE_RINGS is defined: ?
Definition: coeffs.h:41
void On(int sw)
switches
static const int SW_USE_CHINREM_GCD
set to 1 to use modular gcd over Z
Definition: cf_defs.h:38
short errorreported
Definition: feFopen.cc:22
BOOLEAN n_pAEInitChar(coeffs r, void *p)
Definition: OPAEp.cc:351
n_coeffType
Definition: coeffs.h:26
char name(const Variable &v)
Definition: variable.h:95
#define NULL
Definition: omList.c:10
int siSeed
Definition: sirandom.c:29
used for all algebraic extensions, i.e., the top-most extension in an extension tower is algebraic ...
Definition: coeffs.h:34
package basePack
Definition: ipid.cc:63
static const int SW_USE_QGCD
set to 1 to use Encarnacion GCD over Q(a)
Definition: cf_defs.h:40
static const int SW_USE_EZGCD
set to 1 to use EZGCD over Z
Definition: cf_defs.h:32
package currPack
Definition: ipid.cc:62
int rtyp
Definition: subexpr.h:92
#define SI_SAVE_OPT(A, B)
Definition: options.h:19
sleftv sLastPrinted
Definition: subexpr.cc:55
int initTimer()
Definition: timer.cc:69
int iiAddCproc(const char *libname, const char *procname, BOOLEAN pstatic, BOOLEAN(*func)(leftv res, leftv v))
Definition: iplib.cc:991
#define IDDATA(a)
Definition: ipid.h:125
unsigned si_opt_2
Definition: options.c:6
static Poly * h
Definition: janet.cc:978
static BOOLEAN ii_pAE_init(leftv res, leftv a)
Definition: misc_ip.cc:1176
#define NONE
Definition: tok.h:170
void dErrorBreak()
Definition: dError.cc:141
#define omAlloc0(size)
Definition: omAllocDecl.h:211
void(* factoryError)(const char *s)
Definition: cf_util.cc:75
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:316
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
Definition: transext.cc:2370
#define omStrDup(s)
Definition: omAllocDecl.h:263