source: git/Singular/tesths.cc @ 0fb3336

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