diff options
author | Timo Teräs <timo.teras@iki.fi> | 2020-08-24 13:35:36 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2020-08-24 13:35:36 +0300 |
commit | edb45ae46449ddabcac3dea6b3f42c6cec01510a (patch) | |
tree | a27a046df30e4ead8f36c559dabdecb2fa1d7ea5 /src/app_version.c | |
parent | 82de29cf7bad3d9cbb0aeb4dbe756ad2bde73eb3 (diff) | |
download | apk-tools-edb45ae46449ddabcac3dea6b3f42c6cec01510a.tar.gz apk-tools-edb45ae46449ddabcac3dea6b3f42c6cec01510a.tar.bz2 apk-tools-edb45ae46449ddabcac3dea6b3f42c6cec01510a.tar.xz apk-tools-edb45ae46449ddabcac3dea6b3f42c6cec01510a.zip |
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.
Diffstat (limited to 'src/app_version.c')
-rw-r--r-- | src/app_version.c | 23 |
1 files changed, 8 insertions, 15 deletions
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) { |