[hackers] [PATCH 1/8] od: Add some missing type flags

From: Michael Forney <mforney_AT_mforney.org>
Date: Fri, 8 Jul 2016 10:24:07 -0700

---
 od.1 | 17 ++++++++++++++++-
 od.c | 36 ++++++++++++++++++++++++++++++------
 2 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/od.1 b/od.1
index 99f3e32..485e340 100644
--- a/od.1
+++ b/od.1
_AT_@ -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
_AT_@ -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
_AT_@ -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
index 5a625b6..c448ac5 100644
--- a/od.c
+++ b/od.c
_AT_@ -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
_AT_@ -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');
_AT_@ -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') {
_AT_@ -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
-- 
2.6.2
Received on Fri Jul 08 2016 - 19:24:07 CEST

This archive was generated by hypermail 2.3.0 : Fri Jul 08 2016 - 19:36:18 CEST