source: git/Singular/extra.cc @ 3a20c1

fieker-DuValspielwiese
Last change on this file since 3a20c1 was 1caa72, checked in by Olaf Bachmann <obachman@…>, 26 years ago
1998-04-06 Olaf Bachmann <obachman@mathematik.uni-kl.de> * spSpolyLoop.h: neww calling interface for spGetSpolyLoop * kstd1.cc (kNF): moved strat->ak field initailization out of initBuchMora into single routines * febase.cc (feGetSearchPath): added feGetSearchPath; changed algorithm for searching files: $SINGULARPATH -> relative to executable -> burnt-in locations * added find_exec.c to get absolute pathname of executable git-svn-id: file:///usr/local/Singular/svn/trunk@1341 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 17.0 KB
Line 
1/*****************************************
2*  Computer Algebra System SINGULAR      *
3*****************************************/
4/* $Id: extra.cc,v 1.33 1998-04-06 17:59:27 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//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#if 0
248/*==================== whoami ==================================*/
249    if (strcmp((char*)(h->data), "whoami") == 0)
250    {
251      res->rtype=STRING_CMD;
252    }
253#endif
254/*==================== HC ==================================*/
255    if (strcmp((char*)(h->data),"HC")==0)
256    {
257      res->rtyp=INT_CMD;
258      res->data=(void *)HCord;
259      return FALSE;
260    }
261    else
262/*==================== random ==================================*/
263    if(strcmp((char*)(h->Data()),"random")==0)
264    {
265      if ((h->next!=NULL) &&(h->next->Typ()==INT_CMD))
266      {
267        siRandomStart=(int)h->next->Data();
268#ifdef buildin_rand
269        siSeed=siRandomStart;
270#else
271        srand((unsigned int)siRandomStart);
272#endif
273        return FALSE;
274      }
275      else
276        WerrorS("int expected");
277    }
278    else
279/*==================== LaScala ==================================*/
280    if(strcmp((char*)(h->Data()),"LaScala")==0)
281    {
282      if ((h->next!=NULL) 
283      &&((h->next->Typ()==IDEAL_CMD)||(h->next->Typ()==MODUL_CMD)))
284      {
285        int dummy;
286        res->data=(void *)syLaScala3((ideal)h->next->Data(),&dummy);
287        mmTest(res->data,sizeof(ssyStrategy));
288        syStrategy s=(syStrategy)res->data;
289        for (int i=s->length;i>=0;i--)
290        {
291          if (s->res[i]!=NULL)
292            idTest(s->res[i]);
293        }
294        res->rtyp=RESOLUTION_CMD;
295        return FALSE;
296      }
297      else
298         WerrorS("ideal/module expected");
299    }
300    else
301/*==================== naIdeal ==================================*/
302    if(strcmp((char*)(h->Data()),"naIdeal")==0)
303    {
304      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
305      {
306        naSetIdeal((ideal)h->next->Data());
307        return FALSE;
308      }
309      else
310         WerrorS("ideal expected");
311    }
312    else
313/*==================== isSqrFree =============================*/
314#ifdef HAVE_FACTORY
315    if(strcmp((char*)(h->Data()),"isSqrFree")==0)
316    {
317      if ((h->next!=NULL) &&(h->next->Typ()==POLY_CMD))
318      {
319        res->rtyp=INT_CMD;
320        res->data=(void *)singclap_isSqrFree((poly)h->next->Data());
321        return FALSE;
322      }
323      else
324        WerrorS("poly expected");
325    }
326    else
327#endif
328/*==================== neworder =============================*/
329#ifdef HAVE_LIBFAC_P
330    if(strcmp((char*)(h->Data()),"neworder")==0)
331    {
332      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
333      {
334        res->rtyp=STRING_CMD;
335        res->data=(void *)singclap_neworder((ideal)h->next->Data());
336        return FALSE;
337      }
338      else
339        WerrorS("ideal expected");
340    }
341    else
342#endif
343/*==================== alarm ==================================*/
344#ifndef macintosh
345#ifndef MSDOS
346#ifndef atarist
347#ifdef unix
348    if(strcmp((char*)(h->Data()),"alarm")==0)
349    {
350      if ((h->next!=NULL) &&(h->next->Typ()==INT_CMD))
351      {
352        // standard variant -> SIGALARM (standard: abort)
353        //alarm((unsigned)h->next->Data());
354        // process time (user +system): SIGVTALARM
355        struct itimerval t,o;
356        memset(&t,0,sizeof(t));
357        t.it_value.tv_sec     =(unsigned)h->next->Data();
358        setitimer(ITIMER_VIRTUAL,&t,&o);
359        return FALSE;
360      }
361      else
362        WerrorS("int expected");
363    }
364    else
365#endif
366#endif
367#endif
368#endif
369/*==================== red =============================*/
370#if 0
371    if(strcmp((char*)(h->Data()),"red")==0)
372    {
373     if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
374      {
375        res->rtyp=IDEAL_CMD;
376        res->data=(void *)stdred((ideal)h->next->Data(),NULL,testHomog,NULL);
377        setFlag(res,FLAG_STD);
378        return FALSE;
379      }
380      else
381        WerrorS("ideal expected");
382    }
383    else
384#endif
385/*==================== writemat ==================================*/
386//    if(strcmp((char*)(h->Data()),"writemat")==0)
387//    {
388//      if (h->next!=NULL)
389//      {
390//        leftv v=h->next;
391//        if (v->Typ() == STRING_CMD)
392//        {
393//          char *filename = (char *)v->Data();
394//          v = v->next;
395//          if (v->Typ()==MATRIX_CMD)
396//          {
397//            FILE *outfile = fopen(filename,"a");
398//            if (outfile==NULL)
399//            {
400//              Werror("cannot write to file %s",filename);
401//              return TRUE;
402//            }
403//            matrix m=(matrix)v->Data();
404//            fprintf(outfile,"%d\n%d\n",MATROWS(m),MATCOLS(m));
405//            char *s = iiStringMatrix(m,2);
406//            fprintf(outfile,"%s\n",s);
407//            FreeL((ADDRESS)s);
408//            fclose(outfile);
409//            return FALSE;
410//          }
411//          else
412//          {
413//            WerrorS("matrix expected");
414//          }
415//        }
416//        else
417//        {
418//          WerrorS("string expected");
419//        }
420//      }
421//      else
422//        WerrorS("matrix expected");
423//    }
424//    else
425#ifdef HAVE_FACTORY
426/*==================== pdivide ====================*/
427    if (strcmp((char*)(h->Data()),"pdivide")==0)
428    {
429      if (h->next!=NULL && h->next->next!=NULL &&
430           h->next->Typ()==POLY_CMD && h->next->next->Typ()==POLY_CMD)
431      {
432        res->rtyp=POLY_CMD;
433        res->data=(void*)(singclap_pdivide((poly)(h->next->Data()),
434                                         (poly)(h->next->next->Data())));
435        return FALSE;
436      }
437      else
438        WerrorS("poly expected");
439    }
440    else
441#endif
442/*==================== algfetch =====================*/
443    if (strcmp((char*)(h->Data()),"algfetch")==0)
444    {
445      int k;
446      idhdl w;
447      ideal i0, i1;
448      leftv v=h->next;
449      ring r0=(ring)v->Data();
450      v = v->next;
451      w = r0->idroot->get(v->Name(),myynest);
452      i0 = IDIDEAL(w);
453      i1 = idInit(IDELEMS(i0),i0->rank);
454      for (k=0; k<IDELEMS(i1); k++)
455      {
456        i1->m[k] = maAlgpolyFetch(r0, i0->m[k]);
457      }
458      res->rtyp = IDEAL_CMD;
459      res->data = (void*)i1;
460      return FALSE;
461    }
462    else
463/*==================== algmap =======================*/
464    if (strcmp((char*)(h->Data()),"algmap")==0)
465    {
466      int k;
467      idhdl w;
468      ideal i0, i1, i, j;
469      leftv v=h->next;
470      ring r0=(ring)v->Data();
471      v = v->next;
472      w = r0->idroot->get(v->Name(),myynest);
473      i0 = IDIDEAL(w);
474      v = v->next;
475      i = (ideal)v->Data();
476      v = v->next;
477      j = (ideal)v->Data();
478      i1 = idInit(IDELEMS(i0),i0->rank);
479      for (k=0; k<IDELEMS(i1); k++)
480      {
481        i1->m[k] = maAlgpolyMap(r0, i0->m[k], i, j);
482      }
483      res->rtyp = IDEAL_CMD;
484      res->data = (void*)i1;
485      return FALSE;
486    }
487    else
488/*==================== indsetall =============================*/
489    if(strcmp((char*)(h->Data()),"indsetall")==0)
490    {
491      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
492      {
493        int i=0;
494        if (h->next->next!=NULL)
495        {
496          if (h->next->next->Typ()==INT_CMD)
497            i=(int)h->next->next->Data();
498          else
499          {
500            Warn("int expected");
501          }
502        }
503        res->rtyp=LIST_CMD;
504        res->data=(void *)scIndIndset((ideal)h->next->Data(),i,currQuotient);
505        return FALSE;
506      }
507      else
508        WerrorS("ideal expected");
509    }
510    else
511#ifdef STDTRACE
512    /*==================== trace =============================*/
513    /* Parameter : Ideal, Liste mit Links. */
514    if(strcmp((char*)(h->Data()),"stdtrace")==0)
515    {
516      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
517      {
518        leftv root  = NULL,
519              ptr   = NULL,
520              lv    = NULL;
521        lists l     = NULL;
522        ideal I     = (ideal)(h->next->Data());
523        lists links = (lists)(h->next->next->Data());
524        tHomog hom  = testHomog;
525        int rw      = (int)(h->next->next->next->Data());
526
527        if(I==NULL)
528          PrintS("I==NULL\n");
529        for(int i=0; i <= links->nr ; i++)
530        {
531          lv = (leftv)Alloc0(sizeof(sleftv));
532          lv->Copy(&(links->m[i]));
533          if(root==NULL)
534          root=lv;
535          if(ptr==NULL)
536          {
537            ptr=lv;
538            ptr->next=NULL;
539          }
540          else
541          {
542            ptr->next=lv;
543            ptr=lv;
544          }
545        }
546        ptr->next=NULL;
547        l=TraceStd(root,rw,I,currQuotient,testHomog,NULL);
548        idSkipZeroes(((ideal)l->m[0].Data()));
549        res->rtyp=LIST_CMD;
550        res->data=(void *) l;
551        res->next=NULL;
552        root->CleanUp();
553        Free(root,sizeof(sleftv));
554        return FALSE;
555      }
556      else
557         WerrorS("ideal expected");
558    }
559    else 
560#endif
561#ifdef HAVE_FACTORY     
562/*==================== fastcomb =============================*/
563    if(strcmp((char*)(h->Data()),"fastcomb")==0)
564    {
565      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
566      {
567        int i=0;
568        if (h->next->next!=NULL)
569        {
570          if (h->next->next->Typ()!=POLY_CMD)
571          {
572              Warn("Wrong types for poly= comb(ideal,poly)");
573          }
574        }
575        res->rtyp=POLY_CMD;
576        res->data=(void *)fglmLinearCombination((ideal)h->next->Data(),(poly)h->next->next->Data());
577        return FALSE;
578      }
579      else
580        WerrorS("ideal expected");
581    }
582    else
583/*==================== comb =============================*/
584    if(strcmp((char*)(h->Data()),"comb")==0)
585    {
586      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
587      {
588        int i=0;
589        if (h->next->next!=NULL)
590        {
591          if (h->next->next->Typ()!=POLY_CMD)
592          {
593              Warn("Wrong types for poly= comb(ideal,poly)");
594          }
595        }
596        res->rtyp=POLY_CMD;
597        res->data=(void *)fglmNewLinearCombination((ideal)h->next->Data(),(poly)h->next->next->Data());
598        return FALSE;
599      }
600      else
601        WerrorS("ideal expected");
602    }
603    else
604/*==================== finduni =============================*/
605    if(strcmp((char*)(h->Data()),"finduni")==0)
606    {
607      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
608      {
609        res->rtyp=IDEAL_CMD;
610        res->data=(void *)FindUnivariateWrapper((ideal)h->next->Data());
611        return FALSE;
612      }
613      else
614        WerrorS("ideal expected");
615    }
616    else
617#endif
618/*==================== divcount & mcount =============================*/     
619#ifdef MONOM_COUNT
620    if (strcmp((char*)(h->Data()),"mcount")==0)
621    {
622      extern void OutputMonomCount();
623      OutputMonomCount();
624      return FALSE;
625    }
626    else if (strcmp((char*)(h->Data()),"mreset")==0)
627    {
628      extern void ResetMonomCount();
629      ResetMonomCount();
630      return FALSE;
631    }
632    else
633#endif     
634#ifdef DIV_COUNT
635    if (strcmp((char*)(h->Data()),"dcount")==0)
636    {
637      extern void OutputDivCount();
638      OutputDivCount();
639      return FALSE;
640    }
641    else if (strcmp((char*)(h->Data()),"dreset")==0)
642    {
643      extern void ResetDivCount();
644      ResetDivCount();
645      return FALSE;
646    }
647    else
648#endif     
649/*==================== barstep =============================*/
650    if(strcmp((char*)(h->Data()),"barstep")==0)
651    {
652      if ((h->next!=NULL) &&(h->next->Typ()==MATRIX_CMD))
653      {
654        if (h->next->next!=NULL)
655        {
656          if (h->next->next->Typ()!=POLY_CMD)
657          {
658            Warn("Wrong types for barstep(matrix,poly)");
659          }
660        }
661        int r,c;
662        poly div=(poly)h->next->next->Data();
663        res->rtyp=MATRIX_CMD;
664        res->data=(void *)mpOneStepBareiss((matrix)h->next->Data(),
665                                           &div,&r,&c);
666        Print("div: ");pWrite(div);
667        Print("rows: %d, cols: %d\n",r,c);
668        pDelete(&div);
669        return FALSE;
670      }
671      else
672        WerrorS("matrix expected");
673    }
674  }
675 
676/*============================================================*/
677  WerrorS("not implemented\n");
678  return TRUE;
679}
Note: See TracBrowser for help on using the repository browser.