From 22fd7139c62d9f52e30753fe144b24acaf3f8bbe Mon Sep 17 00:00:00 2001 From: ellson Date: Thu, 20 Jan 2005 23:22:02 +0000 Subject: [PATCH] Eliminate "#define NUM_APIS 4" now that I've found a different cool trick for automatically computing the number of APIS --- lib/gvc/gvcint.h | 9 +++++++-- lib/gvc/gvplugin.c | 4 +--- lib/gvc/gvplugin.h | 3 --- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/gvc/gvcint.h b/lib/gvc/gvcint.h index 4b3f9897f..a6d064771 100644 --- a/lib/gvc/gvcint.h +++ b/lib/gvc/gvcint.h @@ -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 */ diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index 1c04d526b..74d419a7a 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -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; } diff --git a/lib/gvc/gvplugin.h b/lib/gvc/gvplugin.h index 728aa43ee..6dae6f781 100644 --- a/lib/gvc/gvplugin.h +++ b/lib/gvc/gvplugin.h @@ -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, ... */ -- 2.40.0