source: git/Singular/extra.cc @ 54c713

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