Make xbps_callback_array_in_dict() return a bool.

The func cb accepted also returns a bool now.

--HG--
extra : convert_revision : 1adf9a54e111f5d7f3dd78a829c3cf680d15f769
This commit is contained in:
Juan RP 2008-12-20 04:53:56 +01:00
parent 835d4e7b7c
commit 6698f3a1ff
3 changed files with 43 additions and 24 deletions

View File

@ -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;
}

View File

@ -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 *);

View File

@ -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 */