source: git/Singular/tesths.cc @ 81d4b2

spielwiese
Last change on this file since 81d4b2 was 81d4b2, checked in by Hans Schoenemann <hannes@…>, 14 years ago
64bit stuff git-svn-id: file:///usr/local/Singular/svn/trunk@12995 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[0e1846]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[341696]4/* $Id$ */
[32df82]5
[0e1846]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>
[32df82]16#include <errno.h>
[0e1846]17#include "mod2.h"
18#include "tok.h"
[210bd9]19#include "options.h"
[0e1846]20#include "ipshell.h"
21#include "febase.h"
22#include "cntrlc.h"
[512a2b]23#include "omalloc.h"
[0e1846]24#include "silink.h"
[7def32f]25#include "ipid.h"
[ea986d]26#include "timer.h"
[473707b]27#include "sdb.h"
[c06a32]28#include "fegetopt.h"
29#include "feOpt.h"
30#include "distrib.h"
31#include "version.h"
[6b32990]32#include "slInit.h"
[c06a32]33
[43d6c5]34#ifdef HAVE_FACTORY
[fda54cc]35#define SI_DONT_HAVE_GLOBAL_VARS
36#include <factory.h>
[43d6c5]37#endif
[40edb03]38
[b6e51b]39extern int iiInitArithmetic();
40
[714503]41const char *singular_date=__DATE__ " " __TIME__;
[923c27]42
[a36f9e8]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
[a1ab2a]89#ifdef LIBSINGULAR
90int siInit(char *name)
91{
92  // hack such that all shared' libs in the bindir are loaded correctly
93  feInitResources(name);
[b372b8b]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;
[a1ab2a]115}
116#endif
117
[672783]118#if ! defined(LIBSINGULAR)
[0e1846]119/*0 implementation*/
120int main(          /* main entry to Singular */
121    int argc,      /* number of parameter */
122    char** argv)   /* parameter array */
123{
[c19758]124#ifdef HAVE_FACTORY
[ff8601]125  On(SW_USE_NTL);
[730230]126  Off(SW_USE_GCD_P);
[e9aa8df]127  On(SW_USE_NTL_GCD_0); // On -> seg11 in Old/algnorm, Old/factor...
[3529bdd]128  On(SW_USE_NTL_GCD_P); // On -> cyle in Short/brnoeth_s: fixed
[a73058]129  On(SW_USE_EZGCD);
[730230]130  On(SW_USE_CHINREM_GCD);
[60bebce]131  //On(SW_USE_fieldGCD);
132  //On(SW_USE_EZGCD_P);
[8017e9]133  On(SW_USE_QGCD);
[3529bdd]134  Off(SW_USE_NTL_SORT); // may be changed by an command line option
[c19758]135#endif
136
[0e1846]137#ifdef INIT_BUG
138  jjInitTab1();
139#endif
140#ifdef GENTABLE
[9c756f]141  extern void ttGen1();
[b6e51b]142  extern void ttGen2b();
[fefe03]143  extern void ttGen4();
[111cfe]144  extern void mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
[44a092]145  extern char *iparith_inc;
[81d4b2]146  #ifdef HAVE_MPSR
[c874cb]147  extern char *mpsr_Tok_inc;
[81d4b2]148  #endif
[111cfe]149  mpsr_ttGen();
[fefe03]150  ttGen4();
[0e1846]151  ttGen1();
[b6e51b]152  ttGen2b();
[44a092]153  rename(iparith_inc,"iparith.inc");
[12a9ac]154  rename("plural_cmd.xx","plural_cmd.inc");
[81d4b2]155  #ifdef HAVE_MPSR
[c874cb]156  rename(mpsr_Tok_inc,"mpsr_Tok.inc");
[81d4b2]157  #endif
[0e1846]158#else
[c232af]159  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
160  omInitRet_2_Info(argv[0]);
161  omInitGetBackTrace();
162
[c06a32]163  /* initialize components */
164  siRandomStart=inits();
[dc25e4]165  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
[eea2b0]166  int optc, option_index;
[a5da6f]167  const char* errormsg;
[eea2b0]168
169  // do this first, because -v might print version path
[c06a32]170  feInitResources(argv[0]);
[b6e51b]171  iiInitArithmetic();
[eea2b0]172
173  // parse command line options
[9b4b45]174  while((optc = fe_getopt_long(argc, argv,
[c06a32]175                               SHORT_OPTS_STRING, feOptSpec, &option_index))
[eea2b0]176        != EOF)
[0e1846]177  {
[8c71e8]178    if (optc == '?' || optc == 0)
[0e1846]179    {
[c06a32]180      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
181      exit(1);
182    }
[e0d91c]183
[c06a32]184    if (optc != LONG_OPTION_RETURN)
185      option_index = feGetOptIndex(optc);
[eea2b0]186
[9b4b45]187    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
[8c71e8]188
189    if (fe_optarg == NULL &&
[c06a32]190        (feOptSpec[option_index].type == feOptBool ||
191         feOptSpec[option_index].has_arg == optional_argument))
192      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
193    else
194      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
[8c71e8]195
[c06a32]196    if (errormsg)
197    {
198      if (fe_optarg == NULL)
[8c71e8]199        fprintf(stderr, "Error: Option '--%s' %s\n",
[c06a32]200               feOptSpec[option_index].name, errormsg);
201      else
[8c71e8]202        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
[c06a32]203               feOptSpec[option_index].name, fe_optarg, errormsg);
204      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
205      exit(1);
[0e1846]206    }
[c06a32]207    if (optc == 'h') exit(0);
[0e1846]208  }
[c06a32]209
[726d50]210  /* say hello */
[77ff8e]211  {
[bd4cb92]212    basePack=(package)omAlloc0(sizeof(*basePack));
213    currPack=basePack;
214    idhdl h;
[3b1a83c]215    h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
[bd4cb92]216    IDPACKAGE(h)->language = LANG_TOP;
217    IDPACKAGE(h)=basePack;
218    currPackHdl=h;
[a3bc95e]219    basePackHdl=h;
[77ff8e]220  }
[6c4db17]221  if (TEST_V_QUIET)
[0e1846]222  {
[50cbdc]223    (printf)(
[3854a98]224"                     SINGULAR                             /"
225#ifndef MAKE_DISTRIBUTION
[9a11fe]226"  Development"
[3854a98]227#endif
228"\n"
[e9aa8df]229" A Computer Algebra System for Polynomial Computations   /   version %s\n"
[0cb8c8]230"                                                       0<\n"
[451bcd]231"     by: G.-M. Greuel, G. Pfister, H. Schoenemann        \\   %s\n"
[0cb8c8]232"FB Mathematik der Universitaet, D-67653 Kaiserslautern    \\\n"
[49eeee]233, S_VERSION1,S_VERSION2);
[0e1846]234  }
235  else
236  {
[ff8601]237#ifdef HAVE_FACTORY
238    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
239#endif
[50cbdc]240#ifdef HAVE_SDB
[473707b]241    sdb_flags = 0;
[a3bc95e]242#endif
[f4edee]243    dup2(1,2);
[48ce9a]244    /* alternative:
245    *    memcpy(stderr,stdout,sizeof(FILE));
246    */
[0e1846]247  }
248  slStandardInit();
249  myynest=0;
[c06a32]250  if (! feOptValue(FE_OPT_NO_STDLIB))
[055021a]251  {
[e54eb4]252    int vv=verbose;
253    verbose &= ~Sy_bit(V_LOAD_LIB);
[22ed4c]254    iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
[e54eb4]255    verbose=vv;
256  }
[9ea9c6]257  errorreported = 0;
[c232af]258
259  // and again, ifdef OM_NDEBUG this call is undef'ed
260  // otherwise, it marks all memory allocated so far as static
261  // i.e. as memory which is not mention on omPrintUsedAddr:
[50cbdc]262  //omMarkMemoryAsStatic();
[c232af]263
[dfc6b54]264  setjmp(si_start_jmpbuf);
[eea2b0]265
266  // Now, put things on the stack of stuff to do
267  // Last thing to do is to execute given scripts
[c06a32]268  if (fe_optind < argc)
[057e93c]269  {
[eea2b0]270    int i = argc - 1;
[b7b08c]271    FILE *fd;
[c06a32]272    while (i >= fe_optind)
[eea2b0]273    {
[b7b08c]274      if ((fd = feFopen(argv[i], "r")) == NULL)
275      {
276        Warn("Can not open %s", argv[i]);
277      }
278      else
279      {
280        fclose(fd);
281        newFile(argv[i]);
282      }
[eea2b0]283      i--;
284    }
[057e93c]285  }
286  else
287  {
[3bd82d]288    currentVoice=feInitStdin(NULL);
[057e93c]289  }
[eea2b0]290
291  // before scripts, we execute -c, if it was given
[c06a32]292  if (feOptValue(FE_OPT_EXECUTE) != NULL)
[c232af]293    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
[eea2b0]294
[6123fa2]295  // first thing, however, is to load .singularrc from Singularpath
296  // and cwd/$HOME (in that order).
[c06a32]297  if (! feOptValue(FE_OPT_NO_RC))
[7def32f]298  {
[6123fa2]299    char buf[MAXPATHLEN];
[b6f537]300    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
301    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
302    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
[8c71e8]303
[b6f537]304    if (rc != NULL)
[7def32f]305    {
[b6f537]306      if (BVERBOSE(V_LOAD_LIB))
307        Print("// ** executing %s\n", buf);
[7def32f]308      fclose(rc);
[6123fa2]309      newFile(buf);
310    }
[7def32f]311  }
[eea2b0]312
[0e1846]313  /* start shell */
[f4edee]314  if (fe_fgets_stdin==fe_fgets_dummy)
[0e1846]315  {
[d754b7]316#ifdef HAVE_MPSR
[6b32990]317    BatchDoProc batch_do = slInitMPBatchDo();
318    if (batch_do != NULL)
319      return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
320                         (char*) feOptValue(FE_OPT_MPHOST));
321    else
322      return 1;
[d754b7]323#else
[eea2b0]324    assume(0);
325#endif
[0e1846]326  }
[07dacd]327  setjmp(si_start_jmpbuf);
[0e1846]328  yyparse();
[057e93c]329  m2_end(0);
[958e16]330#endif
[0e1846]331  return 0;
332}
[a1ab2a]333#endif // not LIBSINGULAR
[c06a32]334
Note: See TracBrowser for help on using the repository browser.