Added xbps_callback_array_iter() and use it in xbps-bin to list missing pkgdeps.

This commit is contained in:
Juan RP 2011-01-25 02:55:34 +01:00
parent 61fbf17bb9
commit 082efc3535
3 changed files with 55 additions and 14 deletions

View File

@ -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",

View File

@ -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.

View File

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