diff options
author | William Pitcock <nenolod@dereferenced.org> | 2018-01-29 02:55:29 +0000 |
---|---|---|
committer | William Pitcock <nenolod@dereferenced.org> | 2018-01-29 02:55:29 +0000 |
commit | 368b8b672521ee3f001d074da5dec47273c87770 (patch) | |
tree | 3ba2c098849d65d6b2c8da88e929d2664e89a0a0 /src | |
parent | 8fcb57bf0f80cec68ce24ef5d9305f23a8d99779 (diff) | |
download | apk-tools-368b8b672521ee3f001d074da5dec47273c87770.tar.gz apk-tools-368b8b672521ee3f001d074da5dec47273c87770.tar.bz2 apk-tools-368b8b672521ee3f001d074da5dec47273c87770.tar.xz apk-tools-368b8b672521ee3f001d074da5dec47273c87770.zip |
list: add --depends option for searching based on rdepends
Diffstat (limited to 'src')
-rw-r--r-- | src/list.c | 30 |
1 files changed, 27 insertions, 3 deletions
@@ -25,6 +25,7 @@ struct list_ctx { unsigned int available : 1; unsigned int upgradable : 1; unsigned int match_origin : 1; + unsigned int match_depends : 1; struct apk_string_array *filters; }; @@ -145,16 +146,35 @@ static void filter_package(const struct apk_package *pkg, const struct list_ctx print_package(pkg, ctx); } +static void iterate_providers(const struct apk_name *name, const struct list_ctx *ctx) +{ + struct apk_provider *p; + + foreach_array_item(p, name->providers) + { + if (p->pkg->name != name) + continue; + + filter_package(p->pkg, ctx); + } +} + static void print_result(struct apk_database *db, const char *match, struct apk_name *name, void *pctx) { struct list_ctx *ctx = pctx; - struct apk_provider *p; if (name == NULL) return; - foreach_array_item(p, name->providers) - filter_package(p->pkg, ctx); + if (ctx->match_depends) + { + struct apk_name **pname; + + foreach_array_item(pname, name->rdepends) + iterate_providers(*pname, ctx); + } + else + iterate_providers(name, ctx); } static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int optch, const char *optarg) @@ -183,6 +203,9 @@ static int option_parse_applet(void *pctx, struct apk_db_options *dbopts, int op case 'o': ctx->match_origin = 1; break; + case 'd': + ctx->match_depends = 1; + break; default: return -1; } @@ -196,6 +219,7 @@ static const struct apk_option options_applet[] = { { 'a', "available", "List available packages only" }, { 'u', "upgradable", "List upgradable packages only" }, { 'o', "origin", "List packages by origin" }, + { 'd', "depends", "List packages by dependency" }, }; static const struct apk_option_group optgroup_applet = { |