source: git/Singular/tesths.cc @ db143c

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