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_upgrade.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_upgrade.c')
-rw-r--r-- | src/app_upgrade.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/app_upgrade.c b/src/app_upgrade.c index 06008f6..b666d8e 100644 --- a/src/app_upgrade.c +++ b/src/app_upgrade.c @@ -24,21 +24,14 @@ struct upgrade_ctx { int errors; }; -enum { - OPT_UPGRADE_available, - OPT_UPGRADE_ignore, - OPT_UPGRADE_latest, - OPT_UPGRADE_no_self_upgrade, - OPT_UPGRADE_self_upgrade_only, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2n("available", "a") - APK_OPT1n("ignore") - APK_OPT2n("latest", "l") - APK_OPT1n("no-self-upgrade") - APK_OPT1n("self-upgrade-only"); +#define UPGRADE_OPTIONS(OPT) \ + OPT(OPT_UPGRADE_available, APK_OPT_SH("a") "available") \ + OPT(OPT_UPGRADE_ignore, "ignore") \ + OPT(OPT_UPGRADE_latest, APK_OPT_SH("l") "latest") \ + OPT(OPT_UPGRADE_no_self_upgrade, "no-self-upgrade") \ + OPT(OPT_UPGRADE_self_upgrade_only, "self-upgrade-only") + +APK_OPT_APPLET(option_desc, UPGRADE_OPTIONS); static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { |