summaryrefslogtreecommitdiffstats
path: root/tools/soslim/debug.c
blob: b8365af4e860f7d1557b3f6520bc18d04ba4012d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <debug.h>
#include <stdio.h>
#include <ctype.h>

#if 0

#define NUM_COLS  (32)

int dump_hex_buffer(FILE *s, void *b, size_t len, size_t elsize) {
    int num_nonprintable = 0;
    int i, last;
    char *pchr = (char *)b;
    fputc('\n', s);
    for (i = last = 0; i < len; i++) {
        if (!elsize) {
            if (i && !(i % 4)) fprintf(s, " ");
            if (i && !(i % 8)) fprintf(s, " ");
        } else {
            if (i && !(i % elsize)) fprintf(s, " ");
        }

        if (i && !(i % NUM_COLS)) {
            while (last < i) {
                if (isprint(pchr[last]))
                    fputc(pchr[last], s);
                else {
                    fputc('.', s);
                    num_nonprintable++;
                }
                last++;
            }
            fprintf(s, " (%d)\n", i);
        }
        fprintf(s, "%02x", (unsigned char)pchr[i]);
    }
    if (i && (i % NUM_COLS)) fputs("\n", s);
    return num_nonprintable;
}

#endif