piplib 1.1
[piplib.git] / source / maindMP.c
blob03304f8024d4125065870ea5a2d6cc4092b56449
1 /********************************************************/
2 /* Part of MultiPrecision PIP port by Zbigniew Chamski */
3 /* and Paul Feautrier. */
4 /* Based on straight PIP E.1 version by Paul Feautrier */
5 /* <Paul.Feautrier@inria.fr> */
6 /* */
7 /* and a previous port (C) Zbigniew CHAMSKI, 1993. */
8 /* <Zbigniew.Chamski@philips.com> */
9 /* */
10 /* Copying subject to the terms and conditions of the */
11 /* GNU General Public License. */
12 /* */
13 /* Send questions, bug reports and fixes to: */
14 /* <Paul.Feautrier@inria.fr> */
15 /********************************************************/
17 #include <stdio.h>
18 #include <ctype.h>
19 #include <string.h>
20 #include <sys/types.h>
21 #include <stdlib.h>
24 #define min(x,y) ((x) < (y)? (x) : (y))
26 #include <piplib/piplib.h>
28 #include <sys/times.h>
29 struct tms chrono;
31 long int cross_product, limit;
32 int allocation, comptage;
33 int verbose = 0;
34 int profondeur = 0;
35 float the_clock = 0.0;
36 int compa_count;
38 FILE *dump = NULL;
39 char dump_name[] = "PipXXXXXX";
41 #define INLENGTH 1024
43 char inbuff[INLENGTH];
44 int inptr = 256;
45 int proviso = 0;
47 Entier UN;
48 Entier ZERO;
50 char version[] = "Version MP.1\n";
52 int dgetc(FILE *foo)
54 char *p;
55 if(inptr >= proviso)
56 {p = fgets(inbuff, INLENGTH, foo);
57 if(p == NULL) return EOF;
58 proviso = min(INLENGTH, strlen(inbuff));
59 inptr = 0;
60 if(verbose > 0) fprintf(dump, "-- %s", inbuff);
62 return inbuff[inptr++];
65 int dscanf(FILE *foo, char *format, int *val)
67 char * p;
68 int c;
69 for(;inptr < proviso; inptr++)
70 if(inbuff[inptr] != ' ' && inbuff[inptr] != '\n' && inbuff[inptr] != '\t')
71 break;
72 while(inptr >= proviso)
73 {p = fgets(inbuff, 256, foo);
74 if(p == NULL) return EOF;
75 proviso = strlen(inbuff);
76 if(verbose > 0) {
77 fprintf(dump, ".. %s", inbuff);
78 fflush(dump);
80 for(inptr = 0; inptr < proviso; inptr++)
81 if(inbuff[inptr] != ' '
82 && inbuff[inptr] != '\n'
83 && inbuff[inptr] != '\t') break;
85 if(sscanf(inbuff+inptr, FORMAT, val) != 1) return -1;
87 for(; inptr < proviso; inptr++)
88 if((c = inbuff[inptr]) != '-' && !isdigit(c)) break;
89 return 0;
92 void balance(FILE *foo, FILE *bar)
94 int level = 0;
95 int c;
96 while((c = dgetc(foo)) != EOF)
98 switch(c)
99 {case '(' : level++; break;
100 case ')' : if(--level == 0) return;
102 putc(c, bar);
106 void escape(FILE *foo, FILE *bar, int level)
107 {int c;
108 while((c = dgetc(foo)) != EOF)
109 switch(c)
110 {case '(' : level ++; break;
111 case ')' : if(--level == 0)
112 { fprintf(bar, "\nSyntax error\n)\n");
113 return;
118 int main(int argc, char *argv[])
121 FILE *in, *out;
122 Tableau *ineq, *context, *ctxt;
123 int nvar, nparm, ni, nc, bigparm;
124 int nq; char * g;
125 int simple = 0;
126 struct high_water_mark hq;
127 int c, non_vide;
128 int p, q, xq;
129 long temps;
130 char *date;
131 int x;
132 mpz_init_set_si(UN, 1);
133 mpz_init_set_si(ZERO, 0);
135 in = stdin; out = stdout;
136 p = 1;
137 if(argc > 1)
138 if(strcmp(argv[1], "-s") == 0)
139 {verbose = -1;
140 p = 2;
142 else if(strcmp(argv[1], "-v") == 0)
143 {verbose = 1;
144 p = 2;
145 g = getenv("DEBUG");
146 if(g && *g)
147 {dump = fopen(g, "w");
148 if(dump == NULL)
149 {fprintf(stdout, "%s unaccessible\n", g);
150 verbose = 0;
153 else
155 mkstemp(dump_name);
156 dump = fopen(dump_name, "w");
159 if(verbose >= 0) fprintf(stdout, version);
160 if(argc > p)
161 if(strcmp(argv[p], "-z") == 0) {
162 simple = 1;
163 p++;
165 if(argc>p)
166 {in = fopen(argv[p], "r");
167 if(in == NULL)
168 {fprintf(stdout, "%s unaccessible\n", argv[p]);
169 exit(1);
172 p++;
173 if(argc>p)
174 {out = fopen(argv[p], "w");
175 if(out == NULL)
176 {fprintf(stdout, "%s unaccessible\n", argv[p]);
177 exit(2);
180 limit = 0L;
181 p++;
182 if(argc > p) limit = atol(argv[p]);
183 sol_init();
184 tab_init();
185 while((c = dgetc(in)) != EOF)
186 {if(c != '(') continue;
187 fprintf(out, "(");
188 balance(in, out);
189 if(dscanf(in, "d", &x) < 0){escape(in, out, 1); continue;}
190 else nvar = x;
191 if(dscanf(in, "d", &x) < 0){escape(in, out, 1); continue; }
192 else nparm = x;
193 if(dscanf(in, "d", &x) < 0){escape(in, out, 1); continue; }
194 else ni = x;
195 if(dscanf(in, "d", &x) < 0){escape(in, out, 1); continue; }
196 else nc = x;
197 if(dscanf(in, "d", &x) < 0){escape(in, out, 1); continue; }
198 else bigparm = x;
199 if(dscanf(in, "d", &x) < 0){escape(in, out, 1); continue; }
200 else nq = x;
201 if(verbose > 0) {fprintf(dump, "%d %d %d %d %d %d\n",nvar, nparm, ni, nc,
202 bigparm, nq);
203 fflush(dump);
205 cross_product = 0;
206 hq = tab_hwm();
207 if(verbose > 0) {fprintf(dump, "hwm %x\n", g);
208 fflush(dump);
210 ineq = tab_get(in, ni, nvar+nparm+1, nvar);
211 if(ineq == NULL){escape(in, out, 2); continue;}
212 context = tab_get(in, nc, nparm+1, 0);
213 if(ineq == NULL){escape(in, out, 2); continue;}
214 xq = p = sol_hwm();
215 /* verification de la non-vacuite' du contexte */
216 if(nc)
217 {ctxt = expanser(context, nparm, nc, nparm+1, nparm, 0, 0);
218 traiter(ctxt, NULL, True, nparm, 0, nc, 0, -1);
219 non_vide = is_not_Nil(p);
220 sol_reset(p);
222 else non_vide = True;
223 if(non_vide) {
224 compa_count = 0;
225 traiter(ineq, context, nq, nvar, nparm, ni, nc, bigparm);
226 putc(' ',out);
227 mpz_out_str(out, 10, ineq->determinant);
228 fputs(" )",out);
229 if(simple) sol_simplify(xq);
230 q = sol_hwm();
231 while((xq = sol_edit(out, xq)) != q);
232 sol_reset(p);
234 else fprintf(out, "void\n");
235 tab_reset(hq);
236 if(verbose > 0) fflush(dump);
237 fprintf(out, ")\n");
238 fflush(out);
239 if(verbose >= 0)fprintf(stdout,"cross : %ld, alloc : %d, compa : %d\n\r",
240 cross_product, allocation, compa_count);
241 comptage++;
243 if(verbose >= 0){
244 times(& chrono);
245 fprintf(stdout, "n %d u %d''' s %d'''\r\n",
246 comptage, chrono.tms_utime, chrono.tms_stime);
248 exit(0);