From 18f83d21c880051a50f83c09a2720f3574dc6994 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 15 Jan 2022 09:51:44 -0800 Subject: [PATCH] API BREAK: use C99 bools for 'port' fields instead of booleans --- CHANGELOG.md | 2 ++ lib/common/shapes.c | 10 +++++----- lib/common/splines.c | 28 ++++++++++++++-------------- lib/common/types.h | 8 ++++---- lib/common/utils.c | 4 ++-- lib/dotgen/dotsplines.c | 10 +++++----- lib/dotgen/position.c | 4 ++-- lib/dotgen/sameport.c | 9 +++++---- 8 files changed, 39 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f90e2f3f..7de817f73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Graphviz-specific `boolean`s. Similarly the `ignoreSwap` and `isOrtho` members of this struct must now be C99 `bool`s instead of a Graphviz-specific `boolean`s. +- **Breaking**: The `defined`, `constrained`, `clip`, and `dyna` fields of the + `port` struct are now C99 `bool`s instead of Graphviz-specific `boolean`s. - **Breaking**: Graphviz headers no longer define the constant `MAXSHORT`. A drop-in replacement is `SHRT_MAX` in the C standard library’s limits.h. - **Breaking**: Graphviz headers no lnger define `NIL` macros. A drop-in diff --git a/lib/common/shapes.c b/lib/common/shapes.c index d09e6ccf2..9e37e9382 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -22,7 +22,7 @@ typedef struct { void (*vertex_gen) (pointf*, pointf*); } poly_desc_t; -static port Center = {.theta = -1, .clip = 1}; +static port Center = {.theta = -1, .clip = true}; #define ATTR_SET(a,n) ((a) && (*(agxget(n,a->index)) != '\0')) /* Default point size = 0.05 inches or 3.6 points */ @@ -2704,10 +2704,10 @@ compassPort(node_t * n, boxf * bp, port * pp, char *compass, int sides, angle -= 2 * M_PI; pp->order = (int) (MC_SCALE * angle / (2 * M_PI)); } - pp->constrained = constrain ? TRUE : FALSE; - pp->defined = defined ? TRUE : FALSE; - pp->clip = clip ? TRUE : FALSE; - pp->dyna = dyna ? TRUE : FALSE; + pp->constrained = constrain; + pp->defined = defined; + pp->clip = clip; + pp->dyna = dyna; return rv; } diff --git a/lib/common/splines.c b/lib/common/splines.c index 907c536c0..79df01a3a 100644 --- a/lib/common/splines.c +++ b/lib/common/splines.c @@ -406,13 +406,13 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, bool merge) if (merge) { /*P->start.theta = - M_PI / 2; */ P->start.theta = conc_slope(agtail(e)); - P->start.constrained = TRUE; + P->start.constrained = true; } else { if (ED_tail_port(e).constrained) { P->start.theta = ED_tail_port(e).theta; - P->start.constrained = TRUE; + P->start.constrained = true; } else - P->start.constrained = FALSE; + P->start.constrained = false; } P->nbox = 0; P->data = (void *) e; @@ -478,9 +478,9 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, bool merge) } for (orig = e; ED_edge_type(orig) != NORMAL; orig = ED_to_orig(orig)); if (n == agtail(orig)) - ED_tail_port(orig).clip = FALSE; + ED_tail_port(orig).clip = false; else - ED_head_port(orig).clip = FALSE; + ED_head_port(orig).clip = false; return; } if (et == FLATEDGE && (side = ED_tail_port(e).side)) { @@ -543,9 +543,9 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, bool merge) } for (orig = e; ED_edge_type(orig) != NORMAL; orig = ED_to_orig(orig)); if (n == agtail(orig)) - ED_tail_port(orig).clip = FALSE; + ED_tail_port(orig).clip = false; else - ED_head_port(orig).clip = FALSE; + ED_head_port(orig).clip = false; endp->sidemask = side; return; } @@ -602,13 +602,13 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, bool merge) /*P->end.theta = M_PI / 2; */ P->end.theta = conc_slope(aghead(e)) + M_PI; assert(P->end.theta < 2 * M_PI); - P->end.constrained = TRUE; + P->end.constrained = true; } else { if (ED_head_port(e).constrained) { P->end.theta = ED_head_port(e).theta; - P->end.constrained = TRUE; + P->end.constrained = true; } else - P->end.constrained = FALSE; + P->end.constrained = false; } endp->np = P->end.p; if (et == REGULAREDGE && ND_node_type(n) == NORMAL && (side = ED_head_port(e).side)) { @@ -672,9 +672,9 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, bool merge) } for (orig = e; ED_edge_type(orig) != NORMAL; orig = ED_to_orig(orig)); if (n == aghead(orig)) - ED_head_port(orig).clip = FALSE; + ED_head_port(orig).clip = false; else - ED_tail_port(orig).clip = FALSE; + ED_tail_port(orig).clip = false; endp->sidemask = side; return; } @@ -739,9 +739,9 @@ void endpath(path * P, edge_t * e, int et, pathend_t * endp, bool merge) } for (orig = e; ED_edge_type(orig) != NORMAL; orig = ED_to_orig(orig)); if (n == aghead(orig)) - ED_head_port(orig).clip = FALSE; + ED_head_port(orig).clip = false; else - ED_tail_port(orig).clip = FALSE; + ED_tail_port(orig).clip = false; endp->sidemask = side; return; } diff --git a/lib/common/types.h b/lib/common/types.h index f7166ed72..aaf389d43 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -64,10 +64,10 @@ extern "C" { boxf *bp; /* if not null, points to bbox of * rectangular area that is port target */ - boolean defined; /* if true, edge has port info at this end */ - boolean constrained; /* if true, constraints such as theta are set */ - boolean clip; /* if true, clip end to node/port shape */ - boolean dyna; /* if true, assign compass point dynamically */ + bool defined; /* if true, edge has port info at this end */ + bool constrained; /* if true, constraints such as theta are set */ + bool clip; /* if true, clip end to node/port shape */ + bool dyna; /* if true, assign compass point dynamically */ unsigned char order; /* for mincross */ unsigned char side; /* if port is on perimeter of node, this * contains the bitwise OR of the sides (TOP, diff --git a/lib/common/utils.c b/lib/common/utils.c index 05072e618..ead7b019d 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -742,7 +742,7 @@ int common_init_edge(edge_t * e) 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; + ED_tail_port(e).clip = false; str = agget(e, HEAD_ID); /* libgraph always defines tailport/headport; libcgraph doesn't */ if (!str) str = ""; @@ -750,7 +750,7 @@ int common_init_edge(edge_t * e) 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; + ED_head_port(e).clip = false; return r; } diff --git a/lib/dotgen/dotsplines.c b/lib/dotgen/dotsplines.c index 16c498bba..383bede8b 100644 --- a/lib/dotgen/dotsplines.c +++ b/lib/dotgen/dotsplines.c @@ -171,9 +171,9 @@ static splineInfo sinfo = {.swapEnds = swap_ends_p, int portcmp(port p0, port p1) { - if (p1.defined == FALSE) + if (!p1.defined) return p0.defined ? 1 : 0; - if (p0.defined == FALSE) + if (!p0.defined) return -1; if (p0.p.x < p1.p.x) return -1; @@ -1846,7 +1846,7 @@ make_regular_edge(graph_t* g, spline_info_t* sp, path * P, edge_t ** edges, int while (ED_to_virt(le)) le = ED_to_virt(le); aghead(&fwdedgea.out) = aghead(le); - ED_head_port(&fwdedgea.out).defined = FALSE; + ED_head_port(&fwdedgea.out).defined = false; ED_edge_type(&fwdedgea.out) = VIRTUAL; ED_head_port(&fwdedgea.out).p.x = ED_head_port(&fwdedgea.out).p.y = 0; ED_to_orig(&fwdedgea.out) = e; @@ -1904,7 +1904,7 @@ make_regular_edge(graph_t* g, spline_info_t* sp, path * P, edge_t ** edges, int ND_coord(hn).y + GD_rank(g)[ND_rank(hn)].ht2); if (b.LL.x < b.UR.x && b.LL.y < b.UR.y) hend.boxes[hend.boxn++] = b; - P->end.theta = M_PI / 2, P->end.constrained = TRUE; + P->end.theta = M_PI / 2, P->end.constrained = true; assert(boxes.size <= (size_t)INT_MAX && "integer overflow"); completeregularpath(P, segfirst, e, &tend, &hend, boxes.data, (int)boxes.size, 1); @@ -1948,7 +1948,7 @@ make_regular_edge(graph_t* g, spline_info_t* sp, path * P, edge_t ** edges, int ND_coord(tn).y - GD_rank(g)[ND_rank(tn)].ht1); if (b.LL.x < b.UR.x && b.LL.y < b.UR.y) tend.boxes[tend.boxn++] = b; - P->start.theta = -M_PI / 2, P->start.constrained = TRUE; + P->start.theta = -M_PI / 2, P->start.constrained = true; smode = FALSE; } boxes_append(&boxes, rank_box(sp, g, ND_rank(tn))); diff --git a/lib/dotgen/position.c b/lib/dotgen/position.c index e22976fd4..059f01978 100644 --- a/lib/dotgen/position.c +++ b/lib/dotgen/position.c @@ -1116,10 +1116,10 @@ int ports_eq(edge_t * e, edge_t * f) return ((ED_head_port(e).defined == ED_head_port(f).defined) && (((ED_head_port(e).p.x == ED_head_port(f).p.x) && (ED_head_port(e).p.y == ED_head_port(f).p.y)) - || (ED_head_port(e).defined == FALSE)) + || !ED_head_port(e).defined) && (((ED_tail_port(e).p.x == ED_tail_port(f).p.x) && (ED_tail_port(e).p.y == ED_tail_port(f).p.y)) - || (ED_tail_port(e).defined == FALSE)) + || !ED_tail_port(e).defined) ); } diff --git a/lib/dotgen/sameport.c b/lib/dotgen/sameport.c index 96784cbf6..9a0da0fc8 100644 --- a/lib/dotgen/sameport.c +++ b/lib/dotgen/sameport.c @@ -15,6 +15,7 @@ #include #include +#include #include #define MAXSAME 5 /* max no of same{head,tail} groups on a node */ @@ -165,10 +166,10 @@ static void sameport(node_t * u, elist * l) prt.bp = 0; prt.order = (MC_SCALE * (ND_lw(u) + prt.p.x)) / (ND_lw(u) + ND_rw(u)); - prt.constrained = FALSE; - prt.defined = TRUE; - prt.clip = FALSE; - prt.dyna = FALSE; + prt.constrained = false; + prt.defined = true; + prt.clip = false; + prt.dyna = false; prt.theta = 0; prt.side = 0; prt.name = NULL; -- 2.40.0