[hackers] [sbase] Implement od(1) v-flag || FRIGN

From: <git_AT_suckless.org>
Date: Wed, 30 Sep 2015 20:44:18 +0200 (CEST)

commit fc886aa14404861d9ad44d2414425bf192dfacf6
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Wed Sep 30 12:54:24 2015 +0200
Commit: sin <sin_AT_2f30.org>
CommitDate: Wed Sep 30 19:44:10 2015 +0100

    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

diff --git a/README b/README
index 0fde83a..4a3d7a0 100644
--- a/README
+++ b/README
_AT_@ -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 .
diff --git a/od.1 b/od.1
index 2fb1311..7900dc7 100644
--- a/od.1
+++ b/od.1
_AT_@ -8,6 +8,7 @@
 .Nm
 .Op Fl A Ar d|o|x|n
 .Op Fl t Ar a|c|d|o|u|x
+.Op Fl v
 .Op Ar file...
 .Sh DESCRIPTION
 .Nm
_AT_@ -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.
 .El
diff --git a/od.c b/od.c
index effe5f5..30031c7 100644
--- a/od.c
+++ b/od.c
_AT_@ -100,7 +100,7 @@ od(FILE *in, char *in_name, FILE *out, char *out_name)
 static 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
_AT_@ -129,6 +129,9 @@ main(int argc, char *argv[])
                         usage();
                 type = s[0];
                 break;
+ case 'v':
+ /* Always set. Use "uniq -f 1 -c" to handle duplicate lines. */
+ break;
         default:
                 usage();
         } ARGEND;
Received on Wed Sep 30 2015 - 20:44:18 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 30 2015 - 20:48:34 CEST