From 082efc35356d28ef70a61f72f1920122a9d3a7a2 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 25 Jan 2011 02:55:34 +0100 Subject: [PATCH] Added xbps_callback_array_iter() and use it in xbps-bin to list missing pkgdeps. --- bin/xbps-bin/install.c | 15 +++++---------- include/xbps_api.h | 18 +++++++++++++++++- lib/plist.c | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 14 deletions(-) diff --git a/bin/xbps-bin/install.c b/bin/xbps-bin/install.c index b9b62998..5187012d 100644 --- a/bin/xbps-bin/install.c +++ b/bin/xbps-bin/install.c @@ -50,26 +50,21 @@ struct transaction { static int show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done) { - const char *reqpkg; - (void)arg; (void)loop_done; - reqpkg = prop_string_cstring_nocopy(obj); - if (reqpkg == NULL) - return EINVAL; + fprintf(stderr, " * Missing binary package for: %s\n", + prop_string_cstring_nocopy(obj)); - fprintf(stderr, " * Missing binary package for: %s\n", reqpkg); return 0; } static void -show_missing_deps(prop_dictionary_t d) +show_missing_deps(prop_array_t a) { fprintf(stderr, "xbps-bin: unable to locate some required packages:\n"); - (void)xbps_callback_array_iter_in_dict(d, "missing_deps", - show_missing_dep_cb, NULL); + (void)xbps_callback_array_iter(a, show_missing_dep_cb, NULL); } static int @@ -644,7 +639,7 @@ xbps_exec_transaction(bool yes) if (errno == ENODEV) { /* missing packages */ array = xbps_transaction_missingdeps_get(); - show_missing_deps(trans->dict); + show_missing_deps(array); goto out; } xbps_dbg_printf("Empty transaction dictionary: %s\n", diff --git a/include/xbps_api.h b/include/xbps_api.h index 3a71b6a5..e2abd6c4 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -53,7 +53,7 @@ * @def XBPS_RELVER * Current library release date. */ -#define XBPS_RELVER "20110124" +#define XBPS_RELVER "20110125" /** * @def XBPS_META_PATH @@ -343,6 +343,22 @@ bool xbps_add_obj_to_dict(prop_dictionary_t dict, */ bool xbps_add_obj_to_array(prop_array_t array, prop_object_t obj); +/** + * Executes a function callback specified in \a fn with \a arg paassed + * as its argument into they array \a array. + * + * @param[in] array Proplib array to iterate. + * @param[in] fn Function callback to run on every object in the array. + * While running the function callback, the hird parameter (a pointer to + * a boolean) can be set to true to stop immediately the loop. + * @param[in] arg Argument to be passed to the function callback. + * + * @return 0 on success, otherwise an errno value is set appropiately. + */ +int xbps_callback_array_iter(prop_array_t array, + int (*fn)(prop_object_t, void *, bool *), + void *arg); + /** * Executes a function callback into the array associated with key \a key, * contained in a proplib dictionary. diff --git a/lib/plist.c b/lib/plist.c index 1e8037c2..7b8dd3cb 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2008-2010 Juan Romero Pardines. + * Copyright (c) 2008-2011 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -76,7 +76,35 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj) } int -xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key, +xbps_callback_array_iter(prop_array_t array, + int (*fn)(prop_object_t, void *, bool *), + void *arg) +{ + prop_object_t obj; + prop_object_iterator_t iter; + int rv = 0; + bool loop_done = false; + + assert(array != NULL); + assert(fn != NULL); + + iter = prop_array_iterator(array); + if (iter == NULL) + return ENOMEM; + + while ((obj = prop_object_iterator_next(iter)) != NULL) { + rv = (*fn)(obj, arg, &loop_done); + if (rv != 0 || loop_done) + break; + } + prop_object_iterator_release(iter); + + return rv; +} + +int +xbps_callback_array_iter_in_dict(prop_dictionary_t dict, + const char *key, int (*fn)(prop_object_t, void *, bool *), void *arg) { @@ -106,7 +134,9 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict, const char *key, int xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict, - const char *key, int (*fn)(prop_object_t, void *, bool *), void *arg) + const char *key, + int (*fn)(prop_object_t, void *, bool *), + void *arg) { prop_array_t array; prop_object_t obj;