add sanity checks

This commit is contained in:
tTh 2023-05-01 11:11:20 +02:00
parent f5de09b23a
commit 755eb65da3

View File

@ -79,7 +79,7 @@ return 0;
/* EXPERIMENTAL GRUIK-CODE !!! */ /* EXPERIMENTAL GRUIK-CODE !!! */
int printf_the_edges(EdgesAndVertices *eav) int printf_the_edges(EdgesAndVertices *eav)
{ {
int idx, a, b; int idx, a, b, vmax;
#if DEBUG_LEVEL #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p )\n", __func__, eav); fprintf(stderr, ">>> %s ( %p )\n", __func__, eav);
@ -87,6 +87,9 @@ fprintf(stderr, ">>> %s ( %p )\n", __func__, eav);
if (verbosity) fprintf(stderr, " fprinting %d edges\n", eav->Elist->fidx); if (verbosity) fprintf(stderr, " fprinting %d edges\n", eav->Elist->fidx);
vmax = eav->Blist->fidx;
fprintf(stderr, " in %s, vmax was %d\n", __func__, vmax);
/* /*
* OK we have (maybe) all the data in da place * OK we have (maybe) all the data in da place
* and we can spit all the edges to stdout * and we can spit all the edges to stdout
@ -95,7 +98,12 @@ for (idx=0; idx<eav->Elist->fidx; idx++) {
a = eav->Elist->edges[idx].A; a = eav->Elist->edges[idx].A;
b = eav->Elist->edges[idx].B; b = eav->Elist->edges[idx].B;
// fprintf(stderr, "%7d %7d\n", a, b);
/* this is a Molly-Guard */
if ( (a<0) || (b<0) || (a>vmax) || (b>vmax) ) {
fprintf(stderr, "ERROR: vmax=%d a=%d b=%d\n", vmax, a, b);
return -1;
}
printf("%.9f %.9f %.9f %.9f %.9f %.9f\n", printf("%.9f %.9f %.9f %.9f %.9f %.9f\n",
eav->Blist->bbs[a].p.x, eav->Blist->bbs[a].p.x,
@ -142,25 +150,34 @@ else if (! strcasecmp("bbox", outmode)) { mode = 2; }
switch (mode) { switch (mode) {
case 0: case 0:
printf_the_edges(&eav); break; foo = printf_the_edges(&eav); break;
case 1: case 1:
printf_the_vertices(&eav); break; foo = printf_the_vertices(&eav); break;
case 2: case 2:
printf_the_boudingbox(&eav); break; foo = printf_the_boudingbox(&eav); break;
default: default:
fprintf(stderr, "no way to do '%s'\n", outmode); fprintf(stderr, "%s: no way for '%s'\n", __func__, outmode);
exit(1); exit(1);
break; break;
} }
if (foo) {
fprintf(stderr, "%s: action '%s' -> %d\n", __func__, outmode, foo);
exit(1);
}
return 0; return 0;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
void help(void) void help(void)
{ {
fprintf(stderr, "YOLO!\n");
/* XXX */ puts("usage:\n $ export_evblob [opts] fichier.evblob");
puts("\t-h\tsome short help...");
puts("\t-t\tone of [edges vertices bbox]");
puts("\t-v\tbe more verbose");
exit(0); exit(0);
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */