source: git/Singular/tesths.cc @ 42f2ad

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