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 | #include <misc/auxiliary.h> |
---|
15 | #include "config.h" |
---|
16 | #include <kernel/mod2.h> |
---|
17 | |
---|
18 | #ifdef HAVE_FACTORY |
---|
19 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
20 | #include <factory/factory.h> |
---|
21 | #endif |
---|
22 | |
---|
23 | #include <coeffs/si_gmp.h> |
---|
24 | #include <coeffs/coeffs.h> |
---|
25 | |
---|
26 | #include <polys/ext_fields/algext.h> |
---|
27 | #include <polys/ext_fields/transext.h> |
---|
28 | |
---|
29 | #include "misc_ip.h" |
---|
30 | #include "ipid.h" |
---|
31 | #include "feOpt.h" |
---|
32 | #include "links/silink.h" |
---|
33 | |
---|
34 | // the following 2 inline functions are just convenience shortcuts for Frank's code: |
---|
35 | static inline void number2mpz(number n, mpz_t m){ n_MPZ(m, n, coeffs_BIGINT); } |
---|
36 | static inline number mpz2number(mpz_t m){ return n_InitMPZ(m, coeffs_BIGINT); } |
---|
37 | |
---|
38 | |
---|
39 | void setListEntry(lists L, int index, mpz_t n) |
---|
40 | { /* assumes n > 0 */ |
---|
41 | /* try to fit nn into an int: */ |
---|
42 | if (mpz_size1(n)<=1) |
---|
43 | { |
---|
44 | int ui=(int)mpz_get_si(n); |
---|
45 | if ((((ui<<3)>>3)==ui) |
---|
46 | && (mpz_cmp_si(n,(long)ui)==0)) |
---|
47 | { |
---|
48 | L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)ui; |
---|
49 | return; |
---|
50 | } |
---|
51 | } |
---|
52 | number nn = mpz2number(n); |
---|
53 | L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn; |
---|
54 | } |
---|
55 | |
---|
56 | void setListEntry_ui(lists L, int index, unsigned long ui) |
---|
57 | { /* assumes n > 0 */ |
---|
58 | /* try to fit nn into an int: */ |
---|
59 | int i=(int)ui; |
---|
60 | if ((((unsigned long)i)==ui) && (((i<<3)>>3)==i)) |
---|
61 | { |
---|
62 | L->m[index].rtyp = INT_CMD; L->m[index].data = (void*)i; |
---|
63 | } |
---|
64 | else |
---|
65 | { |
---|
66 | number nn = n_Init(ui, coeffs_BIGINT); |
---|
67 | L->m[index].rtyp = BIGINT_CMD; L->m[index].data = (void*)nn; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | /* Factoring with Pollard's rho method. stolen from GMP/demos */ |
---|
72 | static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6}; |
---|
73 | |
---|
74 | static int factor_using_division (mpz_t t, unsigned int limit,lists primes, int *multiplicities,int &index, unsigned long bound) |
---|
75 | { |
---|
76 | mpz_t q, r; |
---|
77 | unsigned long int f; |
---|
78 | int ai; |
---|
79 | unsigned *addv = add; |
---|
80 | unsigned int failures; |
---|
81 | int bound_not_reached=1; |
---|
82 | |
---|
83 | mpz_init (q); |
---|
84 | mpz_init (r); |
---|
85 | |
---|
86 | f = mpz_scan1 (t, 0); |
---|
87 | mpz_div_2exp (t, t, f); |
---|
88 | if (f>0) |
---|
89 | { |
---|
90 | setListEntry_ui(primes, index, 2); |
---|
91 | multiplicities[index++] = f; |
---|
92 | } |
---|
93 | |
---|
94 | f=0; |
---|
95 | loop |
---|
96 | { |
---|
97 | mpz_tdiv_qr_ui (q, r, t, 3); |
---|
98 | if (mpz_cmp_ui (r, 0) != 0) |
---|
99 | break; |
---|
100 | mpz_set (t, q); |
---|
101 | f++; |
---|
102 | } |
---|
103 | if (f>0) |
---|
104 | { |
---|
105 | setListEntry_ui(primes, index, 3); |
---|
106 | multiplicities[index++] = f; |
---|
107 | } |
---|
108 | f=0; |
---|
109 | loop |
---|
110 | { |
---|
111 | mpz_tdiv_qr_ui (q, r, t, 5); |
---|
112 | if (mpz_cmp_ui (r, 0) != 0) |
---|
113 | break; |
---|
114 | mpz_set (t, q); |
---|
115 | f++; |
---|
116 | } |
---|
117 | if (f>0) |
---|
118 | { |
---|
119 | setListEntry_ui(primes, index, 5); |
---|
120 | multiplicities[index++] = f; |
---|
121 | } |
---|
122 | |
---|
123 | failures = 0; |
---|
124 | f = 7; |
---|
125 | ai = 0; |
---|
126 | unsigned long last_f=0; |
---|
127 | while (mpz_cmp_ui (t, 1) != 0) |
---|
128 | { |
---|
129 | mpz_tdiv_qr_ui (q, r, t, f); |
---|
130 | if (mpz_cmp_ui (r, 0) != 0) |
---|
131 | { |
---|
132 | f += addv[ai]; |
---|
133 | if (mpz_cmp_ui (t, f) < 0) |
---|
134 | break; |
---|
135 | ai = (ai + 1) & 7; |
---|
136 | failures++; |
---|
137 | if (failures > limit) |
---|
138 | break; |
---|
139 | if ((bound!=0) && (f>bound)) |
---|
140 | { |
---|
141 | bound_not_reached=0; |
---|
142 | break; |
---|
143 | } |
---|
144 | } |
---|
145 | else |
---|
146 | { |
---|
147 | mpz_swap (t, q); |
---|
148 | if (f!=last_f) |
---|
149 | { |
---|
150 | setListEntry_ui(primes, index, f); |
---|
151 | multiplicities[index]++; |
---|
152 | index++; |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | multiplicities[index-1]++; |
---|
157 | } |
---|
158 | last_f=f; |
---|
159 | failures = 0; |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | mpz_clear (q); |
---|
164 | mpz_clear (r); |
---|
165 | //printf("bound=%d,f=%d,failures=%d, reached=%d\n",bound,f,failures,bound_not_reached); |
---|
166 | return bound_not_reached; |
---|
167 | } |
---|
168 | |
---|
169 | static void factor_using_pollard_rho (mpz_t n, unsigned long a, lists primes, int * multiplicities,int &index) |
---|
170 | { |
---|
171 | mpz_t x, x1, y, P; |
---|
172 | mpz_t t1, t2; |
---|
173 | mpz_t last_f; |
---|
174 | unsigned long long k, l, i; |
---|
175 | |
---|
176 | mpz_init (t1); |
---|
177 | mpz_init (t2); |
---|
178 | mpz_init_set_si (last_f, 0); |
---|
179 | mpz_init_set_si (y, 2); |
---|
180 | mpz_init_set_si (x, 2); |
---|
181 | mpz_init_set_si (x1, 2); |
---|
182 | mpz_init_set_ui (P, 1); |
---|
183 | k = 1; |
---|
184 | l = 1; |
---|
185 | |
---|
186 | while (mpz_cmp_ui (n, 1) != 0) |
---|
187 | { |
---|
188 | loop |
---|
189 | { |
---|
190 | do |
---|
191 | { |
---|
192 | mpz_mul (t1, x, x); |
---|
193 | mpz_mod (x, t1, n); |
---|
194 | mpz_add_ui (x, x, a); |
---|
195 | mpz_sub (t1, x1, x); |
---|
196 | mpz_mul (t2, P, t1); |
---|
197 | mpz_mod (P, t2, n); |
---|
198 | |
---|
199 | if (k % 32 == 1) |
---|
200 | { |
---|
201 | mpz_gcd (t1, P, n); |
---|
202 | if (mpz_cmp_ui (t1, 1) != 0) |
---|
203 | goto factor_found; |
---|
204 | mpz_set (y, x); |
---|
205 | } |
---|
206 | } |
---|
207 | while (--k != 0); |
---|
208 | |
---|
209 | mpz_gcd (t1, P, n); |
---|
210 | if (mpz_cmp_ui (t1, 1) != 0) |
---|
211 | goto factor_found; |
---|
212 | |
---|
213 | mpz_set (x1, x); |
---|
214 | k = l; |
---|
215 | l = 2 * l; |
---|
216 | for (i = 0; i < k; i++) |
---|
217 | { |
---|
218 | mpz_mul (t1, x, x); |
---|
219 | mpz_mod (x, t1, n); |
---|
220 | mpz_add_ui (x, x, a); |
---|
221 | } |
---|
222 | mpz_set (y, x); |
---|
223 | } |
---|
224 | |
---|
225 | factor_found: |
---|
226 | do |
---|
227 | { |
---|
228 | mpz_mul (t1, y, y); |
---|
229 | mpz_mod (y, t1, n); |
---|
230 | mpz_add_ui (y, y, a); |
---|
231 | mpz_sub (t1, x1, y); |
---|
232 | mpz_gcd (t1, t1, n); |
---|
233 | } |
---|
234 | while (mpz_cmp_ui (t1, 1) == 0); |
---|
235 | |
---|
236 | mpz_divexact (n, n, t1); /* divide by t1, before t1 is overwritten */ |
---|
237 | |
---|
238 | if (!mpz_probab_prime_p (t1, 10)) |
---|
239 | { |
---|
240 | do |
---|
241 | { |
---|
242 | mp_limb_t a_limb; |
---|
243 | mpn_random (&a_limb, (mp_size_t) 1); |
---|
244 | a = a_limb; |
---|
245 | } |
---|
246 | while (a == 0); |
---|
247 | |
---|
248 | factor_using_pollard_rho (t1, a, primes,multiplicities,index); |
---|
249 | } |
---|
250 | else |
---|
251 | { |
---|
252 | if (mpz_cmp(t1,last_f)==0) |
---|
253 | { |
---|
254 | multiplicities[index-1]++; |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | mpz_set(last_f,t1); |
---|
259 | setListEntry(primes, index, t1); |
---|
260 | multiplicities[index++] = 1; |
---|
261 | } |
---|
262 | } |
---|
263 | mpz_mod (x, x, n); |
---|
264 | mpz_mod (x1, x1, n); |
---|
265 | mpz_mod (y, y, n); |
---|
266 | if (mpz_probab_prime_p (n, 10)) |
---|
267 | { |
---|
268 | if (mpz_cmp(n,last_f)==0) |
---|
269 | { |
---|
270 | multiplicities[index-1]++; |
---|
271 | } |
---|
272 | else |
---|
273 | { |
---|
274 | mpz_set(last_f,n); |
---|
275 | setListEntry(primes, index, n); |
---|
276 | multiplicities[index++] = 1; |
---|
277 | } |
---|
278 | mpz_set_ui(n,1); |
---|
279 | break; |
---|
280 | } |
---|
281 | } |
---|
282 | |
---|
283 | mpz_clear (P); |
---|
284 | mpz_clear (t2); |
---|
285 | mpz_clear (t1); |
---|
286 | mpz_clear (x1); |
---|
287 | mpz_clear (x); |
---|
288 | mpz_clear (y); |
---|
289 | mpz_clear (last_f); |
---|
290 | } |
---|
291 | |
---|
292 | static void factor_gmp (mpz_t t,lists primes,int *multiplicities,int &index,unsigned long bound) |
---|
293 | { |
---|
294 | unsigned int division_limit; |
---|
295 | |
---|
296 | if (mpz_sgn (t) == 0) |
---|
297 | return; |
---|
298 | |
---|
299 | /* Set the trial division limit according the size of t. */ |
---|
300 | division_limit = mpz_sizeinbase (t, 2); |
---|
301 | if (division_limit > 1000) |
---|
302 | division_limit = 1000 * 1000; |
---|
303 | else |
---|
304 | division_limit = division_limit * division_limit; |
---|
305 | |
---|
306 | if (factor_using_division (t, division_limit,primes,multiplicities,index,bound)) |
---|
307 | { |
---|
308 | if (mpz_cmp_ui (t, 1) != 0) |
---|
309 | { |
---|
310 | if (mpz_probab_prime_p (t, 10)) |
---|
311 | { |
---|
312 | setListEntry(primes, index, t); |
---|
313 | multiplicities[index++] = 1; |
---|
314 | mpz_set_ui(t,1); |
---|
315 | } |
---|
316 | else |
---|
317 | factor_using_pollard_rho (t, 1L, primes,multiplicities,index); |
---|
318 | } |
---|
319 | } |
---|
320 | } |
---|
321 | /* n and pBound are assumed to be bigint numbers */ |
---|
322 | lists primeFactorisation(const number n, const int pBound) |
---|
323 | { |
---|
324 | int i; |
---|
325 | int index=0; |
---|
326 | mpz_t nn; number2mpz(n, nn); |
---|
327 | lists primes = (lists)omAllocBin(slists_bin); primes->Init(1000); |
---|
328 | int* multiplicities = (int*)omAlloc0(1000*sizeof(int)); |
---|
329 | int positive=1; |
---|
330 | |
---|
331 | if (!n_IsZero(n, coeffs_BIGINT)) |
---|
332 | { |
---|
333 | if (!n_GreaterZero(n, coeffs_BIGINT)) |
---|
334 | { |
---|
335 | positive=-1; |
---|
336 | mpz_neg(nn,nn); |
---|
337 | } |
---|
338 | factor_gmp(nn,primes,multiplicities,index,pBound); |
---|
339 | } |
---|
340 | |
---|
341 | lists primesL = (lists)omAllocBin(slists_bin); |
---|
342 | primesL->Init(index); |
---|
343 | for (i = 0; i < index; i++) |
---|
344 | { |
---|
345 | primesL->m[i].rtyp = primes->m[i].rtyp; |
---|
346 | primesL->m[i].data = primes->m[i].data; |
---|
347 | primes->m[i].rtyp=0; |
---|
348 | primes->m[i].data=NULL; |
---|
349 | } |
---|
350 | primes->Clean(NULL); |
---|
351 | |
---|
352 | lists multiplicitiesL = (lists)omAllocBin(slists_bin); |
---|
353 | multiplicitiesL->Init(index); |
---|
354 | for (i = 0; i < index; i++) |
---|
355 | { |
---|
356 | multiplicitiesL->m[i].rtyp = INT_CMD; |
---|
357 | multiplicitiesL->m[i].data = (void*)multiplicities[i]; |
---|
358 | } |
---|
359 | omFree(multiplicities); |
---|
360 | |
---|
361 | lists L=(lists)omAllocBin(slists_bin); |
---|
362 | L->Init(3); |
---|
363 | if (positive==-1) mpz_neg(nn,nn); |
---|
364 | L->m[0].rtyp = LIST_CMD; L->m[0].data = (void*)primesL; |
---|
365 | L->m[1].rtyp = LIST_CMD; L->m[1].data = (void*)multiplicitiesL; |
---|
366 | setListEntry(L, 2, nn); |
---|
367 | |
---|
368 | mpz_clear(nn); |
---|
369 | |
---|
370 | return L; |
---|
371 | } |
---|
372 | |
---|
373 | #include <omalloc/omalloc.h> |
---|
374 | #include <misc/mylimits.h> |
---|
375 | |
---|
376 | #include <misc/options.h> |
---|
377 | #include <misc/intvec.h> |
---|
378 | |
---|
379 | #include <polys/monomials/ring.h> |
---|
380 | #include <polys/templates/p_Procs.h> |
---|
381 | |
---|
382 | #include <kernel/febase.h> |
---|
383 | #include <kernel/kstd1.h> |
---|
384 | #include <kernel/timer.h> |
---|
385 | |
---|
386 | |
---|
387 | #include "subexpr.h" |
---|
388 | #include "cntrlc.h" |
---|
389 | #include "ipid.h" |
---|
390 | #include "ipshell.h" |
---|
391 | |
---|
392 | #include "version.h" |
---|
393 | |
---|
394 | #include "fehelp.h" |
---|
395 | |
---|
396 | #ifdef HAVE_STATIC |
---|
397 | #undef HAVE_DYN_RL |
---|
398 | #endif |
---|
399 | |
---|
400 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
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 | char * versionString() |
---|
770 | { |
---|
771 | StringSetS(""); |
---|
772 | StringAppend("Singular for %s version %s (%s %s) %s\nwith\n", // %d- |
---|
773 | S_UNAME, S_VERSION1, // SINGULAR_VERSION, |
---|
774 | PACKAGE_VERSION, feVersionId, singular_date); |
---|
775 | StringAppendS("\t"); |
---|
776 | #ifdef HAVE_FACTORY |
---|
777 | StringAppend("factory(%s)", factoryVersion); |
---|
778 | #ifdef HAVE_LIBFAC |
---|
779 | // libfac: |
---|
780 | // extern const char * libfac_version; |
---|
781 | // extern const char * libfac_date; |
---|
782 | StringAppend("+libfac"); |
---|
783 | #endif // #ifdef HAVE_LIBFAC |
---|
784 | StringAppend(","); |
---|
785 | #endif |
---|
786 | |
---|
787 | #if defined (__GNU_MP_VERSION) && defined (__GNU_MP_VERSION_MINOR) |
---|
788 | StringAppend("GMP(%d.%d),",__GNU_MP_VERSION,__GNU_MP_VERSION_MINOR); |
---|
789 | #else |
---|
790 | StringAppendS("GMP(1.3),"); |
---|
791 | #endif |
---|
792 | #ifdef HAVE_NTL |
---|
793 | #include <NTL/version.h> |
---|
794 | StringAppend("NTL(%s),",NTL_VERSION); |
---|
795 | #endif |
---|
796 | #if SIZEOF_VOIDP == 8 |
---|
797 | StringAppendS("64bit,"); |
---|
798 | #else |
---|
799 | StringAppendS("32bit,"); |
---|
800 | #endif |
---|
801 | #if defined(HAVE_DYN_RL) |
---|
802 | if (fe_fgets_stdin==fe_fgets_dummy) |
---|
803 | StringAppendS("no input,"); |
---|
804 | else if (fe_fgets_stdin==fe_fgets) |
---|
805 | StringAppendS("fgets,"); |
---|
806 | if (fe_fgets_stdin==fe_fgets_stdin_drl) |
---|
807 | StringAppendS("dynamic readline,"); |
---|
808 | #ifdef HAVE_FEREAD |
---|
809 | else if (fe_fgets_stdin==fe_fgets_stdin_emu) |
---|
810 | StringAppendS("emulated readline,"); |
---|
811 | #endif |
---|
812 | else |
---|
813 | StringAppendS("unknown fgets method,"); |
---|
814 | #else |
---|
815 | #if defined(HAVE_READLINE) && !defined(FEREAD) |
---|
816 | StringAppendS("static readline,"); |
---|
817 | #else |
---|
818 | #ifdef HAVE_FEREAD |
---|
819 | StringAppendS("emulated readline,"); |
---|
820 | #else |
---|
821 | StringAppendS("fgets,"); |
---|
822 | #endif |
---|
823 | #endif |
---|
824 | #endif |
---|
825 | #ifdef HAVE_PLURAL |
---|
826 | StringAppendS("Plural,"); |
---|
827 | #endif |
---|
828 | #ifdef HAVE_DBM |
---|
829 | StringAppendS("DBM,\n\t"); |
---|
830 | #else |
---|
831 | StringAppendS("\n\t"); |
---|
832 | #endif |
---|
833 | #ifdef HAVE_DYNAMIC_LOADING |
---|
834 | StringAppendS("dynamic modules,"); |
---|
835 | #endif |
---|
836 | if (p_procs_dynamic) StringAppendS("dynamic p_Procs,"); |
---|
837 | #ifdef TEST |
---|
838 | StringAppendS("TESTs,"); |
---|
839 | #endif |
---|
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 PDEBUG |
---|
859 | StringAppendS("PDEBUG,"); |
---|
860 | #endif |
---|
861 | #ifdef KDEBUG |
---|
862 | StringAppendS("KDEBUG,"); |
---|
863 | #endif |
---|
864 | #ifndef __OPTIMIZE__ |
---|
865 | StringAppendS("-g,"); |
---|
866 | #endif |
---|
867 | #ifdef HAVE_EIGENVAL |
---|
868 | StringAppendS("eigenvalues,"); |
---|
869 | #endif |
---|
870 | #ifdef HAVE_GMS |
---|
871 | StringAppendS("Gauss-Manin system,"); |
---|
872 | #endif |
---|
873 | #ifdef HAVE_RATGRING |
---|
874 | StringAppendS("ratGB,"); |
---|
875 | #endif |
---|
876 | StringAppend("random=%d\n",siRandomStart); |
---|
877 | StringAppend("\tCC=%s,\n\tCXX=%s" |
---|
878 | #ifdef __GNUC__ |
---|
879 | "(" __VERSION__ ")" |
---|
880 | #endif |
---|
881 | "\n",CC,CXX); |
---|
882 | feStringAppendResources(0); |
---|
883 | feStringAppendBrowsers(0); |
---|
884 | StringAppendS("\n"); |
---|
885 | return StringEndS(); |
---|
886 | } |
---|
887 | |
---|
888 | #ifdef PDEBUG |
---|
889 | #if (OM_TRACK > 2) && defined(OM_TRACK_CUSTOM) |
---|
890 | void p_SetRingOfLeftv(leftv l, ring r) |
---|
891 | { |
---|
892 | switch(l->rtyp) |
---|
893 | { |
---|
894 | case INT_CMD: |
---|
895 | case BIGINT_CMD: |
---|
896 | case IDHDL: |
---|
897 | case DEF_CMD: |
---|
898 | break; |
---|
899 | case POLY_CMD: |
---|
900 | case VECTOR_CMD: |
---|
901 | { |
---|
902 | poly p=(poly)l->data; |
---|
903 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
904 | break; |
---|
905 | } |
---|
906 | case IDEAL_CMD: |
---|
907 | case MODUL_CMD: |
---|
908 | case MATRIX_CMD: |
---|
909 | { |
---|
910 | ideal I=(ideal)l->data; |
---|
911 | int i; |
---|
912 | for(i=IDELEMS(I)-1;i>=0;i--) |
---|
913 | { |
---|
914 | poly p=I->m[i]; |
---|
915 | while(p!=NULL) { p_SetRingOfLm(p,r); pIter(p); } |
---|
916 | } |
---|
917 | break; |
---|
918 | } |
---|
919 | case COMMAND: |
---|
920 | { |
---|
921 | command d=(command)l->data; |
---|
922 | p_SetRingOfLeftv(&d->arg1, r); |
---|
923 | if (d->argc>1) p_SetRingOfLeftv(&d->arg2, r); |
---|
924 | if (d->argc>2) p_SetRingOfLeftv(&d->arg3, r); |
---|
925 | break; |
---|
926 | } |
---|
927 | default: |
---|
928 | printf("type %d not yet implementd in p_SetRingOfLeftv\n",l->rtyp); |
---|
929 | break; |
---|
930 | } |
---|
931 | } |
---|
932 | #endif |
---|
933 | #endif |
---|
934 | |
---|
935 | #if 0 /* debug only */ |
---|
936 | void listall(int showproc) |
---|
937 | { |
---|
938 | idhdl hh=basePack->idroot; |
---|
939 | PrintS("====== Top ==============\n"); |
---|
940 | while (hh!=NULL) |
---|
941 | { |
---|
942 | if (showproc || (IDTYP(hh)!=PROC_CMD)) |
---|
943 | { |
---|
944 | if (IDDATA(hh)==(void *)currRing) PrintS("(R)"); |
---|
945 | else if (IDDATA(hh)==(void *)currPack) PrintS("(P)"); |
---|
946 | else PrintS(" "); |
---|
947 | Print("::%s, typ %s level %d data %lx", |
---|
948 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
949 | if ((IDTYP(hh)==RING_CMD) |
---|
950 | || (IDTYP(hh)==QRING_CMD)) |
---|
951 | Print(" ref: %d\n",IDRING(hh)->ref); |
---|
952 | else |
---|
953 | PrintLn(); |
---|
954 | } |
---|
955 | hh=IDNEXT(hh); |
---|
956 | } |
---|
957 | hh=basePack->idroot; |
---|
958 | while (hh!=NULL) |
---|
959 | { |
---|
960 | if (IDDATA(hh)==(void *)basePack) |
---|
961 | Print("(T)::%s, typ %s level %d data %lx\n", |
---|
962 | IDID(hh),Tok2Cmdname(IDTYP(hh)),IDLEV(hh),(long)IDDATA(hh)); |
---|
963 | else |
---|
964 | if ((IDTYP(hh)==RING_CMD) |
---|
965 | || (IDTYP(hh)==QRING_CMD) |
---|
966 | || (IDTYP(hh)==PACKAGE_CMD)) |
---|
967 | { |
---|
968 | Print("====== %s ==============\n",IDID(hh)); |
---|
969 | idhdl h2=IDRING(hh)->idroot; |
---|
970 | while (h2!=NULL) |
---|
971 | { |
---|
972 | if (showproc || (IDTYP(h2)!=PROC_CMD)) |
---|
973 | { |
---|
974 | if ((IDDATA(h2)==(void *)currRing) |
---|
975 | && ((IDTYP(h2)==RING_CMD)||(IDTYP(h2)==QRING_CMD))) |
---|
976 | PrintS("(R)"); |
---|
977 | else if (IDDATA(h2)==(void *)currPack) PrintS("(P)"); |
---|
978 | else PrintS(" "); |
---|
979 | Print("%s::%s, typ %s level %d data %lx\n", |
---|
980 | IDID(hh),IDID(h2),Tok2Cmdname(IDTYP(h2)),IDLEV(h2),(long)IDDATA(h2)); |
---|
981 | } |
---|
982 | h2=IDNEXT(h2); |
---|
983 | } |
---|
984 | } |
---|
985 | hh=IDNEXT(hh); |
---|
986 | } |
---|
987 | Print("currRing:%lx, currPack:%lx,basePack:%lx\n",(long)currRing,(long)currPack,(long)basePack); |
---|
988 | iiCheckPack(currPack); |
---|
989 | } |
---|
990 | #endif |
---|
991 | |
---|
992 | #ifndef NDEBUG |
---|
993 | void checkall() |
---|
994 | { |
---|
995 | idhdl hh=basePack->idroot; |
---|
996 | while (hh!=NULL) |
---|
997 | { |
---|
998 | omCheckAddr(hh); |
---|
999 | omCheckAddr((ADDRESS)IDID(hh)); |
---|
1000 | if (RingDependend(IDTYP(hh))) Print("%s typ %d in Top\n",IDID(hh),IDTYP(hh)); |
---|
1001 | hh=IDNEXT(hh); |
---|
1002 | } |
---|
1003 | hh=basePack->idroot; |
---|
1004 | while (hh!=NULL) |
---|
1005 | { |
---|
1006 | if (IDTYP(hh)==PACKAGE_CMD) |
---|
1007 | { |
---|
1008 | idhdl h2=IDPACKAGE(hh)->idroot; |
---|
1009 | while (h2!=NULL) |
---|
1010 | { |
---|
1011 | omCheckAddr(h2); |
---|
1012 | omCheckAddr((ADDRESS)IDID(h2)); |
---|
1013 | if (RingDependend(IDTYP(h2))) Print("%s typ %d in %s\n",IDID(h2),IDTYP(h2),IDID(hh)); |
---|
1014 | h2=IDNEXT(h2); |
---|
1015 | } |
---|
1016 | } |
---|
1017 | hh=IDNEXT(hh); |
---|
1018 | } |
---|
1019 | } |
---|
1020 | #endif |
---|
1021 | |
---|
1022 | #include <sys/types.h> |
---|
1023 | #include <sys/stat.h> |
---|
1024 | #include <unistd.h> |
---|
1025 | |
---|
1026 | extern "C" |
---|
1027 | int singular_fstat(int fd, struct stat *buf) |
---|
1028 | { |
---|
1029 | return fstat(fd,buf); |
---|
1030 | } |
---|
1031 | |
---|
1032 | /*2 |
---|
1033 | * the global exit routine of Singular |
---|
1034 | */ |
---|
1035 | extern "C" { |
---|
1036 | |
---|
1037 | void m2_end(int i) |
---|
1038 | { |
---|
1039 | fe_reset_input_mode(); |
---|
1040 | #ifdef PAGE_TEST |
---|
1041 | mmEndStat(); |
---|
1042 | #endif |
---|
1043 | fe_reset_input_mode(); |
---|
1044 | idhdl h = IDROOT; |
---|
1045 | while(h != NULL) |
---|
1046 | { |
---|
1047 | if(IDTYP(h) == LINK_CMD) |
---|
1048 | { |
---|
1049 | idhdl hh=h->next; |
---|
1050 | killhdl(h, currPack); |
---|
1051 | h = hh; |
---|
1052 | } |
---|
1053 | else |
---|
1054 | { |
---|
1055 | h = h->next; |
---|
1056 | } |
---|
1057 | } |
---|
1058 | if(!singular_in_batchmode) |
---|
1059 | { |
---|
1060 | if (i<=0) |
---|
1061 | { |
---|
1062 | if (TEST_V_QUIET) |
---|
1063 | { |
---|
1064 | if (i==0) |
---|
1065 | printf("Auf Wiedersehen.\n"); |
---|
1066 | else |
---|
1067 | printf("\n$Bye.\n"); |
---|
1068 | } |
---|
1069 | //#ifdef sun |
---|
1070 | // #ifndef __svr4__ |
---|
1071 | // _cleanup(); |
---|
1072 | // _exit(0); |
---|
1073 | // #endif |
---|
1074 | //#endif |
---|
1075 | i=0; |
---|
1076 | } |
---|
1077 | else |
---|
1078 | { |
---|
1079 | printf("\nhalt %d\n",i); |
---|
1080 | } |
---|
1081 | } |
---|
1082 | exit(i); |
---|
1083 | } |
---|
1084 | } |
---|
1085 | |
---|
1086 | const char *singular_date=__DATE__ " " __TIME__; |
---|
1087 | |
---|
1088 | extern "C" |
---|
1089 | { |
---|
1090 | void omSingOutOfMemoryFunc() |
---|
1091 | { |
---|
1092 | fprintf(stderr, "\nSingular error: no more memory\n"); |
---|
1093 | omPrintStats(stderr); |
---|
1094 | m2_end(14); |
---|
1095 | /* should never get here */ |
---|
1096 | exit(1); |
---|
1097 | } |
---|
1098 | } |
---|
1099 | |
---|
1100 | /*2 |
---|
1101 | * initialize components of Singular |
---|
1102 | */ |
---|
1103 | void siInit(char *name) |
---|
1104 | { |
---|
1105 | #ifdef HAVE_FACTORY |
---|
1106 | // factory default settings: ----------------------------------------------- |
---|
1107 | On(SW_USE_NTL); |
---|
1108 | On(SW_USE_NTL_GCD_0); // On -> seg11 in Old/algnorm, Old/factor... |
---|
1109 | On(SW_USE_NTL_GCD_P); // On -> cyle in Short/brnoeth_s: fixed |
---|
1110 | On(SW_USE_EZGCD); |
---|
1111 | On(SW_USE_CHINREM_GCD); |
---|
1112 | //On(SW_USE_FF_MOD_GCD); |
---|
1113 | On(SW_USE_EZGCD_P); |
---|
1114 | On(SW_USE_QGCD); |
---|
1115 | Off(SW_USE_NTL_SORT); // may be changed by an command line option |
---|
1116 | factoryError=WerrorS; |
---|
1117 | #endif |
---|
1118 | |
---|
1119 | // memory initialization: ----------------------------------------------- |
---|
1120 | om_Opts.OutOfMemoryFunc = omSingOutOfMemoryFunc; |
---|
1121 | #ifndef OM_NDEBUG |
---|
1122 | #ifndef __OPTIMIZE__ |
---|
1123 | om_Opts.ErrorHook = dErrorBreak; |
---|
1124 | #else |
---|
1125 | om_Opts.Keep = 0; /* !OM_NDEBUG, __OPTIMIZE__*/ |
---|
1126 | #endif |
---|
1127 | #else |
---|
1128 | om_Opts.Keep = 0; /* OM_NDEBUG */ |
---|
1129 | #endif |
---|
1130 | omInitInfo(); |
---|
1131 | |
---|
1132 | // interpreter tables etc.: ----------------------------------------------- |
---|
1133 | #ifdef INIT_BUG |
---|
1134 | jjInitTab1(); |
---|
1135 | #endif |
---|
1136 | memset(&sLastPrinted,0,sizeof(sleftv)); |
---|
1137 | sLastPrinted.rtyp=NONE; |
---|
1138 | |
---|
1139 | extern int iiInitArithmetic(); iiInitArithmetic(); // iparith.cc |
---|
1140 | |
---|
1141 | basePack=(package)omAlloc0(sizeof(*basePack)); |
---|
1142 | currPack=basePack; |
---|
1143 | idhdl h; |
---|
1144 | h=enterid("Top", 0, PACKAGE_CMD, &IDROOT, TRUE); |
---|
1145 | IDPACKAGE(h)->language = LANG_TOP; |
---|
1146 | IDPACKAGE(h)=basePack; |
---|
1147 | currPackHdl=h; |
---|
1148 | basePackHdl=h; |
---|
1149 | |
---|
1150 | coeffs_BIGINT = nInitChar(n_Q,NULL); |
---|
1151 | |
---|
1152 | #if 1 |
---|
1153 | // def HAVE_POLYEXTENSIONS |
---|
1154 | if(TRUE) |
---|
1155 | { |
---|
1156 | n_coeffType type = nRegister(n_algExt, naInitChar); |
---|
1157 | assume(type == n_algExt); |
---|
1158 | |
---|
1159 | type = nRegister(n_transExt, ntInitChar); |
---|
1160 | assume(type == n_transExt); |
---|
1161 | |
---|
1162 | (void)type; |
---|
1163 | } |
---|
1164 | #endif |
---|
1165 | |
---|
1166 | // random generator: ----------------------------------------------- |
---|
1167 | int t=initTimer(); |
---|
1168 | if (t==0) t=1; |
---|
1169 | initRTimer(); |
---|
1170 | siSeed=t; |
---|
1171 | #ifdef HAVE_FACTORY |
---|
1172 | factoryseed(t); |
---|
1173 | #endif |
---|
1174 | siRandomStart=t; |
---|
1175 | feOptSpec[FE_OPT_RANDOM].value = (void*) ((long)siRandomStart); |
---|
1176 | |
---|
1177 | // ressource table: ---------------------------------------------------- |
---|
1178 | // Don't worry: ifdef OM_NDEBUG, then all these calls are undef'ed |
---|
1179 | // hack such that all shared' libs in the bindir are loaded correctly |
---|
1180 | feInitResources(name); |
---|
1181 | |
---|
1182 | // singular links: -------------------------------------------------- |
---|
1183 | slStandardInit(); |
---|
1184 | myynest=0; |
---|
1185 | |
---|
1186 | // loading standard.lib ----------------------------------------------- |
---|
1187 | if (! feOptValue(FE_OPT_NO_STDLIB)) |
---|
1188 | { |
---|
1189 | BITSET save1,save2; |
---|
1190 | SI_SAVE_OPT(save1,save2); |
---|
1191 | si_opt_2 &= ~Sy_bit(V_LOAD_LIB); |
---|
1192 | iiLibCmd(omStrDup("standard.lib"), TRUE,TRUE,TRUE); |
---|
1193 | SI_RESTORE_OPT(save1,save2); |
---|
1194 | } |
---|
1195 | errorreported = 0; |
---|
1196 | } |
---|
1197 | |
---|
1198 | /* |
---|
1199 | #ifdef LIBSINGULAR |
---|
1200 | #ifdef HAVE_FACTORY |
---|
1201 | // the init routines of factory need mmInit |
---|
1202 | int mmInit( void ) |
---|
1203 | { |
---|
1204 | return 1; |
---|
1205 | } |
---|
1206 | #endif |
---|
1207 | #endif |
---|
1208 | */ |
---|