source: git/Singular/tesths.cc @ f5d2647

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