[hackers] [sbase] Fix mapping a class to a simple set and improve error-reporting || FRIGN
commit 7a644aea7d3c2cd3f44b8fa15c5ccdc91f111585
Author: FRIGN <dev_AT_frign.de>
Date: Mon Jan 12 00:03:48 2015 +0100
Fix mapping a class to a simple set and improve error-reporting
It's standard behaviour to map a whole class of matched objects
to the last element of a given simple set2 instead of just passing
it through.
Also, error out more strictly when the user gives us bogus sets.
diff --git a/tr.c b/tr.c
index 828adba..d2bf7e0 100644
--- a/tr.c
+++ b/tr.c
_AT_@ -110,7 +110,7 @@ nextbrack:
return 0;
}
}
- eprintf("Invalid character class\n");
+ eprintf("Invalid character class.\n");
}
/* REPEAT [_*n] (only allowed in set2) */
_AT_@ -192,7 +192,9 @@ main(int argc, char *argv[])
if (argc == 2)
set2ranges = makeset(argv[1], &set2, &set2check);
if (dflag == sflag && !set2ranges && !set2check)
- eprintf("set2 must be non-empty\n");
+ eprintf("set2 must be non-empty.\n");
+ if (set2check && set2check != iswlower && set2check != iswupper)
+ eprintf("set2 can only be the 'lower' or 'upper' class.\n");
read:
if (!readrune("<stdin>", stdin, &r))
return 0;
_AT_@ -238,8 +240,12 @@ read:
}
if (set1check == iswupper && set2check == iswlower)
r = towlower((wint_t)r);
- if (set1check == iswlower && set2check == iswupper)
+ else if (set1check == iswlower && set2check == iswupper)
r = towupper((wint_t)r);
+ else if (set2ranges > 0)
+ r = set2[set2ranges - 1].end;
+ else
+ eprintf("Misaligned character classes.\n");
}
if (dflag && cflag)
goto read;
Received on Mon Jan 12 2015 - 12:19:51 CET
This archive was generated by hypermail 2.3.0
: Mon Jan 12 2015 - 12:24:04 CET