From 5dec1519a290b08b81255959d1f819b429e3a695 Mon Sep 17 00:00:00 2001
From: "Rob Swindell (on Debian Linux)" <rob@synchro.net>
Date: Wed, 7 Feb 2024 22:30:50 -0800
Subject: [PATCH] inkey() now returns CP437 characters by default

K_CP437 changed to K_UTF8 with the inverted logic. If you have code/script
that can handle UTF-8 input, then you need to specify K_UTF8 in calls to
inkey, getkey, getstr. Or else, you're going to get a CP437 translated
version of any non-ASCII (UNICODE) UTF-8 chars, if there's a mapping
available. This only impacts UTF-8 terminals.

There are just so many places in Synchronet where UTF-8 input could cause
problems, it makes sense to translate UTF-8 to CP437 by default and make
true UNICODE/UTF-8 handling the exception.

Sorry Nightfox, you'll need to remove the K_CP437 detection/use code you
just added to SlyEdit.
---
 exec/load/sbbsdefs.js | 2 +-
 src/sbbs3/inkey.cpp   | 6 +++---
 src/sbbs3/sbbsdefs.h  | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/exec/load/sbbsdefs.js b/exec/load/sbbsdefs.js
index b2899e52ec..98b854fa73 100644
--- a/exec/load/sbbsdefs.js
+++ b/exec/load/sbbsdefs.js
@@ -185,7 +185,7 @@ var   K_ANSI_CPR	=(1<<22);	/* ANSI Cursor Position Report expected		*/
 var   K_TRIM        =(1<<23);   /* Trim white-space from both ends of str   */
 var   K_CTRLKEYS	=(1<<24);	/* No control-key handling/eating in inkey()*/
 var   K_NUL         =(1<<25);   /* Return null instead of "" upon timeout   */
-var   K_CP437		=(1<<26);	/* Translate (UTF-8) input to CP437 chars	*/
+var   K_UTF8		=(1<<26);	/* Don't translate UTF-8 input to CP437 	*/
 					    		/********************************************/
 
 						    	/********************************************/
diff --git a/src/sbbs3/inkey.cpp b/src/sbbs3/inkey.cpp
index 2047750758..4f8b8c3e9e 100644
--- a/src/sbbs3/inkey.cpp
+++ b/src/sbbs3/inkey.cpp
@@ -123,13 +123,13 @@ int sbbs_t::inkey(int mode, unsigned int timeout)
 	}
 
 	/* Translate (not control character) input into CP437 */
-	if (mode & K_CP437) {
+	if (!(mode & K_UTF8)) {
 		if ((ch & 0x80) && term_supports(UTF8)) {
 			char utf8[UTF8_MAX_LEN] = { (char)ch };
-			int len = utf8_decode_firstbyte(ch);
+			size_t len = utf8_decode_firstbyte(ch);
 			if (len < 2 || len > sizeof(utf8))
 				return no_input;
-			for (int i = 1; i < len; ++i) {
+			for (size_t i = 1; i < len; ++i) {
 				ch = kbincom(timeout);
 				if (!(ch & 0x80) || (ch == NOINP))
 					break;
diff --git a/src/sbbs3/sbbsdefs.h b/src/sbbs3/sbbsdefs.h
index fbef61e517..0a9d03fbbb 100644
--- a/src/sbbs3/sbbsdefs.h
+++ b/src/sbbs3/sbbsdefs.h
@@ -659,7 +659,7 @@ typedef enum {						/* Values for xtrn_t.event				*/
 #define K_TRIM		(1<<23)		/* Trimmed white-space						*/
 #define K_CTRLKEYS	(1<<24)		/* No control-key handling/eating in inkey()*/
 #define K_NUL		(1<<25)		/* Return NOINP on timeout instead of '\0'	*/
-#define K_CP437		(1<<26)		/* Translate (UTF-8) input to CP437 chars	*/
+#define K_UTF8		(1<<26)		/* Don't translate UTF-8 input into CP437 	*/
 
 								/* Bits in 'mode' for putmsg and printfile  */
 #define P_NONE		0			/* No mode flags							*/
-- 
GitLab