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