]> granicus.if.org Git - graphviz/commitdiff
partial conversion of gv.cpp to cgraph
authorellson <devnull@localhost>
Thu, 23 Oct 2008 20:01:38 +0000 (20:01 +0000)
committerellson <devnull@localhost>
Thu, 23 Oct 2008 20:01:38 +0000 (20:01 +0000)
tclpkg/gv/Makefile.am
tclpkg/gv/gv.cpp

index 47a464a6f177457889902748881882d43118d36e..a749acb56f50127bf8749686e23867b4e9336868 100644 (file)
@@ -5,6 +5,7 @@ SUBDIRS = demo
 
 if WITH_CGRAPH
 GRAPH = cgraph
+DEFS += -DWITH_CGRAPH
 else
 GRAPH = graph
 endif
index 4f18fc98898c5bdaa0be19f8f7192280481f65f8..71c4523dbe7c4b311db0074ffa02747d27d159a5 100644 (file)
@@ -15,6 +15,7 @@
 **********************************************************/
 
 #include <string.h>
+#include <stdlib.h>
 #include "gvc.h"
 
 extern "C" {
@@ -107,8 +108,8 @@ Agedge_t *edge(Agnode_t *t, Agnode_t *h)
 {
     // edges from/to the protonode are not permitted
     if (!gvc || !t || !h
-      || (t->name[0] == '\001' && strcmp (t->name, "\001proto") == 0)
-      || (h->name[0] == '\001' && strcmp (h->name, "\001proto") == 0))
+      || (agnameof(t)[0] == '\001' && strcmp (agnameof(t), "\001proto") == 0)
+      || (agnameof(h)[0] == '\001' && strcmp (agnameof(h), "\001proto") == 0))
         return NULL;
     return agedge(t->graph, t, h);
 }
@@ -139,7 +140,11 @@ static char* myagxget(void *obj, Agsym_t *a)
 
     if (!obj || !a)
         return emptystring;
+#ifndef WITH_CGRAPH
     val = agxget(obj, a->index);
+#else
+    val = agxget(obj, a);
+#endif
     if (!val)
         return emptystring;
     if (a->name[0] == 'l' && strcmp(a->name, "label") == 0 && aghtmlstr(val)) {
@@ -163,7 +168,7 @@ char *getv(Agraph_t *g, char *attr)
 
     if (!g || !attr)
         return NULL;
-    a = agfindattr(g->root, attr);
+    a = agfindattr(agroot(g), attr);
     return myagxget(g, a);
 }
 static void myagxset(void *obj, Agsym_t *a, char *val)
@@ -180,7 +185,11 @@ static void myagxset(void *obj, Agsym_t *a, char *val)
             free(hs);
         }
     }
+#ifndef WITH_CGRAPH
     agxset(obj, a->index, val);
+#else
+    agxset(obj, a, val);
+#endif
 }
 char *setv(Agraph_t *g, Agsym_t *a, char *val)
 {
@@ -195,7 +204,7 @@ char *setv(Agraph_t *g, char *attr, char *val)
 
     if (!g || !attr || !val)
         return NULL;
-    a = agfindattr(g->root, attr);
+    a = agfindattr(agroot(g), attr);
     if (!a)
         a = agraphattr(g->root, attr, emptystring);
     myagxset(g, a, val);
@@ -213,7 +222,7 @@ char *getv(Agnode_t *n, char *attr)
 
     if (!n || !attr)
         return NULL;
-    g = n->graph->root;
+    g = agroot(agraphof(n));
     a = agfindattr(g->proto->n, attr);
     return myagxget(n, a);
 }
@@ -231,7 +240,7 @@ char *setv(Agnode_t *n, char *attr, char *val)
 
     if (!n || !attr || !val)
         return NULL;
-    g = n->graph->root;
+    g = agroot(agraphof(n));
     a = agfindattr(g->proto->n, attr);
     if (!a)
         a = agnodeattr(g, attr, emptystring);
@@ -250,8 +259,12 @@ char *getv(Agedge_t *e, char *attr)
 
     if (!e || !attr)
         return NULL;
-    g = e->tail->graph;
+    g = agraphof(agtail(e));
+#ifndef WITH_CGRAPH
     a = agfindattr(g->proto->e, attr);
+#else
+    a = agattr(g, AGEDGE, attr, NULL);
+#endif
     return myagxget(e, a);
 }
 char *setv(Agedge_t *e, Agsym_t *a, char *val)
@@ -268,10 +281,16 @@ char *setv(Agedge_t *e, char *attr, char *val)
 
     if (!e || !attr || !val)
         return NULL;
-    g = e->tail->graph->root;
+    g = agroot(agraphof(agtail(e)));
+#ifndef WITH_CGRAPH
     a = agfindattr(g->proto->e, attr);
     if (!a)
         a = agedgeattr(g, attr, emptystring);
+#else
+    a = agattr(g, AGEDGE, attr, NULL);
+    if (!a)
+        a = agattr(g, AGEDGE, attr, emptystring);
+#endif
     myagxset(e, a, val);
     return val;
 }
@@ -280,21 +299,33 @@ Agraph_t *findsubg(Agraph_t *g, char *name)
 {
     if (!g || !name)
         return NULL;
+#ifndef WITH_CGRAPH
     return agfindsubg(g, name);
+#else
+    return agsubg(g, name, 0);
+#endif
 }
 
 Agnode_t *findnode(Agraph_t *g, char *name)
 {
     if (!g || !name)
         return NULL;
+#ifndef WITH_CGRAPH
     return agfindnode(g, name);
+#else
+    return agnode(g, name, 0);
+#endif
 }
 
 Agedge_t *findedge(Agnode_t *t, Agnode_t *h)
 {
     if (!t || !h)
         return NULL;
-    return agfindedge(t->graph, t, h);
+#ifndef WITH_CGRAPH
+    return agfindedge(agraphof(t), t, h);
+#else
+    return agedge(agraphof(t), t, h, NULL, 0);
+#endif
 }
 
 Agsym_t *findattr(Agraph_t *g, char *name)
@@ -324,42 +355,42 @@ Agnode_t *headof(Agedge_t *e)
 {
     if (!e)
         return NULL;
-    return e->head;
+    return aghead(e);
 }
 
 Agnode_t *tailof(Agedge_t *e)
 {
     if (!e)
         return NULL;
-    return e->tail;
+    return agtail(e);
 }
 
 Agraph_t *graphof(Agraph_t *g)
 {
     if (!g || g == g->root)
         return NULL;
-    return g->root;
+    return agroot(g);
 }
 
 Agraph_t *graphof(Agedge_t *e)
 {
     if (!e)
         return NULL;
-    return e->tail->graph;
+    return agraphof(agtail(e));
 }
 
 Agraph_t *graphof(Agnode_t *n)
 {
     if (!n)
         return NULL;
-    return n->graph;
+    return agraphof(n);
 }
 
 Agraph_t *rootof(Agraph_t *g)
 {
     if (!g)
         return NULL;
-    return g->root;
+    return agroot(g);
 }
 
 //-------------------------------------------------
@@ -382,19 +413,19 @@ char *nameof(Agraph_t *g)
 {
     if (!g)
         return NULL;
-    return g->name;
+    return agnameof(g);
 }
 char *nameof(Agnode_t *n)
 {
     if (!n)
         return NULL;
-    return n->name;
+    return agnameof(n);
 }
 //char *nameof(Agedge_t *e)
 //{
 //    if (!e)
 //        return NULL;
-//    return e->name;
+//    return agnameof(e);
 //}
 char *nameof(Agsym_t *a)
 {
@@ -440,13 +471,13 @@ Agraph_t *firstsubg(Agraph_t *g)
     n = g->meta_node;
     if (!n) 
         return NULL;
-    mg = n->graph;
+    mg = agraphof(n);
     if (!mg) 
         return NULL;
     e = agfstout(mg, n);
     if (!e) 
         return NULL;
-    return agusergraph(e->head);
+    return agusergraph(aghead(e));
 }
 
 Agraph_t *nextsubg(Agraph_t *g, Agraph_t *sg)
@@ -461,16 +492,20 @@ Agraph_t *nextsubg(Agraph_t *g, Agraph_t *sg)
     nsg = sg->meta_node;
     if (!ng || !nsg) 
         return NULL;
-    mg = ng->graph;
+    mg = agraphof(ng);
     if (!mg) 
         return NULL;
+#ifndef WITH_CGRAPH
     e = agfindedge(mg, ng, nsg);
+#else
+    e = agedge(mg, ng, nsg, NULL, 0);
+#endif
     if (!e) 
         return NULL;
     e = agnxtout(mg, e);
     if (!e) 
         return NULL;
-    return agusergraph(e->head);
+    return agusergraph(aghead(e));
 }
 
 Agraph_t *firstsupg(Agraph_t *g)
@@ -484,13 +519,13 @@ Agraph_t *firstsupg(Agraph_t *g)
     n = g->meta_node;
     if (!n) 
         return NULL;
-    mg = n->graph;
+    mg = agraphof(n);
     if (!mg) 
         return NULL;
     e = agfstin(mg, n);
     if (!e) 
         return NULL;
-    return agusergraph(e->tail);
+    return agusergraph(agtail(e));
 }
 
 Agraph_t *nextsupg(Agraph_t *g, Agraph_t *sg)
@@ -505,16 +540,20 @@ Agraph_t *nextsupg(Agraph_t *g, Agraph_t *sg)
     nsg = sg->meta_node;
     if (!ng || !nsg) 
         return NULL;
-    mg = ng->graph;
+    mg = agraphog(ng);
     if (!mg) 
         return NULL;
+#ifndef WITH_CGRAPH
     e = agfindedge(mg, nsg, ng);
+#else
+    e = agedge(mg, nsg, ng, NULL, 0);
+#endif
     if (!e) 
         return NULL;
     e = agnxtin(mg, e);
     if (!e) 
         return NULL;
-    return agusergraph(e->tail);
+    return agusergraph(agtail(e));
 }
 
 Agedge_t *firstout(Agraph_t *g)
@@ -541,7 +580,7 @@ Agedge_t *nextout(Agraph_t *g, Agedge_t *e)
     ne = agnxtout(g, e);
     if (ne)
         return (ne);
-    for (n = agnxtnode(g, e->tail); n; n = agnxtnode(g, n)) {
+    for (n = agnxtnode(g, agtail(e)); n; n = agnxtnode(g, n)) {
        ne = agfstout(g, n);
        if (ne) return ne;
     }
@@ -562,14 +601,14 @@ Agedge_t *firstout(Agnode_t *n)
 {
     if (!n)
         return NULL;
-    return agfstout(n->graph, n);
+    return agfstout(agraphof(n), n);
 }
 
 Agedge_t *nextout(Agnode_t *n, Agedge_t *e)
 {
     if (!n || !e)
         return NULL;
-    return agnxtout(n->graph, e);
+    return agnxtout(agraphof(n), e);
 }
 
 Agnode_t *firsthead(Agnode_t *n)
@@ -578,41 +617,47 @@ Agnode_t *firsthead(Agnode_t *n)
 
     if (!n)
         return NULL;
-    e = agfstout(n->graph, n);
+    e = agfstout(agraphof(n), n);
     if (!e)
         return NULL;
-    return e->head;
+    return aghead(e);
 }
 
 Agnode_t *nexthead(Agnode_t *n, Agnode_t *h)
 {
     Agedge_t *e;
+    Agraph_t *g;
 
     if (!n || !h)
         return NULL;
-    e = agfindedge(n->graph, n, h);
+    g = agraphof(n);
+#ifndef WITH_CGRAPH
+    e = agfindedge(g, n, h);
+#else
+    e = agedge(g, n, h, NULL, 0);
+#endif
     if (!e)
         return NULL;
     do {
-        e = agnxtout(n->graph, e);
+        e = agnxtout(g, e);
         if (!e)
             return NULL;
-    } while (e->head == h);
-    return e->head;
+    } while (aghead(e) == h);
+    return aghead(e);
 }
 
 Agedge_t *firstedge(Agnode_t *n)
 {
     if (!n)
         return NULL;
-    return agfstedge(n->graph, n);
+    return agfstedge(agraphof(n), n);
 } 
 
 Agedge_t *nextedge(Agnode_t *n, Agedge_t *e)
 {
     if (!n || !e)
         return NULL;
-    return agnxtedge(n->graph, e, n); 
+    return agnxtedge(agraphof(n), e, n); 
 } 
 
 Agedge_t *firstin(Agraph_t *g)
@@ -637,7 +682,7 @@ Agedge_t *nextin(Agraph_t *g, Agedge_t *e)
     ne = agnxtin(g, e);
     if (ne)
         return (ne);
-    n = agnxtnode(g, e->head);
+    n = agnxtnode(g, aghead(e));
     if (!n)
         return NULL;
     return agfstin(g, n);
@@ -647,14 +692,14 @@ Agedge_t *firstin(Agnode_t *n)
 {
     if (!n)
         return NULL;
-    return agfstin(n->graph, n);
+    return agfstin(agraphof(n), n);
 }
 
 Agedge_t *nextin(Agnode_t *n, Agedge_t *e)
 {
     if (!n || !e)
         return NULL;
-    return agnxtin(n->graph, e);
+    return agnxtin(agraphof(n), e);
 }
 
 Agnode_t *firsttail(Agnode_t *n)
@@ -663,27 +708,32 @@ Agnode_t *firsttail(Agnode_t *n)
 
     if (!n)
         return NULL;
-    e = agfstin(n->graph, n);
+    e = agfstin(agraphof(n), n);
     if (!e)
         return NULL;
-    return e->tail;
+    return agtail(e);
 }
 
 Agnode_t *nexttail(Agnode_t *n, Agnode_t *t)
 {
     Agedge_t *e;
+    Agraph_t *g;
 
     if (!n || !t)
         return NULL;
-    e = agfindedge(n->graph, t, n);
+#ifndef WITH_CGRAPH
+    e = agfindedge(g, t, n);
+#else
+    e = agedge(g, t, n, NULL, 0);
+#endif
     if (!e)
         return NULL;
     do {
-        e = agnxtout(n->graph, e);
+        e = agnxtout(g, e);
         if (!e)
             return NULL;
-    } while (e->tail == t);
-    return e->tail;
+    } while (agtail(e) == t);
+    return agtail(e);
 }
 
 Agnode_t *firstnode(Agraph_t *g)
@@ -704,21 +754,21 @@ Agnode_t *firstnode(Agedge_t *e)
 {
     if (!e)
         return NULL;
-    return e->tail;
+    return agtail(e);
 }
 
 Agnode_t *nextnode(Agedge_t *e, Agnode_t *n)
 {
-    if (!e || n != e->tail)
+    if (!e || n != agtail(e))
         return NULL;
-    return e->head;
+    return aghead(e);
 }
 
 Agsym_t *firstattr(Agraph_t *g)
 {
     if (!g)
         return NULL;
-    g = g->root;
+    g = agroot(g);
     if (dtsize(g->univ->globattr->dict) == 0)
         return NULL;
     return g->univ->globattr->list[0];
@@ -730,7 +780,7 @@ Agsym_t *nextattr(Agraph_t *g, Agsym_t *a)
 
     if (!g || !a)
         return NULL;
-    g = g->root;
+    g = agroot(g);
     for (i = 0; i < dtsize(g->univ->globattr->dict); i++)
         if (a == g->univ->globattr->list[i])
             break;
@@ -746,7 +796,7 @@ Agsym_t *firstattr(Agnode_t *n)
 
     if (!n)
         return NULL;
-    g = n->graph;
+    g = agraphof(n);
     if (dtsize(g->univ->nodeattr->dict) == 0)
         return NULL;
     return g->univ->nodeattr->list[0];
@@ -759,7 +809,7 @@ Agsym_t *nextattr(Agnode_t *n, Agsym_t *a)
 
     if (!n || !a)
         return NULL;
-    g = n->graph;
+    g = agraphof(n);
     for (i = 0; i < dtsize(g->univ->nodeattr->dict); i++)
         if (a == g->univ->nodeattr->list[i])
             break;
@@ -775,7 +825,7 @@ Agsym_t *firstattr(Agedge_t *e)
 
     if (!e)
         return NULL;
-    g = e->tail->graph;
+    g = agraphof(agtail(e));
     if (dtsize(g->univ->edgeattr->dict) == 0)
         return NULL;
     return g->univ->edgeattr->list[0];
@@ -788,7 +838,7 @@ Agsym_t *nextattr(Agedge_t *e, Agsym_t *a)
 
     if (!e || !a)
         return NULL;
-    g = e->tail->graph;
+    g = agraphof(agtail(e));
     for (i = 0; i < dtsize(g->univ->edgeattr->dict); i++)
         if (a == g->univ->edgeattr->list[i])
             break;
@@ -807,9 +857,9 @@ bool rm(Agraph_t *g)
     if (g->meta_node) {
         for (e = agfstout(g->meta_node->graph, g->meta_node); e;
                        e = agnxtout(g->meta_node->graph, e)) {
-            rm(agusergraph(e->head));
+            rm(agusergraph(aghead(e)));
         }
-        if (g == g->root) {
+        if (g == agroot(g)) {
             agclose(g);
         } else {
             agdelete(g->meta_node->graph, g->meta_node);
@@ -825,9 +875,9 @@ bool rm(Agnode_t *n)
     if (!n)
         return false;
     // removal of the protonode is not permitted
-    if (n->name[0] == '\001' && strcmp (n->name, "\001proto") ==0)
+    if (agnameof(n)[0] == '\001' && strcmp (agnameof(n), "\001proto") ==0)
         return false;
-    agdelete(n->graph, n);
+    agdelete(agraphof(n), n);
     return true;
 }
 
@@ -836,10 +886,10 @@ bool rm(Agedge_t *e)
     if (!e)
         return false;
     // removal of the protoedge is not permitted
-    if ((e->head->name[0] == '\001' && strcmp (e->head->name, "\001proto") == 0)
-     || (e->tail->name[0] == '\001' && strcmp (e->tail->name, "\001proto") == 0))
+    if ((agnameof(aghead(e))[0] == '\001' && strcmp (agnameof(aghead(e)), "\001proto") == 0)
+     || (agnameof(agtail(e))[0] == '\001' && strcmp (agnameof(agtail(e)), "\001proto") == 0))
         return false;
-    agdelete(e->head->graph->root, e);
+    agdelete(agroot(agraphof(aghead(e))), e);
     return true;
 }