source: git/Singular/extra.cc @ bdbe7d

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