From 675ddb4348ad452bf8acb5cb59122491dd247fa9 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Thu, 13 Jan 2022 17:46:02 -0800 Subject: [PATCH] use C99 initialization to simplify 'Dtdisc_t' definitions --- cmd/tools/gmlparse.y | 52 ++++++++++++-------------------------- cmd/tools/graphml2gv.c | 14 ++++------ cmd/tools/gxl2gv.c | 14 ++++------ lib/cgraph/edge.c | 48 +++++++++-------------------------- lib/cgraph/graph.c | 13 +++------- lib/cgraph/node.c | 25 +++++------------- lib/common/emit.c | 11 ++------ lib/common/htmlparse.y | 49 +++++++++-------------------------- lib/common/psusershape.c | 12 +++------ lib/common/utils.c | 28 ++++++++------------ lib/gvc/gvusershape.c | 12 +++------ lib/gvpr/actions.c | 13 +++------- lib/neatogen/multispline.c | 30 +++++++++------------- 13 files changed, 94 insertions(+), 227 deletions(-) diff --git a/cmd/tools/gmlparse.y b/cmd/tools/gmlparse.y index c631497a9..93a4dce41 100644 --- a/cmd/tools/gmlparse.y +++ b/cmd/tools/gmlparse.y @@ -81,51 +81,31 @@ free_graph (Dt_t*d, gmlgraph* p, Dtdisc_t* ds) } static Dtdisc_t nodeDisc = { - offsetof(gmlnode,attrlist), - sizeof(Dt_t*), - offsetof(gmlnode,link), - NIL(Dtmake_f), - (Dtfree_f)free_node, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(gmlnode, attrlist), + .size = sizeof(Dt_t *), + .link = offsetof(gmlnode, link), + .freef = (Dtfree_f)free_node, }; static Dtdisc_t edgeDisc = { - offsetof(gmledge,attrlist), - sizeof(Dt_t*), - offsetof(gmledge,link), - NIL(Dtmake_f), - (Dtfree_f)free_edge, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(gmledge, attrlist), + .size = sizeof(Dt_t *), + .link = offsetof(gmledge, link), + .freef = (Dtfree_f)free_edge, }; static Dtdisc_t attrDisc = { - offsetof(gmlattr,name), - sizeof(char*), - offsetof(gmlattr,link), - NIL(Dtmake_f), - (Dtfree_f)free_attr, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(gmlattr, name), + .size = sizeof(char *), + .link = offsetof(gmlattr, link), + .freef = (Dtfree_f)free_attr, }; static Dtdisc_t graphDisc = { - offsetof(gmlgraph,nodelist), - sizeof(Dt_t*), - offsetof(gmlgraph,link), - NIL(Dtmake_f), - (Dtfree_f)free_graph, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(gmlgraph, nodelist), + .size = sizeof(Dt_t *), + .link = offsetof(gmlgraph, link), + .freef = (Dtfree_f)free_graph, }; static void diff --git a/cmd/tools/graphml2gv.c b/cmd/tools/graphml2gv.c index 21c8be7e3..a0505a7e3 100644 --- a/cmd/tools/graphml2gv.c +++ b/cmd/tools/graphml2gv.c @@ -141,15 +141,11 @@ static void free_nitem(Dt_t * d, namev_t * np, Dtdisc_t * disc) } static Dtdisc_t nameDisc = { - offsetof(namev_t, name), - -1, - offsetof(namev_t, link), - (Dtmake_f) make_nitem, - (Dtfree_f) free_nitem, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(namev_t, name), + .size = -1, + .link = offsetof(namev_t, link), + .makef = (Dtmake_f)make_nitem, + .freef = (Dtfree_f)free_nitem, }; static userdata_t *genUserdata(char* dfltname) diff --git a/cmd/tools/gxl2gv.c b/cmd/tools/gxl2gv.c index 18abeef22..b1936977b 100644 --- a/cmd/tools/gxl2gv.c +++ b/cmd/tools/gxl2gv.c @@ -155,15 +155,11 @@ static void free_nitem(Dt_t * d, namev_t * np, Dtdisc_t * disc) } static Dtdisc_t nameDisc = { - offsetof(namev_t, name), - -1, - offsetof(namev_t, link), - (Dtmake_f) make_nitem, - (Dtfree_f) free_nitem, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(namev_t, name), + .size = -1, + .link = offsetof(namev_t, link), + .makef = (Dtmake_f)make_nitem, + .freef = (Dtfree_f)free_nitem, }; static userdata_t *genUserdata(void) diff --git a/lib/cgraph/edge.c b/lib/cgraph/edge.c index 1676bf366..fa85d2705 100644 --- a/lib/cgraph/edge.c +++ b/lib/cgraph/edge.c @@ -423,50 +423,26 @@ static int agedgeseqcmpf(Dict_t * d, void *arg_e0, void *arg_e1, Dtdisc_t * disc /* indexing for ordered traversal */ Dtdisc_t Ag_mainedge_seq_disc = { - 0, /* pass object ptr */ - 0, /* size (ignored) */ - offsetof(Agedge_t,seq_link),/* use internal links */ - NIL(Dtmake_f), - NIL(Dtfree_f), - agedgeseqcmpf, - NIL(Dthash_f), - agdictobjmem, - NIL(Dtevent_f) + .link = offsetof(Agedge_t, seq_link), // use internal links + .comparf = agedgeseqcmpf, + .memoryf = agdictobjmem, }; Dtdisc_t Ag_subedge_seq_disc = { - 0, /* pass object ptr */ - 0, /* size (ignored) */ - -1, /* use external holder objects */ - NIL(Dtmake_f), - NIL(Dtfree_f), - agedgeseqcmpf, - NIL(Dthash_f), - agdictobjmem, - NIL(Dtevent_f) + .link = -1, // use external holder objects + .comparf = agedgeseqcmpf, + .memoryf = agdictobjmem, }; /* indexing for random search */ Dtdisc_t Ag_mainedge_id_disc = { - 0, /* pass object ptr */ - 0, /* size (ignored) */ - offsetof(Agedge_t,id_link), /* use internal links */ - NIL(Dtmake_f), - NIL(Dtfree_f), - agedgeidcmpf, - NIL(Dthash_f), - agdictobjmem, - NIL(Dtevent_f) + .link = offsetof(Agedge_t, id_link), // use internal links + .comparf = agedgeidcmpf, + .memoryf = agdictobjmem, }; Dtdisc_t Ag_subedge_id_disc = { - 0, /* pass object ptr */ - 0, /* size (ignored) */ - -1, /* use external holder objects */ - NIL(Dtmake_f), - NIL(Dtfree_f), - agedgeidcmpf, - NIL(Dthash_f), - agdictobjmem, - NIL(Dtevent_f) + .link = -1, // use external holder objects + .comparf = agedgeidcmpf, + .memoryf = agdictobjmem, }; diff --git a/lib/cgraph/graph.c b/lib/cgraph/graph.c index b965b318c..adc7b0d88 100644 --- a/lib/cgraph/graph.c +++ b/lib/cgraph/graph.c @@ -248,18 +248,11 @@ static int agraphidcmpf(Dict_t * d, void *arg0, void *arg1, Dtdisc_t * disc) } Dtdisc_t Ag_subgraph_id_disc = { - 0, /* pass object ptr */ - 0, /* size (ignored) */ - offsetof(Agraph_t, link), /* link offset */ - NIL(Dtmake_f), - NIL(Dtfree_f), - agraphidcmpf, - NIL(Dthash_f), - agdictobjmem, - NIL(Dtevent_f) + .link = offsetof(Agraph_t, link), // link offset + .comparf = agraphidcmpf, + .memoryf = agdictobjmem, }; - Agdesc_t Agdirected = { .directed = 1, .maingraph = 1 }; Agdesc_t Agstrictdirected = { .directed = 1, .strict = 1, .maingraph = 1 }; Agdesc_t Agundirected = { .maingraph = 1 }; diff --git a/lib/cgraph/node.c b/lib/cgraph/node.c index 03fc205b8..d9397a62b 100644 --- a/lib/cgraph/node.c +++ b/lib/cgraph/node.c @@ -317,27 +317,16 @@ free_subnode (Dt_t* d, Agsubnode_t* sn, Dtdisc_t * disc) } Dtdisc_t Ag_subnode_id_disc = { - 0, /* pass object ptr */ - 0, /* size (ignored) */ - offsetof(Agsubnode_t, id_link), /* link offset */ - NIL(Dtmake_f), - NIL(Dtfree_f), - agsubnodeidcmpf, - NIL(Dthash_f), - agdictobjmem, - NIL(Dtevent_f) + .link = offsetof(Agsubnode_t, id_link), // link offset + .comparf = agsubnodeidcmpf, + .memoryf = agdictobjmem, }; Dtdisc_t Ag_subnode_seq_disc = { - 0, /* pass object ptr */ - 0, /* size (ignored) */ - offsetof(Agsubnode_t, seq_link), /* link offset */ - NIL(Dtmake_f), - (Dtfree_f)free_subnode, - agsubnodeseqcmpf, - NIL(Dthash_f), - agdictobjmem, - NIL(Dtevent_f) + .link = offsetof(Agsubnode_t, seq_link), // link offset + .freef = (Dtfree_f)free_subnode, + .comparf = agsubnodeseqcmpf, + .memoryf = agdictobjmem, }; static void agnodesetfinger(Agraph_t * g, Agnode_t * n, void *ignored) diff --git a/lib/common/emit.c b/lib/common/emit.c index bc77e7f13..3e4fe7ca3 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -3530,15 +3530,8 @@ static void free_string_entry(Dict_t * dict, char *key, Dtdisc_t * disc) static Dict_t *strings; static Dtdisc_t stringdict = { - 0, /* key - the object itself */ - 0, /* size - null-terminated string */ - -1, /* link - allocate separate holder objects */ - NIL(Dtmake_f), - (Dtfree_f) free_string_entry, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .link = -1, // link - allocate separate holder objects + .freef = (Dtfree_f)free_string_entry, }; int emit_once(char *str) diff --git a/lib/common/htmlparse.y b/lib/common/htmlparse.y index 420d02969..055f09aff 100644 --- a/lib/common/htmlparse.y +++ b/lib/common/htmlparse.y @@ -103,26 +103,16 @@ free_citem(Dt_t* d, pitem* p,Dtdisc_t* ds) } static Dtdisc_t rowDisc = { - offsetof(pitem,u), - sizeof(void*), - offsetof(pitem,link), - NIL(Dtmake_f), - (Dtfree_f)free_ritem, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(pitem, u), + .size = sizeof(void *), + .link = offsetof(pitem, link), + .freef = (Dtfree_f)free_ritem, }; static Dtdisc_t cellDisc = { - offsetof(pitem,u), - sizeof(void*), - offsetof(pitem,link), - NIL(Dtmake_f), - (Dtfree_f)free_item, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(pitem, u), + .size = sizeof(void *), + .link = offsetof(pitem, link), + .freef = (Dtfree_f)free_item, }; typedef struct { @@ -166,28 +156,13 @@ free_fspan(Dt_t* d, fspan* p, Dtdisc_t* ds) } static Dtdisc_t fstrDisc = { - 0, - 0, - offsetof(fitem,link), - NIL(Dtmake_f), - (Dtfree_f)free_item, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .link = offsetof(fitem, link), + .freef = (Dtfree_f)free_item, }; - static Dtdisc_t fspanDisc = { - 0, - 0, - offsetof(fspan,link), - NIL(Dtmake_f), - (Dtfree_f)free_item, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .link = offsetof(fspan, link), + .freef = (Dtfree_f)free_item, }; /* appendFItemList: diff --git a/lib/common/psusershape.c b/lib/common/psusershape.c index 127ce1dad..85c7a7423 100644 --- a/lib/common/psusershape.c +++ b/lib/common/psusershape.c @@ -28,15 +28,9 @@ static void ps_image_free(Dict_t * dict, usershape_t * p, Dtdisc_t * disc) } static Dtdisc_t ImageDictDisc = { - offsetof(usershape_t, name),/* key */ - -1, /* size */ - 0, /* link offset */ - NIL(Dtmake_f), - (Dtfree_f) ps_image_free, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(usershape_t, name), + .size = -1, + .freef = (Dtfree_f)ps_image_free, }; static usershape_t *user_init(const char *str) diff --git a/lib/common/utils.c b/lib/common/utils.c index 05bf4387b..05072e618 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -993,15 +993,12 @@ static void freeItem(Dt_t * d, item * obj, Dtdisc_t * disc) } static Dtdisc_t mapDisc = { - offsetof(item, p), - sizeof(2 * sizeof(void *)), - offsetof(item, link), - (Dtmake_f) newItem, - (Dtfree_f) freeItem, - (Dtcompar_f) cmpItem, - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(item, p), + .size = sizeof(2 * sizeof(void *)), + .link = offsetof(item, link), + .makef = (Dtmake_f)newItem, + .freef = (Dtfree_f)freeItem, + .comparf = (Dtcompar_f)cmpItem, }; /* cloneEdge: @@ -1876,15 +1873,10 @@ static void free_clust (Dt_t* dt, clust_t* clp, Dtdisc_t* disc) } static Dtdisc_t strDisc = { - offsetof(clust_t,name), - -1, - offsetof(clust_t,link), - NIL(Dtmake_f), - (Dtfree_f)free_clust, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(clust_t, name), + .size = -1, + .link = offsetof(clust_t, link), + .freef = (Dtfree_f)free_clust, }; static void fillMap (Agraph_t* g, Dt_t* map) diff --git a/lib/gvc/gvusershape.c b/lib/gvc/gvusershape.c index f552eefbf..3a28db8bd 100644 --- a/lib/gvc/gvusershape.c +++ b/lib/gvc/gvusershape.c @@ -566,15 +566,9 @@ static void usershape_close (Dict_t * dict, void * p, Dtdisc_t * disc) } static Dtdisc_t ImageDictDisc = { - offsetof(usershape_t, name), /* key */ - -1, /* size */ - 0, /* link offset */ - NIL(Dtmake_f), - usershape_close, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(usershape_t, name), + .size = -1, + .freef = usershape_close, }; usershape_t *gvusershape_find(const char *name) diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index 4c941c58b..c2f4b4b3a 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -281,15 +281,10 @@ static int cmppair(Dt_t * d, Agedge_t** key1, Agedge_t** key2, Dtdisc_t * disc) } static Dtdisc_t edgepair = { - offsetof(edgepair_t, key), - sizeof(Agedge_t*), - offsetof(edgepair_t, link), - NIL(Dtmake_f), - NIL(Dtfree_f), - (Dtcompar_f) cmppair, - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(edgepair_t, key), + .size = sizeof(Agedge_t *), + .link = offsetof(edgepair_t, link), + .comparf = (Dtcompar_f)cmppair, }; /* cloneGraph: diff --git a/lib/neatogen/multispline.c b/lib/neatogen/multispline.c index 67eb87970..49d5244b6 100644 --- a/lib/neatogen/multispline.c +++ b/lib/neatogen/multispline.c @@ -94,15 +94,12 @@ static void freeItem(Dt_t * d, item * obj, Dtdisc_t * disc) } static Dtdisc_t itemdisc = { - offsetof(item, a), - 2 * sizeof(int), - offsetof(item, link), - (Dtmake_f) newItem, - (Dtfree_f) freeItem, - (Dtcompar_f) cmpItem, - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(item, a), + .size = 2 * sizeof(int), + .link = offsetof(item, link), + .makef = (Dtmake_f)newItem, + .freef = (Dtfree_f)freeItem, + .comparf = (Dtcompar_f)cmpItem, }; static void addMap(Dt_t * map, int a, int b, int t) @@ -195,15 +192,12 @@ static void freeIpair(Dt_t * d, Ipair * obj, Dtdisc_t * disc) } static Dtdisc_t ipairdisc = { - offsetof(Ipair, i), - sizeof(int), - offsetof(Ipair, link), - (Dtmake_f) newIpair, - (Dtfree_f) freeIpair, - (Dtcompar_f) cmpIpair, - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) + .key = offsetof(Ipair, i), + .size = sizeof(int), + .link = offsetof(Ipair, link), + .makef = (Dtmake_f)newIpair, + .freef = (Dtfree_f)freeIpair, + .comparf = (Dtcompar_f)cmpIpair, }; static void vmapAdd(Dt_t * map, int i, int j) -- 2.40.0