]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main) [!POSIXLY_CORRECT]: Allow the identity mappings:
authorJim Meyering <jim@meyering.net>
Thu, 5 Dec 1996 03:13:33 +0000 (03:13 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 5 Dec 1996 03:13:33 +0000 (03:13 +0000)
[: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

index e55df2505d16aa4169df5fb600aa7b8d3c2d5964..2fb36967576079b9f6f7b87505ce8a2981f4ca6b 100644 (file)
--- 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...  */