source: git/Singular/extra.cc @ 5079a04

spielwiese
Last change on this file since 5079a04 was 5079a04, checked in by Jens Schmidt <schmidt@…>, 26 years ago
* extra.cc (FACTORY_GCD_TIMING): dependency on FACTORY_GCD_TEST removed git-svn-id: file:///usr/local/Singular/svn/trunk@1430 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 18.7 KB
Line 
1/*****************************************
2*  Computer Algebra System SINGULAR      *
3*****************************************/
4/* $Id: extra.cc,v 1.39 1998-04-23 09:50:23 schmidt 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#define FACTORY_GCD_TEST
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 ((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/*==================== writemat ==================================*/
440//    if(strcmp((char*)(h->Data()),"writemat")==0)
441//    {
442//      if (h->next!=NULL)
443//      {
444//        leftv v=h->next;
445//        if (v->Typ() == STRING_CMD)
446//        {
447//          char *filename = (char *)v->Data();
448//          v = v->next;
449//          if (v->Typ()==MATRIX_CMD)
450//          {
451//            FILE *outfile = fopen(filename,"a");
452//            if (outfile==NULL)
453//            {
454//              Werror("cannot write to file %s",filename);
455//              return TRUE;
456//            }
457//            matrix m=(matrix)v->Data();
458//            fprintf(outfile,"%d\n%d\n",MATROWS(m),MATCOLS(m));
459//            char *s = iiStringMatrix(m,2);
460//            fprintf(outfile,"%s\n",s);
461//            FreeL((ADDRESS)s);
462//            fclose(outfile);
463//            return FALSE;
464//          }
465//          else
466//          {
467//            WerrorS("matrix expected");
468//          }
469//        }
470//        else
471//        {
472//          WerrorS("string expected");
473//        }
474//      }
475//      else
476//        WerrorS("matrix expected");
477//    }
478//    else
479#ifdef HAVE_FACTORY
480/*==================== pdivide ====================*/
481    if (strcmp((char*)(h->Data()),"pdivide")==0)
482    {
483      if (h->next!=NULL && h->next->next!=NULL &&
484           h->next->Typ()==POLY_CMD && h->next->next->Typ()==POLY_CMD)
485      {
486        res->rtyp=POLY_CMD;
487        res->data=(void*)(singclap_pdivide((poly)(h->next->Data()),
488                                         (poly)(h->next->next->Data())));
489        return FALSE;
490      }
491      else
492        WerrorS("poly expected");
493    }
494    else
495#endif
496/*==================== algfetch =====================*/
497    if (strcmp((char*)(h->Data()),"algfetch")==0)
498    {
499      int k;
500      idhdl w;
501      ideal i0, i1;
502      leftv v=h->next;
503      ring r0=(ring)v->Data();
504      v = v->next;
505      w = r0->idroot->get(v->Name(),myynest);
506      i0 = IDIDEAL(w);
507      i1 = idInit(IDELEMS(i0),i0->rank);
508      for (k=0; k<IDELEMS(i1); k++)
509      {
510        i1->m[k] = maAlgpolyFetch(r0, i0->m[k]);
511      }
512      res->rtyp = IDEAL_CMD;
513      res->data = (void*)i1;
514      return FALSE;
515    }
516    else
517/*==================== algmap =======================*/
518    if (strcmp((char*)(h->Data()),"algmap")==0)
519    {
520      int k;
521      idhdl w;
522      ideal i0, i1, i, j;
523      leftv v=h->next;
524      ring r0=(ring)v->Data();
525      v = v->next;
526      w = r0->idroot->get(v->Name(),myynest);
527      i0 = IDIDEAL(w);
528      v = v->next;
529      i = (ideal)v->Data();
530      v = v->next;
531      j = (ideal)v->Data();
532      i1 = idInit(IDELEMS(i0),i0->rank);
533      for (k=0; k<IDELEMS(i1); k++)
534      {
535        i1->m[k] = maAlgpolyMap(r0, i0->m[k], i, j);
536      }
537      res->rtyp = IDEAL_CMD;
538      res->data = (void*)i1;
539      return FALSE;
540    }
541    else
542/*==================== indsetall =============================*/
543    if(strcmp((char*)(h->Data()),"indsetall")==0)
544    {
545      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
546      {
547        int i=0;
548        if (h->next->next!=NULL)
549        {
550          if (h->next->next->Typ()==INT_CMD)
551            i=(int)h->next->next->Data();
552          else
553          {
554            Warn("int expected");
555          }
556        }
557        res->rtyp=LIST_CMD;
558        res->data=(void *)scIndIndset((ideal)h->next->Data(),i,currQuotient);
559        return FALSE;
560      }
561      else
562        WerrorS("ideal expected");
563    }
564    else
565#ifdef STDTRACE
566    /*==================== trace =============================*/
567    /* Parameter : Ideal, Liste mit Links. */
568    if(strcmp((char*)(h->Data()),"stdtrace")==0)
569    {
570      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
571      {
572        leftv root  = NULL,
573              ptr   = NULL,
574              lv    = NULL;
575        lists l     = NULL;
576        ideal I     = (ideal)(h->next->Data());
577        lists links = (lists)(h->next->next->Data());
578        tHomog hom  = testHomog;
579        int rw      = (int)(h->next->next->next->Data());
580
581        if(I==NULL)
582          PrintS("I==NULL\n");
583        for(int i=0; i <= links->nr ; i++)
584        {
585          lv = (leftv)Alloc0(sizeof(sleftv));
586          lv->Copy(&(links->m[i]));
587          if(root==NULL)
588          root=lv;
589          if(ptr==NULL)
590          {
591            ptr=lv;
592            ptr->next=NULL;
593          }
594          else
595          {
596            ptr->next=lv;
597            ptr=lv;
598          }
599        }
600        ptr->next=NULL;
601        l=TraceStd(root,rw,I,currQuotient,testHomog,NULL);
602        idSkipZeroes(((ideal)l->m[0].Data()));
603        res->rtyp=LIST_CMD;
604        res->data=(void *) l;
605        res->next=NULL;
606        root->CleanUp();
607        Free(root,sizeof(sleftv));
608        return FALSE;
609      }
610      else
611         WerrorS("ideal expected");
612    }
613    else
614#endif
615#ifdef HAVE_FACTORY
616/*==================== fastcomb =============================*/
617    if(strcmp((char*)(h->Data()),"fastcomb")==0)
618    {
619      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
620      {
621        int i=0;
622        if (h->next->next!=NULL)
623        {
624          if (h->next->next->Typ()!=POLY_CMD)
625          {
626              Warn("Wrong types for poly= comb(ideal,poly)");
627          }
628        }
629        res->rtyp=POLY_CMD;
630        res->data=(void *)fglmLinearCombination((ideal)h->next->Data(),(poly)h->next->next->Data());
631        return FALSE;
632      }
633      else
634        WerrorS("ideal expected");
635    }
636    else
637/*==================== comb =============================*/
638    if(strcmp((char*)(h->Data()),"comb")==0)
639    {
640      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
641      {
642        int i=0;
643        if (h->next->next!=NULL)
644        {
645          if (h->next->next->Typ()!=POLY_CMD)
646          {
647              Warn("Wrong types for poly= comb(ideal,poly)");
648          }
649        }
650        res->rtyp=POLY_CMD;
651        res->data=(void *)fglmNewLinearCombination((ideal)h->next->Data(),(poly)h->next->next->Data());
652        return FALSE;
653      }
654      else
655        WerrorS("ideal expected");
656    }
657    else
658#endif
659/*==================== divcount & mcount =============================*/
660#ifdef MONOM_COUNT
661    if (strcmp((char*)(h->Data()),"mcount")==0)
662    {
663      extern void OutputMonomCount();
664      OutputMonomCount();
665      return FALSE;
666    }
667    else if (strcmp((char*)(h->Data()),"mreset")==0)
668    {
669      extern void ResetMonomCount();
670      ResetMonomCount();
671      return FALSE;
672    }
673    else
674#endif
675#ifdef DIV_COUNT
676    if (strcmp((char*)(h->Data()),"dcount")==0)
677    {
678      extern void OutputDivCount();
679      OutputDivCount();
680      return FALSE;
681    }
682    else if (strcmp((char*)(h->Data()),"dreset")==0)
683    {
684      extern void ResetDivCount();
685      ResetDivCount();
686      return FALSE;
687    }
688    else
689#endif
690/*==================== barstep =============================*/
691    if(strcmp((char*)(h->Data()),"barstep")==0)
692    {
693      if ((h->next!=NULL) &&(h->next->Typ()==MATRIX_CMD))
694      {
695        if (h->next->next!=NULL)
696        {
697          if (h->next->next->Typ()!=POLY_CMD)
698          {
699            Warn("Wrong types for barstep(matrix,poly)");
700          }
701        }
702        int r,c;
703        poly div=(poly)h->next->next->Data();
704        res->rtyp=MATRIX_CMD;
705        res->data=(void *)mpOneStepBareiss((matrix)h->next->Data(),
706                                           &div,&r,&c);
707        Print("div: ");pWrite(div);
708        Print("rows: %d, cols: %d\n",r,c);
709        pDelete(&div);
710        return FALSE;
711      }
712      else
713        WerrorS("matrix expected");
714    }
715    else
716#ifdef FACTORY_GCD_TEST
717/*=======================gcd Testerei ================================*/
718    if ( ! strcmp( (char*)(h->Data()), "setgcd" ) ) {
719        if ( (h->next != NULL) && (h->next->Typ() == INT_CMD) ) {
720            CFPrimitiveGcdUtil::setAlgorithm( (int)h->next->Data() );
721            return FALSE;
722        } else
723            WerrorS("int expected");
724    }
725    else
726#endif
727
728#ifdef FACTORY_GCD_TIMING
729    if ( ! strcmp( (char*)(h->Data()), "gcdtime" ) ) {
730        TIMING_PRINT( contentTimer, "time used for content: " );
731        TIMING_PRINT( algContentTimer, "time used for algContent: " );
732        TIMING_PRINT( algLcmTimer, "time used for algLcm: " );
733        TIMING_RESET( contentTimer );
734        TIMING_RESET( algContentTimer );
735        TIMING_RESET( algLcmTimer );
736        return FALSE;
737    }
738    else
739#endif
740     
741/*============================================================*/
742      WerrorS( feNotImplemented );
743  }
744  return TRUE;
745}
Note: See TracBrowser for help on using the repository browser.