[hackers] [sbase] Fix tr(1) behaviour in special cases and be stricter about stuff || FRIGN

From: <git_AT_suckless.org>
Date: Mon, 2 Feb 2015 20:03:33 +0100 (CET)

commit 23a388195fd89e0fc5ccc63074ad5ced849accf7
Author: FRIGN <dev_AT_frign.de>
Date: Mon Feb 2 19:59:41 2015 +0100

    Fix tr(1) behaviour in special cases and be stricter about stuff

diff --git a/tr.c b/tr.c
index 352a862..a9eb190 100644
--- a/tr.c
+++ b/tr.c
_AT_@ -202,6 +202,8 @@ main(int argc, char *argv[])
                 eprintf("set2 must be non-empty.\n");
         if (set2check && set2check != iswlower && set2check != iswupper)
                 eprintf("set2 can only be the 'lower' or 'upper' class.\n");
+ if (set2check && cflag && !dflag)
+ eprintf("set2 can't be imaged to from a complement.\n");
 read:
         if (!readrune("<stdin>", stdin, &r))
                 return 0;
_AT_@ -209,10 +211,10 @@ read:
         for (i = 0; i < set1ranges; i++) {
                 if (set1[i].start <= r && r <= set1[i].end) {
                         if (dflag) {
- if (cflag)
- goto write;
- else
+ if (!cflag || (sflag && r == lastrune))
                                         goto read;
+ else
+ goto write;
                         }
                         if (sflag) {
                                 if (r == lastrune)
_AT_@ -241,11 +243,12 @@ read:
                 }
         }
         if (set1check && set1check((wint_t)r)) {
- if (dflag)
- if (cflag)
- goto write;
- else
+ if (dflag) {
+ if (!cflag || (sflag && r == lastrune))
                                 goto read;
+ else
+ goto write;
+ }
                 if (sflag) {
                         if (r == lastrune)
                                 goto read;
_AT_@ -257,9 +260,11 @@ read:
                 else if (set1check == iswlower && set2check == iswupper)
                         r = towupper((wint_t)r);
                 else if (set2ranges > 0)
- r = set2[set2ranges - 1].end;
+ r = cflag ? r : set2[set2ranges - 1].end;
                 else
                         eprintf("Misaligned character classes.\n");
+ } else if (cflag && set2ranges > 0) {
+ r = set2[set2ranges - 1].end;
         }
         if (dflag && cflag)
                 goto read;
Received on Mon Feb 02 2015 - 20:03:33 CET

This archive was generated by hypermail 2.3.0 : Mon Feb 02 2015 - 20:12:08 CET