From b5ebd49dd3fa06fd4a505ba9421fda8c6d65861f Mon Sep 17 00:00:00 2001 From: Laslo Hunhold Date: Thu, 6 Oct 2016 01:59:36 +0200 Subject: [PATCH] tr: Provide a fallthrough case for single-arg -s Previously, this would not work properly and not be let through the sanity check. This is a dirty hack until the next iteration where I'll clean up the data structures and make this saner. --- tr.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tr.c b/tr.c index 3aef53e..a633d74 100644 --- a/tr.c +++ b/tr.c @@ -172,7 +172,7 @@ usage(void) int main(int argc, char *argv[]) { - Rune r = 0, lastrune = 0; + Rune r, lastrune = 0; size_t off1, off2, i, m; int ret = 0; @@ -197,9 +197,9 @@ main(int argc, char *argv[]) if (argc == 2) set2ranges = makeset(argv[1], &set2, &set2check); - if (!dflag) { + if (!dflag || (argc == 2 && sflag)) { /* sanity checks as we are translating */ - if (!set2ranges && !set2check) + if (!sflag && !set2ranges && !set2check) eprintf("cannot map to an empty set.\n"); if (set2check && set2check != islowerrune && set2check != isupperrune) { @@ -211,6 +211,8 @@ read: ret |= fshut(stdin, "") | fshut(stdout, ""); return ret; } + if (argc == 1 && sflag) + goto write; for (i = 0, off1 = 0; i < set1ranges; i++, off1 += rangelen(set1[i])) { if (set1[i].start <= r && r <= set1[i].end) { if (dflag) { @@ -278,7 +280,15 @@ read: if (dflag && cflag) goto read; write: - if (sflag && r == lastrune) { + if (argc == 1 && sflag && r == lastrune) { + if (set1check && set1check(r)) + goto read; + for (i = 0; i < set1ranges; i++) { + if (set1[i].start <= r && r <= set1[i].end) + goto read; + } + } + if (argc == 2 && sflag && r == lastrune) { if (set2check && set2check(r)) goto read; for (i = 0; i < set2ranges; i++) { @@ -286,7 +296,7 @@ write: goto read; } } - lastrune = r; efputrune(&r, stdout, ""); + lastrune = r; goto read; }