1 /******************************************************************************
2 * PIP : Parametric Integer Programming *
3 ******************************************************************************
5 * Copyright Paul Feautrier, 1988, 1993, 1994, 1996 *
7 * This is free software; you can redistribute it and/or modify it under the *
8 * terms of the GNU General Public License as published by the Free Software *
9 * Foundation; either version 2 of the License, or (at your option) any later *
12 * This software is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * You should have received a copy of the GNU General Public License along *
18 * with software; if not, write to the Free Software Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 * Written by Paul Feautrier *
23 ******************************************************************************/
28 #include <sys/types.h>
33 #define min(x,y) ((x) < (y)? (x) : (y))
35 #include <piplib/piplib.h>
38 #include <sys/times.h>
42 char version
[]="Version E.2\n";
44 long int cross_product
, limit
;
45 int allocation
, comptage
;
51 char dump_name
[] = "XXXXXX";
55 char inbuff
[INLENGTH
];
64 {p
= fgets(inbuff
, INLENGTH
, foo
);
65 if(p
== NULL
) return EOF
;
66 proviso
= min(INLENGTH
, strlen(inbuff
));
68 if(verbose
> 0) fprintf(dump
, "-- %s", inbuff
);
70 return inbuff
[inptr
++];
73 int dscanf(FILE *foo
, char *format
, Entier
*val
)
77 for(;inptr
< proviso
; inptr
++)
78 if(inbuff
[inptr
] != ' ' && inbuff
[inptr
] != '\n' && inbuff
[inptr
] != '\t')
80 while(inptr
>= proviso
)
81 {p
= fgets(inbuff
, 256, foo
);
82 if(p
== NULL
) return EOF
;
83 proviso
= strlen(inbuff
);
85 fprintf(dump
, ".. %s", inbuff
);
88 for(inptr
= 0; inptr
< proviso
; inptr
++)
89 if(inbuff
[inptr
] != ' '
90 && inbuff
[inptr
] != '\n'
91 && inbuff
[inptr
] != '\t') break;
93 if(sscanf(inbuff
+inptr
, FORMAT
, val
) != 1) return -1;
95 for(; inptr
< proviso
; inptr
++)
96 if((c
= inbuff
[inptr
]) != '-' && !isdigit(c
)) break;
100 void balance(FILE *foo
, FILE *bar
)
104 while((c
= dgetc(foo
)) != EOF
)
107 {case '(' : level
++; break;
108 case ')' : if(--level
== 0) return;
114 void escape(FILE *foo
, FILE *bar
, int level
)
116 while((c
= dgetc(foo
)) != EOF
)
118 {case '(' : level
++; break;
119 case ')' : if(--level
== 0)
120 { fprintf(bar
, "\nSyntax error\n)\n");
128 int main(int argc
, char *argv
[])
132 Tableau
*ineq
, *context
, *ctxt
;
133 int nvar
, nparm
, ni
, nc
, bigparm
;
136 struct high_water_mark hq
;
143 in
= stdin
; out
= stdout
;
146 if(strcmp(argv
[1], "-s") == 0)
150 else if(strcmp(argv
[1], "-v") == 0)
155 {dump
= fopen(g
, "w");
157 {fprintf(stderr
, "%s unaccessible\n", g
);
164 dump
= fopen(dump_name
, "w");
167 if(verbose
>= 0) fprintf(stderr
, version
);
169 if(strcmp(argv
[p
], "-z") == 0) {
174 {in
= fopen(argv
[p
], "r");
176 {fprintf(stderr
, "%s unaccessible\n", argv
[p
]);
182 {out
= fopen(argv
[p
], "w");
184 {fprintf(stderr
, "%s unaccessible\n", argv
[p
]);
190 if(argc
> p
) limit
= atol(argv
[p
]);
193 while((c
= dgetc(in
)) != EOF
)
194 {if(c
!= '(') continue;
197 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue;}
199 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
200 else nparm
= (int) x
;
201 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
203 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
205 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
206 else bigparm
= (int) x
;
207 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
209 if(verbose
> 0) {fprintf(dump
, "%d %d %d %d %d %d\n",nvar
, nparm
, ni
, nc
,
215 if(verbose
> 0) {fprintf(dump
, "hwm %x\n", g
);
218 ineq
= tab_get(in
, ni
, nvar
+nparm
+1, nvar
);
219 if(ineq
== NULL
){escape(in
, out
, 2); continue;}
220 context
= tab_get(in
, nc
, nparm
+1, 0);
221 if(ineq
== NULL
){escape(in
, out
, 2); continue;}
223 /* verification de la non-vacuite' du contexte */
225 {ctxt
= expanser(context
, nparm
, nc
, nparm
+1, nparm
, 0, 0);
226 traiter(ctxt
, NULL
, True
, UN
, nparm
, 0, nc
, 0, -1);
227 non_vide
= is_not_Nil(p
);
230 else non_vide
= True
;
233 D
= traiter(ineq
, context
, nq
, UN
, nvar
, nparm
, ni
, nc
, bigparm
);
235 fprintf(out
, FORMAT
, D
);
237 if(simple
) sol_simplify(xq
);
239 while((xq
= sol_edit(out
, xq
)) != q
);
242 else fprintf(out
, "void\n");
244 if(verbose
> 0) fflush(dump
);
247 if(verbose
>= 0) fprintf(stderr
,"cross : %ld, alloc : %d, compa : %d\n\r",
248 cross_product
, allocation
, compa_count
);
253 fprintf(stderr
, "n %d u %d''' s %d'''\r\n",
254 comptage
, chrono
.tms_utime
, chrono
.tms_stime
);