source: git/Singular/tesths.cc @ 991a3d6

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