mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-05-10 01:30:57 +00:00
[sizebuf] Add function to dump contents of a buffer
The usual 8-bit hex + chars (with chars wrapped into 7-bits) with addresses block.
This commit is contained in:
parent
92aa94d776
commit
fdcdbefc05
2 changed files with 32 additions and 0 deletions
|
@ -50,6 +50,7 @@ void SZ_Clear (sizebuf_t *buf);
|
||||||
void *SZ_GetSpace (sizebuf_t *buf, int length);
|
void *SZ_GetSpace (sizebuf_t *buf, int length);
|
||||||
void SZ_Write (sizebuf_t *buf, const void *data, int length);
|
void SZ_Write (sizebuf_t *buf, const void *data, int length);
|
||||||
void SZ_Print (sizebuf_t *buf, const char *data); // strcats onto the sizebuf
|
void SZ_Print (sizebuf_t *buf, const char *data); // strcats onto the sizebuf
|
||||||
|
void SZ_Dump (sizebuf_t *buf);
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
|
|
|
@ -99,3 +99,34 @@ SZ_Print (sizebuf_t *buf, const char *data)
|
||||||
|
|
||||||
memcpy (SZ_GetSpace (buf, len), data, len);
|
memcpy (SZ_GetSpace (buf, len), data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VISIBLE void
|
||||||
|
SZ_Dump (sizebuf_t *buf)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char chars[17], c;
|
||||||
|
|
||||||
|
chars[16] = 0;
|
||||||
|
for (i = 0; i < buf->cursize; i++) {
|
||||||
|
if (i % 16 == 0) {
|
||||||
|
Sys_Printf ("%04x:", i);
|
||||||
|
} else if (i % 16 == 8) {
|
||||||
|
Sys_Printf (" ");
|
||||||
|
}
|
||||||
|
Sys_Printf (" %02x", buf->data[i]);
|
||||||
|
c = buf->data[i] & 0x7f;
|
||||||
|
if (c < ' ') {
|
||||||
|
c = '.';
|
||||||
|
}
|
||||||
|
chars[i % 16] = c;
|
||||||
|
if (i % 16 == 15) {
|
||||||
|
Sys_Printf (" %s\n", chars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i %= 16;
|
||||||
|
if (i) {
|
||||||
|
chars[i] = 0;
|
||||||
|
i = 16 - i;
|
||||||
|
Sys_Printf ("%*s %s\n", i * 3 + (i > 7), "", chars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue