From 854d802794a6c67c3bb7fe87f1b023f8d68f6ef3 Mon Sep 17 00:00:00 2001
From: Antonio Ospite <ospite@studenti.unina.it>
Date: Sat, 7 Jan 2012 01:44:01 +0100
Subject: [PATCH 1/1] Wrap lines when dumping big buffers

---
 picoproj.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/picoproj.c b/picoproj.c
index 197d5da..7e7cdd5 100644
--- a/picoproj.c
+++ b/picoproj.c
@@ -130,6 +130,11 @@ static void dump_header(struct header *h)
 	fflush(stdout);
 }
 
+static inline unsigned int in_80chars(unsigned int i)
+{
+	return ((i+1) % (80/3));
+}
+
 static void dump_buffer(uint8_t *buffer, unsigned int len)
 {
 	unsigned int i;
@@ -138,7 +143,7 @@ static void dump_buffer(uint8_t *buffer, unsigned int len)
 		return;
 
 	for (i = 0; i < len; i++) {
-		printf("%02hhX%c", buffer[i], (i < len - 1) ? ' ' : '\n');
+		printf("%02hhX%c", buffer[i], (in_80chars(i) && (i < len - 1)) ? ' ' : '\n');
 	}
 	fflush(stdout);
 }
-- 
2.1.4