source: git/Singular/tesths.cc @ 599326

spielwiese
Last change on this file since 599326 was 599326, checked in by Kai Krüger <krueger@…>, 14 years ago
Anne, Kai, Frank: - changes to #include "..." statements to allow cleaner build structure - affected directories: omalloc, kernel, Singular - not yet done: IntergerProgramming git-svn-id: file:///usr/local/Singular/svn/trunk@13032 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5
6/*
7* ABSTRACT - initialize SINGULARs components, run Script and start SHELL
8*/
9
10#include <unistd.h>
11#include <string.h>
12#include <stdio.h>
13#include <stddef.h>
14#include <stdlib.h>
15#include <time.h>
16#include <errno.h>
17#include <Singular/mod2.h>
18#include <Singular/tok.h>
19#include <kernel/options.h>
20#include <Singular/ipshell.h>
21#include <kernel/febase.h>
22#include <Singular/cntrlc.h>
23#include <omalloc.h>
24#include <Singular/silink.h>
25#include <Singular/ipid.h>
26#include <kernel/timer.h>
27#include <Singular/sdb.h>
28#include <kernel/fegetopt.h>
29#include <Singular/feOpt.h>
30#include <Singular/distrib.h>
31#include <Singular/version.h>
32#include <Singular/slInit.h>
33
34#ifdef HAVE_FACTORY
35#define SI_DONT_HAVE_GLOBAL_VARS
36#include <factory.h>
37#endif
38
39extern int iiInitArithmetic();
40
41const char *singular_date=__DATE__ " " __TIME__;
42
43#include <kernel/si_gmp.h>
44
45int mmInit( void );
46int mmIsInitialized=mmInit();
47
48extern "C"
49{
50  void omSingOutOfMemoryFunc()
51  {
52    fprintf(stderr, "\nSingular error: no more memory\n");
53    omPrintStats(stderr);
54    m2_end(14);
55    /* should never get here */
56    exit(1);
57  }
58}
59
60int mmInit( void )
61{
62  if(mmIsInitialized==0)
63  {
64
65#ifndef LIBSINGULAR
66#if defined(OMALLOC_USES_MALLOC) || defined(X_OMALLOC)
67    /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
68    /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
69#include <omalloc.h>
70    /* do not rely on the default in Singular as libsingular may be different */
71    mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc);
72#else
73    mp_set_memory_functions(malloc,reallocSize,freeSize);
74#endif
75#endif // ifndef LIBSINGULAR
76    om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc;
77#ifndef OM_NDEBUG
78    om_Opts.ErrorHook = dErrorBreak;
79#endif
80    omInitInfo();
81#ifdef OM_SING_KEEP
82    om_Opts.Keep = OM_SING_KEEP;
83#endif
84  }
85  mmIsInitialized=1;
86  return 1;
87}
88
89#ifdef LIBSINGULAR
90int siInit(char *name)
91{
92  // hack such that all shared' libs in the bindir are loaded correctly
93  feInitResources(name);
94  iiInitArithmetic();
95
96#if 0
97  SingularBuilder::Ptr SingularInstance = SingularBuilder::instance();
98#else
99  basePack=(package)omAlloc0(sizeof(*basePack));
100  currPack=basePack;
101  idhdl h;
102  h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
103  IDPACKAGE(h)->language = LANG_TOP;
104  IDPACKAGE(h)=basePack;
105  currPackHdl=h;
106  basePackHdl=h;
107
108  slStandardInit();
109  myynest=0;
110#endif
111  if (! feOptValue(FE_OPT_NO_STDLIB))
112  {
113    int vv=verbose;
114    verbose &= ~Sy_bit(V_LOAD_LIB);
115    iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
116    verbose=vv;
117  }
118  errorreported = 0;
119}
120#endif
121
122#if ! defined(LIBSINGULAR)
123/*0 implementation*/
124int main(          /* main entry to Singular */
125    int argc,      /* number of parameter */
126    char** argv)   /* parameter array */
127{
128#ifdef HAVE_FACTORY
129  On(SW_USE_NTL);
130  Off(SW_USE_GCD_P);
131  On(SW_USE_NTL_GCD_0); // On -> seg11 in Old/algnorm, Old/factor...
132  On(SW_USE_NTL_GCD_P); // On -> cyle in Short/brnoeth_s: fixed
133  On(SW_USE_EZGCD);
134  On(SW_USE_CHINREM_GCD);
135  //On(SW_USE_fieldGCD);
136  //On(SW_USE_EZGCD_P);
137  On(SW_USE_QGCD);
138  Off(SW_USE_NTL_SORT); // may be changed by an command line option
139#endif
140
141#ifdef INIT_BUG
142  jjInitTab1();
143#endif
144#ifdef GENTABLE
145  extern void ttGen1();
146  extern void ttGen2b();
147  extern void ttGen4();
148  extern void mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
149  extern char *iparith_inc;
150  #ifdef HAVE_MPSR
151  extern char *mpsr_Tok_inc;
152  #endif
153  mpsr_ttGen();
154  ttGen4();
155  ttGen1();
156  ttGen2b();
157  rename(iparith_inc,"iparith.inc");
158  rename("plural_cmd.xx","plural_cmd.inc");
159  #ifdef HAVE_MPSR
160  rename(mpsr_Tok_inc,"mpsr_Tok.inc");
161  #endif
162#else
163  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
164  omInitRet_2_Info(argv[0]);
165  omInitGetBackTrace();
166
167  /* initialize components */
168  siRandomStart=inits();
169  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
170  int optc, option_index;
171  const char* errormsg;
172
173  // do this first, because -v might print version path
174  feInitResources(argv[0]);
175  iiInitArithmetic();
176
177  // parse command line options
178  while((optc = fe_getopt_long(argc, argv,
179                               SHORT_OPTS_STRING, feOptSpec, &option_index))
180        != EOF)
181  {
182    if (optc == '?' || optc == 0)
183    {
184      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
185      exit(1);
186    }
187
188    if (optc != LONG_OPTION_RETURN)
189      option_index = feGetOptIndex(optc);
190
191    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
192
193    if (fe_optarg == NULL &&
194        (feOptSpec[option_index].type == feOptBool ||
195         feOptSpec[option_index].has_arg == optional_argument))
196      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
197    else
198      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
199
200    if (errormsg)
201    {
202      if (fe_optarg == NULL)
203        fprintf(stderr, "Error: Option '--%s' %s\n",
204               feOptSpec[option_index].name, errormsg);
205      else
206        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
207               feOptSpec[option_index].name, fe_optarg, errormsg);
208      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
209      exit(1);
210    }
211    if (optc == 'h') exit(0);
212  }
213
214  /* say hello */
215#if 0
216  SingularBuilder::Ptr SingularInstance = SingularBuilder::instance();
217#else
218  {
219    basePack=(package)omAlloc0(sizeof(*basePack));
220    currPack=basePack;
221    idhdl h;
222    h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
223    IDPACKAGE(h)->language = LANG_TOP;
224    IDPACKAGE(h)=basePack;
225    currPackHdl=h;
226    basePackHdl=h;
227  }
228#endif
229  if (TEST_V_QUIET)
230  {
231    (printf)(
232"                     SINGULAR                             /"
233#ifndef MAKE_DISTRIBUTION
234"  Development"
235#endif
236"\n"
237" A Computer Algebra System for Polynomial Computations   /   version %s\n"
238"                                                       0<\n"
239"     by: G.-M. Greuel, G. Pfister, H. Schoenemann        \\   %s\n"
240"FB Mathematik der Universitaet, D-67653 Kaiserslautern    \\\n"
241, S_VERSION1,S_VERSION2);
242  }
243  else
244  {
245#ifdef HAVE_FACTORY
246    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
247#endif
248#ifdef HAVE_SDB
249    sdb_flags = 0;
250#endif
251    dup2(1,2);
252    /* alternative:
253    *    memcpy(stderr,stdout,sizeof(FILE));
254    */
255  }
256  slStandardInit();
257  myynest=0;
258  if (! feOptValue(FE_OPT_NO_STDLIB))
259  {
260    int vv=verbose;
261    verbose &= ~Sy_bit(V_LOAD_LIB);
262    iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
263    verbose=vv;
264  }
265  errorreported = 0;
266
267  // and again, ifdef OM_NDEBUG this call is undef'ed
268  // otherwise, it marks all memory allocated so far as static
269  // i.e. as memory which is not mention on omPrintUsedAddr:
270  //omMarkMemoryAsStatic();
271
272  setjmp(si_start_jmpbuf);
273
274  // Now, put things on the stack of stuff to do
275  // Last thing to do is to execute given scripts
276  if (fe_optind < argc)
277  {
278    int i = argc - 1;
279    FILE *fd;
280    while (i >= fe_optind)
281    {
282      if ((fd = feFopen(argv[i], "r")) == NULL)
283      {
284        Warn("Can not open %s", argv[i]);
285      }
286      else
287      {
288        fclose(fd);
289        newFile(argv[i]);
290      }
291      i--;
292    }
293  }
294  else
295  {
296    currentVoice=feInitStdin(NULL);
297  }
298
299  // before scripts, we execute -c, if it was given
300  if (feOptValue(FE_OPT_EXECUTE) != NULL)
301    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
302
303  // first thing, however, is to load .singularrc from Singularpath
304  // and cwd/$HOME (in that order).
305  if (! feOptValue(FE_OPT_NO_RC))
306  {
307    char buf[MAXPATHLEN];
308    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
309    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
310    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
311
312    if (rc != NULL)
313    {
314      if (BVERBOSE(V_LOAD_LIB))
315        Print("// ** executing %s\n", buf);
316      fclose(rc);
317      newFile(buf);
318    }
319  }
320
321  /* start shell */
322  if (fe_fgets_stdin==fe_fgets_dummy)
323  {
324#ifdef HAVE_MPSR
325    BatchDoProc batch_do = slInitMPBatchDo();
326    if (batch_do != NULL)
327      return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
328                         (char*) feOptValue(FE_OPT_MPHOST));
329    else
330      return 1;
331#else
332    assume(0);
333#endif
334  }
335  setjmp(si_start_jmpbuf);
336  yyparse();
337  m2_end(0);
338#endif
339  return 0;
340}
341#endif // not LIBSINGULAR
342
Note: See TracBrowser for help on using the repository browser.