source: git/Singular/tesths.cc @ 98e5882

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