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