]> granicus.if.org Git - graphviz/commitdiff
Commit version of gvpr using the cgraph library. The relevant
authorerg <devnull@localhost>
Wed, 9 Jan 2008 22:36:19 +0000 (22:36 +0000)
committererg <devnull@localhost>
Wed, 9 Jan 2008 22:36:19 +0000 (22:36 +0000)
code is wrapped in #ifdef USE_CGRAPH.

cmd/gvpr/actions.c

index a6d6551c7acbdd78674eef1f261a102fd165315d..98bfd9f6898c8fe8d11462e4895f15e05be9e1d9 100644 (file)
@@ -104,8 +104,13 @@ void nodeInduce(Agraph_t * selected)
     base = agroot(selected);
     if (base == selected)
        return;
+#ifdef USE_CGRAPH
+    for (n = agfstnode(selected); n; n = agnxtnode(selected, n)) {
+       for (e = agfstout(selected, n); e; e = agnxtout(selected, e)) {
+#else
     for (n = agfstnode(selected); n; n = agnxtnode(n)) {
        for (e = agfstout(agsubnode(base, n, FALSE)); e; e = agnxtout(e)) {
+#endif
            if (agsubnode(selected, aghead(e), FALSE))
                agsubedge(selected, e, TRUE);
        }
@@ -175,7 +180,7 @@ Agobj_t *copy(Agraph_t * g, Agobj_t * obj)
        e = (Agedge_t *) obj;
        t = openNode(g, agnameof(agtail(e)));
        h = openNode(g, agnameof(aghead(e)));
-       nobj = (Agobj_t *) openEdge(t, h, name);
+       nobj = (Agobj_t *) openEdge(g, t, h, name);
        break;
     }
     if (nobj)
@@ -200,18 +205,34 @@ static Agraph_t *cloneSubg(Agraph_t * tgt, Agraph_t * g)
     ng = (Agraph_t *) (copy(tgt, OBJ(g)));
     if (!ng)
        return 0;
+#ifdef USE_CGRAPH
+    for (t = agfstnode(g); t; t = agnxtnode(g, t)) {
+#else
     for (t = agfstnode(g); t; t = agnxtnode(t)) {
+#endif
        newt = agnode(tgt, agnameof(t), 0);
        if (!newt)
            error(ERROR_PANIC, "node %s not found in cloned graph %s",
                  agnameof(t), agnameof(tgt));
        agsubnode(ng, newt, 1);
     }
+#ifdef USE_CGRAPH
+    for (t = agfstnode(g); t; t = agnxtnode(g, t)) {
+#else
     for (t = agfstnode(g); t; t = agnxtnode(t)) {
+#endif
        newt = agnode(tgt, agnameof(t), 0);
+#ifdef USE_CGRAPH
+       for (e = agfstout(g, t); e; e = agnxtout(g, e)) {
+#else
        for (e = agfstout(t); e; e = agnxtout(e)) {
+#endif
            newh = agnode(tgt, agnameof(aghead(e)), 0);
+#ifdef USE_CGRAPH
+           newe = agedge(tgt, newt, newh, agnameof(e), 0);
+#else
            newe = agedge(newt, newh, agnameof(e), 0);
+#endif
            if (!newe)
                error(ERROR_PANIC,
                      "edge (%s,%s)[%s] not found in cloned graph %s",
@@ -238,14 +259,23 @@ static void cloneGraph(Agraph_t * tgt, Agraph_t * src)
     Agnode_t *t;
     Agraph_t *sg;
 
+#ifdef USE_CGRAPH
+    for (t = agfstnode(src); t; t = agnxtnode(src, t)) {
+#else
     for (t = agfstnode(src); t; t = agnxtnode(t)) {
+#endif
        if (!copy(tgt, OBJ(t))) {
            error(ERROR_FATAL, "error cloning node %s from graph %s",
                  agnameof(t), agnameof(src));
        }
     }
+#ifdef USE_CGRAPH
+    for (t = agfstnode(src); t; t = agnxtnode(src, t)) {
+       for (e = agfstout(src, t); e; e = agnxtout(src, e)) {
+#else
     for (t = agfstnode(src); t; t = agnxtnode(t)) {
        for (e = agfstout(t); e; e = agnxtout(e)) {
+#endif
            if (!copy(tgt, OBJ(e))) {
                error(ERROR_FATAL,
                      "error cloning edge (%s,%s)[%s] from graph %s",
@@ -303,7 +333,7 @@ Agobj_t *clone(Agraph_t * g, Agobj_t * obj)
        e = (Agedge_t *) obj;
        t = (Agnode_t *) clone(g, OBJ(agtail(e)));
        h = (Agnode_t *) clone(g, OBJ(aghead(e)));
-       nobj = (Agobj_t *) openEdge(t, h, name);
+       nobj = (Agobj_t *) openEdge(g, t, h, name);
        if (nobj)
            copyAttr(obj, nobj);
        break;
@@ -316,20 +346,24 @@ Agobj_t *clone(Agraph_t * g, Agobj_t * obj)
 #define CCMARK(n)    (((nData(n))->iu.integer) |= 2)
 #define CCUNMARK(n)  (((nData(n))->iu.integer) &= ~2)
 
-static void cc_dfs(Agraph_t * comp, Agnode_t * n)
+static void cc_dfs(Agraph_t* g, Agraph_t * comp, Agnode_t * n)
 {
     Agedge_t *e;
     Agnode_t *other;
 
     CCMARK(n);
     agidnode(comp, AGID(n), 1);
+#ifdef USE_CGRAPH
+    for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
+#else
     for (e = agfstedge(n); e; e = agnxtedge(e, n)) {
+#endif
        if (agtail(e) == n)
            other = aghead(e);
        else
            other = agtail(e);
        if (!CCMARKED(other))
-           cc_dfs(comp, other);
+           cc_dfs(g, comp, other);
     }
 }
 
@@ -345,12 +379,16 @@ Agraph_t *compOf(Agraph_t * g, Agnode_t * n)
 
     if (!(n = agidnode(g, AGID(n), 0)))
        return 0;               /* n not in g */
+#ifdef USE_CGRAPH
+    for (np = agfstnode(g); np; np = agnxtnode(g, np))
+#else
     for (np = agfstnode(g); np; np = agnxtnode(np))
+#endif
        CCUNMARK(np);
 
     sprintf(name, "_cc_%d", id++);
     cg = openSubg(g, name);
-    cc_dfs(cg, n);
+    cc_dfs(g, cg, n);
 
     return cg;
 }
@@ -359,16 +397,28 @@ Agraph_t *compOf(Agraph_t * g, Agnode_t * n)
  * Return edge, if any, between t and h with given key.
  * Edge is in root graph
  */
-Agedge_t *isEdge(Agnode_t * t, Agnode_t * h, char *key)
+Agedge_t *isEdge(Agraph_t* g, Agnode_t * t, Agnode_t * h, char *key)
 {
     Agraph_t *root;
 
+#ifdef USE_CGRAPH
+    root = sameG(t, h, "isEdge", "tail and head node");
+    if (!root)
+       return 0;
+    if (g && (root != agroot(g)))
+       return 0;
+    else
+       g = root;
+
+    return agedge(g, t, h, key, 0);
+#else
     if ((root = sameG(t, h, "isEdge", "tail and head node"))) {
        t = (Agnode_t *) agrebind(root, OBJ(t));
        h = (Agnode_t *) agrebind(root, OBJ(h));
        return agedge(t, h, key, 0);
     } else
        return 0;
+#endif
 }
 
 /* isIn:
@@ -392,22 +442,22 @@ int isIn(Agraph_t * gp, Agobj_t * objp)
  * Insert node n into subgraph g.
  * Return image of n
  */
-Agnode_t *addNode(Agraph_t * gp, Agnode_t * np)
+Agnode_t *addNode(Agraph_t * gp, Agnode_t * np, int doAdd)
 {
     if (!sameG(gp, np, "addNode", 0))
        return 0;
-    return agsubnode(gp, np, 1);
+    return agsubnode(gp, np, doAdd);
 }
 
 /* addEdge:
  * Insert edge e into subgraph g.
  * Return image of e
  */
-Agedge_t *addEdge(Agraph_t * gp, Agedge_t * ep)
+Agedge_t *addEdge(Agraph_t * gp, Agedge_t * ep, int doAdd)
 {
     if (!sameG(gp, ep, "addEdge", 0))
        return 0;
-    return agsubedge(gp, ep, 1);
+    return agsubedge(gp, ep, doAdd);
 }
 
 /* lockGraph:
@@ -470,7 +520,9 @@ int deleteObj(Agraph_t * g, Agobj_t * obj)
     /* node or edge */
     if (!g)
        g = agroot(agraphof(obj));
+#ifndef USE_CGRAPH
     obj = agrebind(g, obj);
+#endif
     if (obj)
        return agdelete(g, obj);
     else