source: git/Singular/tesths.cc @ 7b8818

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