From d321db650ef79ce34b4841fa8ef47ba7b8aa73a0 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Mon, 6 Oct 2008 07:42:14 +0000 Subject: [PATCH] Factorise printing costs. [r22517] --- html_dumper.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/html_dumper.c b/html_dumper.c index 1ad46ab26..deef1be07 100644 --- a/html_dumper.c +++ b/html_dumper.c @@ -7,6 +7,16 @@ #include "kaps.h" #include "pbqp_t.h" +/* Caution: Due to static buffer use only once per statement */ +static const char *cost2a(num const cost) +{ + static char buf[10]; + + if (cost == INF_COSTS) return "inf"; + sprintf(buf, "%6d", cost); + return buf; +} + /* print vector */ static void dump_vector(FILE *f, vector *vec) { @@ -18,19 +28,10 @@ static void dump_vector(FILE *f, vector *vec) assert(len > 0); for (index = 0; index < len; ++index) { #if EXT_GRS_DEBUG - if (vec->entries[index].data == INF_COSTS) { - fprintf(f, " inf ", - vec->entries[index].name); - } else { - fprintf(f, "%6d", - vec->entries[index].name, vec->entries[index].data); - } + fprintf(f, "%s ", + vec->entries[index].name, cost2a(vec->entries[index].data)); #else - if (vec->entries[index].data == INF_COSTS) { - fputs(" inf ", f); - } else { - fprintf(f, "%6d", vec->entries[index].data); - } + fprintf(f, "%s ", cost2a(vec->entries[index].data)); #endif } fprintf(f, " )\n"); @@ -46,20 +47,10 @@ static void dump_matrix(FILE *f, pbqp_matrix *mat) assert(mat->rows> 0); fprintf(f, "\t\\begin{pmatrix}\n"); for (row = 0; row < mat->rows; ++row) { - if (*p == INF_COSTS) { - fputs("\t inf", f); - } else { - fprintf(f, "\t %6d", *p); - } - ++p; + fprintf(f, "\t %s", cost2a(*p++)); for (col = 1; col < mat->cols; ++col) { - if (*p == INF_COSTS) { - fputs("& inf", f); - } else { - fprintf(f, "& %6d", *p); - } - ++p + fprintf(f, "& %s", cost2a(*p++)); } fprintf(f, "\\\\\n"); } -- 2.20.1