Blame SOURCES/0006-lsusb-Split-out-field-name-rendering.patch

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