summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2023-03-04 18:39:14 +0200
committerTimo Teräs <timo.teras@iki.fi>2023-04-11 20:47:43 +0300
commit18b8d1e8ad877eb1eaad5216b821c0fb8394c76b (patch)
treebea338338dc048433f804bd62d86b579551a65f3
parentb72ba58207742d044b2933bb2f2ddd3051009aee (diff)
downloadapk-tools-18b8d1e8ad877eb1eaad5216b821c0fb8394c76b.tar.gz
apk-tools-18b8d1e8ad877eb1eaad5216b821c0fb8394c76b.tar.bz2
apk-tools-18b8d1e8ad877eb1eaad5216b821c0fb8394c76b.tar.xz
apk-tools-18b8d1e8ad877eb1eaad5216b821c0fb8394c76b.zip
search: always use apk_db_foreach_sorted_name and fnmatch
To make the search output and experience more consistent.
-rw-r--r--src/app_search.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/app_search.c b/src/app_search.c
index 3651ec6..fd9bd40 100644
--- a/src/app_search.c
+++ b/src/app_search.c
@@ -92,7 +92,6 @@ static int option_parse_applet(void *ctx, struct apk_db_options *dbopts, int opt
break;
case OPT_SEARCH_description:
ictx->search_description = 1;
- ictx->search_exact = 1;
ictx->show_all = 1;
break;
case OPT_SEARCH_exact:
@@ -126,15 +125,16 @@ static void print_result_pkg(struct search_ctx *ctx, struct apk_package *pkg)
if (ctx->search_description) {
foreach_array_item(pmatch, ctx->filter) {
- if (strstr(pkg->description, *pmatch) != NULL ||
- strstr(pkg->name->name, *pmatch) != NULL)
+ if (fnmatch(*pmatch, pkg->description, 0) == 0 ||
+ fnmatch(*pmatch, pkg->name->name, 0) == 0)
goto match;
}
return;
}
if (ctx->search_origin) {
foreach_array_item(pmatch, ctx->filter) {
- if (pkg->origin && apk_blob_compare(APK_BLOB_STR(*pmatch), *pkg->origin) == 0)
+ if (!pkg->origin) continue;
+ if (apk_blob_compare(APK_BLOB_STR(*pmatch), *pkg->origin) == 0)
goto match;
}
return;
@@ -166,12 +166,6 @@ static int print_result(struct apk_database *db, const char *match, struct apk_n
return 0;
}
-static int print_pkg(apk_hash_item item, void *pctx)
-{
- print_result_pkg((struct search_ctx *) pctx, (struct apk_package *) item);
- return 0;
-}
-
static int search_main(void *pctx, struct apk_database *db, struct apk_string_array *args)
{
struct search_ctx *ctx = (struct search_ctx *) pctx;
@@ -184,8 +178,11 @@ static int search_main(void *pctx, struct apk_database *db, struct apk_string_ar
if (ctx->print_result == NULL)
ctx->print_result = ctx->print_package;
- if (ctx->search_description || ctx->search_origin)
- return apk_hash_foreach(&db->available.packages, print_pkg, ctx);
+ if (ctx->search_description || ctx->search_origin) {
+ // Just enumerate all names in sorted order, and do the
+ // filtering in the callback.
+ args = NULL;
+ }
if (!ctx->search_exact) {
foreach_array_item(pmatch, ctx->filter) {