1 /******************************************************************************
2 * PIP : Parametric Integer Programming *
3 ******************************************************************************
5 ******************************************************************************
7 * Copyright Paul Feautrier, 1988, 1993, 1994, 1996, 2002 *
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 *
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 *
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 *
23 * Written by Paul Feautrier *
25 ******************************************************************************/
30 #include <sys/types.h>
35 #define min(x,y) ((x) < (y)? (x) : (y))
37 #include <piplib/piplib.h>
40 #include <sys/times.h>
44 char version
[]="Version E.2 $Revision: 1.3 $\n";
46 long int cross_product
, limit
;
47 int allocation
, comptage
;
53 char dump_name
[] = "PipXXXXXX";
57 char inbuff
[INLENGTH
];
66 {p
= fgets(inbuff
, INLENGTH
, foo
);
67 if(p
== NULL
) return EOF
;
68 proviso
= min(INLENGTH
, strlen(inbuff
));
70 if(verbose
> 0) fprintf(dump
, "-- %s", inbuff
);
72 return inbuff
[inptr
++];
75 int dscanf(FILE *foo
, char *format
, Entier
*val
)
79 for(;inptr
< proviso
; inptr
++)
80 if(inbuff
[inptr
] != ' ' && inbuff
[inptr
] != '\n' && inbuff
[inptr
] != '\t')
82 while(inptr
>= proviso
)
83 {p
= fgets(inbuff
, 256, foo
);
84 if(p
== NULL
) return EOF
;
85 proviso
= strlen(inbuff
);
87 fprintf(dump
, ".. %s", inbuff
);
90 for(inptr
= 0; inptr
< proviso
; inptr
++)
91 if(inbuff
[inptr
] != ' '
92 && inbuff
[inptr
] != '\n'
93 && inbuff
[inptr
] != '\t') break;
95 if(sscanf(inbuff
+inptr
, FORMAT
, val
) != 1) return -1;
97 for(; inptr
< proviso
; inptr
++)
98 if((c
= inbuff
[inptr
]) != '-' && !isdigit(c
)) break;
102 void balance(FILE *foo
, FILE *bar
)
106 while((c
= dgetc(foo
)) != EOF
)
109 {case '(' : level
++; break;
110 case ')' : if(--level
== 0) return;
116 void escape(FILE *foo
, FILE *bar
, int level
)
118 while((c
= dgetc(foo
)) != EOF
)
120 {case '(' : level
++; break;
121 case ')' : if(--level
== 0)
122 { fprintf(bar
, "\nSyntax error\n)\n");
130 int main(int argc
, char *argv
[])
134 Tableau
*ineq
, *context
, *ctxt
;
135 int nvar
, nparm
, ni
, nc
, bigparm
;
138 struct high_water_mark hq
;
145 in
= stdin
; out
= stdout
;
148 if(strcmp(argv
[1], "-s") == 0)
152 else if(strcmp(argv
[1], "-v") == 0)
157 {dump
= fopen(g
, "w");
159 {fprintf(stderr
, "%s unaccessible\n", g
);
166 dump
= fopen(dump_name
, "w");
169 if(verbose
>= 0) fprintf(stderr
, version
);
171 if(strcmp(argv
[p
], "-z") == 0) {
176 {in
= fopen(argv
[p
], "r");
178 {fprintf(stderr
, "%s unaccessible\n", argv
[p
]);
184 {out
= fopen(argv
[p
], "w");
186 {fprintf(stderr
, "%s unaccessible\n", argv
[p
]);
192 if(argc
> p
) limit
= atol(argv
[p
]);
195 while((c
= dgetc(in
)) != EOF
)
196 {if(c
!= '(') continue;
199 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue;}
201 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
202 else nparm
= (int) x
;
203 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
205 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
207 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
208 else bigparm
= (int) x
;
209 if(dscanf(in
, FORMAT
, &x
) < 0){escape(in
, out
, 1); continue; }
211 if(verbose
> 0) {fprintf(dump
, "%d %d %d %d %d %d\n",nvar
, nparm
, ni
, nc
,
217 if(verbose
> 0) {fprintf(dump
, "hwm %x\n", g
);
220 ineq
= tab_get(in
, ni
, nvar
+nparm
+1, nvar
);
221 if(ineq
== NULL
){escape(in
, out
, 2); continue;}
222 context
= tab_get(in
, nc
, nparm
+1, 0);
223 if(ineq
== NULL
){escape(in
, out
, 2); continue;}
225 /* verification de la non-vacuite' du contexte */
227 {ctxt
= expanser(context
, nparm
, nc
, nparm
+1, nparm
, 0, 0);
228 traiter(ctxt
, NULL
, True
, UN
, nparm
, 0, nc
, 0, -1);
229 non_vide
= is_not_Nil(p
);
232 else non_vide
= True
;
235 D
= traiter(ineq
, context
, nq
, UN
, nvar
, nparm
, ni
, nc
, bigparm
);
237 fprintf(out
, FORMAT
, D
);
239 if(simple
) sol_simplify(xq
);
241 while((xq
= sol_edit(out
, xq
)) != q
);
244 else fprintf(out
, "void\n");
246 if(verbose
> 0) fflush(dump
);
249 if(verbose
>= 0) fprintf(stderr
,"cross : %ld, alloc : %d, compa : %d\n\r",
250 cross_product
, allocation
, compa_count
);
255 fprintf(stderr
, "n %d u %d''' s %d'''\r\n",
256 comptage
, chrono
.tms_utime
, chrono
.tms_stime
);