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_info.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_info.c')
-rw-r--r-- | src/app_info.c | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/src/app_info.c b/src/app_info.c index b444b80..8454f0f 100644 --- a/src/app_info.c +++ b/src/app_info.c @@ -364,41 +364,24 @@ static void print_name_info(struct apk_database *db, const char *match, struct a info_subaction(ctx, p->pkg); } -enum { - OPT_INFO_all, - OPT_INFO_contents, - OPT_INFO_depends, - OPT_INFO_description, - OPT_INFO_install_if, - OPT_INFO_installed, - OPT_INFO_license, - OPT_INFO_provides, - OPT_INFO_rdepends, - OPT_INFO_replaces, - OPT_INFO_rinstall_if, - OPT_INFO_size, - OPT_INFO_triggers, - OPT_INFO_webpage, - OPT_INFO_who_owns, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2n("all", "a") - APK_OPT2n("contents", "L") - APK_OPT2n("depends", "R") - APK_OPT2n("description", "d") - APK_OPT1n("install-if") - APK_OPT2n("installed", "e") - APK_OPT1n("license") - APK_OPT2n("provides", "P") - APK_OPT2n("rdepends", "r") - APK_OPT1n("replaces") - APK_OPT1n("rinstall-if") - APK_OPT2n("size", "s") - APK_OPT2n("triggers", "t") - APK_OPT2n("webpage", "w") - APK_OPT2n("who-owns", "W"); +#define INFO_OPTIONS(OPT) \ + OPT(OPT_INFO_all, APK_OPT_SH("a") "all") \ + OPT(OPT_INFO_contents, APK_OPT_SH("L") "contents") \ + OPT(OPT_INFO_depends, APK_OPT_SH("R") "depends") \ + OPT(OPT_INFO_description, APK_OPT_SH("d") "description") \ + OPT(OPT_INFO_install_if, "install-if") \ + OPT(OPT_INFO_installed, APK_OPT_SH("e") "installed") \ + OPT(OPT_INFO_license, "license") \ + OPT(OPT_INFO_provides, APK_OPT_SH("P") "provides") \ + OPT(OPT_INFO_rdepends, APK_OPT_SH("r") "rdepends") \ + OPT(OPT_INFO_replaces, "replaces") \ + OPT(OPT_INFO_rinstall_if, "rinstall-if") \ + OPT(OPT_INFO_size, APK_OPT_SH("s") "size") \ + OPT(OPT_INFO_triggers, APK_OPT_SH("t") "triggers") \ + OPT(OPT_INFO_webpage, APK_OPT_SH("w") "webpage") \ + OPT(OPT_INFO_who_owns, APK_OPT_SH("W") "who-owns") + +APK_OPT_APPLET(option_desc, INFO_OPTIONS); static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int opt, const char *optarg) { |