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_list.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_list.c')
-rw-r--r-- | src/app_list.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/app_list.c b/src/app_list.c index 24d1a88..5606df0 100644 --- a/src/app_list.c +++ b/src/app_list.c @@ -177,25 +177,16 @@ static void print_result(struct apk_database *db, const char *match, struct apk_ iterate_providers(name, ctx); } -enum { - OPT_LIST_available, - OPT_LIST_installed, - OPT_LIST_depends, - OPT_LIST_origin, - OPT_LIST_orphaned, - OPT_LIST_providers, - OPT_LIST_upgradeable, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2n("available", "a") - APK_OPT2n("installed", "I") - APK_OPT2n("depends", "d") - APK_OPT2n("origin", "o") - APK_OPT2n("orphaned", "O") - APK_OPT2n("providers", "P") - APK_OPT2n("upgradeable", "u"); +#define LIST_OPTIONS(OPT) \ + OPT(OPT_LIST_available, APK_OPT_SH("a") "available") \ + OPT(OPT_LIST_installed, APK_OPT_SH("I") "installed") \ + OPT(OPT_LIST_depends, APK_OPT_SH("d") "depends") \ + OPT(OPT_LIST_origin, APK_OPT_SH("o") "origin") \ + OPT(OPT_LIST_orphaned, APK_OPT_SH("O") "orphaned") \ + OPT(OPT_LIST_providers, APK_OPT_SH("P") "providers") \ + OPT(OPT_LIST_upgradeable, APK_OPT_SH("u") "upgradeable") + +APK_OPT_APPLET(option_desc, LIST_OPTIONS); static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int opt, const char *optarg) { |