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);
}
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)
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",
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",
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;
#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);
}
}
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;
}
* 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:
* 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:
/* node or edge */
if (!g)
g = agroot(agraphof(obj));
+#ifndef USE_CGRAPH
obj = agrebind(g, obj);
+#endif
if (obj)
return agdelete(g, obj);
else