From 4a1512e4b2c90f7bc63278036a66c1dc21d9cbd1 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 5 Dec 1996 03:13:33 +0000 Subject: (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. --- src/tr.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'src/tr.c') 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... */ -- cgit v1.2.3-54-g00ecf