From 014de23502e62d509ebd62278950cecd4c30bb68 Mon Sep 17 00:00:00 2001 From: ellson Date: Tue, 21 Oct 2008 21:42:04 +0000 Subject: [PATCH] fdpgen ==> cgraph --- lib/fdpgen/comp.c | 34 +++++++++++++++++++++++++++++----- lib/fdpgen/fdpinit.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/lib/fdpgen/comp.c b/lib/fdpgen/comp.c index fadf5fe1c..b100bc667 100644 --- a/lib/fdpgen/comp.c +++ b/lib/fdpgen/comp.c @@ -39,10 +39,14 @@ static void dfs(Agraph_t * g, Agnode_t * n, Agraph_t * out, char *marks) Agnode_t *other; MARK(n) = 1; +#ifndef WITH_CGRAPH aginsert(out, n); +#else /* WITH_CGRAPH */ + agsubnode(out,n,1); +#endif /* WITH_CGRAPH */ for (e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) { - if ((other = e->tail) == n) - other = e->head; + if ((other = agtail(e)) == n) + other = aghead(e); if (!MARK(other)) dfs(g, other, out, marks); } @@ -81,8 +85,13 @@ graph_t **findCComp(graph_t * g, int *cnt, int *pinned) /* Create component based on port nodes */ subg = 0; if ((pp = PORTS(g))) { - sprintf(name, "cc%s_%d", g->name, c_cnt++ + C_cnt); + sprintf(name, "cc%s_%d", agnameof(g), c_cnt++ + C_cnt); +#ifndef WITH_CGRAPH subg = agsubg(g, name); +#else /* WITH_CGRAPH */ + subg = agsubg(g, name,1); + agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); //node custom data +#endif /* WITH_CGRAPH */ GD_alg(subg) = (void *) NEW(gdata); PORTS(subg) = pp; NPORTS(subg) = NPORTS(g); @@ -101,8 +110,13 @@ graph_t **findCComp(graph_t * g, int *cnt, int *pinned) if (ND_pinned(n) != P_PIN) continue; if (!subg) { - sprintf(name, "cc%s_%d", g->name, c_cnt++ + C_cnt); + sprintf(name, "cc%s_%d", agnameof(g), c_cnt++ + C_cnt); +#ifndef WITH_CGRAPH subg = agsubg(g, name); +#else /* WITH_CGRAPH */ + subg = agsubg(g, name,1); + agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); //node custom data +#endif /* WITH_CGRAPH */ GD_alg(subg) = (void *) NEW(gdata); } pinflag = 1; @@ -115,8 +129,13 @@ graph_t **findCComp(graph_t * g, int *cnt, int *pinned) for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (MARK(n)) continue; - sprintf(name, "cc%s+%d", g->name, c_cnt++ + C_cnt); + sprintf(name, "cc%s+%d", agnameof(g), c_cnt++ + C_cnt); +#ifndef WITH_CGRAPH subg = agsubg(g, name); +#else /* WITH_CGRAPH */ + subg = agsubg(g, name,1); + agbindrec(subg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); //node custom data +#endif /* WITH_CGRAPH */ GD_alg(subg) = (void *) NEW(gdata); dfs(g, n, subg, marks); nodeInduce(subg); @@ -130,10 +149,15 @@ graph_t **findCComp(graph_t * g, int *cnt, int *pinned) *pinned = pinflag; /* freed in layout */ comps = cp = N_NEW(c_cnt + 1, graph_t *); +#ifndef WITH_CGRAPH mg = g->meta_node->graph; for (me = agfstout(mg, g->meta_node); me; me = agnxtout(mg, me)) { mn = me->head; *cp++ = agusergraph(mn); +#else /* WITH_CGRAPH */ + for (me = agfstsubg(g); me; me = agnxtsubg(me)) { + *cp++ = me; +#endif /* WITH_CGRAPH */ c_cnt--; } assert(c_cnt == 0); diff --git a/lib/fdpgen/fdpinit.c b/lib/fdpgen/fdpinit.c index 92642c1d5..afb08cf7e 100644 --- a/lib/fdpgen/fdpinit.c +++ b/lib/fdpgen/fdpinit.c @@ -38,12 +38,24 @@ static void initialPositions(graph_t * g) char *p; char c; +#ifndef WITH_CGRAPH possym = agfindattr(g->proto->n, "pos"); +#else /* WITH_CGRAPH */ + possym = agattr(g,AGNODE, "pos",(char*)0); +#endif /* WITH_CGRAPH */ if (!possym) return; +#ifndef WITH_CGRAPH pinsym = agfindattr(g->proto->n, "pin"); +#else /* WITH_CGRAPH */ + pinsym = agattr(g,AGNODE, "pin",(char*)0); +#endif /* WITH_CGRAPH */ for (i = 0; (np = GD_neato_nlist(g)[i]); i++) { +#ifndef WITH_CGRAPH p = agxget(np, possym->index); +#else /* WITH_CGRAPH */ + p = agxget(np, possym); +#endif /* WITH_CGRAPH */ if (p[0]) { pvec = ND_pos(np); c = '\0'; @@ -55,12 +67,16 @@ static void initialPositions(graph_t * g) } ND_pinned(np) = P_SET; if ((c == '!') +#ifndef WITH_CGRAPH || (pinsym && mapbool(agxget(np, pinsym->index)))) +#else /* WITH_CGRAPH */ + || (pinsym && mapbool(agxget(np, pinsym)))) +#endif /* WITH_CGRAPH */ ND_pinned(np) = P_PIN; } else fprintf(stderr, "Warning: node %s, position %s, expected two floats\n", - np->name, p); + agnameof(np), p); } } } @@ -69,6 +85,9 @@ static void initialPositions(graph_t * g) */ static void init_edge(edge_t * e, attrsym_t * E_len) { +#ifdef WITH_CGRAPH + agbindrec(e, "Agedgeinfo_t", sizeof(Agedgeinfo_t), TRUE); //node custom data +#endif /* WITH_CGRAPH */ ED_factor(e) = late_double(e, E_weight, 1.0, 0.0); ED_dist(e) = late_double(e, E_len, fdp_parms.K, 0.0); @@ -100,7 +119,11 @@ void fdp_init_node_edge(graph_t * g) ND_id(n) = i++; } +#ifndef WITH_CGRAPH E_len = agfindattr(g->proto->e, "len"); +#else /* WITH_CGRAPH */ + E_len = agattr(g,AGEDGE, "len",(char*)0); +#endif /* WITH_CGRAPH */ for (n = agfstnode(g); n; n = agnxtnode(g, n)) { for (e = agfstout(g, n); e; e = agnxtout(g, e)) { init_edge(e, E_len); @@ -112,15 +135,21 @@ void fdp_init_node_edge(graph_t * g) static void cleanup_subgs(graph_t * g) { +#ifndef WITH_CGRAPH graph_t *mg; edge_t *me; node_t *mn; +#endif /* WITH_CGRAPH */ graph_t *subg; +#ifndef WITH_CGRAPH mg = g->meta_node->graph; for (me = agfstout(mg, g->meta_node); me; me = agnxtout(mg, me)) { mn = me->head; subg = agusergraph(mn); +#else /* WITH_CGRAPH */ + for (subg = agfstsubg(g); subg; subg = agnxtsubg(subg)) { +#endif /* WITH_CGRAPH */ free_label(GD_label(subg)); if (GD_alg(subg)) { free(PORTS(subg)); @@ -135,7 +164,12 @@ static void fdp_cleanup_graph(graph_t * g) cleanup_subgs(g); free(GD_neato_nlist(g)); free(GD_alg(g)); +#ifndef WITH_CGRAPH if (g != g->root) memset(&(g->u), 0, sizeof(Agraphinfo_t)); +#else /* WITH_CGRAPH */ + if (g != agroot(g)) + agclean(g,AGRAPH , "Agraphinfo_t"); +#endif /* WITH_CGRAPH */ } void fdp_cleanup(graph_t * g) -- 2.40.0