source: git/Singular/extra.cc @ 30637f

fieker-DuValspielwiese
Last change on this file since 30637f was 592f6b, checked in by Hans Schönemann <hannes@…>, 27 years ago
* hannes: added system("with"...) to extra.cc git-svn-id: file:///usr/local/Singular/svn/trunk@199 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 12.6 KB
Line 
1/*****************************************
2*  Computer Algebra System SINGULAR      *
3*****************************************/
4/* $Id: extra.cc,v 1.10 1997-04-25 18:52:24 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 "kutil.h"
38#include "cntrlc.h"
39#include "stairc.h"
40#include "ipshell.h"
41#include "algmap.h"
42#include "modulop.h"
43#include "febase.h"
44#include "matpol.h"
45#include "longalg.h"
46#include "ideals.h"
47#include "kstd1.h"
48
49#ifdef HAVE_FACTORY
50#define SI_DONT_HAVE_GLOBAL_VARS
51#include "clapsing.h"
52#include "clapconv.h"
53#include "kstdfac.h"
54#endif
55
56//void emStart();
57/*2
58*  the "system" command
59*/
60BOOLEAN jjSYSTEM(leftv res, leftv h)
61{
62  if(h->Typ() == STRING_CMD)
63  {
64/*==================== lib ==================================*/
65    if(strcmp((char*)(h->Data()),"LIB")==0)
66    {
67      idhdl hh=idroot->get((char*)h->next->Data(),0);
68      if ((hh!=NULL)&&(IDTYP(hh)==PROC_CMD))
69      {
70        res->rtyp=STRING_CMD;
71        res->data=mstrdup(iiGetLibName(IDSTRING(hh)));
72        if (res->data==NULL) res->data=mstrdup("");
73        return FALSE;
74      }
75      else
76        Warn("`%s` not found",(char*)h->next->Data());
77    }
78    else
79/*==================== version ==================================*/
80    if(strcmp((char*)(h->Data()),"version")==0)
81    {
82      res->rtyp=INT_CMD;
83      res->data=(void *)VERSION;
84      return FALSE;
85    }
86    else
87/*==================== gen ==================================*/
88    if(strcmp((char*)(h->Data()),"gen")==0)
89    {
90      res->rtyp=INT_CMD;
91      res->data=(void *)npGen;
92      return FALSE;
93    }
94    else
95/*==================== sh ==================================*/
96    #ifndef macintosh
97    if(strcmp((char*)(h->Data()),"sh")==0)
98    {
99      #ifndef MSDOS
100      #ifdef HAVE_FEREAD
101      fe_temp_reset();
102      #endif
103      #endif
104      res->rtyp=INT_CMD;
105      if (h->next==NULL) res->data = (void *)system("/bin/sh");
106      else res->data = (void*) system((char*)(h->next->Data()));
107      #ifndef MSDOS
108      #ifdef HAVE_FEREAD
109      fe_temp_set();
110      #endif
111      #endif
112      return FALSE;
113    }
114    else
115    #endif
116/*==================== with ==================================*/
117    if(strcmp((char*)(h->Data()),"with")==0)
118    {
119      if (h->next==NULL)
120      {
121        res->rtyp=STRING_CMD;
122        char *s=mstrdup(""
123        #ifdef DRING
124          "DRING "
125        #endif
126        #ifdef HAVE_DBM
127          "DBM "
128        #endif
129        #ifdef HAVE_DLD
130          "DLD "
131        #endif
132        #ifdef HAVE_GMP
133          "gmp "
134        #endif
135        #ifdef HAVE_FACTORY
136          "factory "
137        #endif
138        #ifdef HAVE_LIBFAC_P
139          "libfac "
140        #endif
141        #ifdef HAVE_MPSR
142          "MP "
143        #endif
144        #ifdef HAVE_READLINE
145          "readline "
146        #endif
147        #ifdef HAVE_TCL
148          "tcl "
149        #endif
150        #ifdef SRING
151          "SRING "
152        #endif
153        );
154        s[strlen(s)-1]='\0';
155        res->data=(void *)s;
156        return FALSE;
157      } 
158      else if (h->next->Typ()==STRING_CMD)
159      {
160        #define TEST_FOR(A) if(strcmp(s,A)==0) res->data=(void *)1; else
161        char *s=(char *)h->next->Data();
162        res->rtyp=INT_CMD;
163        #ifdef DRING
164          TEST_FOR("DRING")
165        #endif
166        #ifdef HAVE_DBM
167          TEST_FOR("DBM")
168        #endif
169        #ifdef HAVE_DLD
170          TEST_FOR("DLD")
171        #endif
172        #ifdef HAVE_GMP
173          TEST_FOR("gmp")
174        #endif
175        #ifdef HAVE_FACTORY
176          TEST_FOR("factory")
177        #endif
178        #ifdef HAVE_LIBFAC_P
179          TEST_FOR("libfac")
180        #endif
181        #ifdef HAVE_MPSR
182          TEST_FOR("MP")
183        #endif
184        #ifdef HAVE_READLINE
185          TEST_FOR("readline")
186        #endif
187        #ifdef HAVE_TCL
188          TEST_FOR("tcl")
189        #endif
190        #ifdef SRING
191          TEST_FOR("SRING")
192        #endif
193          ;
194        return FALSE;
195        #undef TEST_FOR
196      }
197      return TRUE;
198    }
199    else
200/*==================== pid ==================================*/
201    #ifndef MSDOS
202    #ifndef macintosh
203    if (strcmp((char*)(h->Data()),"pid")==0)
204    {
205      res->rtyp=INT_CMD;
206      res->data=(void *)getpid();
207      return FALSE;
208    }
209    else
210    #endif
211    #endif
212/*==================== getenv ==================================*/
213    if (strcmp((char*)(h->Data()),"getenv")==0)
214    {
215      if ((h->next!=NULL) && (h->next->Typ()==STRING_CMD))
216      {
217        res->rtyp=STRING_CMD;
218        char *r=getenv((char *)h->next->Data());
219        if (r==NULL) r="";
220        res->data=(void *)mstrdup(r);
221        return FALSE;
222      }
223      else
224      {
225        WerrorS("string expected");
226      }
227    }
228    else
229/*==================== tty ==================================*/
230    #ifndef macintosh
231    #ifndef MSDOS
232    if (strcmp((char*)(h->Data()),"tty")==0)
233    {
234        #ifdef HAVE_FEREAD
235        #ifdef HAVE_ATEXIT
236        fe_reset_input_mode();
237        #else
238        fe_reset_input_mode(0,NULL);
239        #endif
240        if ((h->next!=NULL)&&(h->next->Typ()==INT_CMD))
241        {
242          fe_use_fgets=(int)h->next->Data();
243          fe_set_input_mode();
244        }
245        #elif HAVE_READLINE
246        system("stty sane");
247        #endif
248      return FALSE;
249    }
250    else
251    #endif
252    #endif
253/*==================== HC ==================================*/
254    if (strcmp((char*)(h->data),"HC")==0)
255    {
256      res->rtyp=INT_CMD;
257      res->data=(void *)HCord;
258      return FALSE;
259    }
260    else
261/*==================== random ==================================*/
262    if(strcmp((char*)(h->Data()),"random")==0)
263    {
264      if ((h->next!=NULL) &&(h->next->Typ()==INT_CMD))
265      {
266        siRandomStart=(int)h->next->Data();
267#ifdef buildin_rand
268        siSeed=siRandomStart;
269#else
270        srand((unsigned int)siRandomStart);
271#endif
272        return FALSE;
273      }
274      else
275        WerrorS("int expected");
276    }
277    else
278/*==================== naIdeal ==================================*/
279    if(strcmp((char*)(h->Data()),"naIdeal")==0)
280    {
281      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
282      {
283        naSetIdeal((ideal)h->next->Data());
284        return FALSE;
285      }
286      else
287         WerrorS("ideal expected");
288    }
289    else
290/*==================== isSqrFree =============================*/
291#ifdef HAVE_FACTORY
292    if(strcmp((char*)(h->Data()),"isSqrFree")==0)
293    {
294      if ((h->next!=NULL) &&(h->next->Typ()==POLY_CMD))
295      {
296        res->rtyp=INT_CMD;
297        res->data=(void *)singclap_isSqrFree((poly)h->next->Data());
298        return FALSE;
299      }
300      else
301        WerrorS("poly expected");
302    }
303    else
304#endif
305/*==================== neworder =============================*/
306#ifdef HAVE_LIBFAC_P
307    if(strcmp((char*)(h->Data()),"neworder")==0)
308    {
309      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
310      {
311        res->rtyp=STRING_CMD;
312        res->data=(void *)singclap_neworder((ideal)h->next->Data());
313        return FALSE;
314      }
315      else
316        WerrorS("ideal expected");
317    }
318    else
319#endif
320/*==================== alarm ==================================*/
321#ifndef macintosh
322#ifndef MSDOS
323#ifndef atarist
324    if(strcmp((char*)(h->Data()),"alarm")==0)
325    {
326      if ((h->next!=NULL) &&(h->next->Typ()==INT_CMD))
327      {
328        // standard variant -> SIGALARM (standard: abort)
329        //alarm((unsigned)h->next->Data());
330        // process time (user +system): SIGVTALARM
331        struct itimerval t,o;
332        memset(&t,0,sizeof(t));
333        t.it_value.tv_sec     =(unsigned)h->next->Data();
334        setitimer(ITIMER_VIRTUAL,&t,&o);
335        return FALSE;
336      }
337      else
338        WerrorS("int expected");
339    }
340    else
341#endif
342#endif
343#endif
344/*==================== std =============================*/
345#if 0
346#ifdef HAVE_FACTORY
347    if(strcmp((char*)(h->Data()),"std")==0)
348    {
349      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
350      {
351        res->rtyp=LIST_CMD;
352        res->data=(void *)stdfac((ideal)h->next->Data(),NULL,testHomog,NULL);
353        return FALSE;
354      }
355      else
356        WerrorS("ideal expected");
357    }
358    else
359#endif
360#endif
361/*==================== red =============================*/
362#if 0
363    if(strcmp((char*)(h->Data()),"red")==0)
364    {
365      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
366      {
367        res->rtyp=IDEAL_CMD;
368        res->data=(void *)stdred((ideal)h->next->Data(),NULL,testHomog,NULL);
369        setFlag(res,FLAG_STD);
370        return FALSE;
371      }
372      else
373        WerrorS("ideal expected");
374    }
375    else
376#endif
377/*==================== min_std =============================*/
378#if 0
379    if(strcmp((char*)(h->Data()),"min_std")==0)
380    {
381      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
382      {
383        res->rtyp=LIST_CMD;
384        res->data=(void *)min_std((ideal)h->next->Data(),currQuotient,testHomog,NULL);
385        return FALSE;
386      }
387      else
388        WerrorS("ideal expected");
389    }
390    else
391#endif
392/*==================== writemat ==================================*/
393    if(strcmp((char*)(h->Data()),"writemat")==0)
394    {
395      if (h->next!=NULL)
396      {
397        leftv v=h->next;
398        if (v->Typ() == STRING_CMD)
399        {
400          char *filename = (char *)v->Data();
401          v = v->next;
402          if (v->Typ()==MATRIX_CMD)
403          {
404            FILE *outfile = fopen(filename,"a");
405            if (outfile==NULL)
406            {
407              Werror("cannot write to file %s",filename);
408              return TRUE;
409            }
410            matrix m=(matrix)v->Data();
411            fprintf(outfile,"%d\n%d\n",MATROWS(m),MATCOLS(m));
412            char *s = iiStringMatrix(m,2);
413            fprintf(outfile,"%s\n",s);
414            FreeL((ADDRESS)s);
415            fclose(outfile);
416            return FALSE;
417          }
418          else
419          {
420            WerrorS("matrix expected");
421          }
422        }
423        else
424        {
425          WerrorS("string expected");
426        }
427      }
428      else
429        WerrorS("matrix expected");
430    }
431    else
432#ifdef HAVE_FACTORY
433/*==================== pdivide ====================*/
434    if (strcmp((char*)(h->Data()),"pdivide")==0)
435    {
436      if (h->next!=NULL && h->next->next!=NULL &&
437           h->next->Typ()==POLY_CMD && h->next->next->Typ()==POLY_CMD)
438      {
439        res->rtyp=POLY_CMD;
440        res->data=(void*)(singclap_pdivide((poly)(h->next->Data()),
441                                         (poly)(h->next->next->Data())));
442        return FALSE;
443      }
444      else
445        WerrorS("poly expected");
446    }
447    else
448#endif
449/*==================== algfetch =====================*/
450    if (strcmp((char*)(h->Data()),"algfetch")==0)
451    {
452      int k;
453      idhdl w;
454      ideal i0, i1;
455      leftv v=h->next;
456      ring r0=(ring)v->Data();
457      v = v->next;
458      w = r0->idroot->get(v->Name(),myynest);
459      i0 = IDIDEAL(w);
460      i1 = idInit(IDELEMS(i0),i0->rank);
461      for (k=0; k<IDELEMS(i1); k++)
462      {
463        i1->m[k] = maAlgpolyFetch(r0, i0->m[k]);
464      }
465      res->rtyp = IDEAL_CMD;
466      res->data = (void*)i1;
467      return FALSE;
468    }
469    else
470/*==================== algmap =======================*/
471    if (strcmp((char*)(h->Data()),"algmap")==0)
472    {
473      int k;
474      idhdl w;
475      ideal i0, i1, i, j;
476      leftv v=h->next;
477      ring r0=(ring)v->Data();
478      v = v->next;
479      w = r0->idroot->get(v->Name(),myynest);
480      i0 = IDIDEAL(w);
481      v = v->next;
482      i = (ideal)v->Data();
483      v = v->next;
484      j = (ideal)v->Data();
485      i1 = idInit(IDELEMS(i0),i0->rank);
486      for (k=0; k<IDELEMS(i1); k++)
487      {
488        i1->m[k] = maAlgpolyMap(r0, i0->m[k], i, j);
489      }
490      res->rtyp = IDEAL_CMD;
491      res->data = (void*)i1;
492      return FALSE;
493    }
494    else
495/*==================== indsetall =============================*/
496    if(strcmp((char*)(h->Data()),"indsetall")==0)
497    {
498      if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD))
499      {
500        int i=0;
501        if (h->next->next!=NULL)
502        {
503          if (h->next->next->Typ()==INT_CMD)
504            i=(int)h->next->next->Data();
505          else
506          {
507            Warn("int expected");
508          }
509        }
510        res->rtyp=LIST_CMD;
511        res->data=(void *)scIndIndset((ideal)h->next->Data(),i,currQuotient);
512        return FALSE;
513      }
514      else
515        WerrorS("ideal expected");
516    }
517    else
518/*============================================================*/
519      WerrorS("not implemented\n");
520  }
521  return TRUE;
522}
Note: See TracBrowser for help on using the repository browser.