[hackers] [sbase] Fix tr(1) squeezing || FRIGN

From: <git_AT_suckless.org>
Date: Wed, 5 Oct 2016 19:32:58 +0200 (CEST)

commit 9de401a495701836d744dc6c55ff62f361369753
Author: FRIGN <dev_AT_frign.de>
AuthorDate: Wed Oct 5 19:31:50 2016 +0200
Commit: FRIGN <dev_AT_frign.de>
CommitDate: Wed Oct 5 19:31:50 2016 +0200

    Fix tr(1) squeezing
    
    Okay, it took me a while and another look at the Posix spec to see that
    I have been dealing with squeezing in a way too complicated way.
    What just needed to be done is before doing the final write to deploy
    the squeeze-check. We actually do not need this atomically complicated
    squeeze check in every single edge-case. Now it should work properly.

diff --git a/tr.c b/tr.c
index 361ac40..d6d1044 100644
--- a/tr.c
+++ b/tr.c
_AT_@ -213,7 +213,7 @@ read:
         for (i = 0; i < set1ranges; i++) {
                 if (set1[i].start <= r && r <= set1[i].end) {
                         if (dflag) {
- if (!cflag || (sflag && r == lastrune))
+ if (!cflag)
                                         goto read;
                                 else
                                         goto write;
_AT_@ -244,13 +244,7 @@ read:
         }
         if (set1check && set1check(r)) {
                 if (dflag) {
- if (!cflag || (sflag && r == lastrune))
- goto read;
- else
- goto write;
- }
- if (sflag) {
- if (r == lastrune)
+ if (!cflag)
                                 goto read;
                         else
                                 goto write;
_AT_@ -268,9 +262,15 @@ read:
         }
         if (dflag && cflag)
                 goto read;
- if (dflag && sflag && r == lastrune)
- goto read;
 write:
+ if (sflag && r == lastrune) {
+ if (set2check && set2check(r))
+ goto read;
+ for (i = 0; i < set2ranges; i++) {
+ if (set2[i].start <= r && r <= set2[i].end)
+ goto read;
+ }
+ }
         lastrune = r;
         efputrune(&r, stdout, "<stdout>");
         goto read;
Received on Wed Oct 05 2016 - 19:32:58 CEST

This archive was generated by hypermail 2.3.0 : Wed Oct 05 2016 - 19:36:15 CEST