]> granicus.if.org Git - graphviz/commitdiff
fixed to ignore self-arcs
authornorth <devnull@localhost>
Wed, 11 Mar 2009 17:11:33 +0000 (17:11 +0000)
committernorth <devnull@localhost>
Wed, 11 Mar 2009 17:11:33 +0000 (17:11 +0000)
cmd/tools/unflatten.c

index 0385d0662587e2ade2d451e8ecfaa313f785c172..a2bdd74fa70037742652e0a2f61cb2dd23cd327a 100644 (file)
@@ -30,7 +30,6 @@
 #include <unistd.h>
 #endif
 #include    "cgraph.h"
-#define degreeOf(n,I,O) (agdegree(n->root, n, I, O)) 
 #include    "ingraphs.h"
 
 #ifdef HAVE_GETOPT_H
@@ -47,15 +46,31 @@ static Agnode_t *ChainNode;
 static FILE *outFile;
 static char *cmd;
 
+static int myindegree(Agnode_t *n)
+{
+       return agdegree(n->root, n, TRUE, FALSE);
+}
+
+/* need outdegree without selfarcs */
+static int myoutdegree(Agnode_t *n)
+{
+       Agedge_t        *e;
+       int rv = 0;
+
+       for (e = agfstout(n->root, n); e; e = agnxtout(n->root, e)) {
+               if (agtail(e) != aghead(e)) rv++;
+       }
+       return rv;
+}
+
 static int isleaf(Agnode_t * n)
 {
-    return (degreeOf(n, TRUE, TRUE) == 1);
+    return ((myindegree(n) + myoutdegree(n)) == 1);
 }
 
 static int ischainnode(Agnode_t * n)
 {
-    return ((degreeOf(n, TRUE, FALSE) == 1)
-           && degreeOf(n, FALSE, TRUE) == 1);
+    return ((myindegree(n) == 1) && myoutdegree(n) == 1);
 }
 
 static void adjustlen(Agedge_t * e, Agsym_t * sym, int newlen)
@@ -83,7 +98,7 @@ static void transform(Agraph_t * g)
     s_ix = bindedgeattr(g, "style");
 
     for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
-       d = degreeOf(n, TRUE, TRUE);
+       d = myindegree(n) + myoutdegree(n);
        if (d == 0) {
            if (ChainLimit < 1)
                continue;