From b5556f03cf953feefd85fbabc1c33a97b9f7e65b Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 9 Jan 2022 16:32:23 -0800 Subject: [PATCH] mapBool: use C99 bools for boolean parameters Note that this required a somewhat awkward work around in `getAdjustMode` that was abusing being able to fit something other than a boolean into the type used for booleans. --- lib/common/emit.c | 2 +- lib/common/utils.c | 17 +++++++++-------- lib/common/utils.h | 2 +- lib/dotgen/rank.c | 8 +++----- lib/neatogen/adjust.c | 10 ++++++---- lib/neatogen/neatoinit.c | 4 ++-- lib/sfdpgen/sfdpinit.c | 5 +++-- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/common/emit.c b/lib/common/emit.c index 78483bbca..60bb99718 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -2504,7 +2504,7 @@ static void emit_begin_edge(GVJ_t * job, edge_t * e, char** styles) obj->type = EDGE_OBJTYPE; obj->u.e = e; obj->emit_state = EMIT_EDRAW; - if (ED_label(e) && !ED_label(e)->html && mapBool(agget(e,"labelaligned"),FALSE)) + if (ED_label(e) && !ED_label(e)->html && mapBool(agget(e,"labelaligned"), false)) obj->labeledgealigned = TRUE; /* We handle the edge style and penwidth here because the width diff --git a/lib/common/utils.c b/lib/common/utils.c index 0b6dd91f1..204c3ffe4 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -442,27 +442,27 @@ int maptoken(char *p, char **name, int *val) return val[i]; } -boolean mapBool(char *p, boolean dflt) +bool mapBool(char *p, bool dflt) { if (!p || (*p == '\0')) return dflt; if (!strcasecmp(p, "false")) - return FALSE; + return false; if (!strcasecmp(p, "no")) - return FALSE; + return false; if (!strcasecmp(p, "true")) - return TRUE; + return true; if (!strcasecmp(p, "yes")) - return TRUE; + return true; if (isdigit((int)*p)) - return atoi(p); + return atoi(p) != 0; else return dflt; } boolean mapbool(char *p) { - return mapBool (p, FALSE); + return mapBool(p, false) ? TRUE : FALSE; } pointf dotneato_closest(splines * spl, pointf pt) @@ -889,7 +889,8 @@ void compute_bb(graph_t * g) int is_a_cluster (Agraph_t* g) { - return ((g == g->root) || (!strncasecmp(agnameof(g), "cluster", 7)) || mapBool(agget(g,"cluster"),FALSE)); + return g == g->root || !strncasecmp(agnameof(g), "cluster", 7) || + mapBool(agget(g, "cluster"), false); } /* setAttr: diff --git a/lib/common/utils.h b/lib/common/utils.h index 01afc0f5a..a2298eff0 100644 --- a/lib/common/utils.h +++ b/lib/common/utils.h @@ -88,7 +88,7 @@ UTILS_API void UF_setname(Agnode_t *, Agnode_t *); UTILS_API char *Fgets(FILE *fp); UTILS_API const char *safefile(const char *filename); -UTILS_API boolean mapBool(char *, boolean); +UTILS_API bool mapBool(char *, bool); UTILS_API boolean mapbool(char *); UTILS_API int maptoken(char *, char **, int *); diff --git a/lib/dotgen/rank.c b/lib/dotgen/rank.c index de04ea606..4958425da 100644 --- a/lib/dotgen/rank.c +++ b/lib/dotgen/rank.c @@ -25,6 +25,7 @@ #include #include +#include static void dot1_rank(graph_t * g, aspect_t* asp); static void dot2_rank(graph_t * g, aspect_t* asp); @@ -606,13 +607,10 @@ static int is_empty(graph_t * g) return (!agfstnode(g)); } -static int is_a_strong_cluster(graph_t * g) +static bool is_a_strong_cluster(graph_t * g) { - int rv; char *str = agget(g, "compact"); - /* rv = mapBool((str), TRUE); */ - rv = mapBool((str), FALSE); - return rv; + return mapBool(str, false); } static int rankset_kind(graph_t * g) diff --git a/lib/neatogen/adjust.c b/lib/neatogen/adjust.c index 0af47f04a..3f172f1e3 100644 --- a/lib/neatogen/adjust.c +++ b/lib/neatogen/adjust.c @@ -762,7 +762,8 @@ fdpAdjust (graph_t* g, adjust_data* am) } remove_overlap(Ndim, A, pos, sizes, am->value, am->scaling, - ELSCHEME_NONE, 0, NULL, NULL, mapBool (agget(g, "overlap_shrink"), TRUE)); + ELSCHEME_NONE, 0, NULL, NULL, + mapBool(agget(g, "overlap_shrink"), true) ? TRUE : FALSE); for (n = agfstnode(g); n; n = agnxtnode(g, n)) { double *npos = pos + Ndim * ND_id(n); @@ -1007,10 +1008,11 @@ static adjust_data *getAdjustMode(Agraph_t* g, char *s, adjust_data* dp) ap++; } if (ap->attrib == NULL ) { - int v = mapBool(s,'?'); - if (v == '?') { + bool v = mapBool(s, false); + bool unmappable = v != mapBool(s, true); + if (unmappable) { agerr (AGWARN, "Unrecognized overlap value \"%s\" - using false\n", s); - v = FALSE; + v = false; } if (v) { dp->mode = adjustMode[0].mode; diff --git a/lib/neatogen/neatoinit.c b/lib/neatogen/neatoinit.c index 82cc8a90a..9401c60ef 100644 --- a/lib/neatogen/neatoinit.c +++ b/lib/neatogen/neatoinit.c @@ -531,7 +531,7 @@ int init_nop(Agraph_t * g, int adjust) attrsym_t *G_bb = agfindgraphattr(g, "bb"); int didAdjust = 0; /* Have nodes been moved? */ int haveBackground; - boolean translate = !mapBool(agget(g, "notranslate"), FALSE); + bool translate = !mapBool(agget(g, "notranslate"), false); /* If G_bb not defined, define it */ if (!G_bb) @@ -1426,7 +1426,7 @@ void neato_layout(Agraph_t * g) } else gv_postprocess(g, 0); } else { - boolean noTranslate = mapBool(agget(g, "notranslate"), FALSE); + bool noTranslate = mapBool(agget(g, "notranslate"), false); PSinputscale = get_inputscale (g); neato_init_graph(g); layoutMode = neatoMode(g); diff --git a/lib/sfdpgen/sfdpinit.c b/lib/sfdpgen/sfdpinit.c index d9284b9b2..ed8e43c40 100644 --- a/lib/sfdpgen/sfdpinit.c +++ b/lib/sfdpgen/sfdpinit.c @@ -22,6 +22,7 @@ #include #include #include +#include static void sfdp_init_edge(edge_t * e) { @@ -257,8 +258,8 @@ tuneControl (graph_t* g, spring_electrical_control ctrl) ctrl->smoothing = late_smooth(g, agfindgraphattr(g, "smoothing"), SMOOTHING_NONE); ctrl->tscheme = late_quadtree_scheme(g, agfindgraphattr(g, "quadtree"), QUAD_TREE_NORMAL); ctrl->method = METHOD_SPRING_ELECTRICAL; - ctrl->beautify_leaves = mapBool (agget(g, "beautify"), FALSE); - ctrl->do_shrinking = mapBool (agget(g, "overlap_shrink"), TRUE); + ctrl->beautify_leaves = mapBool(agget(g, "beautify"), false) ? TRUE : FALSE; + ctrl->do_shrinking = mapBool(agget(g, "overlap_shrink"), true) ? TRUE : FALSE; ctrl->rotation = late_double(g, agfindgraphattr(g, "rotation"), 0.0, -MAXDOUBLE); ctrl->edge_labeling_scheme = late_int(g, agfindgraphattr(g, "label_scheme"), 0, 0); if (ctrl->edge_labeling_scheme > 4) { -- 2.40.0