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