1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* |
---|
5 | * ABSTRACT: |
---|
6 | */ |
---|
7 | |
---|
8 | #include <string.h> |
---|
9 | #include <unistd.h> |
---|
10 | #include <stdio.h> |
---|
11 | #include <stddef.h> |
---|
12 | #include <stdlib.h> |
---|
13 | #include <time.h> |
---|
14 | |
---|
15 | #include "mod2.h" |
---|
16 | #include <mylimits.h> |
---|
17 | #include "omalloc.h" |
---|
18 | #include "structs.h" |
---|
19 | #include "febase.h" |
---|
20 | //#include "cntrlc.h" |
---|
21 | #include "kstd1.h" |
---|
22 | #include "timer.h" |
---|
23 | #include "intvec.h" |
---|
24 | #include "ring.h" |
---|
25 | #include "omSingularConfig.h" |
---|
26 | #include "p_Procs.h" |
---|
27 | #include "kversion.h" |
---|
28 | |
---|
29 | #define SI_DONT_HAVE_GLOBAL_VARS |
---|
30 | |
---|
31 | //#ifdef HAVE_LIBPARSER |
---|
32 | //# include "libparse.h" |
---|
33 | //#endif /* HAVE_LIBPARSER */ |
---|
34 | |
---|
35 | #ifdef HAVE_FACTORY |
---|
36 | #include <factory.h> |
---|
37 | /* libfac version strings */ |
---|
38 | extern const char * libfac_version; |
---|
39 | extern const char * libfac_date; |
---|
40 | #endif |
---|
41 | |
---|
42 | #include <si_gmp.h> |
---|
43 | #ifdef HAVE_MPSR |
---|
44 | #include <MP_Config.h> |
---|
45 | #endif |
---|
46 | |
---|
47 | /* init bins from structs.h */ |
---|
48 | |
---|
49 | omBin char_ptr_bin = omGetSpecBin(sizeof(char_ptr)); |
---|
50 | omBin ideal_bin = omGetSpecBin(sizeof(ideal)); |
---|
51 | omBin poly_bin = omGetSpecBin(sizeof(poly)); |
---|
52 | omBin indlist_bin = omGetSpecBin(sizeof(indlist)); |
---|
53 | omBin naIdeal_bin = omGetSpecBin(sizeof(naIdeal)); |
---|
54 | omBin snaIdeal_bin = omGetSpecBin(sizeof(snaIdeal)); |
---|
55 | omBin smprec_bin = omGetSpecBin(sizeof(smprec)); |
---|
56 | omBin sip_sideal_bin = omGetSpecBin(sizeof(sip_sideal)); |
---|
57 | omBin sip_smap_bin = omGetSpecBin(sizeof(sip_smap)); |
---|
58 | omBin sip_sring_bin = omGetSpecBin(sizeof(sip_sring)); |
---|
59 | omBin ip_sideal_bin = omGetSpecBin(sizeof(ip_sideal)); |
---|
60 | omBin ip_sring_bin = omGetSpecBin(sizeof(ip_sring)); |
---|
61 | |
---|
62 | /*0 implementation*/ |
---|
63 | |
---|
64 | /*2 |
---|
65 | * the global exit routine of Singular |
---|
66 | */ |
---|
67 | #ifdef HAVE_MPSR |
---|
68 | void (*MP_Exit_Env_Ptr)()=NULL; |
---|
69 | #endif |
---|
70 | extern "C" { |
---|
71 | |
---|
72 | void m2_end(int i) |
---|
73 | { |
---|
74 | fe_reset_input_mode(); |
---|
75 | #ifdef PAGE_TEST |
---|
76 | mmEndStat(); |
---|
77 | #endif |
---|
78 | #ifdef HAVE_TCL |
---|
79 | if (tclmode) |
---|
80 | { |
---|
81 | PrintTCL('Q',0,NULL); |
---|
82 | } |
---|
83 | #endif |
---|
84 | fe_reset_input_mode(); |
---|
85 | if (i<=0) |
---|
86 | { |
---|
87 | #ifdef HAVE_TCL |
---|
88 | if (!tclmode) |
---|
89 | #endif |
---|
90 | if (BVERBOSE(0)) |
---|
91 | { |
---|
92 | if (i==0) |
---|
93 | printf("Auf Wiedersehen.\n"); |
---|
94 | else |
---|
95 | printf("\n$Bye.\n"); |
---|
96 | } |
---|
97 | //#ifdef sun |
---|
98 | // #ifndef __svr4__ |
---|
99 | // _cleanup(); |
---|
100 | // _exit(0); |
---|
101 | // #endif |
---|
102 | //#endif |
---|
103 | exit(0); |
---|
104 | } |
---|
105 | else |
---|
106 | { |
---|
107 | #ifdef HAVE_TCL |
---|
108 | if (!tclmode) |
---|
109 | #endif |
---|
110 | printf("\nhalt %d\n",i); |
---|
111 | } |
---|
112 | #ifdef HAVE_MPSR |
---|
113 | if (MP_Exit_Env_Ptr!=NULL) (*MP_Exit_Env_Ptr)(); |
---|
114 | #endif |
---|
115 | exit(i); |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | /*2 |
---|
120 | * the renice routine for very large jobs |
---|
121 | * works only on unix machines, |
---|
122 | * testet on : linux, HP 9.0 |
---|
123 | * |
---|
124 | *#include <sys/times.h> |
---|
125 | *#include <sys/resource.h> |
---|
126 | *extern "C" int setpriority(int,int,int); |
---|
127 | *void very_nice() |
---|
128 | *{ |
---|
129 | *#ifndef NO_SETPRIORITY |
---|
130 | * setpriority(PRIO_PROCESS,0,19); |
---|
131 | *#endif |
---|
132 | * sleep(10); |
---|
133 | *} |
---|
134 | */ |
---|
135 | |
---|
136 | /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ |
---|
137 | #ifdef buildin_rand |
---|
138 | /* |
---|
139 | * |
---|
140 | * A prime modulus multiplicative linear congruential |
---|
141 | * generator (PMMLCG), or "Lehmer generator". |
---|
142 | * Implementation directly derived from the article: |
---|
143 | * |
---|
144 | * S. K. Park and K. W. Miller |
---|
145 | * Random Number Generators: Good Ones are Hard to Find |
---|
146 | * CACM vol 31, #10. Oct. 1988. pp 1192-1201. |
---|
147 | * |
---|
148 | * Using the following multiplier and modulus, we obtain a |
---|
149 | * generator which: |
---|
150 | * |
---|
151 | * 1) Has a full period: 1 to 2^31 - 2. |
---|
152 | * 2) Is testably "random" (see the article). |
---|
153 | * 3) Has a known implementation by E. L. Schrage. |
---|
154 | */ |
---|
155 | |
---|
156 | |
---|
157 | #define A 16807 /* A "good" multiplier */ |
---|
158 | #define M 2147483647 /* Modulus: 2^31 - 1 */ |
---|
159 | #define Q 127773 /* M / A */ |
---|
160 | #define R 2836 /* M % A */ |
---|
161 | |
---|
162 | |
---|
163 | int siSeed = 1; |
---|
164 | |
---|
165 | |
---|
166 | int siRand() |
---|
167 | { |
---|
168 | siSeed = A * (siSeed % Q) - R * (siSeed / Q); |
---|
169 | |
---|
170 | if ( siSeed < 0 ) |
---|
171 | siSeed += M; |
---|
172 | |
---|
173 | return( siSeed ); |
---|
174 | } |
---|
175 | #endif |
---|
176 | |
---|