source: git/Singular/tesths.cc @ 60bebce

spielwiese
Last change on this file since 60bebce was 60bebce, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: gcd to test git-svn-id: file:///usr/local/Singular/svn/trunk@10874 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: tesths.cc,v 1.114 2008-07-16 12:51:19 Singular Exp $ */
5
6/*
7* ABSTRACT - initialize SINGULARs components, run Script and start SHELL
8*/
9
10#include <unistd.h>
11#include <string.h>
12#include <stdio.h>
13#include <stddef.h>
14#include <stdlib.h>
15#include <time.h>
16#include <errno.h>
17#include "mod2.h"
18#include "tok.h"
19#include "ipshell.h"
20#include "febase.h"
21#include "cntrlc.h"
22#include "omalloc.h"
23#include "silink.h"
24#include "ipid.h"
25#include "timer.h"
26#include "sdb.h"
27#include "fegetopt.h"
28#include "feOpt.h"
29#include "distrib.h"
30#include "version.h"
31#include "slInit.h"
32
33#ifdef HAVE_FACTORY
34#define SI_DONT_HAVE_GLOBAL_VARS
35#include <factory.h>
36#endif
37
38extern int iiInitArithmetic();
39
40const char *singular_date=__DATE__ " " __TIME__;
41
42#ifdef LIBSINGULAR
43int siInit(char *name)
44{
45  // hack such that all shared' libs in the bindir are loaded correctly
46  feInitResources(name);
47}
48#endif
49
50#if (! defined(LIBSINGULAR)) || defined(GENTABLE)
51/*0 implementation*/
52int main(          /* main entry to Singular */
53    int argc,      /* number of parameter */
54    char** argv)   /* parameter array */
55{
56#ifdef HAVE_FACTORY
57  On(SW_USE_NTL);
58  Off(SW_USE_GCD_P);
59  On(SW_USE_NTL_GCD_0); // On -> seg11 in Old/algnorm, Old/factor...
60  On(SW_USE_NTL_GCD_P); // On -> cyle in Short/brnoeth_s: fixed
61  On(SW_USE_EZGCD);
62  On(SW_USE_CHINREM_GCD);
63  //On(SW_USE_fieldGCD);
64  //On(SW_USE_EZGCD_P);
65  //On(SW_USE_QGCD);
66  Off(SW_USE_NTL_SORT); // may be changed by an command line option
67#endif
68
69#ifdef INIT_BUG
70  jjInitTab1();
71#endif
72#ifdef GENTABLE
73  extern void ttGen1();
74  extern void ttGen2b();
75  extern void ttGen4();
76  extern void mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
77  mpsr_ttGen();
78  ttGen4();
79  ttGen1();
80  ttGen2b();
81#else
82  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
83  omInitRet_2_Info(argv[0]);
84  omInitGetBackTrace();
85
86  /* initialize components */
87  siRandomStart=inits();
88  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
89  int optc, option_index;
90  char* errormsg;
91
92  // do this first, because -v might print version path
93  feInitResources(argv[0]);
94  iiInitArithmetic();
95
96  // parse command line options
97  while((optc = fe_getopt_long(argc, argv,
98                               SHORT_OPTS_STRING, feOptSpec, &option_index))
99        != EOF)
100  {
101    if (optc == '?' || optc == 0)
102    {
103      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
104      exit(1);
105    }
106
107    if (optc != LONG_OPTION_RETURN)
108      option_index = feGetOptIndex(optc);
109
110    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
111
112    if (fe_optarg == NULL &&
113        (feOptSpec[option_index].type == feOptBool ||
114         feOptSpec[option_index].has_arg == optional_argument))
115      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
116    else
117      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
118
119    if (errormsg)
120    {
121      if (fe_optarg == NULL)
122        fprintf(stderr, "Error: Option '--%s' %s\n",
123               feOptSpec[option_index].name, errormsg);
124      else
125        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
126               feOptSpec[option_index].name, fe_optarg, errormsg);
127      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
128      exit(1);
129    }
130    if (optc == 'h') exit(0);
131  }
132
133  /* say hello */
134  {
135#ifdef HAVE_NS
136    basePack=(package)omAlloc0(sizeof(*basePack));
137    currPack=basePack;
138    idhdl h;
139    h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
140    IDPACKAGE(h)->language = LANG_TOP;
141    IDPACKAGE(h)=basePack;
142    currPackHdl=h;
143    basePackHdl=h;
144#endif /* HAVE_NS */
145  }
146  if (BVERBOSE(0))
147  {
148    (printf)(
149"                     SINGULAR                             /"
150#ifndef MAKE_DISTRIBUTION
151"  Development"
152#endif
153"\n"
154" A Computer Algebra System for Polynomial Computations   /   version %s\n"
155"                                                       0<\n"
156"     by: G.-M. Greuel, G. Pfister, H. Schoenemann        \\   %s\n"
157"FB Mathematik der Universitaet, D-67653 Kaiserslautern    \\\n"
158, S_VERSION1,S_VERSION2);
159  }
160  else
161  {
162#ifdef HAVE_FACTORY
163    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
164#endif
165#ifdef HAVE_SDB
166    sdb_flags = 0;
167#endif
168    dup2(1,2);
169    /* alternative:
170    *    memcpy(stderr,stdout,sizeof(FILE));
171    */
172  }
173  slStandardInit();
174  myynest=0;
175  if (! feOptValue(FE_OPT_NO_STDLIB))
176  {
177    int vv=verbose;
178    verbose &= ~Sy_bit(V_LOAD_LIB);
179    iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
180    verbose=vv;
181  }
182  errorreported = 0;
183
184  // and again, ifdef OM_NDEBUG this call is undef'ed
185  // otherwise, it marks all memory allocated so far as static
186  // i.e. as memory which is not mention on omPrintUsedAddr:
187  //omMarkMemoryAsStatic();
188
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#ifdef HAVE_MPSR
242    BatchDoProc batch_do = slInitMPBatchDo();
243    if (batch_do != NULL)
244      return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
245                         (char*) feOptValue(FE_OPT_MPHOST));
246    else
247      return 1;
248#else
249    assume(0);
250#endif
251  }
252  setjmp(si_start_jmpbuf);
253  yyparse();
254  m2_end(0);
255#endif
256  return 0;
257}
258#endif // not LIBSINGULAR
259
Note: See TracBrowser for help on using the repository browser.