From 0128dbf214d7926bf2d33756a0f465175f2d0477 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:52:29 +0800 Subject: [PATCH] od: factor dump_line() * The -v flag works the same as for hexdump command, i.e. display all lines including duplicated input * diffdata() compares current line to previous line; if -v flag is given there's no need to call it * Save $lastline if we're not in verbose mode and if we saw a difference in the data * $ml becomes true when we saw a duplicate; this prevents '*' from being printed multiple times --- bin/od | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/bin/od b/bin/od index ae9a6549..f9c48df8 100755 --- a/bin/od +++ b/bin/od @@ -198,17 +198,20 @@ sub emit_offset { } sub dump_line { - if (&diffdata || $opt_v) { + unless ($opt_v) { + if (diffdata()) { + $lastline = $data . '|'; + $ml = 0; + } else { + print "*\n" unless $ml; + $ml = 1; + } + } + unless ($ml) { emit_offset(); &$fmt; printf "$strfmt\n", @arr; - $ml = 0; - } - else { - print "*\n" unless $ml; - $ml = 1; } - $lastline = $data . '|'; $offset1 += length $data; undef $data; }