Implement od(1) v-flag

If this flag is not given, od(1) automatically replaces duplicate
adjacent lines with an '*' for each reoccurence.
If this flag is set, thus, no such filtering occurs.

In this case this would mean having to somehow keep the last printed
line in some backbuffer, building the next line and then doing the
necessary comparisons. This basically means that we duplicate the
functionality provided with uniq(1).

So instead of

$ od -t a > dump

you'd rather do

$ od -t a | uniq -f 1 -c > dump

Skipping the first field is necessary, as the addresses obviously differ.

Now, I was thinking hard why this flag even exists. If POSIX mandated
to add the address before the asterisk, so we know the offset of duplicate
occurrences, this would make sense. However, this is not the case.

Using uniq(1) also gives nicer output:
~ $ echo "111111111111111111111111111111111111111111111111" | od -t a -v | uniq -f 1 -c
      3 0000000   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
      1 0000060  nl
      1 0000061

in comparison to

$ echo "111111111111111111111111111111111111111111111111" | od -t a
0000000   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
0000060  nl

Before working on od(1), I didn't even know it would filter out
duplicate adjacent lines like that. This is also a matter of

Concluding, the v-flag is implicitly set and users urged to just
use the existing tools provided by the system.
I don't think we would break scripts either. Firstly, it's rather
unlikely to have duplicate lines exactly matching the line-length of
od(1). Secondly, even if a script did that specifically, in the worst
case there would be a counting error or something.

Given od(1) is mostly used interactively, we can safely assume this
feature is for the benefit of the users.

Ditch this legacy POSIX crap!
 Please enter the commit message for your changes. Lines starting
This commit is contained in:
FRIGN 2015-09-30 12:54:24 +02:00 committed by sin
parent f8f2a56852
commit fc886aa144
3 changed files with 8 additions and 2 deletions

View File

@ -54,7 +54,7 @@ The following tools are implemented:
=*|o nice .
#*|o nl .
=*|o nohup .
od -t, -v
od -t
#*|o paste .
=*|x printenv .
#*|o printf .

View File

@ -8,6 +8,7 @@
.Op Fl A Ar d|o|x|n
.Op Fl t Ar a|c|d|o|u|x
.Op Fl v
.Op Ar file...
@ -27,4 +28,6 @@ he\fIx\fRadecimal | \fIn\fRone. If unspecified, the default is octal.
Display the content as n\fIa\fRmed character, \fIc\fRharacter, signed
\fId\fRecimal, \fIo\fRctal, \fIu\fRnsigned decimal, or
he\fIx\fRadecimal. If unspecified, the default is octal.
.It Fl v
Always set. Write all input data, including duplicate lines.

View File

@ -100,7 +100,7 @@ od(FILE *in, char *in_name, FILE *out, char *out_name)
static void
eprintf("usage: %s [-A d|o|x|n] [-t a|c|d|o|u|x] [file ...]\n", argv0);
eprintf("usage: %s [-A d|o|x|n] [-t a|c|d|o|u|x] [-v] [file ...]\n", argv0);
@ -129,6 +129,9 @@ main(int argc, char *argv[])
type = s[0];
case 'v':
/* Always set. Use "uniq -f 1 -c" to handle duplicate lines. */