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