source: git/Singular/tesths.cc @ ff8601

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