summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjh21 <bjh21@NetBSD.org>2001-12-05 17:46:15 +0000
committerbjh21 <bjh21@NetBSD.org>2001-12-05 17:46:15 +0000
commita4b50871cba2c7cedae33d7c4eb5220f2df53a3b (patch)
treed211d3c48499d411b34752f6bf762a49fc34aba3
parentfe61017def61034cd49928cc0433a9c9478bc91d (diff)
Add a -j option to od, which does the same as the -s option to
hexdump (skipping some of the input). This brings our od slightly closer to POSIX.2 conformance.
-rw-r--r--usr.bin/hexdump/od.135
-rw-r--r--usr.bin/hexdump/odsyntax.c23
2 files changed, 53 insertions, 5 deletions
diff --git a/usr.bin/hexdump/od.1 b/usr.bin/hexdump/od.1
index 9e0a4cec935..cf4d768c739 100644
--- a/usr.bin/hexdump/od.1
+++ b/usr.bin/hexdump/od.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: od.1,v 1.13 2001/10/03 20:29:39 atatat Exp $
+.\" $NetBSD: od.1,v 1.14 2001/12/05 17:46:15 bjh21 Exp $
.\"
.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -44,6 +44,9 @@
.Nm ""
.Op Fl aBbcDdeFfHhIiLlOovXx
.Bk -words
+.Op Fl j Ar skip
+.Ek
+.Bk -words
.Op Fl t Ar type_string
.Ek
.Sm off
@@ -137,6 +140,36 @@ decimal, per line.
Display the input offset in octal, followed by eight space-separated,
six column, space filled, two-byte units of input data, in decimal,
per line.
+.It Fl j Ar offset
+Skip
+.Ar offset
+bytes from the beginning of the input.
+By default,
+.Ar offset
+is interpreted as a decimal number.
+With a leading
+.Cm 0x
+or
+.Cm 0X ,
+.Ar offset
+is interpreted as a hexadecimal number,
+otherwise, with a leading
+.Cm 0 ,
+.Ar offset
+is interpreted as an octal number.
+Appending the character
+.Cm b ,
+.Cm k ,
+or
+.Cm m
+to
+.Ar offset
+causes it to be interpreted as a multiple of
+.Li 512 ,
+.Li 1024 ,
+or
+.Li 1048576 ,
+respectively.
.It Fl L
Same as
.Fl I .
diff --git a/usr.bin/hexdump/odsyntax.c b/usr.bin/hexdump/odsyntax.c
index 46f915559af..a654e928cd2 100644
--- a/usr.bin/hexdump/odsyntax.c
+++ b/usr.bin/hexdump/odsyntax.c
@@ -1,4 +1,4 @@
-/* $NetBSD: odsyntax.c,v 1.11 2001/02/07 18:32:21 christos Exp $ */
+/* $NetBSD: odsyntax.c,v 1.12 2001/12/05 17:46:15 bjh21 Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: odsyntax.c,v 1.11 2001/02/07 18:32:21 christos Exp $");
+__RCSID("$NetBSD: odsyntax.c,v 1.12 2001/12/05 17:46:15 bjh21 Exp $");
#endif
#endif /* not lint */
@@ -91,12 +91,12 @@ oldsyntax(argc, argvp)
char ***argvp;
{
int ch;
- char **argv;
+ char *p, **argv;
int x, y;
deprecated = 1;
argv = *argvp;
- while ((ch = getopt(argc, argv, "aBbcDdeFfHhIiLlOoPpst:wvXx")) != -1)
+ while ((ch = getopt(argc, argv, "aBbcDdeFfHhIij:LlOoPpst:wvXx")) != -1)
switch (ch) {
case 'a':
odprecede();
@@ -153,6 +153,21 @@ oldsyntax(argc, argvp)
odprecede();
add("8/2 \" %6d \" \"\\n\"");
break;
+ case 'j':
+ if ((skip = strtol(optarg, &p, 0)) < 0)
+ errx(1, "%s: bad skip value", optarg);
+ switch(*p) {
+ case 'b':
+ skip *= 512;
+ break;
+ case 'k':
+ skip *= 1024;
+ break;
+ case 'm':
+ skip *= 1048576;
+ break;
+ }
+ break;
case 'O':
odprecede();
add("4/4 \" %011o \" \"\\n\"");