tesths.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 
5 /*
6 * ABSTRACT - initialize SINGULARs components, run Script and start SHELL
7 */
8 
9 
10 
11 
12 #include <kernel/mod2.h>
13 #include <omalloc/omalloc.h>
14 
15 #include <misc/auxiliary.h>
16 #include <misc/options.h>
17 
18 #include <factory/factory.h>
19 
21 #include <Singular/fevoices.h>
22 #include <kernel/oswrapper/timer.h>
23 
24 // #ifdef HAVE_FANS
25 // #include <callgfanlib/bbcone.h>
26 // #include <callgfanlib/bbpolytope.h>
27 // #include <callgfanlib/bbfan.h>
28 // #include <callgfanlib/gitfan.h>
29 // #endif
30 
31 #include "ipshell.h"
32 #include "cntrlc.h"
33 #include "links/silink.h"
34 #include "ipid.h"
35 #include "sdb.h"
36 #include "feOpt.h"
37 #include "distrib.h"
38 #include "mmalloc.h"
39 #include "tok.h"
40 #include "fegetopt.h"
41 
42 #include <Singular/countedref.h>
44 
45 #include <unistd.h>
46 #include <string.h>
47 #include <stddef.h>
48 #include <stdlib.h>
49 #include <time.h>
50 #include <errno.h>
51 
52 
53 extern int siInit(char *);
54 
55 int mmInit( void )
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 }
67 
68 /*0 implementation*/
69 int main( /* main entry to Singular */
70  int argc, /* number of parameter */
71  char** argv) /* parameter array */
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  dup2(1,2);
149  /* alternative:
150  * memcpy(stderr,stdout,sizeof(FILE));
151  */
152  }
153 
154 #ifdef SINGULAR_PYOBJECT_SETUP_H
155  pyobject_setup();
156 #endif
157 #ifdef SI_COUNTEDREF_AUTOLOAD
158  countedref_init();
159 #endif
160 // #ifdef HAVE_FANS
161 // bbcone_setup();
162 // bbpolytope_setup();
163 // bbfan_setup();
164 // gitfan_setup();
165 // #endif /* HAVE_FANS */
166  errorreported = 0;
167 
168  // -- example for "static" modules ------
169  //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
170  //module_help_main("huhu.so","Help for huhu\nhaha\n");
171  //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
172  setjmp(si_start_jmpbuf);
173 
174  // Now, put things on the stack of stuff to do
175  // Last thing to do is to execute given scripts
176  if (fe_optind < argc)
177  {
178  int i = argc - 1;
179  FILE *fd;
180  while (i >= fe_optind)
181  {
182  if ((fd = feFopen(argv[i], "r")) == NULL)
183  {
184  Warn("Can not open %s", argv[i]);
185  }
186  else
187  {
188  fclose(fd);
189  newFile(argv[i]);
190  }
191  i--;
192  }
193  }
194  else
195  {
197  }
198 
199  // before scripts, we execute -c, if it was given
200  if (feOptValue(FE_OPT_EXECUTE) != NULL)
201  newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
202 
203  // first thing, however, is to load .singularrc from Singularpath
204  // and cwd/$HOME (in that order).
205  if (! feOptValue(FE_OPT_NO_RC))
206  {
207  char buf[MAXPATHLEN];
208  FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
209  if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
210  if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
211 
212  if (rc != NULL)
213  {
214  if (BVERBOSE(V_LOAD_LIB))
215  Print("// ** executing %s\n", buf);
216  fclose(rc);
217  newFile(buf);
218  }
219  }
220 
221  /* start shell */
223  {
225  char *linkname=(char*) feOptValue(FE_OPT_LINK);
226  if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
227  {
228  return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
229  //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
230  //exit(0);
231  }
232  }
233  setjmp(si_start_jmpbuf);
234  yyparse();
235  m2_end(0);
236  return 0;
237 }
238 
feOptIndex
Definition: feOptGen.h:15
jmp_buf si_start_jmpbuf
Definition: cntrlc.cc:102
int status int fd
Definition: si_signals.h:59
#define TEST_V_QUIET
Definition: options.h:127
#define optional_argument
Definition: fegetopt.h:101
void omFreeSizeFunc(void *addr, size_t size)
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
#define Print
Definition: emacs.cc:83
char * fe_optarg
Definition: fegetopt.c:96
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
int main(int argc, char **argv)
Definition: tesths.cc:69
#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
This file defines reusable classes supporting reference counted interpreter objects and initiates the...
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
void * omReallocSizeFunc(void *old_addr, size_t old_size, size_t new_size)
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:72
Voice * feInitStdin(Voice *pp)
Definition: fevoices.cc:651
#define assume(x)
Definition: mod2.h:405
int mmInit(void)
Definition: tesths.cc:55
int status int void * buf
Definition: si_signals.h:59
void * malloc(size_t size)
Definition: omalloc.c:92
struct fe_option feOptSpec[]
int siInit(char *)
Definition: misc_ip.cc:1197
All the auxiliary stuff.
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
#define freeSize
Definition: omAllocFunc.c:13
int yyparse(void)
Definition: grammar.cc:2168
#define reallocSize
Definition: omAllocFunc.c:15
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:57
void init_signals()
Definition: cntrlc.cc:573
void * omMallocFunc(size_t size)
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:171
BOOLEAN newFile(char *fname, FILE *f)
Definition: fevoices.cc:129
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