From: Antonio Ospite Date: Sat, 7 Jan 2012 00:44:01 +0000 (+0100) Subject: Wrap lines when dumping big buffers X-Git-Tag: v0.1.0~39 X-Git-Url: https://git.ao2.it/libam7xxx.git/commitdiff_plain/854d802794a6c67c3bb7fe87f1b023f8d68f6ef3?ds=sidebyside;hp=-c Wrap lines when dumping big buffers --- 854d802794a6c67c3bb7fe87f1b023f8d68f6ef3 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); }