From a359a31ffc36630c385ac9ebdf06b6f20e8401f6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 28 Jun 2010 11:36:35 -0500 Subject: Now iterating through the collection and printing those entries out. --- tools/dbusmenu-dumper.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'tools') diff --git a/tools/dbusmenu-dumper.c b/tools/dbusmenu-dumper.c index 1bf6e43..724ee25 100644 --- a/tools/dbusmenu-dumper.c +++ b/tools/dbusmenu-dumper.c @@ -29,15 +29,50 @@ with this program. If not, see . static GMainLoop * mainloop = NULL; +typedef struct _collection_iterator_t collection_iterator_t; +struct _collection_iterator_t { + gchar * space; + GPtrArray * array; + gboolean first; +}; + +static void +collection_iterate (const GValue * value, gpointer user_data) +{ + collection_iterator_t * iter = (collection_iterator_t *)user_data; + + gchar * str = g_strdup_value_contents(value); + gchar * retval = NULL; + + if (iter->first) { + iter->first = FALSE; + retval = g_strdup_printf("\n%s%s", iter->space, str); + } else { + retval = g_strdup_printf(",\n%s%s", iter->space, str); + } + + g_ptr_array_add(iter->array, retval); + g_free(str); + + return; +} + static gchar * collection_dumper (const GValue * value, int depth) { gchar * space = g_strnfill(depth, ' '); GPtrArray * array = g_ptr_array_new_with_free_func(g_free); - g_ptr_array_add(array, g_strdup("[\n")); - g_ptr_array_add(array, g_strdup_printf("%s\n", space)); - g_ptr_array_add(array, g_strdup_printf("%s]", space)); + g_ptr_array_add(array, g_strdup("[")); + + collection_iterator_t iter; + iter.space = space; + iter.array = array; + iter.first = TRUE; + + dbus_g_type_collection_value_iterate(value, collection_iterate, &iter); + + g_ptr_array_add(array, g_strdup_printf("\n%s]", space)); g_free(space); -- cgit v1.2.3