From 1e33498f8ca6b050f0a32002ca925d1f0c357a7f Mon Sep 17 00:00:00 2001 From: Thomas Cort Date: Tue, 29 Oct 2013 14:48:38 -0400 Subject: [PATCH] Importing usr.bin/hexdump Replaces commands/hexdump as well as commands/od. No Minix-specific changes were needed. test/testsh2.sh was modified to match the spacing used in the output of the NetBSD od command. Change-Id: I65ee1d30e8cdd546097462df7c38c2d38f3e891d --- commands/Makefile | 4 +- commands/hexdump/Makefile | 16 -- commands/od/Makefile | 4 - commands/od/od.c | 314 ---------------------- man/man1/Makefile | 2 +- man/man1/od.1 | 58 ---- releasetools/nbsd_ports | 1 + test/testsh2.sh | 32 +-- usr.bin/Makefile | 2 +- usr.bin/hexdump/Makefile | 18 ++ {commands => usr.bin}/hexdump/conv.c | 2 - {commands => usr.bin}/hexdump/display.c | 2 - {commands => usr.bin}/hexdump/hexdump.1 | 152 ++++++----- {commands => usr.bin}/hexdump/hexdump.c | 36 ++- {commands => usr.bin}/hexdump/hexdump.h | 11 +- {commands => usr.bin}/hexdump/hexsyntax.c | 17 +- {commands => usr.bin}/hexdump/od.1 | 65 +++-- {commands => usr.bin}/hexdump/odsyntax.c | 6 +- {commands => usr.bin}/hexdump/parse.c | 19 +- 19 files changed, 209 insertions(+), 552 deletions(-) delete mode 100644 commands/hexdump/Makefile delete mode 100644 commands/od/Makefile delete mode 100644 commands/od/od.c delete mode 100644 man/man1/od.1 create mode 100644 usr.bin/hexdump/Makefile rename {commands => usr.bin}/hexdump/conv.c (99%) rename {commands => usr.bin}/hexdump/display.c (99%) rename {commands => usr.bin}/hexdump/hexdump.1 (80%) rename {commands => usr.bin}/hexdump/hexdump.c (79%) rename {commands => usr.bin}/hexdump/hexdump.h (93%) rename {commands => usr.bin}/hexdump/hexsyntax.c (91%) rename {commands => usr.bin}/hexdump/od.1 (90%) rename {commands => usr.bin}/hexdump/odsyntax.c (98%) rename {commands => usr.bin}/hexdump/parse.c (97%) diff --git a/commands/Makefile b/commands/Makefile index cad684a4e..4754ecbf4 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -10,14 +10,14 @@ SUBDIR= add_route arp ash at backup btrace \ dhrystone diff diskctl dumpcore \ eject factor fbdctl \ find fix format fortune fsck.mfs \ - gcore gcov-pull getty grep hexdump host \ + gcore gcov-pull getty grep host \ hostaddr id ifconfig ifdef \ intr ipcrm ipcs irdpd isoread last \ less loadkeys loadramdisk logger look lp \ lpd lspci mail MAKEDEV \ mined mkfifo \ mount mt netconf \ - nonamed od patch \ + nonamed patch \ ping postinstall poweroff prep printroot \ profile progressbar pr_routes ps pwdauth \ ramdisk rarpd rawspeed rcp readclock \ diff --git a/commands/hexdump/Makefile b/commands/hexdump/Makefile deleted file mode 100644 index ed82a3622..000000000 --- a/commands/hexdump/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# $NetBSD: Makefile,v 1.13 2009/04/14 22:15:21 lukem Exp $ -# from: @(#)Makefile 8.1 (Berkeley) 6/6/93 - -PROG= hexdump -SRCS= conv.c display.c hexdump.c hexsyntax.c odsyntax.c parse.c -MAN= hexdump.1 #od.1 - -.ifndef HOSTPROG - -LDADD+= -lutil -DPADD+= ${LIBUTIL} - -#LINKS= ${BINDIR}/hexdump ${BINDIR}/od -.endif - -.include diff --git a/commands/od/Makefile b/commands/od/Makefile deleted file mode 100644 index dac693a6a..000000000 --- a/commands/od/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -PROG= od -MAN= - -.include diff --git a/commands/od/od.c b/commands/od/od.c deleted file mode 100644 index 1a2a2bb88..000000000 --- a/commands/od/od.c +++ /dev/null @@ -1,314 +0,0 @@ -/* od - octal dump Author: Andy Tanenbaum */ - -#include -#include -#include -#include -#include - - -int bflag, cflag, dflag, oflag, xflag, hflag, vflag; -int linenr, width, state, ever; -int prevwds[8]; -long off; -char buf[512], buffer[BUFSIZ]; -int next; -int bytespresent; - -int main(int argc, char **argv); -long offset(int argc, char *argv [], int k); -void dumpfile(void); -void wdump(short *words, int k, int radix); -void bdump(char bytes [16 ], int k, int c); -void byte(int val, int c); -int getwords(short **words); -int same(short *w1, int *w2); -void outword(int val, int radix); -void outnum(int num, int radix); -void addrout(long l); -char hexit(int k); -void usage(void); - -int main(argc, argv) -int argc; -char *argv[]; -{ - int k, flags; - char *p; - - /* Process flags */ - setbuf(stdout, buffer); - flags = 0; - p = argv[1]; - if (argc > 1 && *p == '-') { - /* Flags present. */ - flags++; - p++; - while (*p) { - switch (*p) { - case 'b': bflag++; break; - case 'c': cflag++; break; - case 'd': dflag++; break; - case 'h': hflag++; break; - case 'o': oflag++; break; - case 'v': vflag++; break; - case 'x': xflag++; break; - default: usage(); - } - p++; - } - } else { - oflag = 1; - } - if ((bflag | cflag | dflag | oflag | xflag) == 0) oflag = 1; - k = (flags ? 2 : 1); - if (bflag | cflag) { - width = 8; - } else if (oflag) { - width = 7; - } else if (dflag) { - width = 6; - } else { - width = 5; - } - - /* Process file name, if any. */ - p = argv[k]; - if (k < argc && *p != '+') { - /* Explicit file name given. */ - close(0); - if (open(argv[k], O_RDONLY) != 0) { - fprintf(stderr, "od: cannot open %s\n", argv[k]); - exit(1); - } - k++; - } - - /* Process offset, if any. */ - if (k < argc) { - /* Offset present. */ - off = offset(argc, argv, k); - off = (off / 16L) * 16L; - lseek(0, off, SEEK_SET); - } - dumpfile(); - addrout(off); - printf("\n"); - return(0); -} - - -long offset(argc, argv, k) -int argc; -char *argv[]; -int k; -{ - int dot, radix; - char *p, c; - long val; - - /* See if the offset is decimal. */ - dot = 0; - p = argv[k]; - while (*p) - if (*p++ == '.') dot = 1; - - /* Convert offset to binary. */ - radix = (dot ? 10 : 8); - val = 0; - p = argv[k]; - if (*p == '+') p++; - while (*p != 0 && *p != '.') { - c = *p++; - if (c < '0' || c > '9') { - printf("Bad character in offset: %c\n", c); - exit(1); - } - val = radix * val + c - '0'; - } - - p = argv[k + 1]; - if (k + 1 == argc - 1 && *p == 'b') val = 512L * val; - return(val); -} - - -void dumpfile() -{ - int k; - short *words; - - while ((k = getwords(&words))) { /* 'k' is # bytes read */ - if (!vflag) { /* ensure 'lazy' evaluation */ - if (k == 16 && ever == 1 && same(words, prevwds)) { - if (state == 0) { - printf("*\n"); - state = 1; - off += 16; - continue; - } else if (state == 1) { - off += 16; - continue; - } - } - } - addrout(off); - off += k; - state = 0; - ever = 1; - linenr = 1; - if (oflag) wdump(words, k, 8); - if (dflag) wdump(words, k, 10); - if (xflag) wdump(words, k, 16); - if (cflag) bdump((char *)words, k, (int)'c'); - if (bflag) bdump((char *)words, k, (int)'b'); - for (k = 0; k < 8; k++) prevwds[k] = words[k]; - for (k = 0; k < 8; k++) words[k] = 0; - } -} - - -void wdump(words, k, radix) -short *words; -int k, radix; -{ - int i; - - if (linenr++ != 1) printf(" "); - for (i = 0; i < (k + 1) / 2; i++) outword(words[i] & 0xFFFF, radix); - printf("\n"); -} - - -void bdump(bytes, k, c) -char bytes[16]; -int k; -char c; -{ - int i; - - if (linenr++ != 1) printf(" "); - for (i = 0; i < k; i++) byte(bytes[i] & 0377, c); - printf("\n"); -} - -void byte(val, c) -int val; -char c; -{ - if (c == 'b') { - printf(" "); - outnum(val, 7); - return; - } - if (val == 0) - printf(" \\0"); - else if (val == '\b') - printf(" \\b"); - else if (val == '\f') - printf(" \\f"); - else if (val == '\n') - printf(" \\n"); - else if (val == '\r') - printf(" \\r"); - else if (val == '\t') - printf(" \\t"); - else if (val >= ' ' && val < 0177) - printf(" %c", val); - else { - printf(" "); - outnum(val, 7); - } -} - - -int getwords(words) -short **words; -{ - int count; - - if (next >= bytespresent) { - bytespresent = read(0, buf, 512); - next = 0; - } - if (next >= bytespresent) return(0); - *words = (short *) &buf[next]; - if (next + 16 <= bytespresent) - count = 16; - else - count = bytespresent - next; - - next += count; - return(count); -} - -int same(w1, w2) -short *w1; -int *w2; -{ - int i; - i = 8; - while (i--) - if (*w1++ != *w2++) return(0); - return(1); -} - -void outword(val, radix) -int val, radix; -{ -/* Output 'val' in 'radix' in a field of total size 'width'. */ - - int i; - - if (radix == 16) i = width - 4; - if (radix == 10) i = width - 5; - if (radix == 8) i = width - 6; - if (i == 1) - printf(" "); - else if (i == 2) - printf(" "); - else if (i == 3) - printf(" "); - else if (i == 4) - printf(" "); - outnum(val, radix); -} - - -void outnum(num, radix) -int num, radix; -{ -/* Output a number with all leading 0s present. Octal is 6 places, - * decimal is 5 places, hex is 4 places. - */ - unsigned val; - - val = (unsigned) num; - if (radix == 8) - printf ("%06o", val); - else if (radix == 10) - printf ("%05u", val); - else if (radix == 16) - printf ("%04x", val); - else if (radix == 7) { - /* special case */ - printf ("%03o", val); - } -} - - -void addrout(l) -long l; -{ - if (hflag == 0) { - printf("%07lo", l); - } else { - printf("%07lx", l); - } -} - - -void usage() -{ - fprintf(stderr, "Usage: od [-bcdhovx] [file] [ [+] offset [.] [b] ]\n"); -} diff --git a/man/man1/Makefile b/man/man1/Makefile index 2dd7a8ff2..9460797de 100644 --- a/man/man1/Makefile +++ b/man/man1/Makefile @@ -11,7 +11,7 @@ MAN= ash.1 at.1 \ last.1 loadfont.1 loadkeys.1 logger.1 \ look.1 lp.1 lspci.1 mail.1 \ mixer.1 \ - mkproto.1 mount.1 mt.1 od.1 \ + mkproto.1 mount.1 mt.1 \ ping.1 playwave.1 prep.1 \ profile.1 ps.1 rcp.1 recwave.1 \ remsync.1 rget.1 rlogin.1 rsh.1 rz.1 \ diff --git a/man/man1/od.1 b/man/man1/od.1 deleted file mode 100644 index 6601ab740..000000000 --- a/man/man1/od.1 +++ /dev/null @@ -1,58 +0,0 @@ -.TH OD 1 -.SH NAME -od \- octal dump -.SH SYNOPSIS -\fBod\fR [\fB\-bcdhox\fR]\fR [\fIfile\fR] [ [\fB+\fR] \fIoffset\fR [\fB.\fR][\fBb\fR]\fR ]\fR -.br -.de FL -.TP -\\fB\\$1\\fR -\\$2 -.. -.de EX -.TP 20 -\\fB\\$1\\fR -# \\$2 -.. -.SH OPTIONS -.TP 5 -.B \-b -# Dump bytes in octal -.TP 5 -.B \-c -# Dump bytes as ASCII characters -.TP 5 -.B \-d -# Dump words in decimal -.TP 5 -.B \-h -# Print addresses in hex (default is octal) -.TP 5 -.B \-o -# Dump words in octal (default) -.TP 5 -.B \-v -# Verbose (list duplicate lines) -.TP 5 -.B \-x -# Dump words in hex -.SH EXAMPLES -.TP 20 -.B od \-ox file -# Dump \fIfile\fP in octal and hex -.TP 20 -.B od \-d file +1000 -# Dump \fIfile\fP starting at byte 01000 -.TP 20 -.B od \-c file +10.b -# Dump \fIfile\fP starting at block 10 -.SH DESCRIPTION -.PP -.I Od -dumps a file in one or more formats. -If \fIfile\fP is missing, \fIstdin\fR is dumped. -The \fIoffset\fP argument tells -.I od -to skip a certain number of bytes or blocks before starting. -The offset is in octal bytes, unless it is followed by a -\&'.\&' for decimal or \fBb\fP for blocks or both. diff --git a/releasetools/nbsd_ports b/releasetools/nbsd_ports index b182cfa1e..ccfb793c4 100644 --- a/releasetools/nbsd_ports +++ b/releasetools/nbsd_ports @@ -168,6 +168,7 @@ 2012/10/17 12:00:00,usr.bin/fsplit 2013/04/05 12:00:00,usr.bin/ftp 2013/03/18 12:00:00,usr.bin/head +2012/10/17 12:00:00,usr.bin/hexdump 2012/10/17 12:00:00,usr.bin/genassym 2013/03/09 12:00:00,usr.bin/getopt 2012/10/17 12:00:00,usr.bin/gzip diff --git a/test/testsh2.sh b/test/testsh2.sh index f4b4f7ad8..4673f4726 100755 --- a/test/testsh2.sh +++ b/test/testsh2.sh @@ -116,18 +116,18 @@ head -1 $f |od >x # see if od converts ascii to octal ok if [ $ARCH = i86 -o $ARCH = i386 ] then cat >answer <answer <x # see if od converts ascii to decimal ok if [ $ARCH = i86 -o $ARCH = i386 ] then cat >answer <answer < diff --git a/commands/hexdump/conv.c b/usr.bin/hexdump/conv.c similarity index 99% rename from commands/hexdump/conv.c rename to usr.bin/hexdump/conv.c index 8376c0dfc..6b28ffe95 100644 --- a/commands/hexdump/conv.c +++ b/usr.bin/hexdump/conv.c @@ -34,7 +34,6 @@ #endif #include -#if 0 #if !defined(lint) #if 0 static char sccsid[] = "@(#)conv.c 8.1 (Berkeley) 6/6/93"; @@ -42,7 +41,6 @@ static char sccsid[] = "@(#)conv.c 8.1 (Berkeley) 6/6/93"; __RCSID("$NetBSD: conv.c,v 1.13 2010/02/09 14:06:37 drochner Exp $"); #endif #endif /* not lint */ -#endif #include diff --git a/commands/hexdump/display.c b/usr.bin/hexdump/display.c similarity index 99% rename from commands/hexdump/display.c rename to usr.bin/hexdump/display.c index 54832f89b..cb1d973ff 100644 --- a/commands/hexdump/display.c +++ b/usr.bin/hexdump/display.c @@ -34,7 +34,6 @@ #endif #include -#if 0 #if !defined(lint) #if 0 static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93"; @@ -42,7 +41,6 @@ static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93"; __RCSID("$NetBSD: display.c,v 1.21 2009/01/18 21:34:32 apb Exp $"); #endif #endif /* not lint */ -#endif #include #include diff --git a/commands/hexdump/hexdump.1 b/usr.bin/hexdump/hexdump.1 similarity index 80% rename from commands/hexdump/hexdump.1 rename to usr.bin/hexdump/hexdump.1 index c4684f218..96396f3b7 100644 --- a/commands/hexdump/hexdump.1 +++ b/usr.bin/hexdump/hexdump.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: hexdump.1,v 1.20 2010/02/27 10:45:23 mbalmer Exp $ +.\" $NetBSD: hexdump.1,v 1.24 2012/07/06 14:10:06 wiz Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)hexdump.1 8.2 (Berkeley) 4/18/94 .\" -.Dd February 27, 2010 +.Dd June 24, 2012 .Dt HEXDUMP 1 .Os .Sh NAME @@ -37,23 +37,20 @@ .Nd ascii, decimal, hexadecimal, octal dump .Sh SYNOPSIS .Nm -.Op Fl bcCdovx -.Bk -words +.Op Fl bCcdovx .Op Fl e Ar format_string -.Ek -.Bk -words .Op Fl f Ar format_file -.Ek -.Bk -words .Op Fl n Ar length -.Ek -.Bk -words .Op Fl s Ar skip -.Ek -.Ar file ... +.Op Ar .Sh DESCRIPTION -The hexdump utility is a filter which displays the specified files, or -the standard input, if no files are specified, in a user specified +The +.Nm +utility is a filter which displays each specified +.Ar file , +or the standard input if no +.Ar file +arguments are specified, in a user specified format. .Pp The options are as follows: @@ -63,16 +60,18 @@ The options are as follows: Display the input offset in hexadecimal, followed by sixteen space-separated, three column, zero-filled, bytes of input data, in octal, per line. +.It Fl C +.Em Canonical hex+ASCII display . +Display the input offset in hexadecimal, followed by sixteen +space-separated, two column, hexadecimal bytes, followed by the +same sixteen bytes in %_p format enclosed in +.Sq | +characters. .It Fl c .Em One-byte character display . Display the input offset in hexadecimal, followed by sixteen space-separated, three column, space-filled, characters of input data per line. -.It Fl C -.Em Canonical hex+ASCII display . -Display the input offset in hexadecimal, followed by sixteen -space-separated, two column, hexadecimal bytes, followed by the -same sixteen bytes in %_p format enclosed in ``|'' characters. .It Fl d .Em Two-byte decimal display . Display the input offset in hexadecimal, followed by eight @@ -83,7 +82,7 @@ Specify a format string to be used for displaying data. .It Fl f Ar format_file Specify a file that contains one or more newline separated format strings. Empty lines and lines whose first non-blank character is a hash mark -.Pf ( Cm \&# ) +.Pq Sq # are ignored. .It Fl n Ar length Interpret only @@ -94,22 +93,22 @@ bytes of input. Display the input offset in hexadecimal, followed by eight space-separated, six column, zero-filled, two byte quantities of input data, in octal, per line. -.It Fl s Ar offset +.It Fl s Ar skip Skip -.Ar offset +.Ar skip bytes from the beginning of the input. By default, -.Ar offset +.Ar skip is interpreted as a decimal number. With a leading .Cm 0x or .Cm 0X , -.Ar offset -is interpreted as a hexadecimal number, +.Ar skip +is interpreted as a hexadecimal number; otherwise, with a leading .Cm 0 , -.Ar offset +.Ar skip is interpreted as an octal number. Appending the character .Cm b , @@ -117,7 +116,7 @@ Appending the character or .Cm m to -.Ar offset +.Ar skip causes it to be interpreted as a multiple of .Li 512 , .Li 1024 , @@ -127,13 +126,16 @@ respectively. .It Fl v The .Fl v -option causes hexdump to display all input data. +option causes +.Nm +to display all input data. Without the .Fl v option, any number of groups of output lines, which would be identical to the immediately preceding group of output lines (except for the input offsets), are replaced with a line containing a -single asterisk. +single asterisk +.Pq Sq \&* . .It Fl x .Em Two-byte hexadecimal display . Display the input offset in hexadecimal, followed by eight, space @@ -164,47 +166,61 @@ If specified it defines the number of bytes to be interpreted by each iteration of the format. .Pp If an iteration count and/or a byte count is specified, a single slash +.Pq Sq / must be placed after the iteration count and/or before the byte count to disambiguate them. Any whitespace before or after the slash is ignored. .Pp The format is required and must be surrounded by double quote -(" ") marks. +.Pq Sq \&" +marks. It is interpreted as a fprintf-style format string (see .Xr fprintf 3 ) , with the following exceptions: .Bl -bullet -offset indent .It -An asterisk (*) may not be used as a field width or precision. +An asterisk +.Pq Sq \&* +may not be used as a field width or precision. .It A byte count or field precision .Em is -required for each ``s'' conversion +required for each +.Sq s +conversion character (unlike the .Xr fprintf 3 default which prints the entire string if the precision is unspecified). .It -The conversion characters ``h'', ``l'', ``n'', ``p'' and ``q'' are +The conversion characters +.Sq h , +.Sq l , +.Sq n , +.Sq p , +and +.Sq q +are not supported. .It The single character escape sequences described in the C standard are supported: .Bd -ragged -offset indent -compact -.Bl -column \*[Lt]alert_character\*[Gt] +.Bl -column Xalert_characterX .It NUL \e0 -.It \*[Lt]alert character\*[Gt] \ea -.It \*[Lt]backspace\*[Gt] \eb -.It \*[Lt]form-feed\*[Gt] \ef -.It \*[Lt]newline\*[Gt] \en -.It \*[Lt]carriage return\*[Gt] \er -.It \*[Lt]tab\*[Gt] \et -.It \*[Lt]vertical tab\*[Gt] \ev +.It Aq alert character \ea +.It Aq backspace \eb +.It Aq form-feed \ef +.It Aq newline \en +.It Aq carriage return \er +.It Aq tab \et +.It Aq vertical tab \ev .El .Ed .El .Pp -Hexdump also supports the following additional conversion strings: +.Nm +also supports the following additional conversion strings: .Bl -tag -width Fl .It Cm \&_a Ns Op Cm dox Display the input offset, cumulative across input files, of the @@ -223,26 +239,26 @@ conversion string except that it is only performed once, when all of the input data has been processed. .It Cm \&_c Output characters in the default character set. -Nonprinting characters are displayed in three character, zero-padded +Non-printing characters are displayed in three character, zero-padded octal, except for those representable by standard escape notation (see above), which are displayed as two character strings. .It Cm _p Output characters in the default character set. -Nonprinting characters are displayed as a single -.Dq Cm \&. . +Non-printing characters are displayed as a single +.Sq Cm \&. . .It Cm _u Output US ASCII characters, with the exception that control characters are displayed using the following, lower-case, names. Characters greater than 0xff, hexadecimal, are displayed as hexadecimal strings. .Bl -column \&000_nu \&001_so \&002_st \&003_et \&004_eo -.It \&000\ nul\t001\ soh\t002\ stx\t003\ etx\t004\ eot\t005\ enq -.It \&006\ ack\t007\ bel\t008\ bs\t009\ ht\t00A\ lf\t00B\ vt -.It \&00C\ ff\t00D\ cr\t00E\ so\t00F\ si\t010\ dle\t011\ dc1 -.It \&012\ dc2\t013\ dc3\t014\ dc4\t015\ nak\t016\ syn\t017\ etb -.It \&018\ can\t019\ em\t01A\ sub\t01B\ esc\t01C\ fs\t01D\ gs -.It \&01E\ rs\t01F\ us\t07F\ del +.It \&000\ nul Ta 001\ soh Ta 002\ stx Ta 003\ etx Ta 004\ eot Ta 005\ enq +.It \&006\ ack Ta 007\ bel Ta 008\ bs Ta 009\ ht Ta 00A\ lf Ta 00B\ vt +.It \&00C\ ff Ta 00D\ cr Ta 00E\ so Ta 00F\ si Ta 010\ dle Ta 011\ dc1 +.It \&012\ dc2 Ta 013\ dc3 Ta 014\ dc4 Ta 015\ nak Ta 016\ syn Ta 017\ etb +.It \&018\ can Ta 019\ em Ta 01A\ sub Ta 01B\ esc Ta 01C\ fs Ta 01D\ gs +.It \&01E\ rs Ta 01F\ us Ta 07F\ del .El .El .Pp @@ -262,7 +278,9 @@ data required by each format unit, which is the iteration count times the byte count, or the iteration count times the number of bytes required by the format if the byte count is not specified. .Pp -The input is manipulated in ``blocks'', where a block is defined as the +The input is manipulated in +.Dq blocks , +where a block is defined as the largest amount of data specified by any format string. Format strings interpreting less than an input block's worth of data, whose last format unit both interprets some number of bytes and does @@ -270,7 +288,9 @@ not have a specified iteration count, have the iteration count incremented until the entire input block has been processed or there is not enough data remaining in the block to satisfy the format string. .Pp -If, either as a result of user specification or hexdump modifying +If, either as a result of user specification or +.Nm +modifying the iteration count as described above, an iteration count is greater than one, no trailing whitespace characters are output during the last iteration. @@ -297,23 +317,21 @@ output by an conversion character with the same field width and precision as the original conversion character or conversion string but with any -.Dq Li \&+ , -.Dq \&\ \& , -.Dq Li \&# +.Sq Li \&+ , +.Sq \&\ \& , +and +.Sq Li \&# conversion flag characters -removed, and referencing a NULL string. +removed, and referencing a +.Dv NULL +string. .Pp If no format strings are specified, the default display is equivalent to specifying the .Fl x option. -.Pp -.Nm -exits 0 on success and \*[Gt]0 if an error occurred. -.Sh MINIX-SPECIFIC notes -If hexdump is compiled on a compiler that does not support long long (that is, -ACK), 64-bit (8 byte) integer formats are not supported. Conversions where this -is the default are changed to use a 32-bit 4 byte) default instead. +.Sh EXIT STATUS +.Ex -std .Sh EXAMPLES Display the input in perusal format: .Bd -literal -offset indent @@ -322,8 +340,12 @@ Display the input in perusal format: "\en" .Ed .Pp -Implement the \-x option: +Implement the +.Fl x +option: .Bd -literal -offset indent "%07.7_Ax\en" "%07.7_ax " 8/2 "%04x " "\en" .Ed +.Sh SEE ALSO +.Xr od 1 diff --git a/commands/hexdump/hexdump.c b/usr.bin/hexdump/hexdump.c similarity index 79% rename from commands/hexdump/hexdump.c rename to usr.bin/hexdump/hexdump.c index 8cbb274bb..2f7183527 100644 --- a/commands/hexdump/hexdump.c +++ b/usr.bin/hexdump/hexdump.c @@ -1,4 +1,4 @@ -/* $NetBSD: hexdump.c,v 1.15 2010/02/09 14:06:37 drochner Exp $ */ +/* $NetBSD: hexdump.c,v 1.18 2012/07/06 09:06:43 wiz Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,17 +34,15 @@ #endif #include -#if 0 #if !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1989, 1993\ The Regents of the University of California. All rights reserved."); #if 0 static char sccsid[] = "@(#)hexdump.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: hexdump.c,v 1.15 2010/02/09 14:06:37 drochner Exp $"); +__RCSID("$NetBSD: hexdump.c,v 1.18 2012/07/06 09:06:43 wiz Exp $"); #endif #endif /* not lint */ -#endif #include @@ -60,8 +58,7 @@ FS *fshead; /* head of format strings */ int blocksize; /* data block size */ int exitval; /* final exit value */ int length = -1; /* max bytes to read */ - -int main(int, char **); +static int isod = 0; int main(int argc, char *argv[]) @@ -71,10 +68,15 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); - if (!(p = strrchr(argv[0], 'o')) || strcmp(p, "od")) - newsyntax(argc, &argv); - else + isod = 0; + p = strrchr(argv[0], 'o'); + if (p != NULL && strcmp(p, "od") == 0) + isod = 1; + + if (isod) odsyntax(argc, &argv); + else + hexsyntax(argc, &argv); /* figure out the data block size */ for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) { @@ -90,3 +92,19 @@ main(int argc, char *argv[]) display(); exit(exitval); } + +void +usage(void) +{ + const char *pname = getprogname(); + + (void)fprintf(stderr, "usage: %s ", pname); + if (isod) + (void)fprintf(stderr, "[-aBbcDdeFfHhIiLlOovXx] [-A base] " + "[-j skip] [-N length] [-t type_string] [[+]offset[.][Bb]] " + "[file ...]\n"); + else + (void)fprintf(stderr, "[-bCcdovx] [-e format_string] [-f format_file] " + "[-n length] [-s skip] [file ...]\n"); + exit(1); +} diff --git a/commands/hexdump/hexdump.h b/usr.bin/hexdump/hexdump.h similarity index 93% rename from commands/hexdump/hexdump.h rename to usr.bin/hexdump/hexdump.h index e3a086d97..6d2c543c1 100644 --- a/commands/hexdump/hexdump.h +++ b/usr.bin/hexdump/hexdump.h @@ -1,4 +1,4 @@ -/* $NetBSD: hexdump.h,v 1.11 2010/02/09 14:06:37 drochner Exp $ */ +/* $NetBSD: hexdump.h,v 1.13 2011/09/04 20:27:27 joerg Exp $ */ /* * Copyright (c) 1989, 1993 @@ -81,21 +81,16 @@ extern enum _vflag vflag; void add(const char *); void addfile(char *); -void badcnt(char *); -void badconv(char *); -void badfmt(const char *); -void badsfmt(void); void bpad(PR *); void conv_c(PR *, u_char *); void conv_u(PR *, u_char *); void display(void); void doskip(const char *, int); -/*void err(const char *, ...);*/ void escape(char *); u_char *get(void); -void newsyntax(int, char ***); +void hexsyntax(int, char ***); int next(char **); void odsyntax(int, char ***); void rewrite(FS *); int size(FS *); -void usage(void); +void usage(void) __attribute__((__noreturn__)); diff --git a/commands/hexdump/hexsyntax.c b/usr.bin/hexdump/hexsyntax.c similarity index 91% rename from commands/hexdump/hexsyntax.c rename to usr.bin/hexdump/hexsyntax.c index 7364f5d97..67f84cfdc 100644 --- a/commands/hexdump/hexsyntax.c +++ b/usr.bin/hexdump/hexsyntax.c @@ -1,4 +1,4 @@ -/* $NetBSD: hexsyntax.c,v 1.13 2006/01/04 01:30:21 perry Exp $ */ +/* $NetBSD: hexsyntax.c,v 1.14 2010/11/27 20:46:38 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,15 +34,13 @@ #endif #include -#if 0 #if !defined(lint) #if 0 static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: hexsyntax.c,v 1.13 2006/01/04 01:30:21 perry Exp $"); +__RCSID("$NetBSD: hexsyntax.c,v 1.14 2010/11/27 20:46:38 christos Exp $"); #endif #endif /* not lint */ -#endif #include @@ -57,7 +55,7 @@ __RCSID("$NetBSD: hexsyntax.c,v 1.13 2006/01/04 01:30:21 perry Exp $"); off_t skip; /* bytes to skip */ void -newsyntax(int argc, char ***argvp) +hexsyntax(int argc, char ***argvp) { int ch; char *p, **argv; @@ -129,12 +127,3 @@ newsyntax(int argc, char ***argvp) *argvp += optind; } - -void -usage(void) -{ - (void)fprintf(stderr, -"hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n" - ); - exit(1); -} diff --git a/commands/hexdump/od.1 b/usr.bin/hexdump/od.1 similarity index 90% rename from commands/hexdump/od.1 rename to usr.bin/hexdump/od.1 index a0fe654df..ffed1462e 100644 --- a/commands/hexdump/od.1 +++ b/usr.bin/hexdump/od.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: od.1,v 1.25 2010/02/09 14:25:39 wiz Exp $ +.\" $NetBSD: od.1,v 1.27 2012/07/06 09:05:26 wiz Exp $ .\" .\" Copyright (c) 2001 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\"/ -.Dd February 9, 2010 +.Dd June 24, 2012 .Dt OD 1 .Os .Sh NAME @@ -36,16 +36,10 @@ .Sh SYNOPSIS .Nm .Op Fl aBbcDdeFfHhIiLlOovXx -.Bk -words .Op Fl A Ar base .Op Fl j Ar skip -.Ek -.Bk -words .Op Fl N Ar length -.Ek -.Bk -words .Op Fl t Ar type_string -.Ek .Sm off .Oo .Op Cm \&+ @@ -54,8 +48,17 @@ .Op Cm Bb .Sm on .Oc -.Ar file ... +.Op Ar .Sh DESCRIPTION +The +.Nm +utility is a filter which displays each specified +.Ar file , +or the standard input if no +.Ar file +arguments are specified, in a user specified +format. +.Pp The options are as follows: .Bl -tag -width Fl .It Fl A Ar base @@ -131,22 +134,22 @@ 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 +.It Fl j Ar skip Skip -.Ar offset +.Ar skip bytes from the beginning of the input. By default, -.Ar offset +.Ar skip is interpreted as a decimal number. With a leading .Cm 0x or .Cm 0X , -.Ar offset -is interpreted as a hexadecimal number, +.Ar skip +is interpreted as a hexadecimal number; otherwise, with a leading .Cm 0 , -.Ar offset +.Ar skip is interpreted as an octal number. Appending the character .Cm b , @@ -154,7 +157,7 @@ Appending the character or .Cm m to -.Ar offset +.Ar skip causes it to be interpreted as a multiple of .Li 512 , .Li 1024 , @@ -194,13 +197,15 @@ selects US-ASCII output, with control characters replaced with their names instead of as C escape sequences. See also the .Cm _u -conversion provided by hexdump(1). +conversion provided by +.Xr hexdump 1 . .Pp .Cm c selects a standard character based conversion. See also the .Cm _c -conversion provided by hexdump(1). +conversion provided by +.Xr hexdump 1 . .Pp .Cm f selects the floating point output format. @@ -216,7 +221,8 @@ to specify eight byte floating point output. The default output format is eight byte floats. See also the .Cm e -conversion provided by hexdump(1). +conversion provided by +.Xr hexdump 1 . .Pp .Cm d , .Cm o , @@ -256,7 +262,8 @@ See also the .Cm u , and .Cm x -conversions provided by hexdump(1). +conversions provided by +.Xr hexdump 1 . .\"(a|c|f[FLD]?|[doux][C1S2I4L8]?)* .It Fl v The @@ -269,7 +276,8 @@ Without the option, any number of groups of output lines, which would be identical to the immediately preceding group of output lines (except for the input offsets), are replaced with a line comprised of a -single asterisk. +single asterisk +.Pq Sq \&* . .It Fl X Same as .Fl H . @@ -286,18 +294,19 @@ If no options are specified, the default display is equivalent to specifying the .Fl o option. -.Pp -.Nm -exits 0 on success and \*[Gt]0 if an error occurred. +.Sh EXIT STATUS +.Ex -std .Sh SEE ALSO .Xr hexdump 1 , .Xr strings 1 .Sh HISTORY -A +An .Nm -command appears in +command appeared in .At v1 . .Pp -This man page was written in February 2001 by Andrew Brown, shortly -after he augmented the deprecated od syntax to include things he felt +This man page was initially written in February 2001 by Andrew Brown, shortly +after he augmented the deprecated +.Nm +syntax to include things he felt had been missing for a long time. diff --git a/commands/hexdump/odsyntax.c b/usr.bin/hexdump/odsyntax.c similarity index 98% rename from commands/hexdump/odsyntax.c rename to usr.bin/hexdump/odsyntax.c index 5ca9769e3..50770a4b1 100644 --- a/commands/hexdump/odsyntax.c +++ b/usr.bin/hexdump/odsyntax.c @@ -1,4 +1,4 @@ -/* $NetBSD: odsyntax.c,v 1.26 2010/02/09 14:06:37 drochner Exp $ */ +/* $NetBSD: odsyntax.c,v 1.28 2010/11/27 20:46:38 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,15 +34,13 @@ #endif #include -#if 0 #if !defined(lint) #if 0 static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: odsyntax.c,v 1.26 2010/02/09 14:06:37 drochner Exp $"); +__RCSID("$NetBSD: odsyntax.c,v 1.28 2010/11/27 20:46:38 christos Exp $"); #endif #endif /* not lint */ -#endif #include diff --git a/commands/hexdump/parse.c b/usr.bin/hexdump/parse.c similarity index 97% rename from commands/hexdump/parse.c rename to usr.bin/hexdump/parse.c index cc786f909..e29d966a5 100644 --- a/commands/hexdump/parse.c +++ b/usr.bin/hexdump/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.26 2009/01/18 21:34:32 apb Exp $ */ +/* $NetBSD: parse.c,v 1.27 2011/09/04 20:27:27 joerg Exp $ */ /* * Copyright (c) 1989, 1993 @@ -34,15 +34,13 @@ #endif #include -#if 0 #if !defined(lint) #if 0 static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93"; #else -__RCSID("$NetBSD: parse.c,v 1.26 2009/01/18 21:34:32 apb Exp $"); +__RCSID("$NetBSD: parse.c,v 1.27 2011/09/04 20:27:27 joerg Exp $"); #endif #endif /* not lint */ -#endif #include #include @@ -59,6 +57,11 @@ __RCSID("$NetBSD: parse.c,v 1.26 2009/01/18 21:34:32 apb Exp $"); #include "hexdump.h" +__dead static void badcnt(char *); +__dead static void badconv(char *); +__dead static void badfmt(const char *); +__dead static void badsfmt(void); + FU *endfu; /* format at end-of-data */ void @@ -520,25 +523,25 @@ escape(char *p1) } } -void +static void badcnt(char *s) { errx(1, "%s: bad byte count", s); } -void +static void badsfmt(void) { errx(1, "%%s: requires a precision or a byte count"); } -void +static void badfmt(const char *fmt) { errx(1, "\"%s\": bad format", fmt); } -void +static void badconv(char *ch) { errx(1, "%%%s: bad conversion character", ch); -- 2.44.0