|
|
1.1 root 1: /*
2: * Vertical hex dump subroutine
3: * dumps 64 bytes per line
4: */
5:
6: static
7: clean(c)
8: register char c;
9: {
10: return ((c >= ' ' && c <= '~' ) ? c : '.');
11: }
12:
13: static unsigned int linepos = 0; /* how many non sep chars output so far */
14: /*
15: * Put char and separators.
16: */
17: static void
18: outc(c)
19: char c;
20: {
21: if (!(linepos & 3))
22: putchar(linepos ? ' ' : '\n');
23: putchar(c);
24: linepos++;
25: }
26:
27: static
28: hex(c)
29: register char c;
30: {
31: return (c + ((c <= 9) ? '0' : 'A' - 10));
32: }
33:
34: xdump(p, length)
35: register unsigned char *p;
36: {
37: register int tlength;
38: register unsigned char *l;
39:
40: for (;(tlength = (length > 64) ? 64 : length) > 0; length -= 64) {
41: for (linepos = 0, l = p; linepos < tlength; )
42: outc(clean(*p++));
43:
44: for (linepos = 0, p = l; linepos < tlength; )
45: outc(hex(((*p++) >> 4) & 15));
46:
47: for (linepos = 0, p = l; linepos < tlength; )
48: outc(hex((*p++) & 15));
49: }
50: putchar('\n');
51: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.