source: git/Singular/extra.cc @ d5f35ac

spielwiese
Last change on this file since d5f35ac was d5f35ac, checked in by Olaf Bachmann <obachman@…>, 25 years ago
1998-04-27 Olaf Bachmann <obachman@mathematik.uni-kl.de> * febase.cc (myfread): introduced myfread and myfopen which assure that newlines in text files are always \n git-svn-id: file:///usr/local/Singular/svn/trunk@1483 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 17.8 KB
Line 
1/*****************************************
2*  Computer Algebra System SINGULAR      *
3*****************************************/
4/* $Id: extra.cc,v 1.41 1998-04-27 12:34:11 obachman Exp $ */
5/*
6* ABSTRACT: general interface to internals of Singular ("system" command)
7*/
8
9#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
12#include <ctype.h>
13#include "mod2.h"
14
15#ifndef macintosh
16#ifdef TIME_WITH_SYS_TIME
17# include <time.h>
18# ifdef HAVE_SYS_TIME_H
19#   include <sys/time.h>
20# endif
21#else
22# ifdef HAVE_SYS_TIME_H
23#   include <sys/time.h>
24# else
25#   include <time.h>
26# endif
27#endif
28#ifdef HAVE_SYS_TIMES_H
29#include <sys/times.h>
30#endif
31
32#include <unistd.h>
33#endif
34
35#include "tok.h"
36#include "ipid.h"
37#include "polys.h"
38#include "kutil.h"
39#include "cntrlc.h"
40#include "stairc.h"
41#include "ipshell.h"
42#include "algmap.h"
43#include "modulop.h"
44#include "febase.h"
45#include "matpol.h"
46#include "longalg.h"
47#include "ideals.h"
48#include "kstd1.h"
49#include "syz.h"
50#include "polys.h"
51
52#ifdef STDTRACE
53//#include "comm.h"
54#endif
55
56#ifdef HAVE_FACTORY
57#define SI_DONT_HAVE_GLOBAL_VARS
58#include "clapsing.h"
59#include "clapconv.h"
60#include "kstdfac.h"
61#include "fglmcomb.cc"
62#include "fglm.h"
63#endif
64
65#include "silink.h"
66#include "mpsr.h"
67
68// see clapsing.cc for a description of the `FACTORY_*' options
69
70#ifdef FACTORY_GCD_STAT
71#include "gcd_stat.h"
72#endif
73
74#ifdef FACTORY_GCD_TIMING
75#define TIMING
76#include "timing.h"
77TIMING_DEFINE_PRINTPROTO( contentTimer );
78TIMING_DEFINE_PRINTPROTO( algContentTimer );
79TIMING_DEFINE_PRINTPROTO( algLcmTimer );
80#endif
81
82//void emStart();
83/*2
84*  the "system" command
85*/
86BOOLEAN jjSYSTEM(leftv res, leftv h)
87{
88  if(h->Typ() == STRING_CMD)
89  {
90/*==================== lib ==================================*/
91    if(strcmp((char*)(h->Data()),"LIB")==0)
92    {
93      idhdl hh=idroot->get((char*)h->next->Data(),0);
94      if ((hh!=NULL)&&(IDTYP(hh)==PROC_CMD))
95      {
96        res->rtyp=STRING_CMD;
97        res->data=mstrdup(iiGetLibName(IDPROC(hh)));
98        if (res->data==NULL) res->data=mstrdup("");
99        return FALSE;
100      }
101      else
102        Warn("`%s` not found",(char*)h->next->Data());
103    }
104    else
105/*==================== proclist =================================*/
106    if(strcmp((char*)(h->Data()),"proclist")==0)
107    {
108      void piShowProcList();
109      //res->rtyp=STRING_CMD;
110      //res->data=(void *)mstrdup("");
111      piShowProcList();
112      return FALSE;
113    }
114    else
115/*==================== version ==================================*/
116    if(strcmp((char*)(h->Data()),"version")==0)
117    {
118      res->rtyp=INT_CMD;
119      res->data=(void *)SINGULAR_VERSION;
120      return FALSE;
121    }
122    else
123/*==================== gen ==================================*/
124    if(strcmp((char*)(h->Data()),"gen")==0)
125    {
126      res->rtyp=INT_CMD;
127      res->data=(void *)npGen;
128      return FALSE;
129    }
130    else
131/*==================== sh ==================================*/
132    #ifndef macintosh
133    if(strcmp((char*)(h->Data()),"sh")==0)
134    {
135      #ifndef MSDOS
136      #ifdef HAVE_FEREAD
137      fe_temp_reset();
138      #endif
139      #endif
140      res->rtyp=INT_CMD;
141      if (h->next==NULL) res->data = (void *)system("/bin/sh");
142      else res->data = (void*) system((char*)(h->next->Data()));
143      #ifndef MSDOS
144      #ifdef HAVE_FEREAD
145      fe_temp_set();
146      #endif
147      #endif
148      return FALSE;
149    }
150    else
151    #endif
152/*==================== with ==================================*/
153    if(strcmp((char*)(h->Data()),"with")==0)
154    {
155      if (h->next==NULL)
156      {
157        res->rtyp=STRING_CMD;
158        res->data=(void *)mstrdup(versionString());
159        return FALSE;
160      }
161      else if (h->next->Typ()==STRING_CMD)
162      {
163        #define TEST_FOR(A) if(strcmp(s,A)==0) res->data=(void *)1; else
164        char *s=(char *)h->next->Data();
165        res->rtyp=INT_CMD;
166        #ifdef DRING
167          TEST_FOR("DRING")
168        #endif
169        #ifdef HAVE_DBM
170          TEST_FOR("DBM")
171        #endif
172        #ifdef HAVE_DLD
173          TEST_FOR("DLD")
174        #endif
175        #ifdef HAVE_GMP
176          TEST_FOR("gmp")
177        #endif
178        #ifdef HAVE_FACTORY
179          TEST_FOR("factory")
180        #endif
181        #ifdef HAVE_LIBFAC_P
182          TEST_FOR("libfac")
183        #endif
184        #ifdef HAVE_MPSR
185          TEST_FOR("MP")
186        #endif
187        #ifdef HAVE_READLINE
188          TEST_FOR("readline")
189        #endif
190        #ifdef HAVE_TCL
191          TEST_FOR("tcl")
192        #endif
193        #ifdef SRING
194          TEST_FOR("SRING")
195        #endif
196        #ifdef TEST_MAC_ORDER
197          TEST_FOR("MAC_ORDER");
198        #endif
199          ;
200        return FALSE;
201        #undef TEST_FOR
202      }
203      return TRUE;
204    }
205    else
206/*==================== pid ==================================*/
207    #ifndef MSDOS
208    #ifndef macintosh
209    if (strcmp((char*)(h->Data()),"pid")==0)
210    {
211      res->rtyp=INT_CMD;
212      res->data=(void *)getpid();
213      return FALSE;
214    }
215    else
216    #endif
217    #endif
218/*==================== getenv ==================================*/
219    if (strcmp((char*)(h->Data()),"getenv")==0)
220    {
221      if ((h->next!=NULL) && (h->next->Typ()==STRING_CMD))
222      {
223        res->rtyp=STRING_CMD;
224        char *r=getenv((char *)h->next->Data());
225        if (r==NULL) r="";
226        res->data=(void *)mstrdup(r);
227        return FALSE;
228      }
229      else
230      {
231        WerrorS("string expected");
232      }
233    }
234    else
235/*==================== tty ==================================*/
236    #ifndef macintosh
237    #ifndef MSDOS
238    #if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
239    if (strcmp((char*)(h->Data()),"tty")==0)
240    {
241      #ifdef HAVE_FEREAD
242      #ifdef HAVE_ATEXIT
243      fe_reset_input_mode();
244      #else
245      fe_reset_input_mode(0,NULL);
246      #endif
247      #elif defined(HAVE_READLINE)
248      system("stty sane");
249      #endif
250      if ((h->next!=NULL)&&(h->next->Typ()==INT_CMD))
251      {
252        fe_use_fgets=(int)h->next->Data();
253        fe_set_input_mode();
254      }
255      return FALSE;
256    }
257    else
258    #endif
259    #endif
260    #endif
261/*==================== whoami ==================================*/
262    if (strcmp((char*)(h->data), "whoami") == 0)
263    {
264      res->rtyp=STRING_CMD;
265      res->data=(void*)feGetExpandedExecutable();
266      if (res->data != NULL)
267        res->data = (void*) mstrdup((char*) res->data);
268      else
269        res->data = (void*) mstrdup("");
270      return FALSE;
271    }
272    else
273/*==================== options ==================================*/
274    if (strstr((char*)(h->data), "--") == (char*)(h->data))
275    {
276      BOOLEAN mainGetSingOptionValue(const char* name, char** result);
277      char* val;
278     
279      if (mainGetSingOptionValue(&((char*)(h->data))[2], &val))
280      {
281        res->data = (void*) val;
282        if ((unsigned int) val > 1)
283        {
284          res->rtyp=STRING_CMD;
285          res->data = (void*) mstrdup((char*) res->data);
286        }
287        else
288          res->rtyp=INT_CMD;
289        return FALSE;
290      }
291      else
292      {
293        Werror("Unknown option %s\n", (char*)(h->data));
294        return TRUE;
295      }
296    }
297    else
298/*==================== print all option values =================*/
299#ifndef NDEBUG
300    if (strcmp((char*)(h->data), "OptionValues") == 0)
301    {
302      void mainOptionValues();
303      mainOptionValues();
304      return FALSE;
305    }
306    else
307#endif
308/*==================== HC ==================================*/
309    if (strcmp((char*)(h->data),"HC")==0)
310    {
311      res->rtyp=INT_CMD;
312      res->data=(void *)HCord;
313      return FALSE;
314    }
315    else
316/*==================== random ==================================*/
317    if(strcmp((char*)(h->Data()),"random")==0)
318    {
319      if ((h->next!=NULL) &&(h->next->Typ()==INT_CMD))
320      {
321        siRandomStart=(int)h->next->Data();
322#ifdef buildin_rand
323        siSeed=siRandomStart;
324#else
325        srand((unsigned int)siRandomStart);
326#endif
327        return FALSE;
328      }
329      else
330        WerrorS("int expected");
331    }
332    else
333/*==================== LaScala ==================================*/
334    if(strcmp((char*)(h->Data()),"LaScala")==0)
335    {
336      if ((h->next!=NULL)
337      &&((h->next->Typ()==IDEAL_CMD)||(h->next->Typ()==MODUL_CMD)))
338      {
339        int dummy;
340        res->data=(void *)syLaScala3((ideal)h->next->Data(),&dummy);
341        mmTest(res->data,sizeof(ssyStrategy));
342        syStrategy s=(syStrategy)res->data;
343        for (int i=s->length;i>=0;i--)
344        {
345          if (s->res[i]!=NULL)
346            idTest(s->res[i]);
347        }
348        res->rtyp=RESOLUTION_CMD;
349        return FALSE;
350      }
351      else
352         WerrorS("ideal/module expected");
353    }
354    else
355/*==================== naIdeal ==================================*/
356    if(strcmp((char*)(h->Data()),"naIdeal")==0)
357    {
358      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
359      {
360        naSetIdeal((ideal)h->next->Data());
361        return FALSE;
362      }
363      else
364         WerrorS("ideal expected");
365    }
366    else
367/*==================== isSqrFree =============================*/
368#ifdef HAVE_FACTORY
369    if(strcmp((char*)(h->Data()),"isSqrFree")==0)
370    {
371      if ((h->next!=NULL) &&(h->next->Typ()==POLY_CMD))
372      {
373        res->rtyp=INT_CMD;
374        res->data=(void *)singclap_isSqrFree((poly)h->next->Data());
375        return FALSE;
376      }
377      else
378        WerrorS("poly expected");
379    }
380    else
381#endif
382/*==================== neworder =============================*/
383#ifdef HAVE_LIBFAC_P
384    if(strcmp((char*)(h->Data()),"neworder")==0)
385    {
386      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
387      {
388        res->rtyp=STRING_CMD;
389        res->data=(void *)singclap_neworder((ideal)h->next->Data());
390        return FALSE;
391      }
392      else
393        WerrorS("ideal expected");
394    }
395    else
396#endif
397/*==================== alarm ==================================*/
398#ifndef macintosh
399#ifndef MSDOS
400#ifndef atarist
401#ifdef unix
402    if(strcmp((char*)(h->Data()),"alarm")==0)
403    {
404      if ((h->next!=NULL) &&(h->next->Typ()==INT_CMD))
405      {
406        // standard variant -> SIGALARM (standard: abort)
407        //alarm((unsigned)h->next->Data());
408        // process time (user +system): SIGVTALARM
409        struct itimerval t,o;
410        memset(&t,0,sizeof(t));
411        t.it_value.tv_sec     =(unsigned)h->next->Data();
412        setitimer(ITIMER_VIRTUAL,&t,&o);
413        return FALSE;
414      }
415      else
416        WerrorS("int expected");
417    }
418    else
419#endif
420#endif
421#endif
422#endif
423/*==================== red =============================*/
424#if 0
425    if(strcmp((char*)(h->Data()),"red")==0)
426    {
427     if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
428      {
429        res->rtyp=IDEAL_CMD;
430        res->data=(void *)stdred((ideal)h->next->Data(),NULL,testHomog,NULL);
431        setFlag(res,FLAG_STD);
432        return FALSE;
433      }
434      else
435        WerrorS("ideal expected");
436    }
437    else
438#endif
439#ifdef HAVE_FACTORY
440/*==================== pdivide ====================*/
441    if (strcmp((char*)(h->Data()),"pdivide")==0)
442    {
443      if (h->next!=NULL && h->next->next!=NULL &&
444           h->next->Typ()==POLY_CMD && h->next->next->Typ()==POLY_CMD)
445      {
446        res->rtyp=POLY_CMD;
447        res->data=(void*)(singclap_pdivide((poly)(h->next->Data()),
448                                         (poly)(h->next->next->Data())));
449        return FALSE;
450      }
451      else
452        WerrorS("poly expected");
453    }
454    else
455#endif
456/*==================== algfetch =====================*/
457    if (strcmp((char*)(h->Data()),"algfetch")==0)
458    {
459      int k;
460      idhdl w;
461      ideal i0, i1;
462      leftv v=h->next;
463      ring r0=(ring)v->Data();
464      v = v->next;
465      w = r0->idroot->get(v->Name(),myynest);
466      i0 = IDIDEAL(w);
467      i1 = idInit(IDELEMS(i0),i0->rank);
468      for (k=0; k<IDELEMS(i1); k++)
469      {
470        i1->m[k] = maAlgpolyFetch(r0, i0->m[k]);
471      }
472      res->rtyp = IDEAL_CMD;
473      res->data = (void*)i1;
474      return FALSE;
475    }
476    else
477/*==================== algmap =======================*/
478    if (strcmp((char*)(h->Data()),"algmap")==0)
479    {
480      int k;
481      idhdl w;
482      ideal i0, i1, i, j;
483      leftv v=h->next;
484      ring r0=(ring)v->Data();
485      v = v->next;
486      w = r0->idroot->get(v->Name(),myynest);
487      i0 = IDIDEAL(w);
488      v = v->next;
489      i = (ideal)v->Data();
490      v = v->next;
491      j = (ideal)v->Data();
492      i1 = idInit(IDELEMS(i0),i0->rank);
493      for (k=0; k<IDELEMS(i1); k++)
494      {
495        i1->m[k] = maAlgpolyMap(r0, i0->m[k], i, j);
496      }
497      res->rtyp = IDEAL_CMD;
498      res->data = (void*)i1;
499      return FALSE;
500    }
501    else
502/*==================== indsetall =============================*/
503    if(strcmp((char*)(h->Data()),"indsetall")==0)
504    {
505      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
506      {
507        int i=0;
508        if (h->next->next!=NULL)
509        {
510          if (h->next->next->Typ()==INT_CMD)
511            i=(int)h->next->next->Data();
512          else
513          {
514            Warn("int expected");
515          }
516        }
517        res->rtyp=LIST_CMD;
518        res->data=(void *)scIndIndset((ideal)h->next->Data(),i,currQuotient);
519        return FALSE;
520      }
521      else
522        WerrorS("ideal expected");
523    }
524    else
525#ifdef STDTRACE
526    /*==================== trace =============================*/
527    /* Parameter : Ideal, Liste mit Links. */
528    if(strcmp((char*)(h->Data()),"stdtrace")==0)
529    {
530      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
531      {
532        leftv root  = NULL,
533              ptr   = NULL,
534              lv    = NULL;
535        lists l     = NULL;
536        ideal I     = (ideal)(h->next->Data());
537        lists links = (lists)(h->next->next->Data());
538        tHomog hom  = testHomog;
539        int rw      = (int)(h->next->next->next->Data());
540
541        if(I==NULL)
542          PrintS("I==NULL\n");
543        for(int i=0; i <= links->nr ; i++)
544        {
545          lv = (leftv)Alloc0(sizeof(sleftv));
546          lv->Copy(&(links->m[i]));
547          if(root==NULL)
548          root=lv;
549          if(ptr==NULL)
550          {
551            ptr=lv;
552            ptr->next=NULL;
553          }
554          else
555          {
556            ptr->next=lv;
557            ptr=lv;
558          }
559        }
560        ptr->next=NULL;
561        l=TraceStd(root,rw,I,currQuotient,testHomog,NULL);
562        idSkipZeroes(((ideal)l->m[0].Data()));
563        res->rtyp=LIST_CMD;
564        res->data=(void *) l;
565        res->next=NULL;
566        root->CleanUp();
567        Free(root,sizeof(sleftv));
568        return FALSE;
569      }
570      else
571         WerrorS("ideal expected");
572    }
573    else
574#endif
575#ifdef HAVE_FACTORY
576/*==================== fastcomb =============================*/
577    if(strcmp((char*)(h->Data()),"fastcomb")==0)
578    {
579      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
580      {
581        int i=0;
582        if (h->next->next!=NULL)
583        {
584          if (h->next->next->Typ()!=POLY_CMD)
585          {
586              Warn("Wrong types for poly= comb(ideal,poly)");
587          }
588        }
589        res->rtyp=POLY_CMD;
590        res->data=(void *)fglmLinearCombination((ideal)h->next->Data(),(poly)h->next->next->Data());
591        return FALSE;
592      }
593      else
594        WerrorS("ideal expected");
595    }
596    else
597/*==================== comb =============================*/
598    if(strcmp((char*)(h->Data()),"comb")==0)
599    {
600      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
601      {
602        int i=0;
603        if (h->next->next!=NULL)
604        {
605          if (h->next->next->Typ()!=POLY_CMD)
606          {
607              Warn("Wrong types for poly= comb(ideal,poly)");
608          }
609        }
610        res->rtyp=POLY_CMD;
611        res->data=(void *)fglmNewLinearCombination((ideal)h->next->Data(),(poly)h->next->next->Data());
612        return FALSE;
613      }
614      else
615        WerrorS("ideal expected");
616    }
617    else
618#endif
619/*==================== divcount & mcount =============================*/
620#ifdef MONOM_COUNT
621    if (strcmp((char*)(h->Data()),"mcount")==0)
622    {
623      extern void OutputMonomCount();
624      OutputMonomCount();
625      return FALSE;
626    }
627    else if (strcmp((char*)(h->Data()),"mreset")==0)
628    {
629      extern void ResetMonomCount();
630      ResetMonomCount();
631      return FALSE;
632    }
633    else
634#endif
635#ifdef DIV_COUNT
636    if (strcmp((char*)(h->Data()),"dcount")==0)
637    {
638      extern void OutputDivCount();
639      OutputDivCount();
640      return FALSE;
641    }
642    else if (strcmp((char*)(h->Data()),"dreset")==0)
643    {
644      extern void ResetDivCount();
645      ResetDivCount();
646      return FALSE;
647    }
648    else
649#endif
650/*==================== barstep =============================*/
651    if(strcmp((char*)(h->Data()),"barstep")==0)
652    {
653      if ((h->next!=NULL) &&(h->next->Typ()==MATRIX_CMD))
654      {
655        if (h->next->next!=NULL)
656        {
657          if (h->next->next->Typ()!=POLY_CMD)
658          {
659            Warn("Wrong types for barstep(matrix,poly)");
660          }
661        }
662        int r,c;
663        poly div=(poly)h->next->next->Data();
664        res->rtyp=MATRIX_CMD;
665        res->data=(void *)mpOneStepBareiss((matrix)h->next->Data(),
666                                           &div,&r,&c);
667        Print("div: ");pWrite(div);
668        Print("rows: %d, cols: %d\n",r,c);
669        pDelete(&div);
670        return FALSE;
671      }
672      else
673        WerrorS("matrix expected");
674    }
675    else
676#ifdef FACTORY_GCD_TEST
677/*=======================gcd Testerei ================================*/
678    if ( ! strcmp( (char*)(h->Data()), "setgcd" ) ) {
679        if ( (h->next != NULL) && (h->next->Typ() == INT_CMD) ) {
680            CFPrimitiveGcdUtil::setAlgorithm( (int)h->next->Data() );
681            return FALSE;
682        } else
683            WerrorS("int expected");
684    }
685    else
686#endif
687
688#ifdef FACTORY_GCD_TIMING
689    if ( ! strcmp( (char*)(h->Data()), "gcdtime" ) ) {
690        TIMING_PRINT( contentTimer, "time used for content: " );
691        TIMING_PRINT( algContentTimer, "time used for algContent: " );
692        TIMING_PRINT( algLcmTimer, "time used for algLcm: " );
693        TIMING_RESET( contentTimer );
694        TIMING_RESET( algContentTimer );
695        TIMING_RESET( algLcmTimer );
696        return FALSE;
697    }
698    else
699#endif
700     
701#ifdef FACTORY_GCD_STAT
702    if ( ! strcmp( (char*)(h->Data()), "gcdstat" ) ) {
703        printGcdTotal();
704        printContTotal();
705        resetGcdTotal();
706        resetContTotal();
707        return FALSE;
708    }
709    else
710#endif
711     
712/*============================================================*/
713      WerrorS( feNotImplemented );
714  }
715  return TRUE;
716}
Note: See TracBrowser for help on using the repository browser.