sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit ff0347e39163d1ffe64103f1071a159c46615676
parent f9d9672326d2b754833151c624b90fde9b06c817
Author: FRIGN <dev@frign.de>
Date:   Mon,  2 Feb 2015 19:59:41 +0100

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

Diffstat:
tr.c | 21+++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/tr.c b/tr.c @@ -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; @@ -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) @@ -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; @@ -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;