source: git/Singular/tesths.cc @ bd795d

spielwiese
Last change on this file since bd795d was bd795d, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
improved build system in Singuar/: building of libparse and [TE]Singular ADD/CHG: distribute and install emacs/ (under $(datadir)/) CHG: moved fegetopt.{c,h} from kernel/ to Singular/ ADD: build and install Singular/[TE]Singular ADD: better Singular/libparse CHG: only build the static release and debug binaries Singular&Singularg by default!
  • Property mode set to 100644
File size: 6.1 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
[bd795d]10#include "config.h"
[07f3b73]11#include <kernel/mod2.h>
12
13#include <omalloc/omalloc.h>
14
[88479ff]15#include <misc/auxiliary.h>
[bd795d]16#include <misc/options.h>
[07f3b73]17
[88479ff]18#ifdef HAVE_FACTORY
19#define SI_DONT_HAVE_GLOBAL_VARS
20#include <factory/factory.h>
21#endif
22
[599326]23#include <kernel/febase.h>
24#include <kernel/timer.h>
[1cb879]25
[3ec4fce]26#ifdef HAVE_FANS
[898605]27#include <kernel/bbcone.h>
[3ec4fce]28#include <kernel/bbfan.h>
29#endif
[c06a32]30
[07f3b73]31#include "ipshell.h"
32#include "cntrlc.h"
33#include "silink.h"
34#include "ipid.h"
35#include "sdb.h"
36#include "feOpt.h"
37#include "distrib.h"
38#include "version.h"
39#include "slInit.h"
40#include "ssiLink.h"
41#include "bigintm.h"
42#include "mmalloc.h"
43#include "tok.h"
[bd795d]44#include "fegetopt.h"
[07f3b73]45
46// #include "pyobject_setup.h"
47
48#include <unistd.h>
49#include <string.h>
50#include <stddef.h>
51#include <stdlib.h>
52#include <time.h>
53#include <errno.h>
54
55
[40edb03]56
[3645fc]57extern int siInit(char *);
[b6e51b]58
[672783]59#if ! defined(LIBSINGULAR)
[07f3b73]60
61#ifdef HAVE_FACTORY
62int initializeGMP(){ return 1; }
63#endif
64
[896561]65int mmInit2( void )
[5374da]66{
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    /* 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  return 1;
76}
[896561]77int mmInit( void )
78{
79#ifndef SI_THREADS
80  return mmInit2();
81#else
82  return 1;
83#endif
84}
[5374da]85
[0e1846]86/*0 implementation*/
87int main(          /* main entry to Singular */
88    int argc,      /* number of parameter */
89    char** argv)   /* parameter array */
90{
[896561]91  //mmInit();
[c232af]92  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
93  omInitRet_2_Info(argv[0]);
94  omInitGetBackTrace();
95
[3645fc]96  siInit(argv[0]);
[d3b70ae]97  init_signals();
[eea2b0]98
99  // parse command line options
[3645fc]100  int optc, option_index;
101  const char* errormsg;
[9b4b45]102  while((optc = fe_getopt_long(argc, argv,
[c06a32]103                               SHORT_OPTS_STRING, feOptSpec, &option_index))
[eea2b0]104        != EOF)
[0e1846]105  {
[8c71e8]106    if (optc == '?' || optc == 0)
[0e1846]107    {
[c06a32]108      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
109      exit(1);
110    }
[e0d91c]111
[c06a32]112    if (optc != LONG_OPTION_RETURN)
113      option_index = feGetOptIndex(optc);
[eea2b0]114
[9b4b45]115    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
[8c71e8]116
117    if (fe_optarg == NULL &&
[c06a32]118        (feOptSpec[option_index].type == feOptBool ||
119         feOptSpec[option_index].has_arg == optional_argument))
120      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
121    else
122      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
[8c71e8]123
[c06a32]124    if (errormsg)
125    {
126      if (fe_optarg == NULL)
[8c71e8]127        fprintf(stderr, "Error: Option '--%s' %s\n",
[c06a32]128               feOptSpec[option_index].name, errormsg);
129      else
[8c71e8]130        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
[c06a32]131               feOptSpec[option_index].name, fe_optarg, errormsg);
132      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
133      exit(1);
[0e1846]134    }
[c06a32]135    if (optc == 'h') exit(0);
[0e1846]136  }
[c06a32]137
[726d50]138  /* say hello */
[3645fc]139  //for official version: not active
140  //bigintm_setup();
141
[6c4db17]142  if (TEST_V_QUIET)
[0e1846]143  {
[50cbdc]144    (printf)(
[1492bb]145"                     SINGULAR                                 /"
[3854a98]146#ifndef MAKE_DISTRIBUTION
[9a11fe]147"  Development"
[3854a98]148#endif
149"\n"
[1492bb]150" A Computer Algebra System for Polynomial Computations       /   version %s\n"
151"                                                           0<\n"
152" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \\   %s\n"
153"FB Mathematik der Universitaet, D-67653 Kaiserslautern        \\\n"
[49eeee]154, S_VERSION1,S_VERSION2);
[0e1846]155  }
156  else
157  {
[ff8601]158#ifdef HAVE_FACTORY
159    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
160#endif
[50cbdc]161#ifdef HAVE_SDB
[473707b]162    sdb_flags = 0;
[a3bc95e]163#endif
[f4edee]164    dup2(1,2);
[48ce9a]165    /* alternative:
166    *    memcpy(stderr,stdout,sizeof(FILE));
167    */
[0e1846]168  }
[3bdd16]169
170#ifdef SINGULAR_PYOBJECT_SETUP_H
171   pyobject_setup();
172#endif
173
[d3b70ae]174#ifdef HAVE_FANS
175  bbcone_setup();
176  bbfan_setup();
177#endif /* HAVE_FANS */
[9ea9c6]178  errorreported = 0;
[c232af]179
[dfc6b54]180  setjmp(si_start_jmpbuf);
[eea2b0]181
182  // Now, put things on the stack of stuff to do
183  // Last thing to do is to execute given scripts
[c06a32]184  if (fe_optind < argc)
[057e93c]185  {
[eea2b0]186    int i = argc - 1;
[b7b08c]187    FILE *fd;
[c06a32]188    while (i >= fe_optind)
[eea2b0]189    {
[b7b08c]190      if ((fd = feFopen(argv[i], "r")) == NULL)
191      {
192        Warn("Can not open %s", argv[i]);
193      }
194      else
195      {
196        fclose(fd);
197        newFile(argv[i]);
198      }
[eea2b0]199      i--;
200    }
[057e93c]201  }
202  else
203  {
[3bd82d]204    currentVoice=feInitStdin(NULL);
[057e93c]205  }
[eea2b0]206
207  // before scripts, we execute -c, if it was given
[c06a32]208  if (feOptValue(FE_OPT_EXECUTE) != NULL)
[c232af]209    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
[eea2b0]210
[6123fa2]211  // first thing, however, is to load .singularrc from Singularpath
212  // and cwd/$HOME (in that order).
[c06a32]213  if (! feOptValue(FE_OPT_NO_RC))
[7def32f]214  {
[6123fa2]215    char buf[MAXPATHLEN];
[b6f537]216    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
217    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
218    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
[8c71e8]219
[b6f537]220    if (rc != NULL)
[7def32f]221    {
[b6f537]222      if (BVERBOSE(V_LOAD_LIB))
223        Print("// ** executing %s\n", buf);
[7def32f]224      fclose(rc);
[6123fa2]225      newFile(buf);
226    }
[7def32f]227  }
[eea2b0]228
[0e1846]229  /* start shell */
[f4edee]230  if (fe_fgets_stdin==fe_fgets_dummy)
[0e1846]231  {
[655e1f]232    singular_in_batchmode=TRUE;
[425e33c]233    char *linkname=(char*) feOptValue(FE_OPT_LINK);
234    if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
235    {
236      return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
237      //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
238      //exit(0);
239    }
[6b32990]240    else
[425e33c]241    {
242    #ifdef HAVE_MPSR
243      BatchDoProc batch_do = slInitMPBatchDo();
244      if (batch_do != NULL)
245        return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
246                         (char*) feOptValue(FE_OPT_MPHOST));
247      else
248        return 1;
249    #else
250      assume(0);
251    #endif
252    }
[0e1846]253  }
[07dacd]254  setjmp(si_start_jmpbuf);
[0e1846]255  yyparse();
[057e93c]256  m2_end(0);
[0e1846]257  return 0;
258}
[a1ab2a]259#endif // not LIBSINGULAR
[c06a32]260
Note: See TracBrowser for help on using the repository browser.