@@ -24,9 +24,10 @@ use constant LINESZ => 16;
2424use constant PRINTMAX => 126;
2525
2626use vars qw/ $opt_A $opt_a $opt_B $opt_b $opt_c $opt_d $opt_e $opt_F $opt_f
27- $opt_H $opt_i $opt_j $opt_l $opt_N $opt_O $opt_o $opt_s $opt_v $opt_X $opt_x / ;
27+ $opt_H $opt_i $opt_j $opt_l $opt_N $opt_O $opt_o $opt_s $opt_t $opt_v
28+ $opt_X $opt_x / ;
2829
29- our $VERSION = ' 1.1 ' ;
30+ our $VERSION = ' 1.2 ' ;
3031
3132my ($offset1 , $radix , $data , @arr , $lim );
3233my ($lastline , $strfmt , $ml );
@@ -85,7 +86,7 @@ $lastline = '';
8586
8687my $Program = basename($0 );
8788
88- getopts(' A:aBbcdeFfHij:lN:OosvXx ' ) or help();
89+ getopts(' A:aBbcdeFfHij:lN:Oost:vXx ' ) or help();
8990if (defined $opt_A ) {
9091 if ($opt_A !~ m /\A [doxn] \z / ) {
9192 warn " $Program : unexpected radix: '$opt_A '\n " ;
@@ -154,6 +155,19 @@ else {
154155 $fmt = \&octal2;
155156}
156157
158+ if (defined $opt_t ) {
159+ if ($opt_t eq ' x1' ) {
160+ $fmt = \&hex1;
161+ } elsif ($opt_t eq ' x2' ) {
162+ $fmt = \&hex2;
163+ } elsif ($opt_t eq ' x4' ) {
164+ $fmt = \&hex4;
165+ } else {
166+ warn " $Program : unexpected output format specifier\n " ;
167+ exit EX_FAILURE;
168+ }
169+ }
170+
157171my $nread = 0;
158172my $rc = EX_SUCCESS;
159173foreach my $file (@ARGV ) {
@@ -258,6 +272,11 @@ sub octal1 {
258272 $strfmt = ' %.3o ' x (scalar @arr );
259273}
260274
275+ sub hex1 {
276+ @arr = unpack ' C*' , $data ;
277+ $strfmt = ' %.2x ' x (scalar @arr );
278+ }
279+
261280sub char1 {
262281 @arr = ();
263282 my @arr1 = unpack ' C*' , $data ;
@@ -348,7 +367,8 @@ sub diffdata {
348367}
349368
350369sub help {
351- print " usage: od [-aBbcdeFfHilOosXxv] [-A radix] [-j skip_bytes] [-N limit_bytes] [file]...\n " ;
370+ print " usage: od [-aBbcdeFfHilOosXxv] [-A radix] [-j skip_bytes] " ,
371+ " [-N limit_bytes] [-t type] [file]...\n " ;
352372 exit EX_FAILURE;
353373}
354374__END__
@@ -359,7 +379,8 @@ od - dump files in octal and other formats
359379
360380=head1 SYNOPSIS
361381
362- B<od > [ I<-aBbcdeFfHilOosXxv > ] [I<-j skip_n_bytes > ] [I<-N read_n_bytes > ] [ I<-A radix > ] [ F<file> ... ]
382+ B<od > [ I<-aBbcdeFfHilOosXxv > ] [I<-j skip_bytes > ] [I<-N limit_bytes > ]
383+ [ I<-A radix > ] [ I<-t type > ] [ F<file> ... ]
363384
364385=head1 DESCRIPTION
365386
@@ -445,6 +466,11 @@ Format input as two-byte octal numbers.
445466
446467Same as -i
447468
469+ =item -t Type
470+
471+ Select hexadecimal output size as either "x1", "x2" or "x4".
472+ This option overrides other formatting options.
473+
448474=item -X
449475
450476Same as -H
0 commit comments