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
.Sh SYNOPSIS
.Nm
.Op Fl bdosvx
.Op Fl A Ar addrformat
.Op Fl E | e
.Op Fl j Ar skip
.Op Fl t Ar outputformat...
.Op Fl v
.Op Ar file ...
.Sh DESCRIPTION
.Nm
@ -34,10 +34,22 @@ Force Little Endian
or Big Endian
.Fl ( E )
system-independently.
.It Fl b
Equivalent to
.Fl t o1 .
.It Fl d
Equivalent to
.Fl t u2 .
.It Fl j Ar skip
Ignore the first
.Ar skip
bytes of input.
.It Fl o
Equivalent to
.Fl t o2 .
.It Fl s
Equivalent to
.Fl t d2 .
.It Fl t 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
@ -48,6 +60,9 @@ of \fIC\fRhar, \fIS\fRhort, \fII\fRnteger or \fIL\fRong.
The default is octal with 4 bytes.
.It Fl v
Always set. Write all input data, including duplicate lines.
.It Fl x
Equivalent to
.Fl t x2 .
.El
.Sh STANDARDS
The

36
od.c
View File

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