X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/31cef89cb428866f787983e68246030321893df4..4b9ccde74dc34e450ed96bcd3d044f78cf393d8d:/usr/src/cmd/od.c diff --git a/usr/src/cmd/od.c b/usr/src/cmd/od.c index 6fe9ddb860..fdc6804b6e 100644 --- a/usr/src/cmd/od.c +++ b/usr/src/cmd/od.c @@ -1,30 +1,46 @@ -static char *sccsid = "@(#)od.c 4.1 (Berkeley) 10/1/80"; +static char *sccsid = "@(#)od.c 4.2 (Berkeley) 2/7/81"; /* * od -- octal (also hex, decimal, and character) dump */ #include -unsigned short word[8]; -unsigned short lastword[8]; +typedef unsigned long ulong; + +unsigned short word[16]; +unsigned short lastword[16]; +short nword = 8; int conv; int base = 010; int max; -long addr; +ulong addr; +#define DWORD 0700 /* bitmask for double word output formats */ main(argc, argv) char **argv; { register char *p; register n, f, same; + char outbuf[BUFSIZ]; + +#ifdef STANDALONE + if (argv[0][0] == '\0') + argc = getargv("od", &argv, 0); +#else + setbuf(stdout, outbuf); +#endif argv++; f = 0; - if(argc > 1) { + if(argc > 1) + { p = *argv; - if(*p == '-') { - while(*p != '\0') { - switch(*p++) { + if(*p == '-') + { + while(*p != '\0') + { + switch(*p++) + { case 'o': conv |= 001; f = 6; @@ -46,6 +62,22 @@ char **argv; conv |= 040; f = 7; break; + case 'O': + conv |= 0100; + f = 6; + break; + case 'D': + conv |= 0200; + f = 5; + break; + case 'H': + case 'X': + conv |= 0400; + f = 4; + break; + case 'w': + nword = 16; + break; } if(f > max) max = f; @@ -54,64 +86,83 @@ char **argv; argv++; } } - if(!conv) { + 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); + if(**argv != '+') + { + if (freopen(*argv, "r", stdin) == NULL) + { + fprintf(stderr, "od: cannot open %s\n", *argv); + exit(2); + } + argv++; + argc--; } - 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++) + for ( ; (n = fread((char *)word, 1, sizeof(word[0])*nword, stdin)) > 0; addr += n) + { + if (same>=0) + { + for (f=0; f037 && c<0177) { + if(c>037 && c<0177) + { printf(" "); putchar(c); return; } - switch(c) { + switch(c) + { case '\0': printf(" \\0"); break; @@ -183,14 +257,15 @@ cput(c) printf(" \\t"); break; default: - putn((long)c, 8, 3); + putn((ulong)c, 8, 3); } } putn(n, b, c) -long n; +ulong n; +unsigned b; { - register d; + unsigned d; if(!c) return; @@ -214,25 +289,31 @@ offset(s) register char *s; { register char *p; - long a; + ulong a; register int d; if (*s=='+') s++; - if (*s=='x') { + if (*s=='x') + { s++; base = 16; - } else if (*s=='0' && s[1]=='x') { + } + else if (*s=='0' && s[1]=='x') + { s += 2; base = 16; - } else if (*s == '0') + } + else if (*s == '0') base = 8; p = s; - while(*p) { + while(*p) + { if (*p++=='.') base = 10; } - for (a=0; *s; s++) { + for (a=0; *s; s++) + { d = *s; if(d>='0' && d<='9') a = a*base + d - '0';