From: Emden Gansner Date: Thu, 26 May 2016 17:29:27 +0000 (-0400) Subject: Extend acyclic to report the number of reversed edges. X-Git-Tag: TRAVIS_CI_BUILD_EXPERIMENTAL~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=659bfedf7bc750282f2a0e9eeb6cbffc509828ca;p=graphviz Extend acyclic to report the number of reversed edges. --- diff --git a/cmd/tools/acyclic.c b/cmd/tools/acyclic.c index a16cccdac..c5256fcd5 100644 --- a/cmd/tools/acyclic.c +++ b/cmd/tools/acyclic.c @@ -59,6 +59,7 @@ static FILE *outFile; static int doWrite = 1; static int Verbose; static char *cmd; +static int num_rev; /* addRevEdge: * Add a reversed version of e. The new edge has the same key. @@ -73,12 +74,16 @@ static void addRevEdge(Agraph_t * g, Agedge_t * e) agcopyattr (e, f); + num_rev++; sym = agattr (g, AGEDGE, TAILPORT_ID, 0); if (sym) agsafeset (f, HEADPORT_ID, agxget (e, sym), ""); sym = agattr (g, AGEDGE, HEADPORT_ID, 0); if (sym) agsafeset (f, TAILPORT_ID, agxget (e, sym), ""); } +/* dfs: + * Return the number of reversed edges for this component. + */ static int dfs(Agraph_t * g, Agnode_t * t, int hasCycle) { Agedge_t *e; @@ -104,7 +109,7 @@ static int dfs(Agraph_t * g, Agnode_t * t, int hasCycle) agdelete(g, e); hasCycle = 1; } else if (ND_mark(h) == 0) - hasCycle = dfs(g, h, hasCycle); + hasCycle |= dfs(g, h, hasCycle); } ND_onstack(t) = 0; return hasCycle; @@ -202,14 +207,14 @@ int main(int argc, char *argv[]) } if (Verbose) { if (rv) - fprintf(stderr, "Graph %s has cycles\n", graphName(g)); + fprintf(stderr, "Graph \"%s\" has cycles; %d reversed edges\n", graphName(g), num_rev); else - fprintf(stderr, "Graph %s is acyclic\n", graphName(g)); + fprintf(stderr, "Graph \"%s\" is acyclic\n", graphName(g)); } } else { - rv = 2; + rv = -1; if (Verbose) - fprintf(stderr, "Graph %s is undirected\n", graphName(g)); + fprintf(stderr, "Graph \"%s\" is undirected\n", graphName(g)); } exit(rv); } else