source: git/Singular/tesths.cc @ 52e6ef

spielwiese
Last change on this file since 52e6ef was 52e6ef, checked in by Hans Schoenemann <hannes@…>, 8 years ago
chg: use misc/auxiliary.h in libpolys and kernel/mod2.h in Singular for config
  • 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
10
11
12#include <kernel/mod2.h>
13#include <omalloc/omalloc.h>
14
15#include <misc/options.h>
16
17#include <factory/factory.h>
18
19#include <kernel/oswrapper/feread.h>
20#include <Singular/fevoices.h>
21#include <kernel/oswrapper/timer.h>
22
23// #ifdef HAVE_FANS
24// #include <callgfanlib/bbcone.h>
25// #include <callgfanlib/bbpolytope.h>
26// #include <callgfanlib/bbfan.h>
27// #include <callgfanlib/gitfan.h>
28// #endif
29
30#include "ipshell.h"
31#include "cntrlc.h"
32#include "links/silink.h"
33#include "ipid.h"
34#include "sdb.h"
35#include "feOpt.h"
36#include "distrib.h"
37#include "mmalloc.h"
38#include "tok.h"
39#include "fegetopt.h"
40
41#include <Singular/countedref.h>
42#include <Singular/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    switch(option_index)
118    {
119      case FE_OPT_DUMP_VERSIONTUPLE:
120        exit(0);
121        break;
122      default: ;
123    }
124  }
125
126  /* say hello */
127
128  if (TEST_V_QUIET)
129  {
130    (printf)(
131"                     SINGULAR                                 /"
132#ifndef MAKE_DISTRIBUTION
133"  Development"
134#endif
135"\n"
136" A Computer Algebra System for Polynomial Computations       /   version %s\n"
137"                                                           0<\n"
138" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \\   %s\n"
139"FB Mathematik der Universitaet, D-67653 Kaiserslautern        \\\n"
140, VERSION, VERSION_DATE);
141  if (feOptValue(FE_OPT_NO_SHELL)) Warn("running in restricted mode:"
142    " shell invocation and links are disallowed");
143  }
144  else
145  {
146    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
147    dup2(1,2);
148    /* alternative:
149    *    memcpy(stderr,stdout,sizeof(FILE));
150    */
151  }
152
153#ifdef SINGULAR_PYOBJECT_SETUP_H
154   pyobject_setup();
155#endif
156#ifdef SI_COUNTEDREF_AUTOLOAD
157  countedref_init();
158#endif
159// #ifdef HAVE_FANS
160//   bbcone_setup();
161//   bbpolytope_setup();
162//   bbfan_setup();
163//   gitfan_setup();
164// #endif /* HAVE_FANS */
165  errorreported = 0;
166
167  // -- example for "static" modules ------
168  //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
169  //module_help_main("huhu.so","Help for huhu\nhaha\n");
170  //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
171  setjmp(si_start_jmpbuf);
172
173  // Now, put things on the stack of stuff to do
174  // Last thing to do is to execute given scripts
175  if (fe_optind < argc)
176  {
177    int i = argc - 1;
178    FILE *fd;
179    while (i >= fe_optind)
180    {
181      if ((fd = feFopen(argv[i], "r")) == NULL)
182      {
183        Warn("Can not open %s", argv[i]);
184      }
185      else
186      {
187        fclose(fd);
188        newFile(argv[i]);
189      }
190      i--;
191    }
192  }
193  else
194  {
195    currentVoice=feInitStdin(NULL);
196  }
197
198  // before scripts, we execute -c, if it was given
199  if (feOptValue(FE_OPT_EXECUTE) != NULL)
200    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
201
202  // first thing, however, is to load .singularrc from Singularpath
203  // and cwd/$HOME (in that order).
204  if (! feOptValue(FE_OPT_NO_RC))
205  {
206    char buf[MAXPATHLEN];
207    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
208    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
209    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
210
211    if (rc != NULL)
212    {
213      if (BVERBOSE(V_LOAD_LIB))
214        Print("// ** executing %s\n", buf);
215      fclose(rc);
216      newFile(buf);
217    }
218  }
219
220  /* start shell */
221  if (fe_fgets_stdin==fe_fgets_dummy)
222  {
223    singular_in_batchmode=TRUE;
224    char *linkname=(char*) feOptValue(FE_OPT_LINK);
225    if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
226    {
227      return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
228      //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
229      //exit(0);
230    }
231  }
232  setjmp(si_start_jmpbuf);
233  yyparse();
234  m2_end(0);
235  return 0;
236}
237
Note: See TracBrowser for help on using the repository browser.