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

spielwiese
Last change on this file since 3bf6849 was 3bf6849, checked in by Mathias Schulze <mschulze@…>, 25 years ago
*mschulze: modified pcv git-svn-id: file:///usr/local/Singular/svn/trunk@3117 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 24.7 KB
Line 
1/*****************************************
2*  Computer Algebra System SINGULAR      *
3*****************************************/
4/* $Id: extra.cc,v 1.92 1999-06-09 11:53:42 mschulze 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 __MWERKS__
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#endif
33#include <unistd.h>
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 "sdb.h"
51
52// Define to enable many more system commands
53#define HAVE_EXTENDED_SYSTEM
54
55#ifdef STDTRACE
56//#include "comm.h"
57#endif
58
59#ifdef HAVE_FACTORY
60#define SI_DONT_HAVE_GLOBAL_VARS
61#include "clapsing.h"
62#include "clapconv.h"
63#include "kstdfac.h"
64#endif
65
66#include "silink.h"
67#ifdef HAVE_MPSR
68#include "mpsr.h"
69#include "MPT_GP.h"
70#endif
71
72/*
73 *   New function/system-calls that will be included as dynamic module
74 * should be inserted here.
75 * - without HAVE_DYNAMIC_LOADING: these functions comes as system("....");
76 * - with    HAVE_DYNAMIC_LOADING: these functions are loaded as module.
77 */
78#ifndef HAVE_DYNAMIC_LOADING
79#ifdef HAVE_PCV
80#include "pcv.h"
81#endif
82#endif /* not HAVE_DYNAMIC_LOADING */
83
84// see clapsing.cc for a description of the `FACTORY_*' options
85
86#ifdef FACTORY_GCD_STAT
87#include "gcd_stat.h"
88#endif
89
90#ifdef FACTORY_GCD_TIMING
91#define TIMING
92#include "timing.h"
93TIMING_DEFINE_PRINTPROTO( contentTimer );
94TIMING_DEFINE_PRINTPROTO( algContentTimer );
95TIMING_DEFINE_PRINTPROTO( algLcmTimer );
96#endif
97
98void piShowProcList();
99static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h);
100
101
102//void emStart();
103/*2
104*  the "system" command
105*/
106BOOLEAN jjSYSTEM(leftv res, leftv args)
107{
108  if(args->Typ() == STRING_CMD)
109  {
110    const char *sys_cmd=(char *)(args->Data());
111    leftv h=args->next;
112// ONLY documented system calls go here
113// Undocumented system calls go down into #ifdef HAVE_EXTENDED_SYSTEM
114/*==================== nblocks ==================================*/
115    if (strcmp(sys_cmd, "nblocks") == 0)
116    {
117      ring r;
118      if (h == NULL)
119      {
120        if (currRingHdl != NULL)
121        {
122          r = IDRING(currRingHdl);
123        }
124        else
125        {
126          WerrorS("no ring active");
127          return TRUE;
128        }
129      }
130      else
131      {
132        if (h->Typ() != RING_CMD)
133        {
134          WerrorS("ring expected");
135          return TRUE;
136        }
137        r = (ring) h->Data();
138      }
139      res->rtyp = INT_CMD;
140      res->data = (void*) (rBlocks(r) - 1);
141      return FALSE;
142    }
143/*==================== version ==================================*/
144    if(strcmp(sys_cmd,"version")==0)
145    {
146      res->rtyp=INT_CMD;
147      res->data=(void *)SINGULAR_VERSION;
148      return FALSE;
149    }
150    else
151/*==================== gen ==================================*/
152    if(strcmp(sys_cmd,"gen")==0)
153    {
154      res->rtyp=INT_CMD;
155      res->data=(void *)npGen;
156      return FALSE;
157    }
158    else
159/*==================== sh ==================================*/
160    if(strcmp(sys_cmd,"sh")==0)
161    {
162      res->rtyp=INT_CMD;
163      #ifndef __MWERKS__
164      if (h==NULL) res->data = (void *)system("sh");
165      else if (h->Typ()==STRING_CMD)
166        res->data = (void*) system((char*)(h->Data()));
167      else
168        WerrorS("string expected");
169      #else
170      res->data=(void *)0;
171      #endif
172      return FALSE;
173    }
174    else
175/*==================== with ==================================*/
176    if(strcmp(sys_cmd,"with")==0)
177    {
178      if (h==NULL)
179      {
180        res->rtyp=STRING_CMD;
181        res->data=(void *)mstrdup(versionString());
182        return FALSE;
183      }
184      else if (h->Typ()==STRING_CMD)
185      {
186        #define TEST_FOR(A) if(strcmp(s,A)==0) res->data=(void *)1; else
187        char *s=(char *)h->Data();
188        res->rtyp=INT_CMD;
189        #ifdef DRING
190          TEST_FOR("DRING")
191        #endif
192        #ifdef HAVE_DBM
193          TEST_FOR("DBM")
194        #endif
195        #ifdef HAVE_DLD
196          TEST_FOR("DLD")
197        #endif
198        #ifdef HAVE_FACTORY
199          TEST_FOR("factory")
200        #endif
201        #ifdef HAVE_LIBFAC_P
202          TEST_FOR("libfac")
203        #endif
204        #ifdef HAVE_MPSR
205          TEST_FOR("MP")
206        #endif
207        #ifdef HAVE_READLINE
208          TEST_FOR("readline")
209        #endif
210        #ifdef HAVE_TCL
211          TEST_FOR("tcl")
212        #endif
213        #ifdef SRING
214          TEST_FOR("SRING")
215        #endif
216        #ifdef TEST_MAC_ORDER
217          TEST_FOR("MAC_ORDER");
218        #endif
219        #ifdef HAVE_NAMESPACES
220          TEST_FOR("Namespaces");
221        #endif
222        #ifdef HAVE_DYNAMIC_LOADING
223          TEST_FOR("DynamicLoading");
224        #endif
225          ;
226        return FALSE;
227        #undef TEST_FOR
228      }
229      return TRUE;
230    }
231    else
232/*==================== pid ==================================*/
233    if (strcmp(sys_cmd,"pid")==0)
234    {
235      res->rtyp=INT_CMD;
236    #ifndef MSDOS
237    #ifndef __MWERKS__
238      res->data=(void *)getpid();
239    #else
240      res->data=(void *)1;
241    #endif
242    #else
243      res->data=(void *)1;
244    #endif
245      return FALSE;
246    }
247    else
248/*==================== getenv ==================================*/
249    if (strcmp(sys_cmd,"getenv")==0)
250    {
251      if ((h!=NULL) && (h->Typ()==STRING_CMD))
252      {
253        res->rtyp=STRING_CMD;
254        char *r=getenv((char *)h->Data());
255        if (r==NULL) r="";
256        res->data=(void *)mstrdup(r);
257        return FALSE;
258      }
259      else
260      {
261        WerrorS("string expected");
262      }
263    }
264    else
265/*==================== tty ==================================*/
266    #ifndef __MWERKS__
267    #ifndef MSDOS
268    #if defined(HAVE_FEREAD) || defined(HAVE_READLINE)
269    if (strcmp(sys_cmd,"tty")==0)
270    {
271      #if defined(HAVE_READLINE) || defined(HAVE_FEREAD)
272      system("stty sane");
273      #endif
274      if ((h!=NULL)&&(h->Typ()==INT_CMD))
275      {
276        fe_use_fgets=(int)h->Data();
277      }
278      return FALSE;
279    }
280    else
281    #endif
282    #endif
283    #endif
284/*==================== Singular ==================================*/
285#ifndef __MWERKS__
286    if (strcmp(sys_cmd, "Singular") == 0)
287    {
288      res->rtyp=STRING_CMD;
289      char *r=feGetExpandedExecutable();
290      if (r != NULL)
291        res->data = (void*) mstrdup( r );
292      else
293        res->data = (void*) mstrdup("");
294      return FALSE;
295    }
296    else
297#endif
298/*==================== options ==================================*/
299    if (strstr(sys_cmd, "--") == sys_cmd)
300    {
301      BOOLEAN mainGetSingOptionValue(const char* name, char** result);
302      char* val;
303
304      if (mainGetSingOptionValue(&(sys_cmd)[2], &val))
305      {
306        if ((unsigned int) val > 1)
307        {
308          res->rtyp=STRING_CMD;
309          res->data = (void*) mstrdup( val );
310        }
311        else
312        {
313          res->rtyp=INT_CMD;
314          res->data=(void *)val;
315        }
316        return FALSE;
317      }
318      else
319      {
320        Werror("Unknown option %s\n", sys_cmd);
321        return TRUE;
322      }
323    }
324    else
325/*==================== HC ==================================*/
326    if (strcmp(sys_cmd,"HC")==0)
327    {
328      res->rtyp=INT_CMD;
329      res->data=(void *)HCord;
330      return FALSE;
331    }
332    else
333/*==================== random ==================================*/
334    if(strcmp(sys_cmd,"random")==0)
335    {
336      if ((h!=NULL) &&(h->Typ()==INT_CMD))
337      {
338        siRandomStart=(int)h->Data();
339#ifdef buildin_rand
340        siSeed=siRandomStart;
341#else
342        srand((unsigned int)siRandomStart);
343#endif
344        return FALSE;
345      }
346      else if (h != NULL)
347      {
348        WerrorS("int expected");
349        return TRUE;
350      }
351      res->rtyp=INT_CMD;
352      res->data=(void*) siRandomStart;
353      return FALSE;
354    }
355/*==================== neworder =============================*/
356// should go below
357#ifdef HAVE_LIBFAC_P
358    if(strcmp(sys_cmd,"neworder")==0)
359    {
360      if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
361      {
362        res->rtyp=STRING_CMD;
363        res->data=(void *)singclap_neworder((ideal)h->Data());
364        return FALSE;
365      }
366      else
367        WerrorS("ideal expected");
368    }
369    else
370#endif
371/*==================== contributors =============================*/
372   if(strcmp(sys_cmd,"contributors") == 0)
373   {
374     res->rtyp=STRING_CMD;
375     res->data=(void *)mstrdup(
376       "Olaf Bachmann, Hubert Grassmann, Kai Krueger, Wolfgang Neumann, Thomas Nuessler, Wilfred Pohl, Thomas Siebert, Ruediger Stobbe, Tim Wichmann");
377     return FALSE;
378   }
379   else
380   {
381/*================= Extended system call ========================*/
382#ifdef HAVE_EXTENDED_SYSTEM
383     return(jjEXTENDED_SYSTEM(res, args));
384#else
385     Werror( "system(\"%s\",...) %s", sys_cmd, feNotImplemented );
386#endif
387   }
388  } /* typ==string */
389  return TRUE;
390}
391
392
393
394#ifdef HAVE_EXTENDED_SYSTEM
395// You can put your own system calls here
396#include "fglmcomb.cc"
397#include "fglm.h"
398#ifdef HAVE_NEWTON
399#include <hc_newton.h>
400#endif
401#include "mpsr.h"
402
403static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h)
404{
405  if(h->Typ() == STRING_CMD)
406  {
407    char *sys_cmd=(char *)(h->Data());
408    h=h->next;
409/*==================== pcv ==================================*/
410#ifndef HAVE_DYNAMIC_LOADING
411#ifdef HAVE_PCV
412    if(strcmp(sys_cmd,"pcvLAddL")==0)
413    {
414      return pcvLAddL(res,h);
415    }
416    else
417    if(strcmp(sys_cmd,"pcvPMulL")==0)
418    {
419      return pcvPMulL(res,h);
420    }
421    else
422    if(strcmp(sys_cmd,"pcvMinDeg")==0)
423    {
424      return pcvMinDeg(res,h);
425    }
426    else
427    if(strcmp(sys_cmd,"pcvP2CV")==0)
428    {
429      return pcvP2CV(res,h);
430    }
431    else
432    if(strcmp(sys_cmd,"pcvCV2P")==0)
433    {
434      return pcvCV2P(res,h);
435    }
436    else
437    if(strcmp(sys_cmd,"pcvDim")==0)
438    {
439      return pcvDim(res,h);
440    }
441    else
442    if(strcmp(sys_cmd,"pcvBasis")==0)
443    {
444      return pcvBasis(res,h);
445    }
446    else
447#endif
448#endif /* HAVE_DYNAMIC_LOADING */
449/*==================== naIdeal ==================================*/
450    if(strcmp(sys_cmd,"naIdeal")==0)
451    {
452      if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
453      {
454        naSetIdeal((ideal)h->Data());
455        return FALSE;
456      }
457      else
458         WerrorS("ideal expected");
459    }
460    else
461/*==================== isSqrFree =============================*/
462#ifdef HAVE_FACTORY
463    if(strcmp(sys_cmd,"isSqrFree")==0)
464    {
465      if ((h!=NULL) &&(h->Typ()==POLY_CMD))
466      {
467        res->rtyp=INT_CMD;
468        res->data=(void *)singclap_isSqrFree((poly)h->Data());
469        return FALSE;
470      }
471      else
472        WerrorS("poly expected");
473    }
474    else
475#endif
476/*==================== alarm ==================================*/
477#ifndef __MWERKS__
478#ifndef MSDOS
479#ifndef atarist
480#ifdef unix
481    if(strcmp(sys_cmd,"alarm")==0)
482    {
483      if ((h!=NULL) &&(h->Typ()==INT_CMD))
484      {
485        // standard variant -> SIGALARM (standard: abort)
486        //alarm((unsigned)h->next->Data());
487        // process time (user +system): SIGVTALARM
488        struct itimerval t,o;
489        memset(&t,0,sizeof(t));
490        t.it_value.tv_sec     =(unsigned)h->Data();
491        setitimer(ITIMER_VIRTUAL,&t,&o);
492        return FALSE;
493      }
494      else
495        WerrorS("int expected");
496    }
497    else
498#endif
499#endif
500#endif
501#endif
502/*==================== red =============================*/
503#if 0
504    if(strcmp(sys_cmd,"red")==0)
505    {
506      if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
507      {
508        res->rtyp=IDEAL_CMD;
509        res->data=(void *)kStdred((ideal)h->Data(),NULL,testHomog,NULL);
510        setFlag(res,FLAG_STD);
511        return FALSE;
512      }
513      else
514        WerrorS("ideal expected");
515    }
516    else
517#endif
518/*==================== algfetch =====================*/
519    if (strcmp(sys_cmd,"algfetch")==0)
520    {
521      int k;
522      idhdl w;
523      ideal i0, i1;
524      ring r0=(ring)h->Data();
525      leftv v = h->next;
526      w = r0->idroot->get(v->Name(),myynest);
527      i0 = IDIDEAL(w);
528      i1 = idInit(IDELEMS(i0),i0->rank);
529      for (k=0; k<IDELEMS(i1); k++)
530      {
531        i1->m[k] = maAlgpolyFetch(r0, i0->m[k]);
532      }
533      res->rtyp = IDEAL_CMD;
534      res->data = (void*)i1;
535      return FALSE;
536    }
537    else
538/*==================== algmap =======================*/
539    if (strcmp(sys_cmd,"algmap")==0)
540    {
541      int k;
542      idhdl w;
543      ideal i0, i1, i, j;
544      ring r0=(ring)h->Data();
545      leftv v = h->next;
546      w = r0->idroot->get(v->Name(),myynest);
547      i0 = IDIDEAL(w);
548      v = v->next;
549      i = (ideal)v->Data();
550      v = v->next;
551      j = (ideal)v->Data();
552      i1 = idInit(IDELEMS(i0),i0->rank);
553      for (k=0; k<IDELEMS(i1); k++)
554      {
555        i1->m[k] = maAlgpolyMap(r0, i0->m[k], i, j);
556      }
557      res->rtyp = IDEAL_CMD;
558      res->data = (void*)i1;
559      return FALSE;
560    }
561    else
562    /*==================== trace =============================*/
563#ifdef STDTRACE
564    /* Parameter : Ideal, Liste mit Links. */
565    if(strcmp(sys_cmd,"stdtrace")==0)
566    {
567      if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
568      {
569        leftv root  = NULL,
570              ptr   = NULL,
571              lv    = NULL;
572        lists l     = NULL;
573        ideal I     = (ideal)(h->Data());
574        lists links = (lists)(h->next->Data());
575        tHomog hom  = testHomog;
576        int rw      = (int)(h->next->next->Data());
577
578        if(I==NULL)
579          PrintS("I==NULL\n");
580        for(int i=0; i <= links->nr ; i++)
581        {
582          lv = (leftv)Alloc0(sizeof(sleftv));
583          lv->Copy(&(links->m[i]));
584          if(root==NULL)
585          root=lv;
586          if(ptr==NULL)
587          {
588            ptr=lv;
589            ptr->next=NULL;
590          }
591          else
592          {
593            ptr->next=lv;
594            ptr=lv;
595          }
596        }
597        ptr->next=NULL;
598        l=TraceStd(root,rw,I,currQuotient,testHomog,NULL);
599        idSkipZeroes(((ideal)l->m[0].Data()));
600        res->rtyp=LIST_CMD;
601        res->data=(void *) l;
602        res->next=NULL;
603        root->CleanUp();
604        Free(root,sizeof(sleftv));
605        return FALSE;
606      }
607      else
608         WerrorS("ideal expected");
609    }
610    else
611#endif
612#ifdef HAVE_FACTORY
613/*==================== fastcomb =============================*/
614    if(strcmp(sys_cmd,"fastcomb")==0)
615    {
616      if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
617      {
618        int i=0;
619        if (h->next!=NULL)
620        {
621          if (h->next->Typ()!=POLY_CMD)
622          {
623            Warn("Wrong types for poly= comb(ideal,poly)");
624          }
625        }
626        res->rtyp=POLY_CMD;
627        res->data=(void *) fglmLinearCombination(
628                           (ideal)h->Data(),(poly)h->next->Data());
629        return FALSE;
630      }
631      else
632        WerrorS("ideal expected");
633    }
634    else
635/*==================== comb =============================*/
636    if(strcmp(sys_cmd,"comb")==0)
637    {
638      if ((h!=NULL) &&(h->Typ()==IDEAL_CMD))
639      {
640        int i=0;
641        if (h->next!=NULL)
642        {
643          if (h->next->Typ()!=POLY_CMD)
644          {
645              Warn("Wrong types for poly= comb(ideal,poly)");
646          }
647        }
648        res->rtyp=POLY_CMD;
649        res->data=(void *)fglmNewLinearCombination(
650                            (ideal)h->Data(),(poly)h->next->Data());
651        return FALSE;
652      }
653      else
654        WerrorS("ideal expected");
655    }
656    else
657#endif
658/*==================== barstep =============================*/
659    if(strcmp(sys_cmd,"barstep")==0)
660    {
661      if ((h!=NULL) &&(h->Typ()==MATRIX_CMD))
662      {
663        if (h->next!=NULL)
664        {
665          if (h->next->Typ()!=POLY_CMD)
666          {
667            Warn("Wrong types for barstep(matrix,poly)");
668          }
669        }
670        int r,c;
671        poly div=(poly)h->next->Data();
672        res->rtyp=MATRIX_CMD;
673        res->data=(void *)mpOneStepBareiss((matrix)h->Data(),
674                                           &div,&r,&c);
675        PrintS("div: ");pWrite(div);
676        Print("rows: %d, cols: %d\n",r,c);
677        pDelete(&div);
678        return FALSE;
679      }
680      else
681        WerrorS("matrix expected");
682    }
683    else
684#ifdef FACTORY_GCD_TEST
685/*=======================gcd Testerei ================================*/
686    if ( ! strcmp( sys_cmd, "setgcd" ) ) {
687        if ( (h != NULL) && (h->Typ() == INT_CMD) ) {
688            CFPrimitiveGcdUtil::setAlgorithm( (int)h->Data() );
689            return FALSE;
690        } else
691            WerrorS("int expected");
692    }
693    else
694#endif
695
696#ifdef FACTORY_GCD_TIMING
697    if ( ! strcmp( sys_cmd, "gcdtime" ) ) {
698        TIMING_PRINT( contentTimer, "time used for content: " );
699        TIMING_PRINT( algContentTimer, "time used for algContent: " );
700        TIMING_PRINT( algLcmTimer, "time used for algLcm: " );
701        TIMING_RESET( contentTimer );
702        TIMING_RESET( algContentTimer );
703        TIMING_RESET( algLcmTimer );
704        return FALSE;
705    }
706    else
707#endif
708
709#ifdef FACTORY_GCD_STAT
710    if ( ! strcmp( sys_cmd, "gcdstat" ) ) {
711        printGcdTotal();
712        printContTotal();
713        resetGcdTotal();
714        resetContTotal();
715        return FALSE;
716    }
717    else
718#endif
719/*==================== lib ==================================*/
720    if(strcmp(sys_cmd,"LIB")==0)
721    {
722#ifdef HAVE_NAMESPACES
723      idhdl hh=namespaceroot->get((char*)h->Data(),0);
724#else /* HAVE_NAMESPACES */
725      idhdl hh=idroot->get((char*)h->Data(),0);
726#endif /* HAVE_NAMESPACES */
727      if ((hh!=NULL)&&(IDTYP(hh)==PROC_CMD))
728      {
729        res->rtyp=STRING_CMD;
730        char *r=iiGetLibName(IDPROC(hh));
731        if (r==NULL) r="";
732        res->data=mstrdup(r);
733        return FALSE;
734      }
735      else
736        Warn("`%s` not found",(char*)h->Data());
737    }
738    else
739#ifdef HAVE_NAMESPACES
740/*==================== nspush ===================================*/
741    if(strcmp(sys_cmd,"nspush")==0)
742    {
743      if (h->Typ()==PACKAGE_CMD)
744      {
745        idhdl hh=(idhdl)h->data;
746        namespaceroot = namespaceroot->push(IDPACKAGE(hh), IDID(hh));
747        return FALSE;
748      }
749      else
750        Warn("argument 2 is not a package");
751    }
752    else
753/*==================== nspop ====================================*/
754    if(strcmp(sys_cmd,"nspop")==0)
755    {
756      namespaceroot->pop();
757      return FALSE;
758    }
759    else
760#endif /* HAVE_NAMESPACES */
761/*==================== nsstack ===================================*/
762    if(strcmp(sys_cmd,"nsstack")==0)
763    {
764      namehdl nshdl = namespaceroot;
765      for( ; nshdl->isroot != TRUE; nshdl = nshdl->next) {
766        Print("NSstack: %s:%d, nesting=%d\n", nshdl->name, nshdl->lev, nshdl->myynest);
767      }
768      Print("NSstack: %s:%d, nesting=%d\n", nshdl->name, nshdl->lev, nshdl->myynest);
769      return FALSE;
770    }
771    else
772/*==================== proclist =================================*/
773    if(strcmp(sys_cmd,"proclist")==0)
774    {
775      piShowProcList();
776      return FALSE;
777    }
778    else
779/* ==================== newton ================================*/
780#ifdef HAVE_NEWTON
781    if(strcmp(sys_cmd,"newton")==0)
782    {
783      if ((h->Typ()!=POLY_CMD)
784      || (h->next->Typ()!=INT_CMD)
785      || (h->next->next->Typ()!=INT_CMD))
786      {
787        WerrorS("system(\"newton\",<poly>,<int>,<int>) expected");
788        return TRUE;
789      }
790      poly  p=(poly)(h->Data());
791      int l=pLength(p);
792      short *points=(short *)Alloc(currRing->N*l*sizeof(short));
793      int i,j,k;
794      k=0;
795      poly pp=p;
796      for (i=0;pp!=NULL;i++)
797      {
798        for(j=1;j<=currRing->N;j++)
799        {
800          points[k]=pGetExp(pp,j);
801          k++;
802        }
803        pIter(pp);
804      }
805      hc_ERG r=hc_KOENIG(currRing->N,      // dimension
806                l,      // number of points
807                (short*) points,   // points: x_1, y_1,z_1, x_2,y_2,z2,...
808                currRing->OrdSgn==-1,
809                (int) (h->next->Data()),      // 1: Milnor, 0: Newton
810                (int) (h->next->next->Data()) // debug
811               );
812      //----<>---Output-----------------------
813
814
815//  PrintS("Bin jetzt in extra.cc bei der Auswertung.\n"); // **********
816
817
818      lists L=(lists)Alloc(sizeof(slists));
819      L->Init(6);
820      L->m[0].rtyp=STRING_CMD;               // newtonnumber;
821      L->m[0].data=(void *)mstrdup(r.nZahl);
822      L->m[1].rtyp=INT_CMD;
823      L->m[1].data=(void *)r.achse;          // flag for unoccupied axes
824      L->m[2].rtyp=INT_CMD;
825      L->m[2].data=(void *)r.deg;            // #degenerations
826      if ( r.deg != 0)              // only if degenerations exist
827      {
828        L->m[3].rtyp=INT_CMD;
829        L->m[3].data=(void *)r.anz_punkte;     // #points
830        //---<>--number of points------
831        int anz = r.anz_punkte;    // number of points
832        int dim = (currRing->N);     // dimension
833        intvec* v = new intvec( anz*dim );
834        for (i=0; i<anz*dim; i++)    // copy points
835          (*v)[i] = r.pu[i];
836        L->m[4].rtyp=INTVEC_CMD;
837        L->m[4].data=(void *)v;
838        //---<>--degenerations---------
839        int deg = r.deg;    // number of points
840        intvec* w = new intvec( r.speicher );  // necessary memeory
841        i=0;               // start copying
842        do
843        {
844          (*w)[i] = r.deg_tab[i];
845          i++;
846        }
847        while (r.deg_tab[i-1] != -2);   // mark for end of list
848        L->m[5].rtyp=INTVEC_CMD;
849        L->m[5].data=(void *)w;
850      }
851      else
852      {
853        L->m[3].rtyp=INT_CMD; L->m[3].data=(char *)0;
854        L->m[4].rtyp=DEF_CMD;
855        L->m[5].rtyp=DEF_CMD;
856      }
857
858      res->data=(void *)L;
859      res->rtyp=LIST_CMD;
860      // free all pointer in r:
861      delete[] r.nZahl;
862      delete[] r.pu;
863      delete[] r.deg_tab;      // Ist das ein Problem??
864
865      Free((ADDRESS)points,currRing->N*l*sizeof(short));
866      return FALSE;
867    }
868    else
869#endif
870/*==================== gp =================*/
871#ifdef HAVE_MPSR
872     if (strcmp(sys_cmd, "gp") == 0)
873    {
874      if (h->Typ() != LINK_CMD)
875      {
876        WerrorS("No Link arg");
877        return FALSE;
878      }
879      si_link l = (si_link) h->Data();
880      if (strcmp(l->m->type, "MPfile") != 0)
881      {
882        WerrorS("No MPfile link");
883        return TRUE;
884      }
885      if( ! SI_LINK_R_OPEN_P(l)) // open r ?
886      {
887        if (slOpen(l, SI_LINK_READ)) return TRUE;
888      }
889
890      MP_Link_pt link = (MP_Link_pt) l->data;
891      if (MP_InitMsg(link) != MP_Success)
892      {
893        WerrorS("Can not Init");
894      }
895      MPT_Tree_pt tree = NULL;
896      if (MPT_GetTree(link, &tree) != MPT_Success)
897      {
898        WerrorS("Can not get tree");
899        return TRUE;
900      }
901      MPT_GP_pt gp_tree = MPT_GetGP(tree);
902      if (gp_tree == NULL || ! gp_tree->IsOk(gp_tree))
903      {
904        WerrorS("gp error");
905        return TRUE;
906      }
907      delete gp_tree;
908      MPT_DeleteTree(tree);
909      return FALSE;
910    }
911    else
912#endif
913/*==================== sdb-debugger =================*/
914    if (strcmp(sys_cmd, "breakpoint") == 0)
915    {
916      if ((h!=NULL) && (h->Typ()==PROC_CMD))
917      {
918        procinfov p=(procinfov)h->Data();
919        if (p->language!=LANG_SINGULAR)
920        {
921          WerrorS("set breakpoints only in Singular procedures");
922          return TRUE;
923        }
924        int lineno=p->data.s.body_lineno;
925        if ((h->next!=NULL) && (h->next->Typ()==INT_CMD))
926        {
927          lineno=(int)h->next->Data();
928        }
929        int i;
930        if (lineno== -1)
931        {
932          i=p->trace_flag;
933          p->trace_flag &=1;
934          Print("breakpoints in %s deleted(%#x)\n",p->procname,i &255);
935          return FALSE;
936        }
937        i=0;
938        while((i<7) && (sdb_lines[i]!=-1)) i++;
939        if (sdb_lines[i]!= -1)
940        {
941          PrintS("too many breakpoints set, max is 7\n");
942          return FALSE;
943        }
944        else
945        {
946          sdb_lines[i]=lineno;
947          sdb_files[i]=p->libname;
948          i++;
949          Print("breakpoint %d, at line %d in %s\n",i,lineno,p->procname);
950          p->trace_flag|=(1<<i);
951        }
952      }
953      else
954      {
955        WerrorS("system(\"breakpoint\",`proc`,`int`) expected");
956        return TRUE;
957      }
958      return FALSE;
959    }
960    else
961/*==================== sdb_flags =================*/
962    if (strcmp(sys_cmd, "sdb_flags") == 0)
963    {
964      if ((h!=NULL) && (h->Typ()==INT_CMD))
965      {
966        sdb_flags=(int)h->Data();
967      }
968      else
969      {
970        WerrorS("system(\"sdb_flags\",`int`) expected");
971        return TRUE;
972      }
973      return FALSE;
974    }
975    else
976/*==================== sdb_edit =================*/
977    if (strcmp(sys_cmd, "sdb_edit") == 0)
978    {
979      if ((h!=NULL) && (h->Typ()==PROC_CMD))
980      {
981        procinfov p=(procinfov)h->Data();
982        sdb_edit(p);
983      }
984      else
985      {
986        WerrorS("system(\"sdb_edit\",`proc`) expected");
987        return TRUE;
988      }
989      return FALSE;
990    }
991    else
992/*==================== print all option values =================*/
993#ifndef NDEBUG
994    if (strcmp(sys_cmd, "options") == 0)
995    {
996      void mainOptionValues();
997      mainOptionValues();
998      return FALSE;
999    }
1000    else
1001#endif
1002/*============================================================*/
1003      Werror( "system(\"%s\",...) %s", sys_cmd, feNotImplemented );
1004  }
1005  return TRUE;
1006}
1007#endif // HAVE_EXTENDED_SYSTEM
Note: See TracBrowser for help on using the repository browser.