diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/search.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/search.c b/src/search.c index b31859d..9ef61a1 100644 --- a/src/search.c +++ b/src/search.c @@ -97,7 +97,7 @@ static int search_parse(void *ctx, struct apk_db_options *dbopts, return 0; } -static void print_result(struct search_ctx *ctx, struct apk_package *pkg) +static void print_result_pkg(struct search_ctx *ctx, struct apk_package *pkg) { int i; @@ -117,23 +117,13 @@ static void print_result(struct search_ctx *ctx, struct apk_package *pkg) ctx->print_result(ctx, pkg); } -static int match_names(apk_hash_item item, void *pctx) +static void print_result(struct search_ctx *ctx, struct apk_name *name) { - struct search_ctx *ctx = (struct search_ctx *) pctx; - struct apk_name *name = (struct apk_name *) item; int i; - if (!ctx->search_description) { - for (i = 0; i < ctx->argc; i++) - if (fnmatch(ctx->argv[i], name->name, FNM_CASEFOLD) == 0) - break; - if (ctx->argc > 0 && i >= ctx->argc) - return 0; - } - if (ctx->show_all) { for (i = 0; i < name->providers->num; i++) - print_result(ctx, name->providers->item[i].pkg); + print_result_pkg(ctx, name->providers->item[i].pkg); } else { struct apk_package *pkg = NULL; struct apk_provider *p; @@ -144,8 +134,25 @@ static int match_names(apk_hash_item item, void *pctx) apk_version_compare_blob(*p->version, *version) == APK_VERSION_GREATER) pkg = p->pkg; } - print_result(ctx, pkg); + print_result_pkg(ctx, pkg); } +} + +static int match_names(apk_hash_item item, void *pctx) +{ + struct search_ctx *ctx = (struct search_ctx *) pctx; + struct apk_name *name = (struct apk_name *) item; + int i; + + if (!ctx->search_description) { + for (i = 0; i < ctx->argc; i++) + if (fnmatch(ctx->argv[i], name->name, FNM_CASEFOLD) == 0) + break; + if (ctx->argc > 0 && i >= ctx->argc) + return 0; + } + print_result(ctx, name); + return 0; } @@ -175,8 +182,11 @@ static int search_main(void *pctx, struct apk_database *db, int argc, char **arg } } else { ctx->argv = argv; - /* FIXME: if not searching descriptions, we can just - * do direct name lookups here */ + if (!ctx->search_description) { + for (i = 0; i < argc; i++) + print_result(ctx, apk_db_get_name(db, APK_BLOB_STR(argv[i]))); + return 0; + } } return apk_hash_foreach(&db->available.names, match_names, ctx); |