source: git/Singular/tesths.cc @ 658488c

spielwiese
Last change on this file since 658488c was 49eeee, checked in by Hans Schönemann <hannes@…>, 26 years ago
* hannes: fixed bug in maps.cc: size of monom is not pMonomSize but mmGetSpecSize() changed header in tesths.cc changed handling of ring changes (polys*.cc ring.cc) git-svn-id: file:///usr/local/Singular/svn/trunk@1462 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 15.4 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: tesths.cc,v 1.35 1998-04-24 16:39:26 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#include <getopt.h>
36
37// define the long option names here
38#define LON_BATCH           "batch"
39#define LON_EXECUTE         "execute"
40#define LON_ECHO            "echo"
41#define LON_HELP            "help"
42#define LON_RANDOM          "random"
43#define LON_QUIET           "quiet"
44#define LON_NO_TTY          "no-tty"
45#define LON_USER_OPTION     "user-option"
46#define LON_VERSION         "version"
47#define LON_MIN_TIME        "min-time"
48#define LON_NO_STDLIB       "no-stdlib"
49#define LON_NO_RC           "no-rc"
50#define LON_TICKS_PER_SEC   "ticks-per-sec"
51#define LON_TCLMODE         "tclmode"
52#define LON_MP_PORT         "MPport"
53#define LON_MP_HOST         "MPhost"
54// undocumented options
55#ifdef HAVE_MPSR
56#define LON_MP_TRANSP       "MPtransp"
57#define LON_MP_MODE         "MPmode"
58#endif
59
60static struct option longopts[] =
61{
62#ifdef HAVE_MPSR
63  {LON_BATCH,             0,  0,  'b'},   
64#endif
65  {LON_HELP,              0,  0,  'h'},
66  {LON_QUIET,             0,  0,  'q'},   
67  {LON_NO_TTY,            0,  0,  't'},
68  {LON_VERSION,           0,  0,  'v'},
69#ifdef HAVE_TCL
70  {LON_TCLMODE,           0,  0,  'x'},
71#endif
72  {LON_ECHO,              2,  0,  'e'},
73  {LON_EXECUTE,           1,  0,  'c'},
74  {LON_RANDOM,            1,  0,  'r'},
75  {LON_USER_OPTION,       1,  0,  'u'},
76  {LON_NO_STDLIB,         0,  0,  0},
77  {LON_NO_RC,             0,  0,  0},
78  {LON_MIN_TIME,          1,  0,  0},
79#ifdef HAVE_MPSR
80  {LON_MP_PORT,           1,  0,  0},
81  {LON_MP_HOST,           1,  0,  0},
82#endif
83  {LON_TICKS_PER_SEC,     1,  0,  0},
84// undocumented options
85#ifdef HAVE_MPSR
86  {LON_MP_TRANSP,         1,  0,  0},
87  {LON_MP_MODE,           1,  0,  0},
88#endif
89// terminator
90  { 0, 0, 0, 0 }
91};
92// #define SHORT_OPTS_STRING "bc:e::hqr:tu:v"
93#define SHORT_OPTS_STRING "bhqtvxec:r:u:"
94
95struct sing_option
96{
97  const char*   name;    // as in option
98  const char*   arg_name;// name of argument, if has_arg > 0
99  const char*   help;    // (short) help string
100  char*         val;     // (default) value of option: 0: not set 1:set
101                         // string:"" if has_arg > 0
102};
103
104// mention only documented options here
105static struct sing_option sing_longopts[] = 
106{
107#ifdef HAVE_MPSR
108  {LON_BATCH,       0,          "Run in MP batch mode",                                 0},   
109#endif
110  {LON_HELP,        0,          "Print help message and exit",                          0},
111  {LON_QUIET,       0,          "Do not print start-up banner and warnings",            0},   
112  {LON_NO_TTY,      0,          "Do not redefine the terminal characteristics",         0},
113  {LON_VERSION,     0,          "Print extended version and configuration info",        0},
114#ifdef HAVE_TCL
115  {LON_TCLMODE      0,          "Run in TCL mode, i.e., with TCL user interface",       0},
116#endif 
117  {LON_ECHO,        "VAL",      "Set value of variable `echo' to (integer) VAL",        ""},
118  {LON_EXECUTE,     "STRING",   "Execute STRING on start-up",                           ""},
119  {LON_RANDOM,      "SEED",     "Seed random generator with integer (integer) SEED",    ""},
120  {LON_USER_OPTION, "STRING",   "Return STRING on `system(\"--user-option\")'",         ""},
121  {LON_NO_STDLIB,   0,          "Do not load `standard.lib' on start-up",               0},
122  {LON_NO_RC,       0,          "Do not execute `.singularrc' file on start-up",        0},
123  {LON_MIN_TIME,    "SECS",     "Do not display times smaller than SECS (in seconds)",  "0.5"},
124#ifdef HAVE_MPSR
125  {LON_MP_PORT,     "PORT",     "Use PORT number for MP conections",                    ""},
126  {LON_MP_HOST,     "HOST",     "Use HOST for MP connections",                          ""},
127#endif
128  {LON_TICKS_PER_SEC, "TICKS",    "Sets unit of timer to TICKS per second",             "1"},
129  { 0, 0, 0, 0 }
130};
131
132static struct sing_option* mainGetSingOption(const char* name)
133{
134  int i = 0;
135  while (sing_longopts[i].name != 0)
136  {
137    if (strcmp(name, sing_longopts[i].name) == 0)
138      return &(sing_longopts[i]);
139    i++;
140  }
141  return NULL;
142}
143
144static void mainSetSingOptionValue(const char* name, char* value)
145{
146  sing_option* sopt = mainGetSingOption(name);
147  if (sopt != NULL)
148  {
149    sopt->val = value;
150  }
151}
152
153
154static char* mainGetSingOptionValue(const char* name)
155{
156  sing_option* sopt = mainGetSingOption(name);
157  if (sopt!=NULL)
158    return sopt->val;
159  return NULL;
160}
161
162
163// Prints help message
164static void mainHelp(const char* name)
165{
166  int i = 0;
167  struct sing_option *sopt;
168  char tmp[20];
169
170  printf("Singular %s -- a CAS for polynomial computations. Usage:\n", S_VERSION1);
171  printf("   %s [options] [file1 [file2 ...]]\n", name);
172  printf("Options:\n");
173 
174  while (longopts[i].name != 0)
175  {
176    sopt = mainGetSingOption(longopts[i].name);
177    if (sopt != NULL)
178    {
179      if (longopts[i].has_arg > 0)
180      {
181        if  (longopts[i].has_arg > 1)
182          sprintf(tmp, "%s[=%s]", longopts[i].name, sopt->arg_name);
183        else
184          sprintf(tmp, "%s=%s", longopts[i].name, sopt->arg_name);
185
186        printf(" %c%c --%-19s %s\n",
187               (longopts[i].val != 0 ? '-' : ' '),
188               (longopts[i].val != 0 ? longopts[i].val : ' '),
189               tmp,
190               sopt->help);
191      }
192      else
193      {
194        printf(" %c%c --%-19s %s\n",
195               (longopts[i].val != 0 ? '-' : ' '),
196               (longopts[i].val != 0 ? longopts[i].val : ' '),
197               longopts[i].name,
198               sopt->help);
199      }
200    }
201#ifndef NDEBUG     
202    else
203      printf("--%s Undocumented\n", longopts[i].name);
204#endif
205    i++;
206  }
207
208  printf("\nFor more information, type `help;' from within Singular or visit\n");
209  printf("http://www.mathematik.uni-kl.de/~zca/Singular or consult the\n");
210  printf("Singular manual (available as on-line info or printed manual).\n");
211}
212
213// Prints usage message
214static void mainUsage(char* argv0)
215{
216  printf("Use `%s --help' for a complete list of options\n", argv0);
217}
218
219#ifndef NDEBUG
220void mainOptionValues()
221{
222  int i = 0;
223  struct sing_option *sopt;
224
225  while (longopts[i].name != 0)
226  {
227    sopt = mainGetSingOption(longopts[i].name);
228    if (sopt != NULL)
229    {
230      if (sopt->val == NULL || sopt->val == (char*) 1)
231        Print("// --%-10s %d\n", sopt->name, sopt->val);
232      else
233        Print("// --%-10s %s\n", sopt->name, sopt->val); 
234    }
235    else
236      Print("// --%s Undocumented \n", longopts[i].name);
237    i++;
238  }
239}
240#endif // NDEBUG
241
242BOOLEAN mainGetSingOptionValue(const char* name, char** val)
243{
244  sing_option* sopt = mainGetSingOption(name);
245  if (sopt == NULL)
246  {
247    *val = NULL;
248    return FALSE;
249  }
250  else
251  {
252    *val = sopt->val;
253    return TRUE;
254  }
255}
256
257/*0 implementation*/
258int main(          /* main entry to Singular */
259    int argc,      /* number of parameter */
260    char** argv)   /* parameter array */
261{
262  char * thisfile;
263  /* initialize components */
264  siRandomStart=inits();
265#ifdef INIT_BUG
266  jjInitTab1();
267#endif
268#ifdef GENTABLE
269  extern ttGen1();
270  extern ttGen2();
271  #ifndef macintosh
272    extern mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
273    mpsr_ttGen();
274  #endif
275  ttGen1();
276  ttGen2();
277#else
278  int i;
279  thisfile = argv[0];
280  BOOLEAN load_std_lib=TRUE;
281  BOOLEAN load_rc = TRUE;
282  char* execute_string = NULL;
283  int optc, option_index;
284
285  // do this first, because -v might print version path
286  feGetSearchPath(thisfile);
287
288  // parse command line options
289  while((optc = getopt_long(argc, argv,
290                            SHORT_OPTS_STRING, longopts, &option_index)) 
291        != EOF)
292  {
293    switch(optc)
294    {
295         
296        case 'b':
297#ifdef HAVE_MPSR         
298          feBatch=TRUE;
299          mainSetSingOptionValue(LON_BATCH, (char*) 1);
300          break;
301#else
302          printf("%s: Option `-b' not supported in this configuration\n", argv[0]);
303          mainUsage(argv[0]);
304          exit(1);
305#endif
306
307        case 'h':
308          mainHelp(argv[0]);
309          exit(0);
310
311        case 'q':
312          verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
313          mainSetSingOptionValue(LON_QUIET, (char*) 1);
314          break;
315
316        case 't':
317#if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
318          fe_use_fgets=TRUE;
319#endif
320          mainSetSingOptionValue(LON_NO_TTY, (char*) 1);
321          break;
322
323        case 'v':
324          printf("Singular %s  %s  (%d)  %s %s\n",
325                 S_VERSION1,S_VERSION2,
326                 SINGULAR_VERSION_ID,__DATE__,__TIME__);
327          printf("with\n");
328          printf(versionString());
329          printf("\n\n");
330          mainSetSingOptionValue(LON_VERSION, (char*) 1);
331          break;
332
333        case 'x':
334#ifdef HAVE_TCL
335          tclmode = TRUE;
336          mainSetSingOptionValue(LON_TCL-MODE, (char*) 1);
337          break;
338#else
339          printf("%s: Option `-x' not supported in this configuration\n", argv[0]);
340          mainUsage(argv[0]);
341          exit(1);
342#endif
343
344        case 'e':
345          if (optarg != NULL)
346          {
347            errno = 0;
348            si_echo = strtol(optarg, NULL, 10);
349            if (errno)
350            {
351              printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_ECHO);
352              mainUsage(argv[0]);
353              exit(1);
354            }
355            if (si_echo < 0 || si_echo > 9)
356            {
357              printf("%s: `%s' argument for option `--%s' is not in valid range 0..9\n",
358                     argv[0], optarg, LON_ECHO);
359              mainUsage(argv[0]);
360              exit(1);
361            }
362            mainSetSingOptionValue(LON_ECHO, optarg);
363          }
364          else
365          {
366            si_echo = 1;
367            mainSetSingOptionValue(LON_ECHO, "1");
368          }
369          break;
370
371        case 'c':
372          execute_string = optarg;
373          mainSetSingOptionValue(LON_EXECUTE, optarg);
374          break;
375         
376        case 'r':
377          errno = 0;
378          siRandomStart = strtol(optarg, NULL, 10);
379          if (errno)
380          {
381            printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_RANDOM);
382            mainUsage(argv[0]);
383            exit(1);
384          }
385          #ifdef buildin_rand
386          siSeed=siRandomStart;
387          #else
388          srand((unsigned int)siRandomStart);
389          #endif
390          #ifdef HAVE_FACTORY
391          factoryseed(siRandomStart);
392          #endif
393          mainSetSingOptionValue(LON_RANDOM, optarg);
394          break;
395         
396        case 'u':
397          mainSetSingOptionValue(LON_USER_OPTION, optarg);
398          break;
399
400        case 0:
401          if (strcmp(longopts[option_index].name, LON_NO_STDLIB) == 0)
402          {
403            load_std_lib = FALSE;
404            mainSetSingOptionValue(LON_NO_STDLIB, (char*) 1);
405          }
406          else if (strcmp(longopts[option_index].name, LON_NO_RC) == 0)
407          {
408            load_rc = FALSE;
409            mainSetSingOptionValue(LON_NO_RC, (char*) 1);
410          }
411          else if (strcmp(longopts[option_index].name, LON_MIN_TIME) == 0)
412          {
413            double mintime = atof(optarg);
414            if (mintime <= 0)
415            {
416              printf("%s: `%s' invalid float argument for option `--%s'\n", 
417                     argv[0], optarg, LON_MIN_TIME);
418              mainUsage(argv[0]);
419              exit(1);
420            }
421            SetMinDisplayTime(mintime);
422            mainSetSingOptionValue(LON_MIN_TIME, optarg);
423          }
424#ifdef HAVE_MPSR
425          else if (strcmp(longopts[option_index].name, LON_MP_PORT) == 0)
426          {
427            mainSetSingOptionValue(LON_MP_PORT, optarg);
428          }
429          else if (strcmp(longopts[option_index].name, LON_MP_HOST) == 0)
430          {
431            mainSetSingOptionValue(LON_MP_HOST, optarg);
432          }
433#endif         
434          else if (strcmp(longopts[option_index].name, LON_TICKS_PER_SEC) == 0)
435          {
436            int ticks = atoi(optarg);
437            if (ticks <= 0)
438            {
439              printf("%s: `%s' invalid integer argument for option `--%s'\n",
440                     argv[0], optarg, LON_TICKS_PER_SEC);
441              mainUsage(argv[0]);
442              exit(1);
443            }
444            SetTimerResolution(ticks);
445            mainSetSingOptionValue(LON_TICKS_PER_SEC, optarg);
446          }
447          else
448            // undocumented options
449#ifdef HAVE_MPSR
450            if (strcmp(longopts[option_index].name, LON_MP_MODE) == 0 ||
451                strcmp(longopts[option_index].name, LON_MP_TRANSP) == 0)
452            {
453              /* ignore */
454            }
455          else
456#endif
457            assume(0);
458          break;
459
460        default:
461          // Error message already emmited by getopt_long
462          mainUsage(argv[0]);
463          exit(1);
464    }
465  }
466  /*. say hello */
467  if (BVERBOSE(0) && !feBatch)
468  {
469    printf(
470"              Welcome to SINGULAR                  /\n"
471"           A Computer Algebra System             o<     %s\n"
472" for Commutative Algebra and Algebraic Geometry    \\    %s\n\n"
473"by: G.-M. Greuel, G. Pfister, H. Schoenemann\n"
474"Fachbereich Mathematik der Universitaet, D-67653 Kaiserslautern\n"
475#if 0
476"contributions: O.Bachmann,W.Decker,H.Grassmann,B.Martin,M.Messollen,W.Neumann,\n"
477"\tW.Pohl,T.Siebert,R.Stobbe,T.Wichmann\n"
478"e-mail: singular@mathematik.uni-kl.de\n", S_VERSION1,S_VERSION2);
479#endif   
480, S_VERSION1,S_VERSION2);
481#if 0
482    printf("%s  %s  (%d)",S_VERSION1,S_VERSION2, SINGULAR_VERSION_ID);
483#endif   
484    printf("\nPlease note:  EVERY COMMAND MUST END WITH A SEMICOLON \";"
485           "\"\n(e.g., help; help command; help General syntax; help ring; quit;)\n\n");
486  }
487  else
488  if (!feBatch)
489  {
490#ifdef macintosh
491    memcpy(stderr,stdout,sizeof(FILE));
492#else
493    dup2(1,2);
494#endif
495  }
496  slStandardInit();
497  dlInit(thisfile);
498  myynest=0;
499  if (load_std_lib)
500  {
501    iiLibCmd(mstrdup("standard.lib"),TRUE);
502  } 
503  errorreported = 0;
504#ifndef macintosh
505#if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
506  fe_set_input_mode();
507#endif
508#endif
509  setjmp(si_start_jmpbuf);
510
511  // Now, put things on the stack of stuff to do
512
513  // Last thing to do is to execute given scripts
514  if (optind < argc)
515  {
516    int i = argc - 1;
517    while (i >= optind)
518    {
519      newFile(argv[i]);
520      i--;
521    }
522  }
523  else
524  {
525    currentVoice=feInitStdin();
526  }
527
528  // before scripts, we execute -c, if it was given
529  // now execute -c, if it was given
530  if (execute_string != NULL)
531    newBuffer(mstrdup(execute_string), BT_execute);
532
533  // first thing, however, is to load .singularrc
534  if (load_rc)
535  {
536    // Hmm, we should look into $cwd and then into $HOME, only
537    char * where=(char *)AllocL(256);
538    FILE * rc=feFopen(".singularrc","r",where,FALSE);
539    if (rc!=NULL)
540    {
541      fclose(rc);
542      newFile(where);
543    }
544    FreeL((ADDRESS)where);
545  }
546
547  /* start shell */
548  if (feBatch)
549  {
550#ifdef HAVE_MPSR
551    extern int Batch_do(const char* port, const char* host);
552    return Batch_do(mainGetSingOptionValue(LON_MP_PORT),
553                    mainGetSingOptionValue(LON_MP_HOST));
554#else
555    assume(0);
556#endif
557  }
558  setjmp(si_start_jmpbuf);
559  yyparse();
560#endif
561  //Print("at very end\n");
562  m2_end(0);
563  return 0;
564}
Note: See TracBrowser for help on using the repository browser.