1 | /***************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | *****************************************/ |
---|
4 | /* $Id: extra.cc,v 1.49 1998-05-20 07:52:23 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 | #include "fglmcomb.cc" |
---|
65 | #include "fglm.h" |
---|
66 | #endif |
---|
67 | |
---|
68 | #include "silink.h" |
---|
69 | #include "mpsr.h" |
---|
70 | |
---|
71 | #ifdef HAVE_DYNAMIC_LOADING |
---|
72 | #include <dlfcn.h> |
---|
73 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
74 | |
---|
75 | // see clapsing.cc for a description of the `FACTORY_*' options |
---|
76 | |
---|
77 | #ifdef FACTORY_GCD_STAT |
---|
78 | #include "gcd_stat.h" |
---|
79 | #endif |
---|
80 | |
---|
81 | #ifdef FACTORY_GCD_TIMING |
---|
82 | #define TIMING |
---|
83 | #include "timing.h" |
---|
84 | TIMING_DEFINE_PRINTPROTO( contentTimer ); |
---|
85 | TIMING_DEFINE_PRINTPROTO( algContentTimer ); |
---|
86 | TIMING_DEFINE_PRINTPROTO( algLcmTimer ); |
---|
87 | #endif |
---|
88 | |
---|
89 | void piShowProcList(); |
---|
90 | |
---|
91 | //void emStart(); |
---|
92 | /*2 |
---|
93 | * the "system" command |
---|
94 | */ |
---|
95 | BOOLEAN 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("/bin/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_GMP |
---|
191 | TEST_FOR("gmp") |
---|
192 | #endif |
---|
193 | #ifdef HAVE_FACTORY |
---|
194 | TEST_FOR("factory") |
---|
195 | #endif |
---|
196 | #ifdef HAVE_LIBFAC_P |
---|
197 | TEST_FOR("libfac") |
---|
198 | #endif |
---|
199 | #ifdef HAVE_MPSR |
---|
200 | TEST_FOR("MP") |
---|
201 | #endif |
---|
202 | #ifdef HAVE_READLINE |
---|
203 | TEST_FOR("readline") |
---|
204 | #endif |
---|
205 | #ifdef HAVE_TCL |
---|
206 | TEST_FOR("tcl") |
---|
207 | #endif |
---|
208 | #ifdef SRING |
---|
209 | TEST_FOR("SRING") |
---|
210 | #endif |
---|
211 | #ifdef TEST_MAC_ORDER |
---|
212 | TEST_FOR("MAC_ORDER"); |
---|
213 | #endif |
---|
214 | ; |
---|
215 | return FALSE; |
---|
216 | #undef TEST_FOR |
---|
217 | } |
---|
218 | return TRUE; |
---|
219 | } |
---|
220 | else |
---|
221 | /*==================== pid ==================================*/ |
---|
222 | #ifndef MSDOS |
---|
223 | #ifndef __MWERKS__ |
---|
224 | if (strcmp((char*)(h->Data()),"pid")==0) |
---|
225 | { |
---|
226 | res->rtyp=INT_CMD; |
---|
227 | res->data=(void *)getpid(); |
---|
228 | return FALSE; |
---|
229 | } |
---|
230 | else |
---|
231 | #endif |
---|
232 | #endif |
---|
233 | /*==================== getenv ==================================*/ |
---|
234 | if (strcmp((char*)(h->Data()),"getenv")==0) |
---|
235 | { |
---|
236 | if ((h->next!=NULL) && (h->next->Typ()==STRING_CMD)) |
---|
237 | { |
---|
238 | res->rtyp=STRING_CMD; |
---|
239 | char *r=getenv((char *)h->next->Data()); |
---|
240 | if (r==NULL) r=""; |
---|
241 | res->data=(void *)mstrdup(r); |
---|
242 | return FALSE; |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | WerrorS("string expected"); |
---|
247 | } |
---|
248 | } |
---|
249 | else |
---|
250 | /*==================== tty ==================================*/ |
---|
251 | #ifndef __MWERKS__ |
---|
252 | #ifndef MSDOS |
---|
253 | #if defined(HAVE_FEREAD) || defined(HAVE_READLINE) |
---|
254 | if (strcmp((char*)(h->Data()),"tty")==0) |
---|
255 | { |
---|
256 | #ifdef HAVE_FEREAD |
---|
257 | #ifdef HAVE_ATEXIT |
---|
258 | fe_reset_input_mode(); |
---|
259 | #else |
---|
260 | fe_reset_input_mode(0,NULL); |
---|
261 | #endif |
---|
262 | #elif defined(HAVE_READLINE) |
---|
263 | system("stty sane"); |
---|
264 | #endif |
---|
265 | if ((h->next!=NULL)&&(h->next->Typ()==INT_CMD)) |
---|
266 | { |
---|
267 | fe_use_fgets=(int)h->next->Data(); |
---|
268 | fe_set_input_mode(); |
---|
269 | } |
---|
270 | return FALSE; |
---|
271 | } |
---|
272 | else |
---|
273 | #endif |
---|
274 | #endif |
---|
275 | #endif |
---|
276 | /*==================== Singular ==================================*/ |
---|
277 | if (strcmp((char*)(h->data), "Singular") == 0) |
---|
278 | { |
---|
279 | res->rtyp=STRING_CMD; |
---|
280 | res->data=(void*)feGetExpandedExecutable(); |
---|
281 | if (res->data != NULL) |
---|
282 | res->data = (void*) mstrdup((char*) res->data); |
---|
283 | else |
---|
284 | res->data = (void*) mstrdup(""); |
---|
285 | return FALSE; |
---|
286 | } |
---|
287 | else |
---|
288 | /*==================== options ==================================*/ |
---|
289 | if (strstr((char*)(h->data), "--") == (char*)(h->data)) |
---|
290 | { |
---|
291 | BOOLEAN mainGetSingOptionValue(const char* name, char** result); |
---|
292 | char* val; |
---|
293 | |
---|
294 | if (mainGetSingOptionValue(&((char*)(h->data))[2], &val)) |
---|
295 | { |
---|
296 | res->data = (void*) val; |
---|
297 | if ((unsigned int) val > 1) |
---|
298 | { |
---|
299 | res->rtyp=STRING_CMD; |
---|
300 | res->data = (void*) mstrdup((char*) res->data); |
---|
301 | } |
---|
302 | else |
---|
303 | res->rtyp=INT_CMD; |
---|
304 | return FALSE; |
---|
305 | } |
---|
306 | else |
---|
307 | { |
---|
308 | Werror("Unknown option %s\n", (char*)(h->data)); |
---|
309 | return TRUE; |
---|
310 | } |
---|
311 | } |
---|
312 | else |
---|
313 | /*==================== HC ==================================*/ |
---|
314 | if (strcmp((char*)(h->data),"HC")==0) |
---|
315 | { |
---|
316 | res->rtyp=INT_CMD; |
---|
317 | res->data=(void *)HCord; |
---|
318 | return FALSE; |
---|
319 | } |
---|
320 | else |
---|
321 | /*==================== random ==================================*/ |
---|
322 | if(strcmp((char*)(h->Data()),"random")==0) |
---|
323 | { |
---|
324 | if ((h->next!=NULL) &&(h->next->Typ()==INT_CMD)) |
---|
325 | { |
---|
326 | siRandomStart=(int)h->next->Data(); |
---|
327 | #ifdef buildin_rand |
---|
328 | siSeed=siRandomStart; |
---|
329 | #else |
---|
330 | srand((unsigned int)siRandomStart); |
---|
331 | #endif |
---|
332 | return FALSE; |
---|
333 | } |
---|
334 | else if (h->next != NULL) |
---|
335 | { |
---|
336 | WerrorS("int expected"); |
---|
337 | return TRUE; |
---|
338 | } |
---|
339 | res->rtyp=INT_CMD; |
---|
340 | res->data=(void*) siRandomStart; |
---|
341 | return FALSE; |
---|
342 | } |
---|
343 | /*==================== neworder =============================*/ |
---|
344 | // should go below |
---|
345 | #ifdef HAVE_LIBFAC_P |
---|
346 | if(strcmp((char*)(h->Data()),"neworder")==0) |
---|
347 | { |
---|
348 | if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD)) |
---|
349 | { |
---|
350 | res->rtyp=STRING_CMD; |
---|
351 | res->data=(void *)singclap_neworder((ideal)h->next->Data()); |
---|
352 | return FALSE; |
---|
353 | } |
---|
354 | else |
---|
355 | WerrorS("ideal expected"); |
---|
356 | } |
---|
357 | else |
---|
358 | #endif |
---|
359 | /*==================== contributors =============================*/ |
---|
360 | if(strcmp((char*)(h->Data()),"contributors") == 0) |
---|
361 | { |
---|
362 | res->rtyp=STRING_CMD; |
---|
363 | res->data=(void *) |
---|
364 | "Olaf Bachmann, Hubert Grassmann, Kai Krueger, Wolfgang Neumann, Thomas Nuessler, Wilfried Pohl, Thomas Siebert, Ruediger Stobbe, Tim Wichmann"; |
---|
365 | return FALSE; |
---|
366 | } |
---|
367 | #ifdef HAVE_EXTENDED_SYSTEM |
---|
368 | // You can put your own system calls here |
---|
369 | /*==================== LaScala ==================================*/ |
---|
370 | if(strcmp((char*)(h->Data()),"LaScala")==0) |
---|
371 | { |
---|
372 | if ((h->next!=NULL) |
---|
373 | &&((h->next->Typ()==IDEAL_CMD)||(h->next->Typ()==MODUL_CMD))) |
---|
374 | { |
---|
375 | int dummy; |
---|
376 | res->data=(void *)syLaScala3((ideal)h->next->Data(),&dummy); |
---|
377 | mmTest(res->data,sizeof(ssyStrategy)); |
---|
378 | syStrategy s=(syStrategy)res->data; |
---|
379 | for (int i=s->length;i>=0;i--) |
---|
380 | { |
---|
381 | if (s->res[i]!=NULL) |
---|
382 | idTest(s->res[i]); |
---|
383 | } |
---|
384 | res->rtyp=RESOLUTION_CMD; |
---|
385 | return FALSE; |
---|
386 | } |
---|
387 | else |
---|
388 | WerrorS("ideal/module expected"); |
---|
389 | } |
---|
390 | else |
---|
391 | /*==================== naIdeal ==================================*/ |
---|
392 | if(strcmp((char*)(h->Data()),"naIdeal")==0) |
---|
393 | { |
---|
394 | if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD)) |
---|
395 | { |
---|
396 | naSetIdeal((ideal)h->next->Data()); |
---|
397 | return FALSE; |
---|
398 | } |
---|
399 | else |
---|
400 | WerrorS("ideal expected"); |
---|
401 | } |
---|
402 | else |
---|
403 | /*==================== isSqrFree =============================*/ |
---|
404 | #ifdef HAVE_FACTORY |
---|
405 | if(strcmp((char*)(h->Data()),"isSqrFree")==0) |
---|
406 | { |
---|
407 | if ((h->next!=NULL) &&(h->next->Typ()==POLY_CMD)) |
---|
408 | { |
---|
409 | res->rtyp=INT_CMD; |
---|
410 | res->data=(void *)singclap_isSqrFree((poly)h->next->Data()); |
---|
411 | return FALSE; |
---|
412 | } |
---|
413 | else |
---|
414 | WerrorS("poly expected"); |
---|
415 | } |
---|
416 | else |
---|
417 | #endif |
---|
418 | /*==================== alarm ==================================*/ |
---|
419 | #ifndef __MWERKS__ |
---|
420 | #ifndef MSDOS |
---|
421 | #ifndef atarist |
---|
422 | #ifdef unix |
---|
423 | if(strcmp((char*)(h->Data()),"alarm")==0) |
---|
424 | { |
---|
425 | if ((h->next!=NULL) &&(h->next->Typ()==INT_CMD)) |
---|
426 | { |
---|
427 | // standard variant -> SIGALARM (standard: abort) |
---|
428 | //alarm((unsigned)h->next->Data()); |
---|
429 | // process time (user +system): SIGVTALARM |
---|
430 | struct itimerval t,o; |
---|
431 | memset(&t,0,sizeof(t)); |
---|
432 | t.it_value.tv_sec =(unsigned)h->next->Data(); |
---|
433 | setitimer(ITIMER_VIRTUAL,&t,&o); |
---|
434 | return FALSE; |
---|
435 | } |
---|
436 | else |
---|
437 | WerrorS("int expected"); |
---|
438 | } |
---|
439 | else |
---|
440 | #endif |
---|
441 | #endif |
---|
442 | #endif |
---|
443 | #endif |
---|
444 | /*==================== red =============================*/ |
---|
445 | #if 0 |
---|
446 | if(strcmp((char*)(h->Data()),"red")==0) |
---|
447 | { |
---|
448 | if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD)) |
---|
449 | { |
---|
450 | res->rtyp=IDEAL_CMD; |
---|
451 | res->data=(void *)kStdred((ideal)h->next->Data(),NULL,testHomog,NULL); |
---|
452 | setFlag(res,FLAG_STD); |
---|
453 | return FALSE; |
---|
454 | } |
---|
455 | else |
---|
456 | WerrorS("ideal expected"); |
---|
457 | } |
---|
458 | else |
---|
459 | #endif |
---|
460 | #ifdef HAVE_FACTORY |
---|
461 | /*==================== pdivide ====================*/ |
---|
462 | if (strcmp((char*)(h->Data()),"pdivide")==0) |
---|
463 | { |
---|
464 | if (h->next!=NULL && h->next->next!=NULL && |
---|
465 | h->next->Typ()==POLY_CMD && h->next->next->Typ()==POLY_CMD) |
---|
466 | { |
---|
467 | res->rtyp=POLY_CMD; |
---|
468 | res->data=(void*)(singclap_pdivide((poly)(h->next->Data()), |
---|
469 | (poly)(h->next->next->Data()))); |
---|
470 | return FALSE; |
---|
471 | } |
---|
472 | else |
---|
473 | WerrorS("poly expected"); |
---|
474 | } |
---|
475 | else |
---|
476 | #endif |
---|
477 | /*==================== algfetch =====================*/ |
---|
478 | if (strcmp((char*)(h->Data()),"algfetch")==0) |
---|
479 | { |
---|
480 | int k; |
---|
481 | idhdl w; |
---|
482 | ideal i0, i1; |
---|
483 | leftv v=h->next; |
---|
484 | ring r0=(ring)v->Data(); |
---|
485 | v = v->next; |
---|
486 | w = r0->idroot->get(v->Name(),myynest); |
---|
487 | i0 = IDIDEAL(w); |
---|
488 | i1 = idInit(IDELEMS(i0),i0->rank); |
---|
489 | for (k=0; k<IDELEMS(i1); k++) |
---|
490 | { |
---|
491 | i1->m[k] = maAlgpolyFetch(r0, i0->m[k]); |
---|
492 | } |
---|
493 | res->rtyp = IDEAL_CMD; |
---|
494 | res->data = (void*)i1; |
---|
495 | return FALSE; |
---|
496 | } |
---|
497 | else |
---|
498 | /*==================== algmap =======================*/ |
---|
499 | if (strcmp((char*)(h->Data()),"algmap")==0) |
---|
500 | { |
---|
501 | int k; |
---|
502 | idhdl w; |
---|
503 | ideal i0, i1, i, j; |
---|
504 | leftv v=h->next; |
---|
505 | ring r0=(ring)v->Data(); |
---|
506 | v = v->next; |
---|
507 | w = r0->idroot->get(v->Name(),myynest); |
---|
508 | i0 = IDIDEAL(w); |
---|
509 | v = v->next; |
---|
510 | i = (ideal)v->Data(); |
---|
511 | v = v->next; |
---|
512 | j = (ideal)v->Data(); |
---|
513 | i1 = idInit(IDELEMS(i0),i0->rank); |
---|
514 | for (k=0; k<IDELEMS(i1); k++) |
---|
515 | { |
---|
516 | i1->m[k] = maAlgpolyMap(r0, i0->m[k], i, j); |
---|
517 | } |
---|
518 | res->rtyp = IDEAL_CMD; |
---|
519 | res->data = (void*)i1; |
---|
520 | return FALSE; |
---|
521 | } |
---|
522 | else |
---|
523 | /*==================== indsetall =============================*/ |
---|
524 | if(strcmp((char*)(h->Data()),"indsetall")==0) |
---|
525 | { |
---|
526 | if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD)) |
---|
527 | { |
---|
528 | int i=0; |
---|
529 | if (h->next->next!=NULL) |
---|
530 | { |
---|
531 | if (h->next->next->Typ()==INT_CMD) |
---|
532 | i=(int)h->next->next->Data(); |
---|
533 | else |
---|
534 | { |
---|
535 | Warn("int expected"); |
---|
536 | } |
---|
537 | } |
---|
538 | res->rtyp=LIST_CMD; |
---|
539 | res->data=(void *)scIndIndset((ideal)h->next->Data(),i,currQuotient); |
---|
540 | return FALSE; |
---|
541 | } |
---|
542 | else |
---|
543 | WerrorS("ideal expected"); |
---|
544 | } |
---|
545 | else |
---|
546 | #ifdef STDTRACE |
---|
547 | /*==================== trace =============================*/ |
---|
548 | /* Parameter : Ideal, Liste mit Links. */ |
---|
549 | if(strcmp((char*)(h->Data()),"stdtrace")==0) |
---|
550 | { |
---|
551 | if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD)) |
---|
552 | { |
---|
553 | leftv root = NULL, |
---|
554 | ptr = NULL, |
---|
555 | lv = NULL; |
---|
556 | lists l = NULL; |
---|
557 | ideal I = (ideal)(h->next->Data()); |
---|
558 | lists links = (lists)(h->next->next->Data()); |
---|
559 | tHomog hom = testHomog; |
---|
560 | int rw = (int)(h->next->next->next->Data()); |
---|
561 | |
---|
562 | if(I==NULL) |
---|
563 | PrintS("I==NULL\n"); |
---|
564 | for(int i=0; i <= links->nr ; i++) |
---|
565 | { |
---|
566 | lv = (leftv)Alloc0(sizeof(sleftv)); |
---|
567 | lv->Copy(&(links->m[i])); |
---|
568 | if(root==NULL) |
---|
569 | root=lv; |
---|
570 | if(ptr==NULL) |
---|
571 | { |
---|
572 | ptr=lv; |
---|
573 | ptr->next=NULL; |
---|
574 | } |
---|
575 | else |
---|
576 | { |
---|
577 | ptr->next=lv; |
---|
578 | ptr=lv; |
---|
579 | } |
---|
580 | } |
---|
581 | ptr->next=NULL; |
---|
582 | l=TraceStd(root,rw,I,currQuotient,testHomog,NULL); |
---|
583 | idSkipZeroes(((ideal)l->m[0].Data())); |
---|
584 | res->rtyp=LIST_CMD; |
---|
585 | res->data=(void *) l; |
---|
586 | res->next=NULL; |
---|
587 | root->CleanUp(); |
---|
588 | Free(root,sizeof(sleftv)); |
---|
589 | return FALSE; |
---|
590 | } |
---|
591 | else |
---|
592 | WerrorS("ideal expected"); |
---|
593 | } |
---|
594 | else |
---|
595 | #endif |
---|
596 | #ifdef HAVE_FACTORY |
---|
597 | /*==================== fastcomb =============================*/ |
---|
598 | if(strcmp((char*)(h->Data()),"fastcomb")==0) |
---|
599 | { |
---|
600 | if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD)) |
---|
601 | { |
---|
602 | int i=0; |
---|
603 | if (h->next->next!=NULL) |
---|
604 | { |
---|
605 | if (h->next->next->Typ()!=POLY_CMD) |
---|
606 | { |
---|
607 | Warn("Wrong types for poly= comb(ideal,poly)"); |
---|
608 | } |
---|
609 | } |
---|
610 | res->rtyp=POLY_CMD; |
---|
611 | res->data=(void *)fglmLinearCombination((ideal)h->next->Data(),(poly)h->next->next->Data()); |
---|
612 | return FALSE; |
---|
613 | } |
---|
614 | else |
---|
615 | WerrorS("ideal expected"); |
---|
616 | } |
---|
617 | else |
---|
618 | /*==================== comb =============================*/ |
---|
619 | if(strcmp((char*)(h->Data()),"comb")==0) |
---|
620 | { |
---|
621 | if ((h->next!=NULL) &&(h->next->Typ()==IDEAL_CMD)) |
---|
622 | { |
---|
623 | int i=0; |
---|
624 | if (h->next->next!=NULL) |
---|
625 | { |
---|
626 | if (h->next->next->Typ()!=POLY_CMD) |
---|
627 | { |
---|
628 | Warn("Wrong types for poly= comb(ideal,poly)"); |
---|
629 | } |
---|
630 | } |
---|
631 | res->rtyp=POLY_CMD; |
---|
632 | res->data=(void *)fglmNewLinearCombination((ideal)h->next->Data(),(poly)h->next->next->Data()); |
---|
633 | return FALSE; |
---|
634 | } |
---|
635 | else |
---|
636 | WerrorS("ideal expected"); |
---|
637 | } |
---|
638 | else |
---|
639 | #endif |
---|
640 | /*==================== barstep =============================*/ |
---|
641 | if(strcmp((char*)(h->Data()),"barstep")==0) |
---|
642 | { |
---|
643 | if ((h->next!=NULL) &&(h->next->Typ()==MATRIX_CMD)) |
---|
644 | { |
---|
645 | if (h->next->next!=NULL) |
---|
646 | { |
---|
647 | if (h->next->next->Typ()!=POLY_CMD) |
---|
648 | { |
---|
649 | Warn("Wrong types for barstep(matrix,poly)"); |
---|
650 | } |
---|
651 | } |
---|
652 | int r,c; |
---|
653 | poly div=(poly)h->next->next->Data(); |
---|
654 | res->rtyp=MATRIX_CMD; |
---|
655 | res->data=(void *)mpOneStepBareiss((matrix)h->next->Data(), |
---|
656 | &div,&r,&c); |
---|
657 | Print("div: ");pWrite(div); |
---|
658 | Print("rows: %d, cols: %d\n",r,c); |
---|
659 | pDelete(&div); |
---|
660 | return FALSE; |
---|
661 | } |
---|
662 | else |
---|
663 | WerrorS("matrix expected"); |
---|
664 | } |
---|
665 | else |
---|
666 | #ifdef FACTORY_GCD_TEST |
---|
667 | /*=======================gcd Testerei ================================*/ |
---|
668 | if ( ! strcmp( (char*)(h->Data()), "setgcd" ) ) { |
---|
669 | if ( (h->next != NULL) && (h->next->Typ() == INT_CMD) ) { |
---|
670 | CFPrimitiveGcdUtil::setAlgorithm( (int)h->next->Data() ); |
---|
671 | return FALSE; |
---|
672 | } else |
---|
673 | WerrorS("int expected"); |
---|
674 | } |
---|
675 | else |
---|
676 | #endif |
---|
677 | |
---|
678 | #ifdef FACTORY_GCD_TIMING |
---|
679 | if ( ! strcmp( (char*)(h->Data()), "gcdtime" ) ) { |
---|
680 | TIMING_PRINT( contentTimer, "time used for content: " ); |
---|
681 | TIMING_PRINT( algContentTimer, "time used for algContent: " ); |
---|
682 | TIMING_PRINT( algLcmTimer, "time used for algLcm: " ); |
---|
683 | TIMING_RESET( contentTimer ); |
---|
684 | TIMING_RESET( algContentTimer ); |
---|
685 | TIMING_RESET( algLcmTimer ); |
---|
686 | return FALSE; |
---|
687 | } |
---|
688 | else |
---|
689 | #endif |
---|
690 | |
---|
691 | #ifdef FACTORY_GCD_STAT |
---|
692 | if ( ! strcmp( (char*)(h->Data()), "gcdstat" ) ) { |
---|
693 | printGcdTotal(); |
---|
694 | printContTotal(); |
---|
695 | resetGcdTotal(); |
---|
696 | resetContTotal(); |
---|
697 | return FALSE; |
---|
698 | } |
---|
699 | else |
---|
700 | #endif |
---|
701 | /*==================== lib ==================================*/ |
---|
702 | if(strcmp((char*)(h->Data()),"LIB")==0) |
---|
703 | { |
---|
704 | #ifdef HAVE_NAMESPACES |
---|
705 | idhdl hh=namespaceroot->get((char*)h->next->Data(),0); |
---|
706 | #else /* HAVE_NAMESPACES */ |
---|
707 | idhdl hh=idroot->get((char*)h->next->Data(),0); |
---|
708 | #endif /* HAVE_NAMESPACES */ |
---|
709 | if ((hh!=NULL)&&(IDTYP(hh)==PROC_CMD)) |
---|
710 | { |
---|
711 | res->rtyp=STRING_CMD; |
---|
712 | res->data=mstrdup(iiGetLibName(IDPROC(hh))); |
---|
713 | if (res->data==NULL) res->data=mstrdup(""); |
---|
714 | return FALSE; |
---|
715 | } |
---|
716 | else |
---|
717 | Warn("`%s` not found",(char*)h->next->Data()); |
---|
718 | } |
---|
719 | else |
---|
720 | #ifdef HAVE_NAMESPACES |
---|
721 | /*==================== nspush ===================================*/ |
---|
722 | if(strcmp((char*)(h->Data()),"nspush")==0) |
---|
723 | { |
---|
724 | idhdl hh=namespaceroot->get((char*)h->next->Data(),0, TRUE); |
---|
725 | if ((hh!=NULL)&&(IDTYP(hh)==PACKAGE_CMD)) |
---|
726 | { |
---|
727 | namespaceroot = namespaceroot->push(IDPACKAGE(hh), IDID(hh)); |
---|
728 | return FALSE; |
---|
729 | } |
---|
730 | else |
---|
731 | Warn("package `%s` not found",(char*)h->next->Data()); |
---|
732 | } |
---|
733 | else |
---|
734 | /*==================== nspop ====================================*/ |
---|
735 | if(strcmp((char*)(h->Data()),"nspop")==0) |
---|
736 | { |
---|
737 | namespaceroot->pop(); |
---|
738 | return FALSE; |
---|
739 | } |
---|
740 | else |
---|
741 | /*==================== nsstack ===================================*/ |
---|
742 | if(strcmp((char*)(h->Data()),"nsstack")==0) |
---|
743 | { |
---|
744 | namehdl nshdl = namespaceroot; |
---|
745 | for( ; nshdl->isroot != TRUE; nshdl = nshdl->next) { |
---|
746 | Print("NSstack: %s:%d\n", nshdl->name, nshdl->lev); |
---|
747 | } |
---|
748 | Print("NSstack: %s:%d\n", nshdl->name, nshdl->lev); |
---|
749 | return FALSE; |
---|
750 | } |
---|
751 | else |
---|
752 | #endif /* HAVE_NAMESPACES */ |
---|
753 | /*==================== proclist =================================*/ |
---|
754 | if(strcmp((char*)(h->Data()),"proclist")==0) |
---|
755 | { |
---|
756 | //res->rtyp=STRING_CMD; |
---|
757 | //res->data=(void *)mstrdup(""); |
---|
758 | piShowProcList(); |
---|
759 | return FALSE; |
---|
760 | } |
---|
761 | else |
---|
762 | #ifdef HAVE_DYNAMIC_LOADING |
---|
763 | /*==================== load ==================================*/ |
---|
764 | if(strcmp((char*)(h->Data()),"load")==0) |
---|
765 | { |
---|
766 | if ((h->next!=NULL) && (h->next->Typ()==STRING_CMD)) { |
---|
767 | int iiAddCproc(char *libname, char *procname, BOOLEAN pstatic, |
---|
768 | BOOLEAN(*func)(leftv res, leftv v)); |
---|
769 | int (*fktn)(int(*iiAddCproc)(char *libname, char *procname, |
---|
770 | BOOLEAN pstatic, |
---|
771 | BOOLEAN(*func)(leftv res, leftv v))); |
---|
772 | void *vp; |
---|
773 | res->rtyp=STRING_CMD; |
---|
774 | |
---|
775 | fprintf(stderr, "Loading %s\n", h->next->Data()); |
---|
776 | res->data=(void *)mstrdup(""); |
---|
777 | if((vp=dlopen(h->next->Data(),RTLD_LAZY))==(void *)NULL) { |
---|
778 | WerrorS("dlopen failed"); |
---|
779 | Werror("%s not found", h->next->Data()); |
---|
780 | } else { |
---|
781 | fktn = dlsym(vp, "mod_init"); |
---|
782 | if( fktn!= NULL) (*fktn)(iiAddCproc); |
---|
783 | else Werror("mod_init: %s\n", dlerror()); |
---|
784 | piShowProcList(); |
---|
785 | } |
---|
786 | return FALSE; |
---|
787 | } |
---|
788 | else WerrorS("string expected"); |
---|
789 | } |
---|
790 | else |
---|
791 | #endif /* HAVE_DYNAMIC_LOADING */ |
---|
792 | /*==================== print all option values =================*/ |
---|
793 | #ifndef NDEBUG |
---|
794 | if (strcmp((char*)(h->data), "options") == 0) |
---|
795 | { |
---|
796 | void mainOptionValues(); |
---|
797 | mainOptionValues(); |
---|
798 | return FALSE; |
---|
799 | } |
---|
800 | else |
---|
801 | #endif |
---|
802 | #endif // HAVE_EXTENDED_SYSTEM |
---|
803 | /*============================================================*/ |
---|
804 | WerrorS( feNotImplemented ); |
---|
805 | } |
---|
806 | return TRUE; |
---|
807 | } |
---|