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 0000061 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 predictability. 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:
parent
f8f2a56852
commit
fc886aa144
2
README
2
README
|
@ -54,7 +54,7 @@ The following tools are implemented:
|
||||||
=*|o nice .
|
=*|o nice .
|
||||||
#*|o nl .
|
#*|o nl .
|
||||||
=*|o nohup .
|
=*|o nohup .
|
||||||
od -t, -v
|
od -t
|
||||||
#*|o paste .
|
#*|o paste .
|
||||||
=*|x printenv .
|
=*|x printenv .
|
||||||
#*|o printf .
|
#*|o printf .
|
||||||
|
|
3
od.1
3
od.1
|
@ -8,6 +8,7 @@
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl A Ar d|o|x|n
|
.Op Fl A Ar d|o|x|n
|
||||||
.Op Fl t Ar a|c|d|o|u|x
|
.Op Fl t Ar a|c|d|o|u|x
|
||||||
|
.Op Fl v
|
||||||
.Op Ar file...
|
.Op Ar file...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
|
@ -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
|
Display the content as n\fIa\fRmed character, \fIc\fRharacter, signed
|
||||||
\fId\fRecimal, \fIo\fRctal, \fIu\fRnsigned decimal, or
|
\fId\fRecimal, \fIo\fRctal, \fIu\fRnsigned decimal, or
|
||||||
he\fIx\fRadecimal. If unspecified, the default is octal.
|
he\fIx\fRadecimal. If unspecified, the default is octal.
|
||||||
|
.It Fl v
|
||||||
|
Always set. Write all input data, including duplicate lines.
|
||||||
.El
|
.El
|
||||||
|
|
5
od.c
5
od.c
|
@ -100,7 +100,7 @@ od(FILE *in, char *in_name, FILE *out, char *out_name)
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -129,6 +129,9 @@ main(int argc, char *argv[])
|
||||||
usage();
|
usage();
|
||||||
type = s[0];
|
type = s[0];
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
/* Always set. Use "uniq -f 1 -c" to handle duplicate lines. */
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user