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

From: <git_AT_suckless.org>
Date: Tue, 24 Mar 2015 23:53:33 +0100 (CET)

commit ff0347e39163d1ffe64103f1071a159c46615676
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 Tue Mar 24 2015 - 23:53:33 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 25 2015 - 00:07:53 CET