FreeCalypso > hg > sms-coding-utils
comparison libcoding/hexdump.c @ 27:7418ca2e9949
libcoding: add functions from freecalypso-tools/uptools/libcoding
that are needed for sms-pdu-decode & pcm-sms-decode
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 13 Jun 2024 02:29:29 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
26:c8cb05b69118 | 27:7418ca2e9949 |
---|---|
1 /* | |
2 * This library module implements a simple hex dump facility. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 | |
8 msg_bits_hexdump(dumpbuf, dumplen) | |
9 u_char *dumpbuf; | |
10 unsigned dumplen; | |
11 { | |
12 u_char *buf = dumpbuf; | |
13 unsigned lineoff, linelen, i, c; | |
14 | |
15 for (lineoff = 0; lineoff < dumplen; ) { | |
16 linelen = dumplen - lineoff; | |
17 if (linelen > 16) | |
18 linelen = 16; | |
19 printf("%02X: ", lineoff); | |
20 for (i = 0; i < 16; i++) { | |
21 if (i < linelen) | |
22 printf("%02X ", buf[i]); | |
23 else | |
24 fputs(" ", stdout); | |
25 if (i == 7 || i == 15) | |
26 putchar(' '); | |
27 } | |
28 for (i = 0; i < linelen; i++) { | |
29 c = buf[i]; | |
30 if (c < ' ' || c > '~') | |
31 c = '.'; | |
32 putchar(c); | |
33 } | |
34 putchar('\n'); | |
35 buf += linelen; | |
36 lineoff += linelen; | |
37 } | |
38 } |