source: git/Singular/tesths.cc @ b7b65ee

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