source: git/Singular/tesths.cc @ 88479ff

spielwiese
Last change on this file since 88479ff was 88479ff, checked in by Burcin Erocal <burcin@…>, 13 years ago
Change includes in Singular/tesths.cc to work around cstdio/stdio.h conflict.
  • 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 <misc/options.h>
11#include <misc/auxiliary.h>
12#ifdef HAVE_FACTORY
13#define SI_DONT_HAVE_GLOBAL_VARS
14#include <factory/factory.h>
15#endif
16
17#include <kernel/mod2.h>
18#include <Singular/tok.h>
19#include <unistd.h>
20#include <string.h>
21#include <stddef.h>
22#include <stdlib.h>
23#include <time.h>
24#include <errno.h>
25
26#include <Singular/ipshell.h>
27#include <kernel/febase.h>
28#include <Singular/cntrlc.h>
29#include <omalloc/omalloc.h>
30#include <Singular/silink.h>
31#include <Singular/ipid.h>
32#include <kernel/timer.h>
33#include <Singular/sdb.h>
34#include <kernel/fegetopt.h>
35#include <Singular/feOpt.h>
36#include <Singular/distrib.h>
37#include <Singular/version.h>
38#include <Singular/slInit.h>
39#include <Singular/ssiLink.h>
40#include <Singular/bigintm.h>
41#include <Singular/pyobject_setup.h>
42#include <omalloc/omalloc.h>
43#include <kernel/mmalloc.h>
44
45#ifdef HAVE_FANS
46#include <kernel/bbcone.h>
47#include <kernel/bbfan.h>
48#endif
49
50
51extern int siInit(char *);
52
53#if ! defined(LIBSINGULAR)
54int mmInit2( 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}
66int mmInit( void )
67{
68#ifndef SI_THREADS
69  return mmInit2();
70#else
71  return 1;
72#endif
73}
74
75/*0 implementation*/
76int main(          /* main entry to Singular */
77    int argc,      /* number of parameter */
78    char** argv)   /* parameter array */
79{
80  //mmInit();
81  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
82  omInitRet_2_Info(argv[0]);
83  omInitGetBackTrace();
84
85  siInit(argv[0]);
86  init_signals();
87
88  // parse command line options
89  int optc, option_index;
90  const char* errormsg;
91  while((optc = fe_getopt_long(argc, argv,
92                               SHORT_OPTS_STRING, feOptSpec, &option_index))
93        != EOF)
94  {
95    if (optc == '?' || optc == 0)
96    {
97      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
98      exit(1);
99    }
100
101    if (optc != LONG_OPTION_RETURN)
102      option_index = feGetOptIndex(optc);
103
104    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
105
106    if (fe_optarg == NULL &&
107        (feOptSpec[option_index].type == feOptBool ||
108         feOptSpec[option_index].has_arg == optional_argument))
109      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
110    else
111      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
112
113    if (errormsg)
114    {
115      if (fe_optarg == NULL)
116        fprintf(stderr, "Error: Option '--%s' %s\n",
117               feOptSpec[option_index].name, errormsg);
118      else
119        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
120               feOptSpec[option_index].name, fe_optarg, errormsg);
121      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
122      exit(1);
123    }
124    if (optc == 'h') exit(0);
125  }
126
127  /* say hello */
128  //for official version: not active
129  //bigintm_setup();
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, S_VERSION1,S_VERSION2);
144  }
145  else
146  {
147#ifdef HAVE_FACTORY
148    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
149#endif
150#ifdef HAVE_SDB
151    sdb_flags = 0;
152#endif
153    dup2(1,2);
154    /* alternative:
155    *    memcpy(stderr,stdout,sizeof(FILE));
156    */
157  }
158  pyobject_setup();
159#ifdef HAVE_FANS
160  bbcone_setup();
161  bbfan_setup();
162#endif /* HAVE_FANS */
163  errorreported = 0;
164
165  setjmp(si_start_jmpbuf);
166
167  // Now, put things on the stack of stuff to do
168  // Last thing to do is to execute given scripts
169  if (fe_optind < argc)
170  {
171    int i = argc - 1;
172    FILE *fd;
173    while (i >= fe_optind)
174    {
175      if ((fd = feFopen(argv[i], "r")) == NULL)
176      {
177        Warn("Can not open %s", argv[i]);
178      }
179      else
180      {
181        fclose(fd);
182        newFile(argv[i]);
183      }
184      i--;
185    }
186  }
187  else
188  {
189    currentVoice=feInitStdin(NULL);
190  }
191
192  // before scripts, we execute -c, if it was given
193  if (feOptValue(FE_OPT_EXECUTE) != NULL)
194    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
195
196  // first thing, however, is to load .singularrc from Singularpath
197  // and cwd/$HOME (in that order).
198  if (! feOptValue(FE_OPT_NO_RC))
199  {
200    char buf[MAXPATHLEN];
201    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
202    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
203    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
204
205    if (rc != NULL)
206    {
207      if (BVERBOSE(V_LOAD_LIB))
208        Print("// ** executing %s\n", buf);
209      fclose(rc);
210      newFile(buf);
211    }
212  }
213
214  /* start shell */
215  if (fe_fgets_stdin==fe_fgets_dummy)
216  {
217    singular_in_batchmode=TRUE;
218    char *linkname=(char*) feOptValue(FE_OPT_LINK);
219    if((linkname!=NULL)&&(strcmp(linkname,"ssi")==0))
220    {
221      return ssiBatch((char*) feOptValue(FE_OPT_MPHOST),(char*) feOptValue(FE_OPT_MPPORT));
222      //Print("batch: p:%s, h:%s\n",(char*) feOptValue(FE_OPT_MPPORT),(char*) feOptValue(FE_OPT_MPHOST));
223      //exit(0);
224    }
225    else
226    {
227    #ifdef HAVE_MPSR
228      BatchDoProc batch_do = slInitMPBatchDo();
229      if (batch_do != NULL)
230        return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
231                         (char*) feOptValue(FE_OPT_MPHOST));
232      else
233        return 1;
234    #else
235      assume(0);
236    #endif
237    }
238  }
239  setjmp(si_start_jmpbuf);
240  yyparse();
241  m2_end(0);
242  return 0;
243}
244#endif // not LIBSINGULAR
245
Note: See TracBrowser for help on using the repository browser.