1 | /*****************************************************************************\ |
---|
2 | * Computer Algebra System SINGULAR |
---|
3 | \*****************************************************************************/ |
---|
4 | /** @file misc_ip.cc |
---|
5 | * |
---|
6 | * This file provides miscellaneous functionality. |
---|
7 | * |
---|
8 | * For more general information, see the documentation in misc_ip.h. |
---|
9 | * |
---|
10 | **/ |
---|
11 | /*****************************************************************************/ |
---|
12 | |
---|
13 | // include header files |
---|
14 | #include <misc/auxiliary.h> |
---|
15 | #include "config.h" |
---|
16 | #include <kernel/mod2.h> |
---|
17 | |
---|
18 | #ifdef HAVE_FACTORY |
---|
19 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
20 | #include <factory/factory.h> |
---|
21 | #endif |
---|
22 | |
---|
23 | #include <coeffs/si_gmp.h> |
---|
24 | #include <coeffs/coeffs.h> |
---|
25 | |
---|
26 | #include <polys/ext_fields/algext.h> |
---|
27 | #include <polys/ext_fields/transext.h> |
---|
28 | |
---|
29 | #include "misc_ip.h" |
---|
30 | #include "ipid.h" |
---|
31 | #include "feOpt.h" |
---|
32 | #include "silink.h" |
---|
33 | |
---|
34 | // the following 2 inline functions are just convenience shortcuts for Frank's code: |
---|
35 | static inline void number2mpz(number n, mpz_t m){ n_MPZ(m, n, coeffs_BIGINT); } |
---|
36 | static inline number mpz2number(mpz_t m){ return n_InitMPZ(m, coeffs_BIGINT); } |
---|
37 | |
---|
38 | |
---|
39 | void divTimes(mpz_t n, mpz_t d, int* times) |
---|
40 | { |
---|
41 | *times = 0; |
---|
42 | mpz_t r; mpz_init(r); |
---|
43 | mpz_t q; mpz_init(q); |
---|
44 | mpz_fdiv_qr(q, r, n, d); |
---|
45 | while (mpz_cmp_ui(r, 0) == 0) |
---|
46 | { |
---|
47 | (*times)++; |
---|
48 | mpz_set(n, q); |
---|
49 | mpz_fdiv_qr(q, r, n, d); |
---|
50 | } |
---|
51 | mpz_clear(r); |
---|
52 | mpz_clear(q); |
---|
53 | } |
---|
54 | |
---|
55 | void divTimes_ui(mpz_t n, unsigned long d, int* times) |
---|
56 | { |
---|
57 | *times = 0; |
---|
58 | mpz_t r; mpz_init(r); |
---|
59 | mpz_t q; mpz_init(q); |
---|
60 | mpz_fdiv_qr_ui(q, r, n, d); |
---|
61 | while (mpz_cmp_ui(r, 0) == 0) |
---|
62 | { |
---|
63 | (*times)++; |
---|
64 | mpz_set(n, q); |
---|
65 | mpz_fdiv_qr_ui(q, r, n, d); |
---|
66 | } |
---|
67 | mpz_clear(r); |
---|
68 | mpz_clear(q); |
---|
69 | } |
---|
70 | |
---|
71 | static inline void divTimes_ui_ui(unsigned long *n, unsigned long d, int* times) |
---|
72 | { |
---|
73 | *times = 0; |
---|
74 | unsigned long q=(*n) / d; |
---|
75 | unsigned long r=(*n) % d; |
---|
76 | while (r==0) |
---|
77 | { |
---|
78 | (*times)++; |
---|
79 | (*n)=q; |
---|
80 | q=(*n)/d; r=(*n)%d; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | void setListEntry(lists L, int index, mpz_t n) |
---|
85 | { /* assumes n > 0 */ |
---|
86 | /* try to fit nn into an int: */ |
---|
87 | if (mpz_size1(n)<=1) |
---|
88 | { |
---|
89 | int ui=(int)mpz_get_si(n); |
---|
90 | if ((((ui<<3)>>3)==ui) |
---|
91 | && (mpz_cmp_si(n,(long)ui)==0)) |
---|
92 | { |
---|
93 | L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)ui; |
---|
94 | return; |
---|
95 | } |
---|
96 | } |
---|
97 | number nn = mpz2number(n); |
---|
98 | L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn; |
---|
99 | } |
---|
100 | |
---|
101 | void setListEntry_ui(lists L, int index, unsigned long ui) |
---|
102 | { /* assumes n > 0 */ |
---|
103 | /* try to fit nn into an int: */ |
---|
104 | int i=(int)ui; |
---|
105 | if ((((unsigned long)i)==ui) && (((i<<3)>>3)==i)) |
---|
106 | { |
---|
107 | L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)i; |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | number nn = n_Init(ui, coeffs_BIGINT); |
---|
112 | L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | /* true iff p is prime */ |
---|
117 | /* |
---|
118 | bool isPrime(mpz_t p) |
---|
119 | { |
---|
120 | if (mpz_cmp_ui(p, 2) == 0) return true; |
---|
121 | if (mpz_cmp_ui(p, 3) == 0) return true; |
---|
122 | if (mpz_cmp_ui(p, 5) < 0) return false; |
---|
123 | |
---|
124 | mpz_t d; mpz_init_set_ui(d, 5); int add = 2; |
---|
125 | mpz_t sr; mpz_init(sr); mpz_sqrt(sr, p); |
---|
126 | mpz_t r; mpz_init(r); |
---|
127 | while (mpz_cmp(d, sr) <= 0) |
---|
128 | { |
---|
129 | mpz_cdiv_r(r, p, d); |
---|
130 | if (mpz_cmp_ui(r, 0) == 0) |
---|
131 | { |
---|
132 | mpz_clear(d); mpz_clear(sr); mpz_clear(r); |
---|
133 | return false; |
---|
134 | } |
---|
135 | mpz_add_ui(d, d, add); |
---|
136 | add += 2; if (add == 6) add = 2; |
---|
137 | } |
---|
138 | mpz_clear(d); mpz_clear(sr); mpz_clear(r); |
---|
139 | return true; |
---|
140 | } |
---|
141 | */ |
---|
142 | |
---|
143 | /* finds the next prime q, bound >= q >= p; |
---|
144 | in case of success, puts q into p; |
---|
145 | otherwise sets q = bound + 1; |
---|
146 | e.g. p = 24; nextPrime(p, 30) produces p = 29 (success), |
---|
147 | p = 24; nextPrime(p, 29) produces p = 29 (success), |
---|
148 | p = 24; nextPrime(p, 28) produces p = 29 (no success), |
---|
149 | p = 24; nextPrime(p, 27) produces p = 28 (no success) */ |
---|
150 | /* |
---|
151 | void nextPrime(mpz_t p, mpz_t bound) |
---|
152 | { |
---|
153 | int add; |
---|
154 | mpz_t r; mpz_init(r); mpz_cdiv_r_ui(r, p, 6); // r = p mod 6, 0 <= r <= 5 |
---|
155 | if (mpz_cmp_ui(r, 0) == 0) { mpz_add_ui(p, p, 1); add = 4; } |
---|
156 | if (mpz_cmp_ui(r, 1) == 0) { add = 4; } |
---|
157 | if (mpz_cmp_ui(r, 2) == 0) { mpz_add_ui(p, p, 3); add = 2; } |
---|
158 | if (mpz_cmp_ui(r, 3) == 0) { mpz_add_ui(p, p, 2); add = 2; } |
---|
159 | if (mpz_cmp_ui(r, 4) == 0) { mpz_add_ui(p, p, 1); add = 2; } |
---|
160 | if (mpz_cmp_ui(r, 5) == 0) { add = 2; } |
---|
161 | |
---|
162 | while (mpz_cmp(p, bound) <= 0) |
---|
163 | { |
---|
164 | if (isPrime(p)) { mpz_clear(r); return; } |
---|
165 | mpz_add_ui(p, p, add); |
---|
166 | add += 2; if (add == 6) add = 2; |
---|
167 | } |
---|
168 | mpz_set(p, bound); |
---|
169 | mpz_add_ui(p, p, 1); |
---|
170 | mpz_clear(r); |
---|
171 | return; |
---|
172 | } |
---|
173 | */ |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | /* n and pBound are assumed to be bigint numbers */ |
---|
178 | lists primeFactorisation(const number n, const number pBound) |
---|
179 | { |
---|
180 | mpz_t nn; number2mpz(n, nn); |
---|
181 | mpz_t pb; number2mpz(pBound, pb); |
---|
182 | mpz_t b; number2mpz(pBound, b); |
---|
183 | mpz_t p; mpz_init(p); int tt; |
---|
184 | mpz_t sr; mpz_init(sr); int index = 0; int add; |
---|
185 | lists primes = (lists)omAllocBin(slists_bin); primes->Init(1000); |
---|
186 | int* multiplicities = new int[1000]; |
---|
187 | int positive=1; int probTest = 0; |
---|
188 | |
---|
189 | if (!n_IsZero(n, coeffs_BIGINT)) |
---|
190 | { |
---|
191 | if (!n_GreaterZero(n, coeffs_BIGINT)) |
---|
192 | { |
---|
193 | positive=-1; |
---|
194 | mpz_neg(nn,nn); |
---|
195 | } |
---|
196 | divTimes_ui(nn, 2, &tt); |
---|
197 | if (tt > 0) |
---|
198 | { |
---|
199 | setListEntry_ui(primes, index, 2); |
---|
200 | multiplicities[index++] = tt; |
---|
201 | } |
---|
202 | |
---|
203 | divTimes_ui(nn, 3, &tt); |
---|
204 | if (tt > 0) |
---|
205 | { |
---|
206 | setListEntry_ui(primes, index, 3); |
---|
207 | multiplicities[index++] = tt; |
---|
208 | } |
---|
209 | |
---|
210 | unsigned long p_ui=5; add = 2; |
---|
211 | BOOLEAN b_is_0=(mpz_cmp_ui(b, 0) == 0); |
---|
212 | BOOLEAN sr_sets_pb=FALSE; |
---|
213 | mpz_sqrt(sr, nn); |
---|
214 | // there are 3 possible limits, we take the minimum: |
---|
215 | // - argument pBound (if >0) |
---|
216 | // - sr = sqrt(nn) |
---|
217 | // - 1<<31 |
---|
218 | unsigned long limit=~(0L); |
---|
219 | if (b_is_0 || (mpz_cmp(pb, sr) > 0)) |
---|
220 | { |
---|
221 | mpz_set(pb, sr); |
---|
222 | sr_sets_pb=TRUE; |
---|
223 | } |
---|
224 | if (mpz_cmp_ui(pb, limit)<0) |
---|
225 | { |
---|
226 | limit=mpz_get_ui(pb); |
---|
227 | } |
---|
228 | else |
---|
229 | { |
---|
230 | mpz_set_ui(pb,limit); |
---|
231 | } |
---|
232 | while (p_ui <=limit) |
---|
233 | { |
---|
234 | divTimes_ui(nn, p_ui, &tt); |
---|
235 | if (tt > 0) |
---|
236 | { |
---|
237 | setListEntry_ui(primes, index, p_ui); |
---|
238 | multiplicities[index++] = tt; |
---|
239 | //mpz_sqrt(sr, nn); |
---|
240 | //if ((mpz_cmp_ui(b, 0) == 0) || (mpz_cmp(pb, sr) > 0)) mpz_set(pb, sr); |
---|
241 | if (mpz_size1(nn)<=2) |
---|
242 | { |
---|
243 | mpz_sqrt(sr, nn); |
---|
244 | if (sr_sets_pb || (mpz_cmp(pb, sr) > 0)) mpz_set(pb, sr); |
---|
245 | unsigned long l=mpz_get_ui(sr); |
---|
246 | if (l<limit) { limit=l; } |
---|
247 | if (mpz_size1(nn)<=1) |
---|
248 | { |
---|
249 | unsigned long nn_ui=mpz_get_ui(nn); |
---|
250 | while (p_ui <=limit) |
---|
251 | { |
---|
252 | divTimes_ui_ui(&nn_ui, p_ui, &tt); |
---|
253 | if (tt > 0) |
---|
254 | { |
---|
255 | setListEntry_ui(primes, index, p_ui); |
---|
256 | multiplicities[index++] = tt; |
---|
257 | if (nn_ui==1) break; |
---|
258 | if (nn_ui<(limit/6)) { limit=nn_ui/6;} |
---|
259 | } |
---|
260 | p_ui +=add; |
---|
261 | //add += 2; if (add == 6) add = 2; |
---|
262 | add =2+2*(add==2); |
---|
263 | } |
---|
264 | mpz_set_ui(nn,nn_ui); |
---|
265 | break; |
---|
266 | } |
---|
267 | } |
---|
268 | } |
---|
269 | p_ui +=add; |
---|
270 | //add += 2; if (add == 6) add = 2; |
---|
271 | add =2+2*(add==2); |
---|
272 | } |
---|
273 | mpz_set_ui(p, p_ui); |
---|
274 | mpz_sqrt(sr, nn); |
---|
275 | if (b_is_0 || sr_sets_pb || (mpz_cmp(pb, sr) > 0)) mpz_set(pb, sr); |
---|
276 | while (mpz_cmp(pb, p) >= 0) |
---|
277 | { |
---|
278 | divTimes(nn, p, &tt); |
---|
279 | if (tt > 0) |
---|
280 | { |
---|
281 | setListEntry(primes, index, p); |
---|
282 | multiplicities[index++] = tt; |
---|
283 | if (mpz_cmp_ui(nn,1)==0) break; |
---|
284 | mpz_sqrt(sr, nn); |
---|
285 | if (b_is_0 || sr_sets_pb || (mpz_cmp(pb, sr) > 0)) mpz_set(pb, sr); |
---|
286 | } |
---|
287 | mpz_add_ui(p, p, add); |
---|
288 | //add += 2; if (add == 6) add = 2; |
---|
289 | add =2+2*(add==2); |
---|
290 | } |
---|
291 | if ((mpz_cmp_ui(nn, 1) > 0) && |
---|
292 | (b_is_0 || (mpz_cmp(nn, b) <= 0))) |
---|
293 | { |
---|
294 | setListEntry(primes, index, nn); |
---|
295 | multiplicities[index++] = 1; |
---|
296 | mpz_set_ui(nn, 1); |
---|
297 | } |
---|
298 | if ((mpz_cmp_ui(nn, 1) > 0) && (mpz_probab_prime_p(nn, 25) != 0)) |
---|
299 | probTest = 1; |
---|
300 | } |
---|
301 | |
---|
302 | lists primesL = (lists)omAllocBin(slists_bin); |
---|
303 | primesL->Init(index); |
---|
304 | for (int i = 0; i < index; i++) |
---|
305 | { |
---|
306 | primesL->m[i].rtyp = primes->m[i].rtyp; |
---|
307 | primesL->m[i].data = primes->m[i].data; |
---|
308 | } |
---|
309 | omFreeSize((ADDRESS)primes->m, (primes->nr + 1) * sizeof(sleftv)); |
---|
310 | omFreeBin((ADDRESS)primes, slists_bin); |
---|
311 | |
---|
312 | lists multiplicitiesL = (lists)omAllocBin(slists_bin); |
---|
313 | multiplicitiesL->Init(index); |
---|
314 | for (int i = 0; i < index; i++) |
---|
315 | { |
---|
316 | multiplicitiesL->m[i].rtyp = INT_CMD; |
---|
317 | multiplicitiesL->m[i].data = (void*)multiplicities[i]; |
---|
318 | } |
---|
319 | delete[] multiplicities; |
---|
320 | |
---|
321 | lists L=(lists)omAllocBin(slists_bin); |
---|
322 | L->Init(4); |
---|
323 | if (positive==-1) mpz_neg(nn,nn); |
---|
324 | L->m[0].rtyp = LIST_CMD; L->m[0].data = (void*)primesL; |
---|
325 | L->m[1].rtyp = LIST_CMD; L->m[1].data = (void*)multiplicitiesL; |
---|
326 | setListEntry(L, 2, nn); |
---|
327 | L->m[3].rtyp = INT_CMD; L->m[3].data = (void*)probTest; |
---|
328 | mpz_clear(nn); mpz_clear(pb); mpz_clear(b); mpz_clear(p); mpz_clear(sr); |
---|
329 | |
---|
330 | return L; |
---|
331 | } |
---|
332 | |
---|
333 | #include <omalloc/omalloc.h> |
---|
334 | #include <misc/mylimits.h> |
---|
335 | |
---|
336 | #include <misc/options.h> |
---|
337 | #include <misc/intvec.h> |
---|
338 | |
---|
339 | #include <polys/monomials/ring.h> |
---|
340 | #include <polys/templates/p_Procs.h> |
---|
341 | |
---|
342 | #include <kernel/febase.h> |
---|
343 | #include <kernel/kstd1.h> |
---|
344 | #include <kernel/timer.h> |
---|
345 | |
---|
346 | |
---|
347 | #include "subexpr.h" |
---|
348 | #include "cntrlc.h" |
---|
349 | #include "ipid.h" |
---|
350 | #include "ipshell.h" |
---|
351 | |
---|
352 | #include "version.h" |
---|
353 | |
---|
354 | #include "fehelp.h" |
---|
355 | |
---|
356 | #ifdef HAVE_STATIC |
---|
357 | #undef HAVE_DYN_RL |
---|
358 | #endif |
---|
359 | |
---|
360 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
361 | |
---|
362 | //#ifdef HAVE_LIBPARSER |
---|
363 | //# include "libparse.h" |
---|
364 | //#endif /* HAVE_LIBPARSER */ |
---|
365 | |
---|
366 | |
---|
367 | /*2 |
---|
368 | * the renice routine for very large jobs |
---|
369 | * works only on unix machines, |
---|
370 | * testet on : linux, HP 9.0 |
---|
371 | * |
---|
372 | *#include <sys/times.h> |
---|
373 | *#include <sys/resource.h> |
---|
374 | *extern "C" int setpriority(int,int,int); |
---|
375 | *void very_nice() |
---|
376 | *{ |
---|
377 | *#ifndef NO_SETPRIORITY |
---|
378 | * setpriority(PRIO_PROCESS,0,19); |
---|
379 | *#endif |
---|
380 | * sleep(10); |
---|
381 | *} |
---|
382 | */ |
---|
383 | |
---|
384 | #include <string.h> |
---|
385 | #include <unistd.h> |
---|
386 | #include <stdio.h> |
---|
387 | #include <stddef.h> |
---|
388 | #include <stdlib.h> |
---|
389 | #include <time.h> |
---|
390 | |
---|
391 | |
---|
392 | void singular_example(char *str) |
---|
393 | { |
---|
394 | assume(str!=NULL); |
---|
395 | char *s=str; |
---|
396 | while (*s==' ') s++; |
---|
397 | char *ss=s; |
---|
398 | while (*ss!='\0') ss++; |
---|
399 | while (*ss<=' ') |
---|
400 | { |
---|
401 | *ss='\0'; |
---|
402 | ss--; |
---|
403 | } |
---|
404 | idhdl h=IDROOT->get(s,myynest); |
---|
405 | if ((h!=NULL) && (IDTYP(h)==PROC_CMD)) |
---|
406 | { |
---|
407 | char *lib=iiGetLibName(IDPROC(h)); |
---|
408 | if((lib!=NULL)&&(*lib!='\0')) |
---|
409 | { |
---|
410 | Print("// proc %s from lib %s\n",s,lib); |
---|
411 | s=iiGetLibProcBuffer(IDPROC(h), 2); |
---|
412 | if (s!=NULL) |
---|
413 | { |
---|
414 | if (strlen(s)>5) |
---|
415 | { |
---|
416 | iiEStart(s,IDPROC(h)); |
---|
417 | omFree((ADDRESS)s); |
---|
418 | return; |
---|
419 | } |
---|
420 | else omFree((ADDRESS)s); |
---|
421 | } |
---|
422 | } |
---|
423 | } |
---|
424 | else |
---|
425 | { |
---|
426 | char sing_file[MAXPATHLEN]; |
---|
427 | FILE *fd=NULL; |
---|
428 | char *res_m=feResource('m', 0); |
---|
429 | if (res_m!=NULL) |
---|
430 | { |
---|
431 | sprintf(sing_file, "%s/%s.sing", res_m, s); |
---|
432 | fd = feFopen(sing_file, "r"); |
---|
433 | } |
---|
434 | if (fd != NULL) |
---|
435 | { |
---|
436 | |
---|
437 | int old_echo = si_echo; |
---|
438 | int length, got; |
---|
439 | char* s; |
---|
440 | |
---|
441 | fseek(fd, 0, SEEK_END); |
---|
442 | length = ftell(fd); |
---|
443 | fseek(fd, 0, SEEK_SET); |
---|
444 | s = (char*) omAlloc((length+20)*sizeof(char)); |
---|
445 | got = fread(s, sizeof(char), length, fd); |
---|
446 | fclose(fd); |
---|
447 | if (got != length) |
---|
448 | { |
---|
449 | Werror("Error while reading file %s", sing_file); |
---|
450 | } |
---|
451 | else |
---|
452 | { |
---|
453 | s[length] = '\0'; |
---|
454 | strcat(s, "\n;return();\n\n"); |
---|
455 | si_echo = 2; |
---|
456 | iiEStart(s, NULL); |
---|
457 | si_echo = old_echo; |
---|
458 | } |
---|
459 | omFree(s); |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | Werror("no example for %s", str); |
---|
464 | } |
---|
465 | } |
---|
466 | } |
---|
467 | |
---|
468 | |
---|
469 | struct soptionStruct |
---|
470 | { |
---|
471 | const char * name; |
---|
472 | unsigned setval; |
---|
473 | unsigned resetval; |
---|
474 | }; |
---|
475 | |
---|
476 | struct soptionStruct optionStruct[]= |
---|
477 | { |
---|
478 | {"prot", Sy_bit(OPT_PROT), ~Sy_bit(OPT_PROT) }, |
---|
479 | {"redSB", Sy_bit(OPT_REDSB), ~Sy_bit(OPT_REDSB) }, |
---|
480 | {"notBuckets", Sy_bit(OPT_NOT_BUCKETS), ~Sy_bit(OPT_NOT_BUCKETS) }, |
---|
481 | {"notSugar", Sy_bit(OPT_NOT_SUGAR), ~Sy_bit(OPT_NOT_SUGAR) }, |
---|
482 | {"interrupt", Sy_bit(OPT_INTERRUPT), ~Sy_bit(OPT_INTERRUPT) }, |
---|
483 | {"sugarCrit", Sy_bit(OPT_SUGARCRIT), ~Sy_bit(OPT_SUGARCRIT) }, |
---|
484 | {"teach", Sy_bit(OPT_DEBUG), ~Sy_bit(OPT_DEBUG) }, |
---|
485 | {"notSyzMinim", Sy_bit(OPT_NO_SYZ_MINIM), ~Sy_bit(OPT_NO_SYZ_MINIM) }, |
---|
486 | /* 9 return SB in syz, quotient, intersect */ |
---|
487 | {"returnSB", Sy_bit(OPT_RETURN_SB), ~Sy_bit(OPT_RETURN_SB) }, |
---|
488 | {"fastHC", Sy_bit(OPT_FASTHC), ~Sy_bit(OPT_FASTHC) }, |
---|
489 | /* 11-19 sort in L/T */ |
---|
490 | {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND) }, |
---|
491 | {"multBound", Sy_bit(OPT_MULTBOUND), ~Sy_bit(OPT_MULTBOUND) }, |
---|
492 | {"degBound", Sy_bit(OPT_DEGBOUND), ~Sy_bit(OPT_DEGBOUND) }, |
---|
493 | /* 25 no redTail(p)/redTail(s) */ |
---|
494 | {"redTail", Sy_bit(OPT_REDTAIL), ~Sy_bit(OPT_REDTAIL) }, |
---|
495 | {"redThrough", Sy_bit(OPT_REDTHROUGH), ~Sy_bit(OPT_REDTHROUGH) }, |
---|
496 | {"lazy", Sy_bit(OPT_OLDSTD), ~Sy_bit(OPT_OLDSTD) }, |
---|
497 | {"intStrategy", Sy_bit(OPT_INTSTRATEGY), ~Sy_bit(OPT_INTSTRATEGY) }, |
---|
498 | {"infRedTail", Sy_bit(OPT_INFREDTAIL), ~Sy_bit(OPT_INFREDTAIL) }, |
---|
499 | /* 30: use not regularity for syz */ |
---|
500 | {"notRegularity",Sy_bit(OPT_NOTREGULARITY), ~Sy_bit(OPT_NOTREGULARITY) }, |
---|
501 | {"weightM", Sy_bit(OPT_WEIGHTM), ~Sy_bit(OPT_WEIGHTM) }, |
---|
502 | /*special for "none" and also end marker for showOption:*/ |
---|
503 | {"ne", 0, 0 } |
---|
504 | }; |
---|
505 | |
---|
506 | struct soptionStruct verboseStruct[]= |
---|
507 | { |
---|
508 | {"mem", Sy_bit(V_SHOW_MEM), ~Sy_bit(V_SHOW_MEM) }, |
---|
509 | {"yacc", Sy_bit(V_YACC), ~Sy_bit(V_YACC) }, |
---|
510 | {"redefine", Sy_bit(V_REDEFINE), ~Sy_bit(V_REDEFINE) }, |
---|
511 | {"reading", Sy_bit(V_READING), ~Sy_bit(V_READING) }, |
---|
512 | {"loadLib", Sy_bit(V_LOAD_LIB), ~Sy_bit(V_LOAD_LIB) }, |
---|
513 | {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB) }, |
---|
514 | {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC) }, |
---|
515 | {"defRes", Sy_bit(V_DEF_RES), ~Sy_bit(V_DEF_RES) }, |
---|
516 | {"usage", Sy_bit(V_SHOW_USE), ~Sy_bit(V_SHOW_USE) }, |
---|
517 | {"Imap", Sy_bit(V_IMAP), ~Sy_bit(V_IMAP) }, |
---|
518 | {"prompt", Sy_bit(V_PROMPT), ~Sy_bit(V_PROMPT) }, |
---|
519 | {"length", Sy_bit(V_LENGTH), ~Sy_bit(V_LENGTH) }, |
---|
520 | {"notWarnSB",Sy_bit(V_NSB), ~Sy_bit(V_NSB) }, |
---|
521 | {"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB) }, |
---|
522 | {"cancelunit",Sy_bit(V_CANCELUNIT),~Sy_bit(V_CANCELUNIT)}, |
---|
523 | {"modpsolve",Sy_bit(V_MODPSOLVSB),~Sy_bit(V_MODPSOLVSB)}, |
---|
524 | {"geometricSB",Sy_bit(V_UPTORADICAL),~Sy_bit(V_UPTORADICAL)}, |
---|
525 | {"findMonomials",Sy_bit(V_FINDMONOM),~Sy_bit(V_FINDMONOM)}, |
---|
526 | {"coefStrat",Sy_bit(V_COEFSTRAT), ~Sy_bit(V_COEFSTRAT)}, |
---|
527 | {"qringNF", Sy_bit(V_QRING), ~Sy_bit(V_QRING)}, |
---|
528 | {"warn", Sy_bit(V_ALLWARN), ~Sy_bit(V_ALLWARN)}, |
---|
529 | {"interedSyz",Sy_bit(V_INTERSECT_SYZ), ~Sy_bit(V_INTERSECT_SYZ)}, |
---|
530 | {"interedElim",Sy_bit(V_INTERSECT_ELIM), ~Sy_bit(V_INTERSECT_ELIM)}, |
---|
531 | /*special for "none" and also end marker for showOption:*/ |
---|
532 | {"ne", 0, 0 } |
---|
533 | }; |
---|
534 | |
---|
535 | BOOLEAN setOption(leftv res, leftv v) |
---|
536 | { |
---|
537 | const char *n; |
---|
538 | do |
---|
539 | { |
---|
540 | if (v->Typ()==STRING_CMD) |
---|
541 | { |
---|
542 | n=(const char *)v->CopyD(STRING_CMD); |
---|
543 | } |
---|
544 | else |
---|
545 | { |
---|
546 | if (v->name==NULL) |
---|
547 | return TRUE; |
---|
548 | if (v->rtyp==0) |
---|
549 | { |
---|
550 | n=v->name; |
---|
551 | v->name=NULL; |
---|
552 | } |
---|
553 | else |
---|
554 | { |
---|
555 | n=omStrDup(v->name); |
---|
556 | } |
---|
557 | } |
---|
558 | |
---|
559 | int i; |
---|
560 | |
---|
561 | if(strcmp(n,"get")==0) |
---|
562 | { |
---|
563 | intvec *w=new intvec(2); |
---|
564 | (*w)[0]=si_opt_1; |
---|
565 | (*w)[1]=si_opt_2; |
---|
566 | res->rtyp=INTVEC_CMD; |
---|
567 | res->data=(void *)w; |
---|
568 | goto okay; |
---|
569 | } |
---|
570 | if(strcmp(n,"set")==0) |
---|
571 | { |
---|
572 | if((v->next!=NULL) |
---|
573 | &&(v->next->Typ()==INTVEC_CMD)) |
---|
574 | { |
---|
575 | v=v->next; |
---|
576 | intvec *w=(intvec*)v->Data(); |
---|
577 | si_opt_1=(*w)[0]; |
---|
578 | si_opt_2=(*w)[1]; |
---|
579 | #if 0 |
---|
580 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
581 | && rField_has_simple_inverse() |
---|
582 | #ifdef HAVE_RINGS |
---|
583 | && !rField_is_Ring(currRing) |
---|
584 | #endif |
---|
585 | ) { |
---|
586 | si_opt_1 &=~Sy_bit(OPT_INTSTRATEGY); |
---|
587 | } |
---|
588 | #endif |
---|
589 | goto okay; |
---|
590 | } |
---|
591 | } |
---|
592 | if(strcmp(n,"none")==0) |
---|
593 | { |
---|
594 | si_opt_1=0; |
---|
595 | si_opt_2=0; |
---|
596 | goto okay; |
---|
597 | } |
---|
598 | for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++) |
---|
599 | { |
---|
600 | if (strcmp(n,optionStruct[i].name)==0) |
---|
601 | { |
---|
602 | if (optionStruct[i].setval & validOpts) |
---|
603 | { |
---|
604 | si_opt_1 |= optionStruct[i].setval; |
---|
605 | // optOldStd disables redthrough |
---|
606 | if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD)) |
---|
607 | si_opt_1 &= ~Sy_bit(OPT_REDTHROUGH); |
---|
608 | } |
---|
609 | else |
---|
610 | Warn("cannot set option"); |
---|
611 | #if 0 |
---|
612 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
613 | && rField_has_simple_inverse() |
---|
614 | #ifdef HAVE_RINGS |
---|
615 | && !rField_is_Ring(currRing) |
---|
616 | #endif |
---|
617 | ) { |
---|
618 | test &=~Sy_bit(OPT_INTSTRATEGY); |
---|
619 | } |
---|
620 | #endif |
---|
621 | goto okay; |
---|
622 | } |
---|
623 | else if ((strncmp(n,"no",2)==0) |
---|
624 | && (strcmp(n+2,optionStruct[i].name)==0)) |
---|
625 | { |
---|
626 | if (optionStruct[i].setval & validOpts) |
---|
627 | { |
---|
628 | si_opt_1 &= optionStruct[i].resetval; |
---|
629 | } |
---|
630 | else |
---|
631 | Warn("cannot clear option"); |
---|
632 | goto okay; |
---|
633 | } |
---|
634 | } |
---|
635 | for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++) |
---|
636 | { |
---|
637 | if (strcmp(n,verboseStruct[i].name)==0) |
---|
638 | { |
---|
639 | si_opt_2 |= verboseStruct[i].setval; |
---|
640 | #ifdef YYDEBUG |
---|
641 | #if YYDEBUG |
---|
642 | /*debugging the bison grammar --> grammar.cc*/ |
---|
643 | extern int yydebug; |
---|
644 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
645 | else yydebug=0; |
---|
646 | #endif |
---|
647 | #endif |
---|
648 | goto okay; |
---|
649 | } |
---|
650 | else if ((strncmp(n,"no",2)==0) |
---|
651 | && (strcmp(n+2,verboseStruct[i].name)==0)) |
---|
652 | { |
---|
653 | si_opt_2 &= verboseStruct[i].resetval; |
---|
654 | #ifdef YYDEBUG |
---|
655 | #if YYDEBUG |
---|
656 | /*debugging the bison grammar --> grammar.cc*/ |
---|
657 | extern int yydebug; |
---|
658 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
659 | else yydebug=0; |
---|
660 | #endif |
---|
661 | #endif |
---|
662 | goto okay; |
---|
663 | } |
---|
664 | } |
---|
665 | Werror("unknown option `%s`",n); |
---|
666 | okay: |
---|
667 | if (currRing != NULL) |
---|
668 | currRing->options = si_opt_1 & TEST_RINGDEP_OPTS; |
---|
669 | omFree((ADDRESS)n); |
---|
670 | v=v->next; |
---|
671 | } while (v!=NULL); |
---|
672 | |
---|
673 | #ifdef OM_SINGULAR_CONFIG_H |
---|
674 | // set global variable to show memory usage |
---|
675 | extern int om_sing_opt_show_mem; |
---|
676 | if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1; |
---|
677 | else om_sing_opt_show_mem = 0; |
---|
678 | #endif |
---|
679 | |
---|
680 | return FALSE; |
---|
681 | } |
---|
682 | |
---|
683 | char * showOption() |
---|
684 | { |
---|
685 | int i; |
---|
686 | BITSET tmp; |
---|
687 | |
---|
688 | StringSetS("//options:"); |
---|
689 | if ((si_opt_1!=0)||(si_opt_2!=0)) |
---|
690 | { |
---|
691 | tmp=si_opt_1; |
---|
692 | if(tmp) |
---|
693 | { |
---|
694 | for (i=0; optionStruct[i].setval!=0; i++) |
---|
695 | { |
---|
696 | if (optionStruct[i].setval & tmp) |
---|
697 | { |
---|
698 | StringAppend(" %s",optionStruct[i].name); |
---|
699 | tmp &=optionStruct[i].resetval; |
---|
700 | } |
---|
701 | } |
---|
702 | for (i=0; i<32; i++) |
---|
703 | { |
---|
704 | if (tmp & Sy_bit(i)) StringAppend(" %d",i); |
---|
705 | } |
---|
706 | } |
---|
707 | tmp=si_opt_2; |
---|
708 | if (tmp) |
---|
709 | { |
---|
710 | for (i=0; verboseStruct[i].setval!=0; i++) |
---|
711 | { |
---|
712 | if (verboseStruct[i].setval & tmp) |
---|
713 | { |
---|
714 | StringAppend(" %s",verboseStruct[i].name); |
---|
715 | tmp &=verboseStruct[i].resetval; |
---|
716 | } |
---|
717 | } |
---|
718 | for (i=1; i<32; i++) |
---|
719 | { |
---|
720 | if (tmp & Sy_bit(i)) StringAppend(" %d",i+32); |
---|
721 | } |
---|
722 | } |
---|
723 | return omStrDup(StringAppendS("")); |
---|
724 | } |
---|
725 | return omStrDup(StringAppendS(" none")); |
---|
726 | } |
---|
727 | |
---|
728 | char * versionString() |
---|
729 | { |
---|
730 | char* str = StringSetS(""); |
---|
731 | StringAppend("Singular for %s version %s (%d-%s) %s\nwith\n", |
---|
732 | S_UNAME, S_VERSION1, SINGULAR_VERSION, |
---|
733 | feVersionId,singular_date); |
---|
734 | StringAppendS("\t"); |
---|
735 | #ifdef HAVE_FACTORY |
---|
736 | StringAppend("factory(%s)", factoryVersion); |
---|
737 | #ifdef HAVE_LIBFAC |
---|
738 | // libfac: |
---|
739 | // extern const char * libfac_version; |
---|
740 | // extern const char * libfac_date; |
---|
741 | StringAppend("+libfac"); |
---|
742 | #endif // #ifdef HAVE_LIBFAC |
---|
743 | StringAppend(","); |
---|
744 | #endif |
---|
745 | |
---|
746 | #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR) |
---|
747 | StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR); |
---|
748 | #else |
---|
749 | StringAppendS("GMP(1.3),"); |
---|
750 | #endif |
---|
751 | #ifdef HAVE_NTL |
---|
752 | #include <NTL/version.h> |
---|
753 | StringAppend("NTL(%s),",NTL_VERSION); |
---|
754 | #endif |
---|
755 | #if SIZEOF_VOIDP == 8 |
---|
756 | StringAppendS("64bit,"); |
---|
757 | #else |
---|
758 | StringAppendS("32bit,"); |
---|
759 | #endif |
---|
760 | #if defined(HAVE_DYN_RL) |
---|
761 | if (fe_fgets_stdin==fe_fgets_dummy) |
---|
762 | StringAppendS("no input,"); |
---|
763 | else if (fe_fgets_stdin==fe_fgets) |
---|
764 | StringAppendS("fgets,"); |
---|
765 | if (fe_fgets_stdin==fe_fgets_stdin_drl) |
---|
766 | StringAppendS("dynamic readline,"); |
---|
767 | #ifdef HAVE_FEREAD |
---|
768 | else if (fe_fgets_stdin==fe_fgets_stdin_emu) |
---|
769 | StringAppendS("emulated readline,"); |
---|
770 | #endif |
---|
771 | else |
---|
772 | StringAppendS("unknown fgets method,"); |
---|
773 | #else |
---|
774 | #if defined(HAVE_READLINE) && !defined(FEREAD) |
---|
775 | StringAppendS("static readline,"); |
---|
776 | #else |
---|
777 | #ifdef HAVE_FEREAD |
---|
778 | StringAppendS("emulated readline,"); |
---|
779 | #else |
---|
780 | StringAppendS("fgets,"); |
---|
781 | #endif |
---|
782 | #endif |
---|
783 | #endif |
---|
784 | #ifdef HAVE_PLURAL |
---|
785 | StringAppendS("Plural,"); |
---|
786 | #endif |
---|
787 | #ifdef HAVE_DBM |
---|
788 | StringAppendS("DBM,\n\t"); |
---|
789 | #else |
---|
790 | StringAppendS("\n\t"); |
---|
791 | #endif |
---|
792 | #ifdef HAVE_DYNAMIC_LOADING |
---|
793 | StringAppendS("dynamic modules,"); |
---|
794 | #endif |
---|
795 | if (p_procs_dynamic) StringAppendS("dynamic p_Procs,"); |
---|
796 | #ifdef TEST |
---|
797 | StringAppendS("TESTs,"); |
---|
798 | #endif |
---|
799 | #if YYDEBUG |
---|
800 | StringAppendS("YYDEBUG=1,"); |
---|
801 | #endif |
---|
802 | #ifdef HAVE_ASSUME |
---|
803 | StringAppendS("ASSUME,"); |
---|
804 | #endif |
---|
805 | #ifdef MDEBUG |
---|
806 | StringAppend("MDEBUG=%d,",MDEBUG); |
---|
807 | #endif |
---|
808 | #ifdef OM_CHECK |
---|
809 | StringAppend("OM_CHECK=%d,",OM_CHECK); |
---|
810 | #endif |
---|
811 | #ifdef OM_TRACK |
---|
812 | StringAppend("OM_TRACK=%d,",OM_TRACK); |
---|
813 | #endif |
---|
814 | #ifdef OM_NDEBUG |
---|
815 | StringAppendS("OM_NDEBUG,"); |
---|
816 | #endif |
---|
817 | #ifdef PDEBUG |
---|
818 | StringAppendS("PDEBUG,"); |
---|
819 | #endif |
---|
820 | #ifdef KDEBUG |
---|
821 | StringAppendS("KDEBUG,"); |
---|
822 | #endif |
---|
823 | #ifndef __OPTIMIZE__ |
---|
824 | StringAppendS("-g,"); |
---|
825 | #endif |
---|
826 | #ifdef HAVE_EIGENVAL |
---|
827 | StringAppendS("eigenvalues,"); |
---|
828 | #endif |
---|
829 | #ifdef HAVE_GMS |
---|
830 | StringAppendS("Gauss-Manin system,"); |
---|
831 | #endif |
---|
832 | #ifdef HAVE_RATGRING |
---|
833 | StringAppendS("ratGB,"); |
---|
834 | #endif |
---|
835 | StringAppend("random=%d\n",siRandomStart); |
---|
836 | StringAppend("\tCC=%s,\n\tCXX=%s" |
---|
837 | #ifdef __GNUC__ |
---|
838 | "(" __VERSION__ ")" |
---|
839 | #endif |
---|
840 | "\n",CC,CXX); |
---|
841 | feStringAppendResources(0); |
---|
842 | feStringAppendBrowsers(0); |
---|
843 | StringAppendS("\n"); |
---|
844 | return str; |
---|
845 | } |
---|
846 | |
---|
847 | #ifdef PDEBUG |
---|
848 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
849 | void p_SetRingOfLeftv(leftv l, ring r) |
---|
850 | { |
---|
851 | switch(l->rtyp) |
---|
852 | { |
---|
853 | case INT_CMD: |
---|
854 | case BIGINT_CMD: |
---|
855 | case IDHDL: |
---|
856 | case DEF_CMD: |
---|
857 | break; |
---|
858 | case POLY_CMD: |
---|
859 | case VECTOR_CMD: |
---|
860 | { |
---|
861 | poly p=(poly)l->data; |
---|
862 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
863 | break; |
---|
864 | } |
---|
865 | case IDEAL_CMD: |
---|
866 | case MODUL_CMD: |
---|
867 | case MATRIX_CMD: |
---|
868 | { |
---|
869 | ideal I=(ideal)l->data; |
---|
870 | int i; |
---|
871 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
872 | { |
---|
873 | poly p=I->m[i]; |
---|
874 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
875 | } |
---|
876 | break; |
---|
877 | } |
---|
878 | case COMMAND: |
---|
879 | { |
---|
880 | command d=(command)l->data; |
---|
881 | p_SetRingOfLeftv(&d->arg1, r); |
---|
882 | if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r); |
---|
883 | if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r); |
---|
884 | break; |
---|
885 | } |
---|
886 | default: |
---|
887 | printf("type %d not yet implementd in p_SetRingOfLeftv\n",l->rtyp); |
---|
888 | break; |
---|
889 | } |
---|
890 | } |
---|
891 | #endif |
---|
892 | #endif |
---|
893 | |
---|
894 | #if 0 /* debug only */ |
---|
895 | void listall(int showproc) |
---|
896 | { |
---|
897 | idhdl hh=basePack->idroot; |
---|
898 | PrintS("====== Top ==============\n"); |
---|
899 | while (hh!=NULL) |
---|
900 | { |
---|
901 | if (showproc || (IDTYP(hh)!=PROC_CMD)) |
---|
902 | { |
---|
903 | if (IDDATA(hh)==(void *)currRing) PrintS("(R)"); |
---|
904 | else if (IDDATA(hh)==(void *)currPack) PrintS("(P)"); |
---|
905 | else PrintS(" "); |
---|
906 | Print("::%s, typ %s level %d data %lx", |
---|
907 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
908 | if ((IDTYP(hh)==RING_CMD) |
---|
909 | || (IDTYP(hh)==QRING_CMD)) |
---|
910 | Print(" ref: %d\n",IDRING(hh)->ref); |
---|
911 | else |
---|
912 | PrintLn(); |
---|
913 | } |
---|
914 | hh=IDNEXT(hh); |
---|
915 | } |
---|
916 | hh=basePack->idroot; |
---|
917 | while (hh!=NULL) |
---|
918 | { |
---|
919 | if (IDDATA(hh)==(void *)basePack) |
---|
920 | Print("(T)::%s, typ %s level %d data %lx\n", |
---|
921 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
922 | else |
---|
923 | if ((IDTYP(hh)==RING_CMD) |
---|
924 | || (IDTYP(hh)==QRING_CMD) |
---|
925 | || (IDTYP(hh)==PACKAGE_CMD)) |
---|
926 | { |
---|
927 | Print("====== %s ==============\n",IDID(hh)); |
---|
928 | idhdl h2=IDRING(hh)->idroot; |
---|
929 | while (h2!=NULL) |
---|
930 | { |
---|
931 | if (showproc || (IDTYP(h2)!=PROC_CMD)) |
---|
932 | { |
---|
933 | if ((IDDATA(h2)==(void *)currRing) |
---|
934 | && ((IDTYP(h2)==RING_CMD)||(IDTYP(h2)==QRING_CMD))) |
---|
935 | PrintS("(R)"); |
---|
936 | else if (IDDATA(h2)==(void *)currPack) PrintS("(P)"); |
---|
937 | else PrintS(" "); |
---|
938 | Print("%s::%s, typ %s level %d data %lx\n", |
---|
939 | IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),(long)IDDATA(h2)); |
---|
940 | } |
---|
941 | h2=IDNEXT(h2); |
---|
942 | } |
---|
943 | } |
---|
944 | hh=IDNEXT(hh); |
---|
945 | } |
---|
946 | Print("currRing:%lx, currPack:%lx,basePack:%lx\n",(long)currRing,(long)currPack,(long)basePack); |
---|
947 | iiCheckPack(currPack); |
---|
948 | } |
---|
949 | #endif |
---|
950 | |
---|
951 | #ifndef NDEBUG |
---|
952 | void checkall() |
---|
953 | { |
---|
954 | idhdl hh=basePack->idroot; |
---|
955 | while (hh!=NULL) |
---|
956 | { |
---|
957 | omCheckAddr(hh); |
---|
958 | omCheckAddr((ADDRESS)IDID(hh)); |
---|
959 | if (RingDependend(IDTYP(hh))) Print("%s typ %d in Top\n",IDID(hh),IDTYP(hh)); |
---|
960 | hh=IDNEXT(hh); |
---|
961 | } |
---|
962 | hh=basePack->idroot; |
---|
963 | while (hh!=NULL) |
---|
964 | { |
---|
965 | if (IDTYP(hh)==PACKAGE_CMD) |
---|
966 | { |
---|
967 | idhdl h2=IDPACKAGE(hh)->idroot; |
---|
968 | while (h2!=NULL) |
---|
969 | { |
---|
970 | omCheckAddr(h2); |
---|
971 | omCheckAddr((ADDRESS)IDID(h2)); |
---|
972 | if (RingDependend(IDTYP(h2))) Print("%s typ %d in %s\n",IDID(h2),IDTYP(h2),IDID(hh)); |
---|
973 | h2=IDNEXT(h2); |
---|
974 | } |
---|
975 | } |
---|
976 | hh=IDNEXT(hh); |
---|
977 | } |
---|
978 | } |
---|
979 | #endif |
---|
980 | |
---|
981 | #include <sys/types.h> |
---|
982 | #include <sys/stat.h> |
---|
983 | #include <unistd.h> |
---|
984 | |
---|
985 | extern "C" |
---|
986 | int singular_fstat(int fd, struct stat *buf) |
---|
987 | { |
---|
988 | return fstat(fd,buf); |
---|
989 | } |
---|
990 | |
---|
991 | /*2 |
---|
992 | * the global exit routine of Singular |
---|
993 | */ |
---|
994 | extern "C" { |
---|
995 | |
---|
996 | void m2_end(int i) |
---|
997 | { |
---|
998 | fe_reset_input_mode(); |
---|
999 | #ifdef PAGE_TEST |
---|
1000 | mmEndStat(); |
---|
1001 | #endif |
---|
1002 | fe_reset_input_mode(); |
---|
1003 | idhdl h = IDROOT; |
---|
1004 | while(h != NULL) |
---|
1005 | { |
---|
1006 | if(IDTYP(h) == LINK_CMD) |
---|
1007 | { |
---|
1008 | idhdl hh=h->next; |
---|
1009 | killhdl(h, currPack); |
---|
1010 | h = hh; |
---|
1011 | } |
---|
1012 | else |
---|
1013 | { |
---|
1014 | h = h->next; |
---|
1015 | } |
---|
1016 | } |
---|
1017 | if(!singular_in_batchmode) |
---|
1018 | { |
---|
1019 | if (i<=0) |
---|
1020 | { |
---|
1021 | if (TEST_V_QUIET) |
---|
1022 | { |
---|
1023 | if (i==0) |
---|
1024 | printf("Auf Wiedersehen.\n"); |
---|
1025 | else |
---|
1026 | printf("\n$Bye.\n"); |
---|
1027 | } |
---|
1028 | //#ifdef sun |
---|
1029 | // #ifndef __svr4__ |
---|
1030 | // _cleanup(); |
---|
1031 | // _exit(0); |
---|
1032 | // #endif |
---|
1033 | //#endif |
---|
1034 | i=0; |
---|
1035 | } |
---|
1036 | else |
---|
1037 | { |
---|
1038 | printf("\nhalt %d\n",i); |
---|
1039 | } |
---|
1040 | } |
---|
1041 | exit(i); |
---|
1042 | } |
---|
1043 | } |
---|
1044 | |
---|
1045 | const char *singular_date=__DATE__ " " __TIME__; |
---|
1046 | |
---|
1047 | extern "C" |
---|
1048 | { |
---|
1049 | void omSingOutOfMemoryFunc() |
---|
1050 | { |
---|
1051 | fprintf(stderr, "\nSingular error: no more memory\n"); |
---|
1052 | omPrintStats(stderr); |
---|
1053 | m2_end(14); |
---|
1054 | /* should never get here */ |
---|
1055 | exit(1); |
---|
1056 | } |
---|
1057 | } |
---|
1058 | |
---|
1059 | /*2 |
---|
1060 | * initialize components of Singular |
---|
1061 | */ |
---|
1062 | void siInit(char *name) |
---|
1063 | { |
---|
1064 | #ifdef HAVE_FACTORY |
---|
1065 | // factory default settings: ----------------------------------------------- |
---|
1066 | On(SW_USE_NTL); |
---|
1067 | On(SW_USE_NTL_GCD_0); // On -> seg11 in Old/algnorm, Old/factor... |
---|
1068 | On(SW_USE_NTL_GCD_P); // On -> cyle in Short/brnoeth_s: fixed |
---|
1069 | On(SW_USE_EZGCD); |
---|
1070 | On(SW_USE_CHINREM_GCD); |
---|
1071 | //On(SW_USE_FF_MOD_GCD); |
---|
1072 | On(SW_USE_EZGCD_P); |
---|
1073 | On(SW_USE_QGCD); |
---|
1074 | Off(SW_USE_NTL_SORT); // may be changed by an command line option |
---|
1075 | factoryError=WerrorS; |
---|
1076 | #endif |
---|
1077 | |
---|
1078 | // memory initialization: ----------------------------------------------- |
---|
1079 | om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc; |
---|
1080 | #ifndef OM_NDEBUG |
---|
1081 | #ifndef __OPTIMIZE__ |
---|
1082 | om_Opts.ErrorHook = dErrorBreak; |
---|
1083 | #endif |
---|
1084 | #endif |
---|
1085 | omInitInfo(); |
---|
1086 | #ifdef OM_SING_KEEP |
---|
1087 | om_Opts.Keep = OM_SING_KEEP; |
---|
1088 | #endif |
---|
1089 | |
---|
1090 | // interpreter tables etc.: ----------------------------------------------- |
---|
1091 | #ifdef INIT_BUG |
---|
1092 | jjInitTab1(); |
---|
1093 | #endif |
---|
1094 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
1095 | sLastPrinted.rtyp=NONE; |
---|
1096 | |
---|
1097 | extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc |
---|
1098 | |
---|
1099 | basePack=(package)omAlloc0(sizeof(*basePack)); |
---|
1100 | currPack=basePack; |
---|
1101 | idhdl h; |
---|
1102 | h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
1103 | IDPACKAGE(h)->language = LANG_TOP; |
---|
1104 | IDPACKAGE(h)=basePack; |
---|
1105 | currPackHdl=h; |
---|
1106 | basePackHdl=h; |
---|
1107 | |
---|
1108 | coeffs_BIGINT = nInitChar(n_Q,NULL); |
---|
1109 | |
---|
1110 | #if 1 |
---|
1111 | // def HAVE_POLYEXTENSIONS |
---|
1112 | if(TRUE) |
---|
1113 | { |
---|
1114 | n_coeffType type = nRegister(n_algExt, naInitChar); |
---|
1115 | assume(type == n_algExt); |
---|
1116 | |
---|
1117 | type = nRegister(n_transExt, ntInitChar); |
---|
1118 | assume(type == n_transExt); |
---|
1119 | } |
---|
1120 | #endif |
---|
1121 | |
---|
1122 | // random generator: ----------------------------------------------- |
---|
1123 | int t=initTimer(); |
---|
1124 | if (t==0) t=1; |
---|
1125 | initRTimer(); |
---|
1126 | siSeed=t; |
---|
1127 | #ifdef HAVE_FACTORY |
---|
1128 | factoryseed(t); |
---|
1129 | #endif |
---|
1130 | siRandomStart=t; |
---|
1131 | feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart); |
---|
1132 | |
---|
1133 | // ressource table: ---------------------------------------------------- |
---|
1134 | // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed |
---|
1135 | // hack such that all shared' libs in the bindir are loaded correctly |
---|
1136 | feInitResources(name); |
---|
1137 | |
---|
1138 | // singular links: -------------------------------------------------- |
---|
1139 | slStandardInit(); |
---|
1140 | myynest=0; |
---|
1141 | |
---|
1142 | // loading standard.lib ----------------------------------------------- |
---|
1143 | if (! feOptValue(FE_OPT_NO_STDLIB)) |
---|
1144 | { |
---|
1145 | BITSET save1,save2; |
---|
1146 | SI_SAVE_OPT(save1,save2); |
---|
1147 | si_opt_2 &= ~Sy_bit(V_LOAD_LIB); |
---|
1148 | iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE); |
---|
1149 | SI_RESTORE_OPT(save1,save2); |
---|
1150 | } |
---|
1151 | errorreported = 0; |
---|
1152 | } |
---|
1153 | |
---|
1154 | /* |
---|
1155 | #ifdef LIBSINGULAR |
---|
1156 | #ifdef HAVE_FACTORY |
---|
1157 | // the init routines of factory need mmInit |
---|
1158 | int mmInit( void ) |
---|
1159 | { |
---|
1160 | return 1; |
---|
1161 | } |
---|
1162 | #endif |
---|
1163 | #endif |
---|
1164 | */ |
---|