From 7429a1801ccce2e52ba71dd0c8d3c3e46bdfa018 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Fri, 24 Jan 2025 07:43:18 +0800 Subject: [PATCH] od: make float formats accessible with -t * Support arguments "-t f4" and "-t f8", which are already exposed as options -f and -F respectively * In future, od can support multiple formats at once, e.g. "-t f4f8", but for now only one format is allowed --- bin/od | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/od b/bin/od index ba7ca899..a589686e 100755 --- a/bin/od +++ b/bin/od @@ -132,7 +132,7 @@ elsif ($opt_e || $opt_F) { $fmt = \&float8; } elsif ($opt_f) { - $fmt = \&float; + $fmt = \&float4; } elsif ($opt_H || $opt_X) { $fmt = \&hex4; @@ -189,6 +189,10 @@ if (defined $opt_t) { $fmt = \&udecimal4; } elsif ($opt_t eq 'u8') { $fmt = \&udecimal8; + } elsif ($opt_t eq 'f4') { + $fmt = \&float4; + } elsif ($opt_t eq 'f8') { + $fmt = \&float8; } elsif ($opt_t eq 'a') { $fmt = \&char7bit; } elsif ($opt_t eq 'c') { @@ -365,7 +369,7 @@ sub udecimal2 { $strfmt = '%5u ' x (scalar @arr); } -sub float { +sub float4 { @arr = unpack 'f*', $data . zeropad(length($data), 4); $strfmt = '%15.7e ' x (scalar @arr); } @@ -569,6 +573,8 @@ Select output format as one of the following: x2 2-byte unsigned hexadecimal x4 4-byte unsigned hexadecimal x8 8-byte unsigned hexadecimal + f4 4-byte floating point. Same as -f + f8 8-byte floating point. Same as -F This option overrides other formatting options.