source: git/Singular/tesths.cc @ 416465

spielwiese
Last change on this file since 416465 was 416465, checked in by Olaf Bachmann <obachman@…>, 24 years ago
* bug-fixes from work with Thomas git-svn-id: file:///usr/local/Singular/svn/trunk@3826 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 5.4 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: tesths.cc,v 1.78 1999-11-15 17:20:55 obachman 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 "mmemory.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
33#ifdef HAVE_FACTORY
34#define SI_DONT_HAVE_GLOBAL_VARS
35#include <factory.h>
36#endif
37
38/*0 implementation*/
39int main(          /* main entry to Singular */
40    int argc,      /* number of parameter */
41    char** argv)   /* parameter array */
42{
43#ifdef INIT_BUG
44  jjInitTab1();
45#endif
46#ifdef GENTABLE
47  extern void ttGen1();
48  extern void ttGen2();
49  #ifndef __MWERKS__
50    extern mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
51    mpsr_ttGen();
52  #endif
53  ttGen1();
54  ttGen2();
55#else
56  /* initialize components */
57  siRandomStart=inits();
58  feOptSpec[FE_OPT_RANDOM].value = (void*) siRandomStart;
59  int optc, option_index;
60  char* errormsg;
61
62  // do this first, because -v might print version path
63  feInitResources(argv[0]);
64
65  // parse command line options
66  while((optc = fe_getopt_long(argc, argv,
67                               SHORT_OPTS_STRING, feOptSpec, &option_index))
68//                               "", feOptSpec, &option_index))
69        != EOF)
70  {
71    if (optc == '?' || optc == 0)
72    {
73      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
74      exit(1);
75    }
76
77    if (optc != LONG_OPTION_RETURN)
78      option_index = feGetOptIndex(optc);
79
80    assume(option_index >= 0 && option_index < (int) FE_OPT_UNDEF);
81
82    if (fe_optarg == NULL &&
83        (feOptSpec[option_index].type == feOptBool ||
84         feOptSpec[option_index].has_arg == optional_argument))
85      errormsg = feSetOptValue((feOptIndex) option_index, (int) 1);
86    else
87      errormsg = feSetOptValue((feOptIndex) option_index, fe_optarg);
88
89    if (errormsg)
90    {
91      if (fe_optarg == NULL)
92        fprintf(stderr, "Error: Option '--%s' %s\n",
93               feOptSpec[option_index].name, errormsg);
94      else
95        fprintf(stderr, "Error: Option '--%s=%s' %s\n",
96               feOptSpec[option_index].name, fe_optarg, errormsg);
97      fprintf(stderr, "Use '%s --help' for a complete list of options\n", feArgv0);
98      exit(1);
99    }
100    if (optc == 'h') exit(0);
101  }
102
103  /* say hello */
104  {
105    idhdl h;
106    namespaceroot->push(NULL, "Top", 0, TRUE);
107#ifdef HAVE_NAMESPACES
108    h=enterid(mstrdup("Top"), 0, PACKAGE_CMD, &IDROOT, TRUE);
109    IDPACKAGE(h) = NSPACK(namespaceroot);
110    IDPACKAGE(h)->language = LANG_TOP;
111#endif /* HAVE_NAMESPACES */
112  }
113  if (BVERBOSE(0))
114  {
115    printf(
116"                     SINGULAR                             /"
117#ifndef MAKE_DISTRIBUTION
118"  Development"
119#endif
120"\n"
121" A Computer Algebra System for Polynomial Computations   /   version %s\n"
122"                                                       0<\n"
123"     by: G.-M. Greuel, G. Pfister, H. Schoenemann        \\   %s\n"
124"FB Mathematik der Universitaet, D-67653 Kaiserslautern    \\\n"
125, S_VERSION1,S_VERSION2);
126  }
127  else
128  {
129    sdb_flags = 0;
130#ifdef __MWERKS__
131    memcpy(stderr,stdout,sizeof(FILE));
132#else
133    dup2(1,2);
134#endif
135  }
136  slStandardInit();
137  dlInit(feArgv0);
138  myynest=0;
139  if (! feOptValue(FE_OPT_NO_STDLIB))
140  {
141    int vv=verbose;
142    verbose &= ~Sy_bit(V_LOAD_LIB);
143#ifdef HAVE_NAMESPACES
144    iiLibCmd(mstrdup("standard.lib"),TRUE, TRUE);
145#else /* HAVE_NAMESPACES */
146    iiLibCmd(mstrdup("standard.lib"), TRUE);
147#endif /* HAVE_NAMESPACES */
148    verbose=vv;
149  }
150  errorreported = 0;
151  mmMarkInitDBMCB();
152  setjmp(si_start_jmpbuf);
153
154  // Now, put things on the stack of stuff to do
155
156  // Last thing to do is to execute given scripts
157  if (fe_optind < argc)
158  {
159    int i = argc - 1;
160    FILE *fd;
161    while (i >= fe_optind)
162    {
163      if ((fd = feFopen(argv[i], "r")) == NULL)
164      {
165        Warn("Can not open %s", argv[i]);
166      }
167      else
168      {
169        fclose(fd);
170        newFile(argv[i]);
171      }
172      i--;
173    }
174  }
175  else
176  {
177    currentVoice=feInitStdin();
178  }
179
180  // before scripts, we execute -c, if it was given
181  if (feOptValue(FE_OPT_EXECUTE) != NULL)
182    newBuffer(mstrdup((char*) feOptValue(FE_OPT_EXECUTE)), BT_execute);
183
184  // first thing, however, is to load .singularrc from Singularpath
185  // and cwd/$HOME (in that order).
186  if (! feOptValue(FE_OPT_NO_RC))
187  {
188    char buf[MAXPATHLEN];
189    FILE * rc = feFopen("." DIR_SEPP ".singularrc", "r", buf);
190    if (rc == NULL) rc = feFopen("~" DIR_SEPP ".singularrc", "r", buf);
191    if (rc == NULL) rc = feFopen(".singularrc", "r", buf);
192
193    if (rc != NULL)
194    {
195      if (BVERBOSE(V_LOAD_LIB))
196        Print("// ** executing %s\n", buf);
197      fclose(rc);
198      newFile(buf);
199    }
200  }
201
202  /* start shell */
203  if (fe_fgets_stdin==fe_fgets_dummy)
204  {
205#ifdef HAVE_MPSR
206    extern int Batch_do(const char* port, const char* host);
207    return Batch_do((char*) feOptValue(FE_OPT_MPPORT),
208                    (char*) feOptValue(FE_OPT_MPHOST));
209#else
210    assume(0);
211#endif
212  }
213  setjmp(si_start_jmpbuf);
214  yyparse();
215#endif
216  //Print("at very end\n");
217  m2_end(0);
218  return 0;
219}
220
Note: See TracBrowser for help on using the repository browser.