source: git/Singular/extra.cc @ fca547

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