source: git/Singular/tesths.cc @ 4eb5b5

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