xbps-bin: simplify previous.

--HG--
extra : convert_revision : 30d4433b86c4a60fe56a98cb011f3534273818b3
This commit is contained in:
Juan RP 2008-12-19 23:36:30 +01:00
parent db0484ae6e
commit edc4a572bb
3 changed files with 38 additions and 30 deletions

View File

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

View File

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

View File

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