source: git/Singular/extra.cc @ 400884

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