From 9795b68febdde5a3077009ef69e8e20abdf77d82 Mon Sep 17 00:00:00 2001 From: James Bowes Date: Thu, 26 Jun 2008 19:11:36 -0400 Subject: Add 'search' command --- src/main.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index c2ecd6e..4532f02 100644 --- a/src/main.c +++ b/src/main.c @@ -860,6 +860,52 @@ command_info(int argc, const char *argv[]) return 0; } +#define SEARCH_MAX 256 + +static int +command_search(int argc, const char *argv[]) +{ + struct razor_set *set; + struct razor_package_iterator *pi; + struct razor_package *package; + char pattern[SEARCH_MAX]; + const char *name, *version, *arch; + const char *summary, *description, *url, *license; + + if (!argv[0]) { + fprintf(stderr, "must specify a search term\n"); + return 1; + } + + sprintf(pattern, "*%s*", argv[0]); + + set = razor_set_open(repo_filename); + if (set == NULL) + return 1; + if (razor_set_open_details(set, "system-details.repo")) + return 1; + + pi = razor_package_iterator_create(set); + while (razor_package_iterator_next(pi, &package, + &name, &version, &arch)) { + if (!fnmatch(pattern, name, 0)) + printf("%s-%s.%s\n", name, version, arch); + else { + razor_package_get_details (set, package, &summary, + &description, &url, + &license); + if (!fnmatch(pattern, url, 0) || + !fnmatch(pattern, summary, 0) || + !fnmatch(pattern, description, 0)) + printf("%s-%s.%s\n", name, version, arch); + } + } + razor_package_iterator_destroy(pi); + razor_set_destroy(set); + + return 0; +} + static struct { const char *name; const char *description; @@ -884,7 +930,8 @@ static struct { { "install", "install rpm", command_install }, { "init", "init razor root", command_init }, { "download", "download packages", command_download }, - { "info", "display package details", command_info } + { "info", "display package details", command_info }, + { "search", "search package details", command_search } }; static int -- cgit v1.2.3