dect
/
dectmon
Archived
13
0
Fork 0
This repository has been archived on 2022-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
dectmon/src/debug.c

34 lines
748 B
C

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <inttypes.h>
#include <unistd.h>
#include <ctype.h>
#include <dectmon.h>
#define BLOCKSIZE 16
void dect_hexdump(const char *prefix, const uint8_t *buf, size_t size)
{
unsigned int i, off, plen = 0;
char hbuf[3 * BLOCKSIZE + 1], abuf[BLOCKSIZE + 1];
for (i = 0; i < strlen(prefix); i++)
plen += prefix[i] == '\t' ? 8 : 1;
for (i = 0; i < size; i++) {
off = i % BLOCKSIZE;
sprintf(hbuf + 3 * off, "%.2x ", buf[i]);
abuf[off] = isascii(buf[i]) && isprint(buf[i]) ? buf[i] : '.';
if (off == BLOCKSIZE - 1 || i == size - 1) {
abuf[off + 1] = '\0';
printf("%s: %-*s |%s|\n", prefix, 64 - plen, hbuf, abuf);
}
}
}