[hackers] [sbase] tr: Provide a fallthrough case for single-arg -s || Laslo Hunhold
 
commit b5ebd49dd3fa06fd4a505ba9421fda8c6d65861f
Author:     Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Thu Oct 6 01:59:36 2016 +0200
Commit:     Laslo Hunhold <dev_AT_frign.de>
CommitDate: Thu Oct 6 02:00:25 2016 +0200
    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.
diff --git a/tr.c b/tr.c
index 3aef53e..a633d74 100644
--- a/tr.c
+++ b/tr.c
_AT_@ -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;
 
_AT_@ -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) {
_AT_@ -211,6 +211,8 @@ read:
                 ret |= fshut(stdin, "<stdin>") | fshut(stdout, "<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) {
_AT_@ -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++) {
_AT_@ -286,7 +296,7 @@ write:
                                 goto read;
                 }
         }
-	lastrune = r;
         efputrune(&r, stdout, "<stdout>");
+	lastrune = r;
         goto read;
 }
Received on Thu Oct 06 2016 - 02:00:57 CEST
This archive was generated by hypermail 2.3.0
: Thu Oct 06 2016 - 02:12:15 CEST