1 | /***************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | *****************************************/ |
---|
4 | /* $Id: extra.cc,v 1.95 1999-07-08 10:18:07 wenk 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" |
---|
93 | TIMING_DEFINE_PRINTPROTO( contentTimer ); |
---|
94 | TIMING_DEFINE_PRINTPROTO( algContentTimer ); |
---|
95 | TIMING_DEFINE_PRINTPROTO( algLcmTimer ); |
---|
96 | #endif |
---|
97 | |
---|
98 | void piShowProcList(); |
---|
99 | static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h); |
---|
100 | |
---|
101 | |
---|
102 | //void emStart(); |
---|
103 | /*2 |
---|
104 | * the "system" command |
---|
105 | */ |
---|
106 | BOOLEAN 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 | |
---|
403 | #include "mpr_complex.h" |
---|
404 | |
---|
405 | static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h) |
---|
406 | { |
---|
407 | if(h->Typ() == STRING_CMD) |
---|
408 | { |
---|
409 | char *sys_cmd=(char *)(h->Data()); |
---|
410 | h=h->next; |
---|
411 | /*==================== pcv ==================================*/ |
---|
412 | #ifndef HAVE_DYNAMIC_LOADING |
---|
413 | #ifdef HAVE_PCV |
---|
414 | if(strcmp(sys_cmd,"pcvLAddL")==0) |
---|
415 | { |
---|
416 | return pcvLAddL(res,h); |
---|
417 | } |
---|
418 | else |
---|
419 | if(strcmp(sys_cmd,"pcvPMulL")==0) |
---|
420 | { |
---|
421 | return pcvPMulL(res,h); |
---|
422 | } |
---|
423 | else |
---|
424 | if(strcmp(sys_cmd,"pcvMinDeg")==0) |
---|
425 | { |
---|
426 | return pcvMinDeg(res,h); |
---|
427 | } |
---|
428 | else |
---|
429 | if(strcmp(sys_cmd,"pcvP2CV")==0) |
---|
430 | { |
---|
431 | return pcvP2CV(res,h); |
---|
432 | } |
---|
433 | else |
---|
434 | if(strcmp(sys_cmd,"pcvCV2P")==0) |
---|
435 | { |
---|
436 | return pcvCV2P(res,h); |
---|
437 | } |
---|
438 | else |
---|
439 | if(strcmp(sys_cmd,"pcvDim")==0) |
---|
440 | { |
---|
441 | return pcvDim(res,h); |
---|
442 | } |
---|
443 | else |
---|
444 | if(strcmp(sys_cmd,"pcvBasis")==0) |
---|
445 | { |
---|
446 | return pcvBasis(res,h); |
---|
447 | } |
---|
448 | else |
---|
449 | #endif |
---|
450 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
451 | /*==================== naIdeal ==================================*/ |
---|
452 | if(strcmp(sys_cmd,"naIdeal")==0) |
---|
453 | { |
---|
454 | if ((h!=NULL) &&(h->Typ()==IDEAL_CMD)) |
---|
455 | { |
---|
456 | naSetIdeal((ideal)h->Data()); |
---|
457 | return FALSE; |
---|
458 | } |
---|
459 | else |
---|
460 | WerrorS("ideal expected"); |
---|
461 | } |
---|
462 | else |
---|
463 | /*==================== isSqrFree =============================*/ |
---|
464 | #ifdef HAVE_FACTORY |
---|
465 | if(strcmp(sys_cmd,"isSqrFree")==0) |
---|
466 | { |
---|
467 | if ((h!=NULL) &&(h->Typ()==POLY_CMD)) |
---|
468 | { |
---|
469 | res->rtyp=INT_CMD; |
---|
470 | res->data=(void *)singclap_isSqrFree((poly)h->Data()); |
---|
471 | return FALSE; |
---|
472 | } |
---|
473 | else |
---|
474 | WerrorS("poly expected"); |
---|
475 | } |
---|
476 | else |
---|
477 | #endif |
---|
478 | /*==================== alarm ==================================*/ |
---|
479 | #ifndef __MWERKS__ |
---|
480 | #ifndef MSDOS |
---|
481 | #ifndef atarist |
---|
482 | #ifdef unix |
---|
483 | if(strcmp(sys_cmd,"alarm")==0) |
---|
484 | { |
---|
485 | if ((h!=NULL) &&(h->Typ()==INT_CMD)) |
---|
486 | { |
---|
487 | // standard variant -> SIGALARM (standard: abort) |
---|
488 | //alarm((unsigned)h->next->Data()); |
---|
489 | // process time (user +system): SIGVTALARM |
---|
490 | struct itimerval t,o; |
---|
491 | memset(&t,0,sizeof(t)); |
---|
492 | t.it_value.tv_sec =(unsigned)h->Data(); |
---|
493 | setitimer(ITIMER_VIRTUAL,&t,&o); |
---|
494 | return FALSE; |
---|
495 | } |
---|
496 | else |
---|
497 | WerrorS("int expected"); |
---|
498 | } |
---|
499 | else |
---|
500 | #endif |
---|
501 | #endif |
---|
502 | #endif |
---|
503 | #endif |
---|
504 | /*==================== red =============================*/ |
---|
505 | #if 0 |
---|
506 | if(strcmp(sys_cmd,"red")==0) |
---|
507 | { |
---|
508 | if ((h!=NULL) &&(h->Typ()==IDEAL_CMD)) |
---|
509 | { |
---|
510 | res->rtyp=IDEAL_CMD; |
---|
511 | res->data=(void *)kStdred((ideal)h->Data(),NULL,testHomog,NULL); |
---|
512 | setFlag(res,FLAG_STD); |
---|
513 | return FALSE; |
---|
514 | } |
---|
515 | else |
---|
516 | WerrorS("ideal expected"); |
---|
517 | } |
---|
518 | else |
---|
519 | #endif |
---|
520 | /*==================== algfetch =====================*/ |
---|
521 | if (strcmp(sys_cmd,"algfetch")==0) |
---|
522 | { |
---|
523 | int k; |
---|
524 | idhdl w; |
---|
525 | ideal i0, i1; |
---|
526 | ring r0=(ring)h->Data(); |
---|
527 | leftv v = h->next; |
---|
528 | w = r0->idroot->get(v->Name(),myynest); |
---|
529 | i0 = IDIDEAL(w); |
---|
530 | i1 = idInit(IDELEMS(i0),i0->rank); |
---|
531 | for (k=0; k<IDELEMS(i1); k++) |
---|
532 | { |
---|
533 | i1->m[k] = maAlgpolyFetch(r0, i0->m[k]); |
---|
534 | } |
---|
535 | res->rtyp = IDEAL_CMD; |
---|
536 | res->data = (void*)i1; |
---|
537 | return FALSE; |
---|
538 | } |
---|
539 | else |
---|
540 | /*==================== algmap =======================*/ |
---|
541 | if (strcmp(sys_cmd,"algmap")==0) |
---|
542 | { |
---|
543 | int k; |
---|
544 | idhdl w; |
---|
545 | ideal i0, i1, i, j; |
---|
546 | ring r0=(ring)h->Data(); |
---|
547 | leftv v = h->next; |
---|
548 | w = r0->idroot->get(v->Name(),myynest); |
---|
549 | i0 = IDIDEAL(w); |
---|
550 | v = v->next; |
---|
551 | i = (ideal)v->Data(); |
---|
552 | v = v->next; |
---|
553 | j = (ideal)v->Data(); |
---|
554 | i1 = idInit(IDELEMS(i0),i0->rank); |
---|
555 | for (k=0; k<IDELEMS(i1); k++) |
---|
556 | { |
---|
557 | i1->m[k] = maAlgpolyMap(r0, i0->m[k], i, j); |
---|
558 | } |
---|
559 | res->rtyp = IDEAL_CMD; |
---|
560 | res->data = (void*)i1; |
---|
561 | return FALSE; |
---|
562 | } |
---|
563 | else |
---|
564 | /*==================== trace =============================*/ |
---|
565 | #ifdef STDTRACE |
---|
566 | /* Parameter : Ideal, Liste mit Links. */ |
---|
567 | if(strcmp(sys_cmd,"stdtrace")==0) |
---|
568 | { |
---|
569 | if ((h!=NULL) &&(h->Typ()==IDEAL_CMD)) |
---|
570 | { |
---|
571 | leftv root = NULL, |
---|
572 | ptr = NULL, |
---|
573 | lv = NULL; |
---|
574 | lists l = NULL; |
---|
575 | ideal I = (ideal)(h->Data()); |
---|
576 | lists links = (lists)(h->next->Data()); |
---|
577 | tHomog hom = testHomog; |
---|
578 | int rw = (int)(h->next->next->Data()); |
---|
579 | |
---|
580 | if(I==NULL) |
---|
581 | PrintS("I==NULL\n"); |
---|
582 | for(int i=0; i <= links->nr ; i++) |
---|
583 | { |
---|
584 | lv = (leftv)Alloc0(sizeof(sleftv)); |
---|
585 | lv->Copy(&(links->m[i])); |
---|
586 | if(root==NULL) |
---|
587 | root=lv; |
---|
588 | if(ptr==NULL) |
---|
589 | { |
---|
590 | ptr=lv; |
---|
591 | ptr->next=NULL; |
---|
592 | } |
---|
593 | else |
---|
594 | { |
---|
595 | ptr->next=lv; |
---|
596 | ptr=lv; |
---|
597 | } |
---|
598 | } |
---|
599 | ptr->next=NULL; |
---|
600 | l=TraceStd(root,rw,I,currQuotient,testHomog,NULL); |
---|
601 | idSkipZeroes(((ideal)l->m[0].Data())); |
---|
602 | res->rtyp=LIST_CMD; |
---|
603 | res->data=(void *) l; |
---|
604 | res->next=NULL; |
---|
605 | root->CleanUp(); |
---|
606 | Free(root,sizeof(sleftv)); |
---|
607 | return FALSE; |
---|
608 | } |
---|
609 | else |
---|
610 | WerrorS("ideal expected"); |
---|
611 | } |
---|
612 | else |
---|
613 | #endif |
---|
614 | #ifdef HAVE_FACTORY |
---|
615 | /*==================== fastcomb =============================*/ |
---|
616 | if(strcmp(sys_cmd,"fastcomb")==0) |
---|
617 | { |
---|
618 | if ((h!=NULL) &&(h->Typ()==IDEAL_CMD)) |
---|
619 | { |
---|
620 | int i=0; |
---|
621 | if (h->next!=NULL) |
---|
622 | { |
---|
623 | if (h->next->Typ()!=POLY_CMD) |
---|
624 | { |
---|
625 | Warn("Wrong types for poly= comb(ideal,poly)"); |
---|
626 | } |
---|
627 | } |
---|
628 | res->rtyp=POLY_CMD; |
---|
629 | res->data=(void *) fglmLinearCombination( |
---|
630 | (ideal)h->Data(),(poly)h->next->Data()); |
---|
631 | return FALSE; |
---|
632 | } |
---|
633 | else |
---|
634 | WerrorS("ideal expected"); |
---|
635 | } |
---|
636 | else |
---|
637 | /*==================== comb =============================*/ |
---|
638 | if(strcmp(sys_cmd,"comb")==0) |
---|
639 | { |
---|
640 | if ((h!=NULL) &&(h->Typ()==IDEAL_CMD)) |
---|
641 | { |
---|
642 | int i=0; |
---|
643 | if (h->next!=NULL) |
---|
644 | { |
---|
645 | if (h->next->Typ()!=POLY_CMD) |
---|
646 | { |
---|
647 | Warn("Wrong types for poly= comb(ideal,poly)"); |
---|
648 | } |
---|
649 | } |
---|
650 | res->rtyp=POLY_CMD; |
---|
651 | res->data=(void *)fglmNewLinearCombination( |
---|
652 | (ideal)h->Data(),(poly)h->next->Data()); |
---|
653 | return FALSE; |
---|
654 | } |
---|
655 | else |
---|
656 | WerrorS("ideal expected"); |
---|
657 | } |
---|
658 | else |
---|
659 | #endif |
---|
660 | /*==================== barstep =============================*/ |
---|
661 | if(strcmp(sys_cmd,"barstep")==0) |
---|
662 | { |
---|
663 | if ((h!=NULL) &&(h->Typ()==MATRIX_CMD)) |
---|
664 | { |
---|
665 | if (h->next!=NULL) |
---|
666 | { |
---|
667 | if (h->next->Typ()!=POLY_CMD) |
---|
668 | { |
---|
669 | Warn("Wrong types for barstep(matrix,poly)"); |
---|
670 | } |
---|
671 | } |
---|
672 | int r,c; |
---|
673 | poly div=(poly)h->next->Data(); |
---|
674 | res->rtyp=MATRIX_CMD; |
---|
675 | res->data=(void *)mpOneStepBareiss((matrix)h->Data(), |
---|
676 | &div,&r,&c); |
---|
677 | PrintS("div: ");pWrite(div); |
---|
678 | Print("rows: %d, cols: %d\n",r,c); |
---|
679 | pDelete(&div); |
---|
680 | return FALSE; |
---|
681 | } |
---|
682 | else |
---|
683 | WerrorS("matrix expected"); |
---|
684 | } |
---|
685 | else |
---|
686 | #ifdef FACTORY_GCD_TEST |
---|
687 | /*=======================gcd Testerei ================================*/ |
---|
688 | if ( ! strcmp( sys_cmd, "setgcd" ) ) { |
---|
689 | if ( (h != NULL) && (h->Typ() == INT_CMD) ) { |
---|
690 | CFPrimitiveGcdUtil::setAlgorithm( (int)h->Data() ); |
---|
691 | return FALSE; |
---|
692 | } else |
---|
693 | WerrorS("int expected"); |
---|
694 | } |
---|
695 | else |
---|
696 | #endif |
---|
697 | |
---|
698 | #ifdef FACTORY_GCD_TIMING |
---|
699 | if ( ! strcmp( sys_cmd, "gcdtime" ) ) { |
---|
700 | TIMING_PRINT( contentTimer, "time used for content: " ); |
---|
701 | TIMING_PRINT( algContentTimer, "time used for algContent: " ); |
---|
702 | TIMING_PRINT( algLcmTimer, "time used for algLcm: " ); |
---|
703 | TIMING_RESET( contentTimer ); |
---|
704 | TIMING_RESET( algContentTimer ); |
---|
705 | TIMING_RESET( algLcmTimer ); |
---|
706 | return FALSE; |
---|
707 | } |
---|
708 | else |
---|
709 | #endif |
---|
710 | |
---|
711 | #ifdef FACTORY_GCD_STAT |
---|
712 | if ( ! strcmp( sys_cmd, "gcdstat" ) ) { |
---|
713 | printGcdTotal(); |
---|
714 | printContTotal(); |
---|
715 | resetGcdTotal(); |
---|
716 | resetContTotal(); |
---|
717 | return FALSE; |
---|
718 | } |
---|
719 | else |
---|
720 | #endif |
---|
721 | /*==================== lib ==================================*/ |
---|
722 | if(strcmp(sys_cmd,"LIB")==0) |
---|
723 | { |
---|
724 | #ifdef HAVE_NAMESPACES |
---|
725 | idhdl hh=namespaceroot->get((char*)h->Data(),0); |
---|
726 | #else /* HAVE_NAMESPACES */ |
---|
727 | idhdl hh=idroot->get((char*)h->Data(),0); |
---|
728 | #endif /* HAVE_NAMESPACES */ |
---|
729 | if ((hh!=NULL)&&(IDTYP(hh)==PROC_CMD)) |
---|
730 | { |
---|
731 | res->rtyp=STRING_CMD; |
---|
732 | char *r=iiGetLibName(IDPROC(hh)); |
---|
733 | if (r==NULL) r=""; |
---|
734 | res->data=mstrdup(r); |
---|
735 | return FALSE; |
---|
736 | } |
---|
737 | else |
---|
738 | Warn("`%s` not found",(char*)h->Data()); |
---|
739 | } |
---|
740 | else |
---|
741 | #ifdef HAVE_NAMESPACES |
---|
742 | /*==================== nspush ===================================*/ |
---|
743 | if(strcmp(sys_cmd,"nspush")==0) |
---|
744 | { |
---|
745 | if (h->Typ()==PACKAGE_CMD) |
---|
746 | { |
---|
747 | idhdl hh=(idhdl)h->data; |
---|
748 | namespaceroot = namespaceroot->push(IDPACKAGE(hh), IDID(hh)); |
---|
749 | return FALSE; |
---|
750 | } |
---|
751 | else |
---|
752 | Warn("argument 2 is not a package"); |
---|
753 | } |
---|
754 | else |
---|
755 | /*==================== nspop ====================================*/ |
---|
756 | if(strcmp(sys_cmd,"nspop")==0) |
---|
757 | { |
---|
758 | namespaceroot->pop(); |
---|
759 | return FALSE; |
---|
760 | } |
---|
761 | else |
---|
762 | #endif /* HAVE_NAMESPACES */ |
---|
763 | /*==================== nsstack ===================================*/ |
---|
764 | if(strcmp(sys_cmd,"nsstack")==0) |
---|
765 | { |
---|
766 | namehdl nshdl = namespaceroot; |
---|
767 | for( ; nshdl->isroot != TRUE; nshdl = nshdl->next) { |
---|
768 | Print("NSstack: %s:%d, nesting=%d\n", nshdl->name, nshdl->lev, nshdl->myynest); |
---|
769 | } |
---|
770 | Print("NSstack: %s:%d, nesting=%d\n", nshdl->name, nshdl->lev, nshdl->myynest); |
---|
771 | return FALSE; |
---|
772 | } |
---|
773 | else |
---|
774 | /*==================== proclist =================================*/ |
---|
775 | if(strcmp(sys_cmd,"proclist")==0) |
---|
776 | { |
---|
777 | piShowProcList(); |
---|
778 | return FALSE; |
---|
779 | } |
---|
780 | else |
---|
781 | /* ==================== newton ================================*/ |
---|
782 | #ifdef HAVE_NEWTON |
---|
783 | if(strcmp(sys_cmd,"newton")==0) |
---|
784 | { |
---|
785 | if ((h->Typ()!=POLY_CMD) |
---|
786 | || (h->next->Typ()!=INT_CMD) |
---|
787 | || (h->next->next->Typ()!=INT_CMD)) |
---|
788 | { |
---|
789 | WerrorS("system(\"newton\",<poly>,<int>,<int>) expected"); |
---|
790 | return TRUE; |
---|
791 | } |
---|
792 | poly p=(poly)(h->Data()); |
---|
793 | int l=pLength(p); |
---|
794 | short *points=(short *)Alloc(currRing->N*l*sizeof(short)); |
---|
795 | int i,j,k; |
---|
796 | k=0; |
---|
797 | poly pp=p; |
---|
798 | for (i=0;pp!=NULL;i++) |
---|
799 | { |
---|
800 | for(j=1;j<=currRing->N;j++) |
---|
801 | { |
---|
802 | points[k]=pGetExp(pp,j); |
---|
803 | k++; |
---|
804 | } |
---|
805 | pIter(pp); |
---|
806 | } |
---|
807 | hc_ERG r=hc_KOENIG(currRing->N, // dimension |
---|
808 | l, // number of points |
---|
809 | (short*) points, // points: x_1, y_1,z_1, x_2,y_2,z2,... |
---|
810 | currRing->OrdSgn==-1, |
---|
811 | (int) (h->next->Data()), // 1: Milnor, 0: Newton |
---|
812 | (int) (h->next->next->Data()) // debug |
---|
813 | ); |
---|
814 | //----<>---Output----------------------- |
---|
815 | |
---|
816 | |
---|
817 | // PrintS("Bin jetzt in extra.cc bei der Auswertung.\n"); // ********** |
---|
818 | |
---|
819 | |
---|
820 | lists L=(lists)Alloc(sizeof(slists)); |
---|
821 | L->Init(6); |
---|
822 | L->m[0].rtyp=STRING_CMD; // newtonnumber; |
---|
823 | L->m[0].data=(void *)mstrdup(r.nZahl); |
---|
824 | L->m[1].rtyp=INT_CMD; |
---|
825 | L->m[1].data=(void *)r.achse; // flag for unoccupied axes |
---|
826 | L->m[2].rtyp=INT_CMD; |
---|
827 | L->m[2].data=(void *)r.deg; // #degenerations |
---|
828 | if ( r.deg != 0) // only if degenerations exist |
---|
829 | { |
---|
830 | L->m[3].rtyp=INT_CMD; |
---|
831 | L->m[3].data=(void *)r.anz_punkte; // #points |
---|
832 | //---<>--number of points------ |
---|
833 | int anz = r.anz_punkte; // number of points |
---|
834 | int dim = (currRing->N); // dimension |
---|
835 | intvec* v = new intvec( anz*dim ); |
---|
836 | for (i=0; i<anz*dim; i++) // copy points |
---|
837 | (*v)[i] = r.pu[i]; |
---|
838 | L->m[4].rtyp=INTVEC_CMD; |
---|
839 | L->m[4].data=(void *)v; |
---|
840 | //---<>--degenerations--------- |
---|
841 | int deg = r.deg; // number of points |
---|
842 | intvec* w = new intvec( r.speicher ); // necessary memeory |
---|
843 | i=0; // start copying |
---|
844 | do |
---|
845 | { |
---|
846 | (*w)[i] = r.deg_tab[i]; |
---|
847 | i++; |
---|
848 | } |
---|
849 | while (r.deg_tab[i-1] != -2); // mark for end of list |
---|
850 | L->m[5].rtyp=INTVEC_CMD; |
---|
851 | L->m[5].data=(void *)w; |
---|
852 | } |
---|
853 | else |
---|
854 | { |
---|
855 | L->m[3].rtyp=INT_CMD; L->m[3].data=(char *)0; |
---|
856 | L->m[4].rtyp=DEF_CMD; |
---|
857 | L->m[5].rtyp=DEF_CMD; |
---|
858 | } |
---|
859 | |
---|
860 | res->data=(void *)L; |
---|
861 | res->rtyp=LIST_CMD; |
---|
862 | // free all pointer in r: |
---|
863 | delete[] r.nZahl; |
---|
864 | delete[] r.pu; |
---|
865 | delete[] r.deg_tab; // Ist das ein Problem?? |
---|
866 | |
---|
867 | Free((ADDRESS)points,currRing->N*l*sizeof(short)); |
---|
868 | return FALSE; |
---|
869 | } |
---|
870 | else |
---|
871 | #endif |
---|
872 | /*==================== gp =================*/ |
---|
873 | #ifdef HAVE_MPSR |
---|
874 | if (strcmp(sys_cmd, "gp") == 0) |
---|
875 | { |
---|
876 | if (h->Typ() != LINK_CMD) |
---|
877 | { |
---|
878 | WerrorS("No Link arg"); |
---|
879 | return FALSE; |
---|
880 | } |
---|
881 | si_link l = (si_link) h->Data(); |
---|
882 | if (strcmp(l->m->type, "MPfile") != 0) |
---|
883 | { |
---|
884 | WerrorS("No MPfile link"); |
---|
885 | return TRUE; |
---|
886 | } |
---|
887 | if( ! SI_LINK_R_OPEN_P(l)) // open r ? |
---|
888 | { |
---|
889 | if (slOpen(l, SI_LINK_READ)) return TRUE; |
---|
890 | } |
---|
891 | |
---|
892 | MP_Link_pt link = (MP_Link_pt) l->data; |
---|
893 | if (MP_InitMsg(link) != MP_Success) |
---|
894 | { |
---|
895 | WerrorS("Can not Init"); |
---|
896 | } |
---|
897 | MPT_Tree_pt tree = NULL; |
---|
898 | if (MPT_GetTree(link, &tree) != MPT_Success) |
---|
899 | { |
---|
900 | WerrorS("Can not get tree"); |
---|
901 | return TRUE; |
---|
902 | } |
---|
903 | MPT_GP_pt gp_tree = MPT_GetGP(tree); |
---|
904 | if (gp_tree == NULL || ! gp_tree->IsOk(gp_tree)) |
---|
905 | { |
---|
906 | WerrorS("gp error"); |
---|
907 | return TRUE; |
---|
908 | } |
---|
909 | delete gp_tree; |
---|
910 | MPT_DeleteTree(tree); |
---|
911 | return FALSE; |
---|
912 | } |
---|
913 | else |
---|
914 | #endif |
---|
915 | /*==================== sdb-debugger =================*/ |
---|
916 | if (strcmp(sys_cmd, "breakpoint") == 0) |
---|
917 | { |
---|
918 | if ((h!=NULL) && (h->Typ()==PROC_CMD)) |
---|
919 | { |
---|
920 | procinfov p=(procinfov)h->Data(); |
---|
921 | if (p->language!=LANG_SINGULAR) |
---|
922 | { |
---|
923 | WerrorS("set breakpoints only in Singular procedures"); |
---|
924 | return TRUE; |
---|
925 | } |
---|
926 | int lineno=p->data.s.body_lineno; |
---|
927 | if ((h->next!=NULL) && (h->next->Typ()==INT_CMD)) |
---|
928 | { |
---|
929 | lineno=(int)h->next->Data(); |
---|
930 | } |
---|
931 | int i; |
---|
932 | if (lineno== -1) |
---|
933 | { |
---|
934 | i=p->trace_flag; |
---|
935 | p->trace_flag &=1; |
---|
936 | Print("breakpoints in %s deleted(%#x)\n",p->procname,i &255); |
---|
937 | return FALSE; |
---|
938 | } |
---|
939 | i=0; |
---|
940 | while((i<7) && (sdb_lines[i]!=-1)) i++; |
---|
941 | if (sdb_lines[i]!= -1) |
---|
942 | { |
---|
943 | PrintS("too many breakpoints set, max is 7\n"); |
---|
944 | return FALSE; |
---|
945 | } |
---|
946 | else |
---|
947 | { |
---|
948 | sdb_lines[i]=lineno; |
---|
949 | sdb_files[i]=p->libname; |
---|
950 | i++; |
---|
951 | Print("breakpoint %d, at line %d in %s\n",i,lineno,p->procname); |
---|
952 | p->trace_flag|=(1<<i); |
---|
953 | } |
---|
954 | } |
---|
955 | else |
---|
956 | { |
---|
957 | WerrorS("system(\"breakpoint\",`proc`,`int`) expected"); |
---|
958 | return TRUE; |
---|
959 | } |
---|
960 | return FALSE; |
---|
961 | } |
---|
962 | else |
---|
963 | /*==================== sdb_flags =================*/ |
---|
964 | if (strcmp(sys_cmd, "sdb_flags") == 0) |
---|
965 | { |
---|
966 | if ((h!=NULL) && (h->Typ()==INT_CMD)) |
---|
967 | { |
---|
968 | sdb_flags=(int)h->Data(); |
---|
969 | } |
---|
970 | else |
---|
971 | { |
---|
972 | WerrorS("system(\"sdb_flags\",`int`) expected"); |
---|
973 | return TRUE; |
---|
974 | } |
---|
975 | return FALSE; |
---|
976 | } |
---|
977 | else |
---|
978 | /*==================== sdb_edit =================*/ |
---|
979 | if (strcmp(sys_cmd, "sdb_edit") == 0) |
---|
980 | { |
---|
981 | if ((h!=NULL) && (h->Typ()==PROC_CMD)) |
---|
982 | { |
---|
983 | procinfov p=(procinfov)h->Data(); |
---|
984 | sdb_edit(p); |
---|
985 | } |
---|
986 | else |
---|
987 | { |
---|
988 | WerrorS("system(\"sdb_edit\",`proc`) expected"); |
---|
989 | return TRUE; |
---|
990 | } |
---|
991 | return FALSE; |
---|
992 | } |
---|
993 | else |
---|
994 | /*==================== print all option values =================*/ |
---|
995 | #ifndef NDEBUG |
---|
996 | if (strcmp(sys_cmd, "options") == 0) |
---|
997 | { |
---|
998 | void mainOptionValues(); |
---|
999 | mainOptionValues(); |
---|
1000 | return FALSE; |
---|
1001 | } |
---|
1002 | else |
---|
1003 | #endif |
---|
1004 | /*==================== GF =================*/ |
---|
1005 | #if 0 |
---|
1006 | if (strcmp(sys_cmd, "GF") == 0) |
---|
1007 | { |
---|
1008 | int c=rChar(currRing); |
---|
1009 | setCharacteristic( c, 2); |
---|
1010 | CanonicalForm F( convSingGFClapGF( (poly)h->Data() ) ); |
---|
1011 | res->rtyp=POLY_CMD; |
---|
1012 | res->data=convClapGFSingGF( F ); |
---|
1013 | return FALSE; |
---|
1014 | } |
---|
1015 | else |
---|
1016 | #endif |
---|
1017 | /*============================================================*/ |
---|
1018 | Werror( "system(\"%s\",...) %s", sys_cmd, feNotImplemented ); |
---|
1019 | } |
---|
1020 | return TRUE; |
---|
1021 | } |
---|
1022 | #endif // HAVE_EXTENDED_SYSTEM |
---|