source: git/Singular/tesths.cc @ 76d26c

fieker-DuValspielwiese
Last change on this file since 76d26c was c848e3, checked in by Hans Schoenemann <hannes@…>, 12 years ago
chg: re-enable system("cpu"), change setting of semaphore 0 (cherry picked from commit 71871dcf30b201439f1a4885b5dd9f6ecd140938) Signed-off-by: Andreas Steenpass <steenpass@mathematik.uni-kl.de>
  • 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
[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#ifdef HAVE_FACTORY
20#define SI_DONT_HAVE_GLOBAL_VARS
21#include <factory/factory.h>
22#endif
23
[599326]24#include <kernel/febase.h>
25#include <kernel/timer.h>
[1cb879]26
[7b8818]27// #ifdef HAVE_FANS
28// #include <callgfanlib/bbcone.h>
29// #include <callgfanlib/bbpolytope.h>
30// #include <callgfanlib/bbfan.h>
31// #include <callgfanlib/gitfan.h>
32// #endif
[c06a32]33
[07f3b73]34#include "ipshell.h"
35#include "cntrlc.h"
[44ca2f]36#include "links/silink.h"
[07f3b73]37#include "ipid.h"
38#include "sdb.h"
39#include "feOpt.h"
40#include "distrib.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);
[c848e3]138  sipc_semaphore_init(0, cpus-1);
[4d80e2b]139#endif
140
[726d50]141  /* say hello */
[3645fc]142
[6c4db17]143  if (TEST_V_QUIET)
[0e1846]144  {
[50cbdc]145    (printf)(
[1492bb]146"                     SINGULAR                                 /"
[3854a98]147#ifndef MAKE_DISTRIBUTION
[9a11fe]148"  Development"
[3854a98]149#endif
150"\n"
[1492bb]151" A Computer Algebra System for Polynomial Computations       /   version %s\n"
152"                                                           0<\n"
153" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \\   %s\n"
154"FB Mathematik der Universitaet, D-67653 Kaiserslautern        \\\n"
[92644b]155, PACKAGE_VERSION, VERSION_DATE);
[cecef0]156  if (feOptValue(FE_OPT_NO_SHELL)) Warn("running in restricted mode:"
157    " shell invocation and links are disallowed");
[0e1846]158  }
159  else
160  {
[ff8601]161#ifdef HAVE_FACTORY
162    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
163#endif
[50cbdc]164#ifdef HAVE_SDB
[473707b]165    sdb_flags = 0;
[a3bc95e]166#endif
[f4edee]167    dup2(1,2);
[48ce9a]168    /* alternative:
169    *    memcpy(stderr,stdout,sizeof(FILE));
170    */
[0e1846]171  }
[3bdd16]172
173#ifdef SINGULAR_PYOBJECT_SETUP_H
174   pyobject_setup();
175#endif
[d1fbbf]176#ifdef SI_COUNTEDREF_AUTOLOAD
[d94836e]177  countedref_init();
[d1fbbf]178#endif
[7b8818]179// #ifdef HAVE_FANS
180//   bbcone_setup();
181//   bbpolytope_setup();
182//   bbfan_setup();
183//   gitfan_setup();
184// #endif /* HAVE_FANS */
[9ea9c6]185  errorreported = 0;
[c232af]186
[801d2b]187  // -- example for "static" modules ------
188  //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
189  //module_help_main("huhu.so","Help for huhu\nhaha\n");
190  //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
[dfc6b54]191  setjmp(si_start_jmpbuf);
[eea2b0]192
193  // Now, put things on the stack of stuff to do
194  // Last thing to do is to execute given scripts
[c06a32]195  if (fe_optind < argc)
[057e93c]196  {
[eea2b0]197    int i = argc - 1;
[b7b08c]198    FILE *fd;
[c06a32]199    while (i >= fe_optind)
[eea2b0]200    {
[b7b08c]201      if ((fd = feFopen(argv[i], "r")) == NULL)
202      {
203        Warn("Can not open %s", argv[i]);
204      }
205      else
206      {
207        fclose(fd);
208        newFile(argv[i]);
209      }
[eea2b0]210      i--;
211    }
[057e93c]212  }
213  else
214  {
[3bd82d]215    currentVoice=feInitStdin(NULL);
[057e93c]216  }
[eea2b0]217
218  // before scripts, we execute -c, if it was given
[c06a32]219  if (feOptValue(FE_OPT_EXECUTE) != NULL)
[c232af]220    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
[eea2b0]221
[6123fa2]222  // first thing, however, is to load .singularrc from Singularpath
223  // and cwd/$HOME (in that order).
[c06a32]224  if (! feOptValue(FE_OPT_NO_RC))
[7def32f]225  {
[6123fa2]226    char buf[MAXPATHLEN];
[b6f537]227    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
228    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
229    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
[8c71e8]230
[b6f537]231    if (rc != NULL)
[7def32f]232    {
[b6f537]233      if (BVERBOSE(V_LOAD_LIB))
234        Print("// ** executing %s\n", buf);
[7def32f]235      fclose(rc);
[6123fa2]236      newFile(buf);
237    }
[7def32f]238  }
[eea2b0]239
[0e1846]240  /* start shell */
[f4edee]241  if (fe_fgets_stdin==fe_fgets_dummy)
[0e1846]242  {
[655e1f]243    singular_in_batchmode=TRUE;
[425e33c]244    char *linkname=(char*) feOptValue(FE_OPT_LINK);
245    if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
246    {
247      return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
248      //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
249      //exit(0);
250    }
[0e1846]251  }
[07dacd]252  setjmp(si_start_jmpbuf);
[0e1846]253  yyparse();
[057e93c]254  m2_end(0);
[0e1846]255  return 0;
256}
[a1ab2a]257#endif // not LIBSINGULAR
[c06a32]258
Note: See TracBrowser for help on using the repository browser.