source: git/Singular/tesths.cc @ cb8103a

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