/* cc -O2 -Wall dhex.c -o dhex */ #include #include #include #include void usage(char *name); void addfl(char *to, char *from); int count = 16, offset = 0, i, j, asc = 1, fn = 1, f = 0, z = 1, stat = 0, term = 0; char fname[100][256], str[16], opt[100], *temp, red[8], green[8], cyan[8], nc[8]; int main(int argc, char *argv[]) { FILE *fp; register int buf; if (argc < 2) usage(argv[0]); strcpy(red, "\033[0;31m"); /* RED */ strcpy(green, "\033[0;32m"); /* GREEN */ strcpy(cyan, "\033[0;36m"); /* CYAN */ strcpy(nc, "\033[0m"); /* NO COLOR */ for (i=1; i%s%.8x %s", red, cyan, offset, green); count = 0; offset = offset+16; } if (count == 4 || count == 8 || count == 12) printf(" "); if ((buf = fgetc(fp)) == -1) break; printf("%.2x ", buf); if (asc) { if ((buf > 32 && buf < 127) || (buf > 159)) /* print binary as . */ str[count] = buf; else str[count] = '.'; } count++; } fclose(fp); if (asc) { /* finish the string */ for (i=count; i<16; i++) { printf(" "); if (i == 3 || i == 7 || i == 11) printf(" "); } printf("%s %.16s\n", nc, str); } else printf("%s\n", nc); count = 16; offset = 0; bzero(str, 16); } return stat; } void usage(char *name) { fprintf(stderr, "dhex 0.7 by shudder \nusage: %s [-afc] [--] [filename(s)]...\n\t-a\tdo not print ascii\n\t-f\tdo not show filenames\n\t-c\tdisable colors\n\t--\tterminate option list\nuse `-' (dash) instead of a filename to read from stdin\n", name); exit(1); } void addfl(char *to, char *from) { if (f <= 99) { strcpy(to, from); f++; } }