source: git/Singular/tesths.cc @ 48ce9a

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