1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: ipshell.cc,v 1.24 1998-09-29 10:36:39 krueger 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: if(strlen(IDPROC(h)->libname)>0) |
---|
142 | Print(" from %s",IDPROC(h)->libname); |
---|
143 | if(IDPROC(h)->is_static) |
---|
144 | Print(" (static)"); |
---|
145 | break; |
---|
146 | case STRING_CMD: |
---|
147 | { |
---|
148 | char *s; |
---|
149 | l=strlen(IDSTRING(h)); |
---|
150 | memset(buffer,0,22); |
---|
151 | strncpy(buffer,IDSTRING(h),min(l,20)); |
---|
152 | if ((s=strchr(buffer,'\n'))!=NULL) |
---|
153 | { |
---|
154 | *s='\0'; |
---|
155 | } |
---|
156 | PrintS(" "); |
---|
157 | PrintS(buffer); |
---|
158 | if((s!=NULL) ||(l>20)) |
---|
159 | { |
---|
160 | Print("..., %d char(s)",l); |
---|
161 | } |
---|
162 | break; |
---|
163 | } |
---|
164 | case LIST_CMD: Print(", size: %d",IDLIST(h)->nr+1); |
---|
165 | break; |
---|
166 | case QRING_CMD: |
---|
167 | case RING_CMD: |
---|
168 | #ifdef RDEBUG |
---|
169 | if (traceit &TRACE_SHOW_RINGS) Print(" <%d>",IDRING(h)->no); |
---|
170 | #endif |
---|
171 | break; |
---|
172 | /*default: break;*/ |
---|
173 | } |
---|
174 | PrintLn(); |
---|
175 | } |
---|
176 | |
---|
177 | void type_cmd(idhdl h) |
---|
178 | { |
---|
179 | int saveShortOut=pShortOut; |
---|
180 | pShortOut=1; |
---|
181 | list1("// ",h,FALSE); |
---|
182 | if (IDTYP(h)!=INT_CMD) |
---|
183 | { |
---|
184 | sleftv expr; |
---|
185 | memset(&expr,0,sizeof(expr)); |
---|
186 | expr.rtyp=IDHDL; |
---|
187 | expr.name=IDID(h); |
---|
188 | expr.data=(void *)h; |
---|
189 | expr.Print(); |
---|
190 | } |
---|
191 | pShortOut=saveShortOut; |
---|
192 | } |
---|
193 | |
---|
194 | static void killlocals0(int v, idhdl * localhdl) |
---|
195 | { |
---|
196 | idhdl h = *localhdl; |
---|
197 | while (h!=NULL) |
---|
198 | { |
---|
199 | int vv; |
---|
200 | //Print("consider %s, lev: %d:",IDID(h),IDLEV(h)); |
---|
201 | if ((vv=IDLEV(h))>0) |
---|
202 | { |
---|
203 | if (vv < v) |
---|
204 | { |
---|
205 | if (iiNoKeepRing) |
---|
206 | { |
---|
207 | //PrintS(" break\n"); |
---|
208 | return; |
---|
209 | } |
---|
210 | h = IDNEXT(h); |
---|
211 | //PrintLn(); |
---|
212 | } |
---|
213 | else if (vv >= v) |
---|
214 | { |
---|
215 | idhdl nexth = IDNEXT(h); |
---|
216 | killhdl(h,localhdl); |
---|
217 | h = nexth; |
---|
218 | //PrintS("kill\n"); |
---|
219 | } |
---|
220 | } |
---|
221 | else |
---|
222 | { |
---|
223 | h = IDNEXT(h); |
---|
224 | //PrintLn(); |
---|
225 | } |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | void killlocals(int v) |
---|
230 | { |
---|
231 | killlocals0(v,&IDROOT); |
---|
232 | |
---|
233 | idhdl h = IDROOT; |
---|
234 | idhdl sh=currRingHdl; |
---|
235 | BOOLEAN changed=FALSE; |
---|
236 | |
---|
237 | while (h!=NULL) |
---|
238 | { |
---|
239 | if (((IDTYP(h)==QRING_CMD) || (IDTYP(h) == RING_CMD)) |
---|
240 | && (IDRING(h)->idroot!=NULL)) |
---|
241 | { |
---|
242 | if (h!=currRingHdl) {changed=TRUE;rSetHdl(h,FALSE);} |
---|
243 | killlocals0(v,&(IDRING(h)->idroot)); |
---|
244 | } |
---|
245 | h = IDNEXT(h); |
---|
246 | } |
---|
247 | if (changed) |
---|
248 | { |
---|
249 | currRing=NULL; |
---|
250 | currRingHdl=NULL; |
---|
251 | rSetHdl(sh,TRUE); |
---|
252 | } |
---|
253 | if (myynest<=1) iiNoKeepRing=TRUE; |
---|
254 | } |
---|
255 | |
---|
256 | void list_cmd(int typ, const char* what, char *prefix,BOOLEAN iterate) |
---|
257 | { |
---|
258 | idhdl h,start; |
---|
259 | BOOLEAN all = typ==-1; |
---|
260 | BOOLEAN really_all=FALSE; |
---|
261 | |
---|
262 | if ( typ==0 ) |
---|
263 | { |
---|
264 | if (strcmp(what,"all")==0) |
---|
265 | { |
---|
266 | really_all=TRUE; |
---|
267 | h=IDROOT; |
---|
268 | } |
---|
269 | else |
---|
270 | { |
---|
271 | h = ggetid(what); |
---|
272 | if (h!=NULL) |
---|
273 | { |
---|
274 | if (iterate) list1(prefix,h,TRUE); |
---|
275 | if ((IDTYP(h)==RING_CMD) |
---|
276 | || (IDTYP(h)==QRING_CMD)) |
---|
277 | { |
---|
278 | h=IDRING(h)->idroot; |
---|
279 | } |
---|
280 | else if((IDTYP(h)==PACKAGE_CMD) || (IDTYP(h)==POINTER_CMD)) |
---|
281 | { |
---|
282 | //Print("list_cmd:package or pointer\n"); |
---|
283 | h=IDPACKAGE(h)->idroot; |
---|
284 | } |
---|
285 | else |
---|
286 | return; |
---|
287 | } |
---|
288 | else |
---|
289 | { |
---|
290 | Werror("%s is undefined",what); |
---|
291 | return; |
---|
292 | } |
---|
293 | } |
---|
294 | all=TRUE; |
---|
295 | } |
---|
296 | else if ((typ>BEGIN_RING) && (typ<END_RING)) |
---|
297 | { |
---|
298 | h = currRing->idroot; |
---|
299 | } |
---|
300 | else |
---|
301 | h = IDROOT; |
---|
302 | start=h; |
---|
303 | while (h!=NULL) |
---|
304 | { |
---|
305 | if ((all && (IDTYP(h)!=PROC_CMD)) || (typ == IDTYP(h)) |
---|
306 | || ((IDTYP(h)==QRING_CMD) && (typ==RING_CMD))) |
---|
307 | { |
---|
308 | list1(prefix,h,start==currRingHdl); |
---|
309 | if (((IDTYP(h)==RING_CMD)||(IDTYP(h)==QRING_CMD)) |
---|
310 | && (really_all || (all && (h==currRingHdl))) |
---|
311 | && ((IDLEV(h)==0)||(IDLEV(h)==myynest))) |
---|
312 | { |
---|
313 | list_cmd(0,IDID(h),"// ",FALSE); |
---|
314 | } |
---|
315 | #ifdef HAVE_NAMESPACES |
---|
316 | if (IDTYP(h)==PACKAGE_CMD && really_all && strcmp(IDID(h), "Top")) |
---|
317 | { |
---|
318 | namespaceroot->push(IDPACKAGE(h), IDID(h)); |
---|
319 | list_cmd(0,IDID(h),"// ",FALSE); |
---|
320 | namespaceroot->pop(); |
---|
321 | } |
---|
322 | #endif /* HAVE_NAMESPACES */ |
---|
323 | } |
---|
324 | h = IDNEXT(h); |
---|
325 | } |
---|
326 | } |
---|
327 | |
---|
328 | void test_cmd(int i) |
---|
329 | { |
---|
330 | int ii=(char)i; |
---|
331 | |
---|
332 | if (i == (-32)) |
---|
333 | { |
---|
334 | test = 0; |
---|
335 | } |
---|
336 | else |
---|
337 | { |
---|
338 | if (i<0) |
---|
339 | { |
---|
340 | ii= -i; |
---|
341 | if (Sy_bit(ii) & kOptions) |
---|
342 | { |
---|
343 | Warn("use the option command"); |
---|
344 | test &= ~Sy_bit(ii); |
---|
345 | } |
---|
346 | else if (Sy_bit(ii) & validOpts) |
---|
347 | test &= ~Sy_bit(ii); |
---|
348 | } |
---|
349 | else if (i<32) |
---|
350 | { |
---|
351 | if (Sy_bit(ii) & kOptions) |
---|
352 | { |
---|
353 | Warn("use the option command"); |
---|
354 | test |= Sy_bit(ii); |
---|
355 | } |
---|
356 | else if (Sy_bit(ii) & validOpts) |
---|
357 | test |= Sy_bit(ii); |
---|
358 | } |
---|
359 | } |
---|
360 | } |
---|
361 | |
---|
362 | int exprlist_length(leftv v) |
---|
363 | { |
---|
364 | int rc = 0; |
---|
365 | while (v!=NULL) |
---|
366 | { |
---|
367 | switch (v->Typ()) |
---|
368 | { |
---|
369 | case INT_CMD: |
---|
370 | case POLY_CMD: |
---|
371 | case VECTOR_CMD: |
---|
372 | case NUMBER_CMD: |
---|
373 | rc++; |
---|
374 | break; |
---|
375 | case INTVEC_CMD: |
---|
376 | case INTMAT_CMD: |
---|
377 | rc += ((intvec *)(v->Data()))->length(); |
---|
378 | break; |
---|
379 | case MATRIX_CMD: |
---|
380 | case IDEAL_CMD: |
---|
381 | case MODUL_CMD: |
---|
382 | { |
---|
383 | matrix mm = (matrix)(v->Data()); |
---|
384 | rc += mm->rows() * mm->cols(); |
---|
385 | } |
---|
386 | break; |
---|
387 | case LIST_CMD: |
---|
388 | rc+=((lists)v->Data())->nr+1; |
---|
389 | break; |
---|
390 | default: |
---|
391 | rc++; |
---|
392 | } |
---|
393 | v = v->next; |
---|
394 | } |
---|
395 | return rc; |
---|
396 | } |
---|
397 | |
---|
398 | void iiWriteMatrix(matrix im, const char *n, int dim,int spaces) |
---|
399 | { |
---|
400 | int i,ii = MATROWS(im)-1; |
---|
401 | int j,jj = MATCOLS(im)-1; |
---|
402 | poly *pp = im->m; |
---|
403 | |
---|
404 | for (i=0; i<=ii; i++) |
---|
405 | { |
---|
406 | for (j=0; j<=jj; j++) |
---|
407 | { |
---|
408 | if (spaces>0) |
---|
409 | Print("%-*.*s",spaces,spaces," "); |
---|
410 | if (dim == 2) Print("%s[%u,%u]=",n,i+1,j+1); |
---|
411 | else if (dim == 1) Print("%s[%u]=",n,j+1); |
---|
412 | else if (dim == 0) Print("%s=",n); |
---|
413 | if ((i<ii)||(j<jj)) pWrite(*pp++); |
---|
414 | else pWrite0(*pp); |
---|
415 | } |
---|
416 | } |
---|
417 | } |
---|
418 | |
---|
419 | char * iiStringMatrix(matrix im, int dim,char ch) |
---|
420 | { |
---|
421 | int i,ii = MATROWS(im); |
---|
422 | int j,jj = MATCOLS(im); |
---|
423 | poly *pp = im->m; |
---|
424 | char *s=StringSet(""); |
---|
425 | |
---|
426 | for (i=0; i<ii; i++) |
---|
427 | { |
---|
428 | for (j=0; j<jj; j++) |
---|
429 | { |
---|
430 | pString0(*pp++); |
---|
431 | s=StringAppend("%c\n",ch); |
---|
432 | } |
---|
433 | } |
---|
434 | s[strlen(s)-2]='\0'; |
---|
435 | return s; |
---|
436 | } |
---|
437 | |
---|
438 | int IsPrime(int p) /* brute force !!!! */ |
---|
439 | { |
---|
440 | int i,j; |
---|
441 | if (p == 0) return 0; |
---|
442 | else if (p == 1) return 1/*1*/; |
---|
443 | else if (p == 2) return p; |
---|
444 | else if (p < 0) return (-IsPrime(-p)); |
---|
445 | else if (!(p & 1)) return IsPrime(p-1); |
---|
446 | for (j=p/2+1,i=3; i<p; i+=2) |
---|
447 | { |
---|
448 | if ((p%i) == 0) return IsPrime(p-2); |
---|
449 | if (j < i) return p; |
---|
450 | } |
---|
451 | return p; |
---|
452 | } |
---|
453 | |
---|
454 | BOOLEAN iiWRITE(leftv res,leftv v) |
---|
455 | { |
---|
456 | sleftv vf; |
---|
457 | if (iiConvert(v->Typ(),LINK_CMD,iiTestConvert(v->Typ(),LINK_CMD),v,&vf)) |
---|
458 | { |
---|
459 | WerrorS("link expected"); |
---|
460 | return TRUE; |
---|
461 | } |
---|
462 | si_link l=(si_link)vf.Data(); |
---|
463 | if (vf.next == NULL) |
---|
464 | { |
---|
465 | WerrorS("write: need at least two arguments"); |
---|
466 | return TRUE; |
---|
467 | } |
---|
468 | |
---|
469 | BOOLEAN b=slWrite(l,vf.next); /* iiConvert preserves next */ |
---|
470 | if (b) |
---|
471 | { |
---|
472 | const char *s; |
---|
473 | if ((l!=NULL)&&(l->name!=NULL)) s=l->name; |
---|
474 | else s=sNoName; |
---|
475 | Werror("cannot write to %s",s); |
---|
476 | } |
---|
477 | vf.CleanUp(); |
---|
478 | return b; |
---|
479 | } |
---|
480 | |
---|
481 | leftv iiMap(map theMap, char * what) |
---|
482 | { |
---|
483 | idhdl w,r; |
---|
484 | leftv v; |
---|
485 | int i; |
---|
486 | |
---|
487 | #ifdef HAVE_NAMESPACES |
---|
488 | r=namespaceroot->get(theMap->preimage,myynest); |
---|
489 | #else |
---|
490 | r=idroot->get(theMap->preimage,myynest); |
---|
491 | #endif /* HAVE_NAMESPACES */ |
---|
492 | if ((r!=NULL) && ((r->typ == RING_CMD) || (r->typ== QRING_CMD))) |
---|
493 | { |
---|
494 | if (!nSetMap(IDRING(r)->ch, |
---|
495 | IDRING(r)->parameter, |
---|
496 | IDRING(r)->P, |
---|
497 | IDRING(r)->minpoly)) |
---|
498 | { |
---|
499 | Werror("map from characteristic %d to %d not implemented", |
---|
500 | IDRING(r)->ch,currRing->ch); |
---|
501 | return NULL; |
---|
502 | } |
---|
503 | if (IDELEMS(theMap)<IDRING(r)->N) |
---|
504 | { |
---|
505 | theMap->m=(polyset)ReAlloc((ADDRESS)theMap->m, |
---|
506 | IDELEMS(theMap)*sizeof(poly), |
---|
507 | (IDRING(r)->N)*sizeof(poly)); |
---|
508 | for(i=IDELEMS(theMap);i<IDRING(r)->N;i++) |
---|
509 | theMap->m[i]=NULL; |
---|
510 | IDELEMS(theMap)=IDRING(r)->N; |
---|
511 | } |
---|
512 | if (what==NULL) |
---|
513 | { |
---|
514 | WerrorS("argument of a map must have a name"); |
---|
515 | } |
---|
516 | else if ((w=IDRING(r)->idroot->get(what,myynest))!=NULL) |
---|
517 | { |
---|
518 | v=(leftv)Alloc0(sizeof(*v)); |
---|
519 | sleftv tmpW; |
---|
520 | memset(&tmpW,0,sizeof(sleftv)); |
---|
521 | tmpW.rtyp=IDTYP(w); |
---|
522 | tmpW.data=IDDATA(w); |
---|
523 | if (maApplyFetch(MAP_CMD,theMap,v,&tmpW,IDRING(r),NULL,NULL,0)) |
---|
524 | { |
---|
525 | Werror("cannot map %s(%d)",Tok2Cmdname(w->typ),w->typ); |
---|
526 | Free((ADDRESS)v,sizeof(*v)); |
---|
527 | return NULL; |
---|
528 | } |
---|
529 | return v; |
---|
530 | } |
---|
531 | else |
---|
532 | { |
---|
533 | Werror("%s undefined in %s",what,theMap->preimage); |
---|
534 | } |
---|
535 | } |
---|
536 | else |
---|
537 | { |
---|
538 | Werror("cannot find preimage %s",theMap->preimage); |
---|
539 | } |
---|
540 | return NULL; |
---|
541 | } |
---|
542 | |
---|
543 | #ifdef OLD_RES |
---|
544 | void iiMakeResolv(resolvente r, int length, int rlen, char * name, int typ0, |
---|
545 | intvec ** weights) |
---|
546 | { |
---|
547 | lists L=liMakeResolv(r,length,rlen,typ0,weights); |
---|
548 | int i=0; |
---|
549 | idhdl h; |
---|
550 | char * s=(char *)Alloc(strlen(name)+5); |
---|
551 | |
---|
552 | while (i<=L->nr) |
---|
553 | { |
---|
554 | sprintf(s,"%s(%d)",name,i+1); |
---|
555 | if (i==0) |
---|
556 | h=enterid(mstrdup(s),myynest,typ0,&(currRing->idroot), FALSE); |
---|
557 | else |
---|
558 | h=enterid(mstrdup(s),myynest,MODUL_CMD,&(currRing->idroot), FALSE); |
---|
559 | if (h!=NULL) |
---|
560 | { |
---|
561 | h->data.uideal=(ideal)L->m[i].data; |
---|
562 | h->attribute=L->m[i].attribute; |
---|
563 | if (BVERBOSE(V_DEF_RES)) |
---|
564 | Print("//defining: %s as %d-th syzygy module\n",s,i+1); |
---|
565 | } |
---|
566 | else |
---|
567 | { |
---|
568 | idDelete((ideal *)&(L->m[i].data)); |
---|
569 | Warn("cannot define %s",s); |
---|
570 | } |
---|
571 | //L->m[i].data=NULL; |
---|
572 | //L->m[i].rtyp=0; |
---|
573 | //L->m[i].attribute=NULL; |
---|
574 | i++; |
---|
575 | } |
---|
576 | Free((ADDRESS)L->m,(L->nr+1)*sizeof(sleftv)); |
---|
577 | Free((ADDRESS)L,sizeof(slists)); |
---|
578 | Free((ADDRESS)s,strlen(name)+5); |
---|
579 | } |
---|
580 | #endif |
---|
581 | |
---|
582 | //resolvente iiFindRes(char * name, int * len, int *typ0) |
---|
583 | //{ |
---|
584 | // char *s=(char *)Alloc(strlen(name)+5); |
---|
585 | // int i=-1; |
---|
586 | // resolvente r; |
---|
587 | // idhdl h; |
---|
588 | // |
---|
589 | // do |
---|
590 | // { |
---|
591 | // i++; |
---|
592 | // sprintf(s,"%s(%d)",name,i+1); |
---|
593 | // h=currRing->idroot->get(s,myynest); |
---|
594 | // } while (h!=NULL); |
---|
595 | // *len=i-1; |
---|
596 | // if (*len<=0) |
---|
597 | // { |
---|
598 | // Werror("no objects %s(1),.. found",name); |
---|
599 | // Free((ADDRESS)s,strlen(name)+5); |
---|
600 | // return NULL; |
---|
601 | // } |
---|
602 | // r=(ideal *)Alloc(/*(len+1)*/ i*sizeof(ideal)); |
---|
603 | // memset(r,0,(*len)*sizeof(ideal)); |
---|
604 | // i=-1; |
---|
605 | // *typ0=MODUL_CMD; |
---|
606 | // while (i<(*len)) |
---|
607 | // { |
---|
608 | // i++; |
---|
609 | // sprintf(s,"%s(%d)",name,i+1); |
---|
610 | // h=currRing->idroot->get(s,myynest); |
---|
611 | // if (h->typ != MODUL_CMD) |
---|
612 | // { |
---|
613 | // if ((i!=0) || (h->typ!=IDEAL_CMD)) |
---|
614 | // { |
---|
615 | // Werror("%s is not of type module",s); |
---|
616 | // Free((ADDRESS)r,(*len)*sizeof(ideal)); |
---|
617 | // Free((ADDRESS)s,strlen(name)+5); |
---|
618 | // return NULL; |
---|
619 | // } |
---|
620 | // *typ0=IDEAL_CMD; |
---|
621 | // } |
---|
622 | // if ((i>0) && (idIs0(r[i-1]))) |
---|
623 | // { |
---|
624 | // *len=i-1; |
---|
625 | // break; |
---|
626 | // } |
---|
627 | // r[i]=IDIDEAL(h); |
---|
628 | // } |
---|
629 | // Free((ADDRESS)s,strlen(name)+5); |
---|
630 | // return r; |
---|
631 | //} |
---|
632 | |
---|
633 | static resolvente iiCopyRes(resolvente r, int l) |
---|
634 | { |
---|
635 | int i; |
---|
636 | resolvente res=(ideal *)Alloc0((l+1)*sizeof(ideal)); |
---|
637 | |
---|
638 | for (i=0; i<l; i++) |
---|
639 | res[i]=idCopy(r[i]); |
---|
640 | return res; |
---|
641 | } |
---|
642 | |
---|
643 | BOOLEAN jjMINRES(leftv res, leftv v) |
---|
644 | { |
---|
645 | int len=0; |
---|
646 | int typ0; |
---|
647 | resolvente rr=liFindRes((lists)v->Data(),&len,&typ0); |
---|
648 | if (rr==NULL) return TRUE; |
---|
649 | resolvente r=iiCopyRes(rr,len); |
---|
650 | |
---|
651 | syMinimizeResolvente(r,len,0); |
---|
652 | Free((ADDRESS)rr,len*sizeof(ideal)); |
---|
653 | len++; |
---|
654 | res->data=(char *)liMakeResolv(r,len,-1,typ0,NULL); |
---|
655 | return FALSE; |
---|
656 | } |
---|
657 | |
---|
658 | BOOLEAN jjBETTI(leftv res, leftv v) |
---|
659 | { |
---|
660 | resolvente r; |
---|
661 | int len; |
---|
662 | int reg,typ0; |
---|
663 | |
---|
664 | r=liFindRes((lists)v->Data(),&len,&typ0); |
---|
665 | if (r==NULL) return TRUE; |
---|
666 | res->data=(char *)syBetti(r,len,®); |
---|
667 | Free((ADDRESS)r,(len)*sizeof(ideal)); |
---|
668 | return FALSE; |
---|
669 | } |
---|
670 | |
---|
671 | int iiRegularity(lists L) |
---|
672 | { |
---|
673 | resolvente r; |
---|
674 | int len,reg,typ0; |
---|
675 | intvec * dummy; |
---|
676 | |
---|
677 | r=liFindRes(L,&len,&typ0); |
---|
678 | if (r==NULL) return -2; |
---|
679 | dummy=syBetti(r,len,®); |
---|
680 | Free((ADDRESS)r,len*sizeof(ideal)); |
---|
681 | delete dummy; |
---|
682 | return reg-1; |
---|
683 | } |
---|
684 | |
---|
685 | BOOLEAN iiDebugMarker=TRUE; |
---|
686 | void iiDebug() |
---|
687 | { |
---|
688 | Print("\n-- break point in %s --\n",VoiceName()); |
---|
689 | if (iiDebugMarker) VoiceBackTrack(); |
---|
690 | char * s; |
---|
691 | iiDebugMarker=FALSE; |
---|
692 | s = (char *)AllocL(84); |
---|
693 | fe_fgets_stdin(s,80); |
---|
694 | if (*s=='\n') |
---|
695 | { |
---|
696 | iiDebugMarker=TRUE; |
---|
697 | } |
---|
698 | #if MDEBUG |
---|
699 | else if(strncmp(s,"cont;",5)==0) |
---|
700 | { |
---|
701 | iiDebugMarker=TRUE; |
---|
702 | } |
---|
703 | #endif /* MDEBUG */ |
---|
704 | else |
---|
705 | { |
---|
706 | strcat( s, "\n;~\n"); |
---|
707 | newBuffer(s,BT_execute); |
---|
708 | } |
---|
709 | } |
---|
710 | |
---|
711 | int iiDeclCommand(leftv sy, leftv name, int lev,int t, idhdl* root,BOOLEAN init_b) |
---|
712 | { |
---|
713 | BOOLEAN res=FALSE; |
---|
714 | memset(sy,0,sizeof(sleftv)); |
---|
715 | if ((name->name==NULL)||(isdigit(name->name[0]))) |
---|
716 | { |
---|
717 | WerrorS("object to declare is not a name"); |
---|
718 | res=TRUE; |
---|
719 | } |
---|
720 | else |
---|
721 | { |
---|
722 | //if (name->rtyp!=0) |
---|
723 | //{ |
---|
724 | // Warn("`%s` is already in use",name->name); |
---|
725 | //} |
---|
726 | sy->data = (char *)enterid(name->name,lev,t,root,init_b); |
---|
727 | if (sy->data!=NULL) |
---|
728 | { |
---|
729 | sy->rtyp=IDHDL; |
---|
730 | currid=sy->name=IDID((idhdl)sy->data); |
---|
731 | name->name=NULL; /* used in enterid */ |
---|
732 | //sy->e = NULL; |
---|
733 | if (name->next!=NULL) |
---|
734 | { |
---|
735 | sy->next=(leftv)Alloc(sizeof(sleftv)); |
---|
736 | res=iiDeclCommand(sy->next,name->next,lev,t,root); |
---|
737 | } |
---|
738 | } |
---|
739 | else res=TRUE; |
---|
740 | } |
---|
741 | name->CleanUp(); |
---|
742 | return res; |
---|
743 | } |
---|
744 | |
---|
745 | BOOLEAN iiParameter(leftv p) |
---|
746 | { |
---|
747 | if (iiCurrArgs==NULL) |
---|
748 | { |
---|
749 | if (strcmp(p->name,"#")==0) return FALSE; |
---|
750 | Werror("not enough arguments for proc %s",VoiceName()); |
---|
751 | p->CleanUp(); |
---|
752 | return TRUE; |
---|
753 | } |
---|
754 | leftv h=iiCurrArgs; |
---|
755 | if (strcmp(p->name,"#")==0) |
---|
756 | { |
---|
757 | iiCurrArgs=NULL; |
---|
758 | } |
---|
759 | else |
---|
760 | { |
---|
761 | iiCurrArgs=h->next; |
---|
762 | h->next=NULL; |
---|
763 | } |
---|
764 | BOOLEAN res=iiAssign(p,h); |
---|
765 | Free((ADDRESS)h,sizeof(sleftv)); |
---|
766 | return res; |
---|
767 | } |
---|
768 | |
---|
769 | BOOLEAN iiExport (leftv v, int toLev) |
---|
770 | { |
---|
771 | BOOLEAN nok=FALSE; |
---|
772 | leftv r=v; |
---|
773 | while (v!=NULL) |
---|
774 | { |
---|
775 | if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL)) |
---|
776 | { |
---|
777 | WerrorS("cannot export"); |
---|
778 | nok=TRUE; |
---|
779 | } |
---|
780 | else |
---|
781 | { |
---|
782 | idhdl h=(idhdl)v->data; |
---|
783 | if (IDLEV(h)==0) Warn("`%s` is already global",IDID(h)); |
---|
784 | else |
---|
785 | { |
---|
786 | #ifdef HAVE_NAMESPACES |
---|
787 | h=namespaceroot->get(v->name,toLev); |
---|
788 | #else /* HAVE_NAMESPACES */ |
---|
789 | h=idroot->get(v->name,toLev); |
---|
790 | #endif /* HAVE_NAMESPACES */ |
---|
791 | idhdl *root=&IDROOT; |
---|
792 | if ((h==NULL)&&(currRing!=NULL)) |
---|
793 | { |
---|
794 | h=currRing->idroot->get(v->name,toLev); |
---|
795 | root=&currRing->idroot; |
---|
796 | } |
---|
797 | if ((h!=NULL)&&(IDLEV(h)==toLev)) |
---|
798 | { |
---|
799 | if (IDTYP(h)==v->Typ()) |
---|
800 | { |
---|
801 | Warn("redefining %s",IDID(h)); |
---|
802 | if (iiLocalRing[0]==IDRING(h)) iiLocalRing[0]=NULL; |
---|
803 | killhdl(h,root); |
---|
804 | } |
---|
805 | else |
---|
806 | { |
---|
807 | r->CleanUp(); |
---|
808 | return TRUE; |
---|
809 | } |
---|
810 | } |
---|
811 | h=(idhdl)v->data; |
---|
812 | IDLEV(h)=toLev; |
---|
813 | iiNoKeepRing=FALSE; |
---|
814 | } |
---|
815 | } |
---|
816 | v=v->next; |
---|
817 | } |
---|
818 | r->CleanUp(); |
---|
819 | return nok; |
---|
820 | } |
---|
821 | |
---|
822 | /*assume root!=idroot*/ |
---|
823 | BOOLEAN iiExport (leftv v, int toLev, idhdl &root) |
---|
824 | { |
---|
825 | BOOLEAN nok=FALSE; |
---|
826 | leftv rv=v; |
---|
827 | while (v!=NULL) |
---|
828 | { |
---|
829 | if ((v->name==NULL)||(v->rtyp==0)||(v->e!=NULL) |
---|
830 | ) |
---|
831 | { |
---|
832 | WerrorS("cannot export"); |
---|
833 | nok=TRUE; |
---|
834 | } |
---|
835 | else |
---|
836 | { |
---|
837 | idhdl old=root->get(v->name,toLev); |
---|
838 | if (old!=NULL) |
---|
839 | { |
---|
840 | if (IDTYP(old)==v->Typ()) |
---|
841 | { |
---|
842 | Warn("redefining %s",IDID(old)); |
---|
843 | killhdl(old,&root); |
---|
844 | } |
---|
845 | else |
---|
846 | { |
---|
847 | rv->CleanUp(); |
---|
848 | return TRUE; |
---|
849 | } |
---|
850 | } |
---|
851 | idhdl h=(idhdl)v->data; |
---|
852 | if (h==IDROOT) |
---|
853 | { |
---|
854 | IDROOT=h->next; |
---|
855 | } |
---|
856 | else |
---|
857 | { |
---|
858 | idhdl hh=IDROOT; |
---|
859 | while ((hh->next!=h)&&(hh->next!=NULL)) |
---|
860 | hh=hh->next; |
---|
861 | if (hh->next==h) |
---|
862 | hh->next=h->next; |
---|
863 | else |
---|
864 | break; |
---|
865 | } |
---|
866 | h->next=root; |
---|
867 | root=h; |
---|
868 | IDLEV(h)=toLev; |
---|
869 | } |
---|
870 | v=v->next; |
---|
871 | } |
---|
872 | rv->CleanUp(); |
---|
873 | return nok; |
---|
874 | } |
---|
875 | |
---|
876 | BOOLEAN iiCheckRing(int i) |
---|
877 | { |
---|
878 | if (currRingHdl==NULL) |
---|
879 | { |
---|
880 | #ifdef SIQ |
---|
881 | if (siq<=0) |
---|
882 | { |
---|
883 | #endif |
---|
884 | if ((i>BEGIN_RING) && (i<END_RING)) |
---|
885 | { |
---|
886 | WerrorS("no ring active"); |
---|
887 | return TRUE; |
---|
888 | } |
---|
889 | #ifdef SIQ |
---|
890 | } |
---|
891 | #endif |
---|
892 | } |
---|
893 | return FALSE; |
---|
894 | } |
---|