source: git/Singular/tesths.cc @ 41d8a6

fieker-DuValspielwiese
Last change on this file since 41d8a6 was f79b204, checked in by Hans Schönemann <hannes@…>, 25 years ago
*hannes: added -d/sdb git-svn-id: file:///usr/local/Singular/svn/trunk@3078 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 16.9 KB
RevLine 
[0e1846]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[f79b204]4/* $Id: tesths.cc,v 1.62 1999-05-29 11:58:26 Singular Exp $ */
[32df82]5
[0e1846]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>
[32df82]16#include <errno.h>
[40edb03]17#include "version.h"
[0e1846]18#include "mod2.h"
19#include "tok.h"
20#include "ipshell.h"
[6a6dccc]21#include "sing_dld.h"
[0e1846]22#include "febase.h"
23#include "cntrlc.h"
24#include "mmemory.h"
25#include "silink.h"
[7def32f]26#include "ipid.h"
[ea986d]27#include "timer.h"
[473707b]28#include "sdb.h"
[43d6c5]29#ifdef HAVE_FACTORY
[fda54cc]30#define SI_DONT_HAVE_GLOBAL_VARS
31#include <factory.h>
[43d6c5]32#endif
[9c756f]33#include "getopt.h"
[eea2b0]34
[64c6d1]35#ifndef MAXPATHLEN
36#define MAXPATHLEN 1024
37#endif
38
[eea2b0]39// define the long option names here
40#define LON_BATCH           "batch"
41#define LON_EXECUTE         "execute"
42#define LON_ECHO            "echo"
43#define LON_HELP            "help"
44#define LON_RANDOM          "random"
45#define LON_QUIET           "quiet"
46#define LON_NO_TTY          "no-tty"
47#define LON_USER_OPTION     "user-option"
[5bfda2]48#define LON_VERSION         "verbose"
[eea2b0]49#define LON_MIN_TIME        "min-time"
50#define LON_NO_STDLIB       "no-stdlib"
51#define LON_NO_RC           "no-rc"
52#define LON_TICKS_PER_SEC   "ticks-per-sec"
53#define LON_TCLMODE         "tclmode"
54#define LON_MP_PORT         "MPport"
55#define LON_MP_HOST         "MPhost"
[12310e]56#define LON_NO_WARN         "no-warn"
57#define LON_NO_OUT          "no-out"
[f79b204]58#define LON_SDB             "sdb"
[eea2b0]59// undocumented options
60#ifdef HAVE_MPSR
61#define LON_MP_TRANSP       "MPtransp"
62#define LON_MP_MODE         "MPmode"
63#endif
64
[04f9c7]65#define LONG_OPTION_RETURN 13
[eea2b0]66static struct option longopts[] =
67{
68#ifdef HAVE_MPSR
[e54eb4]69  {LON_BATCH,             0,  0,  'b'},
[eea2b0]70#endif
[1a11bc]71  {LON_EXECUTE,           1,  0,  'c'},
[f79b204]72  {LON_SDB,               0,  0,  'd'},
[1a11bc]73  {LON_ECHO,              2,  0,  'e'},
[eea2b0]74  {LON_HELP,              0,  0,  'h'},
[e54eb4]75  {LON_QUIET,             0,  0,  'q'},
[1a11bc]76  {LON_RANDOM,            1,  0,  'r'},
[eea2b0]77  {LON_NO_TTY,            0,  0,  't'},
[1a11bc]78  {LON_USER_OPTION,       1,  0,  'u'},
[eea2b0]79  {LON_VERSION,           0,  0,  'v'},
80#ifdef HAVE_TCL
81  {LON_TCLMODE,           0,  0,  'x'},
82#endif
[5bfda2]83  {LON_NO_STDLIB,         0,  0,  LONG_OPTION_RETURN},
84  {LON_NO_RC,             0,  0,  LONG_OPTION_RETURN},
[12310e]85  {LON_NO_WARN,           0,  0,  LONG_OPTION_RETURN},
[f79b204]86  {LON_NO_OUT,            0,  0,  LONG_OPTION_RETURN},
[5bfda2]87  {LON_MIN_TIME,          1,  0,  LONG_OPTION_RETURN},
[eea2b0]88#ifdef HAVE_MPSR
[5bfda2]89  {LON_MP_PORT,           1,  0,  LONG_OPTION_RETURN},
90  {LON_MP_HOST,           1,  0,  LONG_OPTION_RETURN},
[eea2b0]91#endif
[5bfda2]92  {LON_TICKS_PER_SEC,     1,  0,  LONG_OPTION_RETURN},
[eea2b0]93// undocumented options
94#ifdef HAVE_MPSR
[5bfda2]95  {LON_MP_TRANSP,         1,  0,  LONG_OPTION_RETURN},
96  {LON_MP_MODE,           1,  0,  LONG_OPTION_RETURN},
[eea2b0]97#endif
98// terminator
99  { 0, 0, 0, 0 }
100};
101// #define SHORT_OPTS_STRING "bc:e::hqr:tu:v"
[f79b204]102#define SHORT_OPTS_STRING "bdhqtvxec:r:u:"
[eea2b0]103
104struct sing_option
105{
106  const char*   name;    // as in option
107  const char*   arg_name;// name of argument, if has_arg > 0
108  const char*   help;    // (short) help string
[e54eb4]109  char*         val;     // (default) value of option: 0: not set 1:set
[eea2b0]110                         // string:"" if has_arg > 0
111};
112
113// mention only documented options here
[e54eb4]114static struct sing_option sing_longopts[] =
[eea2b0]115{
116#ifdef HAVE_MPSR
[e54eb4]117  {LON_BATCH,       0,          "Run in MP batch mode",                                 0},
[eea2b0]118#endif
119  {LON_HELP,        0,          "Print help message and exit",                          0},
[12310e]120  {LON_QUIET,       0,          "Do not print start-up banner and library load messages",            0},
[f79b204]121  {LON_SDB,         0,          "Enable sdb debugger (experimental)",            0},
[eea2b0]122  {LON_NO_TTY,      0,          "Do not redefine the terminal characteristics",         0},
123  {LON_VERSION,     0,          "Print extended version and configuration info",        0},
124#ifdef HAVE_TCL
[de6147]125  {LON_TCLMODE,     0,          "Run in TCL mode, i.e., with TCL user interface",       0},
[e54eb4]126#endif
[eea2b0]127  {LON_ECHO,        "VAL",      "Set value of variable `echo' to (integer) VAL",        ""},
128  {LON_EXECUTE,     "STRING",   "Execute STRING on start-up",                           ""},
129  {LON_RANDOM,      "SEED",     "Seed random generator with integer (integer) SEED",    ""},
130  {LON_USER_OPTION, "STRING",   "Return STRING on `system(\"--user-option\")'",         ""},
131  {LON_NO_STDLIB,   0,          "Do not load `standard.lib' on start-up",               0},
132  {LON_NO_RC,       0,          "Do not execute `.singularrc' file on start-up",        0},
[12310e]133  {LON_NO_WARN,     0,          "Do not display warning messages",        0},
134  {LON_NO_OUT,      0,          "Suppress all output",        0},
[eea2b0]135  {LON_MIN_TIME,    "SECS",     "Do not display times smaller than SECS (in seconds)",  "0.5"},
136#ifdef HAVE_MPSR
137  {LON_MP_PORT,     "PORT",     "Use PORT number for MP conections",                    ""},
138  {LON_MP_HOST,     "HOST",     "Use HOST for MP connections",                          ""},
139#endif
140  {LON_TICKS_PER_SEC, "TICKS",    "Sets unit of timer to TICKS per second",             "1"},
141  { 0, 0, 0, 0 }
142};
143
144static struct sing_option* mainGetSingOption(const char* name)
145{
146  int i = 0;
147  while (sing_longopts[i].name != 0)
148  {
149    if (strcmp(name, sing_longopts[i].name) == 0)
150      return &(sing_longopts[i]);
151    i++;
152  }
153  return NULL;
154}
155
156static void mainSetSingOptionValue(const char* name, char* value)
157{
158  sing_option* sopt = mainGetSingOption(name);
159  if (sopt != NULL)
160  {
161    sopt->val = value;
162  }
163}
164
165
166static char* mainGetSingOptionValue(const char* name)
167{
168  sing_option* sopt = mainGetSingOption(name);
169  if (sopt!=NULL)
170    return sopt->val;
171  return NULL;
172}
173
174
175// Prints help message
176static void mainHelp(const char* name)
177{
178  int i = 0;
179  struct sing_option *sopt;
180  char tmp[20];
181
[64c6d1]182  printf("Singular version %s -- a CAS for polynomial computations. Usage:\n", S_VERSION1);
[eea2b0]183  printf("   %s [options] [file1 [file2 ...]]\n", name);
184  printf("Options:\n");
[e54eb4]185
[eea2b0]186  while (longopts[i].name != 0)
187  {
188    sopt = mainGetSingOption(longopts[i].name);
189    if (sopt != NULL)
190    {
191      if (longopts[i].has_arg > 0)
192      {
193        if  (longopts[i].has_arg > 1)
194          sprintf(tmp, "%s[=%s]", longopts[i].name, sopt->arg_name);
195        else
196          sprintf(tmp, "%s=%s", longopts[i].name, sopt->arg_name);
197
198        printf(" %c%c --%-19s %s\n",
199               (longopts[i].val != 0 ? '-' : ' '),
200               (longopts[i].val != 0 ? longopts[i].val : ' '),
201               tmp,
202               sopt->help);
203      }
204      else
205      {
206        printf(" %c%c --%-19s %s\n",
207               (longopts[i].val != 0 ? '-' : ' '),
208               (longopts[i].val != 0 ? longopts[i].val : ' '),
209               longopts[i].name,
210               sopt->help);
211      }
212    }
[e54eb4]213#ifndef NDEBUG
[eea2b0]214    else
215      printf("--%s Undocumented\n", longopts[i].name);
216#endif
217    i++;
218  }
219
220  printf("\nFor more information, type `help;' from within Singular or visit\n");
221  printf("http://www.mathematik.uni-kl.de/~zca/Singular or consult the\n");
222  printf("Singular manual (available as on-line info or printed manual).\n");
223}
224
225// Prints usage message
226static void mainUsage(char* argv0)
227{
228  printf("Use `%s --help' for a complete list of options\n", argv0);
229}
230
231#ifndef NDEBUG
232void mainOptionValues()
233{
234  int i = 0;
235  struct sing_option *sopt;
236
237  while (longopts[i].name != 0)
238  {
239    sopt = mainGetSingOption(longopts[i].name);
240    if (sopt != NULL)
241    {
242      if (sopt->val == NULL || sopt->val == (char*) 1)
243        Print("// --%-10s %d\n", sopt->name, sopt->val);
244      else
[e54eb4]245        Print("// --%-10s %s\n", sopt->name, sopt->val);
[eea2b0]246    }
247    else
248      Print("// --%s Undocumented \n", longopts[i].name);
249    i++;
250  }
251}
252#endif // NDEBUG
253
254BOOLEAN mainGetSingOptionValue(const char* name, char** val)
255{
256  sing_option* sopt = mainGetSingOption(name);
257  if (sopt == NULL)
258  {
259    *val = NULL;
260    return FALSE;
261  }
262  else
263  {
264    *val = sopt->val;
265    return TRUE;
266  }
267}
[40edb03]268
[0e1846]269/*0 implementation*/
270int main(          /* main entry to Singular */
271    int argc,      /* number of parameter */
272    char** argv)   /* parameter array */
273{
[07dacd]274  char * thisfile;
[d754b7]275  /* initialize components */
[0e1846]276  siRandomStart=inits();
277#ifdef INIT_BUG
278  jjInitTab1();
279#endif
280#ifdef GENTABLE
[9c756f]281  extern void ttGen1();
282  extern void ttGen2();
283  #ifndef __MWERKS__
[99965c5]284    extern mpsr_ttGen(); // For initialization of (CMD, MP_COP) tables
285    mpsr_ttGen();
286  #endif
[0e1846]287  ttGen1();
288  ttGen2();
289#else
[2c24d8d]290  thisfile = argv[0];
[9ea9c6]291  BOOLEAN load_std_lib=TRUE;
[eea2b0]292  BOOLEAN load_rc = TRUE;
293  char* execute_string = NULL;
294  int optc, option_index;
295
296  // do this first, because -v might print version path
[fe4d60]297#ifndef __MWERKS__
[64c6d1]298  feInitPaths(thisfile);
[fe4d60]299#endif
[eea2b0]300
301  // parse command line options
302  while((optc = getopt_long(argc, argv,
[e54eb4]303                            SHORT_OPTS_STRING, longopts, &option_index))
[eea2b0]304        != EOF)
[0e1846]305  {
[eea2b0]306    switch(optc)
[0e1846]307    {
[e0d91c]308
[eea2b0]309        case 'b':
[e0d91c]310#ifdef HAVE_MPSR
[eea2b0]311          feBatch=TRUE;
312          mainSetSingOptionValue(LON_BATCH, (char*) 1);
313          break;
[40edb03]314#else
[eea2b0]315          printf("%s: Option `-b' not supported in this configuration\n", argv[0]);
316          mainUsage(argv[0]);
317          exit(1);
318#endif
319        case 'h':
320          mainHelp(argv[0]);
321          exit(0);
322
323        case 'q':
324          verbose &= ~(Sy_bit(0)|Sy_bit(V_LOAD_LIB));
325          mainSetSingOptionValue(LON_QUIET, (char*) 1);
326          break;
327
328        case 't':
329#if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
330          fe_use_fgets=TRUE;
[40edb03]331#endif
[eea2b0]332          mainSetSingOptionValue(LON_NO_TTY, (char*) 1);
333          break;
334
[f79b204]335        case 'd':
336          sdb_flags = 1;
337          break;
338
[eea2b0]339        case 'v':
[72f950]340          printf("Singular for %s version %s  (%d)  %s %s\n",
341                 S_UNAME, S_VERSION1,
[eea2b0]342                 SINGULAR_VERSION_ID,__DATE__,__TIME__);
343          printf("with\n");
344          printf(versionString());
345          printf("\n\n");
346          mainSetSingOptionValue(LON_VERSION, (char*) 1);
347          break;
348
349        case 'x':
350#ifdef HAVE_TCL
351          tclmode = TRUE;
[de6147]352          mainSetSingOptionValue(LON_TCLMODE, (char*) 1);
[e0d91c]353          verbose|=Sy_bit(V_SHOW_MEM);
[eea2b0]354          break;
355#else
356          printf("%s: Option `-x' not supported in this configuration\n", argv[0]);
357          mainUsage(argv[0]);
358          exit(1);
359#endif
360
361        case 'e':
362          if (optarg != NULL)
[ea986d]363          {
[eea2b0]364            errno = 0;
365            si_echo = strtol(optarg, NULL, 10);
366            if (errno)
367            {
368              printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_ECHO);
369              mainUsage(argv[0]);
370              exit(1);
371            }
372            if (si_echo < 0 || si_echo > 9)
373            {
374              printf("%s: `%s' argument for option `--%s' is not in valid range 0..9\n",
375                     argv[0], optarg, LON_ECHO);
376              mainUsage(argv[0]);
377              exit(1);
378            }
379            mainSetSingOptionValue(LON_ECHO, optarg);
[ea986d]380          }
381          else
[eea2b0]382          {
383            si_echo = 1;
384            mainSetSingOptionValue(LON_ECHO, "1");
385          }
386          break;
[9ea9c6]387
[eea2b0]388        case 'c':
389          execute_string = optarg;
390          mainSetSingOptionValue(LON_EXECUTE, optarg);
391          break;
[e0d91c]392
[eea2b0]393        case 'r':
394          errno = 0;
395          siRandomStart = strtol(optarg, NULL, 10);
[b1e0d72]396          if (errno || siRandomStart == 0)
[eea2b0]397          {
398            printf("%s: `%s' invalid integer argument for option `--%s'\n", argv[0], optarg, LON_RANDOM);
399            mainUsage(argv[0]);
400            exit(1);
401          }
402          #ifdef buildin_rand
403          siSeed=siRandomStart;
404          #else
405          srand((unsigned int)siRandomStart);
406          #endif
407          #ifdef HAVE_FACTORY
408          factoryseed(siRandomStart);
409          #endif
410          mainSetSingOptionValue(LON_RANDOM, optarg);
411          break;
[e0d91c]412
[eea2b0]413        case 'u':
414          mainSetSingOptionValue(LON_USER_OPTION, optarg);
415          break;
416
[5bfda2]417        case LONG_OPTION_RETURN:
[eea2b0]418          if (strcmp(longopts[option_index].name, LON_NO_STDLIB) == 0)
419          {
420            load_std_lib = FALSE;
421            mainSetSingOptionValue(LON_NO_STDLIB, (char*) 1);
422          }
423          else if (strcmp(longopts[option_index].name, LON_NO_RC) == 0)
424          {
425            load_rc = FALSE;
426            mainSetSingOptionValue(LON_NO_RC, (char*) 1);
427          }
[12310e]428          else if (strcmp(longopts[option_index].name, LON_NO_WARN) == 0)
429          {
430            feWarn = FALSE;
431            mainSetSingOptionValue(LON_NO_WARN, (char*) 1);
432          }
433          else if (strcmp(longopts[option_index].name, LON_NO_OUT) == 0)
434          {
435            feOut = FALSE;
436            mainSetSingOptionValue(LON_NO_OUT, (char*) 1);
437          }
[eea2b0]438          else if (strcmp(longopts[option_index].name, LON_MIN_TIME) == 0)
439          {
440            double mintime = atof(optarg);
441            if (mintime <= 0)
442            {
[e54eb4]443              printf("%s: `%s' invalid float argument for option `--%s'\n",
[eea2b0]444                     argv[0], optarg, LON_MIN_TIME);
445              mainUsage(argv[0]);
446              exit(1);
[ea986d]447            }
[eea2b0]448            SetMinDisplayTime(mintime);
449            mainSetSingOptionValue(LON_MIN_TIME, optarg);
450          }
451#ifdef HAVE_MPSR
452          else if (strcmp(longopts[option_index].name, LON_MP_PORT) == 0)
453          {
454            mainSetSingOptionValue(LON_MP_PORT, optarg);
455          }
456          else if (strcmp(longopts[option_index].name, LON_MP_HOST) == 0)
457          {
458            mainSetSingOptionValue(LON_MP_HOST, optarg);
459          }
[e0d91c]460#endif
[eea2b0]461          else if (strcmp(longopts[option_index].name, LON_TICKS_PER_SEC) == 0)
462          {
463            int ticks = atoi(optarg);
464            if (ticks <= 0)
[ea986d]465            {
[eea2b0]466              printf("%s: `%s' invalid integer argument for option `--%s'\n",
467                     argv[0], optarg, LON_TICKS_PER_SEC);
468              mainUsage(argv[0]);
469              exit(1);
[ea986d]470            }
[eea2b0]471            SetTimerResolution(ticks);
472            mainSetSingOptionValue(LON_TICKS_PER_SEC, optarg);
473          }
474          else
475            // undocumented options
[0e1846]476#ifdef HAVE_MPSR
[eea2b0]477            if (strcmp(longopts[option_index].name, LON_MP_MODE) == 0 ||
478                strcmp(longopts[option_index].name, LON_MP_TRANSP) == 0)
479            {
480              /* ignore */
481            }
482          else
[ea986d]483#endif
[eea2b0]484            assume(0);
485          break;
486
487        default:
488          // Error message already emmited by getopt_long
489          mainUsage(argv[0]);
490          exit(1);
[0e1846]491    }
492  }
493  /*. say hello */
[77ff8e]494  {
495    idhdl h;
[0a3ddd]496    namespaceroot->push(NULL, "Top", 0, TRUE);
[46d09b]497#ifdef HAVE_NAMESPACES
[77ff8e]498    h=enterid(mstrdup("Top"), 0, PACKAGE_CMD, &IDROOT, TRUE);
499    IDPACKAGE(h) = NSPACK(namespaceroot);
[daeb6d]500    IDPACKAGE(h)->language = LANG_TOP;
[46d09b]501#endif /* HAVE_NAMESPACES */
[77ff8e]502  }
[eea2b0]503  if (BVERBOSE(0) && !feBatch)
[0e1846]504  {
505    printf(
[3854a98]506"                     SINGULAR                             /"
507#ifndef MAKE_DISTRIBUTION
[9a11fe]508"  Development"
[3854a98]509#endif
510"\n"
[49e4cf]511" A Computer Algebra System for Polynomial Computations   /   version %s\n"
[0cb8c8]512"                                                       0<\n"
[451bcd]513"     by: G.-M. Greuel, G. Pfister, H. Schoenemann        \\   %s\n"
[f306b3]514#ifdef SDRING
515"       preliminary experimental version\n"
516#endif
[0cb8c8]517"FB Mathematik der Universitaet, D-67653 Kaiserslautern    \\\n"
[49eeee]518, S_VERSION1,S_VERSION2);
[0e1846]519  }
520  else
521  {
[473707b]522    sdb_flags = 0;
523    if (!feBatch)
524    {
[9c756f]525#ifdef __MWERKS__
[473707b]526      memcpy(stderr,stdout,sizeof(FILE));
[0e1846]527#else
[473707b]528      dup2(1,2);
[0e1846]529#endif
[473707b]530    }
[0e1846]531  }
532  slStandardInit();
533  dlInit(thisfile);
534  myynest=0;
[9ea9c6]535  if (load_std_lib)
[055021a]536  {
[e54eb4]537    int vv=verbose;
538    verbose &= ~Sy_bit(V_LOAD_LIB);
[0a3ddd]539#ifdef HAVE_NAMESPACES
540    iiLibCmd(mstrdup("standard.lib"),TRUE, TRUE);
541#else /* HAVE_NAMESPACES */
542    iiLibCmd(mstrdup("standard.lib"), TRUE);
543#endif /* HAVE_NAMESPACES */
[e54eb4]544    verbose=vv;
545  }
[9ea9c6]546  errorreported = 0;
[6e5833]547  mmMarkInitDBMCB();
[dfc6b54]548#ifndef macintosh
[e0d91c]549#if defined(HAVE_READLINE)
[dfc6b54]550  fe_set_input_mode();
551#endif
552#endif
553  setjmp(si_start_jmpbuf);
[eea2b0]554
555  // Now, put things on the stack of stuff to do
556
557  // Last thing to do is to execute given scripts
558  if (optind < argc)
[057e93c]559  {
[eea2b0]560    int i = argc - 1;
561    while (i >= optind)
562    {
563      newFile(argv[i]);
564      i--;
565    }
[057e93c]566  }
567  else
568  {
569    currentVoice=feInitStdin();
570  }
[eea2b0]571
572  // before scripts, we execute -c, if it was given
573  // now execute -c, if it was given
574  if (execute_string != NULL)
575    newBuffer(mstrdup(execute_string), BT_execute);
576
577  // first thing, however, is to load .singularrc
578  if (load_rc)
[7def32f]579  {
[64c6d1]580    FILE * rc=myfopen(".singularrc","r");
[7def32f]581    if (rc!=NULL)
582    {
583      fclose(rc);
[64c6d1]584      newFile(".singularrc");
585    }
586    else
587    {
588      char buf[MAXPATHLEN];
589      char *home = getenv("HOME");
590      if (home != NULL)
591      {
592        strcpy(buf, home);
593        strcat(buf, "/.singularrc");
594        rc = myfopen(buf, "r");
595        if (rc != NULL)
596        {
597          fclose(rc);
598          newFile(buf);
599        }
600      }
[7def32f]601    }
602  }
[eea2b0]603
[0e1846]604  /* start shell */
605  if (feBatch)
606  {
[d754b7]607#ifdef HAVE_MPSR
[eea2b0]608    extern int Batch_do(const char* port, const char* host);
609    return Batch_do(mainGetSingOptionValue(LON_MP_PORT),
610                    mainGetSingOptionValue(LON_MP_HOST));
[d754b7]611#else
[eea2b0]612    assume(0);
613#endif
[0e1846]614  }
[07dacd]615  setjmp(si_start_jmpbuf);
[0e1846]616  yyparse();
617#endif
[057e93c]618  //Print("at very end\n");
619  m2_end(0);
[0e1846]620  return 0;
621}
Note: See TracBrowser for help on using the repository browser.