diff --git a/src/libei.c b/src/libei.c index 1c227da..0b22baf 100644 --- a/src/libei.c +++ b/src/libei.c @@ -131,7 +131,6 @@ ei_dispatch(struct ei *ei) static const char * ei_event_type_to_string(enum ei_event_type type) { -#define CASE_RETURN_STRING(_t) case _t: return #_t switch(type) { CASE_RETURN_STRING(EI_EVENT_CONNECT); CASE_RETURN_STRING(EI_EVENT_DISCONNECT); @@ -140,7 +139,6 @@ ei_event_type_to_string(enum ei_event_type type) CASE_RETURN_STRING(EI_EVENT_DEVICE_SUSPENDED); CASE_RETURN_STRING(EI_EVENT_DEVICE_RESUMED); } -#undef CASE_RETURN_STRING assert(!"Unhandled event type"); } diff --git a/src/libeis.c b/src/libeis.c index d09fba7..6ba76c7 100644 --- a/src/libeis.c +++ b/src/libeis.c @@ -100,7 +100,6 @@ eis_dispatch(struct eis *eis) static const char * eis_event_type_to_string(enum eis_event_type type) { -#define CASE_RETURN_STRING(_t) case _t: return #_t switch(type) { CASE_RETURN_STRING(EIS_EVENT_CLIENT_CONNECT); CASE_RETURN_STRING(EIS_EVENT_CLIENT_DISCONNECT); @@ -118,7 +117,6 @@ eis_event_type_to_string(enum eis_event_type type) CASE_RETURN_STRING(EIS_EVENT_TOUCH_UP); CASE_RETURN_STRING(EIS_EVENT_TOUCH_MOTION); } -#undef CASE_RETURN_STRING assert(!"Unhandled event type"); } diff --git a/src/util-macros.h b/src/util-macros.h index 2e0633c..762beb8 100644 --- a/src/util-macros.h +++ b/src/util-macros.h @@ -32,6 +32,14 @@ #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) #define ARRAY_FOR_EACH(_arr, _elem) \ for (size_t _i = 0; _i < ARRAY_LENGTH(_arr) && (_elem = &_arr[_i]); _i++) +/** + * Use to stringify a switch case value: + * switch (foo) { + * CASE_RETURN_STRING(ENUMVALUE); + * CASE_RETURN_STRING(OTHERVALUE); + * } + */ +#define CASE_RETURN_STRING(_x) case _x: return #_x #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b))