od: Add some missing type flags

This commit is contained in:
Michael Forney 2016-07-08 10:24:07 -07:00 committed by sin
parent 8ca79a2993
commit 5ae2793da6
2 changed files with 46 additions and 7 deletions

17
od.1
View File

@ -6,11 +6,11 @@
.Nd octal dump .Nd octal dump
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl bdosvx
.Op Fl A Ar addrformat .Op Fl A Ar addrformat
.Op Fl E | e .Op Fl E | e
.Op Fl j Ar skip .Op Fl j Ar skip
.Op Fl t Ar outputformat... .Op Fl t Ar outputformat...
.Op Fl v
.Op Ar file ... .Op Ar file ...
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
@ -34,10 +34,22 @@ Force Little Endian
or Big Endian or Big Endian
.Fl ( E ) .Fl ( E )
system-independently. system-independently.
.It Fl b
Equivalent to
.Fl t o1 .
.It Fl d
Equivalent to
.Fl t u2 .
.It Fl j Ar skip .It Fl j Ar skip
Ignore the first Ignore the first
.Ar skip .Ar skip
bytes of input. bytes of input.
.It Fl o
Equivalent to
.Fl t o2 .
.It Fl s
Equivalent to
.Fl t d2 .
.It Fl t Ar outputformat .It Fl t Ar outputformat
.Ar outputformat .Ar outputformat
is a list of a|c|d|o|u|x followed by a digit or C|S|I|L and sets is a list of a|c|d|o|u|x followed by a digit or C|S|I|L and sets
@ -48,6 +60,9 @@ of \fIC\fRhar, \fIS\fRhort, \fII\fRnteger or \fIL\fRong.
The default is octal with 4 bytes. The default is octal with 4 bytes.
.It Fl v .It Fl v
Always set. Write all input data, including duplicate lines. Always set. Write all input data, including duplicate lines.
.It Fl x
Equivalent to
.Fl t x2 .
.El .El
.Sh STANDARDS .Sh STANDARDS
The The

36
od.c
View File

@ -173,11 +173,22 @@ lcm(unsigned int a, unsigned int b)
return a / d * b; return a / d * b;
} }
static void
addtype(char format, int len)
{
struct type *t;
t = emalloc(sizeof(*t));
t->format = format;
t->len = len;
TAILQ_INSERT_TAIL(&head, t, entry);
}
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-A addressformat] [-E | -e] [-j skip] " eprintf("usage: %s [-bdosvx] [-A addressformat] [-E | -e] [-j skip] "
"[-t outputformat] [-v] [file ...]\n", argv0); "[-t outputformat] [file ...]\n", argv0);
} }
int int
@ -197,6 +208,12 @@ main(int argc, char *argv[])
usage(); usage();
addr_format = s[0]; addr_format = s[0];
break; break;
case 'b':
addtype('o', 1);
break;
case 'd':
addtype('u', 2);
break;
case 'E': case 'E':
case 'e': case 'e':
big_endian = (ARGC() == 'E'); big_endian = (ARGC() == 'E');
@ -209,21 +226,25 @@ main(int argc, char *argv[])
if ((max = parseoffset(EARGF(usage()))) < 0) if ((max = parseoffset(EARGF(usage()))) < 0)
usage(); usage();
break; break;
case 'o':
addtype('o', 2);
break;
case 's':
addtype('d', 2);
break;
case 't': case 't':
s = EARGF(usage()); s = EARGF(usage());
for (; *s; s++) { for (; *s; s++) {
t = emalloc(sizeof(struct type));
switch (*s) { switch (*s) {
case 'a': case 'a':
case 'c': case 'c':
t->format = *s; addtype(*s, 1);
t->len = 1;
TAILQ_INSERT_TAIL(&head, t, entry);
break; break;
case 'd': case 'd':
case 'o': case 'o':
case 'u': case 'u':
case 'x': case 'x':
t = emalloc(sizeof(*t));
t->format = *s; t->format = *s;
/* todo: allow multiple digits */ /* todo: allow multiple digits */
if (*(s+1) > '0' && *(s+1) <= '9') { if (*(s+1) > '0' && *(s+1) <= '9') {
@ -256,6 +277,9 @@ main(int argc, char *argv[])
case 'v': case 'v':
/* always set - use uniq(1) to handle duplicate lines */ /* always set - use uniq(1) to handle duplicate lines */
break; break;
case 'x':
addtype('x', 2);
break;
default: default:
usage(); usage();
} ARGEND } ARGEND