Skip to content

Commit 3d8af3d

Browse files
authored
od: add -D option
* GNU and OpenBSD versions support -d for 2-byte unsigned decimal and -D for 4-byte unsigned decimal * This versions was missing -D; it's a shortcut option for -t u4 * The OpenBSD manual incorrectly states that -D is an octal format[1] * The OpenBSD source confirms the format is unsigned decimal[2] 1. http://man.openbsd.org/od 2. https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/hexdump/odsyntax.c?annotate=1.28 (L127)
1 parent 85b3126 commit 3d8af3d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

bin/od

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ use constant EX_FAILURE => 1;
2323
use constant LINESZ => 16;
2424
use constant PRINTMAX => 126;
2525

26-
use vars qw/ $opt_A $opt_a $opt_B $opt_b $opt_c $opt_d $opt_e $opt_F $opt_f
27-
$opt_H $opt_h $opt_i $opt_j $opt_l $opt_N $opt_O $opt_o $opt_s $opt_t
28-
$opt_v $opt_X $opt_x /;
26+
use vars qw/ $opt_A $opt_a $opt_B $opt_b $opt_c $opt_D $opt_d $opt_e $opt_F
27+
$opt_f $opt_H $opt_h $opt_i $opt_j $opt_l $opt_N $opt_O $opt_o $opt_s
28+
$opt_t $opt_v $opt_X $opt_x /;
2929

30-
our $VERSION = '1.3';
30+
our $VERSION = '1.4';
3131

3232
my ($offset1, $radix, $data, @arr, $lim);
3333
my ($lastline, $strfmt, $ml);
@@ -87,7 +87,7 @@ $lastline = '';
8787

8888
my $Program = basename($0);
8989

90-
getopts('A:aBbcdeFfHhij:lN:Oost:vXx') or help();
90+
getopts('A:aBbcDdeFfHhij:lN:Oost:vXx') or help();
9191
if (defined $opt_A) {
9292
if ($opt_A !~ m/\A[doxn]\z/) {
9393
warn "$Program: unexpected radix: '$opt_A'\n";
@@ -125,6 +125,9 @@ elsif ($opt_b) {
125125
elsif ($opt_c) {
126126
$fmt = \&char1;
127127
}
128+
elsif ($opt_D) {
129+
$fmt = \&udecimal4;
130+
}
128131
elsif ($opt_d) {
129132
$fmt = \&udecimal2;
130133
}
@@ -452,7 +455,7 @@ sub diffdata {
452455
}
453456

454457
sub help {
455-
print "usage: od [-aBbcdeFfHhilOosXxv] [-A radix] [-j skip_bytes] ",
458+
print "usage: od [-aBbcDdeFfHhilOosXxv] [-A radix] [-j skip_bytes] ",
456459
"[-N limit_bytes] [-t type] [file]...\n";
457460
exit EX_FAILURE;
458461
}
@@ -464,7 +467,7 @@ od - dump files in octal and other formats
464467
465468
=head1 SYNOPSIS
466469
467-
B<od> [ I<-aBbcdeFfHhilOosXxv> ] [I<-j skip_bytes>] [I<-N limit_bytes>]
470+
B<od> [ I<-aBbcDdeFfHhilOosXxv> ] [I<-j skip_bytes>] [I<-N limit_bytes>]
468471
[ I<-A radix> ] [ I<-t type> ] [ F<file>... ]
469472
470473
=head1 DESCRIPTION
@@ -503,6 +506,10 @@ Single-byte octal display.
503506
504507
Display characters literally, with non-printable characters displayed as C escape sequences.
505508
509+
=item -D
510+
511+
Four-byte unsigned decimal display.
512+
506513
=item -d
507514
508515
Two-byte unsigned decimal display.

0 commit comments

Comments
 (0)