From 9ee2ac5e28d3f9dbfa67df6bf3e46354bad72995 Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 17 Feb 2003 00:58:53 +0000 Subject: [PATCH] improved Com_HexDumpToConsole, it now prints properly (not with a data byte on the left side followed by offset number, and other sillyness), and also prints a text listing beside the hex, it remains the same width as the old hex-only listing. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2750 d7cf8633-e32d-0410-b094-e92efae38249 --- common.c | 62 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/common.c b/common.c index c6a16ee0..9e549fe7 100644 --- a/common.c +++ b/common.c @@ -469,50 +469,54 @@ void SZ_Print (sizebuf_t *buf, const char *data) static char *hexchar = "0123456789ABCDEF"; void Com_HexDumpToConsole(const qbyte *data, int size) { - int i; + int i, j, n; char text[1024]; char *cur, *flushpointer; + const qbyte *d; cur = text; flushpointer = text + 512; - for (i = 0;i < size;i++) + for (i = 0;i < size;) { - if ((i & 15) == 0) - { - *cur++ = hexchar[(i >> 12) & 15]; - *cur++ = hexchar[(i >> 8) & 15]; - *cur++ = hexchar[(i >> 4) & 15]; - *cur++ = hexchar[(i >> 0) & 15]; - *cur++ = ':'; - *cur++ = ' '; - } - else if ((i & 15) == 15) - *cur++ = '\n'; - else - *cur++ = ' '; - if (i & 1) + n = 16; + if (n > size - i) + n = size - i; + d = data + i; + *cur++ = hexchar[(i >> 12) & 15]; + *cur++ = hexchar[(i >> 8) & 15]; + *cur++ = hexchar[(i >> 4) & 15]; + *cur++ = hexchar[(i >> 0) & 15]; + *cur++ = ':'; + for (j = 0;j < n;j++) { - *cur++ = hexchar[(data[i] >> 4) & 15] | 0x80; - *cur++ = hexchar[(data[i] >> 0) & 15] | 0x80; + if (j & 1) + { + *cur++ = hexchar[(d[j] >> 4) & 15] | 0x80; + *cur++ = hexchar[(d[j] >> 0) & 15] | 0x80; + } + else + { + *cur++ = hexchar[(d[j] >> 4) & 15]; + *cur++ = hexchar[(d[j] >> 0) & 15]; + } } - else + for (;j < 16;j++) { - *cur++ = hexchar[(data[i] >> 4) & 15]; - *cur++ = hexchar[(data[i] >> 0) & 15]; + *cur++ = ' '; + *cur++ = ' '; } - if (cur >= flushpointer) + for (j = 0;j < n;j++) + *cur++ = (d[j] >= ' ' && d[j] <= 0x7E) ? d[j] : '.'; + for (;j < 16;j++) + *cur++ = ' '; + *cur++ = '\n'; + i += n; + if (cur >= flushpointer || i >= size) { *cur++ = 0; Con_Printf("%s", text); cur = text; } } - if ((i & 15) != 0) - *cur++ = '\n'; - if (cur > text) - { - *cur++ = 0; - Con_Printf("%s", text); - } } void SZ_HexDumpToConsole(const sizebuf_t *buf) -- 2.39.2