source: git/Singular/tesths.cc @ 24bfd7

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