source: git/Singular/tesths.cc @ c4ebdd

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