1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: ipshell.cc,v 1.16 1998-02-27 14:06:20 Singular Exp $ */ |
---|
5 | /* |
---|
6 | * ABSTRACT: |
---|
7 | */ |
---|
8 | |
---|
9 | //#include <stdlib.h> |
---|
10 | #include <stdio.h> |
---|
11 | #include <string.h> |
---|
12 | #include <ctype.h> |
---|
13 | |
---|
14 | #include "mod2.h" |
---|
15 | #include "tok.h" |
---|
16 | #include "ipid.h" |
---|
17 | #include "intvec.h" |
---|
18 | #include "mmemory.h" |
---|
19 | #include "febase.h" |
---|
20 | #include "polys.h" |
---|
21 | #include "ideals.h" |
---|
22 | #include "matpol.h" |
---|
23 | #include "kstd1.h" |
---|
24 | #include "ring.h" |
---|
25 | #include "subexpr.h" |
---|
26 | #include "maps.h" |
---|
27 | #include "syz.h" |
---|
28 | #include "numbers.h" |
---|
29 | #include "lists.h" |
---|
30 | #include "attrib.h" |
---|
31 | #include "ipconv.h" |
---|
32 | #include "silink.h" |
---|
33 | #include "ipshell.h" |
---|
34 | |
---|
35 | leftv iiCurrArgs=NULL; |
---|
36 | int traceit = 0; |
---|
37 | char *lastreserved=NULL; |
---|
38 | |
---|
39 | int myynest = -1; |
---|
40 | |
---|
41 | static BOOLEAN iiNoKeepRing=TRUE; |
---|
42 | |
---|
43 | /*0 implementation*/ |
---|
44 | |
---|
45 | char * Tok2Cmdname(int tok) |
---|
46 | { |
---|
47 | int i = 0; |
---|
48 | if (tok < 0) |
---|
49 | { |
---|
50 | return cmds[0].name; |
---|
51 | } |
---|
52 | if (tok==ANY_TYPE) return "any_type"; |
---|
53 | if (tok==NONE) return "nothing"; |
---|
54 | //if (tok==IFBREAK) return "if_break"; |
---|
55 | //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys"; |
---|
56 | //if (tok==ORDER_VECTOR) return "ordering"; |
---|
57 | //if (tok==REF_VAR) return "ref"; |
---|
58 | //if (tok==OBJECT) return "object"; |
---|
59 | //if (tok==PRINT_EXPR) return "print_expr"; |
---|
60 | if (tok==IDHDL) return "identifier"; |
---|
61 | while (cmds[i].tokval!=0) |
---|
62 | { |
---|
63 | if ((cmds[i].tokval == tok)&&(cmds[i].alias==0)) |
---|
64 | { |
---|
65 | return cmds[i].name; |
---|
66 | } |
---|
67 | i++; |
---|
68 | } |
---|
69 | return cmds[0].name; |
---|
70 | } |
---|
71 | |
---|
72 | char * iiTwoOps(int t) |
---|
73 | { |
---|
74 | if (t<127) |
---|
75 | { |
---|
76 | static char ch[2]; |
---|
77 | switch (t) |
---|
78 | { |
---|
79 | case '&': |
---|
80 | return "and"; |
---|
81 | case '|': |
---|
82 | return "or"; |
---|
83 | default: |
---|
84 | ch[0]=t; |
---|
85 | ch[1]='\0'; |
---|
86 | return ch; |
---|
87 | } |
---|
88 | } |
---|
89 | switch (t) |
---|
90 | { |
---|
91 | case COLONCOLON: return "::"; |
---|
92 | case DOTDOT: return ".."; |
---|
93 | //case PLUSEQUAL: return "+="; |
---|
94 | //case MINUSEQUAL: return "-="; |
---|
95 | case MINUSMINUS: return "--"; |
---|
96 | case PLUSPLUS: return "++"; |
---|
97 | case EQUAL_EQUAL: return "=="; |
---|
98 | case LE: return "<="; |
---|
99 | case GE: return ">="; |
---|
100 | case NOTEQUAL: return "<>"; |
---|
101 | default: return Tok2Cmdname(t); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | static void list1(char* s, idhdl h,BOOLEAN c) |
---|
106 | { |
---|
107 | char buffer[22]; |
---|
108 | int l; |
---|
109 | |
---|
110 | Print("%s%-20.20s [%d] ",s,IDID(h),IDLEV(h)); |
---|
111 | if (h == currRingHdl) PrintS("*"); |
---|
112 | PrintS(Tok2Cmdname((int)IDTYP(h))); |
---|
113 | |
---|
114 | ipListFlag(h); |
---|
115 | switch(IDTYP(h)) |
---|
116 | { |
---|
117 | case INT_CMD: Print(" %d",IDINT(h)); break; |
---|
118 | case INTVEC_CMD: Print(" (%d)",IDINTVEC(h)->length()); break; |
---|
119 | case INTMAT_CMD: Print(" %d x %d",IDINTVEC(h)->rows(),IDINTVEC(h)->cols()); |
---|
120 | break; |
---|
121 | case POLY_CMD: |
---|
122 | case VECTOR_CMD: if (c) |
---|
123 | { |
---|
124 | PrintS(" ");wrp(IDPOLY(h)); |
---|
125 | if(IDPOLY(h) != NULL) |
---|
126 | { |
---|
127 | Print(", %d monomial(s)",pLength(IDPOLY(h))); |
---|
128 | } |
---|
129 | } |
---|
130 | break; |
---|
131 | case MODUL_CMD: Print(", rk %d", IDIDEAL(h)->rank); |
---|
132 | case IDEAL_CMD: Print(", %u generator(s)", |
---|
133 | IDELEMS(IDIDEAL(h)),IDIDEAL(h)->rank); break; |
---|
134 | case MAP_CMD: |
---|
135 | Print(" from %s",IDMAP(h)->preimage); break; |
---|
136 | case MATRIX_CMD: Print(" %u x %u" |
---|
137 | ,MATROWS(IDMATRIX(h)) |
---|
138 | ,MATCOLS(IDMATRIX(h)) |
---|
139 | ); |
---|
140 | break; |
---|
141 | case PROC_CMD: break; |
---|
142 | case STRING_CMD: |
---|
143 | { |
---|
144 | char *s; |
---|
145 | l=strlen(IDSTRING(h)); |
---|
146 | memset(buffer,0,22); |
---|
147 | strncpy(buffer,IDSTRING(h),min(l,20)); |
---|
148 | if ((s=strchr(buffer,'\n'))!=NULL) |
---|
149 | { |
---|
150 | *s='\0'; |
---|
151 | } |
---|
152 | PrintS(" "); |
---|
153 | PrintS(buffer); |
---|
154 | if((s!=NULL) ||(l>20)) |
---|
155 | { |
---|
156 | Print("..., %d char(s)",l); |
---|
157 | } |
---|
158 | break; |
---|
159 | } |
---|
160 | case LIST_CMD: Print(", size: %d",IDLIST(h)->nr+1); |
---|
161 | break; |
---|
162 | case QRING_CMD: |
---|
163 | case RING_CMD: |
---|
164 | #ifdef RDEBUG |
---|
165 | if (traceit &TRACE_SHOW_RINGS) Print(" <%d>",IDRING(h)->no); |
---|
166 | #endif |
---|
167 | break; |
---|
168 | /*default: break;*/ |
---|
169 | } |
---|
170 | PrintLn(); |
---|
171 | } |
---|
172 | |
---|
173 | void type_cmd(idhdl h) |
---|
174 | { |
---|
175 | int saveShortOut=pShortOut; |
---|
176 | pShortOut=1; |
---|
177 | list1("// ",h,FALSE); |
---|
178 | if (IDTYP(h)!=INT_CMD) |
---|
179 | { |
---|
180 | sleftv expr; |
---|
181 | memset(&expr,0,sizeof(expr)); |
---|
182 | expr.rtyp=IDHDL; |
---|
183 | expr.name=IDID(h); |
---|
184 | expr.data=(void *)h; |
---|
185 | expr.Print(); |
---|
186 | } |
---|
187 | pShortOut=saveShortOut; |
---|
188 | } |
---|
189 | |
---|
190 | static void killlocals0(int v, idhdl * localhdl) |
---|
191 | { |
---|
192 | idhdl h = *localhdl; |
---|
193 | while (h!=NULL) |
---|
194 | { |
---|
195 | int vv; |
---|
196 | if ((vv=IDLEV(h))>0) |
---|
197 | { |
---|
198 | if (vv < v) |
---|
199 | { |
---|
200 | if (iiNoKeepRing) return; |
---|
201 | h = IDNEXT(h); |
---|
202 | } |
---|
203 | else if (vv >= v) |
---|
204 | { |
---|
205 | idhdl nexth = IDNEXT(h); |
---|
206 | //Print("kill %s, lev: %d\n",IDID(h),IDLEV(h)); |
---|
207 | killhdl(h,localhdl); |
---|
208 | h = nexth; |
---|
209 | } |
---|
210 | } |
---|
211 | else |
---|
212 | h = IDNEXT(h); |
---|
213 | } |
---|
214 | } |
---|
215 | |
---|
216 | void killlocals(int v) |
---|
217 | { |
---|
218 | killlocals0(v,&idroot); |
---|
219 | |
---|
220 | idhdl h = idroot; |
---|
221 | idhdl sh=currRingHdl; |
---|
222 | BOOLEAN changed=FALSE; |
---|
223 | |
---|
224 | while (h!=NULL) |
---|
225 | { |
---|
226 | if (((IDTYP(h)==QRING_CMD) || (IDTYP(h) == RING_CMD)) |
---|
227 | && (IDRING(h)->idroot!=NULL)) |
---|
228 | { |
---|
229 | if (h!=currRingHdl) {changed=TRUE;rSetHdl(h,FALSE);} |
---|
230 | killlocals0(v,&(IDRING(h)->idroot)); |
---|
231 | } |
---|
232 | h = IDNEXT(h); |
---|
233 | } |
---|
234 | if (changed) |
---|
235 | { |
---|
236 | currRing=NULL; |
---|
237 | currRingHdl=NULL; |
---|
238 | rSetHdl(sh,TRUE); |
---|
239 | } |
---|
240 | iiNoKeepRing=TRUE; |
---|
241 | } |
---|
242 | |
---|
243 | void list_cmd(int typ, const char* what, char *prefix,BOOLEAN iterate) |
---|
244 | { |
---|
245 | idhdl h,start; |
---|
246 | BOOLEAN all = typ==-1; |
---|
247 | BOOLEAN really_all=FALSE; |
---|
248 | |
---|
249 | if ( typ==0 ) |
---|
250 | { |
---|
251 | if (strcmp(what,"all")==0) |
---|
252 | { |
---|
253 | really_all=TRUE; |
---|
254 | h=idroot; |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | h = ggetid(what); |
---|
259 | if (h!=NULL) |
---|
260 | { |
---|
261 | if (iterate) list1(prefix,h,TRUE); |
---|
262 | if ((IDTYP(h)==RING_CMD) |
---|
263 | || (IDTYP(h)==QRING_CMD) |
---|
264 | || (IDTYP(h)==PACKAGE_CMD)) |
---|
265 | { |
---|
266 | h=IDRING(h)->idroot; |
---|
267 | } |
---|
268 | else |
---|
269 | return; |
---|
270 | } |
---|
271 | else |
---|
272 | { |
---|
273 | Werror("%s is undefined",what); |
---|
274 | return; |
---|
275 | } |
---|
276 | } |
---|
277 | all=TRUE; |
---|
278 | } |
---|
279 | else if ((typ>BEGIN_RING) && (typ<END_RING)) |
---|
280 | { |
---|
281 | h = currRing->idroot; |
---|
282 | } |
---|
283 | else |
---|
284 | h = idroot; |
---|
285 | start=h; |
---|
286 | while (h!=NULL) |
---|
287 | { |
---|
288 | if ((all && (IDTYP(h)!=PROC_CMD)) || (typ == IDTYP(h)) |
---|
289 | || ((IDTYP(h)==QRING_CMD) && (typ==RING_CMD))) |
---|
290 | { |
---|
291 | list1(prefix,h,start==currRingHdl); |
---|
292 | if ((((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD)) |
---|
293 | && (really_all || (all && (h==currRingHdl))) |
---|
294 | && ((IDLEV(h)==0)||(IDLEV(h)==myynest))) |
---|
295 | ||(IDTYP(h)==PACKAGE_CMD)) |
---|
296 | { |
---|
297 | list_cmd(0,IDID(h),"// ",FALSE); |
---|
298 | } |
---|
299 | } |
---|
300 | h = IDNEXT(h); |
---|
301 | } |
---|
302 | } |
---|
303 | |
---|
304 | void test_cmd(int i) |
---|
305 | { |
---|
306 | int ii=(char)i; |
---|
307 | |
---|
308 | if (i == (-32)) |
---|
309 | { |
---|
310 | test = 0; |
---|
311 | } |
---|
312 | else |
---|
313 | { |
---|
314 | if (i<0) |
---|
315 | { |
---|
316 | ii= -i; |
---|
317 | if (Sy_bit(ii) & kOptions) |
---|
318 | { |
---|
319 | Warn("use the option command"); |
---|
320 | test &= ~Sy_bit(ii); |
---|
321 | } |
---|
322 | else if (Sy_bit(ii) & validOpts) |
---|
323 | test &= ~Sy_bit(ii); |
---|
324 | } |
---|
325 | else if (i<32) |
---|
326 | { |
---|
327 | if (Sy_bit(ii) & kOptions) |
---|
328 | { |
---|
329 | Warn("use the option command"); |
---|
330 | test |= Sy_bit(ii); |
---|
331 | } |
---|
332 | else if (Sy_bit(ii) & validOpts) |
---|
333 | test |= Sy_bit(ii); |
---|
334 | } |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | int exprlist_length(leftv v) |
---|
339 | { |
---|
340 | int rc = 0; |
---|
341 | while (v!=NULL) |
---|
342 | { |
---|
343 | switch (v->Typ()) |
---|
344 | { |
---|
345 | case INT_CMD: |
---|
346 | case POLY_CMD: |
---|
347 | case VECTOR_CMD: |
---|
348 | case NUMBER_CMD: |
---|
349 | rc++; |
---|
350 | break; |
---|
351 | case INTVEC_CMD: |
---|
352 | case INTMAT_CMD: |
---|
353 | rc += ((intvec *)(v->Data()))->length(); |
---|
354 | break; |
---|
355 | case MATRIX_CMD: |
---|
356 | case IDEAL_CMD: |
---|
357 | case MODUL_CMD: |
---|
358 | { |
---|
359 | matrix mm = (matrix)(v->Data()); |
---|
360 | rc += mm->rows() * mm->cols(); |
---|
361 | } |
---|
362 | break; |
---|
363 | case LIST_CMD: |
---|
364 | rc+=((lists)v->Data())->nr+1; |
---|
365 | break; |
---|
366 | default: |
---|
367 | rc++; |
---|
368 | } |
---|
369 | v = v->next; |
---|
370 | } |
---|
371 | return rc; |
---|
372 | } |
---|
373 | |
---|
374 | void iiWriteMatrix(matrix im, const char *n, int dim,int spaces) |
---|
375 | { |
---|
376 | int i,ii = MATROWS(im)-1; |
---|
377 | int j,jj = MATCOLS(im)-1; |
---|
378 | poly *pp = im->m; |
---|
379 | |
---|
380 | for (i=0; i<=ii; i++) |
---|
381 | { |
---|
382 | for (j=0; j<=jj; j++) |
---|
383 | { |
---|
384 | if (spaces>0) |
---|
385 | Print("%-*.*s",spaces,spaces," "); |
---|
386 | if (dim == 2) Print("%s[%u,%u]=",n,i+1,j+1); |
---|
387 | else if (dim == 1) Print("%s[%u]=",n,j+1); |
---|
388 | else if (dim == 0) Print("%s=",n); |
---|
389 | if ((i<ii)||(j<jj)) pWrite(*pp++); |
---|
390 | else pWrite0(*pp); |
---|
391 | } |
---|
392 | } |
---|
393 | } |
---|
394 | |
---|
395 | char * iiStringMatrix(matrix im, int dim,char ch) |
---|
396 | { |
---|
397 | int i,ii = MATROWS(im); |
---|
398 | int j,jj = MATCOLS(im); |
---|
399 | poly *pp = im->m; |
---|
400 | char *s=StringSet(""); |
---|
401 | |
---|
402 | for (i=0; i<ii; i++) |
---|
403 | { |
---|
404 | for (j=0; j<jj; j++) |
---|
405 | { |
---|
406 | pString0(*pp++); |
---|
407 | s=StringAppend("%c\n",ch); |
---|
408 | } |
---|
409 | } |
---|
410 | s[strlen(s)-2]='\0'; |
---|
411 | return s; |
---|
412 | } |
---|
413 | |
---|
414 | int IsPrime(int p) /* brute force !!!! */ |
---|
415 | { |
---|
416 | int i,j; |
---|
417 | if (p == 0) return 0; |
---|
418 | else if (p == 1) return 1/*1*/; |
---|
419 | else if (p == 2) return p; |
---|
420 | else if (p < 0) return (-IsPrime(-p)); |
---|
421 | else if (!(p & 1)) return IsPrime(p-1); |
---|
422 | for (j=p/2+1,i=3; i<p; i+=2) |
---|
423 | { |
---|
424 | if ((p%i) == 0) return IsPrime(p-2); |
---|
425 | if (j < i) return p; |
---|
426 | } |
---|
427 | return p; |
---|
428 | } |
---|
429 | |
---|
430 | BOOLEAN iiWRITE(leftv res,leftv v) |
---|
431 | { |
---|
432 | sleftv vf; |
---|
433 | if (iiConvert(v->Typ(),LINK_CMD,iiTestConvert(v->Typ(),LINK_CMD),v,&vf)) |
---|
434 | { |
---|
435 | WerrorS("link expected"); |
---|
436 | return TRUE; |
---|
437 | } |
---|
438 | si_link l=(si_link)vf.Data(); |
---|
439 | if (vf.next == NULL) |
---|
440 | { |
---|
441 | WerrorS("write: need at least two arguments"); |
---|
442 | return TRUE; |
---|
443 | } |
---|
444 | |
---|
445 | BOOLEAN b=slWrite(l,vf.next); /* iiConvert preserves next */ |
---|
446 | if (b) |
---|
447 | { |
---|
448 | const char *s; |
---|
449 | if ((l!=NULL)&&(l->name!=NULL)) s=l->name; |
---|
450 | else s=sNoName; |
---|
451 | Werror("cannot write to %s",s); |
---|
452 | } |
---|
453 | vf.CleanUp(); |
---|
454 | return b; |
---|
455 | } |
---|
456 | |
---|
457 | leftv iiMap(map theMap, char * what) |
---|
458 | { |
---|
459 | idhdl w,r; |
---|
460 | leftv v; |
---|
461 | int i; |
---|
462 | |
---|
463 | r=idroot->get(theMap->preimage,myynest); |
---|
464 | if ((r!=NULL) && ((r->typ == RING_CMD) || (r->typ== QRING_CMD))) |
---|
465 | { |
---|
466 | if (!nSetMap(IDRING(r)->ch,IDRING(r)->parameter,IDRING(r)->P, IDRING(r)->minpoly)) |
---|
467 | { |
---|
468 | Werror("map from characteristic %d to %d not implemented", |
---|
469 | IDRING(r)->ch,currRing->ch); |
---|
470 | return NULL; |
---|
471 | } |
---|
472 | if (IDELEMS(theMap)<IDRING(r)->N) |
---|
473 | { |
---|
474 | theMap->m=(polyset)ReAlloc((ADDRESS)theMap->m,IDELEMS(theMap)*sizeof(poly), |
---|
475 | (IDRING(r)->N)*sizeof(poly)); |
---|
476 | for(i=IDELEMS(theMap);i<IDRING(r)->N;i++) |
---|
477 | theMap->m[i]=NULL; |
---|
478 | IDELEMS(theMap)=IDRING(r)->N; |
---|
479 | } |
---|
480 | if (what==NULL) |
---|
481 | { |
---|
482 | WerrorS("argument of a map must have a name"); |
---|
483 | } |
---|
484 | else if ((w=IDRING(r)->idroot->get(what,myynest))!=NULL) |
---|
485 | { |
---|
486 | v=(leftv)Alloc0(sizeof(*v)); |
---|
487 | sleftv tmpW; |
---|
488 | memset(&tmpW,0,sizeof(sleftv)); |
---|
489 | tmpW.rtyp=IDTYP(w); |
---|
490 | tmpW.data=IDDATA(w); |
---|
491 | if (maApplyFetch(MAP_CMD,theMap,v,&tmpW,IDRING(r),NULL,NULL,0)) |
---|
492 | { |
---|
493 | Werror("cannot map %s(%d)",Tok2Cmdname(w->typ),w->typ); |
---|
494 | Free((ADDRESS)v,sizeof(*v)); |
---|
495 | return NULL; |
---|
496 | } |
---|
497 | return v; |
---|
498 | } |
---|
499 | else |
---|
500 | Werror("%s undefined in %s",what,theMap->preimage); |
---|
501 | } |
---|
502 | else |
---|
503 | Werror("cannot find preimage %s",theMap->preimage); |
---|
504 | return NULL; |
---|
505 | } |
---|
506 | |
---|
507 | #ifdef OLD_RES |
---|
508 | void iiMakeResolv(resolvente r, int length, int rlen, char * name, int typ0, |
---|
509 | intvec ** weights) |
---|
510 | { |
---|
511 | lists L=liMakeResolv(r,length,rlen,typ0,weights); |
---|
512 | int i=0; |
---|
513 | idhdl h; |
---|
514 | char * s=(char *)Alloc(strlen(name)+5); |
---|
515 | |
---|
516 | while (i<=L->nr) |
---|
517 | { |
---|
518 | sprintf(s,"%s(%d)",name,i+1); |
---|
519 | if (i==0) |
---|
520 | h=enterid(mstrdup(s),myynest,typ0,&(currRing->idroot), FALSE); |
---|
521 | else |
---|
522 | h=enterid(mstrdup(s),myynest,MODUL_CMD,&(currRing->idroot), FALSE); |
---|
523 | if (h!=NULL) |
---|
524 | { |
---|
525 | h->data.uideal=(ideal)L->m[i].data; |
---|
526 | h->attribute=L->m[i].attribute; |
---|
527 | if (BVERBOSE(V_DEF_RES)) |
---|
528 | Print("//defining: %s as %d-th syzygy module\n",s,i+1); |
---|
529 | } |
---|
530 | else |
---|
531 | { |
---|
532 | idDelete((ideal *)&(L->m[i].data)); |
---|
533 | Warn("cannot define %s",s); |
---|
534 | } |
---|
535 | //L->m[i].data=NULL; |
---|
536 | //L->m[i].rtyp=0; |
---|
537 | //L->m[i].attribute=NULL; |
---|
538 | i++; |
---|
539 | } |
---|
540 | Free((ADDRESS)L->m,(L->nr+1)*sizeof(sleftv)); |
---|
541 | Free((ADDRESS)L,sizeof(slists)); |
---|
542 | Free((ADDRESS)s,strlen(name)+5); |
---|
543 | } |
---|
544 | #endif |
---|
545 | |
---|
546 | //resolvente iiFindRes(char * name, int * len, int *typ0) |
---|
547 | //{ |
---|
548 | // char *s=(char *)Alloc(strlen(name)+5); |
---|
549 | // int i=-1; |
---|
550 | // resolvente r; |
---|
551 | // idhdl h; |
---|
552 | // |
---|
553 | // do |
---|
554 | // { |
---|
555 | // i++; |
---|
556 | // sprintf(s,"%s(%d)",name,i+1); |
---|
557 | // h=currRing->idroot->get(s,myynest); |
---|
558 | // } while (h!=NULL); |
---|
559 | // *len=i-1; |
---|
560 | // if (*len<=0) |
---|
561 | // { |
---|
562 | // Werror("no objects %s(1),.. found",name); |
---|
563 | // Free((ADDRESS)s,strlen(name)+5); |
---|
564 | // return NULL; |
---|
565 | // } |
---|
566 | // r=(ideal *)Alloc(/*(len+1)*/ i*sizeof(ideal)); |
---|
567 | // memset(r,0,(*len)*sizeof(ideal)); |
---|
568 | // i=-1; |
---|
569 | // *typ0=MODUL_CMD; |
---|
570 | // while (i<(*len)) |
---|
571 | // { |
---|
572 | // i++; |
---|
573 | // sprintf(s,"%s(%d)",name,i+1); |
---|
574 | // h=currRing->idroot->get(s,myynest); |
---|
575 | // if (h->typ != MODUL_CMD) |
---|
576 | // { |
---|
577 | // if ((i!=0) || (h->typ!=IDEAL_CMD)) |
---|
578 | // { |
---|
579 | // Werror("%s is not of type module",s); |
---|
580 | // Free((ADDRESS)r,(*len)*sizeof(ideal)); |
---|
581 | // Free((ADDRESS)s,strlen(name)+5); |
---|
582 | // return NULL; |
---|
583 | // } |
---|
584 | // *typ0=IDEAL_CMD; |
---|
585 | // } |
---|
586 | // if ((i>0) && (idIs0(r[i-1]))) |
---|
587 | // { |
---|
588 | // *len=i-1; |
---|
589 | // break; |
---|
590 | // } |
---|
591 | // r[i]=IDIDEAL(h); |
---|
592 | // } |
---|
593 | // Free((ADDRESS)s,strlen(name)+5); |
---|
594 | // return r; |
---|
595 | //} |
---|
596 | |
---|
597 | static resolvente iiCopyRes(resolvente r, int l) |
---|
598 | { |
---|
599 | int i; |
---|
600 | resolvente res=(ideal *)Alloc0((l+1)*sizeof(ideal)); |
---|
601 | |
---|
602 | for (i=0; i<l; i++) |
---|
603 | res[i]=idCopy(r[i]); |
---|
604 | return res; |
---|
605 | } |
---|
606 | |
---|
607 | BOOLEAN jjMINRES(leftv res, leftv v) |
---|
608 | { |
---|
609 | int len=0; |
---|
610 | int typ0; |
---|
611 | resolvente rr=liFindRes((lists)v->Data(),&len,&typ0); |
---|
612 | if (rr==NULL) return TRUE; |
---|
613 | resolvente r=iiCopyRes(rr,len); |
---|
614 | |
---|
615 | syMinimizeResolvente(r,len,0); |
---|
616 | Free((ADDRESS)rr,len*sizeof(ideal)); |
---|
617 | len++; |
---|
618 | res->data=(char *)liMakeResolv(r,len,-1,typ0,NULL); |
---|
619 | return FALSE; |
---|
620 | } |
---|
621 | |
---|
622 | BOOLEAN jjBETTI(leftv res, leftv v) |
---|
623 | { |
---|
624 | resolvente r; |
---|
625 | int len; |
---|
626 | int reg,typ0; |
---|
627 | |
---|
628 | r=liFindRes((lists)v->Data(),&len,&typ0); |
---|
629 | if (r==NULL) return TRUE; |
---|
630 | res->data=(char *)syBetti(r,len,®); |
---|
631 | Free((ADDRESS)r,(len)*sizeof(ideal)); |
---|
632 | return FALSE; |
---|
633 | } |
---|
634 | |
---|
635 | int iiRegularity(lists L) |
---|
636 | { |
---|
637 | resolvente r; |
---|
638 | int len,reg,typ0; |
---|
639 | intvec * dummy; |
---|
640 | |
---|
641 | r=liFindRes(L,&len,&typ0); |
---|
642 | if (r==NULL) return -1; |
---|
643 | dummy=syBetti(r,len,®); |
---|
644 | Free((ADDRESS)r,len*sizeof(ideal)); |
---|
645 | delete dummy; |
---|
646 | return reg-1; |
---|
647 | } |
---|
648 | |
---|
649 | BOOLEAN iiDebugMarker=TRUE; |
---|
650 | void iiDebug() |
---|
651 | { |
---|
652 | Print("\n-- break point in %s --\n",VoiceName()); |
---|
653 | if (iiDebugMarker) VoiceBackTrack(); |
---|
654 | char * s; |
---|
655 | iiDebugMarker=FALSE; |
---|
656 | s = (char *)AllocL(84); |
---|
657 | fe_fgets_stdin(s,80); |
---|
658 | if (*s=='\n') |
---|
659 | { |
---|
660 | iiDebugMarker=TRUE; |
---|
661 | } |
---|
662 | else |
---|
663 | { |
---|
664 | strcat( s, "\n;~\n"); |
---|
665 | newBuffer(s,BT_execute); |
---|
666 | } |
---|
667 | } |
---|
668 | |
---|
669 | int iiDeclCommand(leftv sy, leftv name, int lev,int t, idhdl* root,BOOLEAN init_b) |
---|
670 | { |
---|
671 | BOOLEAN res=FALSE; |
---|
672 | memset(sy,0,sizeof(sleftv)); |
---|
673 | if ((name->name==NULL)||(isdigit(name->name[0]))) |
---|
674 | { |
---|
675 | WerrorS("object to declare is not a name"); |
---|
676 | res=TRUE; |
---|
677 | } |
---|
678 | else |
---|
679 | { |
---|
680 | sy->data = (char *)enterid(name->name,lev,t,root,init_b); |
---|
681 | if (sy->data!=NULL) |
---|
682 | { |
---|
683 | sy->rtyp=IDHDL; |
---|
684 | currid=sy->name=IDID((idhdl)sy->data); |
---|
685 | name->name=NULL; /* used in enterid */ |
---|
686 | //sy->e = NULL; |
---|
687 | if (name->next!=NULL) |
---|
688 | { |
---|
689 | sy->next=(leftv)Alloc(sizeof(sleftv)); |
---|
690 | res=iiDeclCommand(sy->next,name->next,lev,t,root); |
---|
691 | } |
---|
692 | } |
---|
693 | else res=TRUE; |
---|
694 | } |
---|
695 | name->CleanUp(); |
---|
696 | return res; |
---|
697 | } |
---|
698 | |
---|
699 | BOOLEAN iiParameter(leftv p) |
---|
700 | { |
---|
701 | if (iiCurrArgs==NULL) |
---|
702 | { |
---|
703 | if (strcmp(p->name,"#")==0) return FALSE; |
---|
704 | Werror("not enough arguments for proc %s",VoiceName()); |
---|
705 | p->CleanUp(); |
---|
706 | return TRUE; |
---|
707 | } |
---|
708 | leftv h=iiCurrArgs; |
---|
709 | if (strcmp(p->name,"#")==0) |
---|
710 | { |
---|
711 | iiCurrArgs=NULL; |
---|
712 | } |
---|
713 | else |
---|
714 | { |
---|
715 | iiCurrArgs=h->next; |
---|
716 | h->next=NULL; |
---|
717 | } |
---|
718 | BOOLEAN res=iiAssign(p,h); |
---|
719 | Free((ADDRESS)h,sizeof(sleftv)); |
---|
720 | return res; |
---|
721 | } |
---|
722 | |
---|
723 | BOOLEAN iiExport (leftv v, int toLev) |
---|
724 | { |
---|
725 | BOOLEAN nok=FALSE; |
---|
726 | leftv r=v; |
---|
727 | while (v!=NULL) |
---|
728 | { |
---|
729 | if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL)) |
---|
730 | { |
---|
731 | WerrorS("cannot export"); |
---|
732 | nok=TRUE; |
---|
733 | } |
---|
734 | else |
---|
735 | { |
---|
736 | idhdl h=(idhdl)v->data; |
---|
737 | if (IDLEV(h)==0) Warn("`%s` is already global",IDID(h)); |
---|
738 | else |
---|
739 | { |
---|
740 | h=idroot->get(v->name,toLev); |
---|
741 | idhdl *root=&idroot; |
---|
742 | if ((h==NULL)&&(currRing!=NULL)) |
---|
743 | { |
---|
744 | h=currRing->idroot->get(v->name,toLev); |
---|
745 | root=&currRing->idroot; |
---|
746 | } |
---|
747 | if ((h!=NULL)&&(IDLEV(h)==toLev)) |
---|
748 | { |
---|
749 | if (IDTYP(h)==v->Typ()) |
---|
750 | { |
---|
751 | Warn("redefining %s",IDID(h)); |
---|
752 | if (iiLocalRing[0]==IDRING(h)) iiLocalRing[0]=NULL; |
---|
753 | killhdl(h,root); |
---|
754 | } |
---|
755 | else |
---|
756 | { |
---|
757 | r->CleanUp(); |
---|
758 | return TRUE; |
---|
759 | } |
---|
760 | } |
---|
761 | h=(idhdl)v->data; |
---|
762 | IDLEV(h)=toLev; |
---|
763 | iiNoKeepRing=FALSE; |
---|
764 | } |
---|
765 | } |
---|
766 | v=v->next; |
---|
767 | } |
---|
768 | r->CleanUp(); |
---|
769 | return nok; |
---|
770 | } |
---|
771 | |
---|
772 | /*assume root!=idroot*/ |
---|
773 | BOOLEAN iiExport (leftv v, int toLev, idhdl &root) |
---|
774 | { |
---|
775 | BOOLEAN nok=FALSE; |
---|
776 | leftv rv=v; |
---|
777 | while (v!=NULL) |
---|
778 | { |
---|
779 | if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL) |
---|
780 | ) |
---|
781 | { |
---|
782 | WerrorS("cannot export"); |
---|
783 | nok=TRUE; |
---|
784 | } |
---|
785 | else |
---|
786 | { |
---|
787 | idhdl old=root->get(v->name,toLev); |
---|
788 | if (old!=NULL) |
---|
789 | { |
---|
790 | if (IDTYP(old)==v->Typ()) |
---|
791 | { |
---|
792 | Warn("redefining %s",IDID(old)); |
---|
793 | killhdl(old,&root); |
---|
794 | } |
---|
795 | else |
---|
796 | { |
---|
797 | rv->CleanUp(); |
---|
798 | return TRUE; |
---|
799 | } |
---|
800 | } |
---|
801 | idhdl h=(idhdl)v->data; |
---|
802 | if (h==idroot) |
---|
803 | { |
---|
804 | idroot=h->next; |
---|
805 | } |
---|
806 | else |
---|
807 | { |
---|
808 | idhdl hh=idroot; |
---|
809 | while ((hh->next!=h)&&(hh->next!=NULL)) |
---|
810 | hh=hh->next; |
---|
811 | if (hh->next==h) |
---|
812 | hh->next=h->next; |
---|
813 | else |
---|
814 | break; |
---|
815 | } |
---|
816 | h->next=root; |
---|
817 | root=h; |
---|
818 | IDLEV(h)=toLev; |
---|
819 | } |
---|
820 | v=v->next; |
---|
821 | } |
---|
822 | rv->CleanUp(); |
---|
823 | return nok; |
---|
824 | } |
---|
825 | |
---|
826 | BOOLEAN iiCheckRing(int i) |
---|
827 | { |
---|
828 | if (currRingHdl==NULL) |
---|
829 | { |
---|
830 | #ifdef SIQ |
---|
831 | if (siq<=0) |
---|
832 | { |
---|
833 | #endif |
---|
834 | if ((i>BEGIN_RING) && (i<END_RING)) |
---|
835 | { |
---|
836 | WerrorS("no ring active"); |
---|
837 | return TRUE; |
---|
838 | } |
---|
839 | #ifdef SIQ |
---|
840 | } |
---|
841 | #endif |
---|
842 | } |
---|
843 | return FALSE; |
---|
844 | } |
---|