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