This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix definition of toCTRL() for EBCDIC
authorKarl Williamson <khw@cpan.org>
Tue, 13 May 2014 00:29:41 +0000 (18:29 -0600)
committerKarl Williamson <khw@cpan.org>
Sat, 31 May 2014 17:57:00 +0000 (11:57 -0600)
The definition was incorrect.  When going from control to printable
name, we need to go from Latin1 -> Native, so that e.g., a 65 gets
turned into the native 'A'

handy.h
utf8.h
utfebcdic.h

diff --git a/handy.h b/handy.h
index 13f8d22..740ebe5 100644 (file)
--- a/handy.h
+++ b/handy.h
@@ -1653,11 +1653,13 @@ EXTCONST U32 PL_charclass[];
 #ifndef EBCDIC
 #  define toCTRL(c)    (toUPPER(c) ^ 64)
 #else
-#  define toCTRL(c)    ((c) == '?'                               \
-                        ? LATIN1_TO_NATIVE(0x9F)                 \
-                        : (c) == LATIN1_TO_NATIVE(0x9F)          \
-                          ? '?'                                  \
-                          : (NATIVE_TO_LATIN1(toUPPER(c)) ^ 64))
+#  define toCTRL(c)    ((isPRINT_A(c))                          \
+                       ? UNLIKELY((c) == '?')                   \
+                         ? QUESTION_MARK_CTRL                   \
+                         : (NATIVE_TO_LATIN1(toUPPER(c)) ^ 64)  \
+                       : UNLIKELY((c) == QUESTION_MARK_CTRL)    \
+                         ? ((c) == '?')                         \
+                         : (LATIN1_TO_NATIVE((c) ^ 64)))
 #endif
 
 /* Line numbers are unsigned, 32 bits. */
diff --git a/utf8.h b/utf8.h
index 52671eb..8945663 100644 (file)
--- a/utf8.h
+++ b/utf8.h
@@ -270,6 +270,10 @@ Perl's extended UTF-8 means we can have start bytes up to FF.
 #error UTF8_MAXBYTES must be at least 12
 #endif
 
+/* ^? is defined to be DEL on ASCII systems.  See the definition of toCTRL()
+ * for more */
+#define QUESTION_MARK_CTRL  DEL_NATIVE
+
 #define MAX_UTF8_TWO_BYTE 0x7FF
 
 #define UTF8_MAXBYTES_CASE     UTF8_MAXBYTES
index 1211c9f..7eec66f 100644 (file)
@@ -194,6 +194,10 @@ END_EXTERN_C
  * character occupies 5 bytes, therefore this number is 15 */
 #define UTF8_MAXBYTES_CASE     15
 
+/* ^? is defined to be APC on EBCDIC systems.  See the definition of toCTRL()
+ * for more */
+#define QUESTION_MARK_CTRL   LATIN1_TO_NATIVE(0x9F)
+
 #define MAX_UTF8_TWO_BYTE 0x3FF
 
 /*