source: git/Singular/tesths.cc @ abb12f

spielwiese
Last change on this file since abb12f was c848e3, checked in by Hans Schoenemann <hannes@…>, 12 years ago
chg: re-enable system("cpu"), change setting of semaphore 0 (cherry picked from commit 71871dcf30b201439f1a4885b5dd9f6ecd140938) Signed-off-by: Andreas Steenpass <steenpass@mathematik.uni-kl.de>
  • 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#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#ifdef HAVE_FACTORY
20#define SI_DONT_HAVE_GLOBAL_VARS
21#include <factory/factory.h>
22#endif
23
24#include <kernel/febase.h>
25#include <kernel/timer.h>
26
27// #ifdef HAVE_FANS
28// #include <callgfanlib/bbcone.h>
29// #include <callgfanlib/bbpolytope.h>
30// #include <callgfanlib/bbfan.h>
31// #include <callgfanlib/gitfan.h>
32// #endif
33
34#include "ipshell.h"
35#include "cntrlc.h"
36#include "links/silink.h"
37#include "ipid.h"
38#include "sdb.h"
39#include "feOpt.h"
40#include "distrib.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-1);
139#endif
140
141  /* say hello */
142
143  if (TEST_V_QUIET)
144  {
145    (printf)(
146"                     SINGULAR                                 /"
147#ifndef MAKE_DISTRIBUTION
148"  Development"
149#endif
150"\n"
151" A Computer Algebra System for Polynomial Computations       /   version %s\n"
152"                                                           0<\n"
153" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \\   %s\n"
154"FB Mathematik der Universitaet, D-67653 Kaiserslautern        \\\n"
155, PACKAGE_VERSION, VERSION_DATE);
156  if (feOptValue(FE_OPT_NO_SHELL)) Warn("running in restricted mode:"
157    " shell invocation and links are disallowed");
158  }
159  else
160  {
161#ifdef HAVE_FACTORY
162    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
163#endif
164#ifdef HAVE_SDB
165    sdb_flags = 0;
166#endif
167    dup2(1,2);
168    /* alternative:
169    *    memcpy(stderr,stdout,sizeof(FILE));
170    */
171  }
172
173#ifdef SINGULAR_PYOBJECT_SETUP_H
174   pyobject_setup();
175#endif
176#ifdef SI_COUNTEDREF_AUTOLOAD
177  countedref_init();
178#endif
179// #ifdef HAVE_FANS
180//   bbcone_setup();
181//   bbpolytope_setup();
182//   bbfan_setup();
183//   gitfan_setup();
184// #endif /* HAVE_FANS */
185  errorreported = 0;
186
187  // -- example for "static" modules ------
188  //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
189  //module_help_main("huhu.so","Help for huhu\nhaha\n");
190  //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
191  setjmp(si_start_jmpbuf);
192
193  // Now, put things on the stack of stuff to do
194  // Last thing to do is to execute given scripts
195  if (fe_optind < argc)
196  {
197    int i = argc - 1;
198    FILE *fd;
199    while (i >= fe_optind)
200    {
201      if ((fd = feFopen(argv[i], "r")) == NULL)
202      {
203        Warn("Can not open %s", argv[i]);
204      }
205      else
206      {
207        fclose(fd);
208        newFile(argv[i]);
209      }
210      i--;
211    }
212  }
213  else
214  {
215    currentVoice=feInitStdin(NULL);
216  }
217
218  // before scripts, we execute -c, if it was given
219  if (feOptValue(FE_OPT_EXECUTE) != NULL)
220    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
221
222  // first thing, however, is to load .singularrc from Singularpath
223  // and cwd/$HOME (in that order).
224  if (! feOptValue(FE_OPT_NO_RC))
225  {
226    char buf[MAXPATHLEN];
227    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
228    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
229    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
230
231    if (rc != NULL)
232    {
233      if (BVERBOSE(V_LOAD_LIB))
234        Print("// ** executing %s\n", buf);
235      fclose(rc);
236      newFile(buf);
237    }
238  }
239
240  /* start shell */
241  if (fe_fgets_stdin==fe_fgets_dummy)
242  {
243    singular_in_batchmode=TRUE;
244    char *linkname=(char*) feOptValue(FE_OPT_LINK);
245    if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
246    {
247      return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
248      //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
249      //exit(0);
250    }
251  }
252  setjmp(si_start_jmpbuf);
253  yyparse();
254  m2_end(0);
255  return 0;
256}
257#endif // not LIBSINGULAR
258
Note: See TracBrowser for help on using the repository browser.