source: git/Singular/tesths.cc @ a18fae

spielwiese
Last change on this file since a18fae was a18fae, checked in by Hans Schönemann <hannes@…>, 26 years ago
* hannes: fixed echo handling (febase.h febase.inc, silink.cc) updated documentation (doc/*.doc) git-svn-id: file:///usr/local/Singular/svn/trunk@1187 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.4 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: tesths.cc,v 1.31 1998-02-27 16:28:01 Singular Exp $ */
5
6/*
7* ABSTRACT - initialize SINGULARs components, run Script and start SHELL
8*/
9
10#ifndef macintosh
11#include <unistd.h>
12#endif
13#include <string.h>
14#include <stdio.h>
15#include <stddef.h>
16#include <stdlib.h>
17#include <time.h>
18#include <errno.h>
19#include "version.h"
20#include "mod2.h"
21#include "tok.h"
22#include "ipshell.h"
23#include "sing_dld.h"
24#include "febase.h"
25#include "cntrlc.h"
26#include "mmemory.h"
27#include "silink.h"
28#include "ipid.h"
29#include "timer.h"
30#ifdef HAVE_FACTORY
31#define SI_DONT_HAVE_GLOBAL_VARS
32#include <factory.h>
33#endif
34
35
36/*0 implementation*/
37int main(          /* main entry to Singular */
38    int argc,      /* number of parameter */
39    char** argv)   /* parameter array */
40{
41  char * thisfile;
42  /* initialize components */
43  siRandomStart=inits();
44#ifdef INIT_BUG
45  jjInitTab1();
46#endif
47#ifdef GENTABLE
48  extern ttGen1();
49  extern ttGen2();
50  #ifndef macintosh
51    extern mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
52    mpsr_ttGen();
53  #endif
54  ttGen1();
55  ttGen2();
56#else
57  int i;
58  thisfile = argv[0];
59  BOOLEAN load_std_lib=TRUE;
60  /*. process parameters */
61  for (;(argc > 1) && (!feBatch); --argc, ++argv)
62  {
63    if (strcmp(argv[1], "-m") == 0)
64    {
65      {
66        if (argc > 2)
67        {
68          char* ptr = NULL;
69#ifdef HAVE_STRTOD
70          double mintime = strtod(argv[2], &ptr);
71          if (errno != ERANGE && ptr != argv[2])
72#else
73          double mintime = 0;
74          sscanf(argv[2],"%f", &mintime);
75          if (mintime != 0.0)
76#endif
77          {
78            argc--;
79            argv++;
80            SetMinDisplayTime(mintime);
81          }
82          else
83            fprintf(stderr, "Can not convert %s to a float\n", argv[2]);
84        }
85        else
86        {
87          fprintf(stderr, "Need a float to set mintime");
88        }
89      }
90    }
91    else if (strcmp(argv[1], "-d") == 0)
92    {
93     
94      if (argc > 2)
95      {
96        char* ptr = NULL;
97        // OLAF: try to avoid using long:
98#ifdef HAVE_STRTOL
99        long res = strtol(argv[2], &ptr, 10);
100        if (errno != ERANGE && ptr != argv[2] && res > 0)
101#else
102          long res = 0;
103        sscanf(argv[2],"%d", &res);
104        if (res > 0)
105#endif
106        {
107          argc--;
108          argv++;
109          i=0;
110          SetTimerResolution(res);
111        }
112        else
113          fprintf(stderr,"Can not convert %s to an integer > 0\n", argv[2]);
114      }
115      else
116      {
117        long res=0;
118        while ((argv[1][i+1]>='0') && (argv[1][i+1]<='9'))
119        {
120          i++;
121          res = res*10+(int)(argv[1][i] - '0');
122          SetTimerResolution(res);
123        }
124      }
125    }
126    else
127    {
128
129      if ((argv[1][0] != '-') ||(argv[1][1] == '-'))
130        break;
131      for (i=1;argv[1][i]!='\0';i++)
132      {
133        switch (argv[1][i])
134        {
135            case 'V':
136            case 'v':{
137              printf("Singular %s  %s  (%d)  %s %s\n",
138                     S_VERSION1,S_VERSION2,
139                     SINGULAR_VERSION_ID,__DATE__,__TIME__);
140              printf("with\n");
141              printf(versionString());
142              printf("\n\n");
143              break;
144            }
145            case 'e': if ((argv[1][i+1]>'0') && (argv[1][i+1]<='9'))
146            {
147              i++;
148              si_echo = (int)(argv[1][i] - '0');
149            }
150            else si_echo = 1;
151            break;
152            case 'r': siRandomStart = 0;
153              while((argv[1][i+1]>='0') && (argv[1][i+1]<='9'))
154              {
155                i++;
156                siRandomStart = siRandomStart*10+(int)(argv[1][i] - '0');
157              }
158              #ifdef buildin_rand
159                siSeed=siRandomStart;
160              #else
161                srand((unsigned int)siRandomStart);
162              #endif
163              #ifdef HAVE_FACTORY
164                factoryseed(siRandomStart);
165              #endif
166              break;
167#ifdef HAVE_TCL       
168            case 'x': tclmode=TRUE;
169              break;
170#endif       
171#ifdef HAVE_MPSR
172            case 'b': feBatch=TRUE;
173#endif
174            case 'q': verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
175              break;
176            case 't':
177#if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
178              fe_use_fgets=TRUE;
179#endif
180              break;
181            case 'n':
182              load_std_lib=FALSE;
183              break;
184            default : printf("Unknown option -%c\n",argv[1][i]);
185              printf("Usage: %s [-bemqtvx] [file]\n",thisfile);
186              exit(1);
187        }
188      }
189    }
190  }
191
192
193  /*. say hello */
194  if (BVERBOSE(0))
195  {
196    printf(
197"              Welcome to SINGULAR                  /\n"
198"           A Computer Algebra System             o<\n"
199" for Commutative Algebra and Algebraic Geometry    \\\n\n"
200"by: G.-M. Greuel, G. Pfister, H. Schoenemann\n"
201"Fachbereich Mathematik der Universitaet, D-67653 Kaiserslautern\n"
202"contributions: O.Bachmann,W.Decker,H.Grassmann,B.Martin,M.Messollen,W.Neumann,\n"
203"\tW.Pohl,T.Siebert,R.Stobbe,T.Wichmann\n"
204"e-mail: singular@mathematik.uni-kl.de\n");
205    printf("%s  %s  (%d)",S_VERSION1,S_VERSION2, SINGULAR_VERSION_ID);
206    printf("\n\nPlease note:  EVERY COMMAND MUST END WITH A SEMICOLON \";"
207           "\"\n(e.g. help; help command; help General syntax; help ring; quit;)\n\n");
208  }
209  else
210  if (!feBatch)
211  {
212#ifdef macintosh
213    memcpy(stderr,stdout,sizeof(FILE));
214#else
215    dup2(1,2);
216#endif
217  }
218  slStandardInit();
219  dlInit(thisfile);
220  myynest=0;
221  if (load_std_lib)
222  {
223    iiLibCmd(mstrdup("standard.lib"),TRUE);
224  } 
225  errorreported = 0;
226#ifndef macintosh
227#if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
228  fe_set_input_mode();
229#endif
230#endif
231  setjmp(si_start_jmpbuf);
232  /* if script is given */
233  if ((argc > 1)&&(argv[1][0]!='-'))
234  {
235    /* read and run the Script */
236    argc=1;
237    newFile(argv[1]);
238  }
239  else
240  {
241    currentVoice=feInitStdin();
242  }
243  // set up voice for .singularc
244  {
245    char * where=(char *)AllocL(256);
246    FILE * rc=feFopen(".singularrc","r",where,FALSE);
247    if (rc!=NULL)
248    {
249      fclose(rc);
250      newFile(where);
251    }
252    FreeL((ADDRESS)where);
253  }
254  /* start shell */
255  if (feBatch)
256  {
257#ifdef HAVE_MPSR
258    extern int Batch_do(int argc, char **argv);
259    return Batch_do(argc,argv);
260#else
261    fprintf(stderr, "Option -b not supported in this version");
262    return 1;
263#endif // HAVE_MPSR
264  }
265  setjmp(si_start_jmpbuf);
266  yyparse();
267#endif
268  //Print("at very end\n");
269  m2_end(0);
270  return 0;
271}
Note: See TracBrowser for help on using the repository browser.