source: git/Singular/tesths.cc @ c232af

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