From edb45ae46449ddabcac3dea6b3f42c6cec01510a Mon Sep 17 00:00:00 2001 From: Timo Teräs Date: Mon, 24 Aug 2020 13:35:36 +0300 Subject: enforce options definitions to bind the enum and the descriptor This uses some macro trickery to make sure that there's one-to-one mapping with the option index enum and the descriptor. The down side is that enum's are generated via #define's and editors might not pick them up for auto completion, but the benefits are more: it's no longer possible have mismatching enum value and descriptor index, and the amount of source code lines is less. --- src/app_dot.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/app_dot.c') diff --git a/src/app_dot.c b/src/app_dot.c index 89e385a..ad9167c 100644 --- a/src/app_dot.c +++ b/src/app_dot.c @@ -22,15 +22,11 @@ struct dot_ctx { int installed_only : 1; }; -enum { - OPT_DOT_errors, - OPT_DOT_installed, -}; +#define DOT_OPTIONS(OPT) \ + OPT(OPT_DOT_errors, "errors") \ + OPT(OPT_DOT_installed, "installed") -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT1n("errors") - APK_OPT1n("installed"); +APK_OPT_APPLET(option_desc, DOT_OPTIONS); static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int opt, const char *optarg) { -- cgit v1.2.3-70-g09d2