From 6698f3a1ffded8da1d3f375aec5411268422b20c Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 20 Dec 2008 04:53:56 +0100 Subject: [PATCH] Make xbps_callback_array_in_dict() return a bool. The func cb accepted also returns a bool now. --HG-- extra : convert_revision : 1adf9a54e111f5d7f3dd78a829c3cf680d15f769 --- utils/plist.c | 44 ++++++++++++++++++++++++++++---------------- utils/plist.h | 18 ++++++++++++------ utils/xbps-pkgdb.c | 5 +++-- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/utils/plist.c b/utils/plist.c index aa8a3b5dc44..ac198f7a22b 100644 --- a/utils/plist.c +++ b/utils/plist.c @@ -33,7 +33,7 @@ #include "xbps_api.h" -static void xbps_list_strings_in_array2(prop_object_t); +static bool xbps_list_strings_in_array2(prop_object_t); bool xbps_add_obj_to_dict(prop_dictionary_t dict, prop_object_t obj, @@ -64,24 +64,29 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj) return true; } -void +bool xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key, - void (*func)(prop_object_t)) + bool (*func)(prop_object_t)) { prop_object_iterator_t iter; prop_object_t obj; if (func == NULL) - return; + return false; iter = xbps_get_array_iter_from_dict(dict, key); if (iter == NULL) - return; + return false; - while ((obj = prop_object_iterator_next(iter))) - (*func)(obj); + while ((obj = prop_object_iterator_next(iter))) { + if (!(*func)(obj)) { + prop_object_iterator_release(iter); + return false; + } + } prop_object_iterator_release(iter); + return true; } prop_dictionary_t @@ -250,9 +255,10 @@ xbps_show_pkg_info(prop_dictionary_t dict) } else if (prop_object_type(obj2) == PROP_TYPE_ARRAY) { printf("\n\t"); - xbps_callback_array_iter_in_dict(dict, + if (!xbps_callback_array_iter_in_dict(dict, prop_dictionary_keysym_cstring_nocopy(obj), - xbps_list_strings_in_array2); + xbps_list_strings_in_array2)) + return; printf("\n"); } } @@ -260,28 +266,32 @@ xbps_show_pkg_info(prop_dictionary_t dict) prop_object_iterator_release(iter); } -void +bool xbps_list_pkgs_in_dict(prop_object_t obj) { const char *pkgname, *version, *short_desc; if (prop_object_type(obj) != PROP_TYPE_DICTIONARY) - return; + return false; prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "version", &version); prop_dictionary_get_cstring_nocopy(obj, "short_desc", &short_desc); - if (pkgname && version && short_desc) + if (pkgname && version && short_desc) { printf("%s (%s)\t%s\n", pkgname, version, short_desc); + return true; + } + + return false; } -static void +static bool xbps_list_strings_in_array2(prop_object_t obj) { static uint16_t count; if (prop_object_type(obj) != PROP_TYPE_STRING) - return; + return false; if (count == 4) { printf("\n\t"); @@ -290,13 +300,15 @@ xbps_list_strings_in_array2(prop_object_t obj) printf("%s ", prop_string_cstring_nocopy(obj)); count++; + return true; } -void +bool xbps_list_strings_in_array(prop_object_t obj) { if (prop_object_type(obj) != PROP_TYPE_STRING) - return; + return false; printf("%s\n", prop_string_cstring_nocopy(obj)); + return true; } diff --git a/utils/plist.h b/utils/plist.h index d43374d734e..c8a00de5ba2 100644 --- a/utils/plist.h +++ b/utils/plist.h @@ -59,10 +59,12 @@ xbps_add_obj_to_array(prop_array_t, prop_object_t); * - prop_dictionary_t: dictionary to search on. * - const char *: key of the array. * - (*func)(prop_object_t): callback associated. + * + * Returns true on success, false otherwise and the loop is terminated. */ -void +bool xbps_callback_array_iter_in_dict(prop_dictionary_t, const char *, - void (*func)(prop_object_t)); + bool (*func)(prop_object_t)); /* * Finds a package's dictionary into the main dictionary. @@ -83,7 +85,7 @@ xbps_find_pkg_in_dict(prop_dictionary_t, const char *); * - prop_array_t: array to search for the string. * - const char *: string value of the object to be found. * - * Returns true on success, false on failure. + * Returns true on success, false otherwise. */ bool xbps_find_string_in_array(prop_array_t, const char *); @@ -106,8 +108,10 @@ xbps_get_array_iter_from_dict(prop_dictionary_t, const char *); * * Arguments: * - prop_object_t: the object to be processed. + * + * Returns true on success, false otherwise. */ -void +bool xbps_list_pkgs_in_dict(prop_object_t); /* @@ -115,8 +119,10 @@ xbps_list_pkgs_in_dict(prop_object_t); * * Arguments: * - prop_object_t: the object to be processed. + * + * Returns true on success, false otherwise. */ -void +bool xbps_list_strings_in_array(prop_object_t); /* @@ -125,7 +131,7 @@ xbps_list_strings_in_array(prop_object_t); * Arguments: * - const char *: URI to register. * - * Returns true on success, false on failure. + * Returns true on success, false otherwise. */ bool xbps_register_repository(const char *); diff --git a/utils/xbps-pkgdb.c b/utils/xbps-pkgdb.c index cdc51e95ab2..46d74dd7f73 100644 --- a/utils/xbps-pkgdb.c +++ b/utils/xbps-pkgdb.c @@ -291,8 +291,9 @@ main(int argc, char **argv) usage(); dbdict = prop_dictionary_internalize_from_file(dbfile); - xbps_callback_array_iter_in_dict(dbdict, - "packages", xbps_list_pkgs_in_dict); + if (!xbps_callback_array_iter_in_dict(dbdict, + "packages", xbps_list_pkgs_in_dict)) + exit(EINVAL); } else if (strcmp(argv[1], "version") == 0) { /* Prints version of an installed package */