diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index 766d4bf0c7b..79b71669528 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -251,7 +251,10 @@ main(int argc, char **argv) } } else if (strcasecmp(argv[0], "search") == 0) { - /* Search for a package by looking at short_desc. */ + /* + * Search for a package by looking at pkgname/short_desc + * by using shell style match patterns (fnmatch(3)). + */ if (argc != 2) usage(); diff --git a/bin/xbps-repo/util.c b/bin/xbps-repo/util.c index 7384d30bc0a..29ca318b2cb 100644 --- a/bin/xbps-repo/util.c +++ b/bin/xbps-repo/util.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -146,7 +147,6 @@ search_string_in_pkgs(prop_object_t obj, void *arg, bool *loop_done) const char *repofile; char *plist; - (void)arg; (void)loop_done; assert(prop_object_type(obj) == PROP_TYPE_STRING); @@ -335,21 +335,21 @@ show_pkg_info_from_repolist(prop_object_t obj, void *arg, bool *loop_done) static int show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done) { - const char *pkgname, *desc, *ver, *string = arg; + const char *pkgname, *desc, *ver, *pattern = arg; - (void)arg; (void)loop_done; assert(prop_object_type(obj) == PROP_TYPE_DICTIONARY); - assert(string != NULL); + assert(pattern != NULL); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc); prop_dictionary_get_cstring_nocopy(obj, "version", &ver); assert(ver != NULL); - if ((strstr(pkgname, string) || strstr(desc, string))) - printf(" %s-%s - %s\n", pkgname, ver, desc); + if ((fnmatch(pattern, pkgname, 0) == 0) || + (fnmatch(pattern, desc, 0) == 0)) + printf(" %s-%s - %s\n", pkgname, ver, desc); return 0; }