summaryrefslogtreecommitdiff
path: root/src/tr.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-12-05 03:13:33 +0000
committerJim Meyering <jim@meyering.net>1996-12-05 03:13:33 +0000
commit4a1512e4b2c90f7bc63278036a66c1dc21d9cbd1 (patch)
treeac7e2da61239943adee61d26ffb512a580b67c89 /src/tr.c
parentad44ac84c8c08fae9990adaf2fbed23fa80317ae (diff)
downloadcoreutils-4a1512e4b2c90f7bc63278036a66c1dc21d9cbd1.tar.xz
(main) [!POSIXLY_CORRECT]: Allow the identity mappings:
[:upper:] to [:upper:] and [:lower:] to [:lower:]. (main) [POSIXLY_CORRECT]: Give a more specific diagnostic for the identity mappings [:upper:] to [:upper:] and [:lower:] to [:lower:]. (class_ok): Update table to reflect that tr now allows these identity mappings.
Diffstat (limited to 'src/tr.c')
-rw-r--r--src/tr.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/tr.c b/src/tr.c
index e55df2505..2fb369675 100644
--- a/src/tr.c
+++ b/src/tr.c
@@ -113,13 +113,14 @@ enum Upper_Lower_class
/* A shortcut to ensure that when constructing the translation array,
one of the values returned by paired calls to get_next (from s1 and s2)
is from [:upper:] and the other is from [:lower:], or neither is from
- upper or lower. In fact, no other character classes are allowed when
- translating, but that condition is tested elsewhere. This array is
- indexed by values of type enum Upper_Lower_class. */
+ upper or lower. By default, GNU tr permits the identity mappings: from
+ [:upper:] to [:upper:] and [:lower:] to [:lower:]. But when
+ POSIXLY_CORRECT is set, those evoke diagnostics. This array is indexed
+ by values of type enum Upper_Lower_class. */
static int const class_ok[3][3] =
{
- {0, 1, 0},
- {1, 0, 0},
+ {1, 1, 0},
+ {1, 1, 0},
{0, 0, 1}
};
@@ -2001,7 +2002,7 @@ without squeezing repeats"));
c2 = get_next (s2, &class_s2);
if (!class_ok[(int) class_s1][(int) class_s2])
error (EXIT_FAILURE, 0,
- _("misaligned or mismatched upper and/or lower classes"));
+ _("misaligned [:upper:] and/or [:lower:] construct"));
if (class_s1 == UL_LOWER && class_s2 == UL_UPPER)
{
@@ -2015,6 +2016,21 @@ without squeezing repeats"));
if (ISUPPER (i))
xlate[i] = tolower (i);
}
+ else if ((class_s1 == UL_LOWER && class_s2 == UL_LOWER)
+ || (class_s1 == UL_UPPER && class_s2 == UL_UPPER))
+ {
+ /* By default, GNU tr permits the identity mappings: from
+ [:upper:] to [:upper:] and [:lower:] to [:lower:]. But
+ when POSIXLY_CORRECT is set, those evoke diagnostics. */
+ if (posix_pedantic)
+ {
+ error (EXIT_FAILURE, 0,
+ _("\
+invalid identity mapping; when translating, any [:lower:] or [:upper:]\n\
+construct in string1 must be aligned with a corresponding construct\n\
+([:upper:] or [:lower:], respectively) in string2"));
+ }
+ }
else
{
/* The following should have been checked by validate... */