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 | |
---|
24 | void number2mpz(number n, mpz_t m) |
---|
25 | { |
---|
26 | if (SR_HDL(n) & SR_INT) mpz_init_set_si(m, SR_TO_INT(n)); /* n fits in an int */ |
---|
27 | else mpz_init_set(m, (mpz_ptr)n->z); |
---|
28 | } |
---|
29 | |
---|
30 | number mpz2number(mpz_t m) |
---|
31 | { |
---|
32 | number z = (number)omAllocBin(rnumber_bin); |
---|
33 | mpz_init_set(z->z, m); |
---|
34 | mpz_init_set_ui(z->n, 1); |
---|
35 | z->s = 3; |
---|
36 | return z; |
---|
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 = nlRInit(ui); |
---|
112 | mpz_set_ui(nn->z,ui); |
---|
113 | L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | /* true iff p is prime */ |
---|
118 | /* |
---|
119 | bool isPrime(mpz_t p) |
---|
120 | { |
---|
121 | if (mpz_cmp_ui(p, 2) == 0) return true; |
---|
122 | if (mpz_cmp_ui(p, 3) == 0) return true; |
---|
123 | if (mpz_cmp_ui(p, 5) < 0) return false; |
---|
124 | |
---|
125 | mpz_t d; mpz_init_set_ui(d, 5); int add = 2; |
---|
126 | mpz_t sr; mpz_init(sr); mpz_sqrt(sr, p); |
---|
127 | mpz_t r; mpz_init(r); |
---|
128 | while (mpz_cmp(d, sr) <= 0) |
---|
129 | { |
---|
130 | mpz_cdiv_r(r, p, d); |
---|
131 | if (mpz_cmp_ui(r, 0) == 0) |
---|
132 | { |
---|
133 | mpz_clear(d); mpz_clear(sr); mpz_clear(r); |
---|
134 | return false; |
---|
135 | } |
---|
136 | mpz_add_ui(d, d, add); |
---|
137 | add += 2; if (add == 6) add = 2; |
---|
138 | } |
---|
139 | mpz_clear(d); mpz_clear(sr); mpz_clear(r); |
---|
140 | return true; |
---|
141 | } |
---|
142 | */ |
---|
143 | |
---|
144 | /* finds the next prime q, bound >= q >= p; |
---|
145 | in case of success, puts q into p; |
---|
146 | otherwise sets q = bound + 1; |
---|
147 | e.g. p = 24; nextPrime(p, 30) produces p = 29 (success), |
---|
148 | p = 24; nextPrime(p, 29) produces p = 29 (success), |
---|
149 | p = 24; nextPrime(p, 28) produces p = 29 (no success), |
---|
150 | p = 24; nextPrime(p, 27) produces p = 28 (no success) */ |
---|
151 | /* |
---|
152 | void nextPrime(mpz_t p, mpz_t bound) |
---|
153 | { |
---|
154 | int add; |
---|
155 | mpz_t r; mpz_init(r); mpz_cdiv_r_ui(r, p, 6); // r = p mod 6, 0 <= r <= 5 |
---|
156 | if (mpz_cmp_ui(r, 0) == 0) { mpz_add_ui(p, p, 1); add = 4; } |
---|
157 | if (mpz_cmp_ui(r, 1) == 0) { add = 4; } |
---|
158 | if (mpz_cmp_ui(r, 2) == 0) { mpz_add_ui(p, p, 3); add = 2; } |
---|
159 | if (mpz_cmp_ui(r, 3) == 0) { mpz_add_ui(p, p, 2); add = 2; } |
---|
160 | if (mpz_cmp_ui(r, 4) == 0) { mpz_add_ui(p, p, 1); add = 2; } |
---|
161 | if (mpz_cmp_ui(r, 5) == 0) { add = 2; } |
---|
162 | |
---|
163 | while (mpz_cmp(p, bound) <= 0) |
---|
164 | { |
---|
165 | if (isPrime(p)) { mpz_clear(r); return; } |
---|
166 | mpz_add_ui(p, p, add); |
---|
167 | add += 2; if (add == 6) add = 2; |
---|
168 | } |
---|
169 | mpz_set(p, bound); |
---|
170 | mpz_add_ui(p, p, 1); |
---|
171 | mpz_clear(r); |
---|
172 | return; |
---|
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 (!nlIsZero(n)) |
---|
189 | { |
---|
190 | if (!nlGreaterZero(n)) |
---|
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 <string.h> |
---|
333 | #include <unistd.h> |
---|
334 | #include <stdio.h> |
---|
335 | #include <stddef.h> |
---|
336 | #include <stdlib.h> |
---|
337 | #include <time.h> |
---|
338 | |
---|
339 | #include <omalloc/mylimits.h> |
---|
340 | #include <omalloc/omalloc.h> |
---|
341 | #include <kernel/options.h> |
---|
342 | #include <kernel/febase.h> |
---|
343 | #include <Singular/cntrlc.h> |
---|
344 | #include <kernel/page.h> |
---|
345 | #include <Singular/ipid.h> |
---|
346 | #include <Singular/ipshell.h> |
---|
347 | #include <kernel/kstd1.h> |
---|
348 | #include <Singular/subexpr.h> |
---|
349 | #include <kernel/timer.h> |
---|
350 | #include <kernel/intvec.h> |
---|
351 | #include <kernel/ring.h> |
---|
352 | #include <Singular/omSingularConfig.h> |
---|
353 | #include <kernel/p_Procs.h> |
---|
354 | /* Needed for debug Version of p_SetRingOfLeftv, Oliver */ |
---|
355 | #ifdef PDEBUG |
---|
356 | #include <kernel/polys.h> |
---|
357 | #endif |
---|
358 | #include <Singular/version.h> |
---|
359 | |
---|
360 | #include <Singular/static.h> |
---|
361 | #ifdef HAVE_STATIC |
---|
362 | #undef HAVE_DYN_RL |
---|
363 | #endif |
---|
364 | |
---|
365 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
366 | |
---|
367 | //#ifdef HAVE_LIBPARSER |
---|
368 | //# include "libparse.h" |
---|
369 | //#endif /* HAVE_LIBPARSER */ |
---|
370 | |
---|
371 | #ifdef HAVE_FACTORY |
---|
372 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
373 | #include <factory/factory.h> |
---|
374 | // libfac: |
---|
375 | extern const char * libfac_version; |
---|
376 | extern const char * libfac_date; |
---|
377 | #endif |
---|
378 | |
---|
379 | /* version strings */ |
---|
380 | #include <kernel/si_gmp.h> |
---|
381 | #ifdef HAVE_MPSR |
---|
382 | #include <MP_Config.h> |
---|
383 | #endif |
---|
384 | |
---|
385 | /*2 |
---|
386 | * initialize components of Singular |
---|
387 | */ |
---|
388 | int inits(void) |
---|
389 | { |
---|
390 | int t; |
---|
391 | /*4 signal handler:*/ |
---|
392 | init_signals(); |
---|
393 | /*4 randomize: */ |
---|
394 | t=initTimer(); |
---|
395 | /*t=(int)time(NULL);*/ |
---|
396 | if (t==0) t=1; |
---|
397 | initRTimer(); |
---|
398 | siSeed=t; |
---|
399 | #ifdef HAVE_FACTORY |
---|
400 | factoryseed(t); |
---|
401 | #endif |
---|
402 | /*4 private data of other modules*/ |
---|
403 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
404 | sLastPrinted.rtyp=NONE; |
---|
405 | return t; |
---|
406 | } |
---|
407 | |
---|
408 | /*2 |
---|
409 | * the renice routine for very large jobs |
---|
410 | * works only on unix machines, |
---|
411 | * testet on : linux, HP 9.0 |
---|
412 | * |
---|
413 | *#include <sys/times.h> |
---|
414 | *#include <sys/resource.h> |
---|
415 | *extern "C" int setpriority(int,int,int); |
---|
416 | *void very_nice() |
---|
417 | *{ |
---|
418 | *#ifndef NO_SETPRIORITY |
---|
419 | * setpriority(PRIO_PROCESS,0,19); |
---|
420 | *#endif |
---|
421 | * sleep(10); |
---|
422 | *} |
---|
423 | */ |
---|
424 | |
---|
425 | void singular_example(char *str) |
---|
426 | { |
---|
427 | assume(str!=NULL); |
---|
428 | char *s=str; |
---|
429 | while (*s==' ') s++; |
---|
430 | char *ss=s; |
---|
431 | while (*ss!='\0') ss++; |
---|
432 | while (*ss<=' ') |
---|
433 | { |
---|
434 | *ss='\0'; |
---|
435 | ss--; |
---|
436 | } |
---|
437 | idhdl h=IDROOT->get(s,myynest); |
---|
438 | if ((h!=NULL) && (IDTYP(h)==PROC_CMD)) |
---|
439 | { |
---|
440 | char *lib=iiGetLibName(IDPROC(h)); |
---|
441 | if((lib!=NULL)&&(*lib!='\0')) |
---|
442 | { |
---|
443 | Print("// proc %s from lib %s\n",s,lib); |
---|
444 | s=iiGetLibProcBuffer(IDPROC(h), 2); |
---|
445 | if (s!=NULL) |
---|
446 | { |
---|
447 | if (strlen(s)>5) |
---|
448 | { |
---|
449 | iiEStart(s,IDPROC(h)); |
---|
450 | return; |
---|
451 | } |
---|
452 | else omFree((ADDRESS)s); |
---|
453 | } |
---|
454 | } |
---|
455 | } |
---|
456 | else |
---|
457 | { |
---|
458 | char sing_file[MAXPATHLEN]; |
---|
459 | FILE *fd=NULL; |
---|
460 | char *res_m=feResource('m', 0); |
---|
461 | if (res_m!=NULL) |
---|
462 | { |
---|
463 | sprintf(sing_file, "%s/%s.sing", res_m, s); |
---|
464 | fd = feFopen(sing_file, "r"); |
---|
465 | } |
---|
466 | if (fd != NULL) |
---|
467 | { |
---|
468 | |
---|
469 | int old_echo = si_echo; |
---|
470 | int length, got; |
---|
471 | char* s; |
---|
472 | |
---|
473 | fseek(fd, 0, SEEK_END); |
---|
474 | length = ftell(fd); |
---|
475 | fseek(fd, 0, SEEK_SET); |
---|
476 | s = (char*) omAlloc((length+20)*sizeof(char)); |
---|
477 | got = fread(s, sizeof(char), length, fd); |
---|
478 | fclose(fd); |
---|
479 | if (got != length) |
---|
480 | { |
---|
481 | Werror("Error while reading file %s", sing_file); |
---|
482 | omFree(s); |
---|
483 | } |
---|
484 | else |
---|
485 | { |
---|
486 | s[length] = '\0'; |
---|
487 | strcat(s, "\n;return();\n\n"); |
---|
488 | si_echo = 2; |
---|
489 | iiEStart(s, NULL); |
---|
490 | si_echo = old_echo; |
---|
491 | } |
---|
492 | } |
---|
493 | else |
---|
494 | { |
---|
495 | Werror("no example for %s", str); |
---|
496 | } |
---|
497 | } |
---|
498 | } |
---|
499 | |
---|
500 | |
---|
501 | struct soptionStruct |
---|
502 | { |
---|
503 | const char * name; |
---|
504 | unsigned setval; |
---|
505 | unsigned resetval; |
---|
506 | }; |
---|
507 | |
---|
508 | struct soptionStruct optionStruct[]= |
---|
509 | { |
---|
510 | {"prot", Sy_bit(OPT_PROT), ~Sy_bit(OPT_PROT) }, |
---|
511 | {"redSB", Sy_bit(OPT_REDSB), ~Sy_bit(OPT_REDSB) }, |
---|
512 | {"notBuckets", Sy_bit(OPT_NOT_BUCKETS), ~Sy_bit(OPT_NOT_BUCKETS) }, |
---|
513 | {"notSugar", Sy_bit(OPT_NOT_SUGAR), ~Sy_bit(OPT_NOT_SUGAR) }, |
---|
514 | {"interrupt", Sy_bit(OPT_INTERRUPT), ~Sy_bit(OPT_INTERRUPT) }, |
---|
515 | {"sugarCrit", Sy_bit(OPT_SUGARCRIT), ~Sy_bit(OPT_SUGARCRIT) }, |
---|
516 | {"teach", Sy_bit(OPT_DEBUG), ~Sy_bit(OPT_DEBUG) }, |
---|
517 | /* 9 return SB in syz, quotient, intersect */ |
---|
518 | {"returnSB", Sy_bit(OPT_RETURN_SB), ~Sy_bit(OPT_RETURN_SB) }, |
---|
519 | {"fastHC", Sy_bit(OPT_FASTHC), ~Sy_bit(OPT_FASTHC) }, |
---|
520 | /* 11-19 sort in L/T */ |
---|
521 | {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND) }, |
---|
522 | {"multBound", Sy_bit(OPT_MULTBOUND), ~Sy_bit(OPT_MULTBOUND) }, |
---|
523 | {"degBound", Sy_bit(OPT_DEGBOUND), ~Sy_bit(OPT_DEGBOUND) }, |
---|
524 | /* 25 no redTail(p)/redTail(s) */ |
---|
525 | {"redTail", Sy_bit(OPT_REDTAIL), ~Sy_bit(OPT_REDTAIL) }, |
---|
526 | {"redThrough", Sy_bit(OPT_REDTHROUGH), ~Sy_bit(OPT_REDTHROUGH) }, |
---|
527 | {"lazy", Sy_bit(OPT_OLDSTD), ~Sy_bit(OPT_OLDSTD) }, |
---|
528 | {"intStrategy", Sy_bit(OPT_INTSTRATEGY), ~Sy_bit(OPT_INTSTRATEGY) }, |
---|
529 | {"infRedTail", Sy_bit(OPT_INFREDTAIL), ~Sy_bit(OPT_INFREDTAIL) }, |
---|
530 | /* 30: use not regularity for syz */ |
---|
531 | {"notRegularity",Sy_bit(OPT_NOTREGULARITY), ~Sy_bit(OPT_NOTREGULARITY) }, |
---|
532 | {"weightM", Sy_bit(OPT_WEIGHTM), ~Sy_bit(OPT_WEIGHTM) }, |
---|
533 | /*special for "none" and also end marker for showOption:*/ |
---|
534 | {"ne", 0, 0 } |
---|
535 | }; |
---|
536 | |
---|
537 | struct soptionStruct verboseStruct[]= |
---|
538 | { |
---|
539 | {"mem", Sy_bit(V_SHOW_MEM), ~Sy_bit(V_SHOW_MEM) }, |
---|
540 | {"yacc", Sy_bit(V_YACC), ~Sy_bit(V_YACC) }, |
---|
541 | {"redefine", Sy_bit(V_REDEFINE), ~Sy_bit(V_REDEFINE) }, |
---|
542 | {"reading", Sy_bit(V_READING), ~Sy_bit(V_READING) }, |
---|
543 | {"loadLib", Sy_bit(V_LOAD_LIB), ~Sy_bit(V_LOAD_LIB) }, |
---|
544 | {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB) }, |
---|
545 | {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC) }, |
---|
546 | {"defRes", Sy_bit(V_DEF_RES), ~Sy_bit(V_DEF_RES) }, |
---|
547 | {"usage", Sy_bit(V_SHOW_USE), ~Sy_bit(V_SHOW_USE) }, |
---|
548 | {"Imap", Sy_bit(V_IMAP), ~Sy_bit(V_IMAP) }, |
---|
549 | {"prompt", Sy_bit(V_PROMPT), ~Sy_bit(V_PROMPT) }, |
---|
550 | {"length", Sy_bit(V_LENGTH), ~Sy_bit(V_LENGTH) }, |
---|
551 | {"notWarnSB",Sy_bit(V_NSB), ~Sy_bit(V_NSB) }, |
---|
552 | {"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB) }, |
---|
553 | {"cancelunit",Sy_bit(V_CANCELUNIT),~Sy_bit(V_CANCELUNIT)}, |
---|
554 | {"modpsolve",Sy_bit(V_MODPSOLVSB),~Sy_bit(V_MODPSOLVSB)}, |
---|
555 | {"geometricSB",Sy_bit(V_UPTORADICAL),~Sy_bit(V_UPTORADICAL)}, |
---|
556 | {"findMonomials",Sy_bit(V_FINDMONOM),~Sy_bit(V_FINDMONOM)}, |
---|
557 | {"coefStrat",Sy_bit(V_COEFSTRAT), ~Sy_bit(V_COEFSTRAT)}, |
---|
558 | {"qringNF", Sy_bit(V_QRING), ~Sy_bit(V_QRING)}, |
---|
559 | {"warn", Sy_bit(V_ALLWARN), ~Sy_bit(V_ALLWARN)}, |
---|
560 | /*special for "none" and also end marker for showOption:*/ |
---|
561 | {"ne", 0, 0 } |
---|
562 | }; |
---|
563 | |
---|
564 | BOOLEAN setOption(leftv res, leftv v) |
---|
565 | { |
---|
566 | const char *n; |
---|
567 | do |
---|
568 | { |
---|
569 | if (v->Typ()==STRING_CMD) |
---|
570 | { |
---|
571 | n=(const char *)v->CopyD(STRING_CMD); |
---|
572 | } |
---|
573 | else |
---|
574 | { |
---|
575 | if (v->name==NULL) |
---|
576 | return TRUE; |
---|
577 | if (v->rtyp==0) |
---|
578 | { |
---|
579 | n=v->name; |
---|
580 | v->name=NULL; |
---|
581 | } |
---|
582 | else |
---|
583 | { |
---|
584 | n=omStrDup(v->name); |
---|
585 | } |
---|
586 | } |
---|
587 | |
---|
588 | int i; |
---|
589 | |
---|
590 | if(strcmp(n,"get")==0) |
---|
591 | { |
---|
592 | intvec *w=new intvec(2); |
---|
593 | (*w)[0]=test; |
---|
594 | (*w)[1]=verbose; |
---|
595 | res->rtyp=INTVEC_CMD; |
---|
596 | res->data=(void *)w; |
---|
597 | goto okay; |
---|
598 | } |
---|
599 | if(strcmp(n,"set")==0) |
---|
600 | { |
---|
601 | if((v->next!=NULL) |
---|
602 | &&(v->next->Typ()==INTVEC_CMD)) |
---|
603 | { |
---|
604 | v=v->next; |
---|
605 | intvec *w=(intvec*)v->Data(); |
---|
606 | test=(*w)[0]; |
---|
607 | verbose=(*w)[1]; |
---|
608 | #if 0 |
---|
609 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
610 | && rField_has_simple_inverse() |
---|
611 | #ifdef HAVE_RINGS |
---|
612 | && !rField_is_Ring(currRing) |
---|
613 | #endif |
---|
614 | ) { |
---|
615 | test &=~Sy_bit(OPT_INTSTRATEGY); |
---|
616 | } |
---|
617 | #endif |
---|
618 | goto okay; |
---|
619 | } |
---|
620 | } |
---|
621 | if(strcmp(n,"none")==0) |
---|
622 | { |
---|
623 | test=0; |
---|
624 | verbose=0; |
---|
625 | goto okay; |
---|
626 | } |
---|
627 | for (i=0; (i==0) || (optionStruct[i-1].setval!=0); i++) |
---|
628 | { |
---|
629 | if (strcmp(n,optionStruct[i].name)==0) |
---|
630 | { |
---|
631 | if (optionStruct[i].setval & validOpts) |
---|
632 | { |
---|
633 | test |= optionStruct[i].setval; |
---|
634 | // optOldStd disables redthrough |
---|
635 | if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD)) |
---|
636 | test &= ~Sy_bit(OPT_REDTHROUGH); |
---|
637 | } |
---|
638 | else |
---|
639 | Warn("cannot set option"); |
---|
640 | #if 0 |
---|
641 | if (TEST_OPT_INTSTRATEGY && (currRing!=NULL) |
---|
642 | && rField_has_simple_inverse() |
---|
643 | #ifdef HAVE_RINGS |
---|
644 | && !rField_is_Ring(currRing) |
---|
645 | #endif |
---|
646 | ) { |
---|
647 | test &=~Sy_bit(OPT_INTSTRATEGY); |
---|
648 | } |
---|
649 | #endif |
---|
650 | goto okay; |
---|
651 | } |
---|
652 | else if ((strncmp(n,"no",2)==0) |
---|
653 | && (strcmp(n+2,optionStruct[i].name)==0)) |
---|
654 | { |
---|
655 | if (optionStruct[i].setval & validOpts) |
---|
656 | { |
---|
657 | test &= optionStruct[i].resetval; |
---|
658 | } |
---|
659 | else |
---|
660 | Warn("cannot clear option"); |
---|
661 | goto okay; |
---|
662 | } |
---|
663 | } |
---|
664 | for (i=0; (i==0) || (verboseStruct[i-1].setval!=0); i++) |
---|
665 | { |
---|
666 | if (strcmp(n,verboseStruct[i].name)==0) |
---|
667 | { |
---|
668 | verbose |= verboseStruct[i].setval; |
---|
669 | #ifdef YYDEBUG |
---|
670 | #if YYDEBUG |
---|
671 | /*debugging the bison grammar --> grammar.cc*/ |
---|
672 | extern int yydebug; |
---|
673 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
674 | else yydebug=0; |
---|
675 | #endif |
---|
676 | #endif |
---|
677 | goto okay; |
---|
678 | } |
---|
679 | else if ((strncmp(n,"no",2)==0) |
---|
680 | && (strcmp(n+2,verboseStruct[i].name)==0)) |
---|
681 | { |
---|
682 | verbose &= verboseStruct[i].resetval; |
---|
683 | #ifdef YYDEBUG |
---|
684 | #if YYDEBUG |
---|
685 | /*debugging the bison grammar --> grammar.cc*/ |
---|
686 | extern int yydebug; |
---|
687 | if (BVERBOSE(V_YACC)) yydebug=1; |
---|
688 | else yydebug=0; |
---|
689 | #endif |
---|
690 | #endif |
---|
691 | goto okay; |
---|
692 | } |
---|
693 | } |
---|
694 | Werror("unknown option `%s`",n); |
---|
695 | okay: |
---|
696 | if (currRing != NULL) |
---|
697 | currRing->options = test & TEST_RINGDEP_OPTS; |
---|
698 | omFree((ADDRESS)n); |
---|
699 | v=v->next; |
---|
700 | } while (v!=NULL); |
---|
701 | // set global variable to show memory usage |
---|
702 | if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1; |
---|
703 | else om_sing_opt_show_mem = 0; |
---|
704 | return FALSE; |
---|
705 | } |
---|
706 | |
---|
707 | char * showOption() |
---|
708 | { |
---|
709 | int i; |
---|
710 | BITSET tmp; |
---|
711 | |
---|
712 | StringSetS("//options:"); |
---|
713 | if ((test!=0)||(verbose!=0)) |
---|
714 | { |
---|
715 | tmp=test; |
---|
716 | if(tmp) |
---|
717 | { |
---|
718 | for (i=0; optionStruct[i].setval!=0; i++) |
---|
719 | { |
---|
720 | if (optionStruct[i].setval & test) |
---|
721 | { |
---|
722 | StringAppend(" %s",optionStruct[i].name); |
---|
723 | tmp &=optionStruct[i].resetval; |
---|
724 | } |
---|
725 | } |
---|
726 | for (i=0; i<32; i++) |
---|
727 | { |
---|
728 | if (tmp & Sy_bit(i)) StringAppend(" %d",i); |
---|
729 | } |
---|
730 | } |
---|
731 | tmp=verbose; |
---|
732 | if (tmp) |
---|
733 | { |
---|
734 | for (i=0; verboseStruct[i].setval!=0; i++) |
---|
735 | { |
---|
736 | if (verboseStruct[i].setval & tmp) |
---|
737 | { |
---|
738 | StringAppend(" %s",verboseStruct[i].name); |
---|
739 | tmp &=verboseStruct[i].resetval; |
---|
740 | } |
---|
741 | } |
---|
742 | for (i=1; i<32; i++) |
---|
743 | { |
---|
744 | if (tmp & Sy_bit(i)) StringAppend(" %d",i+32); |
---|
745 | } |
---|
746 | } |
---|
747 | return omStrDup(StringAppendS("")); |
---|
748 | } |
---|
749 | else |
---|
750 | return omStrDup(StringAppendS(" none")); |
---|
751 | } |
---|
752 | |
---|
753 | char * versionString() |
---|
754 | { |
---|
755 | char* str = StringSetS(""); |
---|
756 | StringAppend("Singular for %s version %s (%d-%s) %s\nwith\n", |
---|
757 | S_UNAME, S_VERSION1, SINGULAR_VERSION, |
---|
758 | feVersionId,singular_date); |
---|
759 | StringAppendS("\t"); |
---|
760 | #ifdef HAVE_FACTORY |
---|
761 | StringAppend("factory(%s),", factoryVersion); |
---|
762 | StringAppend("libfac(%s,%s),\n\t",libfac_version,libfac_date); |
---|
763 | #endif |
---|
764 | #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR) |
---|
765 | StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR); |
---|
766 | #else |
---|
767 | StringAppendS("GMP(1.3),"); |
---|
768 | #endif |
---|
769 | #ifdef HAVE_NTL |
---|
770 | #include <NTL/version.h> |
---|
771 | StringAppend("NTL(%s),",NTL_VERSION); |
---|
772 | #endif |
---|
773 | #ifdef HAVE_MPSR |
---|
774 | StringAppend("MP(%s),",MP_VERSION); |
---|
775 | #endif |
---|
776 | #if SIZEOF_VOIDP == 8 |
---|
777 | StringAppendS("64bit,"); |
---|
778 | #else |
---|
779 | StringAppendS("32bit,"); |
---|
780 | #endif |
---|
781 | #if defined(HAVE_DYN_RL) |
---|
782 | if (fe_fgets_stdin==fe_fgets_dummy) |
---|
783 | StringAppendS("no input,"); |
---|
784 | else if (fe_fgets_stdin==fe_fgets) |
---|
785 | StringAppendS("fgets,"); |
---|
786 | if (fe_fgets_stdin==fe_fgets_stdin_drl) |
---|
787 | StringAppendS("dynamic readline,"); |
---|
788 | #ifdef HAVE_FEREAD |
---|
789 | else if (fe_fgets_stdin==fe_fgets_stdin_emu) |
---|
790 | StringAppendS("emulated readline,"); |
---|
791 | #endif |
---|
792 | else |
---|
793 | StringAppendS("unknown fgets method,"); |
---|
794 | #else |
---|
795 | #if defined(HAVE_READLINE) && !defined(FEREAD) |
---|
796 | StringAppendS("static readline,"); |
---|
797 | #else |
---|
798 | #ifdef HAVE_FEREAD |
---|
799 | StringAppendS("emulated readline,"); |
---|
800 | #else |
---|
801 | StringAppendS("fgets,"); |
---|
802 | #endif |
---|
803 | #endif |
---|
804 | #endif |
---|
805 | #ifdef HAVE_PLURAL |
---|
806 | StringAppendS("Plural,"); |
---|
807 | #endif |
---|
808 | #ifdef HAVE_DBM |
---|
809 | StringAppendS("DBM,\n\t"); |
---|
810 | #else |
---|
811 | StringAppendS("\n\t"); |
---|
812 | #endif |
---|
813 | #ifdef HAVE_DYNAMIC_LOADING |
---|
814 | StringAppendS("dynamic modules,"); |
---|
815 | #endif |
---|
816 | if (p_procs_dynamic) StringAppendS("dynamic p_Procs,"); |
---|
817 | #ifdef TEST |
---|
818 | StringAppendS("TESTs,"); |
---|
819 | #endif |
---|
820 | #if YYDEBUG |
---|
821 | StringAppendS("YYDEBUG=1,"); |
---|
822 | #endif |
---|
823 | #ifdef HAVE_ASSUME |
---|
824 | StringAppendS("ASSUME,"); |
---|
825 | #endif |
---|
826 | #ifdef MDEBUG |
---|
827 | StringAppend("MDEBUG=%d,",MDEBUG); |
---|
828 | #endif |
---|
829 | #ifdef OM_CHECK |
---|
830 | StringAppend("OM_CHECK=%d,",OM_CHECK); |
---|
831 | #endif |
---|
832 | #ifdef OM_TRACK |
---|
833 | StringAppend("OM_TRACK=%d,",OM_TRACK); |
---|
834 | #endif |
---|
835 | #ifdef OM_NDEBUG |
---|
836 | StringAppendS("OM_NDEBUG,"); |
---|
837 | #endif |
---|
838 | #ifdef PDEBUG |
---|
839 | StringAppendS("PDEBUG,"); |
---|
840 | #endif |
---|
841 | #ifdef KDEBUG |
---|
842 | StringAppendS("KDEBUG,"); |
---|
843 | #endif |
---|
844 | #ifndef __OPTIMIZE__ |
---|
845 | StringAppendS("-g,"); |
---|
846 | #endif |
---|
847 | #ifdef HAVE_EIGENVAL |
---|
848 | StringAppendS("eigenvalues,"); |
---|
849 | #endif |
---|
850 | #ifdef HAVE_GMS |
---|
851 | StringAppendS("Gauss-Manin system,"); |
---|
852 | #endif |
---|
853 | #ifdef HAVE_RATGRING |
---|
854 | StringAppendS("ratGB,"); |
---|
855 | #endif |
---|
856 | StringAppend("random=%d\n",siRandomStart); |
---|
857 | StringAppend("\tCC=%s,\n\tCXX=%s" |
---|
858 | #ifdef __GNUC__ |
---|
859 | "(" __VERSION__ ")" |
---|
860 | #endif |
---|
861 | "\n",CC,CXX); |
---|
862 | feStringAppendResources(0); |
---|
863 | feStringAppendBrowsers(0); |
---|
864 | StringAppendS("\n"); |
---|
865 | return str; |
---|
866 | } |
---|
867 | |
---|
868 | #ifdef PDEBUG |
---|
869 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
870 | void p_SetRingOfLeftv(leftv l, ring r) |
---|
871 | { |
---|
872 | switch(l->rtyp) |
---|
873 | { |
---|
874 | case INT_CMD: |
---|
875 | case BIGINT_CMD: |
---|
876 | case IDHDL: |
---|
877 | case DEF_CMD: |
---|
878 | break; |
---|
879 | case POLY_CMD: |
---|
880 | case VECTOR_CMD: |
---|
881 | { |
---|
882 | poly p=(poly)l->data; |
---|
883 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
884 | break; |
---|
885 | } |
---|
886 | case IDEAL_CMD: |
---|
887 | case MODUL_CMD: |
---|
888 | case MATRIX_CMD: |
---|
889 | { |
---|
890 | ideal I=(ideal)l->data; |
---|
891 | int i; |
---|
892 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
893 | { |
---|
894 | poly p=I->m[i]; |
---|
895 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
896 | } |
---|
897 | break; |
---|
898 | } |
---|
899 | case COMMAND: |
---|
900 | { |
---|
901 | command d=(command)l->data; |
---|
902 | p_SetRingOfLeftv(&d->arg1, r); |
---|
903 | if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r); |
---|
904 | if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r); |
---|
905 | break; |
---|
906 | } |
---|
907 | default: |
---|
908 | printf("type %d not yet implementd in p_SetRingOfLeftv\n",l->rtyp); |
---|
909 | break; |
---|
910 | } |
---|
911 | } |
---|
912 | #endif |
---|
913 | #endif |
---|
914 | |
---|
915 | #if 0 |
---|
916 | void listall(int showproc) |
---|
917 | { |
---|
918 | idhdl hh=basePack->idroot; |
---|
919 | PrintS("====== Top ==============\n"); |
---|
920 | while (hh!=NULL) |
---|
921 | { |
---|
922 | if (showproc || (IDTYP(hh)!=PROC_CMD)) |
---|
923 | { |
---|
924 | if (IDDATA(hh)==(void *)currRing) PrintS("(R)"); |
---|
925 | else if (IDDATA(hh)==(void *)currPack) PrintS("(P)"); |
---|
926 | else PrintS(" "); |
---|
927 | Print("::%s, typ %s level %d data %lx", |
---|
928 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
929 | if ((IDTYP(hh)==RING_CMD) |
---|
930 | || (IDTYP(hh)==QRING_CMD)) |
---|
931 | Print(" ref: %d\n",IDRING(hh)->ref); |
---|
932 | else |
---|
933 | PrintLn(); |
---|
934 | } |
---|
935 | hh=IDNEXT(hh); |
---|
936 | } |
---|
937 | hh=basePack->idroot; |
---|
938 | while (hh!=NULL) |
---|
939 | { |
---|
940 | if (IDDATA(hh)==(void *)basePack) |
---|
941 | Print("(T)::%s, typ %s level %d data %lx\n", |
---|
942 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
943 | else |
---|
944 | if ((IDTYP(hh)==RING_CMD) |
---|
945 | || (IDTYP(hh)==QRING_CMD) |
---|
946 | || (IDTYP(hh)==PACKAGE_CMD)) |
---|
947 | { |
---|
948 | Print("====== %s ==============\n",IDID(hh)); |
---|
949 | idhdl h2=IDRING(hh)->idroot; |
---|
950 | while (h2!=NULL) |
---|
951 | { |
---|
952 | if (showproc || (IDTYP(h2)!=PROC_CMD)) |
---|
953 | { |
---|
954 | if ((IDDATA(h2)==(void *)currRing) |
---|
955 | && ((IDTYP(h2)==RING_CMD)||(IDTYP(h2)==QRING_CMD))) |
---|
956 | PrintS("(R)"); |
---|
957 | else if (IDDATA(h2)==(void *)currPack) PrintS("(P)"); |
---|
958 | else PrintS(" "); |
---|
959 | Print("%s::%s, typ %s level %d data %lx\n", |
---|
960 | IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),(long)IDDATA(h2)); |
---|
961 | } |
---|
962 | h2=IDNEXT(h2); |
---|
963 | } |
---|
964 | } |
---|
965 | hh=IDNEXT(hh); |
---|
966 | } |
---|
967 | Print("currRing:%lx, currPack:%lx,basePack:%lx\n",(long)currRing,(long)currPack,(long)basePack); |
---|
968 | iiCheckPack(currPack); |
---|
969 | } |
---|
970 | #ifndef NDEBUG |
---|
971 | void checkall() |
---|
972 | { |
---|
973 | idhdl hh=basePack->idroot; |
---|
974 | while (hh!=NULL) |
---|
975 | { |
---|
976 | omCheckAddr(hh); |
---|
977 | omCheckAddr((ADDRESS)IDID(hh)); |
---|
978 | if (RingDependend(IDTYP(hh))) Print("%s typ %d in Top\n",IDID(hh),IDTYP(hh)); |
---|
979 | hh=IDNEXT(hh); |
---|
980 | } |
---|
981 | hh=basePack->idroot; |
---|
982 | while (hh!=NULL) |
---|
983 | { |
---|
984 | if (IDTYP(hh)==PACKAGE_CMD) |
---|
985 | { |
---|
986 | idhdl h2=IDPACKAGE(hh)->idroot; |
---|
987 | while (h2!=NULL) |
---|
988 | { |
---|
989 | omCheckAddr(h2); |
---|
990 | omCheckAddr((ADDRESS)IDID(h2)); |
---|
991 | if (RingDependend(IDTYP(h2))) Print("%s typ %d in %s\n",IDID(h2),IDTYP(h2),IDID(hh)); |
---|
992 | h2=IDNEXT(h2); |
---|
993 | } |
---|
994 | } |
---|
995 | hh=IDNEXT(hh); |
---|
996 | } |
---|
997 | } |
---|
998 | #endif |
---|
999 | #endif |
---|
1000 | |
---|
1001 | #include <sys/types.h> |
---|
1002 | #include <sys/stat.h> |
---|
1003 | #include <unistd.h> |
---|
1004 | |
---|
1005 | extern "C" |
---|
1006 | int singular_fstat(int fd, struct stat *buf) |
---|
1007 | { |
---|
1008 | return fstat(fd,buf); |
---|
1009 | } |
---|
1010 | |
---|
1011 | /*2 |
---|
1012 | * the global exit routine of Singular |
---|
1013 | */ |
---|
1014 | #ifdef HAVE_MPSR |
---|
1015 | void (*MP_Exit_Env_Ptr)()=NULL; |
---|
1016 | #endif |
---|
1017 | |
---|
1018 | extern "C" { |
---|
1019 | |
---|
1020 | void m2_end(int i) |
---|
1021 | { |
---|
1022 | fe_reset_input_mode(); |
---|
1023 | #ifdef PAGE_TEST |
---|
1024 | mmEndStat(); |
---|
1025 | #endif |
---|
1026 | fe_reset_input_mode(); |
---|
1027 | idhdl h = IDROOT; |
---|
1028 | while(h != NULL) |
---|
1029 | { |
---|
1030 | if(IDTYP(h) == LINK_CMD) |
---|
1031 | { |
---|
1032 | idhdl hh=h->next; |
---|
1033 | killhdl(h, currPack); |
---|
1034 | h = hh; |
---|
1035 | } |
---|
1036 | else |
---|
1037 | { |
---|
1038 | h = h->next; |
---|
1039 | } |
---|
1040 | } |
---|
1041 | if (i<=0) |
---|
1042 | { |
---|
1043 | if (TEST_V_QUIET) |
---|
1044 | { |
---|
1045 | if (i==0) |
---|
1046 | printf("Auf Wiedersehen.\n"); |
---|
1047 | else |
---|
1048 | printf("\n$Bye.\n"); |
---|
1049 | } |
---|
1050 | //#ifdef sun |
---|
1051 | // #ifndef __svr4__ |
---|
1052 | // _cleanup(); |
---|
1053 | // _exit(0); |
---|
1054 | // #endif |
---|
1055 | //#endif |
---|
1056 | exit(0); |
---|
1057 | } |
---|
1058 | else |
---|
1059 | { |
---|
1060 | printf("\nhalt %d\n",i); |
---|
1061 | } |
---|
1062 | #ifdef HAVE_MPSR |
---|
1063 | if (MP_Exit_Env_Ptr!=NULL) (*MP_Exit_Env_Ptr)(); |
---|
1064 | #endif |
---|
1065 | exit(i); |
---|
1066 | } |
---|
1067 | } |
---|
1068 | |
---|
1069 | const char *singular_date=__DATE__ " " __TIME__; |
---|
1070 | |
---|
1071 | int mmInit( void ); |
---|
1072 | int mmIsInitialized=mmInit(); |
---|
1073 | |
---|
1074 | extern "C" |
---|
1075 | { |
---|
1076 | void omSingOutOfMemoryFunc() |
---|
1077 | { |
---|
1078 | fprintf(stderr, "\nSingular error: no more memory\n"); |
---|
1079 | omPrintStats(stderr); |
---|
1080 | m2_end(14); |
---|
1081 | /* should never get here */ |
---|
1082 | exit(1); |
---|
1083 | } |
---|
1084 | } |
---|
1085 | |
---|
1086 | int mmInit( void ) |
---|
1087 | { |
---|
1088 | if(mmIsInitialized==0) |
---|
1089 | { |
---|
1090 | |
---|
1091 | #ifndef LIBSINGULAR |
---|
1092 | #if defined(OMALLOC_USES_MALLOC) || defined(X_OMALLOC) |
---|
1093 | /* in mmstd.c, for some architectures freeSize() unconditionally uses the *system* free() */ |
---|
1094 | /* sage ticket 5344: http://trac.sagemath.org/sage_trac/ticket/5344 */ |
---|
1095 | #include <omalloc/omalloc.h> |
---|
1096 | /* do not rely on the default in Singular as libsingular may be different */ |
---|
1097 | mp_set_memory_functions(omMallocFunc,omReallocSizeFunc,omFreeSizeFunc); |
---|
1098 | #else |
---|
1099 | mp_set_memory_functions(malloc,reallocSize,freeSize); |
---|
1100 | #endif |
---|
1101 | #endif // ifndef LIBSINGULAR |
---|
1102 | om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc; |
---|
1103 | #ifndef OM_NDEBUG |
---|
1104 | #ifndef __OPTIMIZE__ |
---|
1105 | om_Opts.ErrorHook = dErrorBreak; |
---|
1106 | #endif |
---|
1107 | #endif |
---|
1108 | omInitInfo(); |
---|
1109 | #ifdef OM_SING_KEEP |
---|
1110 | om_Opts.Keep = OM_SING_KEEP; |
---|
1111 | #endif |
---|
1112 | } |
---|
1113 | mmIsInitialized=1; |
---|
1114 | return 1; |
---|
1115 | } |
---|
1116 | |
---|
1117 | #ifdef LIBSINGULAR |
---|
1118 | int siInit(char *name) |
---|
1119 | { |
---|
1120 | // hack such that all shared' libs in the bindir are loaded correctly |
---|
1121 | feInitResources(name); |
---|
1122 | iiInitArithmetic(); |
---|
1123 | |
---|
1124 | #if 0 |
---|
1125 | SingularBuilder::Ptr SingularInstance = SingularBuilder::instance(); |
---|
1126 | #else |
---|
1127 | basePack=(package)omAlloc0(sizeof(*basePack)); |
---|
1128 | currPack=basePack; |
---|
1129 | idhdl h; |
---|
1130 | h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
1131 | IDPACKAGE(h)->language = LANG_TOP; |
---|
1132 | IDPACKAGE(h)=basePack; |
---|
1133 | currPackHdl=h; |
---|
1134 | basePackHdl=h; |
---|
1135 | |
---|
1136 | slStandardInit(); |
---|
1137 | myynest=0; |
---|
1138 | #endif |
---|
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 | #endif |
---|
1149 | |
---|