source: git/Singular/tesths.cc @ f17318

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