From 9f4cf7a1f49fa63380761c5072eb0839bd786a46 Mon Sep 17 00:00:00 2001 From: erg Date: Thu, 7 Dec 2006 22:49:36 +0000 Subject: [PATCH] Re-do some .h files to limit exposure of internal values, .h files, and dependencies on config.h; return to a simple, concrete boolean type --- lib/common/postproc.c | 4 +-- lib/common/render.h | 18 ++++++------ lib/common/shapes.c | 22 +++++++------- lib/common/splines.c | 16 +++++----- lib/common/types.h | 60 ++++++++++++++++++++------------------ lib/common/usershape.h | 4 ++- lib/common/utils.c | 66 +++++++++++++++++++++--------------------- lib/common/utils.h | 10 +++---- 8 files changed, 103 insertions(+), 97 deletions(-) diff --git a/lib/common/postproc.c b/lib/common/postproc.c index d3f392f01..a28c5ce3f 100644 --- a/lib/common/postproc.c +++ b/lib/common/postproc.c @@ -19,7 +19,7 @@ static int Rankdir; -static bool Flip; +static boolean Flip; static point Offset; static void place_flip_graph_label(graph_t * g); @@ -139,7 +139,7 @@ void translate_bb(graph_t * g, int rankdir) translate_bb(GD_clust(g)[c], rankdir); } -void dot_nodesize(node_t * n, bool flip) +void dot_nodesize(node_t * n, boolean flip) { double x, y; int ps; diff --git a/lib/common/render.h b/lib/common/render.h index 1615f87b9..5585fec7f 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -61,7 +61,7 @@ extern "C" { point offset; } epsf_t; - typedef void (*nodesizefn_t) (Agnode_t *, bool); + typedef void (*nodesizefn_t) (Agnode_t *, boolean); extern void add_box(path *, box); extern void arrow_flags(Agedge_t * e, int *sflag, int *eflag); @@ -72,11 +72,11 @@ extern "C" { extern int arrowEndClip(edge_t*, point*, int, int , bezier*, int eflag); extern int arrowStartClip(edge_t*, point* ps, int, int, bezier*, int sflag); extern void attach_attrs(Agraph_t *); - extern void beginpath(path *, Agedge_t *, int, pathend_t *, bool); + extern void beginpath(path *, Agedge_t *, int, pathend_t *, boolean); extern void bezier_clip(inside_t * inside_context, - bool(*insidefn) (inside_t * inside_context, + boolean(*insidefn) (inside_t * inside_context, pointf p), pointf * sp, - bool left_inside); + boolean left_inside); extern shape_desc *bind_shape(char *name, node_t *); extern void clip_and_install(edge_t *, edge_t *, point *, int, splineInfo *); @@ -84,7 +84,7 @@ extern "C" { extern char* charsetToStr (int c); extern point coord(node_t * n); extern void do_graph_label(graph_t * sg); - extern void graph_init(graph_t * g, bool use_rankdir); + extern void graph_init(graph_t * g, boolean use_rankdir); extern void graph_cleanup(graph_t * g); extern void dotneato_args_initialize(GVC_t * gvc, int, char **); extern void dotneato_usage(int); @@ -103,7 +103,7 @@ extern "C" { extern void emit_jobs_eof(GVC_t * gvc); extern void emit_map_rect(GVJ_t *job, point LL, point UR); extern void enqueue_neighbors(nodequeue *, Agnode_t *, int); - extern void endpath(path *, Agedge_t *, int, pathend_t *, bool); + extern void endpath(path *, Agedge_t *, int, pathend_t *, boolean); extern void epsf_init(node_t * n); extern void epsf_free(node_t * n); extern shape_desc *find_user_shape(char *); @@ -115,7 +115,7 @@ extern "C" { extern void global_def(char *, Agsym_t * (*fun) (Agraph_t *, char *, char *)); extern int gvRenderJobs (GVC_t * gvc, graph_t * g); - extern bool isPolygon(node_t *); + extern boolean isPolygon(node_t *); extern char *strdup_and_subst_obj(char *str, void *obj); extern char *xml_string(char *s); extern void makeSelfEdge(path *, edge_t **, int, int, int, int, @@ -126,7 +126,7 @@ extern "C" { extern void osize_label(textlabel_t *, int *, int *, int *, int *); extern char **parse_style(char *s); extern void place_graph_label(Agraph_t *); - extern void place_portlabel(edge_t * e, bool head_p); + extern void place_portlabel(edge_t * e, boolean head_p); extern char *ps_string(char *s, int); extern int rank(graph_t * g, int balance, int maxiter); extern void round_corners(GVJ_t*, char*, char*, pointf*, int, int); @@ -143,7 +143,7 @@ extern "C" { extern void translate_bb(Agraph_t *, int); extern void write_attributed_dot(graph_t *g, FILE *f); extern void write_canonical_dot(graph_t *g, FILE *f); - extern void write_plain(GVJ_t * job, graph_t * g, FILE * f, bool extend); + extern void write_plain(GVJ_t * job, graph_t * g, FILE * f, boolean extend); #if defined(_BLD_dot) && defined(_DLL) # define extern __EXPORT__ diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 89abdd830..3829a8b25 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -36,20 +36,20 @@ static shape_desc *point_desc; static void poly_init(node_t * n); static void poly_free(node_t * n); static port poly_port(node_t * n, char *portname, char *); -static bool poly_inside(inside_t * inside_context, pointf p); +static boolean poly_inside(inside_t * inside_context, pointf p); static int poly_path(node_t* n, port* p, int side, box rv[], int *kptr); static void poly_gencode(GVJ_t * job, node_t * n); static void record_init(node_t * n); static void record_free(node_t * n); static port record_port(node_t * n, char *portname, char *); -static bool record_inside(inside_t * inside_context, pointf p); +static boolean record_inside(inside_t * inside_context, pointf p); static int record_path(node_t* n, port* p, int side, box rv[], int *kptr); static void record_gencode(GVJ_t * job, node_t * n); static void point_init(node_t * n); -static bool epsf_inside(inside_t * inside_context, pointf p); +static boolean epsf_inside(inside_t * inside_context, pointf p); static void epsf_gencode(GVJ_t * job, node_t * n); /* polygon descriptions. "polygon" with 0 sides takes all user control */ @@ -459,7 +459,7 @@ shape_kind shapeOf(node_t * n) return SH_USER; } -bool isPolygon(node_t * n) +boolean isPolygon(node_t * n) { return (ND_shape(n) && (ND_shape(n)->fns->initfn == poly_init)); } @@ -768,7 +768,7 @@ static void poly_free(node_t * n) #define GET_PORT_BOX(n,e) ((n) == (e)->head ? ED_head_port(e).bp : ED_tail_port(e).bp) -static bool poly_inside(inside_t * inside_context, pointf p) +static boolean poly_inside(inside_t * inside_context, pointf p) { static node_t *lastn; /* last node argument */ static polygon_t *poly; @@ -1017,10 +1017,10 @@ compassPort(node_t* n, box* bp, port* pp, char* compass, int sides, inside_t* ic point p, ctr; int rv = 0; double theta = 0.0; - bool constrain = FALSE; + boolean constrain = FALSE; int side = 0; - bool clip = TRUE; - bool defined; + boolean clip = TRUE; + boolean defined; if (bp) { b = *bp; @@ -1193,7 +1193,7 @@ static void poly_gencode(GVJ_t * job, node_t * n) static point *A; static pointf *AF; static int A_size; - bool filled; + boolean filled; char *color, *name; if (obj->url || obj->explicit_tooltip) @@ -1782,7 +1782,7 @@ static port record_port(node_t * n, char *portname, char *compass) * Note that this does not handle Mrecords correctly. It assumes * everything is a rectangle. */ -static bool +static boolean record_inside(inside_t * inside_context, pointf p) { @@ -1973,7 +1973,7 @@ shape_desc *bind_shape(char *name, node_t * np) return rv; } -static bool epsf_inside(inside_t * inside_context, pointf p) +static boolean epsf_inside(inside_t * inside_context, pointf p) { pointf P; double x2; diff --git a/lib/common/splines.c b/lib/common/splines.c index def952d33..ea289b4b9 100644 --- a/lib/common/splines.c +++ b/lib/common/splines.c @@ -98,12 +98,12 @@ arrow_clip(edge_t * fe, edge_t * le, * The points p are in node coordinates. */ void bezier_clip(inside_t * inside_context, - bool(*inside) (inside_t * inside_context, pointf p), - pointf * sp, bool left_inside) + boolean(*inside) (inside_t * inside_context, pointf p), + pointf * sp, boolean left_inside) { pointf seg[4], best[4], pt, opt, *left, *right; double low, high, t, *idir, *odir; - bool found; + boolean found; int i; if (left_inside) { @@ -152,7 +152,7 @@ void bezier_clip(inside_t * inside_context, */ static void shape_clip0(inside_t * inside_context, node_t * n, point curve[4], - bool left_inside) + boolean left_inside) { int i, save_real_size; pointf c[4]; @@ -188,7 +188,7 @@ shape_clip0(inside_t * inside_context, node_t * n, point curve[4], void shape_clip(node_t * n, point curve[4]) { int save_real_size; - bool left_inside; + boolean left_inside; pointf c; inside_t inside_context; @@ -389,7 +389,7 @@ void add_box(path * P, box b) #define FUDGE 2 void -beginpath(path * P, edge_t * e, int et, pathend_t * endp, bool merge) +beginpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) { int side, mask; node_t *n; @@ -579,7 +579,7 @@ beginpath(path * P, edge_t * e, int et, pathend_t * endp, bool merge) } } -void endpath(path * P, edge_t * e, int et, pathend_t * endp, bool merge) +void endpath(path * P, edge_t * e, int et, pathend_t * endp, boolean merge) { int side, mask; node_t *n; @@ -1360,7 +1360,7 @@ makeSelfEdge(path * P, edge_t * edges[], int ind, int cnt, int sizex, } /* vladimir */ -void place_portlabel(edge_t * e, bool head_p) +void place_portlabel(edge_t * e, boolean head_p) /* place the {head,tail}label (depending on HEAD_P) of edge E */ /* N.B. Assume edges are normalized, so tail is at spl->list[0].list[0] * and head is at spl->list[spl->size-l].list[bez->size-1] diff --git a/lib/common/types.h b/lib/common/types.h index 788d8adc8..4ba0dda8d 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -21,13 +21,15 @@ #include #include -#include "cdt.h" +typedef unsigned char boolean; +#define NOT(v) (!(v)) +#define FALSE 0 +#define TRUE NOT(FALSE) + #include "geom.h" -#include "pathplan.h" -#include "color.h" #include "gvcext.h" +#include "pathgeom.h" #include "textpara.h" -#include "usershape.h" #ifdef __cplusplus extern "C" { @@ -60,9 +62,9 @@ extern "C" { box *bp; /* if not null, points to bbox of * rectangular area that is port target */ - 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 */ + 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 */ unsigned char order; /* for mincross */ unsigned char side; /* if port is on perimeter of node, this * contains the bitwise OR of the sides (TOP, @@ -71,8 +73,8 @@ extern "C" { } port; typedef struct { - bool(*swapEnds) (edge_t * e); /* Should head and tail be swapped? */ - bool(*splineMerge) (node_t * n); /* Is n a node in the middle of an edge? */ + boolean(*swapEnds) (edge_t * e); /* Should head and tail be swapped? */ + boolean(*splineMerge) (node_t * n); /* Is n a node in the middle of an edge? */ } splineInfo; typedef struct pathend_t { @@ -130,8 +132,8 @@ extern "C" { } txt; htmllabel_t *html; } u; - bool set; /* true if position is set */ - bool html; /* true if html label */ + boolean set; /* true if position is set */ + boolean html; /* true if html label */ } textlabel_t; typedef struct polygon_t { /* mutable shape information for a node */ @@ -169,7 +171,7 @@ extern "C" { void (*initfn) (node_t *); /* initializes shape from node u.shape_info structure */ void (*freefn) (node_t *); /* frees shape from node u.shape_info structure */ port(*portfn) (node_t *, char *, char *); /* finds aiming point and slope of port */ - bool(*insidefn) (inside_t * inside_context, pointf); /* clips incident gvc->e spline on shape of gvc->n */ + boolean(*insidefn) (inside_t * inside_context, pointf); /* clips incident gvc->e spline on shape of gvc->n */ int (*pboxfn)(node_t* n, port* p, int side, box rv[], int *kptr); /* finds box path to reach port */ void (*codefn) (GVJ_t * job, node_t * n); /* emits graphics code for node */ } shape_functions; @@ -181,10 +183,12 @@ extern "C" { char *name; /* as read from graph file */ shape_functions *fns; polygon_t *polygon; /* base polygon info */ - bool usershape; + boolean usershape; } shape_desc; #ifdef WITH_CODEGENS +#include + struct codegen_s { void (*reset) (void); void (*begin_job) (FILE * ofp, graph_t * g, char **lib, char *user, @@ -221,9 +225,9 @@ extern "C" { void (*beziercurve) (point * A, int n, int arrow_at_start, int arrow_at_end, int filled); void (*polyline) (point * A, int n); - bool bezier_has_arrows; + boolean bezier_has_arrows; void (*comment) (char *str); - void (*usershape) (usershape_t *us, boxf b, point * A, int sides, bool filled); + void (*usershape) (usershape_t *us, boxf b, point * A, int sides, boolean filled); }; struct codegen_info_s { @@ -252,8 +256,8 @@ extern "C" { node_t **av; /* allocated list of nodes in rank */ int ht1, ht2; /* height below/above centerline */ int pht1, pht2; /* as above, but only primitive nodes */ - bool candidate; /* for transpose () */ - bool valid; + boolean candidate; /* for transpose () */ + boolean valid; int cache_nc; /* caches number of crossings */ adjmatrix_t *flat; } rank_t; @@ -269,9 +273,9 @@ extern "C" { point margin; point page; point size; - bool filled; - bool landscape; - bool centered; + boolean filled; + boolean landscape; + boolean centered; ratio_t ratio_kind; } layout_t; @@ -315,7 +319,7 @@ extern "C" { point border[4]; /* sizes of margins for graph labels */ unsigned char gui_state; /* Graph state for GUI ops */ unsigned char has_labels; - bool has_images; + boolean has_images; unsigned char charset; /* input character set */ int rankdir; int ht1, ht2; /* below and above extremal ranks */ @@ -346,9 +350,9 @@ extern "C" { short minrank, maxrank; /* various flags */ - bool has_flat_edges; + boolean has_flat_edges; unsigned char showboxes; - bool cluster_was_collapsed; + boolean cluster_was_collapsed; int nodesep, ranksep; node_t *ln, *rn; /* left, right nodes of bounding box */ @@ -356,11 +360,11 @@ extern "C" { /* for clusters */ node_t *leader, **rankleader; - bool expanded; + boolean expanded; char installed; char set_type; char label_pos; - bool exact_ranksep; + boolean exact_ranksep; #endif } Agraphinfo_t; @@ -429,7 +433,7 @@ extern "C" { void *alg; char state; unsigned char gui_state; /* Node state for GUI ops */ - bool clustnode; + boolean clustnode; #ifndef DOT_ONLY unsigned char pinned; @@ -439,7 +443,7 @@ extern "C" { #endif #ifndef NEATO_ONLY unsigned char showboxes; - bool has_port; + boolean has_port; /* fast graph */ char node_type, mark, onstack; @@ -541,7 +545,7 @@ extern "C" { #endif #ifndef NEATO_ONLY unsigned char showboxes; - bool conc_opp_flag; + boolean conc_opp_flag; short xpenalty; int weight; int cutvalue, tree_index; diff --git a/lib/common/usershape.h b/lib/common/usershape.h index 66a1b59a5..cda611972 100644 --- a/lib/common/usershape.h +++ b/lib/common/usershape.h @@ -17,6 +17,8 @@ #ifndef USERSHAPE_H #define USERSHAPE_H +#include + #ifdef __cplusplus extern "C" { #endif @@ -32,7 +34,7 @@ extern "C" { Dtlink_t link; char *name; int macro_id; - bool must_inline; + boolean must_inline; FILE *f; imagetype_t type; char *stringtype; diff --git a/lib/common/utils.c b/lib/common/utils.c index e4fce06f4..87d3ce70d 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -118,7 +118,7 @@ char *late_nnstring(void *obj, attrsym_t * attr, char *def) return rv; } -bool late_bool(void *obj, attrsym_t * attr, int def) +boolean late_bool(void *obj, attrsym_t * attr, int def) { if (attr == NULL) return def; @@ -331,7 +331,7 @@ static char *Fgets(FILE * fp) */ char *safefile(char *filename) { - static bool onetime = true; + static boolean onetime = TRUE; static char *safefilename = NULL; char *str, *p; @@ -349,7 +349,7 @@ char *safefile(char *filename) "file loading is disabled because the environment contains: %s\n" "and there is no GV_FILE_PATH variable.\n", HTTPServerEnVar); - onetime = false; + onetime = FALSE; } return NULL; } @@ -375,7 +375,7 @@ char *safefile(char *filename) " because files are only permitted to be loaded from the \"%s\"" " directory when running in an http server.\n", filename, Gvfilepath); - onetime = false; + onetime = FALSE; } return safefilename; @@ -399,13 +399,13 @@ void cat_libfile(FILE * ofp, char **arglib, char **stdlib) FILE *fp; char *p, **s, *bp; int i; - bool use_stdlib = true; + boolean use_stdlib = TRUE; /* check for empty string to turn off stdlib */ if (arglib) { for (i = 0; use_stdlib && ((p = arglib[i])); i++) { if (*p == '\0') - use_stdlib = false; + use_stdlib = FALSE; } } if (use_stdlib) @@ -443,14 +443,14 @@ int maptoken(char *p, char **name, int *val) return val[i]; } -bool mapbool(char *p) +boolean mapbool(char *p) { if (p == NULL) - return false; + return FALSE; if (!strcasecmp(p, "false")) - return false; + return FALSE; if (!strcasecmp(p, "true")) - return true; + return TRUE; return atoi(p); } @@ -678,16 +678,16 @@ initFontLabelEdgeAttr(edge_t * e, struct fontinfo *fi, * Return true if head/tail end of edge should not be clipped * to node. */ -static bool +static boolean noClip(edge_t *e, attrsym_t* sym) { char *str; - bool rv = false; + boolean rv = FALSE; if (sym) { /* mapbool isn't a good fit, because we want "" to mean true */ str = agxget(e,sym->index); if (str && str[0]) rv = !mapbool(str); - else rv = false; + else rv = FALSE; } return rv; } @@ -778,23 +778,23 @@ int common_init_edge(edge_t * e) /* We still accept ports beginning with colons but this is deprecated */ s = agget(e, TAIL_ID); if (s[0]) - ND_has_port(e->tail) = true; + ND_has_port(e->tail) = TRUE; ED_tail_port(e) = chkPort (ND_shape(e->tail)->fns->portfn,e->tail, s); if (noClip(e, E_tailclip)) - ED_tail_port(e).clip = false; + ED_tail_port(e).clip = FALSE; s = agget(e, HEAD_ID); if (s[0]) - ND_has_port(e->head) = true; + ND_has_port(e->head) = TRUE; ED_head_port(e) = chkPort(ND_shape(e->head)->fns->portfn,e->head, s); if (noClip(e, E_headclip)) - ED_head_port(e).clip = false; + ED_head_port(e).clip = FALSE; return r; } /* addLabelBB: */ -static box addLabelBB(box bb, textlabel_t * lp, bool flipxy) +static box addLabelBB(box bb, textlabel_t * lp, boolean flipxy) { int width, height; point p = lp->p; @@ -1498,7 +1498,7 @@ utf8ToLatin1 (char* s) return ns; } -bool overlap_node(node_t *n, boxf b) +boolean overlap_node(node_t *n, boxf b) { boxf bb; inside_t ictxt; @@ -1506,7 +1506,7 @@ bool overlap_node(node_t *n, boxf b) bb = ND_bb(n); if (! OVERLAP(b, bb)) - return false; + return FALSE; P2PF(ND_coord_i(n),p); @@ -1520,7 +1520,7 @@ bool overlap_node(node_t *n, boxf b) return ND_shape(n)->fns->insidefn(&ictxt, p); } -bool overlap_label(textlabel_t *lp, boxf b) +boolean overlap_label(textlabel_t *lp, boxf b) { double sx, sy; boxf bb; @@ -1534,19 +1534,19 @@ bool overlap_label(textlabel_t *lp, boxf b) return OVERLAP(b, bb); } -static bool overlap_arrow(pointf p, pointf u, double scale, int flag, boxf b) +static boolean overlap_arrow(pointf p, pointf u, double scale, int flag, boxf b) { boxf bb; bb = arrow_bb(p, u, scale, flag); if (OVERLAP(b, bb)) { /* FIXME - check inside arrow shape */ - return true; + return TRUE; } - return false; + return FALSE; } -static bool overlap_bezier(bezier bz, boxf b) +static boolean overlap_bezier(bezier bz, boxf b) { int i; point pp; @@ -1559,7 +1559,7 @@ static bool overlap_bezier(bezier bz, boxf b) pp = bz.list[i]; P2PF(pp, p); if (lineToBox(p, u, b) != -1) - return true; + return TRUE; u = p; } @@ -1568,18 +1568,18 @@ static bool overlap_bezier(bezier bz, boxf b) P2PF(bz.sp, p); P2PF(bz.list[0], u); if (overlap_arrow(p, u, 1, bz.sflag, b)) - return true; + return TRUE; } if (bz.eflag) { P2PF(bz.ep, p); P2PF(bz.list[bz.size - 1], u); if (overlap_arrow(p, u, 1, bz.eflag, b)) - return true; + return TRUE; } - return false; + return FALSE; } -bool overlap_edge(edge_t *e, boxf b) +boolean overlap_edge(edge_t *e, boxf b) { int i; splines *spl; @@ -1589,13 +1589,13 @@ bool overlap_edge(edge_t *e, boxf b) if (spl && boxf_overlap(spl->bb, b)) for (i = 0; i < spl->size; i++) if (overlap_bezier(spl->list[i], b)) - return true; + return TRUE; lp = ED_label(e); if (lp && overlap_label(lp, b)) - return true; + return TRUE; - return false; + return FALSE; } diff --git a/lib/common/utils.h b/lib/common/utils.h index 63841757c..c299e4f87 100644 --- a/lib/common/utils.h +++ b/lib/common/utils.h @@ -35,7 +35,7 @@ extern "C" { extern double late_double(void *, Agsym_t *, double, double); extern char *late_nnstring(void *, Agsym_t *, char *); extern char *late_string(void *, Agsym_t *, char *); - extern bool late_bool(void *, Agsym_t *, int); + extern boolean late_bool(void *, Agsym_t *, int); extern Agnode_t *UF_find(Agnode_t *); extern Agnode_t *UF_union(Agnode_t *, Agnode_t *); @@ -47,7 +47,7 @@ extern "C" { extern void cat_libfile(FILE *of, char **arglib, char **stdlib); extern void cat_preamble(GVJ_t *job, char **arglib); - extern bool mapbool(char *); + extern boolean mapbool(char *); extern int maptoken(char *, char **, int *); extern int test_toggle(void); @@ -58,9 +58,9 @@ extern "C" { extern void updateBB(graph_t * g, textlabel_t * lp); extern void update_bb(graph_t * g, point p); extern void compute_bb(Agraph_t *); - extern bool overlap_node(node_t *n, boxf b); - extern bool overlap_label(textlabel_t *lp, boxf b); - extern bool overlap_edge(edge_t *e, boxf b); + extern boolean overlap_node(node_t *n, boxf b); + extern boolean overlap_label(textlabel_t *lp, boxf b); + extern boolean overlap_edge(edge_t *e, boxf b); extern int processClusterEdges(graph_t * g); extern void undoClusterEdges(graph_t * g); -- 2.40.0