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 #include "kernel/mod2.h"
11 #include "omalloc/omalloc.h"
12 #include "misc/options.h"
13 #include "factory/factory.h"
15 #include "Singular/fevoices.h"
16 #include "kernel/oswrapper/timer.h"
17 
18 #include "ipshell.h"
19 #include "cntrlc.h"
20 #include "links/silink.h"
21 #include "ipid.h"
22 #include "sdb.h"
23 #include "feOpt.h"
24 #include "distrib.h"
25 #include "mmalloc.h"
26 #include "tok.h"
27 #include "fegetopt.h"
28 
29 #include "Singular/countedref.h"
31 
32 #include <unistd.h>
33 #ifdef HAVE_NTL
34 #include <NTL/config.h>
35 #endif
36 
37 
38 extern int siInit(char *);
39 
40 int mmInit( void )
41 {
42 #ifndef X_OMALLOC
43 #if defined(OMALLOC_USES_MALLOC)
44  /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
45  /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
46  /* do not rely on the default in Singular as libsingular may be different */
47  mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc);
48 #else
49  mp_set_memory_functions(malloc,reallocSize,freeSize);
50 #endif
51 #endif
52  return 1;
53 }
54 
55 /*0 implementation*/
56 int main( /* main entry to Singular */
57  int argc, /* number of parameter */
58  char** argv) /* parameter array */
59 {
60  mmInit();
61  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
62  omInitRet_2_Info(argv[0]);
64 
65  siInit(argv[0]);
66  init_signals();
67  #ifdef HAVE_NTL
68  #if NTL_MAJOR_VERSION>=10
69  #ifdef NTL_THREAD_BOOST
70  SetNumThreads(feOptValue(FE_OPT_CPUS));
71  #endif
72  #endif
73  #endif
74 
75  // parse command line options
76  int optc, option_index;
77  const char* errormsg;
78  while((optc = fe_getopt_long(argc, argv,
79  SHORT_OPTS_STRING, feOptSpec, &option_index))
80  != EOF)
81  {
82  if (optc == '?' || optc == 0)
83  {
84  fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
85  exit(1);
86  }
87 
88  if (optc != LONG_OPTION_RETURN)
89  option_index = feGetOptIndex(optc);
90 
91  assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
92 
93  if (fe_optarg == NULL &&
94  (feOptSpec[option_index].type == feOptBool ||
95  feOptSpec[option_index].has_arg == optional_argument))
96  errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
97  else
98  errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
99 
100  if (errormsg)
101  {
102  if (fe_optarg == NULL)
103  fprintf(stderr, "Error: Option '--%s' %s\n",
104  feOptSpec[option_index].name, errormsg);
105  else
106  fprintf(stderr, "Error: Option '--%s=%s' %s\n",
107  feOptSpec[option_index].name, fe_optarg, errormsg);
108  fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
109  exit(1);
110  }
111  if (optc == 'h') exit(0);
112  switch(option_index)
113  {
114  case FE_OPT_DUMP_VERSIONTUPLE:
115  exit(0);
116  break;
117  default: ;
118  }
119  }
120 
121  /* say hello */
122 
123  if (TEST_V_QUIET)
124  {
125  (printf)(
126 " SINGULAR /"
127 #ifndef MAKE_DISTRIBUTION
128 " Development"
129 #endif
130 "\n"
131 " A Computer Algebra System for Polynomial Computations / version %s\n"
132 " 0<\n"
133 " by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann \\ %s\n"
134 "FB Mathematik der Universitaet, D-67653 Kaiserslautern \\ Debian " DEB_PKG_VERSION "\n"
135 , VERSION, VERSION_DATE);
136  if (feOptValue(FE_OPT_NO_SHELL)) WarnS("running in restricted mode:"
137  " shell invocation and links are disallowed");
138  }
139  else
140  {
141  if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
142  dup2(1,2);
143  /* alternative:
144  * memcpy(stderr,stdout,sizeof(FILE));
145  */
146  }
147 
148 #ifdef SINGULAR_PYOBJECT_SETUP_H
149  pyobject_setup();
150 #endif
151 #ifdef SI_COUNTEDREF_AUTOLOAD
152  countedref_init();
153 #endif
154  errorreported = 0;
155 
156  // -- example for "static" modules ------
157  //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
158  //module_help_main("huhu.so","Help for huhu\nhaha\n");
159  //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
160  setjmp(si_start_jmpbuf);
161 
162  // Now, put things on the stack of stuff to do
163  // Last thing to do is to execute given scripts
164  if (fe_optind < argc)
165  {
166  int i = argc - 1;
167  FILE *fd;
168  while (i >= fe_optind)
169  {
170  if ((fd = feFopen(argv[i], "r")) == NULL)
171  {
172  Warn("Can not open %s", argv[i]);
173  }
174  else
175  {
176  fclose(fd);
177  newFile(argv[i]);
178  }
179  i--;
180  }
181  }
182  else
183  {
185  }
186 
187  // before scripts, we execute -c, if it was given
188  if (feOptValue(FE_OPT_EXECUTE) != NULL)
189  newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
190 
191  // first thing, however, is to load .singularrc from Singularpath
192  // and cwd/$HOME (in that order).
193  if (! feOptValue(FE_OPT_NO_RC))
194  {
195  char buf[MAXPATHLEN];
196  FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
197  if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
198  if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
199 
200  if (rc != NULL)
201  {
202  if (BVERBOSE(V_LOAD_LIB))
203  Print("// ** executing %s\n", buf);
204  fclose(rc);
205  newFile(buf);
206  }
207  }
208 
209  /* start shell */
211  {
213  char *linkname=(char*) feOptValue(FE_OPT_LINK);
214  if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
215  {
216  return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
217  //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
218  //exit(0);
219  }
220  else
221  {
222  Print("** missing arguments: -b requires --link/--MPhost/--MPport\n");
223  return 1;
224  }
225  }
226  setjmp(si_start_jmpbuf);
227  yyparse();
228  m2_end(0);
229  return 0;
230 }
231 
feOptIndex
Definition: feOptGen.h:15
jmp_buf si_start_jmpbuf
Definition: cntrlc.cc:95
int status int fd
Definition: si_signals.h:59
#define TEST_V_QUIET
Definition: options.h:131
#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:34
void pyobject_setup()
initialize blackbox support for pyobject; functionilty os autoloaded on demand
#define MAXPATHLEN
Definition: omRet2Info.c:22
#define Print
Definition: emacs.cc:80
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:56
#define omInitGetBackTrace()
#define V_LOAD_LIB
Definition: options.h:47
char * fe_fgets_dummy(const char *, char *, int)
Definition: feread.cc:451
BOOLEAN newFile(char *fname)
Definition: fevoices.cc:119
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:98
const char * feSetOptValue(feOptIndex opt, char *optarg)
Definition: feOpt.cc:151
This file defines reusable classes supporting reference counted interpreter objects and initiates the...
#define WarnS
Definition: emacs.cc:78
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)
#define omInitRet_2_Info(argv0)
Definition: xalloc.h:318
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:65
Voice * feInitStdin(Voice *pp)
Definition: fevoices.cc:655
#define assume(x)
Definition: mod2.h:390
int mmInit(void)
Definition: tesths.cc:40
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:1316
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:47
void countedref_init()
Definition: countedref.h:458
int i
Definition: cfEzgcd.cc:125
char name(const Variable &v)
Definition: factory.h:180
#define freeSize
Definition: omAllocFunc.c:15
int yyparse(void)
Definition: grammar.cc:2111
#define reallocSize
Definition: omAllocFunc.c:17
short errorreported
Definition: feFopen.cc:23
char * feArgv0
Definition: feResource.cc:19
#define BVERBOSE(a)
Definition: options.h:35
void m2_end(int i)
Definition: misc_ip.cc:1096
#define NULL
Definition: omList.c:12
#define VERSION
Definition: mod2.h:18
#define LONG_OPTION_RETURN
Definition: feOptTab.h:4
Voice * currentVoice
Definition: fevoices.cc:47
void init_signals()
init signal handlers and error handling for libraries: NTL, factory
Definition: cntrlc.cc:559
void * omMallocFunc(size_t size)
void newBuffer(char *s, feBufferTypes t, procinfo *pi, int lineno)
Definition: fevoices.cc:156
feOptIndex feGetOptIndex(const char *name)
Definition: feOpt.cc:101
int fe_optind
Definition: fegetopt.c:111
const char SHORT_OPTS_STRING[]
Definition: feOpt.cc:26
#define Warn
Definition: emacs.cc:77
#define omStrDup(s)
Definition: omAllocDecl.h:263