source: git/Singular/tesths.cc @ bd795d

spielwiese
Last change on this file since bd795d was bd795d, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
improved build system in Singuar/: building of libparse and [TE]Singular ADD/CHG: distribute and install emacs/ (under $(datadir)/) CHG: moved fegetopt.{c,h} from kernel/ to Singular/ ADD: build and install Singular/[TE]Singular ADD: better Singular/libparse CHG: only build the static release and debug binaries Singular&Singularg by default!
  • Property mode set to 100644
File size: 6.1 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5
6/*
7* ABSTRACT - initialize SINGULARs components, run Script and start SHELL
8*/
9
10#include "config.h"
11#include <kernel/mod2.h>
12
13#include <omalloc/omalloc.h>
14
15#include <misc/auxiliary.h>
16#include <misc/options.h>
17
18#ifdef HAVE_FACTORY
19#define SI_DONT_HAVE_GLOBAL_VARS
20#include <factory/factory.h>
21#endif
22
23#include <kernel/febase.h>
24#include <kernel/timer.h>
25
26#ifdef HAVE_FANS
27#include <kernel/bbcone.h>
28#include <kernel/bbfan.h>
29#endif
30
31#include "ipshell.h"
32#include "cntrlc.h"
33#include "silink.h"
34#include "ipid.h"
35#include "sdb.h"
36#include "feOpt.h"
37#include "distrib.h"
38#include "version.h"
39#include "slInit.h"
40#include "ssiLink.h"
41#include "bigintm.h"
42#include "mmalloc.h"
43#include "tok.h"
44#include "fegetopt.h"
45
46// #include "pyobject_setup.h"
47
48#include <unistd.h>
49#include <string.h>
50#include <stddef.h>
51#include <stdlib.h>
52#include <time.h>
53#include <errno.h>
54
55
56
57extern int siInit(char *);
58
59#if ! defined(LIBSINGULAR)
60
61#ifdef HAVE_FACTORY
62int initializeGMP(){ return 1; }
63#endif
64
65int mmInit2( void )
66{
67#if defined(OMALLOC_USES_MALLOC) || defined(X_OMALLOC)
68    /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */
69    /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */
70    /* do not rely on the default in Singular as libsingular may be different */
71    mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc);
72#else
73    mp_set_memory_functions(malloc,reallocSize,freeSize);
74#endif
75  return 1;
76}
77int mmInit( void )
78{
79#ifndef SI_THREADS
80  return mmInit2();
81#else
82  return 1;
83#endif
84}
85
86/*0 implementation*/
87int main(          /* main entry to Singular */
88    int argc,      /* number of parameter */
89    char** argv)   /* parameter array */
90{
91  //mmInit();
92  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
93  omInitRet_2_Info(argv[0]);
94  omInitGetBackTrace();
95
96  siInit(argv[0]);
97  init_signals();
98
99  // parse command line options
100  int optc, option_index;
101  const char* errormsg;
102  while((optc = fe_getopt_long(argc, argv,
103                               SHORT_OPTS_STRING, feOptSpec, &option_index))
104        != EOF)
105  {
106    if (optc == '?' || optc == 0)
107    {
108      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
109      exit(1);
110    }
111
112    if (optc != LONG_OPTION_RETURN)
113      option_index = feGetOptIndex(optc);
114
115    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
116
117    if (fe_optarg == NULL &&
118        (feOptSpec[option_index].type == feOptBool ||
119         feOptSpec[option_index].has_arg == optional_argument))
120      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
121    else
122      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
123
124    if (errormsg)
125    {
126      if (fe_optarg == NULL)
127        fprintf(stderr, "Error: Option '--%s' %s\n",
128               feOptSpec[option_index].name, errormsg);
129      else
130        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
131               feOptSpec[option_index].name, fe_optarg, errormsg);
132      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
133      exit(1);
134    }
135    if (optc == 'h') exit(0);
136  }
137
138  /* say hello */
139  //for official version: not active
140  //bigintm_setup();
141
142  if (TEST_V_QUIET)
143  {
144    (printf)(
145"                     SINGULAR                                 /"
146#ifndef MAKE_DISTRIBUTION
147"  Development"
148#endif
149"\n"
150" A Computer Algebra System for Polynomial Computations       /   version %s\n"
151"                                                           0<\n"
152" by: W. Decker, G.-M. Greuel, G. Pfister, H. Schoenemann     \\   %s\n"
153"FB Mathematik der Universitaet, D-67653 Kaiserslautern        \\\n"
154, S_VERSION1,S_VERSION2);
155  }
156  else
157  {
158#ifdef HAVE_FACTORY
159    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
160#endif
161#ifdef HAVE_SDB
162    sdb_flags = 0;
163#endif
164    dup2(1,2);
165    /* alternative:
166    *    memcpy(stderr,stdout,sizeof(FILE));
167    */
168  }
169
170#ifdef SINGULAR_PYOBJECT_SETUP_H
171   pyobject_setup();
172#endif
173
174#ifdef HAVE_FANS
175  bbcone_setup();
176  bbfan_setup();
177#endif /* HAVE_FANS */
178  errorreported = 0;
179
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    #ifdef HAVE_MPSR
243      BatchDoProc batch_do = slInitMPBatchDo();
244      if (batch_do != NULL)
245        return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
246                         (char*) feOptValue(FE_OPT_MPHOST));
247      else
248        return 1;
249    #else
250      assume(0);
251    #endif
252    }
253  }
254  setjmp(si_start_jmpbuf);
255  yyparse();
256  m2_end(0);
257  return 0;
258}
259#endif // not LIBSINGULAR
260
Note: See TracBrowser for help on using the repository browser.