source: git/Singular/tesths.cc @ ae74d2

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