From 549b5e2e3600322c644b6ba413fbb06209c6158e Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 28 Oct 2011 23:02:07 +0200 Subject: [PATCH] xbps-{bin,repo}: dynamically print all objs in the 'show-files' target. --- bin/xbps-bin/util.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/bin/xbps-bin/util.c b/bin/xbps-bin/util.c index f723ede9..e1232231 100644 --- a/bin/xbps-bin/util.c +++ b/bin/xbps-bin/util.c @@ -95,38 +95,34 @@ show_pkg_info(prop_dictionary_t dict) int show_pkg_files(prop_dictionary_t filesd) { - prop_array_t array; - prop_object_iterator_t iter = NULL; + prop_array_t array, allkeys; prop_object_t obj; - const char *file, *array_str, *target; - int i = 0; + prop_dictionary_keysym_t ksym; + const char *keyname, *file; + size_t i, x; - /* This will print links, conf_files and files respectively. */ - for (i = 0; i < 3; i++) { - if (i == 0) - array_str = "links"; - else if (i == 1) - array_str = "conf_files"; - else - array_str = "files"; - - array = prop_dictionary_get(filesd, array_str); - if (array == NULL || prop_array_count(array) == 0) + allkeys = prop_dictionary_all_keys(filesd); + for (i = 0; i < prop_array_count(allkeys); i++) { + ksym = prop_array_get(allkeys, i); + keyname = prop_dictionary_keysym_cstring_nocopy(ksym); + if (strcmp(keyname, "dirs") == 0) continue; - iter = xbps_array_iter_from_dict(filesd, array_str); - if (iter == NULL) - return EINVAL; + array = prop_dictionary_get(filesd, keyname); + if (prop_object_type(array) != PROP_TYPE_ARRAY || + prop_array_count(array) == 0) + continue; - while ((obj = prop_object_iterator_next(iter))) { + for (x = 0; x < prop_array_count(array); x++) { + obj = prop_array_get(array, x); prop_dictionary_get_cstring_nocopy(obj, "file", &file); printf("%s", file); if (prop_dictionary_get_cstring_nocopy(obj, - "target", &target)) - printf(" -> %s", target); + "target", &file)) + printf(" -> %s", file); + printf("\n"); } - prop_object_iterator_release(iter); } return 0;