From 2b3cd2af0324ac0f680d4a5693924f8fad965ebd Mon Sep 17 00:00:00 2001 From: John Ellson Date: Sun, 18 Dec 2016 01:14:25 -0500 Subject: [PATCH] demo/modgraph.lua now demos built-in tred --- cmd/tools/tred2.c | 7 ++++--- graphviz.spec.in | 1 + lib/common/types.h | 3 +-- lib/gvc/gvc.h | 2 +- lib/gvc/gvtool_tred.c | 20 +++++++++++++++----- tclpkg/gv/demo/modgraph.lua | 5 +++-- tclpkg/gv/gv.cpp | 4 ++-- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/cmd/tools/tred2.c b/cmd/tools/tred2.c index 088a48bd0..a11b4e22d 100644 --- a/cmd/tools/tred2.c +++ b/cmd/tools/tred2.c @@ -87,20 +87,21 @@ int main(int argc, char **argv) { Agraph_t *g; ingraph_state ig; + int rc = 0; init(argc, argv); newIngraph(&ig, Files, gread); while ((g = nextGraph(&ig)) != 0) { if (agisdirected(g)) { - aginit(g, AGNODE, "info", sizeof(Agnodeinfo_t), TRUE); - gvToolTred(g); + if ((rc = gvToolTred(g))) + break; agwrite(g, stdout); fflush(stdout); } agclose(g); } - return 0; + return rc; } diff --git a/graphviz.spec.in b/graphviz.spec.in index 5ba14a298..509196ffe 100644 --- a/graphviz.spec.in +++ b/graphviz.spec.in @@ -219,6 +219,7 @@ When used alone, this is intended for mimimalist web-server apps with no X11 on %endif %doc COPYING AUTHORS ChangeLog NEWS README %exclude %{_bindir}/dot_builtins +%exclude %{_bindir}/tred2 %{_bindir}/acyclic %{_bindir}/bcomps %{_bindir}/ccomps diff --git a/lib/common/types.h b/lib/common/types.h index 8c9e0a305..933af78cd 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -406,7 +406,6 @@ typedef enum {NATIVEFONTS,PSFONTS,SVGFONTS} fontname_kind; char state; unsigned char gui_state; /* Node state for GUI ops */ boolean clustnode; - int mark; /* for tools like tred */ #ifndef DOT_ONLY unsigned char pinned; @@ -420,7 +419,7 @@ typedef enum {NATIVEFONTS,PSFONTS,SVGFONTS} fontname_kind; node_t *set; /* fast graph */ - char node_type, onstack; + char node_type, mark, onstack; char ranktype, weight_class; node_t *next, *prev; elist in, out, flat_out, flat_in, other; diff --git a/lib/gvc/gvc.h b/lib/gvc/gvc.h index 24cdada15..3c9cb91af 100644 --- a/lib/gvc/gvc.h +++ b/lib/gvc/gvc.h @@ -116,7 +116,7 @@ extern void gvAddLibrary(GVC_t *gvc, gvplugin_library_t *lib); /** Perform a Transitive Reduction on a graph * @param g graph to be transformed. */ -extern void gvToolTred(graph_t *g); +extern int gvToolTred(graph_t *g); #undef extern diff --git a/lib/gvc/gvtool_tred.c b/lib/gvc/gvtool_tred.c index d53e289a9..763a79d9a 100644 --- a/lib/gvc/gvtool_tred.c +++ b/lib/gvc/gvtool_tred.c @@ -27,6 +27,13 @@ #include "cgraph.h" #include "gvc.h" +typedef struct { + Agrec_t h; + int mark; +} Agmarknodeinfo_t; + +#define MARK(n) (((Agmarknodeinfo_t*)(n->base.data))->mark) + #define agrootof(n) ((n)->root) static int dfs(Agnode_t * n, Agedge_t * link, int warn) @@ -35,18 +42,18 @@ static int dfs(Agnode_t * n, Agedge_t * link, int warn) Agedge_t *f; Agraph_t *g = agrootof(n); - ND_mark(n) = 1; + MARK(n) = 1; for (e = agfstin(g, n); e; e = f) { f = agnxtin(g, e); if (e == link) continue; - if (ND_mark(agtail(e))) + if (MARK(agtail(e))) agdelete(g, e); } for (e = agfstout(g, n); e; e = agnxtout(g, e)) { - if (ND_mark(aghead(e))) { + if (MARK(aghead(e))) { if (!warn) { warn++; fprintf(stderr, @@ -59,21 +66,24 @@ static int dfs(Agnode_t * n, Agedge_t * link, int warn) warn = dfs(aghead(e), AGOUT2IN(e), warn); } - ND_mark(n) = 0; + MARK(n) = 0; return warn; } -void gvToolTred(Agraph_t * g) +int gvToolTred(Agraph_t * g) { Agnode_t *n; int warn = 0; if (agisdirected(g)) { + aginit(g, AGNODE, "info", sizeof(Agmarknodeinfo_t), TRUE); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { warn = dfs(n, NULL, warn); } + agclean(g, AGNODE, "info"); } else { fprintf(stderr, "warning: %s is not a directed graph, not attempting tred\n", agnameof(g)); } + return 0; // FIXME - return proper errors } diff --git a/tclpkg/gv/demo/modgraph.lua b/tclpkg/gv/demo/modgraph.lua index 4cb83344d..f73d1f626 100755 --- a/tclpkg/gv/demo/modgraph.lua +++ b/tclpkg/gv/demo/modgraph.lua @@ -23,8 +23,7 @@ gv.setv(E, 'arrowsize', '.4') for rec in modules do - -- note - Lua's "gfind" in 5.1 became "fmatch" in 5.2 - + -- note - Lua's "string.gfind" in 5.1 became "string.gmatch" in 5.2 for mod, usedbylist in string.gmatch(rec, "([_%w]+) %w+ %w+ ([-,_%w]+)") do n = gv.node(G, mod) @@ -36,5 +35,7 @@ for rec in modules do end end +gv.tred(G) + gv.layout(G, 'dot') gv.render(G, 'gtk') diff --git a/tclpkg/gv/gv.cpp b/tclpkg/gv/gv.cpp index 097fc5b6b..1136b2124 100644 --- a/tclpkg/gv/gv.cpp +++ b/tclpkg/gv/gv.cpp @@ -950,11 +950,11 @@ bool write(Agraph_t *g, const char *filename) bool tred(Agraph_t *g) { - int err = 0; + int err; if (!g) return false; - gvToolTred(g); // FIXME - gvToolTred should rteturn errors code + err = gvToolTred(g); return (! err); } -- 2.40.0