source: git/Singular/tesths.cc @ f5d2647

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