|
|
d2dc68 |
From 80843d0818c61823bd9dd4c365442d29a8a6f2af Mon Sep 17 00:00:00 2001
|
|
|
d2dc68 |
From: Michael Drake <michael.drake@codethink.co.uk>
|
|
|
d2dc68 |
Date: Thu, 7 Jun 2018 12:37:13 +0100
|
|
|
d2dc68 |
Subject: [PATCH 6/9] lsusb: Split out field name rendering.
|
|
|
d2dc68 |
|
|
|
d2dc68 |
Splits out the rendering of fields from desc_dump() since it
|
|
|
d2dc68 |
is a single unit of functionality and the desc_dump() function
|
|
|
d2dc68 |
had grown quite complex.
|
|
|
d2dc68 |
|
|
|
d2dc68 |
Signed-off-by: Michael Drake <michael.drake@codethink.co.uk>
|
|
|
d2dc68 |
---
|
|
|
d2dc68 |
desc-dump.c | 45 +++++++++++++++++++++++++++++++++------------
|
|
|
d2dc68 |
1 file changed, 33 insertions(+), 12 deletions(-)
|
|
|
d2dc68 |
|
|
|
d2dc68 |
diff --git a/desc-dump.c b/desc-dump.c
|
|
|
d2dc68 |
index 393ff70..2f92768 100644
|
|
|
d2dc68 |
--- a/desc-dump.c
|
|
|
d2dc68 |
+++ b/desc-dump.c
|
|
|
d2dc68 |
@@ -446,6 +446,35 @@ static unsigned int get_char_count_for_array_index(unsigned int array_entries)
|
|
|
d2dc68 |
return 3;
|
|
|
d2dc68 |
}
|
|
|
d2dc68 |
|
|
|
d2dc68 |
+/**
|
|
|
d2dc68 |
+ * Render a field's name.
|
|
|
d2dc68 |
+ *
|
|
|
d2dc68 |
+ * \param[in] entry Current entry number (for arrays).
|
|
|
d2dc68 |
+ * \param[in] entries Entry count (for arrays).
|
|
|
d2dc68 |
+ * \param[in] field_len Character width of field name space for alignment.
|
|
|
d2dc68 |
+ * \param[in] current Descriptor definition of field to render.
|
|
|
d2dc68 |
+ * \param[in] indent Current indent level.
|
|
|
d2dc68 |
+ */
|
|
|
d2dc68 |
+static void field_render(
|
|
|
d2dc68 |
+ unsigned int entry,
|
|
|
d2dc68 |
+ unsigned int entries,
|
|
|
d2dc68 |
+ unsigned int field_len,
|
|
|
d2dc68 |
+ const struct desc *current,
|
|
|
d2dc68 |
+ unsigned int indent)
|
|
|
d2dc68 |
+{
|
|
|
d2dc68 |
+ if (current->array.array) {
|
|
|
d2dc68 |
+ unsigned int needed_chars = field_len -
|
|
|
d2dc68 |
+ get_char_count_for_array_index(entries) -
|
|
|
d2dc68 |
+ strlen(current->field);
|
|
|
d2dc68 |
+ printf("%*s%s(%u)%*s", indent * 2, "",
|
|
|
d2dc68 |
+ current->field, entry,
|
|
|
d2dc68 |
+ needed_chars, "");
|
|
|
d2dc68 |
+ } else {
|
|
|
d2dc68 |
+ printf("%*s%-*s", indent * 2, "",
|
|
|
d2dc68 |
+ field_len, current->field);
|
|
|
d2dc68 |
+ }
|
|
|
d2dc68 |
+}
|
|
|
d2dc68 |
+
|
|
|
d2dc68 |
/* Function documented in desc-dump.h */
|
|
|
d2dc68 |
void desc_dump(
|
|
|
d2dc68 |
libusb_device_handle *dev,
|
|
|
d2dc68 |
@@ -506,19 +535,11 @@ void desc_dump(
|
|
|
d2dc68 |
printf("\n");
|
|
|
d2dc68 |
return;
|
|
|
d2dc68 |
}
|
|
|
d2dc68 |
+
|
|
|
d2dc68 |
/* Dump the field name */
|
|
|
d2dc68 |
- if (current->array.array) {
|
|
|
d2dc68 |
- needed_chars = field_len -
|
|
|
d2dc68 |
- get_char_count_for_array_index(
|
|
|
d2dc68 |
- entries) -
|
|
|
d2dc68 |
- strlen(current->field);
|
|
|
d2dc68 |
- printf("%*s%s(%u)%*s", indent * 2, "",
|
|
|
d2dc68 |
- current->field, entry,
|
|
|
d2dc68 |
- needed_chars, "");
|
|
|
d2dc68 |
- } else {
|
|
|
d2dc68 |
- printf("%*s%-*s", indent * 2, "",
|
|
|
d2dc68 |
- field_len, current->field);
|
|
|
d2dc68 |
- }
|
|
|
d2dc68 |
+ field_render(entry, entries, field_len,
|
|
|
d2dc68 |
+ current, indent);
|
|
|
d2dc68 |
+
|
|
|
d2dc68 |
/* Dump the value */
|
|
|
d2dc68 |
value_renderer(dev, current, current_size, buf,
|
|
|
d2dc68 |
indent, offset);
|
|
|
d2dc68 |
--
|
|
|
d2dc68 |
2.14.4
|
|
|
d2dc68 |
|