From 22bae87d929dccc827bb73b6b7f62ad490b0551e Mon Sep 17 00:00:00 2001 From: ellson Date: Wed, 15 Oct 2008 12:57:08 +0000 Subject: [PATCH] more cgraph merging --- lib/common/shapes.c | 55 +++++----- lib/common/splines.c | 168 +--------------------------- lib/common/utils.c | 253 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 247 insertions(+), 229 deletions(-) diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 57899e6c8..289ee95e0 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -206,7 +206,7 @@ static shape_desc Shapes[] = { /* first entry is default for no such shape */ static void unrecognized(node_t * n, char *p) { - agerr(AGWARN, "node %s, port %s unrecognized\n", n->name, p); + agerr(AGWARN, "node %s, port %s unrecognized\n", agnameof(n), p); } static double quant(double val, double q) @@ -770,7 +770,7 @@ static void poly_init(node_t * n) PAD(dimen); } /* quantization */ - if ((temp = GD_drawing(n->graph)->quantum) > 0.0) { + if ((temp = GD_drawing(agraphof(n))->quantum) > 0.0) { temp = POINTS(temp); dimen.x = quant(dimen.x, temp); dimen.y = quant(dimen.y, temp); @@ -784,30 +784,30 @@ static void poly_init(node_t * n) */ if (streq(ND_shape(n)->name, "custom")) { sfile = agget(n, "shapefile"); - imagesize = gvusershape_size(n->graph, sfile); + imagesize = gvusershape_size(agraphof(n), sfile); if ((imagesize.x == -1) && (imagesize.y == -1)) { agerr(AGWARN, "No or improper shapefile=\"%s\" for node \"%s\"\n", - (sfile ? sfile : ""), n->name); + (sfile ? sfile : ""), agnameof(n)); imagesize.x = imagesize.y = 0; } else { - GD_has_images(n->graph) = TRUE; + GD_has_images(agraphof(n)) = TRUE; imagesize.x += 2; /* some fixed padding */ imagesize.y += 2; } } } else if ((sfile = agget(n, "image")) && (*sfile != '\0')) { - imagesize = gvusershape_size(n->graph, sfile); + imagesize = gvusershape_size(agraphof(n), sfile); if ((imagesize.x == -1) && (imagesize.y == -1)) { agerr(AGWARN, "No or improper image=\"%s\" for node \"%s\"\n", - (sfile ? sfile : ""), n->name); + (sfile ? sfile : ""), agnameof(n)); imagesize.x = imagesize.y = 0; } else { - GD_has_images(n->graph) = TRUE; + GD_has_images(agraphof(n)) = TRUE; imagesize.x += 2; /* some fixed padding */ imagesize.y += 2; } @@ -868,7 +868,7 @@ static void poly_init(node_t * n) if ((width < bb.x) || (height < bb.y)) agerr(AGWARN, "node '%s', graph '%s' size too small for label\n", - n->name, n->graph->name); + agnameof(n), agraphof(n)->name); bb.x = width; bb.y = height; } @@ -1061,7 +1061,7 @@ static boolean poly_inside(inside_t * inside_context, pointf p) boxf *bp = inside_context->s.bp; node_t *n = inside_context->s.n; - P = ccwrotatepf(p, 90*GD_rankdir(n->graph)); + P = ccwrotatepf(p, 90*GD_rankdir(agraphof(n))); /* Quick test if port rectangle is target */ if (bp) { @@ -1075,7 +1075,7 @@ static boolean poly_inside(inside_t * inside_context, pointf p) sides = poly->sides; /* get point and node size adjusted for rankdir=LR */ - if (GD_flip(n->graph)) { + if (GD_flip(agraphof(n))) { ysize = ND_lw(n) + ND_rw(n); xsize = ND_ht(n); } else { @@ -1304,7 +1304,7 @@ compassPort(node_t* n, boxf* bp, port* pp, char* compass, int sides, inside_t* i defined = TRUE; } else { p.x = p.y = 0.; - if (GD_flip(n->graph)) { + if (GD_flip(agraphof(n))) { b.UR.x = ND_ht(n) / 2.; b.LL.x = -b.UR.x; b.UR.y = ND_lw(n); @@ -1411,12 +1411,12 @@ compassPort(node_t* n, boxf* bp, port* pp, char* compass, int sides, inside_t* i break; } } - p = cwrotatepf(p, 90*GD_rankdir(n->graph)); + p = cwrotatepf(p, 90*GD_rankdir(agraphof(n))); if (dyna) pp->side = side; - else pp->side = invflip_side(side, GD_rankdir(n->graph)); + else pp->side = invflip_side(side, GD_rankdir(agraphof(n))); pp->bp = bp; PF2P(p, pp->p); - pp->theta = invflip_angle(theta, GD_rankdir(n->graph)); + pp->theta = invflip_angle(theta, GD_rankdir(agraphof(n))); if ((p.x == 0) && (p.y == 0)) pp->order = MC_SCALE/2; else { @@ -1448,7 +1448,7 @@ static port poly_port(node_t * n, char *portname, char *compass) if (compassPort(n, bp, &rv, compass, sides, NULL)) { agerr(AGWARN, "node %s, port %s, unrecognized compass point '%s' - ignored\n", - n->name, portname, compass); + agnameof(n), portname, compass); } } else { @@ -1687,7 +1687,7 @@ point_inside(inside_t* inside_context, pointf p) pointf P; node_t *n = inside_context->s.n; - P = ccwrotatepf(p, 90*GD_rankdir(n->graph)); + P = ccwrotatepf(p, 90*GD_rankdir(agraphof(n))); if (n != lastn) { int outp; @@ -2111,7 +2111,7 @@ static void record_init(node_t * n) int sides = BOTTOM | RIGHT | TOP | LEFT; /* Always use rankdir to determine how records are laid out */ - flip = NOT(GD_realflip(n->graph)); + flip = NOT(GD_realflip(agraphof(n))); reclblp = ND_label(n)->text; len = strlen(reclblp); textbuf = N_NEW(len + 1, char); @@ -2128,9 +2128,8 @@ static void record_init(node_t * n) if (mapbool(late_string(n, N_fixed, "false"))) { if ((sz.x < info->size.x) || (sz.y < info->size.y)) { /* should check that the record really won't fit, e.g., there may be no text. - agerr(AGWARN, "node '%s' size may be too small\n", - n->name); - */ + agerr(AGWARN, "node '%s' size may be too small\n", agnameof(n)); +*/ } } else { sz.x = MAX(info->size.x, sz.x); @@ -2199,7 +2198,7 @@ static port record_port(node_t * n, char *portname, char *compass) if (compassPort(n, &subf->b, &rv, compass, subf->sides, NULL)) { agerr(AGWARN, "node %s, port %s, unrecognized compass point '%s' - ignored\n", - n->name, portname, compass); + agnameof(n), portname, compass); } } else if (compassPort(n, &f->b, &rv, portname, sides, NULL)) { @@ -2223,7 +2222,7 @@ record_inside(inside_t * inside_context, pointf p) boxf bbox; /* convert point to node coordinate system */ - p = ccwrotatepf(p, 90*GD_rankdir(n->graph)); + p = ccwrotatepf(p, 90*GD_rankdir(agraphof(n))); if (bp == NULL) { fld0 = (field_t *) ND_shape_info(n); @@ -2249,7 +2248,7 @@ static int record_path(node_t* n, port* prt, int side, boxf rv[], int *kptr) info = (field_t *) ND_shape_info(n); for (i = 0; i < info->n_flds; i++) { - if (!GD_flip(n->graph)) { + if (!GD_flip(agraphof(n))) { ls = info->fld[i]->b.LL.x; rs = info->fld[i]->b.UR.x; } else { @@ -2258,7 +2257,7 @@ static int record_path(node_t* n, port* prt, int side, boxf rv[], int *kptr) } if (BETWEEN(ls, p.x, rs)) { /* FIXME: I don't understand this code */ - if (GD_flip(n->graph)) { + if (GD_flip(agraphof(n))) { rv[0] = flip_rec_boxf(info->fld[i]->b, ND_coord(n)); } else { rv[0].LL.x = ND_coord(n).x + ls; @@ -2413,7 +2412,7 @@ static boolean epsf_inside(inside_t * inside_context, pointf p) double x2; node_t *n = inside_context->s.n; - P = ccwrotatepf(p, 90*GD_rankdir(n->graph)); + P = ccwrotatepf(p, 90*GD_rankdir(agraphof(n))); x2 = ND_ht(n) / 2; return ((P.y >= -x2) && (P.y <= x2) && (P.x >= -ND_lw(n)) && (P.x <= ND_rw(n))); } @@ -2481,7 +2480,7 @@ cvtPt (pointf p, int rankdir) static char* closestSide (node_t* n, node_t* other, port* oldport) { boxf b; - int rkd = GD_rankdir(n->graph->root); + int rkd = GD_rankdir(agraphof(n)->root); point p = {0, 0}; point pt = cvtPt (ND_coord(n), rkd); point opt = cvtPt (ND_coord(other), rkd); @@ -2494,7 +2493,7 @@ static char* closestSide (node_t* n, node_t* other, port* oldport) if (oldport->bp) { b = *oldport->bp; } else { - if (GD_flip(n->graph)) { + if (GD_flip(agraphof(n))) { b.UR.x = ND_ht(n) / 2; b.LL.x = -b.UR.x; b.UR.y = ND_lw(n); diff --git a/lib/common/splines.c b/lib/common/splines.c index b204c0bda..979e81e83 100644 --- a/lib/common/splines.c +++ b/lib/common/splines.c @@ -24,21 +24,11 @@ #ifdef DEBUG static int debugleveln(edge_t* e, int i) { -#ifndef WITH_CGRAPH - return (GD_showboxes(e->head->graph) == i || - GD_showboxes(e->tail->graph) == i || -#else /* WITH_CGRAPH */ - return (GD_showboxes(aghead(e)->graph) == i || - GD_showboxes(agtail(e)->graph) == i || -#endif /* WITH_CGRAPH */ + return (GD_showboxes(agraphof(aghead(e))) == i || + GD_showboxes(agraphof(agtail(e))) == i || ED_showboxes(e) == i || -#ifndef WITH_CGRAPH - ND_showboxes(e->head) == i || - ND_showboxes(e->tail) == i); -#else /* WITH_CGRAPH */ ND_showboxes(aghead(e)) == i || ND_showboxes(agtail(e)) == i); -#endif /* WITH_CGRAPH */ } static void showPoints(pointf ps[], int pn) @@ -83,11 +73,7 @@ arrow_clip(edge_t * fe, node_t * hn, arrow_flags(e, &sflag, &eflag); if (info->splineMerge(hn)) eflag = ARR_NONE; -#ifndef WITH_CGRAPH - if (info->splineMerge(fe->tail)) -#else /* WITH_CGRAPH */ if (info->splineMerge(agtail(fe))) -#endif /* WITH_CGRAPH */ sflag = ARR_NONE; if (j) { i = sflag; @@ -225,11 +211,6 @@ void shape_clip(node_t * n, pointf curve[4]) bezier *new_spline(edge_t * e, int sz) { bezier *rv; -#ifndef WITH_CGRAPH - -#else /* WITH_CGRAPH */ - splines* sp_test; -#endif /* WITH_CGRAPH */ while (ED_edge_type(e) != NORMAL) e = ED_to_orig(e); if (ED_spl(e) == NULL) @@ -261,33 +242,20 @@ clip_and_install(edge_t * fe, node_t * hn, pointf * ps, int pn, boxf *tbox, *hbox; inside_t inside_context; -#ifndef WITH_CGRAPH - tn = fe->tail; - g = tn->graph; -#else /* WITH_CGRAPH */ tn = agtail(fe); g = agraphof(tn); -#endif /* WITH_CGRAPH */ newspl = new_spline(fe, pn); for (orig = fe; ED_edge_type(orig) != NORMAL; orig = ED_to_orig(orig)); /* may be a reversed flat edge */ -#ifndef WITH_CGRAPH - if ((tn->u.rank == hn->u.rank) && (tn->u.order > hn->u.order)) { -#else /* WITH_CGRAPH */ if ((ND_rank(tn) == ND_rank(hn)) && (ND_order(tn) > ND_order(hn))) { -#endif /* WITH_CGRAPH */ node_t *tmp; tmp = hn; hn = tn; tn = tmp; } -#ifndef WITH_CGRAPH - if (tn == orig->tail) { -#else /* WITH_CGRAPH */ if (tn == agtail(orig)) { -#endif /* WITH_CGRAPH */ clipTail = ED_tail_port(orig).clip; clipHead = ED_head_port(orig).clip; tbox = ED_tail_port(orig).bp; @@ -361,30 +329,14 @@ conc_slope(node_t* n) s_in = s_out = 0.0; for (cnt_in = 0; (e = ND_in(n).list[cnt_in]); cnt_in++) -#ifndef WITH_CGRAPH - s_in += ND_coord(e->tail).x; -#else /* WITH_CGRAPH */ s_in += ND_coord(agtail(e)).x; -#endif /* WITH_CGRAPH */ for (cnt_out = 0; (e = ND_out(n).list[cnt_out]); cnt_out++) -#ifndef WITH_CGRAPH - s_out += ND_coord(e->head).x; -#else /* WITH_CGRAPH */ s_out += ND_coord(aghead(e)).x; -#endif /* WITH_CGRAPH */ p.x = ND_coord(n).x - (s_in / cnt_in); -#ifndef WITH_CGRAPH - p.y = ND_coord(n).y - ND_coord(ND_in(n).list[0]->tail).y; -#else /* WITH_CGRAPH */ p.y = ND_coord(n).y - ND_coord(agtail(ND_in(n).list[0])).y; -#endif /* WITH_CGRAPH */ m_in = atan2(p.y, p.x); p.x = (s_out / cnt_out) - ND_coord(n).x; -#ifndef WITH_CGRAPH - p.y = ND_coord(ND_out(n).list[0]->head).y - ND_coord(n).y; -#else /* WITH_CGRAPH */ p.y = ND_coord(aghead(ND_out(n).list[0])).y - ND_coord(n).y; -#endif /* WITH_CGRAPH */ m_out = atan2(p.y, p.x); return ((m_in + m_out) / 2.0); } @@ -434,18 +386,10 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) node_t *n; int (*pboxfn) (node_t*, port*, int, boxf*, int*); -#ifndef WITH_CGRAPH - n = e->tail; -#else /* WITH_CGRAPH */ n = agtail(e); -#endif /* WITH_CGRAPH */ if (ED_tail_port(e).dyna) -#ifndef WITH_CGRAPH - ED_tail_port(e) = resolvePort(e->tail, e->head, &ED_tail_port(e)); -#else ED_tail_port(e) = resolvePort(agtail(e), aghead(e), &ED_tail_port(e)); -#endif if (ND_shape(n)) pboxfn = ND_shape(n)->fns->pboxfn; else @@ -453,11 +397,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) P->start.p = add_pointf(ND_coord(n), ED_tail_port(e).p); if (merge) { /*P->start.theta = - M_PI / 2; */ -#ifndef WITH_CGRAPH - P->start.theta = conc_slope(e->tail); -#else /* WITH_CGRAPH */ P->start.theta = conc_slope(agtail(e)); -#endif /* WITH_CGRAPH */ P->start.constrained = TRUE; } else { if (ED_tail_port(e).constrained) { @@ -479,11 +419,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) /* b0.LL.y = ND_coord(n).y + ND_ht(n)/2; */ b0.LL.y = P->start.p.y; b0.UR.x = b.UR.x; -#ifndef WITH_CGRAPH - b0.UR.y = ND_coord(n).y + ND_ht(n)/2 + GD_ranksep(n->graph)/2; -#else /* WITH_CGRAPH */ b0.UR.y = ND_coord(n).y + ND_ht(n)/2 + GD_ranksep(agraphof(n))/2; -#endif /* WITH_CGRAPH */ b.UR.x = ND_coord(n).x - ND_lw(n) - (FUDGE-2); b.UR.y = b0.LL.y; b.LL.y = ND_coord(n).y - ND_ht(n)/2; @@ -496,11 +432,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) b0.LL.y = P->start.p.y; /* b0.LL.y = ND_coord(n).y + ND_ht(n)/2; */ b0.UR.x = b.UR.x+1; -#ifndef WITH_CGRAPH - b0.UR.y = ND_coord(n).y + ND_ht(n)/2 + GD_ranksep(n->graph)/2; -#else /* WITH_CGRAPH */ b0.UR.y = ND_coord(n).y + ND_ht(n)/2 + GD_ranksep(agraphof(n))/2; -#endif /* WITH_CGRAPH */ b.LL.x = ND_coord(n).x + ND_rw(n) + (FUDGE-2); b.UR.y = b0.LL.y; b.LL.y = ND_coord(n).y - ND_ht(n)/2; @@ -537,11 +469,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) P->start.p.x += 1; } for (orig = e; ED_edge_type(orig) != NORMAL; orig = ED_to_orig(orig)); -#ifndef WITH_CGRAPH - if (n == orig->tail) -#else /* WITH_CGRAPH */ if (n == agtail(orig)) -#endif /* WITH_CGRAPH */ ED_tail_port(orig).clip = FALSE; else ED_head_port(orig).clip = FALSE; @@ -560,11 +488,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) b0.UR.y = ND_coord(n).y - ND_ht(n)/2; b0.UR.x = b.UR.x+1; b0.LL.x = P->start.p.x; -#ifndef WITH_CGRAPH - b0.LL.y = b0.UR.y - GD_ranksep(n->graph)/2; -#else /* WITH_CGRAPH */ b0.LL.y = b0.UR.y - GD_ranksep(agraphof(n))/2; -#endif /* WITH_CGRAPH */ b.LL.x = ND_coord(n).x + ND_rw(n) + (FUDGE-2); b.LL.y = b0.UR.y; b.UR.y = ND_coord(n).y + ND_ht(n)/2; @@ -606,11 +530,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) endp->boxn = 1; } for (orig = e; ED_edge_type(orig) != NORMAL; orig = ED_to_orig(orig)); -#ifndef WITH_CGRAPH - if (n == orig->tail) -#else /* WITH_CGRAPH */ if (n == agtail(orig)) -#endif /* WITH_CGRAPH */ ED_tail_port(orig).clip = FALSE; else ED_head_port(orig).clip = FALSE; @@ -657,18 +577,10 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) node_t *n; int (*pboxfn) (node_t* n, port*, int, boxf*, int*); -#ifndef WITH_CGRAPH - n = e->head; -#else /* WITH_CGRAPH */ n = aghead(e); -#endif /* WITH_CGRAPH */ if (ED_head_port(e).dyna) -#ifndef WITH_CGRAPH - ED_head_port(e) = resolvePort(e->head, e->tail, &ED_head_port(e)); -#else /* WITH_CGRAPH */ ED_head_port(e) = resolvePort(aghead(e), agtail(e), &ED_head_port(e)); -#endif /* WITH_CGRAPH */ if (ND_shape(n)) pboxfn = ND_shape(n)->fns->pboxfn; else @@ -676,11 +588,7 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) P->end.p = add_pointf(ND_coord(n), ED_head_port(e).p); if (merge) { /*P->end.theta = M_PI / 2; */ -#ifndef WITH_CGRAPH - P->end.theta = conc_slope(e->head) + M_PI; -#else /* WITH_CGRAPH */ P->end.theta = conc_slope(aghead(e)) + M_PI; -#endif /* WITH_CGRAPH */ assert(P->end.theta < 2 * M_PI); P->end.constrained = TRUE; } else { @@ -708,11 +616,7 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) /* b0.UR.y = ND_coord(n).y - ND_ht(n)/2; */ b0.UR.y = P->end.p.y; b0.UR.x = b.UR.x; -#ifndef WITH_CGRAPH - b0.LL.y = ND_coord(n).y - ND_ht(n)/2 - GD_ranksep(n->graph)/2; -#else /* WITH_CGRAPH */ b0.LL.y = ND_coord(n).y - ND_ht(n)/2 - GD_ranksep(agraphof(n))/2; -#endif /* WITH_CGRAPH */ b.UR.x = ND_coord(n).x - ND_lw(n) - (FUDGE-2); b.LL.y = b0.UR.y; b.UR.y = ND_coord(n).y + ND_ht(n)/2; @@ -725,11 +629,7 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) b0.UR.y = P->end.p.y; /* b0.UR.y = ND_coord(n).y - ND_ht(n)/2; */ b0.UR.x = b.UR.x+1; -#ifndef WITH_CGRAPH - b0.LL.y = ND_coord(n).y - ND_ht(n)/2 - GD_ranksep(n->graph)/2; -#else /* WITH_CGRAPH */ b0.LL.y = ND_coord(n).y - ND_ht(n)/2 - GD_ranksep(agraphof(n))/2; -#endif /* WITH_CGRAPH */ b.LL.x = ND_coord(n).x + ND_rw(n) + (FUDGE-2); b.LL.y = b0.UR.y; b.UR.y = ND_coord(n).y + ND_ht(n)/2; @@ -759,11 +659,7 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) P->start.p.x -= 1; } for (orig = e; ED_edge_type(orig) != NORMAL; orig = ED_to_orig(orig)); -#ifndef WITH_CGRAPH - if (n == orig->head) -#else /* WITH_CGRAPH */ if (n == aghead(orig)) -#endif /* WITH_CGRAPH */ ED_head_port(orig).clip = FALSE; else ED_tail_port(orig).clip = FALSE; @@ -811,11 +707,7 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) b0.LL.x = b.LL.x-1; b0.UR.y = ND_coord(n).y - ND_ht(n)/2; b0.UR.x = P->end.p.x; -#ifndef WITH_CGRAPH - b0.LL.y = b0.UR.y - GD_ranksep(n->graph)/2; -#else /* WITH_CGRAPH */ b0.LL.y = b0.UR.y - GD_ranksep(agraphof(n))/2; -#endif /* WITH_CGRAPH */ b.UR.x = ND_coord(n).x - ND_lw(n) - 2; b.LL.y = b0.UR.y; b.UR.y = ND_coord(n).y + ND_ht(n)/2; @@ -832,11 +724,7 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) break; } for (orig = e; ED_edge_type(orig) != NORMAL; orig = ED_to_orig(orig)); -#ifndef WITH_CGRAPH - if (n == orig->head) -#else /* WITH_CGRAPH */ if (n == aghead(orig)) -#endif /* WITH_CGRAPH */ ED_head_port(orig).clip = FALSE; else ED_tail_port(orig).clip = FALSE; @@ -888,11 +776,7 @@ static void selfBottom (edge_t* edges[], int ind, int cnt, int pointn; e = edges[ind]; -#ifndef WITH_CGRAPH - n = e->tail; -#else n = agtail(e); -#endif stepx = (sizex / 2.) / cnt; stepx = MAX(stepx,2.); @@ -921,11 +805,7 @@ static void selfBottom (edge_t* edges[], int ind, int cnt, points[pointn++] = pointfof(hp.x - dx, hp.y - hy / 3); points[pointn++] = hp; if (ED_label(e)) { -#ifndef WITH_CGRAPH - if (GD_flip(e->tail->graph)) { -#else if (GD_flip(agraphof(agtail(e)))) { -#endif width = ED_label(e)->dimen.y; height = ED_label(e)->dimen.x; } else { @@ -940,11 +820,7 @@ static void selfBottom (edge_t* edges[], int ind, int cnt, if (dx + stepx < width) dx += width - stepx; } -#ifndef WITH_CGRAPH - clip_and_install(e, e->head, points, pointn, sinfo); -#else clip_and_install(e, aghead(e), points, pointn, sinfo); -#endif #ifdef DEBUG if (debugleveln(e,1)) showPoints (points, pointn); @@ -966,11 +842,7 @@ selfTop (edge_t* edges[], int ind, int cnt, double sizex, double stepy, int pointn; e = edges[ind]; -#ifndef WITH_CGRAPH - n = e->tail; -#else n = agtail(e); -#endif stepx = (sizex / 2.) / cnt; stepx = MAX(stepx, 2.); @@ -999,11 +871,7 @@ selfTop (edge_t* edges[], int ind, int cnt, double sizex, double stepy, points[pointn++] = pointfof(hp.x - dx, hp.y + hy / 3); points[pointn++] = hp; if (ED_label(e)) { -#ifndef WITH_CGRAPH - if (GD_flip(e->tail->graph)) { -#else if (GD_flip(agraphof(agtail(e)))) { -#endif width = ED_label(e)->dimen.y; height = ED_label(e)->dimen.x; } else { @@ -1018,11 +886,7 @@ selfTop (edge_t* edges[], int ind, int cnt, double sizex, double stepy, if (dx + stepx < width) dx += width - stepx; } -#ifndef WITH_CGRAPH - clip_and_install(e, e->head, points, pointn, sinfo); -#else clip_and_install(e, aghead(e), points, pointn, sinfo); -#endif #ifdef DEBUG if (debugleveln(e,1)) showPoints (points, pointn); @@ -1044,11 +908,7 @@ selfRight (edge_t* edges[], int ind, int cnt, double stepx, double sizey, int pointn; e = edges[ind]; -#ifndef WITH_CGRAPH - n = e->tail; -#else n = agtail(e); -#endif stepy = (sizey / 2.) / cnt; stepy = MAX(stepy, 2.); @@ -1077,11 +937,7 @@ selfRight (edge_t* edges[], int ind, int cnt, double stepx, double sizey, points[pointn++] = pointfof(hp.x + hx / 3, hp.y - dy); points[pointn++] = hp; if (ED_label(e)) { -#ifndef WITH_CGRAPH - if (GD_flip(e->tail->graph)) { -#else if (GD_flip(agraphof(agtail(e)))) { -#endif width = ED_label(e)->dimen.y; height = ED_label(e)->dimen.x; } else { @@ -1096,11 +952,7 @@ selfRight (edge_t* edges[], int ind, int cnt, double stepx, double sizey, if (dy + stepy < height) dy += height - stepy; } -#ifndef WITH_CGRAPH - clip_and_install(e, e->head, points, pointn, sinfo); -#else clip_and_install(e, aghead(e), points, pointn, sinfo); -#endif #ifdef DEBUG if (debugleveln(e,1)) showPoints (points, pointn); @@ -1122,11 +974,7 @@ selfLeft (edge_t* edges[], int ind, int cnt, double stepx, double sizey, int pointn; e = edges[ind]; -#ifndef WITH_CGRAPH - n = e->tail; -#else /* WITH_CGRAPH */ n = agtail(e); -#endif /* WITH_CGRAPH */ stepy = (sizey / 2.) / cnt; stepy = MAX(stepy,2.); @@ -1155,11 +1003,7 @@ selfLeft (edge_t* edges[], int ind, int cnt, double stepx, double sizey, points[pointn++] = pointfof(hp.x - hx / 3, hp.y - dy); points[pointn++] = hp; if (ED_label(e)) { -#ifndef WITH_CGRAPH - if (GD_flip(e->tail->graph)) { -#else /* WITH_CGRAPH */ if (GD_flip(agraphof(agtail(e)))) { -#endif /* WITH_CGRAPH */ width = ED_label(e)->dimen.y; height = ED_label(e)->dimen.x; } else { @@ -1174,11 +1018,7 @@ selfLeft (edge_t* edges[], int ind, int cnt, double stepx, double sizey, if (dy + stepy < height) dy += height - stepy; } -#ifndef WITH_CGRAPH - clip_and_install(e, e->head, points, pointn, sinfo); -#else /* WITH_CGRAPH */ clip_and_install(e, aghead(e), points, pointn, sinfo); -#endif /* WITH_CGRAPH */ #ifdef DEBUG if (debugleveln(e,1)) showPoints (points, pointn); @@ -1208,11 +1048,7 @@ selfRightSpace (edge_t* e) (!(ED_tail_port(e).side & (TOP|BOTTOM)))))) { sw = SELF_EDGE_SIZE; if (l) { -#ifndef WITH_CGRAPH - label_width = GD_flip(e->head->graph) ? l->dimen.y : l->dimen.x; -#else /* WITH_CGRAPH */ label_width = GD_flip(agraphof(aghead(e))) ? l->dimen.y : l->dimen.x; -#endif /* WITH_CGRAPH */ sw += label_width; } } diff --git a/lib/common/utils.c b/lib/common/utils.c index ee6903ada..1523bf34f 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -64,14 +64,28 @@ node_t *dequeue(nodequeue * q) return n; } +#ifndef WITH_CGRAPH /* returns index of an attribute if bound, else -1 */ int late_attr(void *obj, char *name) +#else /* WITH_CGRAPH */ +/* returns index of an attribute if bound, else NULL */ +attrsym_t* late_attr(void *obj, char *name) +#endif /* WITH_CGRAPH */ { attrsym_t *a; +#ifndef WITH_CGRAPH if ((a = agfindattr(obj, name)) != 0) return a->index; +#else /* WITH_CGRAPH */ + if ((a = agget(obj, name)) != 0) + return a; +#endif /* WITH_CGRAPH */ else +#ifndef WITH_CGRAPH return -1; +#else /* WITH_CGRAPH */ + return NULL; +#endif /* WITH_CGRAPH */ } int late_int(void *obj, attrsym_t * attr, int def, int low) @@ -80,7 +94,11 @@ int late_int(void *obj, attrsym_t * attr, int def, int low) int rv; if (attr == NULL) return def; +#ifndef WITH_CGRAPH p = agxget(obj, attr->index); +#else /* WITH_CGRAPH */ + p = agxget(obj, attr); +#endif /* WITH_CGRAPH */ if (p[0] == '\0') return def; if ((rv = atoi(p)) < low) @@ -90,14 +108,30 @@ int late_int(void *obj, attrsym_t * attr, int def, int low) double late_double(void *obj, attrsym_t * attr, double def, double low) { +#ifndef WITH_CGRAPH char *p; +#else /* WITH_CGRAPH */ + char *p=NULL; +#endif /* WITH_CGRAPH */ double rv; if (attr == NULL) return def; +#ifndef WITH_CGRAPH p = agxget(obj, attr->index); +#else /* WITH_CGRAPH */ + if(!obj) + return def; + p = agxget(obj, attr); + if (!p) + return def; +#endif /* WITH_CGRAPH */ if (p[0] == '\0') return def; +#ifdef WITH_CGRAPH + if (!obj) + return def; +#endif /* WITH_CGRAPH */ if ((rv = atof(p)) < low) rv = low; return rv; @@ -105,15 +139,28 @@ double late_double(void *obj, attrsym_t * attr, double def, double low) char *late_string(void *obj, attrsym_t * attr, char *def) { +#ifndef WITH_CGRAPH if (attr == NULL) +#else /* WITH_CGRAPH */ + if ((attr == NULL) || (obj==NULL)) +#endif /* WITH_CGRAPH */ return def; +#ifndef WITH_CGRAPH return agxget(obj, attr->index); +#else /* WITH_CGRAPH */ + return agxget(obj, attr); +#endif /* WITH_CGRAPH */ } char *late_nnstring(void *obj, attrsym_t * attr, char *def) { char *rv = late_string(obj, attr, def); +#ifndef WITH_CGRAPH if (rv[0] == '\0') +#else /* WITH_CGRAPH */ + + if ((!rv)||(rv[0] == '\0')) +#endif /* WITH_CGRAPH */ rv = def; return rv; } @@ -122,15 +169,25 @@ boolean late_bool(void *obj, attrsym_t * attr, int def) { if (attr == NULL) return def; +#ifndef WITH_CGRAPH return mapbool(agxget(obj, attr->index)); +#else /* WITH_CGRAPH */ + + return mapbool(agxget(obj, attr)); +#endif /* WITH_CGRAPH */ } /* union-find */ node_t *UF_find(node_t * n) { while (ND_UF_parent(n) && (ND_UF_parent(n) != n)) { +#ifndef WITH_CGRAPH if (ND_UF_parent(n)->u.UF_parent) ND_UF_parent(n) = ND_UF_parent(n)->u.UF_parent; +#else /* WITH_CGRAPH */ + if (ND_UF_parent(ND_UF_parent(n))) + ND_UF_parent(n) = ND_UF_parent(ND_UF_parent(n)); +#endif /* WITH_CGRAPH */ n = ND_UF_parent(n); } return n; @@ -150,7 +207,11 @@ node_t *UF_union(node_t * u, node_t * v) ND_UF_size(v) = 1; } else v = UF_find(v); +#ifndef WITH_CGRAPH if (u->id > v->id) { +#else /* WITH_CGRAPH */ + if (ND_id(u) > ND_id(v)) { +#endif /* WITH_CGRAPH */ ND_UF_parent(u) = v; ND_UF_size(v) += ND_UF_size(u); } else { @@ -569,7 +630,11 @@ void common_init_node(node_t * n) late_double(n, N_height, DEFAULT_NODEHEIGHT, MIN_NODEHEIGHT); ND_shape(n) = bind_shape(late_nnstring(n, N_shape, DEFAULT_NODESHAPE), n); +#ifndef WITH_CGRAPH str = agxget(n, N_label->index); +#else + str = agxget(n, N_label); +#endif ND_label(n) = make_label((void*)n, str, ((aghtmlstr(str) ? LT_HTML : LT_NONE) | ( (shapeOf(n) == SH_RECORD) ? LT_RECD : LT_NONE)), late_double(n, N_fontsize, DEFAULT_FONTSIZE, MIN_FONTSIZE), @@ -613,7 +678,11 @@ noClip(edge_t *e, attrsym_t* sym) boolean rv = FALSE; if (sym) { /* mapbool isn't a good fit, because we want "" to mean true */ +#ifndef WITH_CGRAPH str = agxget(e,sym->index); +#else /* WITH_CGRAPH */ + str = agxget(e,sym); +#endif /* WITH_CGRAPH */ if (str && str[0]) rv = !mapbool(str); else rv = FALSE; } @@ -626,8 +695,14 @@ static port chkPort (port (*pf)(node_t*, char*, char*), node_t* n, char* s) { port pt; +#ifndef WITH_CGRAPH char* cp = strchr(s,':'); +#else /* WITH_CGRAPH */ + char* cp=NULL; + if(s) + cp= strchr(s,':'); +#endif /* WITH_CGRAPH */ if (cp) { *cp = '\0'; pt = pf(n, s, cp+1); @@ -647,11 +722,15 @@ int common_init_edge(edge_t * e) int r = 0; struct fontinfo fi; struct fontinfo lfi; - graph_t *sg = e->tail->graph; + graph_t *sg = agraphof(agtail(e)); fi.fontname = NULL; lfi.fontname = NULL; +#ifndef WITH_CGRAPH if (E_label && (str = agxget(e, E_label->index)) && (str[0])) { +#else + if (E_label && (str = agxget(e, E_label)) && (str[0])) { +#endif r = 1; initFontEdgeAttr(e, &fi); ED_label(e) = make_label((void*)e, str, (aghtmlstr(str) ? LT_HTML : LT_NONE), @@ -663,13 +742,21 @@ int common_init_edge(edge_t * e) /* vladimir */ +#ifndef WITH_CGRAPH if (E_headlabel && (str = agxget(e, E_headlabel->index)) && (str[0])) { +#else + if (E_headlabel && (str = agxget(e, E_headlabel)) && (str[0])) { +#endif initFontLabelEdgeAttr(e, &fi, &lfi); ED_head_label(e) = make_label((void*)e, str, (aghtmlstr(str) ? LT_HTML : LT_NONE), lfi.fontsize, lfi.fontname, lfi.fontcolor); GD_has_labels(sg) |= HEAD_LABEL; } +#ifndef WITH_CGRAPH if (E_taillabel && (str = agxget(e, E_taillabel->index)) && (str[0])) { +#else + if (E_taillabel && (str = agxget(e, E_taillabel)) && (str[0])) { +#endif if (!lfi.fontname) initFontLabelEdgeAttr(e, &fi, &lfi); ED_tail_label(e) = make_label((void*)e, str, (aghtmlstr(str) ? LT_HTML : LT_NONE), @@ -680,15 +767,15 @@ int common_init_edge(edge_t * e) /* We still accept ports beginning with colons but this is deprecated */ str = agget(e, TAIL_ID); - if (str[0]) - ND_has_port(e->tail) = TRUE; - ED_tail_port(e) = chkPort (ND_shape(e->tail)->fns->portfn,e->tail, str); + if (str && str[0]) + ND_has_port(agtail(e)) = TRUE; + ED_tail_port(e) = chkPort (ND_shape(agtail(e))->fns->portfn, agtail(e), str); if (noClip(e, E_tailclip)) ED_tail_port(e).clip = FALSE; str = agget(e, HEAD_ID); - if (str[0]) - ND_has_port(e->head) = TRUE; - ED_head_port(e) = chkPort(ND_shape(e->head)->fns->portfn,e->head, str); + if (str && str[0]) + ND_has_port(aghead(e)) = TRUE; + ED_head_port(e) = chkPort(ND_shape(aghead(e))->fns->portfn, aghead(e), str); if (noClip(e, E_headclip)) ED_head_port(e).clip = FALSE; @@ -771,7 +858,11 @@ void compute_bb(graph_t * g) if (ED_spl(e) == 0) continue; for (i = 0; i < ED_spl(e)->size; i++) { +#ifndef WITH_CGRAPH for (j = 0; j < ED_spl(e)->list[i].size; j++) { +#else + for (j = 0; j < (((Agedgeinfo_t*)AGDATA(e))->spl)->list[i].size; j++) { +#endif ptf = ED_spl(e)->list[i].list[j]; EXPANDBP(bb,ptf); } @@ -783,7 +874,7 @@ void compute_bb(graph_t * g) } for (i = 1; i <= GD_n_cluster(g); i++) { - B2BF(GD_clust(g)[i]->u.bb, BF); + B2BF(GD_bb(GD_clust(g)[i]), BF); EXPANDBB(bb,BF); } @@ -799,18 +890,35 @@ Agsym_t *setAttr(graph_t * g, void *obj, char *name, char *value, { if (ap == NULL) { switch (agobjkind(obj)) { +#ifndef WITH_CGRAPH case AGGRAPH: ap = agraphattr(g, name, ""); +#else /* WITH_CGRAPH */ + case AGRAPH: + ap = agattr(g, AGRAPH,name, "",1); +#endif /* WITH_CGRAPH */ break; case AGNODE: +#ifndef WITH_CGRAPH ap = agnodeattr(g, name, ""); +#else /* WITH_CGRAPH */ + ap = agattr(g,AGNODE, name, "",1); +#endif /* WITH_CGRAPH */ break; case AGEDGE: +#ifndef WITH_CGRAPH ap = agedgeattr(g, name, ""); +#else /* WITH_CGRAPH */ + ap = agattr(g,AGEDGE, name, "",1); +#endif /* WITH_CGRAPH */ break; } } +#ifndef WITH_CGRAPH agxset(obj, ap->index, value); +#else /* WITH_CGRAPH */ + agxset(obj, ap, value); +#endif /* WITH_CGRAPH */ return ap; } @@ -831,17 +939,30 @@ static node_t *clustNode(node_t * n, graph_t * cg, agxbuf * xb, sprintf(num, "%d", idx++); agxbput(xb, num); agxbputc(xb, ':'); - agxbput(xb, cg->name); + agxbput(xb, agnameof(cg)); + +#ifndef WITH_CGRAPH + cn = agnode(agroot(cg), agxbuse(xb)); +#else + cn = agnode(agroot(cg), agxbuse(xb), 1); + agbindrec(cn, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); //node custom data +#endif /* WITH_CGRAPH */ - cn = agnode(cg->root, agxbuse(xb)); SET_CLUST_NODE(cn); +#ifndef WITH_CGRAPH aginsert(cg, cn); aginsert(clg, n); +#else /* WITH_CGRAPH */ + agsubnode(cg,cn,1); + //aginsert(cg, cn); + agsubnode(clg,n,1); + //aginsert(clg, n); +#endif /* WITH_CGRAPH */ /* set attributes */ - N_label = setAttr(cn->graph, cn, "label", "", N_label); - N_style = setAttr(cn->graph, cn, "style", "invis", N_style); - N_shape = setAttr(cn->graph, cn, "shape", "box", N_shape); + N_label = setAttr(agraphof(cn), cn, "label", "", N_label); + N_style = setAttr(agraphof(cn), cn, "style", "invis", N_style); + N_shape = setAttr(agraphof(cn), cn, "shape", "box", N_shape); /* N_width = setAttr (cn->graph, cn, "width", "0.0001", N_width); */ return cn; @@ -910,8 +1031,12 @@ static Dtdisc_t mapDisc = { */ static edge_t *cloneEdge(edge_t * e, node_t * ct, node_t * ch) { - graph_t *g = ct->graph; + graph_t *g = agraphof(ct); +#ifndef WITH_CGRAPH edge_t *ce = agedge(g, ct, ch); +#else /* WITH_CGRAPH */ + edge_t *ce = agedge(g, ct, ch,NULL,1); +#endif /* WITH_CGRAPH */ agcopyattr(e, ce); return ce; @@ -925,14 +1050,14 @@ static void insertEdge(Dt_t * map, void *t, void *h, edge_t * e) dummy.p[0] = t; dummy.p[1] = h; - dummy.t = e->tail; - dummy.h = e->head; + dummy.t = agtail(e); + dummy.h = aghead(e); dtinsert(map, &dummy); dummy.p[0] = h; dummy.p[1] = t; - dummy.t = e->head; - dummy.h = e->tail; + dummy.t = aghead(e); + dummy.h = agtail(e); dtinsert(map, &dummy); } @@ -944,8 +1069,8 @@ static item *mapEdge(Dt_t * map, edge_t * e) { void *key[2]; - key[0] = e->tail; - key[1] = e->head; + key[0] = agtail(e); + key[1] = aghead(e); return (item *) dtmatch(map, &key); } @@ -963,7 +1088,11 @@ static item *mapEdge(Dt_t * map, edge_t * e) * so we could use a simpler model in which we create a single cluster * node for each cluster used in a cluster edge. */ +#ifndef WITH_CGRAPH #define MAPC(n) (strncmp((n)->name,"cluster",7)?NULL:agfindsubg((n)->graph, (n)->name)) +#else /* WITH_CGRAPH */ +#define MAPC(n) (strncmp(agnameof(n),"cluster",7)?NULL:agsubg(agraphof(n), agnameof(n),0)) +#endif /* WITH_CGRAPH */ static void checkCompound(edge_t * e, graph_t * clg, agxbuf * xb, Dt_t * map) @@ -972,8 +1101,8 @@ checkCompound(edge_t * e, graph_t * clg, agxbuf * xb, Dt_t * map) graph_t *hg; node_t *cn; node_t *cn1; - node_t *t = e->tail; - node_t *h = e->head; + node_t *t = agtail(e); + node_t *h = aghead(e); edge_t *ce; item *ip; @@ -983,8 +1112,8 @@ checkCompound(edge_t * e, graph_t * clg, agxbuf * xb, Dt_t * map) if (!tg && !hg) return; if (tg == hg) { - agerr(AGWARN, "cluster cycle %s -- %s not supported\n", t->name, - t->name); + agerr(AGWARN, "cluster cycle %s -- %s not supported\n", agnameof(t), + agnameof(t)); return; } ip = mapEdge(map, e); @@ -997,12 +1126,12 @@ checkCompound(edge_t * e, graph_t * clg, agxbuf * xb, Dt_t * map) if (tg) { if (agcontains(hg, tg)) { agerr(AGWARN, "tail cluster %s inside head cluster %s\n", - tg->name, hg->name); + agnameof(tg), agnameof(hg)); return; } if (agcontains(tg, hg)) { agerr(AGWARN, "head cluster %s inside tail cluster %s\n", - hg->name, tg->name); + agnameof(hg),agnameof(tg)); return; } cn = clustNode(t, tg, xb, clg); @@ -1012,7 +1141,7 @@ checkCompound(edge_t * e, graph_t * clg, agxbuf * xb, Dt_t * map) } else { if (agcontains(hg, t)) { agerr(AGWARN, "tail node %s inside head cluster %s\n", - t->name, hg->name); + agnameof(t), agnameof(hg)); return; } cn = clustNode(h, hg, xb, clg); @@ -1021,8 +1150,8 @@ checkCompound(edge_t * e, graph_t * clg, agxbuf * xb, Dt_t * map) } } else { if (agcontains(tg, h)) { - agerr(AGWARN, "head node %s inside tail cluster %s\n", h->name, - tg->name); + agerr(AGWARN, "head node %s inside tail cluster %s\n", agnameof(h), + agnameof(tg)); return; } cn = clustNode(t, tg, xb, clg); @@ -1049,7 +1178,12 @@ int processClusterEdges(graph_t * g) unsigned char buf[SMALLBUF]; map = dtopen(&mapDisc, Dtoset); +#ifndef WITH_CGRAPH clg = agsubg(g, "__clusternodes"); +#else /* WITH_CGRAPH */ + clg = agsubg(g, "__clusternodes",1); + agbindrec(clg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); //node custom data +#endif /* WITH_CGRAPH */ agxbinit(&xb, SMALLBUF, buf); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { if (IS_CLUST_NODE(n)) continue; @@ -1080,41 +1214,64 @@ int processClusterEdges(graph_t * g) */ static node_t *mapN(node_t * n, graph_t * clg) { +#ifndef WITH_CGRAPH extern Agdict_t *agdictof(void *); +#endif /* WITH_CGRAPH */ node_t *nn; char *name; - graph_t *g = n->graph; + graph_t *g = agraphof(n); +#ifndef WITH_CGRAPH Agdict_t *d; +#endif /* WITH_CGRAPH */ Agsym_t **list; Agsym_t *sym; if (!(IS_CLUST_NODE(n))) return n; +#ifndef WITH_CGRAPH aginsert(clg, n); - - name = strchr(n->name, ':'); +#else /* WITH_CGRAPH */ + agsubnode(clg, n,1); +#endif /* WITH_CGRAPH */ + name = strchr(agnameof(n), ':'); assert(name); name++; +#ifndef WITH_CGRAPH if ((nn = agfindnode(g, name))) +#else /* WITH_CGRAPH */ + if ((nn = agnode(g, name,0))) +#endif /* WITH_CGRAPH */ return nn; +#ifndef WITH_CGRAPH nn = agnode(g, name); +#else /* WITH_CGRAPH */ + nn = agnode(g, name,1); + agbindrec(nn, "Agnodeinfo_t", sizeof(Agnodeinfo_t), TRUE); //node custom data +#endif /* WITH_CGRAPH */ /* Set all attributes to default */ +#ifndef WITH_CGRAPH d = agdictof(n); list = d->list; while ((sym = *list++)) { /* Can use pointer comparison because of ref strings. */ if (agxget(nn, sym->index) != sym->value) agxset(nn, sym->index, sym->value); +#else /* WITH_CGRAPH */ + sym=0; + while (sym = agnxtattr(g, AGNODE, sym)) + { + if (agxget(nn, sym) != sym->defval) + agxset(nn, sym, sym->defval); +#endif /* WITH_CGRAPH */ } - return nn; } static void undoCompound(edge_t * e, graph_t * clg) { - node_t *t = e->tail; - node_t *h = e->head; + node_t *t = agtail(e); + node_t *h = aghead(e); node_t *ntail; node_t *nhead; @@ -1136,7 +1293,12 @@ void undoClusterEdges(graph_t * g) edge_t *e; graph_t *clg; +#ifndef WITH_CGRAPH clg = agsubg(g, "__clusternodes"); +#else /* WITH_CGRAPH */ + clg = agsubg(g, "__clusternodes",1); + agbindrec(clg, "Agraphinfo_t", sizeof(Agraphinfo_t), TRUE); //node custom data +#endif /* WITH_CGRAPH */ for (n = agfstnode(g); n; n = agnxtnode(g, n)) { for (e = agfstout(g, n); e; e = agnxtout(g, e)) { undoCompound(e, clg); @@ -1153,13 +1315,24 @@ void undoClusterEdges(graph_t * g) * with given name. If one does not exist, create it with the * supplied function fun with default value def. */ +#ifndef WITH_CGRAPH attrsym_t* safe_dcl(graph_t * g, void *obj, char *name, char *def, attrsym_t * (*fun) (Agraph_t *, char *, char *)) +#else /* WITH_CGRAPH */ +attrsym_t* +safe_dcl(graph_t * g, int obj_kind, char *name, char *def) +#endif /* WITH_CGRAPH */ { +#ifndef WITH_CGRAPH attrsym_t *a = agfindattr(obj, name); if (a == NULL) a = fun(g, name, def); +#else /* WITH_CGRAPH */ + attrsym_t *a = agattr(g,obj_kind,name,(char*)0); + if (!a) /*attribute exists*/ + a=agattr(g,obj_kind,name,def); +#endif /* WITH_CGRAPH */ return a; } @@ -1646,7 +1819,12 @@ void gv_cleanup_edge(edge_t * e) { gv_free_splines(e); free_label(ED_label(e)); +#ifndef WITH_CGRAPH memset(&(e->u), 0, sizeof(Agedgeinfo_t)); +#else /* WITH_CGRAPH */ + /*FIX HERE , shallow cleaning may not be enough here */ + agdelrec(agraphof(e), e, "Agedgeinfo_t"); +#endif /* WITH_CGRAPH */ } void gv_cleanup_node(node_t * n) @@ -1655,7 +1833,12 @@ void gv_cleanup_node(node_t * n) if (ND_shape(n)) ND_shape(n)->fns->freefn(n); free_label(ND_label(n)); +#ifndef WITH_CGRAPH memset(&(n->u), 0, sizeof(Agnodeinfo_t)); +#else /* WITH_CGRAPH */ + /*FIX HERE , shallow cleaning may not be enough here */ + agdelrec(agraphof(n), n, "Agnodeinfo_t"); +#endif /* WITH_CGRAPH */ } void gv_nodesize(node_t * n, boolean flip) -- 2.40.0