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_version.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/app_version.c') diff --git a/src/app_version.c b/src/app_version.c index 2dc3bcd..d5d9c88 100644 --- a/src/app_version.c +++ b/src/app_version.c @@ -66,21 +66,14 @@ static int ver_validate(struct apk_database *db, struct apk_string_array *args) return errors; } -enum { - OPT_VERSION_all, - OPT_VERSION_check, - OPT_VERSION_indexes, - OPT_VERSION_limit, - OPT_VERSION_test, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2n("all", "a") - APK_OPT2n("check", "c") - APK_OPT2n("indexes", "I") - APK_OPT2R("limit", "l") - APK_OPT2n("test", "t"); +#define VERSION_OPTIONS(OPT) \ + OPT(OPT_VERSION_all, APK_OPT_SH("a") "all") \ + OPT(OPT_VERSION_check, APK_OPT_SH("c") "check") \ + OPT(OPT_VERSION_indexes, APK_OPT_SH("I") "indexes") \ + OPT(OPT_VERSION_limit, APK_OPT_ARG APK_OPT_SH("l") "limit") \ + OPT(OPT_VERSION_test, APK_OPT_SH("t") "test") + +APK_OPT_APPLET(option_desc, VERSION_OPTIONS); static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { -- cgit v1.2.3-60-g2f50