source: git/Singular/tesths.cc @ 6ab785

spielwiese
Last change on this file since 6ab785 was 6ab785, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: sing_dld removed git-svn-id: file:///usr/local/Singular/svn/trunk@10699 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.113 2008-05-02 15:41:08 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  Off(SW_USE_NTL_SORT); // may be changed by an command line option
64#endif
65
66#ifdef INIT_BUG
67  jjInitTab1();
68#endif
69#ifdef GENTABLE
70  extern void ttGen1();
71  extern void ttGen2b();
72  extern void ttGen4();
73  extern void mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
74  mpsr_ttGen();
75  ttGen4();
76  ttGen1();
77  ttGen2b();
78#else
79  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
80  omInitRet_2_Info(argv[0]);
81  omInitGetBackTrace();
82
83  /* initialize components */
84  siRandomStart=inits();
85  feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart);
86  int optc, option_index;
87  char* errormsg;
88
89  // do this first, because -v might print version path
90  feInitResources(argv[0]);
91  iiInitArithmetic();
92
93  // parse command line options
94  while((optc = fe_getopt_long(argc, argv,
95                               SHORT_OPTS_STRING, feOptSpec, &option_index))
96        != EOF)
97  {
98    if (optc == '?' || optc == 0)
99    {
100      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
101      exit(1);
102    }
103
104    if (optc != LONG_OPTION_RETURN)
105      option_index = feGetOptIndex(optc);
106
107    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
108
109    if (fe_optarg == NULL &&
110        (feOptSpec[option_index].type == feOptBool ||
111         feOptSpec[option_index].has_arg == optional_argument))
112      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
113    else
114      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
115
116    if (errormsg)
117    {
118      if (fe_optarg == NULL)
119        fprintf(stderr, "Error: Option '--%s' %s\n",
120               feOptSpec[option_index].name, errormsg);
121      else
122        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
123               feOptSpec[option_index].name, fe_optarg, errormsg);
124      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
125      exit(1);
126    }
127    if (optc == 'h') exit(0);
128  }
129
130  /* say hello */
131  {
132#ifdef HAVE_NS
133    basePack=(package)omAlloc0(sizeof(*basePack));
134    currPack=basePack;
135    idhdl h;
136    h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
137    IDPACKAGE(h)->language = LANG_TOP;
138    IDPACKAGE(h)=basePack;
139    currPackHdl=h;
140    basePackHdl=h;
141#endif /* HAVE_NS */
142  }
143  if (BVERBOSE(0))
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: G.-M. Greuel, G. Pfister, H. Schoenemann        \\   %s\n"
154"FB Mathematik der Universitaet, D-67653 Kaiserslautern    \\\n"
155, S_VERSION1,S_VERSION2);
156  }
157  else
158  {
159#ifdef HAVE_FACTORY
160    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
161#endif
162#ifdef HAVE_SDB
163    sdb_flags = 0;
164#endif
165    dup2(1,2);
166    /* alternative:
167    *    memcpy(stderr,stdout,sizeof(FILE));
168    */
169  }
170  slStandardInit();
171  myynest=0;
172  if (! feOptValue(FE_OPT_NO_STDLIB))
173  {
174    int vv=verbose;
175    verbose &= ~Sy_bit(V_LOAD_LIB);
176    iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE);
177    verbose=vv;
178  }
179  errorreported = 0;
180
181  // and again, ifdef OM_NDEBUG this call is undef'ed
182  // otherwise, it marks all memory allocated so far as static
183  // i.e. as memory which is not mention on omPrintUsedAddr:
184  //omMarkMemoryAsStatic();
185
186  setjmp(si_start_jmpbuf);
187
188  // Now, put things on the stack of stuff to do
189  // Last thing to do is to execute given scripts
190  if (fe_optind < argc)
191  {
192    int i = argc - 1;
193    FILE *fd;
194    while (i >= fe_optind)
195    {
196      if ((fd = feFopen(argv[i], "r")) == NULL)
197      {
198        Warn("Can not open %s", argv[i]);
199      }
200      else
201      {
202        fclose(fd);
203        newFile(argv[i]);
204      }
205      i--;
206    }
207  }
208  else
209  {
210    currentVoice=feInitStdin(NULL);
211  }
212
213  // before scripts, we execute -c, if it was given
214  if (feOptValue(FE_OPT_EXECUTE) != NULL)
215    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
216
217  // first thing, however, is to load .singularrc from Singularpath
218  // and cwd/$HOME (in that order).
219  if (! feOptValue(FE_OPT_NO_RC))
220  {
221    char buf[MAXPATHLEN];
222    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
223    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
224    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
225
226    if (rc != NULL)
227    {
228      if (BVERBOSE(V_LOAD_LIB))
229        Print("// ** executing %s\n", buf);
230      fclose(rc);
231      newFile(buf);
232    }
233  }
234
235  /* start shell */
236  if (fe_fgets_stdin==fe_fgets_dummy)
237  {
238#ifdef HAVE_MPSR
239    BatchDoProc batch_do = slInitMPBatchDo();
240    if (batch_do != NULL)
241      return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
242                         (char*) feOptValue(FE_OPT_MPHOST));
243    else
244      return 1;
245#else
246    assume(0);
247#endif
248  }
249  setjmp(si_start_jmpbuf);
250  yyparse();
251  m2_end(0);
252#endif
253  return 0;
254}
255#endif // not LIBSINGULAR
256
Note: See TracBrowser for help on using the repository browser.