summaryrefslogtreecommitdiff
path: root/src/app_version.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2020-05-04 21:45:11 +0300
committerTimo Teräs <timo.teras@iki.fi>2020-05-06 13:05:25 +0300
commit1d7123d83796182f851ccccaf056063955343718 (patch)
treeca675fd3363af3584694d0db5a3b65e618ae894b /src/app_version.c
parent791f93fcbe7a543e0bb844887ba395be8ed8ea44 (diff)
downloadapk-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_version.c')
-rw-r--r--src/app_version.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/app_version.c b/src/app_version.c
index 33d787e..eb6922d 100644
--- a/src/app_version.c
+++ b/src/app_version.c
@@ -68,26 +68,42 @@ static int ver_validate(struct apk_database *db, struct apk_string_array *args)
return errors;
}
-static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int optch, const char *optarg)
+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");
+
+static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt, const char *optarg)
{
struct ver_ctx *ictx = (struct ver_ctx *) ctx;
- switch (optch) {
- case 'I':
- ictx->action = ver_indexes;
- break;
- case 't':
- ictx->action = ver_test;
- dbopts->open_flags |= APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS;
+ switch (opt) {
+ case OPT_VERSION_all:
+ ictx->all_tags = 1;
break;
- case 'c':
+ case OPT_VERSION_check:
ictx->action = ver_validate;
dbopts->open_flags |= APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS;
break;
- case 'l':
+ case OPT_VERSION_indexes:
+ ictx->action = ver_indexes;
+ break;
+ case OPT_VERSION_limit:
ictx->limchars = optarg;
break;
- case 'a':
- ictx->all_tags = 1;
+ case OPT_VERSION_test:
+ ictx->action = ver_test;
+ dbopts->open_flags |= APK_OPENF_NO_STATE | APK_OPENF_NO_REPOS;
break;
default:
return -ENOTSUP;
@@ -95,18 +111,8 @@ static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt
return 0;
}
-static const struct apk_option options_applet[] = {
- { 'I', "indexes" },
- { 't', "test" },
- { 'c', "check" },
- { 'a', "all" },
- { 'l', "limit", required_argument },
-};
-
static const struct apk_option_group optgroup_applet = {
- .name = "Version",
- .options = options_applet,
- .num_options = ARRAY_SIZE(options_applet),
+ .desc = option_desc,
.parse = option_parse_applet,
};