source: git/Singular/tesths.cc @ 0dd77c2

fieker-DuValspielwiese
Last change on this file since 0dd77c2 was 8017e9, checked in by Hans Schoenemann <hannes@…>, 14 years ago
selecting gcd algorithms git-svn-id: file:///usr/local/Singular/svn/trunk@12825 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 7.8 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 "mod2.h"
18#include "tok.h"
19#include "options.h"
20#include "ipshell.h"
21#include "febase.h"
22#include "cntrlc.h"
23#include "omalloc.h"
24#include "silink.h"
25#include "ipid.h"
26#include "timer.h"
27#include "sdb.h"
28#include "fegetopt.h"
29#include "feOpt.h"
30#include "distrib.h"
31#include "version.h"
32#include "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 <si_gmp.h>
44
45int mmInit( void );
46int mmIsInitialized=mmInit();
47
48extern "C"
49{
50  void omSingOutOfMemoryFunc()
51  {
52    fprintf(stderr, "\nerror: 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    /* solution: correctly check OMALLOC_USES_MALLOC from 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  basePack=(package)omAlloc0(sizeof(*basePack));
97  currPack=basePack;
98  idhdl h;
99  h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
100  IDPACKAGE(h)->language = LANG_TOP;
101  IDPACKAGE(h)=basePack;
102  currPackHdl=h;
103  basePackHdl=h;
104
105  slStandardInit();
106  myynest=0;
107  if (! feOptValue(FE_OPT_NO_STDLIB))
108  {
109    int vv=verbose;
110    verbose &= ~Sy_bit(V_LOAD_LIB);
111    iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
112    verbose=vv;
113  }
114  errorreported = 0;
115}
116#endif
117
118#if ! defined(LIBSINGULAR)
119/*0 implementation*/
120int main(          /* main entry to Singular */
121    int argc,      /* number of parameter */
122    char** argv)   /* parameter array */
123{
124#ifdef HAVE_FACTORY
125  On(SW_USE_NTL);
126  Off(SW_USE_GCD_P);
127  On(SW_USE_NTL_GCD_0); // On -> seg11 in Old/algnorm, Old/factor...
128  On(SW_USE_NTL_GCD_P); // On -> cyle in Short/brnoeth_s: fixed
129  On(SW_USE_EZGCD);
130  On(SW_USE_CHINREM_GCD);
131  //On(SW_USE_fieldGCD);
132  //On(SW_USE_EZGCD_P);
133  On(SW_USE_QGCD);
134  Off(SW_USE_NTL_SORT); // may be changed by an command line option
135#endif
136
137#ifdef INIT_BUG
138  jjInitTab1();
139#endif
140#ifdef GENTABLE
141  extern void ttGen1();
142  extern void ttGen2b();
143  extern void ttGen4();
144  extern void mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
145  mpsr_ttGen();
146  ttGen4();
147  ttGen1();
148  ttGen2b();
149#else
150  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
151  omInitRet_2_Info(argv[0]);
152  omInitGetBackTrace();
153
154  /* initialize components */
155  siRandomStart=inits();
156  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
157  int optc, option_index;
158  const char* errormsg;
159
160  // do this first, because -v might print version path
161  feInitResources(argv[0]);
162  iiInitArithmetic();
163
164  // parse command line options
165  while((optc = fe_getopt_long(argc, argv,
166                               SHORT_OPTS_STRING, feOptSpec, &option_index))
167        != EOF)
168  {
169    if (optc == '?' || optc == 0)
170    {
171      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
172      exit(1);
173    }
174
175    if (optc != LONG_OPTION_RETURN)
176      option_index = feGetOptIndex(optc);
177
178    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
179
180    if (fe_optarg == NULL &&
181        (feOptSpec[option_index].type == feOptBool ||
182         feOptSpec[option_index].has_arg == optional_argument))
183      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
184    else
185      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
186
187    if (errormsg)
188    {
189      if (fe_optarg == NULL)
190        fprintf(stderr, "Error: Option '--%s' %s\n",
191               feOptSpec[option_index].name, errormsg);
192      else
193        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
194               feOptSpec[option_index].name, fe_optarg, errormsg);
195      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
196      exit(1);
197    }
198    if (optc == 'h') exit(0);
199  }
200
201  /* say hello */
202  {
203    basePack=(package)omAlloc0(sizeof(*basePack));
204    currPack=basePack;
205    idhdl h;
206    h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
207    IDPACKAGE(h)->language = LANG_TOP;
208    IDPACKAGE(h)=basePack;
209    currPackHdl=h;
210    basePackHdl=h;
211  }
212  if (TEST_V_QUIET)
213  {
214    (printf)(
215"                     SINGULAR                             /"
216#ifndef MAKE_DISTRIBUTION
217"  Development"
218#endif
219"\n"
220" A Computer Algebra System for Polynomial Computations   /   version %s\n"
221"                                                       0<\n"
222"     by: G.-M. Greuel, G. Pfister, H. Schoenemann        \\   %s\n"
223"FB Mathematik der Universitaet, D-67653 Kaiserslautern    \\\n"
224, S_VERSION1,S_VERSION2);
225  }
226  else
227  {
228#ifdef HAVE_FACTORY
229    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
230#endif
231#ifdef HAVE_SDB
232    sdb_flags = 0;
233#endif
234    dup2(1,2);
235    /* alternative:
236    *    memcpy(stderr,stdout,sizeof(FILE));
237    */
238  }
239  slStandardInit();
240  myynest=0;
241  if (! feOptValue(FE_OPT_NO_STDLIB))
242  {
243    int vv=verbose;
244    verbose &= ~Sy_bit(V_LOAD_LIB);
245    iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
246    verbose=vv;
247  }
248  errorreported = 0;
249
250  // and again, ifdef OM_NDEBUG this call is undef'ed
251  // otherwise, it marks all memory allocated so far as static
252  // i.e. as memory which is not mention on omPrintUsedAddr:
253  //omMarkMemoryAsStatic();
254
255  setjmp(si_start_jmpbuf);
256
257  // Now, put things on the stack of stuff to do
258  // Last thing to do is to execute given scripts
259  if (fe_optind < argc)
260  {
261    int i = argc - 1;
262    FILE *fd;
263    while (i >= fe_optind)
264    {
265      if ((fd = feFopen(argv[i], "r")) == NULL)
266      {
267        Warn("Can not open %s", argv[i]);
268      }
269      else
270      {
271        fclose(fd);
272        newFile(argv[i]);
273      }
274      i--;
275    }
276  }
277  else
278  {
279    currentVoice=feInitStdin(NULL);
280  }
281
282  // before scripts, we execute -c, if it was given
283  if (feOptValue(FE_OPT_EXECUTE) != NULL)
284    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
285
286  // first thing, however, is to load .singularrc from Singularpath
287  // and cwd/$HOME (in that order).
288  if (! feOptValue(FE_OPT_NO_RC))
289  {
290    char buf[MAXPATHLEN];
291    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
292    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
293    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
294
295    if (rc != NULL)
296    {
297      if (BVERBOSE(V_LOAD_LIB))
298        Print("// ** executing %s\n", buf);
299      fclose(rc);
300      newFile(buf);
301    }
302  }
303
304  /* start shell */
305  if (fe_fgets_stdin==fe_fgets_dummy)
306  {
307#ifdef HAVE_MPSR
308    BatchDoProc batch_do = slInitMPBatchDo();
309    if (batch_do != NULL)
310      return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
311                         (char*) feOptValue(FE_OPT_MPHOST));
312    else
313      return 1;
314#else
315    assume(0);
316#endif
317  }
318  setjmp(si_start_jmpbuf);
319  yyparse();
320  m2_end(0);
321#endif
322  return 0;
323}
324#endif // not LIBSINGULAR
325
Note: See TracBrowser for help on using the repository browser.