]> granicus.if.org Git - graphviz/commitdiff
use C99 initialization to simplify 'Dtdisc_t' definitions
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 14 Jan 2022 01:46:02 +0000 (17:46 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 15 Jan 2022 17:16:13 +0000 (09:16 -0800)
13 files changed:
cmd/tools/gmlparse.y
cmd/tools/graphml2gv.c
cmd/tools/gxl2gv.c
lib/cgraph/edge.c
lib/cgraph/graph.c
lib/cgraph/node.c
lib/common/emit.c
lib/common/htmlparse.y
lib/common/psusershape.c
lib/common/utils.c
lib/gvc/gvusershape.c
lib/gvpr/actions.c
lib/neatogen/multispline.c

index c631497a97d2315bf604872da8855c901415cff1..93a4dce41cfd50bfa7885cd531a61d9e74150c01 100644 (file)
@@ -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
index 21c8be7e37c88776b4112064313c99ca3e3dfdc0..a0505a7e3bccb6676c6938d37a94cd335bf2c610 100644 (file)
@@ -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)
index 18abeef225ed6ac5b88cfedcfce17b4cb3c63f76..b1936977b1d8ef6996ff6b8c68a6848ca243e01d 100644 (file)
@@ -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)
index 1676bf366b9063ea3f6c7a8ee09324374b3a6774..fa85d2705559fc684e0d09bb4b227f60bd213340 100644 (file)
@@ -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,
 };
index b965b318caf86c664f0cf35c57b7da34e6a74705..adc7b0d882b4645b36a1ce23f49a95ca00613e13 100644 (file)
@@ -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 };
index 03fc205b8a77c7c7ec461eb591dfd285b71f22f3..d9397a62b416abd23439142d23346447e1d0f22f 100644 (file)
@@ -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)
index bc77e7f13fedf92fb6cf788c25dd260caa6e81b4..3e4fe7ca32a195da7478ab87d2043eba02594131 100644 (file)
@@ -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)
index 420d02969f32f3bcd6658f2600a9077d4bee67b5..055f09aff61314adf4e99b21f4f765bd866cb089 100644 (file)
@@ -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:
index 127ce1dad5ee189dd784fff7afd2cb5be23a0c25..85c7a7423f7e9f5779c14aed62766635e4afd1b0 100644 (file)
@@ -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)
index 05bf4387b492e50b39d4b92e54f03cfdb76445a4..05072e618cd3fa672f2bf6dc8f9bf8dfd1349aad 100644 (file)
@@ -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)
index f552eefbf2da933e0fc8f6cc0e5d9ffa1bd93424..3a28db8bdcc181874ffd85609b4a15dd1aa31b6f 100644 (file)
@@ -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)
index 4c941c58ba9c9c4e5a78cd5be15496f03ecbc4bf..c2f4b4b3a6513ca5c49909480434dcb80355e9c6 100644 (file)
@@ -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:
index 67eb87970cbae40af11be5871edd5be5e46e3127..49d5244b69c3b71dfd7310c231d66e6078a94d30 100644 (file)
@@ -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)