source: git/Singular/tesths.cc @ 9f7665

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