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 | |
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.
-rw-r--r-- | src/apk.c | 136 | ||||
-rw-r--r-- | src/apk_applet.h | 25 | ||||
-rw-r--r-- | src/app_add.c | 23 | ||||
-rw-r--r-- | src/app_audit.c | 23 | ||||
-rw-r--r-- | src/app_cache.c | 12 | ||||
-rw-r--r-- | src/app_del.c | 9 | ||||
-rw-r--r-- | src/app_dot.c | 12 | ||||
-rw-r--r-- | src/app_fetch.c | 23 | ||||
-rw-r--r-- | src/app_fix.c | 23 | ||||
-rw-r--r-- | src/app_index.c | 23 | ||||
-rw-r--r-- | src/app_info.c | 53 | ||||
-rw-r--r-- | src/app_list.c | 29 | ||||
-rw-r--r-- | src/app_search.c | 26 | ||||
-rw-r--r-- | src/app_upgrade.c | 23 | ||||
-rw-r--r-- | src/app_version.c | 23 |
15 files changed, 175 insertions, 288 deletions
@@ -73,80 +73,48 @@ static struct apk_repository_list *apk_repository_new(const char *url) return r; } -enum { - OPT_GLOBAL_allow_untrusted, - OPT_GLOBAL_arch, - OPT_GLOBAL_cache_dir, - OPT_GLOBAL_cache_max_age, - OPT_GLOBAL_force, - OPT_GLOBAL_force_binary_stdout, - OPT_GLOBAL_force_broken_world, - OPT_GLOBAL_force_non_repository, - OPT_GLOBAL_force_old_apk, - OPT_GLOBAL_force_overwrite, - OPT_GLOBAL_force_refresh, - OPT_GLOBAL_help, - OPT_GLOBAL_interactive, - OPT_GLOBAL_keys_dir, - OPT_GLOBAL_no_cache, - OPT_GLOBAL_no_network, - OPT_GLOBAL_no_progress, - OPT_GLOBAL_print_arch, - OPT_GLOBAL_progress, - OPT_GLOBAL_progress_fd, - OPT_GLOBAL_purge, - OPT_GLOBAL_quiet, - OPT_GLOBAL_repositories_file, - OPT_GLOBAL_repository, - OPT_GLOBAL_root, - OPT_GLOBAL_update_cache, - OPT_GLOBAL_verbose, - OPT_GLOBAL_version, - OPT_GLOBAL_wait, -#ifdef TEST_MODE - OPT_GLOBAL_test_instdb, - OPT_GLOBAL_test_repo, - OPT_GLOBAL_test_world, -#endif -}; +#define GLOBAL_OPTIONS(OPT) \ + OPT(OPT_GLOBAL_allow_untrusted, "allow-untrusted") \ + OPT(OPT_GLOBAL_arch, APK_OPT_ARG "arch") \ + OPT(OPT_GLOBAL_cache_dir, APK_OPT_ARG "cache-dir") \ + OPT(OPT_GLOBAL_cache_max_age, APK_OPT_ARG "cache-max-age") \ + OPT(OPT_GLOBAL_force, APK_OPT_SH("f") "force") \ + OPT(OPT_GLOBAL_force_binary_stdout, "force-binary-stdout") \ + OPT(OPT_GLOBAL_force_broken_world, "force-broken-world") \ + OPT(OPT_GLOBAL_force_non_repository, "force-non-repository") \ + OPT(OPT_GLOBAL_force_old_apk, "force-old-apk") \ + OPT(OPT_GLOBAL_force_overwrite, "force-overwrite") \ + OPT(OPT_GLOBAL_force_refresh, "force-refresh") \ + OPT(OPT_GLOBAL_help, APK_OPT_SH("h") "help") \ + OPT(OPT_GLOBAL_interactive, APK_OPT_SH("i") "interactive") \ + OPT(OPT_GLOBAL_keys_dir, APK_OPT_ARG "keys-dir") \ + OPT(OPT_GLOBAL_no_cache, "no-cache") \ + OPT(OPT_GLOBAL_no_network, "no-network") \ + OPT(OPT_GLOBAL_no_progress, "no-progress") \ + OPT(OPT_GLOBAL_print_arch, "print-arch") \ + OPT(OPT_GLOBAL_progress, "progress") \ + OPT(OPT_GLOBAL_progress_fd, APK_OPT_ARG "progress-fd") \ + OPT(OPT_GLOBAL_purge, "purge") \ + OPT(OPT_GLOBAL_quiet, APK_OPT_SH("q") "quiet") \ + OPT(OPT_GLOBAL_repositories_file, APK_OPT_ARG "repositories-file") \ + OPT(OPT_GLOBAL_repository, APK_OPT_ARG APK_OPT_SH("x") "repository") \ + OPT(OPT_GLOBAL_root, APK_OPT_ARG APK_OPT_SH("p") "root") \ + OPT(OPT_GLOBAL_update_cache, APK_OPT_SH("U") "update-cache") \ + OPT(OPT_GLOBAL_verbose, APK_OPT_SH("v") "verbose") \ + OPT(OPT_GLOBAL_version, APK_OPT_SH("V") "version") \ + OPT(OPT_GLOBAL_wait, APK_OPT_ARG "wait") \ + +#define TEST_OPTIONS(OPT) \ + OPT(OPT_GLOBAL_test_instdb, APK_OPT_ARG "test-instdb") \ + OPT(OPT_GLOBAL_test_repo, APK_OPT_ARG "test-repo") \ + OPT(OPT_GLOBAL_test_world, APK_OPT_ARG "test-world") + -static const char optiondesc_global[] = - APK_OPTGROUP("Global") - APK_OPT1n("allow-untrusted") - APK_OPT1R("arch") - APK_OPT1R("cache-dir") - APK_OPT1R("cache-max-age") - APK_OPT2n("force", "f") - APK_OPT1n("force-binary-stdout") - APK_OPT1n("force-broken-world") - APK_OPT1n("force-non-repository") - APK_OPT1n("force-old-apk") - APK_OPT1n("force-overwrite") - APK_OPT1n("force-refresh") - APK_OPT2n("help", "h") - APK_OPT2n("interactive", "i") - APK_OPT1R("keys-dir") - APK_OPT1n("no-cache") - APK_OPT1n("no-network") - APK_OPT1n("no-progress") - APK_OPT1n("print-arch") - APK_OPT1n("progress") - APK_OPT1R("progress-fd") - APK_OPT1n("purge") - APK_OPT2n("quiet", "q") - APK_OPT1R("repositories-file") - APK_OPT2R("repository", "X") - APK_OPT2R("root", "p") - APK_OPT2n("update-cache", "U") - APK_OPT2n("verbose", "v") - APK_OPT2n("version", "V") - APK_OPT1R("wait") #ifdef TEST_MODE - APK_OPT1R("test-instdb") - APK_OPT1R("test-repo") - APK_OPT1R("test-world") +APK_OPT_GROUP2(optiondesc_global, "Global", GLOBAL_OPTIONS, TEST_OPTIONS); +#else +APK_OPT_GROUP(optiondesc_global, "Global", GLOBAL_OPTIONS); #endif - ; static int option_parse_global(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { @@ -266,23 +234,15 @@ const struct apk_option_group optgroup_global = { .parse = option_parse_global, }; -enum { - OPT_COMMIT_clean_protected, - OPT_COMMIT_initramfs_diskless_boot, - OPT_COMMIT_no_commit_hooks, - OPT_COMMIT_no_scripts, - OPT_COMMIT_overlay_from_stdin, - OPT_COMMIT_simulate, -}; +#define COMMIT_OPTIONS(OPT) \ + OPT(OPT_COMMIT_clean_protected, "clean-protected") \ + OPT(OPT_COMMIT_initramfs_diskless_boot, "initramfs-diskless-boot") \ + OPT(OPT_COMMIT_no_commit_hooks, "no-commit-hooks") \ + OPT(OPT_COMMIT_no_scripts, "no-scripts") \ + OPT(OPT_COMMIT_overlay_from_stdin, "overlay-from-stdin") \ + OPT(OPT_COMMIT_simulate, APK_OPT_SH("s") "simulate") -static const char optiondesc_commit[] = - APK_OPTGROUP("commit") - APK_OPT1n("clean-protected") - APK_OPT1n("initramfs-diskless-boot") - APK_OPT1n("no-commit-hooks") - APK_OPT1n("no-scripts") - APK_OPT1n("overlay-from-stdin") - APK_OPT2n("simulate", "s"); +APK_OPT_GROUP(optiondesc_commit, "Commit", COMMIT_OPTIONS); static int option_parse_commit(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { @@ -387,7 +347,7 @@ static int parse_options(int argc, char **argv, struct apk_applet *applet, void opt->has_arg = required_argument; d++; } - num_short = 1; + num_short = 0; if ((unsigned char)*d >= 0xf0) num_short = *d++ & 0x0f; for (; num_short > 0; num_short--) { diff --git a/src/apk_applet.h b/src/apk_applet.h index e682314..3bc2eb9 100644 --- a/src/apk_applet.h +++ b/src/apk_applet.h @@ -15,12 +15,33 @@ #include "apk_defines.h" #include "apk_database.h" -#define APK_OPTAPPLET "\x00" -#define APK_OPTGROUP(_name) _name "\x00" +#if 0 #define APK_OPT1n(_opt) "\xf0" _opt "\x00" #define APK_OPT1R(_opt) "\xaf" "\xf0" _opt "\x00" #define APK_OPT2n(_opt, _short) _short _opt "\x00" #define APK_OPT2R(_opt, _short) "\xaf" _short _opt "\x00" +#endif + +#define __APK_OPTAPPLET "\x00" +#define __APK_OPTGROUP(_name) _name "\x00" +#define __APK_OPT_ENUM(_enum,__desc) _enum, +#define __APK_OPT_DESC(_enum,__desc) __desc "\x00" + +#define APK_OPT_ARG "\xaf" +#define APK_OPT_SH(x) "\xf1" x +#define APK_OPT_S2(x) "\xf2" x + +#define APK_OPT_APPLET(var_name, init_macro) \ + enum { init_macro(__APK_OPT_ENUM) }; \ + static const char var_name[] = __APK_OPTAPPLET init_macro(__APK_OPT_DESC); + +#define APK_OPT_GROUP(var_name, group_name, init_macro) \ + enum { init_macro(__APK_OPT_ENUM) }; \ + static const char var_name[] = __APK_OPTGROUP(group_name) init_macro(__APK_OPT_DESC); + +#define APK_OPT_GROUP2(var_name, group_name, init_macro, init_macro2) \ + enum { init_macro(__APK_OPT_ENUM) init_macro2(__APK_OPT_ENUM) }; \ + static const char var_name[] = __APK_OPTGROUP(group_name) init_macro(__APK_OPT_DESC) init_macro2(__APK_OPT_DESC); struct apk_option_group { const char *desc; diff --git a/src/app_add.c b/src/app_add.c index 1f6c875..f4acd22 100644 --- a/src/app_add.c +++ b/src/app_add.c @@ -21,21 +21,14 @@ struct add_ctx { unsigned short extract_flags; }; -enum { - OPT_ADD_initdb, - OPT_ADD_latest, - OPT_ADD_no_chown, - OPT_ADD_upgrade, - OPT_ADD_virtual, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT1n("initdb") - APK_OPT2n("latest", "l") - APK_OPT1n("no-chown") - APK_OPT2n("upgrade", "u") - APK_OPT2R("virtual", "t"); +#define ADD_OPTIONS(OPT) \ + OPT(OPT_ADD_initdb, "initdb") \ + OPT(OPT_ADD_latest, APK_OPT_SH("l") "latest") \ + OPT(OPT_ADD_no_chown, "no-chown") \ + OPT(OPT_ADD_upgrade, APK_OPT_SH("u") "upgrade") \ + OPT(OPT_ADD_virtual, APK_OPT_ARG APK_OPT_SH("t") "virtual") + +APK_OPT_APPLET(option_desc, ADD_OPTIONS); static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { diff --git a/src/app_audit.c b/src/app_audit.c index 011a26c..9b410c5 100644 --- a/src/app_audit.c +++ b/src/app_audit.c @@ -35,21 +35,14 @@ struct audit_ctx { unsigned packages_only : 1; }; -enum { - OPT_AUDIT_backup, - OPT_AUDIT_check_permissions, - OPT_AUDIT_packages, - OPT_AUDIT_recursive, - OPT_AUDIT_system, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT1n("backup") - APK_OPT1n("check-permissions") - APK_OPT1n("packages") - APK_OPT2n("recursive", "r") - APK_OPT1n("system"); +#define AUDIT_OPTIONS(OPT) \ + OPT(OPT_AUDIT_backup, "backup") \ + OPT(OPT_AUDIT_check_permissions, "check-permissions") \ + OPT(OPT_AUDIT_packages, "packages") \ + OPT(OPT_AUDIT_recursive, APK_OPT_SH("r") "recursive") \ + OPT(OPT_AUDIT_system, "system") + +APK_OPT_APPLET(option_desc, AUDIT_OPTIONS); static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { diff --git a/src/app_cache.c b/src/app_cache.c index 8f38807..f4dd951 100644 --- a/src/app_cache.c +++ b/src/app_cache.c @@ -28,15 +28,11 @@ struct cache_ctx { unsigned short solver_flags; }; -enum { - OPT_CACHE_latest, - OPT_CACHE_upgrade, -}; +#define CACHE_OPTIONS(OPT) \ + OPT(OPT_CACHE_latest, APK_OPT_SH("l") "latest") \ + OPT(OPT_CACHE_upgrade, APK_OPT_SH("u") "upgrade") -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2n("latest", "l") - APK_OPT2n("upgrade", "u"); +APK_OPT_APPLET(option_desc, CACHE_OPTIONS); static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { diff --git a/src/app_del.c b/src/app_del.c index 32398b3..aa7ab4f 100644 --- a/src/app_del.c +++ b/src/app_del.c @@ -19,13 +19,10 @@ struct del_ctx { int errors; }; -enum { - OPT_DEL_redepends, -}; +#define DEL_OPTIONS(OPT) \ + OPT(OPT_DEL_redepends, APK_OPT_SH("r") "rdepends") -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2n("rdepends", "r"); +APK_OPT_APPLET(option_desc, DEL_OPTIONS); static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int opt, const char *optarg) { diff --git a/src/app_dot.c b/src/app_dot.c index 89e385a..ad9167c 100644 --- a/src/app_dot.c +++ b/src/app_dot.c @@ -22,15 +22,11 @@ struct dot_ctx { int installed_only : 1; }; -enum { - OPT_DOT_errors, - OPT_DOT_installed, -}; +#define DOT_OPTIONS(OPT) \ + OPT(OPT_DOT_errors, "errors") \ + OPT(OPT_DOT_installed, "installed") -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT1n("errors") - APK_OPT1n("installed"); +APK_OPT_APPLET(option_desc, DOT_OPTIONS); static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int opt, const char *optarg) { diff --git a/src/app_fetch.c b/src/app_fetch.c index e6f4fbe..4704b0b 100644 --- a/src/app_fetch.c +++ b/src/app_fetch.c @@ -66,21 +66,14 @@ static int cup(void) return write(STDOUT_FILENO, buf, len) != len; } -enum { - OPT_FETCH_link, - OPT_FETCH_recursive, - OPT_FETCH_output, - OPT_FETCH_simulate, - OPT_FETCH_stdout, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2n("link", "l") - APK_OPT2n("recursive", "R") - APK_OPT2R("output", "o") - APK_OPT1n("simulate") - APK_OPT2n("stdout", "s"); +#define FETCH_OPTIONS(OPT) \ + OPT(OPT_FETCH_link, APK_OPT_SH("l") "link") \ + OPT(OPT_FETCH_recursive, APK_OPT_SH("R") "recursive") \ + OPT(OPT_FETCH_output, APK_OPT_ARG APK_OPT_SH("o") "output") \ + OPT(OPT_FETCH_simulate, "simulate") \ + OPT(OPT_FETCH_stdout, APK_OPT_SH("s") "stdout") + +APK_OPT_APPLET(option_desc, FETCH_OPTIONS); static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { diff --git a/src/app_fix.c b/src/app_fix.c index 43e6f7e..ccd1e3c 100644 --- a/src/app_fix.c +++ b/src/app_fix.c @@ -22,21 +22,14 @@ struct fix_ctx { int errors; }; -enum { - OPT_FIX_depends, - OPT_FIX_directory_permissions, - OPT_FIX_reinstall, - OPT_FIX_upgrade, - OPT_FIX_xattr, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2n("depends", "d") - APK_OPT1n("directory-permissions") - APK_OPT2n("reinstall", "r") - APK_OPT2n("upgrade", "u") - APK_OPT2n("xattr", "x"); +#define FIX_OPTIONS(OPT) \ + OPT(OPT_FIX_depends, APK_OPT_SH("d") "depends") \ + OPT(OPT_FIX_directory_permissions, "directory-permissions") \ + OPT(OPT_FIX_reinstall, APK_OPT_SH("r") "reinstall") \ + OPT(OPT_FIX_upgrade, APK_OPT_SH("u") "upgrade") \ + OPT(OPT_FIX_xattr, APK_OPT_SH("x") "xattr") + +APK_OPT_APPLET(option_desc, FIX_OPTIONS); static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int opt, const char *optarg) { diff --git a/src/app_index.c b/src/app_index.c index 53e53b0..18c240f 100644 --- a/src/app_index.c +++ b/src/app_index.c @@ -33,21 +33,14 @@ struct index_ctx { unsigned short index_flags; }; -enum { - OPT_INDEX_description, - OPT_INDEX_index, - OPT_INDEX_no_warnings, - OPT_INDEX_output, - OPT_INDEX_rewrite_arch, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2R("description", "d") - APK_OPT2R("index", "x") - APK_OPT1n("no-warnings") - APK_OPT2R("output", "o") - APK_OPT1R("rewrite-arch"); +#define INDEX_OPTIONS(OPT) \ + OPT(OPT_INDEX_description, APK_OPT_ARG APK_OPT_SH("d") "description") \ + OPT(OPT_INDEX_index, APK_OPT_ARG APK_OPT_SH("x") "index") \ + OPT(OPT_INDEX_no_warnings, "no-warnings") \ + OPT(OPT_INDEX_output, APK_OPT_ARG APK_OPT_SH("o") "output") \ + OPT(OPT_INDEX_rewrite_arch, APK_OPT_ARG "rewrite-arch") + +APK_OPT_APPLET(option_desc, INDEX_OPTIONS); static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { 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) { 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) { diff --git a/src/app_search.c b/src/app_search.c index 5f6f431..866bb7a 100644 --- a/src/app_search.c +++ b/src/app_search.c @@ -72,23 +72,15 @@ static void print_rdepends(struct search_ctx *ctx, struct apk_package *pkg) apk_pkg_foreach_reverse_dependency(pkg, ctx->matches, print_rdep_pkg, ctx); } -enum { - OPT_SEARCH_all, - OPT_SEARCH_description, - OPT_SEARCH_exact, - OPT_SEARCH_has_origin, - OPT_SEARCH_origin, - OPT_SEARCH_rdepends, -}; - -static const char option_desc[] = - APK_OPTAPPLET - APK_OPT2n("all", "a") - APK_OPT2n("description", "d") - APK_OPT2n("exact", "\xf2""ex") - APK_OPT1n("has-origin") - APK_OPT2n("origin", "o") - APK_OPT2n("rdepends", "r"); +#define SEARCH_OPTIONS(OPT) \ + OPT(OPT_SEARCH_all, APK_OPT_SH("a") "all") \ + OPT(OPT_SEARCH_description, APK_OPT_SH("d") "description") \ + OPT(OPT_SEARCH_exact, APK_OPT_S2("ex") "exact") \ + OPT(OPT_SEARCH_has_origin, "has-origin") \ + OPT(OPT_SEARCH_origin, APK_OPT_SH("o") "origin") \ + OPT(OPT_SEARCH_rdepends, APK_OPT_SH("r") "rdepends") \ + +APK_OPT_APPLET(option_desc, SEARCH_OPTIONS); static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg) { 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) { 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) { |