source: git/Singular/misc.cc @ 634dab0

spielwiese
Last change on this file since 634dab0 was 922a71f, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes: export, version stuff git-svn-id: file:///usr/local/Singular/svn/trunk@8283 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 16.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5* ABSTRACT:
6*/
7
8#include <string.h>
9#include <unistd.h>
10#include <stdio.h>
11#include <stddef.h>
12#include <stdlib.h>
13#include <time.h>
14
15#include "mod2.h"
16#include <mylimits.h>
17#include "omalloc.h"
18#include "structs.h"
19#include "tok.h"
20#include "febase.h"
21#include "cntrlc.h"
22#include "page.h"
23#include "ipid.h"
24#include "ipshell.h"
25#include "kstd1.h"
26#include "subexpr.h"
27#include "timer.h"
28#include "intvec.h"
29#include "ring.h"
30#include "omSingularConfig.h"
31#include "p_Procs.h"
32#include "version.h"
33
34#include "static.h"
35#ifdef HAVE_STATIC
36#undef HAVE_DYN_RL
37#endif
38
39#define SI_DONT_HAVE_GLOBAL_VARS
40
41//#ifdef HAVE_LIBPARSER
42//#  include "libparse.h"
43//#endif /* HAVE_LIBPARSER */
44
45#ifdef HAVE_FACTORY
46#include <factory.h>
47#endif
48
49/* version strings */
50#ifdef HAVE_LIBFAC_P
51  extern const char * libfac_version;
52  extern const char * libfac_date;
53#endif
54//extern "C" {
55//#include <gmp.h>
56//}
57#include <si_gmp.h>
58#ifdef HAVE_MPSR
59#include <MP_Config.h>
60#endif
61
62/*2
63* initialize components of Singular
64*/
65int inits(void)
66{
67  int t;
68/*4 signal handler:*/
69  init_signals();
70/*4 randomize: */
71  t=initTimer();
72  /*t=(int)time(NULL);*/
73  if (t==0) t=1;
74#ifdef HAVE_RTIMER
75  initRTimer();
76#endif
77#ifdef buildin_rand
78  siSeed=t;
79#else
80  srand((unsigned int)t);
81#endif
82#ifdef HAVE_FACTORY
83  factoryseed(t);
84#endif
85/*4 private data of other modules*/
86  memset(&sLastPrinted,0,sizeof(sleftv));
87  sLastPrinted.rtyp=NONE;
88  return t;
89}
90
91/*2
92* the renice routine for very large jobs
93* works only on unix machines,
94* testet on : linux, HP 9.0
95*
96*#ifndef MSDOS
97*#ifndef macintosh
98*#include <sys/times.h>
99*#include <sys/resource.h>
100*extern "C" int setpriority(int,int,int);
101*void very_nice()
102*{
103*#ifndef NO_SETPRIORITY
104*  setpriority(PRIO_PROCESS,0,19);
105*#endif
106*  sleep(10);
107*}
108*#else
109*void very_nice(){}
110*#endif
111*#else
112*void very_nice(){}
113*#endif
114*/
115
116void singular_example(char *str)
117{
118  assume(str!=NULL);
119  char *s=str;
120  while (*s==' ') s++;
121  char *ss=s;
122  while (*ss!='\0') ss++;
123  while (*ss<=' ')
124  {
125    *ss='\0';
126    ss--;
127  }
128  idhdl h=IDROOT->get(s,myynest);
129  if ((h!=NULL) && (IDTYP(h)==PROC_CMD))
130  {
131    char *lib=iiGetLibName(IDPROC(h));
132    if((lib!=NULL)&&(*lib!='\0'))
133    {
134      Print("// proc %s from lib %s\n",s,lib);
135      s=iiGetLibProcBuffer(IDPROC(h), 2);
136      if (s!=NULL)
137      {
138        if (strlen(s)>5)
139        {
140          iiEStart(s,IDPROC(h));
141          return;
142        }
143        else omFree((ADDRESS)s);
144      }
145    }
146  }
147  else
148  {
149    char sing_file[MAXPATHLEN];
150    FILE *fd=NULL;
151    char *res_m=feResource('m', 0);
152    if (res_m!=NULL)
153    {
154      sprintf(sing_file, "%s/%s.sing", res_m, s);
155      fd = feFopen(sing_file, "r");
156    }
157    if (fd != NULL)
158    {
159
160      int old_echo = si_echo;
161      int length, got;
162      char* s;
163
164      fseek(fd, 0, SEEK_END);
165      length = ftell(fd);
166      fseek(fd, 0, SEEK_SET);
167      s = (char*) omAlloc((length+20)*sizeof(char));
168      got = fread(s, sizeof(char), length, fd);
169      fclose(fd);
170      if (got != length)
171      {
172        Werror("Error while reading file %s", sing_file);
173        omFree(s);
174      }
175      else
176      {
177        s[length] = '\0';
178        strcat(s, "\n;return();\n\n");
179        si_echo = 2;
180        iiEStart(s, NULL);
181        si_echo = old_echo;
182      }
183    }
184    else
185    {
186      Werror("no example for %s", str);
187    }
188  }
189}
190
191
192struct soptionStruct
193{
194  char * name;
195  unsigned   setval;
196  unsigned   resetval;
197};
198
199struct soptionStruct optionStruct[]=
200{
201  {"prot",         Sy_bit(OPT_PROT),           ~Sy_bit(OPT_PROT)   },
202  {"redSB",        Sy_bit(OPT_REDSB),          ~Sy_bit(OPT_REDSB)   },
203  {"notBuckets",   Sy_bit(OPT_NOT_BUCKETS),    ~Sy_bit(OPT_NOT_BUCKETS)   },
204  {"notSugar",     Sy_bit(OPT_NOT_SUGAR),      ~Sy_bit(OPT_NOT_SUGAR)   },
205  {"interrupt",    Sy_bit(OPT_INTERRUPT),      ~Sy_bit(OPT_INTERRUPT)   },
206  {"sugarCrit",    Sy_bit(OPT_SUGARCRIT),      ~Sy_bit(OPT_SUGARCRIT)   },
207  {"teach",     Sy_bit(OPT_DEBUG),          ~Sy_bit(OPT_DEBUG)  },
208  /* 9 return SB in syz, quotient, intersect */
209  {"returnSB",     Sy_bit(OPT_RETURN_SB),      ~Sy_bit(OPT_RETURN_SB)  },
210  {"fastHC",       Sy_bit(OPT_FASTHC),         ~Sy_bit(OPT_FASTHC)  },
211  /* 11-19 sort in L/T */
212  {"keepvars",     Sy_bit(OPT_KEEPVARS),       ~Sy_bit(OPT_KEEPVARS) },
213  {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND)  },
214  {"multBound",    Sy_bit(OPT_MULTBOUND),      ~Sy_bit(OPT_MULTBOUND)  },
215  {"degBound",     Sy_bit(OPT_DEGBOUND),       ~Sy_bit(OPT_DEGBOUND)  },
216  /* 25 no redTail(p)/redTail(s) */
217  {"redTail",      Sy_bit(OPT_REDTAIL),        ~Sy_bit(OPT_REDTAIL)  },
218  {"redThrough",   Sy_bit(OPT_REDTHROUGH),     ~Sy_bit(OPT_REDTHROUGH)  },
219  {"lazy",         Sy_bit(OPT_OLDSTD),         ~Sy_bit(OPT_OLDSTD)  },
220  {"intStrategy",  Sy_bit(OPT_INTSTRATEGY),    ~Sy_bit(OPT_INTSTRATEGY)  },
221  {"infRedTail",   Sy_bit(OPT_INFREDTAIL),     ~Sy_bit(OPT_INFREDTAIL)  },
222  /* 30: use not regularity for syz */
223  {"notRegularity",Sy_bit(OPT_NOTREGULARITY),  ~Sy_bit(OPT_NOTREGULARITY)  },
224  {"weightM",      Sy_bit(OPT_WEIGHTM),        ~Sy_bit(OPT_WEIGHTM)  },
225/*special for "none" and also end marker for showOption:*/
226  {"ne",           0,                          0 }
227};
228
229struct soptionStruct verboseStruct[]=
230{
231  {"mem",      Sy_bit(V_SHOW_MEM),  ~Sy_bit(V_SHOW_MEM)   },
232  {"yacc",     Sy_bit(V_YACC),      ~Sy_bit(V_YACC)       },
233  {"redefine", Sy_bit(V_REDEFINE),  ~Sy_bit(V_REDEFINE)   },
234  {"reading",  Sy_bit(V_READING),   ~Sy_bit(V_READING)    },
235  {"loadLib",  Sy_bit(V_LOAD_LIB),  ~Sy_bit(V_LOAD_LIB)   },
236  {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB)  },
237  {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC)  },
238  {"defRes",   Sy_bit(V_DEF_RES),   ~Sy_bit(V_DEF_RES)    },
239  {"debugMem", Sy_bit(V_DEBUG_MEM), ~Sy_bit(V_DEBUG_MEM)  },
240  {"usage",    Sy_bit(V_SHOW_USE),  ~Sy_bit(V_SHOW_USE)   },
241  {"Imap",     Sy_bit(V_IMAP),      ~Sy_bit(V_IMAP)       },
242  {"prompt",   Sy_bit(V_PROMPT),    ~Sy_bit(V_PROMPT)     },
243  {"notWarnSB",Sy_bit(V_NSB),       ~Sy_bit(V_NSB)        },
244  {"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB)  },
245  {"cancelunit",Sy_bit(V_CANCELUNIT),~Sy_bit(V_CANCELUNIT)},
246/*special for "none" and also end marker for showOption:*/
247  {"ne",         0,          0 }
248};
249
250BOOLEAN setOption(leftv res, leftv v)
251{
252  char *n;
253  do
254  {
255    if (v->Typ()==STRING_CMD)
256    {
257      n=(char *)v->CopyD(STRING_CMD);
258    }
259    else
260    {
261      if (v->name==NULL)
262        return TRUE;
263      if (v->rtyp==0)
264      {
265        n=v->name;
266        v->name=NULL;
267      }
268      else
269      {
270        n=omStrDup(v->name);
271      }
272    }
273
274    int i;
275
276    if(strcmp(n,"get")==0)
277    {
278      intvec *w=new intvec(2);
279      (*w)[0]=test;
280      (*w)[1]=verbose;
281      res->rtyp=INTVEC_CMD;
282      res->data=(void *)w;
283      goto okay;
284    }
285    if(strcmp(n,"set")==0)
286    {
287      if((v->next!=NULL)
288      &&(v->next->Typ()==INTVEC_CMD))
289      {
290        v=v->next;
291        intvec *w=(intvec*)v->Data();
292        test=(*w)[0];
293        verbose=(*w)[1];
294
295        if (TEST_OPT_INTSTRATEGY && (currRing!=NULL)
296        && rField_has_simple_inverse())
297        {
298          test &=~Sy_bit(OPT_INTSTRATEGY);
299        }
300        goto okay;
301      }
302    }
303    if(strcmp(n,"none")==0)
304    {
305      test=0;
306      verbose=0;
307      goto okay;
308    }
309    for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++)
310    {
311      if (strcmp(n,optionStruct[i].name)==0)
312      {
313        if (optionStruct[i].setval & validOpts)
314        {
315          test |= optionStruct[i].setval;
316          // optOldStd disables redthrough
317          if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD))
318            test &= ~Sy_bit(OPT_REDTHROUGH);
319        }
320        else
321          Warn("cannot set option");
322        if (TEST_OPT_INTSTRATEGY && (currRing!=NULL)
323        && rField_has_simple_inverse())
324        {
325          test &=~Sy_bit(OPT_INTSTRATEGY);
326        }
327        goto okay;
328      }
329      else if ((strncmp(n,"no",2)==0)
330      && (strcmp(n+2,optionStruct[i].name)==0))
331      {
332        if (optionStruct[i].setval & validOpts)
333        {
334          test &= optionStruct[i].resetval;
335        }
336        else
337          Warn("cannot clear option");
338        goto okay;
339      }
340    }
341    for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++)
342    {
343      if (strcmp(n,verboseStruct[i].name)==0)
344      {
345        verbose |= verboseStruct[i].setval;
346        #ifdef YYDEBUG
347        #if YYDEBUG
348        if (BVERBOSE(V_YACC)) yydebug=1;
349        else                  yydebug=0;
350        #endif
351        #endif
352        goto okay;
353      }
354      else if ((strncmp(n,"no",2)==0)
355      && (strcmp(n+2,verboseStruct[i].name)==0))
356      {
357        verbose &= verboseStruct[i].resetval;
358        #ifdef YYDEBUG
359        #if YYDEBUG
360        if (BVERBOSE(V_YACC)) yydebug=1;
361        else                  yydebug=0;
362        #endif
363        #endif
364        goto okay;
365      }
366    }
367    Werror("unknown option `%s`",n);
368  okay:
369    if (currRing != NULL)
370      currRing->options = test & TEST_RINGDEP_OPTS;
371    omFree((ADDRESS)n);
372    v=v->next;
373  } while (v!=NULL);
374  #ifdef HAVE_TCL
375    if (tclmode)
376    {
377      BITSET tmp;
378      int i;
379      StringSetS("");
380      if ((test!=0)||(verbose!=0))
381      {
382        tmp=test;
383        if(tmp)
384        {
385          for (i=0; optionStruct[i].setval!=0; i++)
386          {
387            if (optionStruct[i].setval & test)
388            {
389              StringAppend(" %s",optionStruct[i].name);
390              tmp &=optionStruct[i].resetval;
391            }
392          }
393        }
394        tmp=verbose;
395        if (tmp)
396        {
397          for (i=0; verboseStruct[i].setval!=0; i++)
398          {
399            if (verboseStruct[i].setval & tmp)
400            {
401              StringAppend(" %s",verboseStruct[i].name);
402              tmp &=verboseStruct[i].resetval;
403            }
404          }
405        }
406        PrintTCLS('O',StringAppendS(""));
407        StringSetS("");
408      }
409      else
410      {
411        PrintTCLS('O'," ");
412      }
413    }
414  #endif
415    // set global variable to show memory usage
416    if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1;
417    else om_sing_opt_show_mem = 0;
418  return FALSE;
419}
420
421char * showOption()
422{
423  int i;
424  BITSET tmp;
425
426  StringSetS("//options:");
427  if ((test!=0)||(verbose!=0))
428  {
429    tmp=test;
430    if(tmp)
431    {
432      for (i=0; optionStruct[i].setval!=0; i++)
433      {
434        if (optionStruct[i].setval & test)
435        {
436          StringAppend(" %s",optionStruct[i].name);
437          tmp &=optionStruct[i].resetval;
438        }
439      }
440      for (i=0; i<32; i++)
441      {
442        if (tmp & Sy_bit(i)) StringAppend(" %d",i);
443      }
444    }
445    tmp=verbose;
446    if (tmp)
447    {
448      for (i=0; verboseStruct[i].setval!=0; i++)
449      {
450        if (verboseStruct[i].setval & tmp)
451        {
452          StringAppend(" %s",verboseStruct[i].name);
453          tmp &=verboseStruct[i].resetval;
454        }
455      }
456      for (i=1; i<32; i++)
457      {
458        if (tmp & Sy_bit(i)) StringAppend(" %d",i+32);
459      }
460    }
461    return omStrDup(StringAppendS(""));
462  }
463  else
464    return omStrDup(StringAppendS(" none"));
465}
466
467char * versionString()
468{
469  char* str = StringSetS("");
470  StringAppend("Singular for %s version %s  (%lu)  %s\nwith\n",
471               S_UNAME, S_VERSION1,
472               feVersionId,singular_date);
473  StringAppend("\t");
474#ifdef HAVE_FACTORY
475              StringAppend("factory(%s),", factoryVersion);
476#endif
477#ifdef HAVE_LIBFAC_P
478              StringAppend("libfac(%s,%s),\n\t",libfac_version,libfac_date);
479#endif
480#if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR)
481              StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR);
482#elif defined (HAVE_SMALLGMP)
483              StringAppendS("SmallGMP(2.0.2.0),");
484#else
485              StringAppendS("GMP(1.3),");
486#endif
487#ifdef HAVE_NTL
488              StringAppendS("NTL,");
489#endif
490#ifdef HAVE_MPSR
491              StringAppend("MP(%s),",MP_VERSION);
492#endif
493#if defined(HAVE_DYN_RL)
494              if (fe_fgets_stdin==fe_fgets_dummy)
495                StringAppendS("no input,");
496              else if (fe_fgets_stdin==fe_fgets)
497                StringAppendS("fgets,");
498              if (fe_fgets_stdin==fe_fgets_stdin_drl)
499                StringAppendS("dynamic readline,");
500              #ifdef HAVE_FEREAD
501              else if (fe_fgets_stdin==fe_fgets_stdin_emu)
502                StringAppendS("emulated readline,");
503              #endif
504              else
505                StringAppendS("unknown fgets method,");
506#else
507  #if defined(HAVE_READLINE) && !defined(FEREAD)
508              StringAppendS("static readline,");
509  #else
510    #ifdef HAVE_FEREAD
511              StringAppendS("emulated readline,");
512    #else
513              StringAppendS("fgets,");
514    #endif
515  #endif
516#endif
517#ifdef HAVE_PLURAL
518              StringAppendS("Plural,");
519#endif
520#ifdef HAVE_DBM
521              StringAppendS("DBM,\n\t");
522#else
523              StringAppendS("\n\t");
524#endif
525#ifdef HAVE_NS
526              StringAppendS("namespaces,");
527#endif
528#ifdef HAVE_DYNAMIC_LOADING
529              StringAppendS("dynamic modules,");
530#endif
531              if (p_procs_dynamic) StringAppendS("dynamic p_Procs,");
532#ifdef TEST
533              StringAppendS("TESTs,");
534#endif
535#if YYDEBUG
536              StringAppendS("YYDEBUG=1,");
537#endif
538#ifdef HAVE_ASSUME
539             StringAppendS("ASSUME,");
540#endif
541#ifdef MDEBUG
542              StringAppend("MDEBUG=%d,",MDEBUG);
543#endif
544#ifdef OM_CHECK
545              StringAppend("OM_CHECK=%d,",OM_CHECK);
546#endif
547#ifdef OM_TRACK
548              StringAppend("OM_TRACK=%d,",OM_TRACK);
549#endif
550#ifdef OM_NDEBUG
551              StringAppend("OM_NDEBUG,");
552#endif
553#ifdef PDEBUG
554              StringAppendS("PDEBUG,");
555#endif
556#ifdef KDEBUG
557              StringAppendS("KDEBUG,");
558#endif
559#ifndef __OPTIMIZE__
560#ifdef __MWERKS__
561              StringAppendS(" Codewarrior 2.0,");
562#else
563              StringAppendS("-g,");
564#endif
565#endif
566#ifdef HAVE_EIGENVAL
567              StringAppendS("eigenvalues,");
568#endif
569#ifdef HAVE_GMS
570              StringAppendS("Gauss-Manin system,");
571#endif
572              StringAppend("random=%d\n",siRandomStart);
573              StringAppend("\tCC=%s,\n\tCXX=%s"
574#ifdef __GNUC__
575              "(" __VERSION__ ")"
576#endif
577              "\n",CC,CXX);
578              feStringAppendResources(0);
579              feStringAppendBrowsers(0);
580              StringAppend("\n");
581              return str;
582}
583
584#ifdef HAVE_NS
585void listall(int showproc)
586{
587      idhdl hh=basePack->idroot;
588      PrintS("====== Top ==============\n");
589      while (hh!=NULL)
590      {
591        if (showproc || (IDTYP(hh)!=PROC_CMD))
592        {
593          if (IDDATA(hh)==(void *)currRing) PrintS("(R)");
594          else if (IDDATA(hh)==(void *)currPack) PrintS("(P)");
595          else PrintS("   ");
596          Print("::%s, typ %s level %d data %x",
597                 IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),IDDATA(hh));
598          if ((IDTYP(hh)==RING_CMD)
599          || (IDTYP(hh)==QRING_CMD))
600            Print(" ref: %d\n",IDRING(hh)->ref);
601          else
602            PrintLn();
603        }
604        hh=IDNEXT(hh);
605      }
606      hh=basePack->idroot;
607      while (hh!=NULL)
608      {
609        if (IDDATA(hh)==(void *)basePack)
610          Print("(T)::%s, typ %s level %d data %x\n",
611          IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),IDDATA(hh));
612        else
613        if ((IDTYP(hh)==RING_CMD)
614        || (IDTYP(hh)==QRING_CMD)
615        || (IDTYP(hh)==PACKAGE_CMD))
616        {
617          Print("====== %s ==============\n",IDID(hh));
618          idhdl h2=IDRING(hh)->idroot;
619          while (h2!=NULL)
620          {
621            if (showproc || (IDTYP(h2)!=PROC_CMD))
622            {
623              if ((IDDATA(h2)==(void *)currRing)
624              && ((IDTYP(h2)==RING_CMD)||(IDTYP(h2)==QRING_CMD)))
625                PrintS("(R)");
626              else if (IDDATA(h2)==(void *)currPack) PrintS("(P)");
627              else PrintS("   ");
628              Print("%s::%s, typ %s level %d data %x\n",
629              IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),IDDATA(h2));
630            }
631            h2=IDNEXT(h2);
632          }
633        }
634        hh=IDNEXT(hh);
635      }
636      Print("currRing:%x, currPack:%x,basePack:%x\n",currRing,currPack,basePack);
637      iiCheckPack(currPack);
638}
639#ifndef NDEBUG
640void checkall()
641{
642      idhdl hh=basePack->idroot;
643      while (hh!=NULL)
644      {
645        omCheckAddr(hh);
646        omCheckAddr(IDID(hh));
647        if (RingDependend(IDTYP(hh))) Print("%s typ %d in Top\n",IDID(hh),IDTYP(hh));
648        hh=IDNEXT(hh);
649      }
650      hh=basePack->idroot;
651      while (hh!=NULL)
652      {
653        if (IDTYP(hh)==PACKAGE_CMD)
654        {
655          idhdl h2=IDPACKAGE(hh)->idroot;
656          while (h2!=NULL)
657          {
658            omCheckAddr(h2);
659            omCheckAddr(IDID(h2));
660            if (RingDependend(IDTYP(h2))) Print("%s typ %d in %s\n",IDID(h2),IDTYP(h2),IDID(hh));
661            h2=IDNEXT(h2);
662          }
663        }
664        hh=IDNEXT(hh);
665      }
666}
667#endif
668#endif
Note: See TracBrowser for help on using the repository browser.