From 505f9ad63173f67774421c048b0f6416d357a6ce Mon Sep 17 00:00:00 2001 From: Glen Low Date: Wed, 7 Oct 2015 08:16:45 +0800 Subject: [PATCH] Reinstate static functions used for debugging --- lib/common/htmllex.c | 6 +-- lib/common/routespl.c | 37 +++++++++++++++++ lib/common/shapes.c | 32 +++++++++++++++ lib/common/taper.c | 6 +-- lib/dotgen/dotinit.c | 25 ++++++++++++ lib/dotgen/mincross.c | 84 +++++++++++++++++++++++++++++++++++++++ lib/dotgen/position.c | 22 ++++++++++ lib/fdpgen/clusteredges.c | 21 ++++++++++ lib/gvpr/compile.c | 17 ++++++++ lib/neatogen/constraint.c | 45 +++++++++++++++++++++ lib/neatogen/fPQ.h | 16 ++++++++ lib/neatogen/stress.c | 13 ++++++ lib/ortho/partition.c | 30 ++++++++++++++ 13 files changed, 348 insertions(+), 6 deletions(-) diff --git a/lib/common/htmllex.c b/lib/common/htmllex.c index f8a38bb2e..8c303beee 100644 --- a/lib/common/htmllex.c +++ b/lib/common/htmllex.c @@ -883,7 +883,6 @@ int htmllineno() #endif } -/* #ifdef DEBUG static void printTok(int tok) { @@ -998,7 +997,6 @@ static void printTok(int tok) } #endif -*/ int htmllex() { @@ -1052,7 +1050,9 @@ int htmllex() if (endp) state.ptr = endp; } while (state.tok == 0); - /* printTok (state.tok); */ +#if DEBUG + printTok (state.tok); +#endif return state.tok; #else return EOF; diff --git a/lib/common/routespl.c b/lib/common/routespl.c index 37342ea06..f70661997 100644 --- a/lib/common/routespl.c +++ b/lib/common/routespl.c @@ -64,6 +64,43 @@ static void printboxes(int boxn, boxf* boxes) Show_boxes[Show_cnt+1] = NULL; } +#if DEBUG > 1 +static void psprintpolypts(Ppoint_t * p, int sz) +{ + int i; + + fprintf(stderr, "%%!\n"); + fprintf(stderr, "%% constraint poly\n"); + fprintf(stderr, "newpath\n"); + for (i = 0; i < sz; i++) + fprintf(stderr, "%f %f %s\n", p[i].x, p[i].y, + (i == 0 ? "moveto" : "lineto")); + fprintf(stderr, "closepath stroke\n"); +} +static void psprintpoint(point p) +{ + fprintf(stderr, "gsave\n"); + fprintf(stderr, + "newpath %d %d moveto %d %d 2 0 360 arc closepath fill stroke\n", + p.x, p.y, p.x, p.y); + fprintf(stderr, "/Times-Roman findfont 4 scalefont setfont\n"); + fprintf(stderr, "%d %d moveto (\\(%d,%d\\)) show\n", p.x + 5, p.y + 5, + p.x, p.y); + fprintf(stderr, "grestore\n"); +} +static void psprintpointf(pointf p) +{ + fprintf(stderr, "gsave\n"); + fprintf(stderr, + "newpath %.5g %.5g moveto %.5g %.5g 2 0 360 arc closepath fill stroke\n", + p.x, p.y, p.x, p.y); + fprintf(stderr, "/Times-Roman findfont 4 scalefont setfont\n"); + fprintf(stderr, "%.5g %.5g moveto (\\(%.5g,%.5g\\)) show\n", p.x + 5, p.y + 5, + p.x, p.y); + fprintf(stderr, "grestore\n"); +} +#endif + static void psprintspline(Ppolyline_t spl) { char buf[BUFSIZ]; diff --git a/lib/common/shapes.c b/lib/common/shapes.c index e2e43523d..139d85e8b 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -3463,6 +3463,38 @@ static void pos_reclbl(field_t * f, pointf ul, int sides) } } +#if DEBUG > 1 +static void indent(int l) +{ + int i; + for (i = 0; i < l; i++) + fputs(" ", stderr); +} + +static void prbox(boxf b) +{ + fprintf(stderr, "((%.5g,%.5g),(%.5g,%.5g))\n", b.LL.x, b.LL.y, b.UR.x, + b.UR.y); +} + +static void dumpL(field_t * info, int level) +{ + int i; + + indent(level); + if (info->n_flds == 0) { + fprintf(stderr, "Label \"%s\" ", info->lp->text); + prbox(info->b); + } else { + fprintf(stderr, "Tbl "); + prbox(info->b); + for (i = 0; i < info->n_flds; i++) { + dumpL(info->fld[i], level + 1); + } + } +} +#endif + /* syntax of labels: foo|bar|baz or foo|(recursive|label)|baz */ static void record_init(node_t * n) { diff --git a/lib/common/taper.c b/lib/common/taper.c index bdfd03804..e9dabf21f 100644 --- a/lib/common/taper.c +++ b/lib/common/taper.c @@ -156,7 +156,6 @@ insertArr (vararr_t* arr, pointf p, double l) arr->pts[arr->cnt++].lengthsofar = l; } -/* #ifdef DEBUG static void printArr (vararr_t* arr, FILE* fp) @@ -171,7 +170,6 @@ printArr (vararr_t* arr, FILE* fp) } } #endif -*/ static void fixArr (vararr_t* arr) @@ -228,7 +226,9 @@ static vararr_t* pathtolines (bezier* bez, double initwid) } } fixArr (arr); - /* printArr (arr, stderr); */ +#ifdef DEBUG + printArr (arr, stderr); +#endif return arr; } diff --git a/lib/dotgen/dotinit.c b/lib/dotgen/dotinit.c index c7c5fa864..c1f25e989 100644 --- a/lib/dotgen/dotinit.c +++ b/lib/dotgen/dotinit.c @@ -200,6 +200,31 @@ fastn (graph_t * g) for (u = GD_nlist(g); u; u = ND_next(u)) cnt++; return cnt; } + +#if DEBUG > 1 +static void +dumpRanks (graph_t * g) +{ + int i, j; + node_t* u; + rank_t *rank = GD_rank(g); + int rcnt = 0; + for (i = GD_minrank(g); i <= GD_maxrank(g); i++) { + fprintf (stderr, "[%d] :", i); + for (j = 0; j < rank[i].n; j++) { + u = rank[i].v[j]; + rcnt++; + if (streq(agnameof(u),"virtual")) + fprintf (stderr, " %x", u); + else + fprintf (stderr, " %s", agnameof(u)); + + } + fprintf (stderr, "\n"); + } + fprintf (stderr, "count %d rank count = %d\n", fastn(g), rcnt); +} +#endif #endif diff --git a/lib/dotgen/mincross.c b/lib/dotgen/mincross.c index 920453324..6d084891b 100644 --- a/lib/dotgen/mincross.c +++ b/lib/dotgen/mincross.c @@ -47,6 +47,12 @@ static adjmatrix_t *new_matrix(int i, int j); static void free_matrix(adjmatrix_t * p); static int ordercmpf(int *i0, int *i1); #ifdef DEBUG +#if DEBUG > 1 +static int gd_minrank(Agraph_t *g) {return GD_minrank(g);} +static int gd_maxrank(Agraph_t *g) {return GD_maxrank(g);} +static rank_t *gd_rank(Agraph_t *g, int r) {return &GD_rank(g)[r];} +static int nd_order(Agnode_t *v) { return ND_order(v); } +#endif void check_rs(graph_t * g, int null_ok); void check_order(void); void check_vlists(graph_t * g); @@ -64,6 +70,84 @@ static edge_t **TE_list; static int *TI_list; static boolean ReMincross; +#if DEBUG > 1 +static void indent(graph_t* g) +{ + if (g->parent) { + fprintf (stderr, " "); + indent(g->parent); + } +} + +static char* nname(node_t* v) +{ + static char buf[1000]; + if (ND_node_type(v)) { + if (ND_ranktype(v) == CLUSTER) + sprintf (buf, "v%s_%p", agnameof(ND_clust(v)), v); + else + sprintf (buf, "v_%p", v); + } else + sprintf (buf, "%s", agnameof(v)); + return buf; +} +static void dumpg (graph_t* g) +{ + int j, i, r; + node_t* v; + edge_t* e; + + fprintf (stderr, "digraph A {\n"); + for (r = GD_minrank(g); r <= GD_maxrank(g); r++) { + fprintf (stderr, " subgraph {rank=same "); + for (i = 0; i < GD_rank(g)[r].n; i++) { + v = GD_rank(g)[r].v[i]; + if (i > 0) + fprintf (stderr, " -> %s", nname(v)); + else + fprintf (stderr, "%s", nname(v)); + } + if (i > 1) fprintf (stderr, " [style=invis]}\n"); + else fprintf (stderr, " }\n"); + } + for (r = GD_minrank(g); r < GD_maxrank(g); r++) { + for (i = 0; i < GD_rank(g)[r].n; i++) { + v = GD_rank(g)[r].v[i]; + for (j = 0; (e = ND_out(v).list[j]); j++) { + fprintf (stderr, "%s -> ", nname(v)); + fprintf (stderr, "%s\n", nname(aghead(e))); + } + } + } + fprintf (stderr, "}\n"); +} +static void dumpr (graph_t* g, int edges) +{ + int j, i, r; + node_t* v; + edge_t* e; + + for (r = GD_minrank(g); r <= GD_maxrank(g); r++) { + fprintf (stderr, "[%d] ", r); + for (i = 0; i < GD_rank(g)[r].n; i++) { + v = GD_rank(g)[r].v[i]; + fprintf (stderr, "%s(%.02f,%d) ", nname(v), saveorder(v),ND_order(v)); + } + fprintf (stderr, "\n"); + } + if (edges == 0) return; + for (r = GD_minrank(g); r < GD_maxrank(g); r++) { + for (i = 0; i < GD_rank(g)[r].n; i++) { + v = GD_rank(g)[r].v[i]; + for (j = 0; (e = ND_out(v).list[j]); j++) { + fprintf (stderr, "%s -> ", nname(v)); + fprintf (stderr, "%s\n", nname(aghead(e))); + } + } + } +} +#endif + typedef struct { Agrec_t h; int x, lo, hi; diff --git a/lib/dotgen/position.c b/lib/dotgen/position.c index df0cfcab3..21c9b08d5 100644 --- a/lib/dotgen/position.c +++ b/lib/dotgen/position.c @@ -34,6 +34,28 @@ static void make_lrvn(graph_t * g); static void contain_nodes(graph_t * g); static boolean idealsize(graph_t * g, double); +#if DEBUG > 1 +static void +dumpNS (graph_t * g) +{ + node_t* n = GD_nlist(g); + elist el; + edge_t* e; + int i; + + while (n) { + el = ND_out(n); + for (i = 0; i < el.size; i++) { + e = el.list[i]; + fprintf (stderr, "%s(%x) -> ", agnameof(agtail(e)),agtail(e)); + fprintf (stderr, "%s(%x) : %d\n", agnameof(aghead(e)), aghead(e), + ED_minlen(e)); + } + n = ND_next(n); + } +} +#endif + static double largeMinlen (double l) { diff --git a/lib/fdpgen/clusteredges.c b/lib/fdpgen/clusteredges.c index 85f52148b..f10b1f9f1 100644 --- a/lib/fdpgen/clusteredges.c +++ b/lib/fdpgen/clusteredges.c @@ -41,6 +41,27 @@ typedef struct { */ #define INIT_SZ 100 +#if DEBUG > 1 +static void dumpObj(Ppoly_t * p) +{ + int j; + Ppoint_t pt; + for (j = 0; j < p->pn; j++) { + pt = p->ps[j]; + fprintf(stderr, " %.5g %.5g", pt.x, pt.y); + } + fputs("\n", stderr); +} + +static void dumpObjlist(objlist * l) +{ + int i; + for (i = 0; i < l->cnt; i++) { + dumpObj(l->obs[i]); + } +} +#endif + static void addObj(objlist * l, Ppoly_t * obj) { if (l->sz == l->cnt) { diff --git a/lib/gvpr/compile.c b/lib/gvpr/compile.c index 03fd0d6a8..e36e09dc3 100644 --- a/lib/gvpr/compile.c +++ b/lib/gvpr/compile.c @@ -192,6 +192,23 @@ static int posOf(Agnode_t* np, int idx, double* v) } +#if DEBUG > 1 +static char *symName(Expr_t * ex, int op) +{ + if (op >= MINNAME && op <= MAXNAME) + return gprnames[op]; + else { + Sfio_t *sf = sfstropen(); + char *s; + + sfprintf(sf, "", op); + s = exstring(ex, sfstruse(sf)); + sfclose(sf); + return s; + } +} +#endif + /* xargs: * Convert string argument to graph to type of graph desired. * u => undirected diff --git a/lib/neatogen/constraint.c b/lib/neatogen/constraint.c index 025e09d50..53040fd2d 100644 --- a/lib/neatogen/constraint.c +++ b/lib/neatogen/constraint.c @@ -154,6 +154,51 @@ static void mapGraphs(graph_t * g, graph_t * cg, distfn dist) } } +#if DEBUG > 1 +static int +indegree (graph_t * g, node_t *n) +{ + edge_t *e; + int cnt = 0; + for (e = agfstin(g,n); e; e = agnxtin(g,e)) cnt++; + return cnt; +} + +static int +outdegree (graph_t * g, node_t *n) +{ + edge_t *e; + int cnt = 0; + for (e = agfstout(g,n); e; e = agnxtout(g,e)) cnt++; + return cnt; +} + +static void +validate(graph_t * g) +{ + node_t *n; + edge_t *e; + int i, cnt; + + cnt = 0; + for (n = GD_nlist(g);n; n = ND_next(n)) { + assert(outdegree(g,n) == ND_out(n).size); + for (i = 0; (e = ND_out(n).list[i]); i++) { + assert(agtail(e) == n); + assert( e == agfindedge(g, n, aghead(e))); + } + assert(indegree(g,n) == ND_in(n).size); + for (i = 0; (e = ND_in(n).list[i]); i++) { + assert(aghead(e) == n); + assert( e == agfindedge(g, agtail(e), n)); + } + cnt++; + } + + assert (agnnodes(g) == cnt); +} +#endif + #ifdef OLD static node_t *newNode(graph_t * g) { diff --git a/lib/neatogen/fPQ.h b/lib/neatogen/fPQ.h index d95d48f9f..268b87c04 100644 --- a/lib/neatogen/fPQ.h +++ b/lib/neatogen/fPQ.h @@ -164,5 +164,21 @@ PQupdate (PQ* pq, PQTYPE n, PQVTYPE d) #endif } +#if DEBUG > 1 + +static void +PQprint (PQ* pq) +{ + int i; + PQTYPE n; + + fprintf (stderr, "Q: "); + for (i = 1; i <= pq->PQcnt; i++) { + n = pq->pq[i]; + fprintf (stderr, "(%d:%f) ", N_IDX(pq,n), N_VAL(pq,n)); + } + fprintf (stderr, "\n"); +} +#endif #endif diff --git a/lib/neatogen/stress.c b/lib/neatogen/stress.c index a96a77a81..4ba4e2827 100644 --- a/lib/neatogen/stress.c +++ b/lib/neatogen/stress.c @@ -865,6 +865,19 @@ float *compute_apsp_artifical_weights_packed(vtx_data * graph, int n) return Dij; } +#if DEBUG > 1 +static void dumpMatrix(float *Dij, int n) +{ + int i, j, count = 0; + for (i = 0; i < n; i++) { + for (j = i; j < n; j++) { + fprintf(stderr, "%.02f ", Dij[count++]); + } + fputs("\n", stderr); + } +} +#endif + /* Accumulator type for diagonal of Laplacian. Needs to be as large * as possible. Use long double; configure to double if necessary. */ diff --git a/lib/ortho/partition.c b/lib/ortho/partition.c index e860f0e03..43b71f737 100644 --- a/lib/ortho/partition.c +++ b/lib/ortho/partition.c @@ -687,6 +687,36 @@ rectIntersect (boxf *d, const boxf *r0, const boxf *r1) return 1; } +#if DEBUG > 1 +static void +dumpTrap (trap_t* tr, int n) +{ + int i; + for (i = 1; i <= n; i++) { + tr++; + fprintf (stderr, "%d : %d %d (%f,%f) (%f,%f) %d %d %d %d\n", i, + tr->lseg, tr->rseg, tr->hi.x, tr->hi.y, tr->lo.x, tr->lo.y, + tr->u0, tr->u1, tr->d0, tr->d1); + fprintf (stderr, " %d %d %d %d\n", tr->sink, tr->usave, + tr->uside, tr->state); + } + fprintf (stderr, "====\n"); +} + +static void +dumpSegs (segment_t* sg, int n) +{ + int i; + for (i = 1; i <= n; i++) { + sg++; + fprintf (stderr, "%d : (%f,%f) (%f,%f) %d %d %d %d %d\n", i, + sg->v0.x, sg->v0.y, sg->v1.x, sg->v1.y, + sg->is_inserted, sg->root0, sg->root1, sg->next, sg->prev); + } + fprintf (stderr, "====\n"); +} +#endif + boxf* partition (cell* cells, int ncells, int* nrects, boxf bb) { -- 2.50.1