void outi( unsigned i ) { static char foo[5]; outs( " " ); foo[4] = 0; foo[3] = hdigit( i & 0xF ); i >>= 4; foo[2] = hdigit( i & 0xF ); i >>= 4; foo[1] = hdigit( i & 0xF ); i >>= 4; foo[0] = hdigit( i & 0xF ); outs( foo ); }
void hexdump(direction d, int fd, unsigned char *p, int n) { register int l=0; char buf[78]; unsigned char c; #define hpos(x) (3*(x)+(((x)>7)?2:1)) #define apos(x) ((x)+60) /* (x+((x>7)?60:59)) */ #define hdigit(x) (((x)>9)?((x)-10+'a'):((x)+'0')) memset(buf, ' ', 77); buf[77]='\0'; printf("%s %d:\n", (d==d_from) ? "From" : "To", fd); while (n-->0) { c=(unsigned char)*p++; buf[hpos(l)] = hdigit(c>>4); buf[hpos(l)+1] = hdigit(c&15); buf[apos(l)] = (c<32||c>126) ? '.' : c; if (++l>15) { puts(buf); memset(buf, ' ', 77); l=0; } } puts(buf); #undef hpos #undef apos #undef hdigit }