Build example program in each object directory.
[piplib.git] / source / maind.c
blob592d6492151e766b0efea248ef7b853c2fbae6a9
1 /******************************************************************************
2 * PIP : Parametric Integer Programming *
3 ******************************************************************************
4 * maind.h *
5 ******************************************************************************
6 * *
7 * Copyright Paul Feautrier, 1988-2005 *
8 * *
9 * This is free software; you can redistribute it and/or modify it under the *
10 * terms of the GNU General Public License as published by the Free Software *
11 * Foundation; either version 2 of the License, or (at your option) any later *
12 * version. *
13 * *
14 * This software is distributed in the hope that it will be useful, but *
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License along *
20 * with software; if not, write to the Free Software Foundation, Inc., *
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
22 * *
23 * Written by Paul Feautrier *
24 * *
25 ******************************************************************************/
27 #include <stdio.h>
28 #include <ctype.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include <stdlib.h>
32 #ifdef __TURBOC__
33 #include <dir.h>
34 #endif
35 #define min(x,y) ((x) < (y)? (x) : (y))
37 #include "pip.h"
39 #ifdef UNIX
40 #include <sys/times.h>
41 struct tms chrono;
42 #endif
44 char version[]="Version E.2 $Revision: 1.3 $\n";
47 extern long int cross_product, limit ;
48 extern int allocation, comptage, verbose ;
49 extern FILE * dump ;
50 extern int compa_count ;
51 extern char dump_name[] ;
52 extern int deepest_cut;
54 void balance(FILE *foo, FILE *bar)
56 int level = 0;
57 int c;
58 while((c = dgetc(foo)) != EOF)
60 switch(c)
61 {case '(' : level++; break;
62 case ')' : if(--level == 0) return;
64 putc(c, bar);
68 void escape(FILE *foo, FILE *bar, int level)
69 {int c;
70 while((c = dgetc(foo)) != EOF)
71 switch(c)
72 {case '(' : level ++; break;
73 case ')' : if(--level == 0)
74 { fprintf(bar, "\nSyntax error\n)\n");
75 return;
80 char * getenv();
82 int main(int argc, char *argv[])
84 FILE *in, *out;
85 Tableau *ineq, *context, *ctxt;
86 int nvar, nparm, ni, nc, bigparm;
87 int nq; char * g;
88 int simple = 0;
89 struct high_water_mark hq;
90 int c, non_vide;
91 int p, q, xq;
92 long temps;
93 char *date;
94 Entier x ;
95 #if defined(LINEAR_VALUE_IS_MP)
96 mpz_init(x);
97 #else
98 Entier i;
99 #endif
101 #if defined(LINEAR_VALUE_IS_MP)
102 mpz_init_set_si(UN, 1);
103 mpz_init_set_si(ZERO, 0);
104 #else
105 UN = VAL_UN ;
106 ZERO = VAL_ZERO ;
107 #endif
109 in = stdin; out = stdout;
110 p = 1;
111 if(argc > 1)
112 { if(strcmp(argv[1], "-s") == 0)
113 { verbose = -1;
114 p = 2;
116 /* the number of 'v' in the verbose option control the amount of debug
117 * information generated by Pip.
119 else
120 if(strncmp(argv[1], "-v", 2) == 0)
121 { verbose = 1;
122 g = argv[1]+2;
123 while(*g++ == 'v') verbose++;
125 p = 2;
126 g = getenv("DEBUG");
127 if(g && *g)
128 { dump = fopen(g, "w");
129 if(dump == NULL)
130 { fprintf(stderr, "%s unaccessible\n", g);
131 verbose = 0;
134 else
135 { mkstemp(dump_name);
136 dump = fopen(dump_name, "w");
139 if(argc>p && strcmp(argv[p], "-d") == 0)
140 { deepest_cut = 1;
141 p++;
145 if(verbose >= 0) fprintf(stderr, version);
146 if(argc > p)
147 { if(strcmp(argv[p], "-z") == 0)
148 { simple = 1;
149 p++;
152 in = fopen(argv[p], "r");
153 if(in == NULL)
154 { fprintf(stderr, "%s unaccessible\n", argv[p]);
155 exit(1);
158 p++;
159 if(argc>p)
160 { out = fopen(argv[p], "w");
161 if(out == NULL)
162 { fprintf(stderr, "%s unaccessible\n", argv[p]);
163 exit(2);
167 limit = 0L;
168 p++;
169 if(argc > p) limit = atol(argv[p]);
170 sol_init();
171 tab_init();
172 while((c = dgetc(in)) != EOF)
173 {if(c != '(') continue;
174 fprintf(out, "(");
175 balance(in, out);
176 #if defined(LINEAR_VALUE_IS_MP)
177 if(dscanf(in, x) < 0){escape(in, out, 1); continue;}
178 else
179 nvar = mpz_get_si(x);
180 if(dscanf(in, x) < 0){escape(in, out, 1); continue;}
181 else
182 nparm = mpz_get_si(x);
183 if(dscanf(in, x) < 0){escape(in, out, 1); continue;}
184 else
185 ni = mpz_get_si(x);
186 if(dscanf(in, x) < 0){escape(in, out, 1); continue;}
187 else
188 nc = mpz_get_si(x);
189 if(dscanf(in, x) < 0){escape(in, out, 1); continue;}
190 else
191 bigparm = mpz_get_si(x);
192 if(dscanf(in, x) < 0){escape(in, out, 1); continue;}
193 else
194 nq = mpz_get_si(x);
195 #else
196 if(dscanf(in, &x) < 0){escape(in, out, 1); continue;}
197 else
198 nvar = (int) x;
199 if(dscanf(in, &x) < 0){escape(in, out, 1); continue;}
200 else
201 nparm = (int) x;
202 if(dscanf(in, &x) < 0){escape(in, out, 1); continue;}
203 else
204 ni = (int) x;
205 if(dscanf(in, &x) < 0){escape(in, out, 1); continue;}
206 else
207 nc = (int) x;
208 if(dscanf(in, &x) < 0){escape(in, out, 1); continue;}
209 else
210 bigparm = (int) x;
211 if(dscanf(in, &x) < 0){escape(in, out, 1); continue;}
212 else
213 nq = (int) x;
214 #endif
216 if(verbose > 0) {fprintf(dump, "%d %d %d %d %d %d\n",nvar, nparm, ni, nc,
217 bigparm, nq);
218 fflush(dump);
220 cross_product = 0;
221 hq = tab_hwm();
222 if(verbose > 0) {fprintf(dump, "hwm %x\n", g);
223 fflush(dump);
225 ineq = tab_get(in, ni, nvar+nparm+1, nvar);
226 if(ineq == NULL){escape(in, out, 2); continue;}
227 context = tab_get(in, nc, nparm+1, 0);
228 if(context == NULL){escape(in, out, 2); continue;}
229 xq = p = sol_hwm();
230 /* verification de la non-vacuite' du contexte */
231 if(nc)
232 {ctxt = expanser(context, nparm, nc, nparm+1, nparm, 0, 0);
233 traiter(ctxt, NULL, Pip_True, nparm, 0, nc, 0, -1);
234 non_vide = is_not_Nil(p);
235 sol_reset(p);
237 else non_vide = Pip_True;
238 if(non_vide) {
239 compa_count = 0;
240 traiter(ineq, context, nq, nvar, nparm, ni, nc, bigparm);
241 putc(' ',out);
242 #if defined(LINEAR_VALUE_IS_MP)
243 mpz_out_str(out, 10, ineq->determinant);
244 #else
245 for(i=0; i<ineq->l_determinant; i++) {
246 fprintf(out, FORMAT, ineq->determinant[i]);
247 fprintf(out, " ");
249 #endif
250 fputs(" )",out);
251 if(simple) sol_simplify(xq);
252 q = sol_hwm();
253 while((xq = sol_edit(out, xq)) != q);
254 sol_reset(p);
256 else fprintf(out, "void\n");
257 tab_reset(hq);
258 if(verbose > 0) fflush(dump);
259 /* add a right parenthesis in order to keep the output in balance */
260 fprintf(out, ")\n");
261 fflush(out);
262 if(verbose >= 0)
263 fprintf(stderr,"cross : %ld, alloc : %d, compa : %d\n\r",
264 cross_product, allocation, compa_count);
265 comptage++;
267 #ifdef UNIX
268 times(& chrono);
269 fprintf(stderr, "n %d u %d''' s %d'''\r\n",
270 comptage, chrono.tms_utime, chrono.tms_stime);
271 #endif
273 #if defined(LINEAR_VALUE_IS_MP)
274 mpz_clear(x);
275 #endif
276 pip_close();
277 exit(0);