source: git/Singular/tesths.cc @ 634dab0

spielwiese
Last change on this file since 634dab0 was d87eb0, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes: grammar.y tesths.cc git-svn-id: file:///usr/local/Singular/svn/trunk@8011 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: tesths.cc,v 1.98 2005-05-03 09:35:17 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 "sing_dld.h"
21#include "febase.h"
22#include "cntrlc.h"
23#include "omalloc.h"
24#include "silink.h"
25#include "ipid.h"
26#include "timer.h"
27#include "sdb.h"
28#include "fegetopt.h"
29#include "feOpt.h"
30#include "distrib.h"
31#include "version.h"
32#include "slInit.h"
33
34#ifdef HAVE_FACTORY
35#define SI_DONT_HAVE_GLOBAL_VARS
36#include <factory.h>
37#endif
38
39char *singular_date=__DATE__ " " __TIME__;
40
41/*0 implementation*/
42int main(          /* main entry to Singular */
43    int argc,      /* number of parameter */
44    char** argv)   /* parameter array */
45{
46#ifdef HAVE_FACTORY
47  On(SW_USE_NTL);
48  Off(SW_USE_NTL_GCD_0);
49  Off(SW_USE_NTL_GCD_P);
50  On(SW_USE_EZGCD);
51  Off(SW_USE_NTL_SORT);
52#endif
53
54#ifdef INIT_BUG
55  jjInitTab1();
56#endif
57#ifdef GENTABLE
58  extern void ttGen1();
59  extern void ttGen2();
60  extern void ttGen4();
61  #ifndef __MWERKS__
62    extern void mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
63    mpsr_ttGen();
64  #endif
65  ttGen4();
66  ttGen1();
67  ttGen2();
68#else
69  // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed
70  omInitRet_2_Info(argv[0]);
71  omInitGetBackTrace();
72
73  /* initialize components */
74  siRandomStart=inits();
75  feOptSpec[FE_OPT_RANDOM].value = (void*) siRandomStart;
76  int optc, option_index;
77  char* errormsg;
78
79  // do this first, because -v might print version path
80  feInitResources(argv[0]);
81
82  // parse command line options
83  while((optc = fe_getopt_long(argc, argv,
84                               SHORT_OPTS_STRING, feOptSpec, &option_index))
85        != EOF)
86  {
87    if (optc == '?' || optc == 0)
88    {
89      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
90      exit(1);
91    }
92
93    if (optc != LONG_OPTION_RETURN)
94      option_index = feGetOptIndex(optc);
95
96    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
97
98    if (fe_optarg == NULL &&
99        (feOptSpec[option_index].type == feOptBool ||
100         feOptSpec[option_index].has_arg == optional_argument))
101      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
102    else
103      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
104
105    if (errormsg)
106    {
107      if (fe_optarg == NULL)
108        fprintf(stderr, "Error: Option '--%s' %s\n",
109               feOptSpec[option_index].name, errormsg);
110      else
111        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
112               feOptSpec[option_index].name, fe_optarg, errormsg);
113      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
114      exit(1);
115    }
116    if (optc == 'h') exit(0);
117  }
118
119  /* say hello */
120  {
121#ifdef HAVE_NS
122    basePack=(package)omAlloc0(sizeof(*basePack));
123    currPack=basePack;
124    idhdl h;
125    h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE);
126    IDPACKAGE(h)->language = LANG_TOP;
127    IDPACKAGE(h)=basePack;
128    currPackHdl=h;
129    basePackHdl=h;
130#endif /* HAVE_NS */
131  }
132  if (BVERBOSE(0))
133  {
134    (printf)(
135"                     SINGULAR                             /"
136#ifndef MAKE_DISTRIBUTION
137"  Development"
138#endif
139"\n"
140" A Computer Algebra System for Polynomial Computations   /   version %s\n"
141"                                                       0<\n"
142"     by: G.-M. Greuel, G. Pfister, H. Schoenemann        \\   %s\n"
143"FB Mathematik der Universitaet, D-67653 Kaiserslautern    \\\n"
144, S_VERSION1,S_VERSION2);
145  }
146  else
147  {
148#ifdef HAVE_FACTORY
149    if (feOptValue(FE_OPT_SORT)) On(SW_USE_NTL_SORT);
150#endif
151#ifdef HAVE_SDB
152    sdb_flags = 0;
153#endif
154#ifdef __MWERKS__
155    memcpy(stderr,stdout,sizeof(FILE));
156#else
157    dup2(1,2);
158#endif
159  }
160  slStandardInit();
161  dlInit(feArgv0);
162  myynest=0;
163  if (! feOptValue(FE_OPT_NO_STDLIB))
164  {
165    int vv=verbose;
166    verbose &= ~Sy_bit(V_LOAD_LIB);
167    iiLibCmd(omStrDup("standard.lib"), TRUE);
168    verbose=vv;
169  }
170  errorreported = 0;
171
172  // and again, ifdef OM_NDEBUG this call is undef'ed
173  // otherwise, it marks all memory allocated so far as static
174  // i.e. as memory which is not mention on omPrintUsedAddr:
175  //omMarkMemoryAsStatic();
176
177  setjmp(si_start_jmpbuf);
178
179  // Now, put things on the stack of stuff to do
180  // Last thing to do is to execute given scripts
181  if (fe_optind < argc)
182  {
183    int i = argc - 1;
184    FILE *fd;
185    while (i >= fe_optind)
186    {
187      if ((fd = feFopen(argv[i], "r")) == NULL)
188      {
189        Warn("Can not open %s", argv[i]);
190      }
191      else
192      {
193        fclose(fd);
194        newFile(argv[i]);
195      }
196      i--;
197    }
198  }
199  else
200  {
201    currentVoice=feInitStdin(NULL);
202  }
203
204  // before scripts, we execute -c, if it was given
205  if (feOptValue(FE_OPT_EXECUTE) != NULL)
206    newBuffer(omStrDup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
207
208  // first thing, however, is to load .singularrc from Singularpath
209  // and cwd/$HOME (in that order).
210  if (! feOptValue(FE_OPT_NO_RC))
211  {
212    char buf[MAXPATHLEN];
213    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
214    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
215    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
216
217    if (rc != NULL)
218    {
219      if (BVERBOSE(V_LOAD_LIB))
220        Print("// ** executing %s\n", buf);
221      fclose(rc);
222      newFile(buf);
223    }
224  }
225
226  /* start shell */
227  if (fe_fgets_stdin==fe_fgets_dummy)
228  {
229#ifdef HAVE_MPSR
230    BatchDoProc batch_do = slInitMPBatchDo();
231    if (batch_do != NULL)
232      return (*batch_do)((char*) feOptValue(FE_OPT_MPPORT),
233                         (char*) feOptValue(FE_OPT_MPHOST));
234    else
235      return 1;
236#else
237    assume(0);
238#endif
239  }
240  setjmp(si_start_jmpbuf);
241  yyparse();
242  m2_end(0);
243#endif
244  return 0;
245}
246
Note: See TracBrowser for help on using the repository browser.