/* * od -- octal (also hex, decimal, and character) dump */ #include unsigned short word[8]; unsigned short lastword[8]; int conv; int base = 010; int max; long addr; main(argc, argv) char **argv; { register char *p; register n, f, same; argv++; f = 0; if(argc > 1) { p = *argv; if(*p == '-') { while(*p != '\0') { switch(*p++) { case 'o': conv |= 001; f = 6; break; case 'd': conv |= 002; f = 5; break; case 'x': case 'h': conv |= 010; f = 4; break; case 'c': conv |= 020; f = 7; break; case 'b': conv |= 040; f = 7; break; } if(f > max) max = f; } argc--; argv++; } } if(!conv) { max = 6; conv = 1; } if(argc > 1) if(**argv != '+') { if (freopen(*argv, "r", stdin) == NULL) { printf("cannot open %s\n", *argv); exit(1); } argv++; argc--; } if(argc > 1) offset(*argv); same = -1; for ( ; (n = fread((char *)word, 1, sizeof(word), stdin)) > 0; addr += n) { if (same>=0) { for (f=0; f<8; f++) if (lastword[f] != word[f]) goto notsame; if (same==0) { printf("*\n"); same = 1; } continue; } notsame: line(addr, word, (n+sizeof(word[0])-1)/sizeof(word[0])); same = 0; for (f=0; f<8; f++) lastword[f] = word[f]; for (f=0; f<8; f++) word[f] = 0; } putn(addr, base, 7); putchar('\n'); } line(a, w, n) long a; unsigned short *w; { register i, f, c; f = 1; for(c=1; c; c<<=1) { if((c&conv) == 0) continue; if(f) { putn(a, base, 7); putchar(' '); f = 0; } else putchar('\t'); for (i=0; i037 && c<0177) { printf(" "); putchar(c); return; } switch(c) { case '\0': printf(" \\0"); break; case '\b': printf(" \\b"); break; case '\f': printf(" \\f"); break; case '\n': printf(" \\n"); break; case '\r': printf(" \\r"); break; case '\t': printf(" \\t"); break; default: putn((long)c, 8, 3); } } putn(n, b, c) long n; { register d; if(!c) return; putn(n/b, b, c-1); d = n%b; if (d > 9) putchar(d-10+'a'); else putchar(d+'0'); } pre(n) { int i; for(i=n; i='0' && d<='9') a = a*base + d - '0'; else if (d>='a' && d<='f' && base==16) a = a*base + d + 10 - 'a'; else break; } if (*s == '.') s++; if(*s=='b' || *s=='B') a *= 512; fseek(stdin, a, 0); addr = a; }