From edc4a572bbc026d14be2770692a46e05d9931608 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 19 Dec 2008 23:36:30 +0100 Subject: [PATCH] xbps-bin: simplify previous. --HG-- extra : convert_revision : 30d4433b86c4a60fe56a98cb011f3534273818b3 --- utils/plist_utils.c | 44 +++++++++++++++++++++----------------------- utils/plist_utils.h | 19 ++++++++++++++++--- utils/xbps-bin.c | 5 +---- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/utils/plist_utils.c b/utils/plist_utils.c index 9a3741f319d..d75c7830b83 100644 --- a/utils/plist_utils.c +++ b/utils/plist_utils.c @@ -62,6 +62,21 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj) return true; } +prop_object_iterator_t +xbps_get_array_iter_from_dict(prop_dictionary_t dict, const char *key) +{ + prop_array_t array; + + if (dict == NULL || key == NULL) + return NULL; + + array = prop_dictionary_get(dict, key); + if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY) + return NULL; + + return prop_array_iterator(array); +} + prop_dictionary_t xbps_find_pkg_in_dict(prop_dictionary_t dict, const char *key, const char *pkgname) @@ -197,27 +212,13 @@ fail: void xbps_list_pkgs_in_dict(prop_dictionary_t dict, const char *key) { - prop_array_t array; - prop_object_t obj; prop_object_iterator_t iter; + prop_object_t obj; const char *pkgname, *version, *short_desc; - if (dict == NULL || key == NULL) { - printf("%s: NULL dict/key\n", __func__); - exit(1); - } - - array = prop_dictionary_get(dict, key); - if (array == NULL || prop_object_type(array) != PROP_TYPE_ARRAY) { - printf("%s: NULL or incorrect array type\n", __func__); - exit(1); - } - - iter = prop_array_iterator(array); - if (iter == NULL) { - printf("%s: NULL iter\n", __func__); - exit(1); - } + iter = xbps_get_array_iter_from_dict(dict, key); + if (iter == NULL) + return; while ((obj = prop_object_iterator_next(iter))) { prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); @@ -232,15 +233,12 @@ xbps_list_pkgs_in_dict(prop_dictionary_t dict, const char *key) } void -xbps_list_strings_in_array(prop_array_t array) +xbps_list_strings_in_array(prop_dictionary_t dict, const char *key) { prop_object_iterator_t iter; prop_object_t obj; - if (array == NULL) - return; - - iter = prop_array_iterator(array); + iter = xbps_get_array_iter_from_dict(dict, key); if (iter == NULL) return; diff --git a/utils/plist_utils.h b/utils/plist_utils.h index 7b575f70092..12b8f8fdf35 100644 --- a/utils/plist_utils.h +++ b/utils/plist_utils.h @@ -76,6 +76,18 @@ xbps_find_pkg_in_dict(prop_dictionary_t, const char *, const char *); bool xbps_find_string_in_array(prop_array_t, const char *); +/* + * Gets an array iterator from a dictionary with a specified key. + * + * Arguments: + * - prop_dictionary_t: dictionary to search the array. + * - const char *: key of the array. + * + * Returns the object iterator, NULL otherwise. + */ +prop_object_iterator_t +xbps_get_array_iter_from_dict(prop_dictionary_t, const char *); + /* * Lists information about all packages found in a dictionary, by * using a triplet: pkgname, version and short_desc. @@ -88,13 +100,14 @@ void xbps_list_pkgs_in_dict(prop_dictionary_t, const char *); /* - * Lists all string values in an array. + * Lists all string values in an array object in a dictionary. * * Arguments: - * - prop_array_t: array where to search on. + * - prop_dictionary_t: dictionary that has the array. + * - const char *: key of the array. */ void -xbps_list_strings_in_array(prop_array_t); +xbps_list_strings_in_array(prop_dictionary_t, const char *); /* * Registers a repository specified by an URI into the pool. diff --git a/utils/xbps-bin.c b/utils/xbps-bin.c index 49612aed308..4b1f70c3e75 100644 --- a/utils/xbps-bin.c +++ b/utils/xbps-bin.c @@ -94,7 +94,6 @@ int main(int argc, char **argv) { prop_dictionary_t dict; - prop_array_t array; repo_info_t *rinfo = NULL; char pkgindex[PATH_MAX], *tmp; @@ -158,9 +157,7 @@ main(int argc, char **argv) exit(EINVAL); } - array = prop_dictionary_get(dict, "repository-list"); - if (array) - xbps_list_strings_in_array(array); + xbps_list_strings_in_array(dict, "repository-list"); } else if (strcmp(argv[1], "show") == 0) { /* Shows info about a binary package. */