]> granicus.if.org Git - graphviz/commitdiff
gxl2gv: use an enum instead of #defines for attribute type
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 6 Jul 2021 00:28:39 +0000 (17:28 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 11 Jul 2021 23:04:25 +0000 (16:04 -0700)
This introduces some stronger typing and makes it clearer that the attribute
type variables like Current_class can only ever be one of these values. Related
to #517.

cmd/tools/gxl2gv.c

index bec235a012ed1a88a925c5c93d0a475b4b5422c5..73bed1c8d3c640b6e4b40c98fdb31ddad6c53bae 100644 (file)
 #define GXL_COMP    "_gxl_composite_"
 #define GXL_LOC     "_gxl_locator_"
 
-#define        TAG_NONE        -1
-#define        TAG_GRAPH       0
-#define TAG_NODE       1
-#define TAG_EDGE       2
+typedef enum {
+  TAG_NONE,
+  TAG_GRAPH,
+  TAG_NODE,
+  TAG_EDGE,
+} attr_t;
 
 typedef struct slist slist;
 struct slist {
@@ -105,15 +107,15 @@ typedef struct userdata {
     agxbuf composite_buffer;
     slist *elements;
     int listen;
-    int closedElementType;
-    int globalAttrType;
+    attr_t closedElementType;
+    attr_t globalAttrType;
     int compositeReadState;
     int edgeinverted;
     Dt_t *nameMap;
 } userdata_t;
 
 static Agraph_t *root;         /* root graph */
-static int Current_class;      /* Current element type */
+static attr_t Current_class;   /* Current element type */
 static Agraph_t *G;            /* Current graph */
 static Agnode_t *N;            /* Set if Current_class == TAG_NODE */
 static Agedge_t *E;            /* Set if Current_class == TAG_EDGE */