source: git/Singular/tesths.cc @ 8c1285

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