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