isl_obj_list_print: properly return isl_printer
[barvinok.git] / collect_nonsimple.c
blob101330bac5633b85732c11711adb33739e0ce874
1 #include <assert.h>
2 #include <dlfcn.h>
3 #include <limits.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <unistd.h>
9 #include <barvinok/evalue.h>
10 #include <barvinok/barvinok.h>
12 /* gcc -shared -g collect_nonsimple.c -rdynamic -o libcollect.so -ldl -lc -lgmp */
14 Polyhedron* triangularize_cone(Polyhedron *P, unsigned MaxRays)
16 static Polyhedron *(*orig)(Polyhedron *, unsigned) = NULL;
17 static char *prefix = NULL;
18 Polyhedron *res;
19 static int recurse = 0;
20 static int counter = 0;
22 if (!orig) {
23 void *handle = dlopen("libbarvinok.so", RTLD_LAZY);
24 assert(handle);
25 orig = dlsym(handle, "triangularize_cone");
26 assert(orig);
27 dlclose(handle);
29 prefix = getenv("POLYTOPE_PREFIX");
30 if (prefix)
31 prefix = strdup(prefix);
34 if (prefix && !recurse) {
35 char path[PATH_MAX];
36 FILE *f;
37 int i, j;
38 unsigned nr, nc;
40 snprintf(path, PATH_MAX, "%s-%05d-%05d", prefix, getpid(), counter++);
41 f = fopen(path, "w");
42 fprintf(f, "%d %d\n", nr=P->NbRays, nc=P->Dimension+2);
43 for (i=0; i < nr; i++) {
44 for (j=0; j < nc; j++) {
45 value_print(f," "P_VALUE_FMT" ", P->Ray[i][j]);
47 fprintf(f, "\n");
49 fclose(f);
52 recurse = 1;
53 res = orig(P, MaxRays);
54 recurse = 0;
56 return res;