From 41d197eb10163b060041fdd8eb682660de30f7f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Thu, 10 Jan 2008 23:42:42 -0500 Subject: [PATCH] Move more front-end logic from razor_set_list_property_packages() to main.c. --- main.c | 47 +++++++++++++++++++++++++++++++++++------------ razor.c | 49 ++++++++++++++----------------------------------- razor.h | 5 ++--- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/main.c b/main.c index 7959617..a39c19f 100644 --- a/main.c +++ b/main.c @@ -137,29 +137,52 @@ command_list_package_files(int argc, const char *argv[]) } static int -command_what_requires(int argc, const char *argv[]) +list_property_packages(const char *ref_name, + const char *ref_version, + enum razor_property_type ref_type) { struct razor_set *set; + struct razor_property *property; + struct razor_property_iterator *pi; + const char *name, *version; + enum razor_property_type type; + + if (ref_name == NULL) + return 0; set = razor_set_open(repo_filename); - razor_set_list_property_packages(set, argv[0], argv[1], - RAZOR_PROPERTY_REQUIRES); - razor_set_destroy(set); + if (set == NULL) + return 1; + + pi = razor_property_iterator_create(set, NULL); + while (razor_property_iterator_next(pi, &property, + &name, &version, &type)) { + if (strcmp(ref_name, name) != 0) + continue; + if (ref_version && strcmp(ref_version, version) != 0) + continue; + if (ref_type != type) + continue; + + razor_set_list_property_packages(set, property); + } + razor_property_iterator_destroy(pi); return 0; } static int -command_what_provides(int argc, const char *argv[]) +command_what_requires(int argc, const char *argv[]) { - struct razor_set *set; - - set = razor_set_open(repo_filename); - razor_set_list_property_packages(set, argv[0], argv[1], - RAZOR_PROPERTY_PROVIDES); - razor_set_destroy(set); + return list_property_packages(argv[0], argv[1], + RAZOR_PROPERTY_REQUIRES); +} - return 0; +static int +command_what_provides(int argc, const char *argv[]) +{ + return list_property_packages(argv[0], argv[1], + RAZOR_PROPERTY_PROVIDES); } static int diff --git a/razor.c b/razor.c index c8a27d0..250e383 100644 --- a/razor.c +++ b/razor.c @@ -621,7 +621,6 @@ versioncmp(const char *s1, const char *s2) return *p1 - *p2; } - static int compare_packages(const void *p1, const void *p2, void *data) { @@ -1059,48 +1058,28 @@ razor_property_iterator_destroy(struct razor_property_iterator *pi) void razor_set_list_property_packages(struct razor_set *set, - const char *ref_name, - const char *ref_version, - enum razor_property_type ref_type) + struct razor_property *property) { - struct razor_property *property; - struct razor_property_iterator *pi; struct razor_package *p, *packages; - const char *name, *version, *pool; - enum razor_property_type type; + const char *pool; unsigned long *r; - if (ref_name == NULL) - return; - packages = set->packages.data; pool = set->string_pool.data; - pi = razor_property_iterator_create(set, NULL); - while (razor_property_iterator_next(pi, &property, - &name, &version, &type)) { - if (strcmp(ref_name, name) != 0) - continue; - if (ref_version && versioncmp(ref_version, version) != 0) - continue; - if (ref_type != type) - continue; - - if (property->packages & RAZOR_IMMEDIATE) - r = &property->packages; - else - r = (unsigned long *) - set->package_pool.data + property->packages; - while (1) { - p = &packages[*r & RAZOR_ENTRY_MASK]; - printf("%s-%s\n", - &pool[p->name & RAZOR_ENTRY_MASK], - &pool[p->version]); - if (*r++ & RAZOR_IMMEDIATE) - break; - } + if (property->packages & RAZOR_IMMEDIATE) + r = &property->packages; + else + r = (unsigned long *) + set->package_pool.data + property->packages; + while (1) { + p = &packages[*r & RAZOR_ENTRY_MASK]; + printf("%s-%s\n", + &pool[p->name & RAZOR_ENTRY_MASK], + &pool[p->version]); + if (*r++ & RAZOR_IMMEDIATE) + break; } - razor_property_iterator_destroy(pi); } static struct razor_entry * diff --git a/razor.h b/razor.h index 7e55d26..92ff6d8 100644 --- a/razor.h +++ b/razor.h @@ -46,9 +46,8 @@ razor_property_iterator_destroy(struct razor_property_iterator *pi); void razor_set_list_properties(struct razor_set *set, const char *name, enum razor_property_type type); void razor_set_list_property_packages(struct razor_set *set, - const char *name, - const char *version, - enum razor_property_type type); + struct razor_property *property); + void razor_set_list_files(struct razor_set *set, const char *prefix); void razor_set_list_file_packages(struct razor_set *set, const char *filename); void razor_set_list_package_files(struct razor_set *set, const char *name); -- 1.7.1