Skip to content
Snippets Groups Projects
Commit 55ccda62 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

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.
parent f469f33a
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
/********************************************/
/********************************************/
......
......@@ -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;
......
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment