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> */
7 /* and a previous port (C) Zbigniew CHAMSKI, 1993. */
8 /* <Zbigniew.Chamski@philips.com> */
10 /* Copying subject to the terms and conditions of the */
11 /* GNU General Public License. */
13 /* Send questions, bug reports and fixes to: */
14 /* <Paul.Feautrier@inria.fr> */
15 /********************************************************/
20 #include <sys/types.h>
24 #define min(x,y) ((x) < (y)? (x) : (y))
26 #include <piplib/piplib.h>
28 #include <sys/times.h>
31 long int cross_product
, limit
;
32 int allocation
, comptage
;
35 float the_clock
= 0.0;
39 char dump_name
[] = "PipXXXXXX";
43 char inbuff
[INLENGTH
];
50 char version
[] = "Version MP.1\n";
56 {p
= fgets(inbuff
, INLENGTH
, foo
);
57 if(p
== NULL
) return EOF
;
58 proviso
= min(INLENGTH
, strlen(inbuff
));
60 if(verbose
> 0) fprintf(dump
, "-- %s", inbuff
);
62 return inbuff
[inptr
++];
65 int dscanf(FILE *foo
, char *format
, int *val
)
69 for(;inptr
< proviso
; inptr
++)
70 if(inbuff
[inptr
] != ' ' && inbuff
[inptr
] != '\n' && inbuff
[inptr
] != '\t')
72 while(inptr
>= proviso
)
73 {p
= fgets(inbuff
, 256, foo
);
74 if(p
== NULL
) return EOF
;
75 proviso
= strlen(inbuff
);
77 fprintf(dump
, ".. %s", inbuff
);
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;
92 void balance(FILE *foo
, FILE *bar
)
96 while((c
= dgetc(foo
)) != EOF
)
99 {case '(' : level
++; break;
100 case ')' : if(--level
== 0) return;
106 void escape(FILE *foo
, FILE *bar
, int level
)
108 while((c
= dgetc(foo
)) != EOF
)
110 {case '(' : level
++; break;
111 case ')' : if(--level
== 0)
112 { fprintf(bar
, "\nSyntax error\n)\n");
118 int main(int argc
, char *argv
[])
122 Tableau
*ineq
, *context
, *ctxt
;
123 int nvar
, nparm
, ni
, nc
, bigparm
;
126 struct high_water_mark hq
;
132 mpz_init_set_si(UN
, 1);
133 mpz_init_set_si(ZERO
, 0);
135 in
= stdin
; out
= stdout
;
138 if(strcmp(argv
[1], "-s") == 0)
142 else if(strcmp(argv
[1], "-v") == 0)
147 {dump
= fopen(g
, "w");
149 {fprintf(stdout
, "%s unaccessible\n", g
);
156 dump
= fopen(dump_name
, "w");
159 if(verbose
>= 0) fprintf(stdout
, version
);
161 if(strcmp(argv
[p
], "-z") == 0) {
166 {in
= fopen(argv
[p
], "r");
168 {fprintf(stdout
, "%s unaccessible\n", argv
[p
]);
174 {out
= fopen(argv
[p
], "w");
176 {fprintf(stdout
, "%s unaccessible\n", argv
[p
]);
182 if(argc
> p
) limit
= atol(argv
[p
]);
185 while((c
= dgetc(in
)) != EOF
)
186 {if(c
!= '(') continue;
189 if(dscanf(in
, "d", &x
) < 0){escape(in
, out
, 1); continue;}
191 if(dscanf(in
, "d", &x
) < 0){escape(in
, out
, 1); continue; }
193 if(dscanf(in
, "d", &x
) < 0){escape(in
, out
, 1); continue; }
195 if(dscanf(in
, "d", &x
) < 0){escape(in
, out
, 1); continue; }
197 if(dscanf(in
, "d", &x
) < 0){escape(in
, out
, 1); continue; }
199 if(dscanf(in
, "d", &x
) < 0){escape(in
, out
, 1); continue; }
201 if(verbose
> 0) {fprintf(dump
, "%d %d %d %d %d %d\n",nvar
, nparm
, ni
, nc
,
207 if(verbose
> 0) {fprintf(dump
, "hwm %x\n", g
);
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;}
215 /* verification de la non-vacuite' du contexte */
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
);
222 else non_vide
= True
;
225 traiter(ineq
, context
, nq
, nvar
, nparm
, ni
, nc
, bigparm
);
227 mpz_out_str(out
, 10, ineq
->determinant
);
229 if(simple
) sol_simplify(xq
);
231 while((xq
= sol_edit(out
, xq
)) != q
);
234 else fprintf(out
, "void\n");
236 if(verbose
> 0) fflush(dump
);
239 if(verbose
>= 0)fprintf(stdout
,"cross : %ld, alloc : %d, compa : %d\n\r",
240 cross_product
, allocation
, compa_count
);
245 fprintf(stdout
, "n %d u %d''' s %d'''\r\n",
246 comptage
, chrono
.tms_utime
, chrono
.tms_stime
);