summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2009-09-09 20:58:53 +0100
committerColin Walters <walters@verbum.org>2010-01-28 17:01:23 -0500
commit1a33efb54b6a40d48b64c735741298afc699bbd3 (patch)
treedeca10ac354b40f9940dc16c057d7ec76f5caa80
parent3171383ce9bac0c2718da4ce288db890d5d7bfda (diff)
downloaddbus-1a33efb54b6a40d48b64c735741298afc699bbd3.tar.gz
Print byte arrays as nicely-formatted hex.
-rw-r--r--tools/dbus-print-message.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/tools/dbus-print-message.c b/tools/dbus-print-message.c
index 749fca68..f934c7d1 100644
--- a/tools/dbus-print-message.c
+++ b/tools/dbus-print-message.c
@@ -39,12 +39,63 @@ type_to_name (int message_type)
}
}
+#define INDENT 3
static void
indent (int depth)
{
while (depth-- > 0)
- printf (" ");
+ printf (" "); /* INDENT spaces. */
+}
+
+static void
+print_ay (DBusMessageIter *iter, int depth)
+{
+ int current_type;
+ int n = 0;
+ int columns;
+
+ printf ("array of bytes [\n");
+
+ indent (depth + 1);
+
+ /* Each byte takes 3 cells (two hexits, and a space), except the last one. */
+ columns = (80 - ((depth + 1) * INDENT)) / 3;
+
+ if (columns < 8)
+ columns = 8;
+
+ current_type = dbus_message_iter_get_arg_type (iter);
+
+ while (current_type != DBUS_TYPE_INVALID)
+ {
+ unsigned char val;
+ dbus_message_iter_get_basic (iter, &val);
+ printf ("%02x", val);
+
+ n++;
+
+ dbus_message_iter_next (iter);
+ current_type = dbus_message_iter_get_arg_type (iter);
+
+ if (current_type != DBUS_TYPE_INVALID)
+ {
+ if (n == columns)
+ {
+ printf ("\n");
+ indent (depth + 1);
+ n = 0;
+ }
+ else
+ {
+ printf (" ");
+ }
+ }
+ }
+
+ printf ("\n");
+ indent (depth);
+ printf ("]\n");
}
static void
@@ -188,6 +239,12 @@ print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
current_type = dbus_message_iter_get_arg_type (&subiter);
+ if (current_type == DBUS_TYPE_BYTE)
+ {
+ print_ay (&subiter, depth);
+ break;
+ }
+
printf("array [\n");
while (current_type != DBUS_TYPE_INVALID)
{