sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit c2632d5096ee5db30d4c5ba0606941697c8e0727
parent ad2f255b435176844aa618b9c609b447769b4c00
Author: Michael Forney <mforney@mforney.org>
Date:   Fri Jul  8 10:24:07 -0700

od: Add some missing type flags

Diffstat:
od.1 | 17++++++++++++++++-
od.c | 36++++++++++++++++++++++++++++++------
2 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/od.1 b/od.1 @@ -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 diff --git a/od.c b/od.c @@ -174,10 +174,21 @@ lcm(unsigned int a, unsigned int 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