source: git/Singular/tesths.cc @ fa167e

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