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
This commit is contained in:
parent
69ccf97d12
commit
1e33498f8c
@ -10,14 +10,14 @@ SUBDIR= add_route arp ash at backup btrace \
|
|||||||
dhrystone diff diskctl dumpcore \
|
dhrystone diff diskctl dumpcore \
|
||||||
eject factor fbdctl \
|
eject factor fbdctl \
|
||||||
find fix format fortune fsck.mfs \
|
find fix format fortune fsck.mfs \
|
||||||
gcore gcov-pull getty grep hexdump host \
|
gcore gcov-pull getty grep host \
|
||||||
hostaddr id ifconfig ifdef \
|
hostaddr id ifconfig ifdef \
|
||||||
intr ipcrm ipcs irdpd isoread last \
|
intr ipcrm ipcs irdpd isoread last \
|
||||||
less loadkeys loadramdisk logger look lp \
|
less loadkeys loadramdisk logger look lp \
|
||||||
lpd lspci mail MAKEDEV \
|
lpd lspci mail MAKEDEV \
|
||||||
mined mkfifo \
|
mined mkfifo \
|
||||||
mount mt netconf \
|
mount mt netconf \
|
||||||
nonamed od patch \
|
nonamed patch \
|
||||||
ping postinstall poweroff prep printroot \
|
ping postinstall poweroff prep printroot \
|
||||||
profile progressbar pr_routes ps pwdauth \
|
profile progressbar pr_routes ps pwdauth \
|
||||||
ramdisk rarpd rawspeed rcp readclock \
|
ramdisk rarpd rawspeed rcp readclock \
|
||||||
|
@ -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 <bsd.prog.mk>
|
|
@ -1,4 +0,0 @@
|
|||||||
PROG= od
|
|
||||||
MAN=
|
|
||||||
|
|
||||||
.include <bsd.prog.mk>
|
|
314
commands/od/od.c
314
commands/od/od.c
@ -1,314 +0,0 @@
|
|||||||
/* od - octal dump Author: Andy Tanenbaum */
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
@ -11,7 +11,7 @@ MAN= ash.1 at.1 \
|
|||||||
last.1 loadfont.1 loadkeys.1 logger.1 \
|
last.1 loadfont.1 loadkeys.1 logger.1 \
|
||||||
look.1 lp.1 lspci.1 mail.1 \
|
look.1 lp.1 lspci.1 mail.1 \
|
||||||
mixer.1 \
|
mixer.1 \
|
||||||
mkproto.1 mount.1 mt.1 od.1 \
|
mkproto.1 mount.1 mt.1 \
|
||||||
ping.1 playwave.1 prep.1 \
|
ping.1 playwave.1 prep.1 \
|
||||||
profile.1 ps.1 rcp.1 recwave.1 \
|
profile.1 ps.1 rcp.1 recwave.1 \
|
||||||
remsync.1 rget.1 rlogin.1 rsh.1 rz.1 \
|
remsync.1 rget.1 rlogin.1 rsh.1 rz.1 \
|
||||||
|
@ -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.
|
|
@ -168,6 +168,7 @@
|
|||||||
2012/10/17 12:00:00,usr.bin/fsplit
|
2012/10/17 12:00:00,usr.bin/fsplit
|
||||||
2013/04/05 12:00:00,usr.bin/ftp
|
2013/04/05 12:00:00,usr.bin/ftp
|
||||||
2013/03/18 12:00:00,usr.bin/head
|
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
|
2012/10/17 12:00:00,usr.bin/genassym
|
||||||
2013/03/09 12:00:00,usr.bin/getopt
|
2013/03/09 12:00:00,usr.bin/getopt
|
||||||
2012/10/17 12:00:00,usr.bin/gzip
|
2012/10/17 12:00:00,usr.bin/gzip
|
||||||
|
@ -116,18 +116,18 @@ head -1 $f |od >x # see if od converts ascii to octal ok
|
|||||||
if [ $ARCH = i86 -o $ARCH = i386 ]
|
if [ $ARCH = i86 -o $ARCH = i386 ]
|
||||||
then
|
then
|
||||||
cat >answer <<END
|
cat >answer <<END
|
||||||
0000000 064124 020145 064564 062555 064040 071541 061440 066557
|
0000000 064124 020145 064564 062555 064040 071541 061440 066557
|
||||||
0000020 020145 064164 020145 060567 071154 071565 071440 064541
|
0000020 020145 064164 020145 060567 071154 071565 071440 064541
|
||||||
0000040 020144 067564 072040 066141 020153 063157 066440 067141
|
0000040 020144 067564 072040 066141 020153 063157 066440 067141
|
||||||
0000060 020171 064164 067151 071547 000012
|
0000060 020171 064164 067151 071547 000012
|
||||||
0000071
|
0000071
|
||||||
END
|
END
|
||||||
else
|
else
|
||||||
cat >answer <<END
|
cat >answer <<END
|
||||||
0000000 052150 062440 072151 066545 020150 060563 020143 067555
|
0000000 052150 062440 072151 066545 020150 060563 020143 067555
|
||||||
0000020 062440 072150 062440 073541 066162 072563 020163 060551
|
0000020 062440 072150 062440 073541 066162 072563 020163 060551
|
||||||
0000040 062040 072157 020164 060554 065440 067546 020155 060556
|
0000040 062040 072157 020164 060554 065440 067546 020155 060556
|
||||||
0000060 074440 072150 064556 063563 005000
|
0000060 074440 072150 064556 063563 005000
|
||||||
0000071
|
0000071
|
||||||
END
|
END
|
||||||
fi
|
fi
|
||||||
@ -138,18 +138,18 @@ head -1 $f |od -d >x # see if od converts ascii to decimal ok
|
|||||||
if [ $ARCH = i86 -o $ARCH = i386 ]
|
if [ $ARCH = i86 -o $ARCH = i386 ]
|
||||||
then
|
then
|
||||||
cat >answer <<END
|
cat >answer <<END
|
||||||
0000000 26708 08293 26996 25965 26656 29537 25376 28015
|
0000000 26708 08293 26996 25965 26656 29537 25376 28015
|
||||||
0000020 08293 26740 08293 24951 29292 29557 29472 26977
|
0000020 08293 26740 08293 24951 29292 29557 29472 26977
|
||||||
0000040 08292 28532 29728 27745 08299 26223 27936 28257
|
0000040 08292 28532 29728 27745 08299 26223 27936 28257
|
||||||
0000060 08313 26740 28265 29543 00010
|
0000060 08313 26740 28265 29543 00010
|
||||||
0000071
|
0000071
|
||||||
END
|
END
|
||||||
else
|
else
|
||||||
cat >answer <<END
|
cat >answer <<END
|
||||||
0000000 21608 25888 29801 28005 08296 24947 08291 28525
|
0000000 21608 25888 29801 28005 08296 24947 08291 28525
|
||||||
0000020 25888 29800 25888 30561 27762 30067 08307 24937
|
0000020 25888 29800 25888 30561 27762 30067 08307 24937
|
||||||
0000040 25632 29807 08308 24940 27424 28518 08301 24942
|
0000040 25632 29807 08308 24940 27424 28518 08301 24942
|
||||||
0000060 31008 29800 26990 26483 02560
|
0000060 31008 29800 26990 26483 02560
|
||||||
0000071
|
0000071
|
||||||
END
|
END
|
||||||
fi
|
fi
|
||||||
|
@ -12,7 +12,7 @@ SUBDIR= asa \
|
|||||||
env expand \
|
env expand \
|
||||||
finger fold from \
|
finger fold from \
|
||||||
fsplit ftp genassym getopt \
|
fsplit ftp genassym getopt \
|
||||||
head indent infocmp join \
|
head hexdump indent infocmp join \
|
||||||
ldd leave \
|
ldd leave \
|
||||||
lock login logname lorder m4 \
|
lock login logname lorder m4 \
|
||||||
machine make man mesg \
|
machine make man mesg \
|
||||||
|
18
usr.bin/hexdump/Makefile
Normal file
18
usr.bin/hexdump/Makefile
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# $NetBSD: Makefile,v 1.14 2011/08/14 13:45:34 christos 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
|
||||||
|
|
||||||
|
COPTS.conv.c += -Wno-format-nonliteral
|
||||||
|
COPTS.display.c += -Wno-format-nonliteral
|
||||||
|
|
||||||
|
.include <bsd.prog.mk>
|
@ -34,7 +34,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if 0
|
|
||||||
#if !defined(lint)
|
#if !defined(lint)
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)conv.c 8.1 (Berkeley) 6/6/93";
|
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 $");
|
__RCSID("$NetBSD: conv.c,v 1.13 2010/02/09 14:06:37 drochner Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
@ -34,7 +34,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if 0
|
|
||||||
#if !defined(lint)
|
#if !defined(lint)
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)display.c 8.1 (Berkeley) 6/6/93";
|
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 $");
|
__RCSID("$NetBSD: display.c,v 1.21 2009/01/18 21:34:32 apb Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
@ -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
|
.\" Copyright (c) 1989, 1990, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
@ -29,7 +29,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" from: @(#)hexdump.1 8.2 (Berkeley) 4/18/94
|
.\" from: @(#)hexdump.1 8.2 (Berkeley) 4/18/94
|
||||||
.\"
|
.\"
|
||||||
.Dd February 27, 2010
|
.Dd June 24, 2012
|
||||||
.Dt HEXDUMP 1
|
.Dt HEXDUMP 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -37,23 +37,20 @@
|
|||||||
.Nd ascii, decimal, hexadecimal, octal dump
|
.Nd ascii, decimal, hexadecimal, octal dump
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl bcCdovx
|
.Op Fl bCcdovx
|
||||||
.Bk -words
|
|
||||||
.Op Fl e Ar format_string
|
.Op Fl e Ar format_string
|
||||||
.Ek
|
|
||||||
.Bk -words
|
|
||||||
.Op Fl f Ar format_file
|
.Op Fl f Ar format_file
|
||||||
.Ek
|
|
||||||
.Bk -words
|
|
||||||
.Op Fl n Ar length
|
.Op Fl n Ar length
|
||||||
.Ek
|
|
||||||
.Bk -words
|
|
||||||
.Op Fl s Ar skip
|
.Op Fl s Ar skip
|
||||||
.Ek
|
.Op Ar
|
||||||
.Ar file ...
|
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The hexdump utility is a filter which displays the specified files, or
|
The
|
||||||
the standard input, if no files are specified, in a user specified
|
.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.
|
format.
|
||||||
.Pp
|
.Pp
|
||||||
The options are as follows:
|
The options are as follows:
|
||||||
@ -63,16 +60,18 @@ The options are as follows:
|
|||||||
Display the input offset in hexadecimal, followed by sixteen
|
Display the input offset in hexadecimal, followed by sixteen
|
||||||
space-separated, three column, zero-filled, bytes of input data,
|
space-separated, three column, zero-filled, bytes of input data,
|
||||||
in octal, per line.
|
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
|
.It Fl c
|
||||||
.Em One-byte character display .
|
.Em One-byte character display .
|
||||||
Display the input offset in hexadecimal, followed by sixteen
|
Display the input offset in hexadecimal, followed by sixteen
|
||||||
space-separated, three column, space-filled, characters of input
|
space-separated, three column, space-filled, characters of input
|
||||||
data per line.
|
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
|
.It Fl d
|
||||||
.Em Two-byte decimal display .
|
.Em Two-byte decimal display .
|
||||||
Display the input offset in hexadecimal, followed by eight
|
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
|
.It Fl f Ar format_file
|
||||||
Specify a file that contains one or more newline separated format strings.
|
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
|
Empty lines and lines whose first non-blank character is a hash mark
|
||||||
.Pf ( Cm \&# )
|
.Pq Sq #
|
||||||
are ignored.
|
are ignored.
|
||||||
.It Fl n Ar length
|
.It Fl n Ar length
|
||||||
Interpret only
|
Interpret only
|
||||||
@ -94,22 +93,22 @@ bytes of input.
|
|||||||
Display the input offset in hexadecimal, followed by eight
|
Display the input offset in hexadecimal, followed by eight
|
||||||
space-separated, six column, zero-filled, two byte quantities of
|
space-separated, six column, zero-filled, two byte quantities of
|
||||||
input data, in octal, per line.
|
input data, in octal, per line.
|
||||||
.It Fl s Ar offset
|
.It Fl s Ar skip
|
||||||
Skip
|
Skip
|
||||||
.Ar offset
|
.Ar skip
|
||||||
bytes from the beginning of the input.
|
bytes from the beginning of the input.
|
||||||
By default,
|
By default,
|
||||||
.Ar offset
|
.Ar skip
|
||||||
is interpreted as a decimal number.
|
is interpreted as a decimal number.
|
||||||
With a leading
|
With a leading
|
||||||
.Cm 0x
|
.Cm 0x
|
||||||
or
|
or
|
||||||
.Cm 0X ,
|
.Cm 0X ,
|
||||||
.Ar offset
|
.Ar skip
|
||||||
is interpreted as a hexadecimal number,
|
is interpreted as a hexadecimal number;
|
||||||
otherwise, with a leading
|
otherwise, with a leading
|
||||||
.Cm 0 ,
|
.Cm 0 ,
|
||||||
.Ar offset
|
.Ar skip
|
||||||
is interpreted as an octal number.
|
is interpreted as an octal number.
|
||||||
Appending the character
|
Appending the character
|
||||||
.Cm b ,
|
.Cm b ,
|
||||||
@ -117,7 +116,7 @@ Appending the character
|
|||||||
or
|
or
|
||||||
.Cm m
|
.Cm m
|
||||||
to
|
to
|
||||||
.Ar offset
|
.Ar skip
|
||||||
causes it to be interpreted as a multiple of
|
causes it to be interpreted as a multiple of
|
||||||
.Li 512 ,
|
.Li 512 ,
|
||||||
.Li 1024 ,
|
.Li 1024 ,
|
||||||
@ -127,13 +126,16 @@ respectively.
|
|||||||
.It Fl v
|
.It Fl v
|
||||||
The
|
The
|
||||||
.Fl v
|
.Fl v
|
||||||
option causes hexdump to display all input data.
|
option causes
|
||||||
|
.Nm
|
||||||
|
to display all input data.
|
||||||
Without the
|
Without the
|
||||||
.Fl v
|
.Fl v
|
||||||
option, any number of groups of output lines, which would be
|
option, any number of groups of output lines, which would be
|
||||||
identical to the immediately preceding group of output lines (except
|
identical to the immediately preceding group of output lines (except
|
||||||
for the input offsets), are replaced with a line containing a
|
for the input offsets), are replaced with a line containing a
|
||||||
single asterisk.
|
single asterisk
|
||||||
|
.Pq Sq \&* .
|
||||||
.It Fl x
|
.It Fl x
|
||||||
.Em Two-byte hexadecimal display .
|
.Em Two-byte hexadecimal display .
|
||||||
Display the input offset in hexadecimal, followed by eight, space
|
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.
|
each iteration of the format.
|
||||||
.Pp
|
.Pp
|
||||||
If an iteration count and/or a byte count is specified, a single slash
|
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
|
must be placed after the iteration count and/or before the byte count
|
||||||
to disambiguate them.
|
to disambiguate them.
|
||||||
Any whitespace before or after the slash is ignored.
|
Any whitespace before or after the slash is ignored.
|
||||||
.Pp
|
.Pp
|
||||||
The format is required and must be surrounded by double quote
|
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
|
It is interpreted as a fprintf-style format string (see
|
||||||
.Xr fprintf 3 ) ,
|
.Xr fprintf 3 ) ,
|
||||||
with the
|
with the
|
||||||
following exceptions:
|
following exceptions:
|
||||||
.Bl -bullet -offset indent
|
.Bl -bullet -offset indent
|
||||||
.It
|
.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
|
.It
|
||||||
A byte count or field precision
|
A byte count or field precision
|
||||||
.Em is
|
.Em is
|
||||||
required for each ``s'' conversion
|
required for each
|
||||||
|
.Sq s
|
||||||
|
conversion
|
||||||
character (unlike the
|
character (unlike the
|
||||||
.Xr fprintf 3
|
.Xr fprintf 3
|
||||||
default which prints the entire string if the precision is unspecified).
|
default which prints the entire string if the precision is unspecified).
|
||||||
.It
|
.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.
|
not supported.
|
||||||
.It
|
.It
|
||||||
The single character escape sequences
|
The single character escape sequences
|
||||||
described in the C standard are supported:
|
described in the C standard are supported:
|
||||||
.Bd -ragged -offset indent -compact
|
.Bd -ragged -offset indent -compact
|
||||||
.Bl -column \*[Lt]alert_character\*[Gt]
|
.Bl -column Xalert_characterX
|
||||||
.It NUL \e0
|
.It NUL \e0
|
||||||
.It \*[Lt]alert character\*[Gt] \ea
|
.It Aq alert character \ea
|
||||||
.It \*[Lt]backspace\*[Gt] \eb
|
.It Aq backspace \eb
|
||||||
.It \*[Lt]form-feed\*[Gt] \ef
|
.It Aq form-feed \ef
|
||||||
.It \*[Lt]newline\*[Gt] \en
|
.It Aq newline \en
|
||||||
.It \*[Lt]carriage return\*[Gt] \er
|
.It Aq carriage return \er
|
||||||
.It \*[Lt]tab\*[Gt] \et
|
.It Aq tab \et
|
||||||
.It \*[Lt]vertical tab\*[Gt] \ev
|
.It Aq vertical tab \ev
|
||||||
.El
|
.El
|
||||||
.Ed
|
.Ed
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Hexdump also supports the following additional conversion strings:
|
.Nm
|
||||||
|
also supports the following additional conversion strings:
|
||||||
.Bl -tag -width Fl
|
.Bl -tag -width Fl
|
||||||
.It Cm \&_a Ns Op Cm dox
|
.It Cm \&_a Ns Op Cm dox
|
||||||
Display the input offset, cumulative across input files, of the
|
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.
|
once, when all of the input data has been processed.
|
||||||
.It Cm \&_c
|
.It Cm \&_c
|
||||||
Output characters in the default character set.
|
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
|
octal, except for those representable by standard escape notation
|
||||||
(see above),
|
(see above),
|
||||||
which are displayed as two character strings.
|
which are displayed as two character strings.
|
||||||
.It Cm _p
|
.It Cm _p
|
||||||
Output characters in the default character set.
|
Output characters in the default character set.
|
||||||
Nonprinting characters are displayed as a single
|
Non-printing characters are displayed as a single
|
||||||
.Dq Cm \&. .
|
.Sq Cm \&. .
|
||||||
.It Cm _u
|
.It Cm _u
|
||||||
Output US ASCII characters, with the exception that control characters are
|
Output US ASCII characters, with the exception that control characters are
|
||||||
displayed using the following, lower-case, names.
|
displayed using the following, lower-case, names.
|
||||||
Characters greater than 0xff, hexadecimal, are displayed as hexadecimal
|
Characters greater than 0xff, hexadecimal, are displayed as hexadecimal
|
||||||
strings.
|
strings.
|
||||||
.Bl -column \&000_nu \&001_so \&002_st \&003_et \&004_eo
|
.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 \&000\ nul Ta 001\ soh Ta 002\ stx Ta 003\ etx Ta 004\ eot Ta 005\ enq
|
||||||
.It \&006\ ack\t007\ bel\t008\ bs\t009\ ht\t00A\ lf\t00B\ vt
|
.It \&006\ ack Ta 007\ bel Ta 008\ bs Ta 009\ ht Ta 00A\ lf Ta 00B\ vt
|
||||||
.It \&00C\ ff\t00D\ cr\t00E\ so\t00F\ si\t010\ dle\t011\ dc1
|
.It \&00C\ ff Ta 00D\ cr Ta 00E\ so Ta 00F\ si Ta 010\ dle Ta 011\ dc1
|
||||||
.It \&012\ dc2\t013\ dc3\t014\ dc4\t015\ nak\t016\ syn\t017\ etb
|
.It \&012\ dc2 Ta 013\ dc3 Ta 014\ dc4 Ta 015\ nak Ta 016\ syn Ta 017\ etb
|
||||||
.It \&018\ can\t019\ em\t01A\ sub\t01B\ esc\t01C\ fs\t01D\ gs
|
.It \&018\ can Ta 019\ em Ta 01A\ sub Ta 01B\ esc Ta 01C\ fs Ta 01D\ gs
|
||||||
.It \&01E\ rs\t01F\ us\t07F\ del
|
.It \&01E\ rs Ta 01F\ us Ta 07F\ del
|
||||||
.El
|
.El
|
||||||
.El
|
.El
|
||||||
.Pp
|
.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
|
byte count, or the iteration count times the number of bytes required by
|
||||||
the format if the byte count is not specified.
|
the format if the byte count is not specified.
|
||||||
.Pp
|
.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.
|
largest amount of data specified by any format string.
|
||||||
Format strings interpreting less than an input block's worth of data,
|
Format strings interpreting less than an input block's worth of data,
|
||||||
whose last format unit both interprets some number of bytes and does
|
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
|
incremented until the entire input block has been processed or there
|
||||||
is not enough data remaining in the block to satisfy the format string.
|
is not enough data remaining in the block to satisfy the format string.
|
||||||
.Pp
|
.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
|
the iteration count as described above, an iteration count is
|
||||||
greater than one, no trailing whitespace characters are output
|
greater than one, no trailing whitespace characters are output
|
||||||
during the last iteration.
|
during the last iteration.
|
||||||
@ -297,23 +317,21 @@ output by an
|
|||||||
conversion character with the same field width
|
conversion character with the same field width
|
||||||
and precision as the original conversion character or conversion
|
and precision as the original conversion character or conversion
|
||||||
string but with any
|
string but with any
|
||||||
.Dq Li \&+ ,
|
.Sq Li \&+ ,
|
||||||
.Dq \&\ \& ,
|
.Sq \&\ \& ,
|
||||||
.Dq Li \&#
|
and
|
||||||
|
.Sq Li \&#
|
||||||
conversion flag characters
|
conversion flag characters
|
||||||
removed, and referencing a NULL string.
|
removed, and referencing a
|
||||||
|
.Dv NULL
|
||||||
|
string.
|
||||||
.Pp
|
.Pp
|
||||||
If no format strings are specified, the default display is equivalent
|
If no format strings are specified, the default display is equivalent
|
||||||
to specifying the
|
to specifying the
|
||||||
.Fl x
|
.Fl x
|
||||||
option.
|
option.
|
||||||
.Pp
|
.Sh EXIT STATUS
|
||||||
.Nm
|
.Ex -std
|
||||||
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 EXAMPLES
|
.Sh EXAMPLES
|
||||||
Display the input in perusal format:
|
Display the input in perusal format:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
@ -322,8 +340,12 @@ Display the input in perusal format:
|
|||||||
"\en"
|
"\en"
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
Implement the \-x option:
|
Implement the
|
||||||
|
.Fl x
|
||||||
|
option:
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
"%07.7_Ax\en"
|
"%07.7_Ax\en"
|
||||||
"%07.7_ax " 8/2 "%04x " "\en"
|
"%07.7_ax " 8/2 "%04x " "\en"
|
||||||
.Ed
|
.Ed
|
||||||
|
.Sh SEE ALSO
|
||||||
|
.Xr od 1
|
@ -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
|
* Copyright (c) 1989, 1993
|
||||||
@ -34,17 +34,15 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if 0
|
|
||||||
#if !defined(lint)
|
#if !defined(lint)
|
||||||
__COPYRIGHT("@(#) Copyright (c) 1989, 1993\
|
__COPYRIGHT("@(#) Copyright (c) 1989, 1993\
|
||||||
The Regents of the University of California. All rights reserved.");
|
The Regents of the University of California. All rights reserved.");
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)hexdump.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)hexdump.c 8.1 (Berkeley) 6/6/93";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
@ -60,8 +58,7 @@ FS *fshead; /* head of format strings */
|
|||||||
int blocksize; /* data block size */
|
int blocksize; /* data block size */
|
||||||
int exitval; /* final exit value */
|
int exitval; /* final exit value */
|
||||||
int length = -1; /* max bytes to read */
|
int length = -1; /* max bytes to read */
|
||||||
|
static int isod = 0;
|
||||||
int main(int, char **);
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -71,10 +68,15 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
if (!(p = strrchr(argv[0], 'o')) || strcmp(p, "od"))
|
isod = 0;
|
||||||
newsyntax(argc, &argv);
|
p = strrchr(argv[0], 'o');
|
||||||
else
|
if (p != NULL && strcmp(p, "od") == 0)
|
||||||
|
isod = 1;
|
||||||
|
|
||||||
|
if (isod)
|
||||||
odsyntax(argc, &argv);
|
odsyntax(argc, &argv);
|
||||||
|
else
|
||||||
|
hexsyntax(argc, &argv);
|
||||||
|
|
||||||
/* figure out the data block size */
|
/* figure out the data block size */
|
||||||
for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
|
for (blocksize = 0, tfs = fshead; tfs; tfs = tfs->nextfs) {
|
||||||
@ -90,3 +92,19 @@ main(int argc, char *argv[])
|
|||||||
display();
|
display();
|
||||||
exit(exitval);
|
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);
|
||||||
|
}
|
@ -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
|
* Copyright (c) 1989, 1993
|
||||||
@ -81,21 +81,16 @@ extern enum _vflag vflag;
|
|||||||
|
|
||||||
void add(const char *);
|
void add(const char *);
|
||||||
void addfile(char *);
|
void addfile(char *);
|
||||||
void badcnt(char *);
|
|
||||||
void badconv(char *);
|
|
||||||
void badfmt(const char *);
|
|
||||||
void badsfmt(void);
|
|
||||||
void bpad(PR *);
|
void bpad(PR *);
|
||||||
void conv_c(PR *, u_char *);
|
void conv_c(PR *, u_char *);
|
||||||
void conv_u(PR *, u_char *);
|
void conv_u(PR *, u_char *);
|
||||||
void display(void);
|
void display(void);
|
||||||
void doskip(const char *, int);
|
void doskip(const char *, int);
|
||||||
/*void err(const char *, ...);*/
|
|
||||||
void escape(char *);
|
void escape(char *);
|
||||||
u_char *get(void);
|
u_char *get(void);
|
||||||
void newsyntax(int, char ***);
|
void hexsyntax(int, char ***);
|
||||||
int next(char **);
|
int next(char **);
|
||||||
void odsyntax(int, char ***);
|
void odsyntax(int, char ***);
|
||||||
void rewrite(FS *);
|
void rewrite(FS *);
|
||||||
int size(FS *);
|
int size(FS *);
|
||||||
void usage(void);
|
void usage(void) __attribute__((__noreturn__));
|
@ -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
|
* Copyright (c) 1990, 1993
|
||||||
@ -34,15 +34,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if 0
|
|
||||||
#if !defined(lint)
|
#if !defined(lint)
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95";
|
static char sccsid[] = "@(#)hexsyntax.c 8.2 (Berkeley) 5/4/95";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
@ -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 */
|
off_t skip; /* bytes to skip */
|
||||||
|
|
||||||
void
|
void
|
||||||
newsyntax(int argc, char ***argvp)
|
hexsyntax(int argc, char ***argvp)
|
||||||
{
|
{
|
||||||
int ch;
|
int ch;
|
||||||
char *p, **argv;
|
char *p, **argv;
|
||||||
@ -129,12 +127,3 @@ newsyntax(int argc, char ***argvp)
|
|||||||
|
|
||||||
*argvp += optind;
|
*argvp += optind;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
usage(void)
|
|
||||||
{
|
|
||||||
(void)fprintf(stderr,
|
|
||||||
"hexdump: [-bcCdovx] [-e fmt] [-f fmt_file] [-n length] [-s skip] [file ...]\n"
|
|
||||||
);
|
|
||||||
exit(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.
|
.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
@ -27,7 +27,7 @@
|
|||||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||||
.\"/
|
.\"/
|
||||||
.Dd February 9, 2010
|
.Dd June 24, 2012
|
||||||
.Dt OD 1
|
.Dt OD 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -36,16 +36,10 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl aBbcDdeFfHhIiLlOovXx
|
.Op Fl aBbcDdeFfHhIiLlOovXx
|
||||||
.Bk -words
|
|
||||||
.Op Fl A Ar base
|
.Op Fl A Ar base
|
||||||
.Op Fl j Ar skip
|
.Op Fl j Ar skip
|
||||||
.Ek
|
|
||||||
.Bk -words
|
|
||||||
.Op Fl N Ar length
|
.Op Fl N Ar length
|
||||||
.Ek
|
|
||||||
.Bk -words
|
|
||||||
.Op Fl t Ar type_string
|
.Op Fl t Ar type_string
|
||||||
.Ek
|
|
||||||
.Sm off
|
.Sm off
|
||||||
.Oo
|
.Oo
|
||||||
.Op Cm \&+
|
.Op Cm \&+
|
||||||
@ -54,8 +48,17 @@
|
|||||||
.Op Cm Bb
|
.Op Cm Bb
|
||||||
.Sm on
|
.Sm on
|
||||||
.Oc
|
.Oc
|
||||||
.Ar file ...
|
.Op Ar
|
||||||
.Sh DESCRIPTION
|
.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:
|
The options are as follows:
|
||||||
.Bl -tag -width Fl
|
.Bl -tag -width Fl
|
||||||
.It Fl A Ar base
|
.It Fl A Ar base
|
||||||
@ -131,22 +134,22 @@ decimal, per line.
|
|||||||
Display the input offset in octal, followed by eight space-separated,
|
Display the input offset in octal, followed by eight space-separated,
|
||||||
six column, space filled, two-byte units of input data, in decimal,
|
six column, space filled, two-byte units of input data, in decimal,
|
||||||
per line.
|
per line.
|
||||||
.It Fl j Ar offset
|
.It Fl j Ar skip
|
||||||
Skip
|
Skip
|
||||||
.Ar offset
|
.Ar skip
|
||||||
bytes from the beginning of the input.
|
bytes from the beginning of the input.
|
||||||
By default,
|
By default,
|
||||||
.Ar offset
|
.Ar skip
|
||||||
is interpreted as a decimal number.
|
is interpreted as a decimal number.
|
||||||
With a leading
|
With a leading
|
||||||
.Cm 0x
|
.Cm 0x
|
||||||
or
|
or
|
||||||
.Cm 0X ,
|
.Cm 0X ,
|
||||||
.Ar offset
|
.Ar skip
|
||||||
is interpreted as a hexadecimal number,
|
is interpreted as a hexadecimal number;
|
||||||
otherwise, with a leading
|
otherwise, with a leading
|
||||||
.Cm 0 ,
|
.Cm 0 ,
|
||||||
.Ar offset
|
.Ar skip
|
||||||
is interpreted as an octal number.
|
is interpreted as an octal number.
|
||||||
Appending the character
|
Appending the character
|
||||||
.Cm b ,
|
.Cm b ,
|
||||||
@ -154,7 +157,7 @@ Appending the character
|
|||||||
or
|
or
|
||||||
.Cm m
|
.Cm m
|
||||||
to
|
to
|
||||||
.Ar offset
|
.Ar skip
|
||||||
causes it to be interpreted as a multiple of
|
causes it to be interpreted as a multiple of
|
||||||
.Li 512 ,
|
.Li 512 ,
|
||||||
.Li 1024 ,
|
.Li 1024 ,
|
||||||
@ -194,13 +197,15 @@ selects US-ASCII output, with control characters replaced with their
|
|||||||
names instead of as C escape sequences.
|
names instead of as C escape sequences.
|
||||||
See also the
|
See also the
|
||||||
.Cm _u
|
.Cm _u
|
||||||
conversion provided by hexdump(1).
|
conversion provided by
|
||||||
|
.Xr hexdump 1 .
|
||||||
.Pp
|
.Pp
|
||||||
.Cm c
|
.Cm c
|
||||||
selects a standard character based conversion.
|
selects a standard character based conversion.
|
||||||
See also the
|
See also the
|
||||||
.Cm _c
|
.Cm _c
|
||||||
conversion provided by hexdump(1).
|
conversion provided by
|
||||||
|
.Xr hexdump 1 .
|
||||||
.Pp
|
.Pp
|
||||||
.Cm f
|
.Cm f
|
||||||
selects the floating point output format.
|
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.
|
The default output format is eight byte floats.
|
||||||
See also the
|
See also the
|
||||||
.Cm e
|
.Cm e
|
||||||
conversion provided by hexdump(1).
|
conversion provided by
|
||||||
|
.Xr hexdump 1 .
|
||||||
.Pp
|
.Pp
|
||||||
.Cm d ,
|
.Cm d ,
|
||||||
.Cm o ,
|
.Cm o ,
|
||||||
@ -256,7 +262,8 @@ See also the
|
|||||||
.Cm u ,
|
.Cm u ,
|
||||||
and
|
and
|
||||||
.Cm x
|
.Cm x
|
||||||
conversions provided by hexdump(1).
|
conversions provided by
|
||||||
|
.Xr hexdump 1 .
|
||||||
.\"(a|c|f[FLD]?|[doux][C1S2I4L8]?)*
|
.\"(a|c|f[FLD]?|[doux][C1S2I4L8]?)*
|
||||||
.It Fl v
|
.It Fl v
|
||||||
The
|
The
|
||||||
@ -269,7 +276,8 @@ Without the
|
|||||||
option, any number of groups of output lines, which would be
|
option, any number of groups of output lines, which would be
|
||||||
identical to the immediately preceding group of output lines (except
|
identical to the immediately preceding group of output lines (except
|
||||||
for the input offsets), are replaced with a line comprised of a
|
for the input offsets), are replaced with a line comprised of a
|
||||||
single asterisk.
|
single asterisk
|
||||||
|
.Pq Sq \&* .
|
||||||
.It Fl X
|
.It Fl X
|
||||||
Same as
|
Same as
|
||||||
.Fl H .
|
.Fl H .
|
||||||
@ -286,18 +294,19 @@ If no options are specified, the
|
|||||||
default display is equivalent to specifying the
|
default display is equivalent to specifying the
|
||||||
.Fl o
|
.Fl o
|
||||||
option.
|
option.
|
||||||
.Pp
|
.Sh EXIT STATUS
|
||||||
.Nm
|
.Ex -std
|
||||||
exits 0 on success and \*[Gt]0 if an error occurred.
|
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr hexdump 1 ,
|
.Xr hexdump 1 ,
|
||||||
.Xr strings 1
|
.Xr strings 1
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
A
|
An
|
||||||
.Nm
|
.Nm
|
||||||
command appears in
|
command appeared in
|
||||||
.At v1 .
|
.At v1 .
|
||||||
.Pp
|
.Pp
|
||||||
This man page was written in February 2001 by Andrew Brown, shortly
|
This man page was initially written in February 2001 by Andrew Brown, shortly
|
||||||
after he augmented the deprecated od syntax to include things he felt
|
after he augmented the deprecated
|
||||||
|
.Nm
|
||||||
|
syntax to include things he felt
|
||||||
had been missing for a long time.
|
had been missing for a long time.
|
@ -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
|
* Copyright (c) 1990, 1993
|
||||||
@ -34,15 +34,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if 0
|
|
||||||
#if !defined(lint)
|
#if !defined(lint)
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
|
static char sccsid[] = "@(#)odsyntax.c 8.2 (Berkeley) 5/4/95";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
@ -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
|
* Copyright (c) 1989, 1993
|
||||||
@ -34,15 +34,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if 0
|
|
||||||
#if !defined(lint)
|
#if !defined(lint)
|
||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
|
||||||
#else
|
#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
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
@ -59,6 +57,11 @@ __RCSID("$NetBSD: parse.c,v 1.26 2009/01/18 21:34:32 apb Exp $");
|
|||||||
|
|
||||||
#include "hexdump.h"
|
#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 */
|
FU *endfu; /* format at end-of-data */
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -520,25 +523,25 @@ escape(char *p1)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
badcnt(char *s)
|
badcnt(char *s)
|
||||||
{
|
{
|
||||||
errx(1, "%s: bad byte count", s);
|
errx(1, "%s: bad byte count", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
badsfmt(void)
|
badsfmt(void)
|
||||||
{
|
{
|
||||||
errx(1, "%%s: requires a precision or a byte count");
|
errx(1, "%%s: requires a precision or a byte count");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
badfmt(const char *fmt)
|
badfmt(const char *fmt)
|
||||||
{
|
{
|
||||||
errx(1, "\"%s\": bad format", fmt);
|
errx(1, "\"%s\": bad format", fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
badconv(char *ch)
|
badconv(char *ch)
|
||||||
{
|
{
|
||||||
errx(1, "%%%s: bad conversion character", ch);
|
errx(1, "%%%s: bad conversion character", ch);
|
Loading…
x
Reference in New Issue
Block a user