1 | /*****************************************************************************\ |
---|
2 | * Computer Algebra System SINGULAR |
---|
3 | \*****************************************************************************/ |
---|
4 | /** @file misc_ip.cc |
---|
5 | * |
---|
6 | * This file provides miscellaneous functionality. |
---|
7 | * |
---|
8 | * For more general information, see the documentation in misc_ip.h. |
---|
9 | * |
---|
10 | **/ |
---|
11 | /*****************************************************************************/ |
---|
12 | |
---|
13 | // include header files |
---|
14 | |
---|
15 | #include <kernel/mod2.h> |
---|
16 | #include <misc/auxiliary.h> |
---|
17 | |
---|
18 | #include <reporter/si_signals.h> |
---|
19 | |
---|
20 | #include <factory/factory.h> |
---|
21 | |
---|
22 | #include <coeffs/si_gmp.h> |
---|
23 | #include <coeffs/coeffs.h> |
---|
24 | |
---|
25 | #include <polys/ext_fields/algext.h> |
---|
26 | #include <polys/ext_fields/transext.h> |
---|
27 | |
---|
28 | #ifdef HAVE_SIMPLEIPC |
---|
29 | #include <Singular/links/simpleipc.h> |
---|
30 | #endif |
---|
31 | |
---|
32 | #include "misc_ip.h" |
---|
33 | #include "ipid.h" |
---|
34 | #include "feOpt.h" |
---|
35 | #include "links/silink.h" |
---|
36 | #include "mod_lib.h" |
---|
37 | |
---|
38 | // the following 2 inline functions are just convenience shortcuts for Frank's code: |
---|
39 | static inline void number2mpz(number n, mpz_t m){ n_MPZ(m, n, coeffs_BIGINT); } |
---|
40 | static inline number mpz2number(mpz_t m){ return n_InitMPZ(m, coeffs_BIGINT); } |
---|
41 | |
---|
42 | |
---|
43 | void setListEntry(lists L, int index, mpz_t n) |
---|
44 | { /* assumes n > 0 */ |
---|
45 | /* try to fit nn into an int: */ |
---|
46 | if (mpz_size1(n)<=1) |
---|
47 | { |
---|
48 | int ui=(int)mpz_get_si(n); |
---|
49 | if ((((ui<<3)>>3)==ui) |
---|
50 | && (mpz_cmp_si(n,(long)ui)==0)) |
---|
51 | { |
---|
52 | L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)ui; |
---|
53 | return; |
---|
54 | } |
---|
55 | } |
---|
56 | number nn = mpz2number(n); |
---|
57 | L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn; |
---|
58 | } |
---|
59 | |
---|
60 | void setListEntry_ui(lists L, int index, unsigned long ui) |
---|
61 | { /* assumes n > 0 */ |
---|
62 | /* try to fit nn into an int: */ |
---|
63 | int i=(int)ui; |
---|
64 | if ((((unsigned long)i)==ui) && (((i<<3)>>3)==i)) |
---|
65 | { |
---|
66 | L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)(long)i; |
---|
67 | } |
---|
68 | else |
---|
69 | { |
---|
70 | number nn = n_Init(ui, coeffs_BIGINT); |
---|
71 | L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | /* Factoring with Pollard's rho method. stolen from GMP/demos */ |
---|
76 | static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6}; |
---|
77 | |
---|
78 | static int factor_using_division (mpz_t t, unsigned int limit,lists primes, int *multiplicities,int &index, unsigned long bound) |
---|
79 | { |
---|
80 | mpz_t q, r; |
---|
81 | unsigned long int f; |
---|
82 | int ai; |
---|
83 | unsigned *addv = add; |
---|
84 | unsigned int failures; |
---|
85 | int bound_not_reached=1; |
---|
86 | |
---|
87 | mpz_init (q); |
---|
88 | mpz_init (r); |
---|
89 | |
---|
90 | f = mpz_scan1 (t, 0); |
---|
91 | mpz_div_2exp (t, t, f); |
---|
92 | if (f>0) |
---|
93 | { |
---|
94 | setListEntry_ui(primes, index, 2); |
---|
95 | multiplicities[index++] = f; |
---|
96 | } |
---|
97 | |
---|
98 | f=0; |
---|
99 | loop |
---|
100 | { |
---|
101 | mpz_tdiv_qr_ui (q, r, t, 3); |
---|
102 | if (mpz_cmp_ui (r, 0) != 0) |
---|
103 | break; |
---|
104 | mpz_set (t, q); |
---|
105 | f++; |
---|
106 | } |
---|
107 | if (f>0) |
---|
108 | { |
---|
109 | setListEntry_ui(primes, index, 3); |
---|
110 | multiplicities[index++] = f; |
---|
111 | } |
---|
112 | f=0; |
---|
113 | loop |
---|
114 | { |
---|
115 | mpz_tdiv_qr_ui (q, r, t, 5); |
---|
116 | if (mpz_cmp_ui (r, 0) != 0) |
---|
117 | break; |
---|
118 | mpz_set (t, q); |
---|
119 | f++; |
---|
120 | } |
---|
121 | if (f>0) |
---|
122 | { |
---|
123 | setListEntry_ui(primes, index, 5); |
---|
124 | multiplicities[index++] = f; |
---|
125 | } |
---|
126 | |
---|
127 | failures = 0; |
---|
128 | f = 7; |
---|
129 | ai = 0; |
---|
130 | unsigned long last_f=0; |
---|
131 | while (mpz_cmp_ui (t, 1) != 0) |
---|
132 | { |
---|
133 | mpz_tdiv_qr_ui (q, r, t, f); |
---|
134 | if (mpz_cmp_ui (r, 0) != 0) |
---|
135 | { |
---|
136 | f += addv[ai]; |
---|
137 | if (mpz_cmp_ui (t, f) < 0) |
---|
138 | break; |
---|
139 | ai = (ai + 1) & 7; |
---|
140 | failures++; |
---|
141 | if (failures > limit) |
---|
142 | break; |
---|
143 | if ((bound!=0) && (f>bound)) |
---|
144 | { |
---|
145 | bound_not_reached=0; |
---|
146 | break; |
---|
147 | } |
---|
148 | } |
---|
149 | else |
---|
150 | { |
---|
151 | mpz_swap (t, q); |
---|
152 | if (f!=last_f) |
---|
153 | { |
---|
154 | setListEntry_ui(primes, index, f); |
---|
155 | multiplicities[index]++; |
---|
156 | index++; |
---|
157 | } |
---|
158 | else |
---|
159 | { |
---|
160 | multiplicities[index-1]++; |
---|
161 | } |
---|
162 | last_f=f; |
---|
163 | failures = 0; |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | mpz_clear (q); |
---|
168 | mpz_clear (r); |
---|
169 | //printf("bound=%d,f=%d,failures=%d, reached=%d\n",bound,f,failures,bound_not_reached); |
---|
170 | return bound_not_reached; |
---|
171 | } |
---|
172 | |
---|
173 | static void factor_using_pollard_rho (mpz_t n, unsigned long a, lists primes, int * multiplicities,int &index) |
---|
174 | { |
---|
175 | mpz_t x, x1, y, P; |
---|
176 | mpz_t t1, t2; |
---|
177 | mpz_t last_f; |
---|
178 | unsigned long long k, l, i; |
---|
179 | |
---|
180 | mpz_init (t1); |
---|
181 | mpz_init (t2); |
---|
182 | mpz_init_set_si (last_f, 0); |
---|
183 | mpz_init_set_si (y, 2); |
---|
184 | mpz_init_set_si (x, 2); |
---|
185 | mpz_init_set_si (x1, 2); |
---|
186 | mpz_init_set_ui (P, 1); |
---|
187 | k = 1; |
---|
188 | l = 1; |
---|
189 | |
---|
190 | while (mpz_cmp_ui (n, 1) != 0) |
---|
191 | { |
---|
192 | loop |
---|
193 | { |
---|
194 | do |
---|
195 | { |
---|
196 | mpz_mul (t1, x, x); |
---|
197 | mpz_mod (x, t1, n); |
---|
198 | mpz_add_ui (x, x, a); |
---|
199 | mpz_sub (t1, x1, x); |
---|
200 | mpz_mul (t2, P, t1); |
---|
201 | mpz_mod (P, t2, n); |
---|
202 | |
---|
203 | if (k % 32 == 1) |
---|
204 | { |
---|
205 | mpz_gcd (t1, P, n); |
---|
206 | if (mpz_cmp_ui (t1, 1) != 0) |
---|
207 | goto factor_found; |
---|
208 | mpz_set (y, x); |
---|
209 | } |
---|
210 | } |
---|
211 | while (--k != 0); |
---|
212 | |
---|
213 | mpz_gcd (t1, P, n); |
---|
214 | if (mpz_cmp_ui (t1, 1) != 0) |
---|
215 | goto factor_found; |
---|
216 | |
---|
217 | mpz_set (x1, x); |
---|
218 | k = l; |
---|
219 | l = 2 * l; |
---|
220 | for (i = 0; i < k; i++) |
---|
221 | { |
---|
222 | mpz_mul (t1, x, x); |
---|
223 | mpz_mod (x, t1, n); |
---|
224 | mpz_add_ui (x, x, a); |
---|
225 | } |
---|
226 | mpz_set (y, x); |
---|
227 | } |
---|
228 | |
---|
229 | factor_found: |
---|
230 | do |
---|
231 | { |
---|
232 | mpz_mul (t1, y, y); |
---|
233 | mpz_mod (y, t1, n); |
---|
234 | mpz_add_ui (y, y, a); |
---|
235 | mpz_sub (t1, x1, y); |
---|
236 | mpz_gcd (t1, t1, n); |
---|
237 | } |
---|
238 | while (mpz_cmp_ui (t1, 1) == 0); |
---|
239 | |
---|
240 | mpz_divexact (n, n, t1); /* divide by t1, before t1 is overwritten */ |
---|
241 | |
---|
242 | if (!mpz_probab_prime_p (t1, 10)) |
---|
243 | { |
---|
244 | do |
---|
245 | { |
---|
246 | mp_limb_t a_limb; |
---|
247 | mpn_random (&a_limb, (mp_size_t) 1); |
---|
248 | a = a_limb; |
---|
249 | } |
---|
250 | while (a == 0); |
---|
251 | |
---|
252 | factor_using_pollard_rho (t1, a, primes,multiplicities,index); |
---|
253 | } |
---|
254 | else |
---|
255 | { |
---|
256 | if (mpz_cmp(t1,last_f)==0) |
---|
257 | { |
---|
258 | multiplicities[index-1]++; |
---|
259 | } |
---|
260 | else |
---|
261 | { |
---|
262 | mpz_set(last_f,t1); |
---|
263 | setListEntry(primes, index, t1); |
---|
264 | multiplicities[index++] = 1; |
---|
265 | } |
---|
266 | } |
---|
267 | mpz_mod (x, x, n); |
---|
268 | mpz_mod (x1, x1, n); |
---|
269 | mpz_mod (y, y, n); |
---|
270 | if (mpz_probab_prime_p (n, 10)) |
---|
271 | { |
---|
272 | if (mpz_cmp(n,last_f)==0) |
---|
273 | { |
---|
274 | multiplicities[index-1]++; |
---|
275 | } |
---|
276 | else |
---|
277 | { |
---|
278 | mpz_set(last_f,n); |
---|
279 | setListEntry(primes, index, n); |
---|
280 | multiplicities[index++] = 1; |
---|
281 | } |
---|
282 | mpz_set_ui(n,1); |
---|
283 | break; |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | mpz_clear (P); |
---|
288 | mpz_clear (t2); |
---|
289 | mpz_clear (t1); |
---|
290 | mpz_clear (x1); |
---|
291 | mpz_clear (x); |
---|
292 | mpz_clear (y); |
---|
293 | mpz_clear (last_f); |
---|
294 | } |
---|
295 | |
---|
296 | static void factor_gmp (mpz_t t,lists primes,int *multiplicities,int &index,unsigned long bound) |
---|
297 | { |
---|
298 | unsigned int division_limit; |
---|
299 | |
---|
300 | if (mpz_sgn (t) == 0) |
---|
301 | return; |
---|
302 | |
---|
303 | /* Set the trial division limit according the size of t. */ |
---|
304 | division_limit = mpz_sizeinbase (t, 2); |
---|
305 | if (division_limit > 1000) |
---|
306 | division_limit = 1000 * 1000; |
---|
307 | else |
---|
308 | division_limit = division_limit * division_limit; |
---|
309 | |
---|
310 | if (factor_using_division (t, division_limit,primes,multiplicities,index,bound)) |
---|
311 | { |
---|
312 | if (mpz_cmp_ui (t, 1) != 0) |
---|
313 | { |
---|
314 | if (mpz_probab_prime_p (t, 10)) |
---|
315 | { |
---|
316 | setListEntry(primes, index, t); |
---|
317 | multiplicities[index++] = 1; |
---|
318 | mpz_set_ui(t,1); |
---|
319 | } |
---|
320 | else |
---|
321 | factor_using_pollard_rho (t, 1L, primes,multiplicities,index); |
---|
322 | } |
---|
323 | } |
---|
324 | } |
---|
325 | /* n and pBound are assumed to be bigint numbers */ |
---|
326 | lists primeFactorisation(const number n, const int pBound) |
---|
327 | { |
---|
328 | int i; |
---|
329 | int index=0; |
---|
330 | mpz_t nn; number2mpz(n, nn); |
---|
331 | lists primes = (lists)omAllocBin(slists_bin); primes->Init(1000); |
---|
332 | int* multiplicities = (int*)omAlloc0(1000*sizeof(int)); |
---|
333 | int positive=1; |
---|
334 | |
---|
335 | if (!n_IsZero(n, coeffs_BIGINT)) |
---|
336 | { |
---|
337 | if (!n_GreaterZero(n, coeffs_BIGINT)) |
---|
338 | { |
---|
339 | positive=-1; |
---|
340 | mpz_neg(nn,nn); |
---|
341 | } |
---|
342 | factor_gmp(nn,primes,multiplicities,index,pBound); |
---|
343 | } |
---|
344 | |
---|
345 | lists primesL = (lists)omAllocBin(slists_bin); |
---|
346 | primesL->Init(index); |
---|
347 | for (i = 0; i < index; i++) |
---|
348 | { |
---|
349 | primesL->m[i].rtyp = primes->m[i].rtyp; |
---|
350 | primesL->m[i].data = primes->m[i].data; |
---|
351 | primes->m[i].rtyp=0; |
---|
352 | primes->m[i].data=NULL; |
---|
353 | } |
---|
354 | primes->Clean(NULL); |
---|
355 | |
---|
356 | lists multiplicitiesL = (lists)omAllocBin(slists_bin); |
---|
357 | multiplicitiesL->Init(index); |
---|
358 | for (i = 0; i < index; i++) |
---|
359 | { |
---|
360 | multiplicitiesL->m[i].rtyp = INT_CMD; |
---|
361 | multiplicitiesL->m[i].data = (void*)(long)multiplicities[i]; |
---|
362 | } |
---|
363 | omFree(multiplicities); |
---|
364 | |
---|
365 | lists L=(lists)omAllocBin(slists_bin); |
---|
366 | L->Init(3); |
---|
367 | if (positive==-1) mpz_neg(nn,nn); |
---|
368 | L->m[0].rtyp = LIST_CMD; L->m[0].data = (void*)primesL; |
---|
369 | L->m[1].rtyp = LIST_CMD; L->m[1].data = (void*)multiplicitiesL; |
---|
370 | setListEntry(L, 2, nn); |
---|
371 | |
---|
372 | mpz_clear(nn); |
---|
373 | |
---|
374 | return L; |
---|
375 | } |
---|
376 | |
---|
377 | #include <omalloc/omalloc.h> |
---|
378 | #include <misc/mylimits.h> |
---|
379 | |
---|
380 | #include <misc/options.h> |
---|
381 | #include <misc/intvec.h> |
---|
382 | |
---|
383 | #include <polys/monomials/ring.h> |
---|
384 | #include <polys/templates/p_Procs.h> |
---|
385 | |
---|
386 | #include <Singular/febase.h> |
---|
387 | #include <kernel/GBEngine/kstd1.h> |
---|
388 | #include <Singular/timer.h> |
---|
389 | |
---|
390 | |
---|
391 | #include "subexpr.h" |
---|
392 | #include "cntrlc.h" |
---|
393 | #include "ipid.h" |
---|
394 | #include "ipshell.h" |
---|
395 | |
---|
396 | #include "fehelp.h" |
---|
397 | |
---|
398 | #ifdef HAVE_STATIC |
---|
399 | #undef HAVE_DYN_RL |
---|
400 | #endif |
---|
401 | |
---|
402 | //#ifdef HAVE_LIBPARSER |
---|
403 | //# include "libparse.h" |
---|
404 | //#endif /* HAVE_LIBPARSER */ |
---|
405 | |
---|
406 | |
---|
407 | /*2 |
---|
408 | * the renice routine for very large jobs |
---|
409 | * works only on unix machines, |
---|
410 | * testet on : linux, HP 9.0 |
---|
411 | * |
---|
412 | *#include <sys/times.h> |
---|
413 | *#include <sys/resource.h> |
---|
414 | *extern "C" int setpriority(int,int,int); |
---|
415 | *void very_nice() |
---|
416 | *{ |
---|
417 | *#ifndef NO_SETPRIORITY |
---|
418 | * setpriority(PRIO_PROCESS,0,19); |
---|
419 | *#endif |
---|
420 | * sleep(10); |
---|
421 | *} |
---|
422 | */ |
---|
423 | |
---|
424 | #include <string.h> |
---|
425 | #include <unistd.h> |
---|
426 | #include <stdio.h> |
---|
427 | #include <stddef.h> |
---|
428 | #include <stdlib.h> |
---|
429 | #include <time.h> |
---|
430 | |
---|
431 | |
---|
432 | void singular_example(char *str) |
---|
433 | { |
---|
434 | assume(str!=NULL); |
---|
435 | char *s=str; |
---|
436 | while (*s==' ') s++; |
---|
437 | char *ss=s; |
---|
438 | while (*ss!='\0') ss++; |
---|
439 | while (*ss<=' ') |
---|
440 | { |
---|
441 | *ss='\0'; |
---|
442 | ss--; |
---|
443 | } |
---|
444 | idhdl h=IDROOT->get(s,myynest); |
---|
445 | if ((h!=NULL) && (IDTYP(h)==PROC_CMD)) |
---|
446 | { |
---|
447 | char *lib=iiGetLibName(IDPROC(h)); |
---|
448 | if((lib!=NULL)&&(*lib!='\0')) |
---|
449 | { |
---|
450 | Print("// proc %s from lib %s\n",s,lib); |
---|
451 | s=iiGetLibProcBuffer(IDPROC(h), 2); |
---|
452 | if (s!=NULL) |
---|
453 | { |
---|
454 | if (strlen(s)>5) |
---|
455 | { |
---|
456 | iiEStart(s,IDPROC(h)); |
---|
457 | omFree((ADDRESS)s); |
---|
458 | return; |
---|
459 | } |
---|
460 | else omFree((ADDRESS)s); |
---|
461 | } |
---|
462 | } |
---|
463 | } |
---|
464 | else |
---|
465 | { |
---|
466 | char sing_file[MAXPATHLEN]; |
---|
467 | FILE *fd=NULL; |
---|
468 | char *res_m=feResource('m', 0); |
---|
469 | if (res_m!=NULL) |
---|
470 | { |
---|
471 | sprintf(sing_file, "%s/%s.sing", res_m, s); |
---|
472 | fd = feFopen(sing_file, "r"); |
---|
473 | } |
---|
474 | if (fd != NULL) |
---|
475 | { |
---|
476 | |
---|
477 | int old_echo = si_echo; |
---|
478 | int length, got; |
---|
479 | char* s; |
---|
480 | |
---|
481 | fseek(fd, 0, SEEK_END); |
---|
482 | length = ftell(fd); |
---|
483 | fseek(fd, 0, SEEK_SET); |
---|
484 | s = (char*) omAlloc((length+20)*sizeof(char)); |
---|
485 | got = fread(s, sizeof(char), length, fd); |
---|
486 | fclose(fd); |
---|
487 | if (got != length) |
---|
488 | { |
---|
489 | Werror("Error while reading file %s", sing_file); |
---|
490 | } |
---|
491 | else |
---|
492 | { |
---|
493 | s[length] = '\0'; |
---|
494 | strcat(s, "\n;return();\n\n"); |
---|
495 | si_echo = 2; |
---|
496 | iiEStart(s, NULL); |
---|
497 | si_echo = old_echo; |
---|
498 | } |
---|
499 | omFree(s); |
---|
500 | } |
---|
501 | else |
---|
502 | { |
---|
503 | Werror("no example for %s", str); |
---|
504 | } |
---|
505 | } |
---|
506 | } |
---|
507 | |
---|
508 | |
---|
509 | struct soptionStruct |
---|
510 | { |
---|
511 | const char * name; |
---|
512 | unsigned setval; |
---|
513 | unsigned resetval; |
---|
514 | }; |
---|
515 | |
---|
516 | struct soptionStruct optionStruct[]= |
---|
517 | { |
---|
518 | {"prot", Sy_bit(OPT_PROT), ~Sy_bit(OPT_PROT) }, |
---|
519 | {"redSB", Sy_bit(OPT_REDSB), ~Sy_bit(OPT_REDSB) }, |
---|
520 | {"notBuckets", Sy_bit(OPT_NOT_BUCKETS), ~Sy_bit(OPT_NOT_BUCKETS) }, |
---|
521 | {"notSugar", Sy_bit(OPT_NOT_SUGAR), ~Sy_bit(OPT_NOT_SUGAR) }, |
---|
522 | {"interrupt", Sy_bit(OPT_INTERRUPT), ~Sy_bit(OPT_INTERRUPT) }, |
---|
523 | {"sugarCrit", Sy_bit(OPT_SUGARCRIT), ~Sy_bit(OPT_SUGARCRIT) }, |
---|
524 | {"teach", Sy_bit(OPT_DEBUG), ~Sy_bit(OPT_DEBUG) }, |
---|
525 | {"notSyzMinim", Sy_bit(OPT_NO_SYZ_MINIM), ~Sy_bit(OPT_NO_SYZ_MINIM) }, |
---|
526 | /* 9 return SB in syz, quotient, intersect */ |
---|
527 | {"returnSB", Sy_bit(OPT_RETURN_SB), ~Sy_bit(OPT_RETURN_SB) }, |
---|
528 | {"fastHC", Sy_bit(OPT_FASTHC), ~Sy_bit(OPT_FASTHC) }, |
---|
529 | /* 11-19 sort in L/T */ |
---|
530 | {"staircaseBound",Sy_bit(OPT_STAIRCASEBOUND),~Sy_bit(OPT_STAIRCASEBOUND) }, |
---|
531 | {"multBound", Sy_bit(OPT_MULTBOUND), ~Sy_bit(OPT_MULTBOUND) }, |
---|
532 | {"degBound", Sy_bit(OPT_DEGBOUND), ~Sy_bit(OPT_DEGBOUND) }, |
---|
533 | /* 25 no redTail(p)/redTail(s) */ |
---|
534 | {"redTail", Sy_bit(OPT_REDTAIL), ~Sy_bit(OPT_REDTAIL) }, |
---|
535 | {"redThrough", Sy_bit(OPT_REDTHROUGH), ~Sy_bit(OPT_REDTHROUGH) }, |
---|
536 | {"lazy", Sy_bit(OPT_OLDSTD), ~Sy_bit(OPT_OLDSTD) }, |
---|
537 | {"intStrategy", Sy_bit(OPT_INTSTRATEGY), ~Sy_bit(OPT_INTSTRATEGY) }, |
---|
538 | {"infRedTail", Sy_bit(OPT_INFREDTAIL), ~Sy_bit(OPT_INFREDTAIL) }, |
---|
539 | /* 30: use not regularity for syz */ |
---|
540 | {"notRegularity",Sy_bit(OPT_NOTREGULARITY), ~Sy_bit(OPT_NOTREGULARITY) }, |
---|
541 | {"weightM", Sy_bit(OPT_WEIGHTM), ~Sy_bit(OPT_WEIGHTM) }, |
---|
542 | /*special for "none" and also end marker for showOption:*/ |
---|
543 | {"ne", 0, 0 } |
---|
544 | }; |
---|
545 | |
---|
546 | struct soptionStruct verboseStruct[]= |
---|
547 | { |
---|
548 | {"mem", Sy_bit(V_SHOW_MEM), ~Sy_bit(V_SHOW_MEM) }, |
---|
549 | {"yacc", Sy_bit(V_YACC), ~Sy_bit(V_YACC) }, |
---|
550 | {"redefine", Sy_bit(V_REDEFINE), ~Sy_bit(V_REDEFINE) }, |
---|
551 | {"reading", Sy_bit(V_READING), ~Sy_bit(V_READING) }, |
---|
552 | {"loadLib", Sy_bit(V_LOAD_LIB), ~Sy_bit(V_LOAD_LIB) }, |
---|
553 | {"debugLib", Sy_bit(V_DEBUG_LIB), ~Sy_bit(V_DEBUG_LIB) }, |
---|
554 | {"loadProc", Sy_bit(V_LOAD_PROC), ~Sy_bit(V_LOAD_PROC) }, |
---|
555 | {"defRes", Sy_bit(V_DEF_RES), ~Sy_bit(V_DEF_RES) }, |
---|
556 | {"usage", Sy_bit(V_SHOW_USE), ~Sy_bit(V_SHOW_USE) }, |
---|
557 | {"Imap", Sy_bit(V_IMAP), ~Sy_bit(V_IMAP) }, |
---|
558 | {"prompt", Sy_bit(V_PROMPT), ~Sy_bit(V_PROMPT) }, |
---|
559 | {"length", Sy_bit(V_LENGTH), ~Sy_bit(V_LENGTH) }, |
---|
560 | {"notWarnSB",Sy_bit(V_NSB), ~Sy_bit(V_NSB) }, |
---|
561 | {"contentSB",Sy_bit(V_CONTENTSB), ~Sy_bit(V_CONTENTSB) }, |
---|
562 | {"cancelunit",Sy_bit(V_CANCELUNIT),~Sy_bit(V_CANCELUNIT)}, |
---|
563 | {"modpsolve",Sy_bit(V_MODPSOLVSB),~Sy_bit(V_MODPSOLVSB)}, |
---|
564 | {"geometricSB",Sy_bit(V_UPTORADICAL),~Sy_bit(V_UPTORADICAL)}, |
---|
565 | {"findMonomials",Sy_bit(V_FINDMONOM),~Sy_bit(V_FINDMONOM)}, |
---|
566 | {"coefStrat",Sy_bit(V_COEFSTRAT), ~Sy_bit(V_COEFSTRAT)}, |
---|
567 | {"qringNF", Sy_bit(V_QRING), ~Sy_bit(V_QRING)}, |
---|
568 | {"warn", Sy_bit(V_ALLWARN), ~Sy_bit(V_ALLWARN)}, |
---|
569 | {"interedSyz",Sy_bit(V_INTERSECT_SYZ), ~Sy_bit(V_INTERSECT_SYZ)}, |
---|
570 | {"interedElim",Sy_bit(V_INTERSECT_ELIM), ~Sy_bit(V_INTERSECT_ELIM)}, |
---|
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]=si_opt_1; |
---|
605 | (*w)[1]=si_opt_2; |
---|
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 | si_opt_1=(*w)[0]; |
---|
618 | si_opt_2=(*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 | si_opt_1 &=~Sy_bit(OPT_INTSTRATEGY); |
---|
627 | } |
---|
628 | #endif |
---|
629 | goto okay; |
---|
630 | } |
---|
631 | } |
---|
632 | if(strcmp(n,"none")==0) |
---|
633 | { |
---|
634 | si_opt_1=0; |
---|
635 | si_opt_2=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 | si_opt_1 |= optionStruct[i].setval; |
---|
645 | // optOldStd disables redthrough |
---|
646 | if (optionStruct[i].setval == Sy_bit(OPT_OLDSTD)) |
---|
647 | si_opt_1 &= ~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 | si_opt_1 &= 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 | si_opt_2 |= 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 | si_opt_2 &= 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 = si_opt_1 & TEST_RINGDEP_OPTS; |
---|
709 | omFree((ADDRESS)n); |
---|
710 | v=v->next; |
---|
711 | } while (v!=NULL); |
---|
712 | |
---|
713 | #ifdef OM_SINGULAR_CONFIG_H |
---|
714 | // set global variable to show memory usage |
---|
715 | extern int om_sing_opt_show_mem; |
---|
716 | if (BVERBOSE(V_SHOW_MEM)) om_sing_opt_show_mem = 1; |
---|
717 | else om_sing_opt_show_mem = 0; |
---|
718 | #endif |
---|
719 | |
---|
720 | return FALSE; |
---|
721 | } |
---|
722 | |
---|
723 | char * showOption() |
---|
724 | { |
---|
725 | int i; |
---|
726 | BITSET tmp; |
---|
727 | |
---|
728 | StringSetS("//options:"); |
---|
729 | if ((si_opt_1!=0)||(si_opt_2!=0)) |
---|
730 | { |
---|
731 | tmp=si_opt_1; |
---|
732 | if(tmp) |
---|
733 | { |
---|
734 | for (i=0; optionStruct[i].setval!=0; i++) |
---|
735 | { |
---|
736 | if (optionStruct[i].setval & tmp) |
---|
737 | { |
---|
738 | StringAppend(" %s",optionStruct[i].name); |
---|
739 | tmp &=optionStruct[i].resetval; |
---|
740 | } |
---|
741 | } |
---|
742 | for (i=0; i<32; i++) |
---|
743 | { |
---|
744 | if (tmp & Sy_bit(i)) StringAppend(" %d",i); |
---|
745 | } |
---|
746 | } |
---|
747 | tmp=si_opt_2; |
---|
748 | if (tmp) |
---|
749 | { |
---|
750 | for (i=0; verboseStruct[i].setval!=0; i++) |
---|
751 | { |
---|
752 | if (verboseStruct[i].setval & tmp) |
---|
753 | { |
---|
754 | StringAppend(" %s",verboseStruct[i].name); |
---|
755 | tmp &=verboseStruct[i].resetval; |
---|
756 | } |
---|
757 | } |
---|
758 | for (i=1; i<32; i++) |
---|
759 | { |
---|
760 | if (tmp & Sy_bit(i)) StringAppend(" %d",i+32); |
---|
761 | } |
---|
762 | } |
---|
763 | return StringEndS(); |
---|
764 | } |
---|
765 | StringAppendS(" none"); |
---|
766 | return StringEndS(); |
---|
767 | } |
---|
768 | |
---|
769 | /* version strings */ |
---|
770 | #ifdef HAVE_FLINT |
---|
771 | extern "C" |
---|
772 | { |
---|
773 | #ifndef __GMP_BITS_PER_MP_LIMB |
---|
774 | #define __GMP_BITS_PER_MP_LIMB GMP_LIMB_BITS |
---|
775 | #endif |
---|
776 | #include <flint/flint.h> |
---|
777 | } |
---|
778 | #endif |
---|
779 | |
---|
780 | char * versionString(/*const bool bShowDetails = false*/ ) |
---|
781 | { |
---|
782 | StringSetS(""); |
---|
783 | StringAppend("Singular for %s version %s (%s, %d bit) %s #%s", |
---|
784 | S_UNAME, VERSION, // SINGULAR_VERSION, |
---|
785 | PACKAGE_VERSION, SIZEOF_VOIDP*8, singular_date, GIT_VERSION); |
---|
786 | StringAppendS("\nwith\n\t"); |
---|
787 | |
---|
788 | #if defined(mpir_version) |
---|
789 | StringAppend("MPIR(%s)~GMP(%s),", mpir_version, gmp_version); |
---|
790 | #elif defined(gmp_version) |
---|
791 | // #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR) |
---|
792 | // StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR); |
---|
793 | StringAppend("GMP(%s),", gmp_version); |
---|
794 | #endif |
---|
795 | #ifdef HAVE_NTL |
---|
796 | #include <NTL/version.h> |
---|
797 | StringAppend("NTL(%s),",NTL_VERSION); |
---|
798 | #endif |
---|
799 | |
---|
800 | #ifdef HAVE_FLINT |
---|
801 | StringAppend("FLINT(%s),",version); |
---|
802 | #endif |
---|
803 | StringAppend("factory(%s),\n\t", factoryVersion); |
---|
804 | #if defined(HAVE_DYN_RL) |
---|
805 | if (fe_fgets_stdin==fe_fgets_dummy) |
---|
806 | StringAppendS("no input,"); |
---|
807 | else if (fe_fgets_stdin==fe_fgets) |
---|
808 | StringAppendS("fgets,"); |
---|
809 | if (fe_fgets_stdin==fe_fgets_stdin_drl) |
---|
810 | StringAppendS("dynamic readline,"); |
---|
811 | #ifdef HAVE_FEREAD |
---|
812 | else if (fe_fgets_stdin==fe_fgets_stdin_emu) |
---|
813 | StringAppendS("emulated readline,"); |
---|
814 | #endif |
---|
815 | else |
---|
816 | StringAppendS("unknown fgets method,"); |
---|
817 | #else |
---|
818 | #if defined(HAVE_READLINE) && !defined(FEREAD) |
---|
819 | StringAppendS("static readline,"); |
---|
820 | #else |
---|
821 | #ifdef HAVE_FEREAD |
---|
822 | StringAppendS("emulated readline,"); |
---|
823 | #else |
---|
824 | StringAppendS("fgets,"); |
---|
825 | #endif |
---|
826 | #endif |
---|
827 | #endif |
---|
828 | #ifdef HAVE_PLURAL |
---|
829 | StringAppendS("Plural,"); |
---|
830 | #endif |
---|
831 | #ifdef HAVE_DBM |
---|
832 | StringAppendS("DBM,\n\t"); |
---|
833 | #else |
---|
834 | StringAppendS("\n\t"); |
---|
835 | #endif |
---|
836 | #ifdef HAVE_DYNAMIC_LOADING |
---|
837 | StringAppendS("dynamic modules,"); |
---|
838 | #endif |
---|
839 | if (p_procs_dynamic) StringAppendS("dynamic p_Procs,"); |
---|
840 | #if YYDEBUG |
---|
841 | StringAppendS("YYDEBUG=1,"); |
---|
842 | #endif |
---|
843 | #ifdef HAVE_ASSUME |
---|
844 | StringAppendS("ASSUME,"); |
---|
845 | #endif |
---|
846 | #ifdef MDEBUG |
---|
847 | StringAppend("MDEBUG=%d,",MDEBUG); |
---|
848 | #endif |
---|
849 | #ifdef OM_CHECK |
---|
850 | StringAppend("OM_CHECK=%d,",OM_CHECK); |
---|
851 | #endif |
---|
852 | #ifdef OM_TRACK |
---|
853 | StringAppend("OM_TRACK=%d,",OM_TRACK); |
---|
854 | #endif |
---|
855 | #ifdef OM_NDEBUG |
---|
856 | StringAppendS("OM_NDEBUG,"); |
---|
857 | #endif |
---|
858 | #ifdef SING_NDEBUG |
---|
859 | StringAppendS("SING_NDEBUG,"); |
---|
860 | #endif |
---|
861 | #ifdef PDEBUG |
---|
862 | StringAppendS("PDEBUG,"); |
---|
863 | #endif |
---|
864 | #ifdef KDEBUG |
---|
865 | StringAppendS("KDEBUG,"); |
---|
866 | #endif |
---|
867 | #ifdef __OPTIMIZE__ |
---|
868 | StringAppendS("CC:OPTIMIZE,"); |
---|
869 | #endif |
---|
870 | #ifdef __OPTIMIZE_SIZE__ |
---|
871 | StringAppendS("CC:OPTIMIZE_SIZE,"); |
---|
872 | #endif |
---|
873 | #ifdef __NO_INLINE__ |
---|
874 | StringAppendS("CC:NO_INLINE,"); |
---|
875 | #endif |
---|
876 | #ifdef HAVE_EIGENVAL |
---|
877 | StringAppendS("eigenvalues,"); |
---|
878 | #endif |
---|
879 | #ifdef HAVE_GMS |
---|
880 | StringAppendS("Gauss-Manin system,"); |
---|
881 | #endif |
---|
882 | #ifdef HAVE_RATGRING |
---|
883 | StringAppendS("ratGB,"); |
---|
884 | #endif |
---|
885 | StringAppend("random=%d\n",siRandomStart); |
---|
886 | |
---|
887 | #define SI_SHOW_BUILTIN_MODULE(name) StringAppend(" %s", #name); |
---|
888 | StringAppendS("built-in modules: {"); |
---|
889 | SI_FOREACH_BUILTIN(SI_SHOW_BUILTIN_MODULE) |
---|
890 | StringAppendS("}\n"); |
---|
891 | #undef SI_SHOW_BUILTIN_MODULE |
---|
892 | |
---|
893 | StringAppend("AC_CONFIGURE_ARGS = %s,\n" |
---|
894 | "CC = %s,FLAGS : %s,\n" |
---|
895 | "CXX = %s,FLAGS : %s,\n" |
---|
896 | "DEFS : %s,CPPFLAGS : %s,\n" |
---|
897 | "LDFLAGS : %s,LIBS : %s " |
---|
898 | #ifdef __GNUC__ |
---|
899 | "(ver: " __VERSION__ ")" |
---|
900 | #endif |
---|
901 | "\n",AC_CONFIGURE_ARGS, CC,CFLAGS, CXX,CXXFLAGS, DEFS,CPPFLAGS, LDFLAGS,LIBS); |
---|
902 | feStringAppendResources(0); |
---|
903 | feStringAppendBrowsers(0); |
---|
904 | StringAppendS("\n"); |
---|
905 | return StringEndS(); |
---|
906 | } |
---|
907 | |
---|
908 | #ifdef PDEBUG |
---|
909 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
910 | void p_SetRingOfLeftv(leftv l, ring r) |
---|
911 | { |
---|
912 | switch(l->rtyp) |
---|
913 | { |
---|
914 | case INT_CMD: |
---|
915 | case BIGINT_CMD: |
---|
916 | case IDHDL: |
---|
917 | case DEF_CMD: |
---|
918 | break; |
---|
919 | case POLY_CMD: |
---|
920 | case VECTOR_CMD: |
---|
921 | { |
---|
922 | poly p=(poly)l->data; |
---|
923 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
924 | break; |
---|
925 | } |
---|
926 | case IDEAL_CMD: |
---|
927 | case MODUL_CMD: |
---|
928 | case MATRIX_CMD: |
---|
929 | { |
---|
930 | ideal I=(ideal)l->data; |
---|
931 | int i; |
---|
932 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
933 | { |
---|
934 | poly p=I->m[i]; |
---|
935 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
936 | } |
---|
937 | break; |
---|
938 | } |
---|
939 | case COMMAND: |
---|
940 | { |
---|
941 | command d=(command)l->data; |
---|
942 | p_SetRingOfLeftv(&d->arg1, r); |
---|
943 | if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r); |
---|
944 | if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r); |
---|
945 | break; |
---|
946 | } |
---|
947 | default: |
---|
948 | printf("type %d not yet implementd in p_SetRingOfLeftv\n",l->rtyp); |
---|
949 | break; |
---|
950 | } |
---|
951 | } |
---|
952 | #endif |
---|
953 | #endif |
---|
954 | |
---|
955 | #if 0 /* debug only */ |
---|
956 | void listall(int showproc) |
---|
957 | { |
---|
958 | idhdl hh=basePack->idroot; |
---|
959 | PrintS("====== Top ==============\n"); |
---|
960 | while (hh!=NULL) |
---|
961 | { |
---|
962 | if (showproc || (IDTYP(hh)!=PROC_CMD)) |
---|
963 | { |
---|
964 | if (IDDATA(hh)==(void *)currRing) PrintS("(R)"); |
---|
965 | else if (IDDATA(hh)==(void *)currPack) PrintS("(P)"); |
---|
966 | else PrintS(" "); |
---|
967 | Print("::%s, typ %s level %d data %lx", |
---|
968 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
969 | if ((IDTYP(hh)==RING_CMD) |
---|
970 | || (IDTYP(hh)==QRING_CMD)) |
---|
971 | Print(" ref: %d\n",IDRING(hh)->ref); |
---|
972 | else |
---|
973 | PrintLn(); |
---|
974 | } |
---|
975 | hh=IDNEXT(hh); |
---|
976 | } |
---|
977 | hh=basePack->idroot; |
---|
978 | while (hh!=NULL) |
---|
979 | { |
---|
980 | if (IDDATA(hh)==(void *)basePack) |
---|
981 | Print("(T)::%s, typ %s level %d data %lx\n", |
---|
982 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
983 | else |
---|
984 | if ((IDTYP(hh)==RING_CMD) |
---|
985 | || (IDTYP(hh)==QRING_CMD) |
---|
986 | || (IDTYP(hh)==PACKAGE_CMD)) |
---|
987 | { |
---|
988 | Print("====== %s ==============\n",IDID(hh)); |
---|
989 | idhdl h2=IDRING(hh)->idroot; |
---|
990 | while (h2!=NULL) |
---|
991 | { |
---|
992 | if (showproc || (IDTYP(h2)!=PROC_CMD)) |
---|
993 | { |
---|
994 | if ((IDDATA(h2)==(void *)currRing) |
---|
995 | && ((IDTYP(h2)==RING_CMD)||(IDTYP(h2)==QRING_CMD))) |
---|
996 | PrintS("(R)"); |
---|
997 | else if (IDDATA(h2)==(void *)currPack) PrintS("(P)"); |
---|
998 | else PrintS(" "); |
---|
999 | Print("%s::%s, typ %s level %d data %lx\n", |
---|
1000 | IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),(long)IDDATA(h2)); |
---|
1001 | } |
---|
1002 | h2=IDNEXT(h2); |
---|
1003 | } |
---|
1004 | } |
---|
1005 | hh=IDNEXT(hh); |
---|
1006 | } |
---|
1007 | Print("currRing:%lx, currPack:%lx,basePack:%lx\n",(long)currRing,(long)currPack,(long)basePack); |
---|
1008 | iiCheckPack(currPack); |
---|
1009 | } |
---|
1010 | #endif |
---|
1011 | |
---|
1012 | #ifndef SING_NDEBUG |
---|
1013 | void checkall() |
---|
1014 | { |
---|
1015 | idhdl hh=basePack->idroot; |
---|
1016 | while (hh!=NULL) |
---|
1017 | { |
---|
1018 | omCheckAddr(hh); |
---|
1019 | omCheckAddr((ADDRESS)IDID(hh)); |
---|
1020 | if (RingDependend(IDTYP(hh))) Print("%s typ %d in Top\n",IDID(hh),IDTYP(hh)); |
---|
1021 | hh=IDNEXT(hh); |
---|
1022 | } |
---|
1023 | hh=basePack->idroot; |
---|
1024 | while (hh!=NULL) |
---|
1025 | { |
---|
1026 | if (IDTYP(hh)==PACKAGE_CMD) |
---|
1027 | { |
---|
1028 | idhdl h2=IDPACKAGE(hh)->idroot; |
---|
1029 | while (h2!=NULL) |
---|
1030 | { |
---|
1031 | omCheckAddr(h2); |
---|
1032 | omCheckAddr((ADDRESS)IDID(h2)); |
---|
1033 | if (RingDependend(IDTYP(h2))) Print("%s typ %d in %s\n",IDID(h2),IDTYP(h2),IDID(hh)); |
---|
1034 | h2=IDNEXT(h2); |
---|
1035 | } |
---|
1036 | } |
---|
1037 | hh=IDNEXT(hh); |
---|
1038 | } |
---|
1039 | } |
---|
1040 | #endif |
---|
1041 | |
---|
1042 | #include <sys/types.h> |
---|
1043 | #include <sys/stat.h> |
---|
1044 | #include <unistd.h> |
---|
1045 | |
---|
1046 | extern "C" |
---|
1047 | int singular_fstat(int fd, struct stat *buf) |
---|
1048 | { |
---|
1049 | return si_fstat(fd,buf); |
---|
1050 | } |
---|
1051 | |
---|
1052 | /*2 |
---|
1053 | * the global exit routine of Singular |
---|
1054 | */ |
---|
1055 | extern "C" { |
---|
1056 | /* Note: We cannot use a mutex here because mutexes are not async-safe, but |
---|
1057 | * m2_end is called by sig_term_hdl(). Anyway, the race condition in the first |
---|
1058 | * few lines of m2_end() should not matter. |
---|
1059 | */ |
---|
1060 | volatile BOOLEAN m2_end_called = FALSE; |
---|
1061 | |
---|
1062 | void m2_end(int i) |
---|
1063 | { |
---|
1064 | if (!m2_end_called) |
---|
1065 | { |
---|
1066 | m2_end_called = TRUE; |
---|
1067 | #ifdef HAVE_SIMPLEIPC |
---|
1068 | for (int j = SIPC_MAX_SEMAPHORES; j >= 0; j--) |
---|
1069 | { |
---|
1070 | if (semaphore[j] != NULL) |
---|
1071 | { |
---|
1072 | while (sem_acquired[j] > 0) |
---|
1073 | { |
---|
1074 | sem_post(semaphore[j]); |
---|
1075 | sem_acquired[j]--; |
---|
1076 | } |
---|
1077 | } |
---|
1078 | } |
---|
1079 | #endif // HAVE_SIMPLEIPC |
---|
1080 | fe_reset_input_mode(); |
---|
1081 | #ifdef PAGE_TEST |
---|
1082 | mmEndStat(); |
---|
1083 | #endif |
---|
1084 | fe_reset_input_mode(); |
---|
1085 | if (ssiToBeClosed_inactive) |
---|
1086 | { |
---|
1087 | link_list hh=ssiToBeClosed; |
---|
1088 | while(hh!=NULL) |
---|
1089 | { |
---|
1090 | //Print("close %s\n",hh->l->name); |
---|
1091 | slPrepClose(hh->l); |
---|
1092 | hh=(link_list)hh->next; |
---|
1093 | } |
---|
1094 | ssiToBeClosed_inactive=FALSE; |
---|
1095 | |
---|
1096 | idhdl h = currPack->idroot; |
---|
1097 | while(h != NULL) |
---|
1098 | { |
---|
1099 | if(IDTYP(h) == LINK_CMD) |
---|
1100 | { |
---|
1101 | idhdl hh=h->next; |
---|
1102 | //Print("kill %s\n",IDID(h)); |
---|
1103 | killhdl(h, currPack); |
---|
1104 | h = hh; |
---|
1105 | } |
---|
1106 | else |
---|
1107 | { |
---|
1108 | h = h->next; |
---|
1109 | } |
---|
1110 | } |
---|
1111 | hh=ssiToBeClosed; |
---|
1112 | while(hh!=NULL) |
---|
1113 | { |
---|
1114 | //Print("close %s\n",hh->l->name); |
---|
1115 | slClose(hh->l); |
---|
1116 | hh=ssiToBeClosed; |
---|
1117 | } |
---|
1118 | } |
---|
1119 | if (!singular_in_batchmode) |
---|
1120 | { |
---|
1121 | if (i<=0) |
---|
1122 | { |
---|
1123 | if (TEST_V_QUIET) |
---|
1124 | { |
---|
1125 | if (i==0) |
---|
1126 | printf("Auf Wiedersehen.\n"); |
---|
1127 | else |
---|
1128 | printf("\n$Bye.\n"); |
---|
1129 | } |
---|
1130 | //#ifdef sun |
---|
1131 | // #ifndef __svr4__ |
---|
1132 | // _cleanup(); |
---|
1133 | // _exit(0); |
---|
1134 | // #endif |
---|
1135 | //#endif |
---|
1136 | i=0; |
---|
1137 | } |
---|
1138 | else |
---|
1139 | { |
---|
1140 | printf("\nhalt %d\n",i); |
---|
1141 | } |
---|
1142 | } |
---|
1143 | exit(i); |
---|
1144 | } |
---|
1145 | } |
---|
1146 | } |
---|
1147 | |
---|
1148 | const char *singular_date=__DATE__ " " __TIME__; |
---|
1149 | |
---|
1150 | extern "C" |
---|
1151 | { |
---|
1152 | void omSingOutOfMemoryFunc() |
---|
1153 | { |
---|
1154 | fprintf(stderr, "\nSingular error: no more memory\n"); |
---|
1155 | omPrintStats(stderr); |
---|
1156 | m2_end(14); |
---|
1157 | /* should never get here */ |
---|
1158 | exit(1); |
---|
1159 | } |
---|
1160 | } |
---|
1161 | |
---|
1162 | /*2 |
---|
1163 | * initialize components of Singular |
---|
1164 | */ |
---|
1165 | void siInit(char *name) |
---|
1166 | { |
---|
1167 | // factory default settings: ----------------------------------------------- |
---|
1168 | On(SW_USE_EZGCD); |
---|
1169 | On(SW_USE_CHINREM_GCD); |
---|
1170 | //On(SW_USE_FF_MOD_GCD); |
---|
1171 | On(SW_USE_EZGCD_P); |
---|
1172 | On(SW_USE_QGCD); |
---|
1173 | Off(SW_USE_NTL_SORT); // may be changed by an command line option |
---|
1174 | factoryError=WerrorS; |
---|
1175 | |
---|
1176 | // memory initialization: ----------------------------------------------- |
---|
1177 | om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc; |
---|
1178 | #ifndef OM_NDEBUG |
---|
1179 | #ifndef __OPTIMIZE__ |
---|
1180 | om_Opts.ErrorHook = dErrorBreak; |
---|
1181 | #else |
---|
1182 | om_Opts.Keep = 0; /* !OM_NDEBUG, __OPTIMIZE__*/ |
---|
1183 | #endif |
---|
1184 | #else |
---|
1185 | om_Opts.Keep = 0; /* OM_NDEBUG */ |
---|
1186 | #endif |
---|
1187 | omInitInfo(); |
---|
1188 | |
---|
1189 | // interpreter tables etc.: ----------------------------------------------- |
---|
1190 | #ifdef INIT_BUG |
---|
1191 | jjInitTab1(); |
---|
1192 | #endif |
---|
1193 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
1194 | sLastPrinted.rtyp=NONE; |
---|
1195 | |
---|
1196 | extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc |
---|
1197 | |
---|
1198 | basePack=(package)omAlloc0(sizeof(*basePack)); |
---|
1199 | currPack=basePack; |
---|
1200 | idhdl h; |
---|
1201 | h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
1202 | IDPACKAGE(h)->language = LANG_TOP; |
---|
1203 | IDPACKAGE(h)=basePack; |
---|
1204 | currPackHdl=h; |
---|
1205 | basePackHdl=h; |
---|
1206 | |
---|
1207 | coeffs_BIGINT = nInitChar(n_Q,NULL); |
---|
1208 | |
---|
1209 | #if 1 |
---|
1210 | // def HAVE_POLYEXTENSIONS |
---|
1211 | if(TRUE) |
---|
1212 | { |
---|
1213 | n_coeffType type = nRegister(n_algExt, naInitChar); |
---|
1214 | assume(type == n_algExt); |
---|
1215 | |
---|
1216 | type = nRegister(n_transExt, ntInitChar); |
---|
1217 | assume(type == n_transExt); |
---|
1218 | |
---|
1219 | (void)type; |
---|
1220 | } |
---|
1221 | #endif |
---|
1222 | |
---|
1223 | // random generator: ----------------------------------------------- |
---|
1224 | int t=initTimer(); |
---|
1225 | if (t==0) t=1; |
---|
1226 | initRTimer(); |
---|
1227 | siSeed=t; |
---|
1228 | factoryseed(t); |
---|
1229 | siRandomStart=t; |
---|
1230 | feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart); |
---|
1231 | |
---|
1232 | // ressource table: ---------------------------------------------------- |
---|
1233 | // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed |
---|
1234 | // hack such that all shared' libs in the bindir are loaded correctly |
---|
1235 | feInitResources(name); |
---|
1236 | |
---|
1237 | // singular links: -------------------------------------------------- |
---|
1238 | slStandardInit(); |
---|
1239 | myynest=0; |
---|
1240 | // semapohore 0 ----------------------------------------------------- |
---|
1241 | int cpus=2; |
---|
1242 | int cpu_n; |
---|
1243 | #ifdef _SC_NPROCESSORS_ONLN |
---|
1244 | if ((cpu_n=sysconf(_SC_NPROCESSORS_ONLN))>cpus) cpus=cpu_n; |
---|
1245 | #elif defined(_SC_NPROCESSORS_CONF) |
---|
1246 | if ((cpu_n=sysconf(_SC_NPROCESSORS_CONF))>cpus) cpus=cpu_n; |
---|
1247 | #endif |
---|
1248 | feSetOptValue(FE_OPT_CPUS, cpus); |
---|
1249 | |
---|
1250 | // loading standard.lib ----------------------------------------------- |
---|
1251 | if (! feOptValue(FE_OPT_NO_STDLIB)) |
---|
1252 | { |
---|
1253 | BITSET save1,save2; |
---|
1254 | SI_SAVE_OPT(save1,save2); |
---|
1255 | si_opt_2 &= ~Sy_bit(V_LOAD_LIB); |
---|
1256 | iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE); |
---|
1257 | SI_RESTORE_OPT(save1,save2); |
---|
1258 | } |
---|
1259 | errorreported = 0; |
---|
1260 | } |
---|