]> granicus.if.org Git - graphviz/commitdiff
Eliminate "#define NUM_APIS 4" now that I've found a different cool trick
authorellson <devnull@localhost>
Thu, 20 Jan 2005 23:22:02 +0000 (23:22 +0000)
committerellson <devnull@localhost>
Thu, 20 Jan 2005 23:22:02 +0000 (23:22 +0000)
for automatically computing the number of APIS

lib/gvc/gvcint.h
lib/gvc/gvplugin.c
lib/gvc/gvplugin.h

index 4b3f9897fa726bcff3e459c202e2aa4665c27016..a6d064771f8ea5926ff4ecd7046a068936ae9f1c 100644 (file)
@@ -23,6 +23,8 @@
 extern "C" {
 #endif
 
+#define ARRAY_SIZE(A) (sizeof(A)/sizeof(A[0]))
+
     typedef enum { PEN_NONE, PEN_DASHED, PEN_DOTTED, PEN_SOLID } pen_type;
     typedef enum { FILL_NONE, FILL_SOLID } fill_type;
     typedef enum { FONT_REGULAR, FONT_BOLD, FONT_ITALIC } font_type;
@@ -150,8 +152,11 @@ extern "C" {
        void (*errorfn) (char *fmt, ...);
 
        /* plugins */
-       gv_plugin_t *apis[NUM_APIS];    /* array of linked lists of plugins for each api */
-       gv_plugin_t *api[NUM_APIS];     /* array of current plugins for each api */
+#define ELEM(x) +1
+       /* APIS expands to "+1 +1 ... +1" to give the number of APIs */
+       gv_plugin_t *apis[ APIS ]; /* array of linked-list of plugins per api */
+       gv_plugin_t *api[ APIS ];  /* array of current plugins per api */
+#undef ELEM
 
        void *display; /* window display data for gvdisplay plugin */
        gvdisplay_engine_t *display_engine; /* current display engine */
index 1c04d526bd2a2ced18282411bea60f460881cc14..74d419a7a67e4a8cabbf4d50e329574880c8d38b 100644 (file)
@@ -28,8 +28,6 @@
  * Define an apis array of name strings using an enumerated api_t as index.
  * The enumerated type is defined gvplugin.h.  The apis array is
  * inititialized here by redefining ELEM and reinvoking APIS.
- *
- * The NUM_APIS is the size of the array.
  */
 #define ELEM(x) #x,
 static char *apis[] = { APIS };        /* "render", "layout", ... */
@@ -40,7 +38,7 @@ api_t gvplugin_api(char *str)
 {
     int api;
 
-    for (api = 0; api < NUM_APIS; api++) {
+    for (api = 0; api < ARRAY_SIZE(apis); api++) {
        if (strcmp(str, apis[api]) == 0)
            return api;
     }
index 728aa43eedc2dd115efd335c2ac68b4ce9377f4d..6dae6f7818d08ee2e3c972bbf856d43f868b27e1 100644 (file)
@@ -31,11 +31,8 @@ extern "C" {
  * Define an apis array of name strings using an enumerated api_t as index.
  * The enumerated type is defined here.  The apis array is
  * inititialized in gvplugin.c by redefining ELEM and reinvoking APIS.
- *
- * NUM_APIS is the size of the array.
  */
 #define APIS ELEM(render) ELEM(layout) ELEM(display) ELEM(text)
-#define NUM_APIS 4
 
 #define ELEM(x) API_##x,
     typedef enum { APIS } api_t; /* API_render, API_layout, ... */