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_info.c | 53 ++++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'src/app_info.c') 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) { -- cgit v1.2.3-60-g2f50