diff options
author | Timo Teräs <timo.teras@iki.fi> | 2020-05-04 21:45:11 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2020-05-06 13:05:25 +0300 |
commit | 1d7123d83796182f851ccccaf056063955343718 (patch) | |
tree | ca675fd3363af3584694d0db5a3b65e618ae894b /src/app_list.c | |
parent | 791f93fcbe7a543e0bb844887ba395be8ed8ea44 (diff) | |
download | apk-tools-1d7123d83796182f851ccccaf056063955343718.tar.gz apk-tools-1d7123d83796182f851ccccaf056063955343718.tar.bz2 apk-tools-1d7123d83796182f851ccccaf056063955343718.tar.xz apk-tools-1d7123d83796182f851ccccaf056063955343718.zip |
rewrite option descriptors to be single string
This reduces the number of relocations on PIE binaries, and also
reduces the executable size. Parsing of the options is slightly
sped up as only the exact matching option group parser is called.
Diffstat (limited to 'src/app_list.c')
-rw-r--r-- | src/app_list.c | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/src/app_list.c b/src/app_list.c index f46d30f..7f141f5 100644 --- a/src/app_list.c +++ b/src/app_list.c @@ -187,38 +187,57 @@ static void print_result(struct apk_database *db, const char *match, struct apk_ iterate_providers(name, ctx); } -static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int optch, const char *optarg) +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"); + +static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int opt, const char *optarg) { struct list_ctx *ctx = pctx; - switch (optch) - { - case 'I': + switch (opt) { + case OPT_LIST_available: + ctx->available = 1; + ctx->orphaned = 0; + break; + case OPT_LIST_installed: ctx->installed = 1; break; - case 'O': + case OPT_LIST_depends: + ctx->match_depends = 1; + break; + case OPT_LIST_origin: + ctx->match_origin = 1; + break; + case OPT_LIST_orphaned: ctx->installed = 1; ctx->orphaned = 1; break; - case 'u': + case OPT_LIST_providers: + ctx->match_providers = 1; + break; + case OPT_LIST_upgradeable: ctx->available = 1; ctx->orphaned = 0; ctx->installed = 0; ctx->upgradable = 1; break; - case 'a': - ctx->available = 1; - ctx->orphaned = 0; - break; - case 'o': - ctx->match_origin = 1; - break; - case 'd': - ctx->match_depends = 1; - break; - case 'P': - ctx->match_providers = 1; - break; default: return -ENOTSUP; } @@ -226,20 +245,8 @@ static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int op return 0; } -static const struct apk_option options_applet[] = { - { 'I', "installed" }, - { 'O', "orphaned" }, - { 'a', "available" }, - { 'u', "upgradable" }, - { 'o', "origin" }, - { 'd', "depends" }, - { 'P', "providers" }, -}; - static const struct apk_option_group optgroup_applet = { - .name = "List", - .options = options_applet, - .num_options = ARRAY_SIZE(options_applet), + .desc = option_desc, .parse = option_parse_applet, }; |