source: git/Singular/tesths.cc @ 923c27

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