add -a (assoc only) command line option
[rofl0r-wpakey.git] / dump.c
blob69b7651973af79294b17fe05873117eff579368f
1 #include <stdio.h>
3 static inline int myisascii(int x) {
4 return x >= ' ' && x < 127;
7 void dump(const unsigned char* data, size_t len) {
8 static const char atab[] = "0123456789abcdef";
9 char hex[24*2+1], ascii[24+1];
10 unsigned h = 0, a = 0;
11 int fill = ' ';
13 while(len) {
14 len--;
15 hex[h++] = atab[*data >> 4];
16 hex[h++] = atab[*data & 0xf];
17 ascii[a++] = myisascii(*data) ? *data : '.';
18 if(a == 24) {
19 dump:
20 hex[h] = 0;
21 ascii[a] = 0;
22 printf("%s\t%s\n", hex, ascii);
24 if(fill == '_') return; /* jump from filler */
26 a = 0;
27 h = 0;
29 data++;
31 if(a) {
32 filler:
33 while(a<24) {
34 hex[h++] = fill;
35 hex[h++] = fill;
36 ascii[a++] = fill;
38 goto dump;
40 a = 0;
41 fill = '_';
42 goto filler;