source: git/Singular/tesths.cc @ 991a3d6

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