source: git/Singular/tesths.cc @ e3c628

spielwiese
Last change on this file since e3c628 was b270e37, checked in by Hans Schoenemann <hannes@…>, 22 months ago
moved distrib.h to libpolys/misc for dError.cc
  • Property mode set to 100644
File size: 6.4 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#include "kernel/mod2.h"
11#include "omalloc/omalloc.h"
12#include "misc/options.h"
13#include "factory/factory.h"
14#include "kernel/oswrapper/feread.h"
15#include "Singular/fevoices.h"
16#include "kernel/oswrapper/timer.h"
17
18#include "ipshell.h"
19#include "cntrlc.h"
20#include "links/silink.h"
21#include "ipid.h"
22#include "sdb.h"
23#include "feOpt.h"
24#include "misc/distrib.h"
25#include "mmalloc.h"
26#include "tok.h"
27#include "resources/fegetopt.h"
28
29#include "Singular/countedref.h"
30#include "Singular/pyobject_setup.h"
31
32#include <unistd.h>
33#ifdef HAVE_NTL
34#include <NTL/config.h>
35#endif
36
37
38extern void siInit(char *);
39#ifdef PSINGULAR
40GLOBAL_VAR char *global_argv0;
41#endif
42EXTERN_VAR FILE* File_Log;
43EXTERN_VAR BOOLEAN FE_OPT_NO_SHELL_FLAG;
44
45int mmInit( void )
46{
47#ifndef X_OMALLOC
48#if defined(OMALLOC_USES_MALLOC)
49    /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
50    /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
51    /* do not rely on the default in Singular as libsingular may be different */
52    mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc);
53#else
54    mp_set_memory_functions(malloc,reallocSize,freeSize);
55#endif
56#endif
57  return 1;
58}
59
60/*0 implementation*/
61int main(          /* main entry to Singular */
62    int argc,      /* number of parameter */
63    char** argv)   /* parameter array */
64{
65  mmInit();
66  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
67  omInitRet_2_Info(argv[0]);
68  omInitGetBackTrace();
69
70#ifdef PSINGULAR
71  global_argv0 = argv[0];
72#endif
73  siInit(argv[0]);
74  init_signals();
75  #ifdef HAVE_NTL
76  #if NTL_MAJOR_VERSION>=10
77  #ifdef NTL_THREAD_BOOST
78  SetNumThreads(feOptValue(FE_OPT_CPUS));
79  #endif
80  #endif
81  #endif
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    switch(option_index)
121    {
122      case FE_OPT_DUMP_VERSIONTUPLE:
123        exit(0);
124        break;
125      default: ;
126    }
127  }
128
129  /* say hello */
130
131  if (TEST_V_QUIET)
132  {
133    (printf)(
134"                     SINGULAR                                 /"
135#ifndef MAKE_DISTRIBUTION
136"  Development"
137#endif
138"\n"
139" A Computer Algebra System for Polynomial Computations       /   version %s\n"
140"                                                           0<\n"
141" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \\   %s\n"
142"FB Mathematik der Universitaet, D-67653 Kaiserslautern        \\\n"
143, VERSION, VERSION_DATE);
144    if (feOptValue(FE_OPT_NO_SHELL))
145    {
146      WarnS("running in restricted mode:"
147      " shell invocation and links are disallowed");
148      FE_OPT_NO_SHELL_FLAG=TRUE;
149    }
150  }
151  else
152  {
153    FE_OPT_NO_SHELL_FLAG=FALSE;
154    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
155    dup2(1,2);
156    /* alternative:
157    *    memcpy(stderr,stdout,sizeof(FILE));
158    */
159  }
160  if (feOptValue(FE_OPT_LOG)!=NULL)
161  {
162    int pid=getpid();
163    char *buf=(char*)malloc(10+strlen((char*) feOptSpec[FE_OPT_LOG].value));
164    sprintf(buf,"%s.%d",(char*) feOptSpec[FE_OPT_LOG].value,pid);
165    File_Log=fopen(buf,"w");
166  }
167
168#ifdef SINGULAR_PYOBJECT_SETUP_H
169   pyobject_setup();
170#endif
171#ifdef SI_COUNTEDREF_AUTOLOAD
172  countedref_init();
173#endif
174  errorreported = 0;
175
176  // -- example for "static" modules ------
177  //load_builtin("huhu.so",FALSE,(SModulFunc_t)huhu_mod_init);
178  //module_help_main("huhu.so","Help for huhu\nhaha\n");
179  //module_help_proc("huhu.so","p","Help for huhu::p\nhaha\n");
180  setjmp(si_start_jmpbuf);
181
182  // Now, put things on the stack of stuff to do
183  // Last thing to do is to execute given scripts
184  if (fe_optind < argc)
185  {
186    int i = argc - 1;
187    FILE *fd;
188    while (i >= fe_optind)
189    {
190      if ((fd = feFopen(argv[i], "r")) == NULL)
191      {
192        Warn("Can not open %s", argv[i]);
193      }
194      else
195      {
196        fclose(fd);
197        newFile(argv[i]);
198      }
199      i--;
200    }
201  }
202  else
203  {
204    currentVoice=feInitStdin(NULL);
205  }
206
207  // before scripts, we execute -c, if it was given
208  if (feOptValue(FE_OPT_EXECUTE) != NULL)
209    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
210
211  // first thing, however, is to load .singularrc from Singularpath
212  // and cwd/$HOME (in that order).
213  if (! feOptValue(FE_OPT_NO_RC))
214  {
215    char buf[MAXPATHLEN];
216    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
217    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
218    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
219
220    if (rc != NULL)
221    {
222      if (BVERBOSE(V_LOAD_LIB))
223        Print("// ** executing %s\n", buf);
224      fclose(rc);
225      newFile(buf);
226    }
227  }
228
229  /* start shell */
230  if (fe_fgets_stdin==fe_fgets_dummy)
231  {
232    singular_in_batchmode=TRUE;
233    char *linkname=(char*) feOptValue(FE_OPT_LINK);
234    if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
235    {
236      return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
237      //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
238      //exit(0);
239    }
240    else
241    {
242      Print("** missing arguments: -b requires --link/--MPhost/--MPport\n");
243      return 1;
244    }
245  }
246  setjmp(si_start_jmpbuf);
247  yyparse();
248  m2_end(0);
249  return 0;
250}
251
Note: See TracBrowser for help on using the repository browser.