improved Com_HexDumpToConsole, it now prints properly (not with a data byte on the...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 17 Feb 2003 00:58:53 +0000 (00:58 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 17 Feb 2003 00:58:53 +0000 (00:58 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2750 d7cf8633-e32d-0410-b094-e92efae38249

common.c

index c6a16ee..9e549fe 100644 (file)
--- 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)