source: git/Singular/tesths.cc @ 341696

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