source: git/Singular/tesths.cc @ 18dd47

spielwiese
Last change on this file since 18dd47 was 7def32f, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: introduced '.singularrc', modified loading of satndard.lib (tesths.cc) git-svn-id: file:///usr/local/Singular/svn/trunk@530 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 6.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: tesths.cc,v 1.27 1997-07-16 10:58:58 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
92    {
93
94      if ((argv[1][0] != '-') ||(argv[1][1] == '-'))
95        break;
96      for (i=1;argv[1][i]!='\0';i++)
97      {
98        switch (argv[1][i])
99        {
100            case 'V':
101            case 'v':{
102              printf("Singular %s  %s  (%d)  %s %s\n",
103                     S_VERSION1,S_VERSION2,
104                     SINGULAR_VERSION_ID,__DATE__,__TIME__);
105              printf("with\n");
106              printf(versionString());
107              printf("\n\n");
108              break;
109            }
110            case 'd':
111            {
112              if (argc > 2)
113              {
114                char* ptr = NULL;
115                // OLAF: try to avoid using long:
116#ifdef HAVE_STRTOL
117                long res = strtol(argv[2], &ptr, 10);
118                if (errno != ERANGE && ptr != argv[2] && res > 0)
119#else
120                long res = 0;
121                sscanf(argv[2],"%d", &res);
122                if (res > 0)
123#endif
124                {
125                  argc--;
126                  argv++;
127                  i=0;
128                  SetTimerResolution(res);
129                }
130                else
131                  fprintf(stderr,"Can not convert %s to an integer > 0\n", argv[2]);
132              }
133              else
134              {
135                long res=0;
136                while ((argv[1][i+1]>='0') && (argv[1][i+1]<='9'))
137                {
138                  i++;
139                  res = res*10+(int)(argv[1][i] - '0');
140                }
141              }
142              break;
143            }
144            case 'e': if ((argv[1][i+1]>'0') && (argv[1][i+1]<='9'))
145            {
146              i++;
147              si_echo = (int)(argv[1][i] - '0');
148            }
149            else si_echo = 2;
150            break;
151            case 'r': siRandomStart = 0;
152              while((argv[1][i+1]>='0') && (argv[1][i+1]<='9'))
153              {
154                i++;
155                siRandomStart = siRandomStart*10+(int)(argv[1][i] - '0');
156              }
157              #ifdef buildin_rand
158                siSeed=siRandomStart;
159              #else
160                srand((unsigned int)siRandomStart);
161              #endif
162              #ifdef HAVE_FACTORY
163                factoryseed(siRandomStart);
164              #endif
165              break;
166            case 'x': tclmode=TRUE;
167              break;
168#ifdef HAVE_MPSR
169            case 'b': feBatch=TRUE;
170#endif
171            case 'q': verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
172              break;
173            case 't':
174#if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
175              fe_use_fgets=TRUE;
176#endif
177              break;
178            case 'n':
179              load_std_lib=FALSE;
180              break;
181            default : printf("Unknown option -%c\n",argv[1][i]);
182              printf("Usage: %s [-bemqtvx] [file]\n",thisfile);
183              exit(1);
184        }
185      }
186    }
187  }
188
189
190  /*. say hello */
191  if (BVERBOSE(0))
192  {
193    printf(
194"              Welcome to SINGULAR                  /\n"
195"           A Computer Algebra System             o<\n"
196" for Commutative Algebra and Algebraic Geometry    \\\n\n"
197"by: G.-M. Greuel, G. Pfister, H. Schoenemann\n"
198"Fachbereich Mathematik der Universitaet, D-67653 Kaiserslautern\n"
199"contributions: O.Bachmann,W.Decker,H.Grassmann,B.Martin,M.Messollen,W.Neumann,\n"
200"\tW.Pohl,T.Siebert,R.Stobbe,T.Wichmann\n"
201"e-mail: singular@mathematik.uni-kl.de\n");
202    printf("%s  %s  (%d)",S_VERSION1,S_VERSION2, SINGULAR_VERSION_ID);
203    printf("\n\nPlease note:  EVERY COMMAND MUST END WITH A SEMICOLON \";"
204           "\"\n(e.g. help; help command; help General syntax; help ring; quit;)\n\n");
205  }
206  else
207  if (!feBatch)
208  {
209#ifdef macintosh
210    memcpy(stderr,stdout,sizeof(FILE));
211#else
212    dup2(1,2);
213#endif
214  }
215  slStandardInit();
216  dlInit(thisfile);
217  myynest=0;
218  if (load_std_lib)
219  {
220    iiLibCmd(mstrdup("standard.lib"),TRUE);
221    //idhdl h=idroot->get("init",0);
222    //if ((h!=NULL) && (IDTYP(h)==PROC_CMD))
223    //{
224    //  IDSTRING(h)=iiGetLibProcBuffer( IDSTRING(h), IDID(h));
225    //  newBuffer( mstrdup(IDSTRING(h)), BT_execute, IDID(h) );
226      //leftv r=iiMake_proc(h,NULL);
227      //r->CleanUp();
228      //iiPStart(h,NULL,NULL);
229    //}
230  } 
231  errorreported = 0;
232#ifndef macintosh
233#if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
234  fe_set_input_mode();
235#endif
236#endif
237  setjmp(si_start_jmpbuf);
238  {
239    char * where=(char *)AllocL(256);
240    FILE * rc=feFopen(".singularrc","r",where,FALSE);
241    if (rc!=NULL)
242    {
243      fclose(rc);
244      iiPStart(NULL,where,NULL);
245    }
246    FreeL((ADDRESS)where);
247  }
248  /* if script is given */
249  if ((argc > 1)&&(argv[1][0]!='-'))
250  {
251    /* read and run the Script */
252    argc=1;
253    iiPStart(NULL,argv[1],NULL);
254  }
255  /* start shell */
256  if (feBatch)
257  {
258#ifdef HAVE_MPSR
259    extern int Batch_do(int argc, char **argv);
260    return Batch_do(argc,argv);
261#else
262    fprintf(stderr, "Option -b not supported in this version");
263    return 1;
264#endif // HAVE_MPSR
265  }
266  setjmp(si_start_jmpbuf);
267  yyparse();
268#endif
269  return 0;
270}
Note: See TracBrowser for help on using the repository browser.