From d7331f736f3a8a12503e835d62c0fafe0eedf06d Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 27 Oct 2026 10:41:30 +1300 Subject: [PATCH 01/23] Now that UDKs are locked by default, we're fine to have Shift+F1...Shift+F10 mapped to K_UDKF1...K_UDKF10 by default for the K95 terminal type. And for compatibility with xterm, UDKs are now initialised to what xterm sends for the K95 type. --- doc/keyb.xml | 30 ++++++++++-------------------- kermit/k95/ckoco3.c | 21 ++++++++++++++++++++- kermit/k95/ckokey.c | 5 +++++ 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/doc/keyb.xml b/doc/keyb.xml index 43a3cd0b8..df4e757fc 100644 --- a/doc/keyb.xml +++ b/doc/keyb.xml @@ -1067,8 +1067,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F1 \880 - \Kudkf1 - \{27}[1\{59}2P + \Kudkf1 \Ksni_s_f01 \Kansif13 @@ -1080,8 +1079,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F2 \881 - \Kudkf2 - \{27}[1\{59}2Q + \Kudkf2 \Ksni_s_f02 \Kansif14 @@ -1093,8 +1091,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F3 \882 - \Kudkf3 - \{27}[1\{59}2R + \Kudkf3 \Ksni_s_f03 \Kansif15 @@ -1106,8 +1103,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F4 \883 - \Kudkf4 - \{27}[1\{59}2S + \Kudkf4 \Ksni_s_f04 \Kansif16 @@ -1119,8 +1115,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F5 \884 - \Kudkf5 - \{27}[15\{59}2~ + \Kudkf5 \Ksni_s_f05 \Kansif17 @@ -1132,8 +1127,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F6 \885 - \Kudkf6 - \{27}[17\{59}2~ + \Kudkf6 \Ksni_s_f06 \Kansif18 @@ -1145,8 +1139,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F7 \886 - \Kudkf7 - \{27}[18\{59}2~ + \Kudkf7 \Ksni_s_f07 \Kansif19 @@ -1158,8 +1151,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F8 \887 - \Kudkf8 - \{27}[19\{59}2~ + \Kudkf8 \Ksni_s_f08 \Kansif20 @@ -1171,8 +1163,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F9 \888 - \Kudkf9 - \{27}[20\{59}2~ + \Kudkf9 \Ksni_s_f09 \Kansif21 @@ -1184,8 +1175,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Shift-F10 \889 - \Kudkf10 - \{27}[21\{59}2~ + \Kudkf10 \Ksni_s_f10 \Kansif22 diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 704fcbceb..7dd03716e 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -9669,7 +9669,10 @@ void udkreset( void ) { int i; - udklock = FALSE; /* Unlock User Defined Keys */ + + /*udklock = FALSE;*/ /* Unlock User Defined Keys */ + /* We no longer leave UDKs unlocked by default for better security */ + for ( i=0 ; i<200 ; i++ ) /* Reset the User Defined Keys */ { if ( udkfkeys[i] ) @@ -10422,6 +10425,22 @@ udkreset( void ) } } } + + /* xterm treats Shift+F1..F12 as function keys F13-F24. To retain + * compatibility with DECUDK, we preload the UDK slots with what xterm sends + * for Shift+F1..F12. */ + if (ISK95(tt_type)) { + udkfkeys[0] = strdup("\033[1;2P"); /* F1 */ + udkfkeys[1] = strdup("\033[1;2Q"); + udkfkeys[2] = strdup("\033[1;2R"); + udkfkeys[3] = strdup("\033[1;2S"); + udkfkeys[4] = strdup("\033[15;2~"); + udkfkeys[5] = strdup("\033[17;2~"); + udkfkeys[6] = strdup("\033[18;2~"); + udkfkeys[7] = strdup("\033[19;2~"); + udkfkeys[8] = strdup("\033[20;2~"); + udkfkeys[9] = strdup("\033[21;2~"); + } } void diff --git a/kermit/k95/ckokey.c b/kermit/k95/ckokey.c index cc2d25d90..b9a4b7f4f 100644 --- a/kermit/k95/ckokey.c +++ b/kermit/k95/ckokey.c @@ -6018,6 +6018,10 @@ defk95km( int tt) { insertkeymap( tt, 379, mkkeyevt(F_KVERB | K_DECF12 )) || /* F12 */ /* Function Keys 13-24 */ +#ifdef COMMENT + /* Shift+F1...10 are assigned to K_UDKF1...10 as in VT emulations. For + * compatibility with xterm, UDKs are initialised to what xterm sends + * for Shift+F1...10 over in function udkreset() in ckoco3.c. */ insertkeymap( tt, 880, mkliteralevt("\033[1;2P")) || /* Shift+F1 */ insertkeymap( tt, 881, mkliteralevt("\033[1;2Q")) || /* Shift+F2 */ insertkeymap( tt, 882, mkliteralevt("\033[1;2R")) || /* Shift+F3 */ @@ -6028,6 +6032,7 @@ defk95km( int tt) { insertkeymap( tt, 887, mkliteralevt("\033[19;2~")) || /* Shift+F8 */ insertkeymap( tt, 888, mkliteralevt("\033[20;2~")) || /* Shift+F9 */ insertkeymap( tt, 889, mkliteralevt("\033[21;2~")) || /* Shift+F10 */ +#endif /* COMMENT */ insertkeymap( tt, 890, mkliteralevt("\033[23;2~")) || /* Shift+F11 */ insertkeymap( tt, 891, mkliteralevt("\033[24;2~")) || /* Shift+F12 */ From fa5c10d4c7cfe06713ccd741385587a3a224b382 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 27 Oct 2026 11:06:01 +1300 Subject: [PATCH 02/23] Fix DEC UDKs being reset on soft terminal reset when it should only occur on hard reset. --- doc/changes.md | 1 + kermit/k95/ckoco3.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/changes.md b/doc/changes.md index 578adc3d9..5147f3a2f 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -564,6 +564,7 @@ as part of K95 at this time, the default terminal remains VT220 for now. discarded and the remainder written to the terminal. While this behaviour was intentional, it was incorrect and doesn't match any real terminal. - Fixed rendering on large window sizes (this time for good I hope!) + - Fixed DEC UDKs being reset on soft terminal reset ## Kermit 95 v3.0 beta 7 - 27 January 2025 diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 7dd03716e..716c3d6ec 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -11391,7 +11391,9 @@ doreset(int x) { /* x = 0 (soft), nonzero (hard) */ tt_term_scroll = 1; decspma_max_page = -1; - udkreset() ; /* Reset UDKs */ + if (x) { + udkreset() ; /* Reset UDKs */ + } deccolm = FALSE; /* default column mode */ tt_cols[VTERM] = tt_cols_usr ; #ifdef KUI From d7186157691281fe1480ad7578f5ed9a2def5ae4 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 27 Oct 2026 11:06:28 +1300 Subject: [PATCH 03/23] When UDKs are reset, reset the UDK lock to whatever the user set it to. --- kermit/k95/ckoco3.c | 5 ++--- kermit/k95/ckuus7.c | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 716c3d6ec..8d4f41e85 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -3362,7 +3362,7 @@ char * ekeys[] = { /* And close to 108 DG keys (regular and unix modes) */ /* 153 SNI 97801 keys */ char * udkfkeys[200]; /* let udkreset() initialize them */ -int udklock = 1 ; /* Are User Defined Keys locked? */ +int udklock = 1, udklock_usr = 1 ; /* Are User Defined Keys locked? */ #ifndef NOKVERBS extern struct keytab kverbs[] ; /* Kverbs table */ @@ -9670,8 +9670,7 @@ udkreset( void ) { int i; - /*udklock = FALSE;*/ /* Unlock User Defined Keys */ - /* We no longer leave UDKs unlocked by default for better security */ + udklock = udklock_usr; /* Restore user setting */ for ( i=0 ; i<200 ; i++ ) /* Reset the User Defined Keys */ { diff --git a/kermit/k95/ckuus7.c b/kermit/k95/ckuus7.c index 64d88a966..f2986fb91 100644 --- a/kermit/k95/ckuus7.c +++ b/kermit/k95/ckuus7.c @@ -5117,8 +5117,8 @@ settrm() { case XYTLOCKKEYS: { /* SET TERMINAL LOCK-KEY-DEFINITIONS */ y = seton(&x); /* Go parse ON or OFF */ if (y > 0) { /* Command succeeded? */ - extern int udklock; - udklock = x; + extern int udklock, udklock_usr; + udklock = udklock_usr = x; } return(y); } From 463e3f89c2e050e1d80d97bfbb8da1d0634430f3 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Tue, 27 Oct 2026 12:39:05 +1300 Subject: [PATCH 04/23] Map UDKF11...UDKF20 too --- doc/keyb.xml | 30 ++++++++++-------------------- kermit/k95/ckoco3.c | 10 ++++++++++ kermit/k95/ckokey.c | 5 +++++ 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/doc/keyb.xml b/doc/keyb.xml index df4e757fc..dcd66e05b 100644 --- a/doc/keyb.xml +++ b/doc/keyb.xml @@ -2475,8 +2475,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F1 \2928 - \Kudkf11 - \{27}[1\{59}4P + \Kudkf11 \Ksni_c_f01 @@ -2487,8 +2486,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F2 \2929 - \Kudkf12 - \{27}[1\{59}4Q + \Kudkf12 \Ksni_c_f02 @@ -2499,8 +2497,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F3 \2930 - \Kudkf13 - \{27}[1\{59}4R + \Kudkf13 \Ksni_c_f03 @@ -2511,8 +2508,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F4 \2931 - \Kudkf14 - \{27}[1\{59}4S + \Kudkf14 \Ksni_c_f04 @@ -2523,8 +2519,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F5 \2932 - \Kudkf15 - \{27}[15\{59}4~ + \Kudkf15 \Ksni_c_f05 @@ -2535,8 +2530,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F6 \2933 - \Kudkdo - \{27}[17\{59}4~ + \Kudkdo \Ksni_c_f06 @@ -2547,8 +2541,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F7 \2934 - \Kudkf17 - \{27}[18\{59}4~ + \Kudkf17 \Ksni_c_f07 @@ -2559,8 +2552,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F8 \2935 - \Kudkf18 - \{27}[19\{59}4~ + \Kudkf18 \Ksni_c_f08 @@ -2571,8 +2563,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F9 \2936 - \Kudkf19 - \{27}[20\{59}4~ + \Kudkf19 \Ksni_c_f09 @@ -2583,8 +2574,7 @@ this document to HTML isn't quite as strict, and the DTD is not comprehensive. Alt-Shift-F10 \2937 - \Kudkf20 - \{27}[21\{59}4~ + \Kudkf20 \Ksni_c_f10 diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 8d4f41e85..49f8cb6e2 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -10439,6 +10439,16 @@ udkreset( void ) udkfkeys[7] = strdup("\033[19;2~"); udkfkeys[8] = strdup("\033[20;2~"); udkfkeys[9] = strdup("\033[21;2~"); + udkfkeys[10] = strdup("\033[1;4P"); /* F10 */ + udkfkeys[11] = strdup("\033[1;4Q"); + udkfkeys[12] = strdup("\033[1;4R"); + udkfkeys[13] = strdup("\033[1;4S"); + udkfkeys[14] = strdup("\033[15;4~"); + udkfkeys[15] = strdup("\033[17;4~"); + udkfkeys[16] = strdup("\033[18;4~"); + udkfkeys[17] = strdup("\033[19;4~"); + udkfkeys[18] = strdup("\033[20;4~"); + udkfkeys[19] = strdup("\033[21;4~"); } } diff --git a/kermit/k95/ckokey.c b/kermit/k95/ckokey.c index b9a4b7f4f..456758bb6 100644 --- a/kermit/k95/ckokey.c +++ b/kermit/k95/ckokey.c @@ -6079,6 +6079,10 @@ defk95km( int tt) { insertkeymap( tt, 2427, mkliteralevt("\033[24;3~")) || /* Alt+F12 */ /* Function Keys 61-63, Alt+Shift+F4-12 */ +#ifdef COMMENT + /* Alt+Shift+F1...10 are assigned to K_UDKF1...10 as in VT emulations. + * For compatibility with xterm, UDKs are initialised to what xterm + * sends for Alt+Shift+F1...10 over in function udkreset() in ckoco3.c.*/ insertkeymap( tt, 2928, mkliteralevt("\033[1;4P" )) || /* Alt+Shift+F1 */ insertkeymap( tt, 2929, mkliteralevt("\033[1;4Q" )) || /* Alt+Shift+F2 */ insertkeymap( tt, 2930, mkliteralevt("\033[1;4R" )) || /* Alt+Shift+F3 */ @@ -6089,6 +6093,7 @@ defk95km( int tt) { insertkeymap( tt, 2935, mkliteralevt("\033[19;4~")) || /* Alt+Shift+F8 */ insertkeymap( tt, 2936, mkliteralevt("\033[20;4~")) || /* Alt+Shift+F9 */ insertkeymap( tt, 2937, mkliteralevt("\033[21;4~")) || /* Alt+Shift+F10 */ +#endif /* COMMENT */ insertkeymap( tt, 2938, mkliteralevt("\033[23;4~")) || /* Alt+Shift+F11 */ insertkeymap( tt, 2939, mkliteralevt("\033[24;4~")) || /* Alt+Shift+F12 */ From 9a85bccffb7dbff05db081eac708391ba1fa56e3 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 29 Oct 2026 12:33:53 +1300 Subject: [PATCH 05/23] Map PC F11...F20 to UDK11...20 --- kermit/k95/ckokey.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/kermit/k95/ckokey.c b/kermit/k95/ckokey.c index 456758bb6..b8e231500 100644 --- a/kermit/k95/ckokey.c +++ b/kermit/k95/ckokey.c @@ -6016,6 +6016,14 @@ defk95km( int tt) { insertkeymap( tt, 377, mkkeyevt(F_KVERB | K_DECF10 )) || /* F10 */ insertkeymap( tt, 378, mkkeyevt(F_KVERB | K_DECF11 )) || /* F11 */ insertkeymap( tt, 379, mkkeyevt(F_KVERB | K_DECF12 )) || /* F12 */ + insertkeymap( tt, 380, mkkeyevt(F_KVERB | K_DECF13 )) || /* F13 */ + insertkeymap( tt, 381, mkkeyevt(F_KVERB | K_DECF14 )) || /* F14 */ + insertkeymap( tt, 382, mkkeyevt(F_KVERB | K_DECF15 )) || /* F15 */ + insertkeymap( tt, 383, mkkeyevt(F_KVERB | K_DECF16 )) || /* F16 */ + insertkeymap( tt, 384, mkkeyevt(F_KVERB | K_DECF17 )) || /* F17 */ + insertkeymap( tt, 385, mkkeyevt(F_KVERB | K_DECF18 )) || /* F18 */ + insertkeymap( tt, 386, mkkeyevt(F_KVERB | K_DECF19 )) || /* F19 */ + insertkeymap( tt, 387, mkkeyevt(F_KVERB | K_DECF20 )) || /* F20 */ /* Function Keys 13-24 */ #ifdef COMMENT @@ -6032,9 +6040,21 @@ defk95km( int tt) { insertkeymap( tt, 887, mkliteralevt("\033[19;2~")) || /* Shift+F8 */ insertkeymap( tt, 888, mkliteralevt("\033[20;2~")) || /* Shift+F9 */ insertkeymap( tt, 889, mkliteralevt("\033[21;2~")) || /* Shift+F10 */ -#endif /* COMMENT */ insertkeymap( tt, 890, mkliteralevt("\033[23;2~")) || /* Shift+F11 */ - insertkeymap( tt, 891, mkliteralevt("\033[24;2~")) || /* Shift+F12 */ + insertkeymap( tt, 891, mkliteralevt("\033[24;2~")) || /* Shift+F12 */ +#endif /* COMMENT */ + insertkeymap( tt, 890 , mkkeyevt(F_KVERB | K_UDKF11 )) || /* F11 */ + insertkeymap( tt, 891 , mkkeyevt(F_KVERB | K_UDKF12 )) || /* F12 */ + insertkeymap( tt, 892 , mkkeyevt(F_KVERB | K_UDKF13 )) || /* F13 */ + insertkeymap( tt, 893 , mkkeyevt(F_KVERB | K_UDKF14 )) || /* F14 */ + insertkeymap( tt, 894 , mkkeyevt(F_KVERB | K_UDKF15 )) || /* F15 */ + insertkeymap( tt, 895 , mkkeyevt(F_KVERB | K_UDKF16 )) || /* F16 */ + insertkeymap( tt, 896 , mkkeyevt(F_KVERB | K_UDKF17 )) || /* F17 */ + insertkeymap( tt, 897 , mkkeyevt(F_KVERB | K_UDKF18 )) || /* F18 */ + insertkeymap( tt, 898 , mkkeyevt(F_KVERB | K_UDKF19 )) || /* F19 */ + insertkeymap( tt, 899 , mkkeyevt(F_KVERB | K_UDKF20 )) || /* F20 */ + + /* Function Keys 25-36 */ insertkeymap( tt, 1392, mkliteralevt("\033[1;5P" )) || /* Ctrl+F1 */ From c520e49f5dcb18034136667454217b9524738d95 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Fri, 30 Oct 2026 15:25:27 +1300 Subject: [PATCH 06/23] Fix potential buffer overflow when processing DECUDK with very long key definitions --- doc/changes.md | 1 + kermit/k95/ckoco3.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/doc/changes.md b/doc/changes.md index 5147f3a2f..e2ffe6494 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -565,6 +565,7 @@ as part of K95 at this time, the default terminal remains VT220 for now. intentional, it was incorrect and doesn't match any real terminal. - Fixed rendering on large window sizes (this time for good I hope!) - Fixed DEC UDKs being reset on soft terminal reset + - Fixed a potential buffer overflow in DECUDK processing ## Kermit 95 v3.0 beta 7 - 27 January 2025 diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 49f8cb6e2..22ab56c2b 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -17152,6 +17152,12 @@ dodcs( void ) int pn[11]; int i,k,l; int dcsnext = 0 ; + /* The VT220 only has 256 bytes of UDK memory, so thats the maximum for any + * one key definition as well as all key definitions combined. The VT420 + * bumps this up to 768 but we don't support that yet. UDK_KEYDEF_MAX is + * intentionally one less that the size of keydef to allow for null + * termination of the string. */ + const int UDK_KEYDEF_MAX = 255; char keydef[257] ; /* UDK defs can't be longer than 256 chars */ char c; @@ -17845,6 +17851,10 @@ dodcs( void ) while ( apcbuf[dcsnext] != ';' && dcsnext < apclength ) { achar = (dcsnext UDK_KEYDEF_MAX) continue; + c = 0 ; if ( isxdigit(achar) ) { From 504421da734e19a5cc7e0f8f84dbdcf2d83e1ab9 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Fri, 30 Oct 2026 15:35:32 +1300 Subject: [PATCH 07/23] Fix invalid parameters in DECUDK being ignored rather than canceling. --- kermit/k95/ckoco3.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 22ab56c2b..33e8e3618 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -17808,6 +17808,9 @@ dodcs( void ) if ( k<1 ) pn[1] = 0 ; + if (pn[2] > 1 || pn[1] > 1) + return; /* Parameter out of range */ + if ( udklock ) return; /* do nothing if the UDKs are locked */ From 1c5672acd45f13a4ea645c06a18bf95715e51d02 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Fri, 30 Oct 2026 16:28:12 +1300 Subject: [PATCH 08/23] Fix the rest of the DECUDK sequence being dumped to the terminal when a partial hex code was encountered. STD 070 says the key definition and the rest of the DECUDK sequence should be ignored in this scenario. It doesn't say the rest of the DECUDK sequence should be dumped to the terminal. And the VT220, VT420 and VT520 I have access to don't behave in this way at all - they just ignore the partial hex code and continue on. As the old behaviour was at least partially consistent with the standard I can't rule out some DEC terminal out there behaving in the same way as past K95 releases, so for now the behaviour is just commented out. --- doc/changes.md | 3 +++ kermit/k95/ckoco3.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/doc/changes.md b/doc/changes.md index e2ffe6494..4de229c6a 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -566,6 +566,9 @@ as part of K95 at this time, the default terminal remains VT220 for now. - Fixed rendering on large window sizes (this time for good I hope!) - Fixed DEC UDKs being reset on soft terminal reset - Fixed a potential buffer overflow in DECUDK processing + - Fixed DECUDK dumping the remainder of the DECUDK sequence to the terminal + when an odd number of hex digits was encountered. This behaviour was + inconsistent with the VT220, VT420 and VT520. ## Kermit 95 v3.0 beta 7 - 27 January 2025 diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 33e8e3618..dcf65009f 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -17880,6 +17880,15 @@ dodcs( void ) } } +#ifdef COMMENT + /* The VT220 (really VT22Z) v3.1, VT420 (v1.4) and + * VT520 (v2.1) don't behave like this. If they encounter + * an odd number of hex digits then the odd hex digit is + * discarded and processing continues. STD 070 says that in + * this situation the current key definition and the rest of + * DECUDK should be ignored in this situation, so I can't + * rule out some DEC terminal actually behaving in this way + * so for now its just commented out. */ if ( i == 1 || apcbuf[dcsnext] != ';' && dcsnext < apclength ){ @@ -17896,6 +17905,7 @@ dodcs( void ) cwrite('\\'); return ; } +#endif /* COMMENT */ i = -1 ; switch ( key ) { From dff31c78437435f63e2cbd149544442ec382b7a5 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Fri, 30 Oct 2026 16:43:00 +1300 Subject: [PATCH 09/23] Ignore null key definitions in DECUDK as per DEC STD 070. Previously K95 would abort the DECUDK sequence dumping the remainder of the DCS buffer to the terminal in this scenario. This behaviour is commented out for now in case one of the other terminals K95 emulates really did behave this way. --- doc/changes.md | 3 +++ kermit/k95/ckoco3.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/doc/changes.md b/doc/changes.md index 4de229c6a..ead8a004f 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -569,6 +569,9 @@ as part of K95 at this time, the default terminal remains VT220 for now. - Fixed DECUDK dumping the remainder of the DECUDK sequence to the terminal when an odd number of hex digits was encountered. This behaviour was inconsistent with the VT220, VT420 and VT520. + - Fixed null key definitions causing the remainder of a DECUDK sequence to be + dumped to the terminal. This behaviour was inconsistent with the VT220, + VT420, and VT520. Null key definitions are now ignored as per DEC STD 070. ## Kermit 95 v3.0 beta 7 - 27 January 2025 diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index dcf65009f..359fe5579 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -17834,6 +17834,22 @@ dodcs( void ) /* Check for proper separator */ if ( achar != '/') { +#ifndef COMMENT + /* Skip null key definition */ + while (achar != ';') { + achar = (dcsnext Date: Fri, 30 Oct 2026 16:45:50 +1300 Subject: [PATCH 10/23] Comment - reminder for future work when VT420 and VT52x emulations are tackled. --- kermit/k95/ckoco3.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 359fe5579..2ccf41392 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -17821,6 +17821,13 @@ dodcs( void ) while ( dcsnext < apclength ) { /* look for patterns of XX/string; */ + /* TODO - + * - VT420 and up: + * - Per key limit should be 768 bytes + * - Modifier keys: none, Shift (default), Alt, Alt+Shift + * - VT52x supports specifying Direction (Kyn/Stn/Dir) + */ + key=0; /* which key to assign to? */ achar = (dcsnext Date: Sun, 1 Nov 2026 15:00:43 +1300 Subject: [PATCH 11/23] Fix the C1 control code SCI being interpreted as DECID --- doc/changes.md | 1 + kermit/k95/ckoco3.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/doc/changes.md b/doc/changes.md index ead8a004f..fc1994f61 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -572,6 +572,7 @@ as part of K95 at this time, the default terminal remains VT220 for now. - Fixed null key definitions causing the remainder of a DECUDK sequence to be dumped to the terminal. This behaviour was inconsistent with the VT220, VT420, and VT520. Null key definitions are now ignored as per DEC STD 070. + - Fixed C1 control code SCI being interpreted as DECID ## Kermit 95 v3.0 beta 7 - 27 January 2025 diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 2ccf41392..47ec19e41 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -12342,7 +12342,27 @@ scriptwrtbuf(unsigned short word) if ((ISVT220(tt_type_mode) || ISANSI(tt_type_mode)) && !xprint ) { /* VT220 and above... */ - cx = utf8_active ? c : c & cmask & pmask; /* C1 check must be masked */ + + if (!utf8_active && ( GR->c1 )) { + if (c == 0x9a) { + /* The DEC VT220 and up don't implement SCI. If it is + * received while processing an escape sequence it acts + * similar to CAN. If we convert SCI to its two byte + * representation here, we get ESC Z which is DECID. And the + * VT220 and up *do* implement that. + * + * So instead here we'll just convert SCI to CAN. This + * should have the same overall effect while not producing + * any unexpected side-effects like responding with the DA1 + * string. + */ + /* TODO: There are probably more C1 control codes that + * should be handled in this way */ + c = CAN; + } + } + + cx = utf8_active ? c : c & cmask & pmask; /* C1 check must be masked */ if (!utf8_active && ( GR->c1 ) && (cx > 127) && (cx < 160) /* It's a C1 character */ From 21d69158157e84a1e5fc1b316c7a275a2d205358 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 1 Nov 2026 15:04:41 +1300 Subject: [PATCH 12/23] Fix APC falling through to DCS causing the next received string to be processed as DCS regardless of the set type. And also fix a larger issue: apcrecv is only reset on terminal reset. This means that once an APC has been received, *all* subsequent string-type escape sequences will be interprted as APC until terminal reset. This bug has existed since at least v1.1.11 (February 1997) and is now described as bug 845. --- doc/changes.md | 3 +++ doc/manual/k95bugs.html | 17 +++++++++++++++++ kermit/k95/ckoco3.c | 2 ++ 3 files changed, 22 insertions(+) diff --git a/doc/changes.md b/doc/changes.md index fc1994f61..be29ac74c 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -573,6 +573,9 @@ as part of K95 at this time, the default terminal remains VT220 for now. dumped to the terminal. This behaviour was inconsistent with the VT220, VT420, and VT520. Null key definitions are now ignored as per DEC STD 070. - Fixed C1 control code SCI being interpreted as DECID + - Fixed APC causing all subsequent OSC, DCS and other string-type escape + sequences to be processed as APC (and so likely producing errors on the + command screen if APC is enabled) until terminal reset (K95 bug 845). ## Kermit 95 v3.0 beta 7 - 27 January 2025 diff --git a/doc/manual/k95bugs.html b/doc/manual/k95bugs.html index cbc8a72f6..2b9c0ad97 100644 --- a/doc/manual/k95bugs.html +++ b/doc/manual/k95bugs.html @@ -1017,6 +1017,7 @@

BUG LIST

  • [+] (K) 842. Japanese-roman character set does not work
  • [+] (K) 843. SGR font attributes do not turn off if the reverse video attribute is set
  • [+] (K) 844. Cursor positioning on double-width lines in K95G +
  • [+] (K) 845. APC causes subsequent string escape sequences (DCS, OSC, etc) to be interpreted as APC @@ -8231,6 +8232,22 @@

    844. Cursor positioning on double-width lines in K95G

    This is also logged as Issue #561 on Github +

    845. APC causes subsequent string escape sequences (DCS, OSC, etc) to be interpreted as APC

    +

    + When K95 receives an APC escape sequence it fails to clear the APC flag + whether or not the APC sequence is processed. This causes subsequent OSC, + DCS and other string-type control sequences to be interprted as APC instead + of their correct type until the terminal is reset. If APC is enabled, using + an OSC (like setting the title) or DCS (like setting user-defined keys) may + cause errors to appear on the command screen. +

    +

    + This affects all releases of Kermit 95 since at least 1.1.11 (February + 1997). Older releases were not available for testing, but its possible the + bug may have been introduced as early as 1.1.7 (July 1996). It is fixed in + K95 3.0.0 beta 8. +

    + - DCS ; | ST + DCS ; | ST -

    The first parameter can be either 0 (clear all UDK definitions before - starting, default), or 1 (erase below).

    -

    The second parameter can be either 0 (lock the keys, default), or 1 (do not - lock the keys)

    - - +

    + Programs the response to pressing one or more of the user-defined + function keys (Shift+F1 through F20). If key definitions are + locked (SET TERM LOCK-KEY-DEFINITIONS ON, the default) + then DECUDK is ignored. You can view the current state of the + user-defined keys with SHOW UDK, and query for it with + DSR-25. +

    - The third parameter is a ;-seperated list of key definitions. A key - definition consists of the key code for one of the function keys, a / character - and then the string to send in response to that function key being pressed. + While DECs hardware terminals offered a fixed amount of space + available to store all key definitions (256 bytes on the VT220, + 768 bytes on the VT420 and VT520), Kermit 95 instead currently + enforces a per-key limit of 256 bytes.

    +
    +

    Specifies which existing key definitions should be erased. + Valid values are: +

    +
      +
    • 0 = erase all definitions before loading new definitions (default).
    • +
    • 1 = erase individual key definitions as new definitions are loaded
    • +
    +

    + Using Pe=1, you can modify only some key definitions without + having to reload all definitions. +

    +
    +
    +

    + Specifies if key definitions should be locked upon completion + of DECDLD to prevent subsequent modification, or if they + should be left unlocked. Valid values are: +

    +
      +
    • 0 = Lock key definitions
    • +
    • 1 = Leave key definitions unlocked
    • +
    +

    + If key definitions are locked (Pl=0), only the user can + unlock them again using the + SET TERM LOCK-KEY-DEFINITIONS OFF command. +

    +

    + In the interests of security, host applications should not + leave key definitions unlocked. +

    +
    + +
    +

    + The command string portion of the DCS sequence contains zero + or more key definition strings separated by the + semicolon character (';'). Each key definition + string is of the form Kyn/Kstn where Kyn is the key + number, and Kstn is the new definition for that key. +

    + +

    Note that key numbers 16, 22, 27 and 30 are skipped. Valid + key numbers are: +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Key number (Kyn)KeyNotes
    11F1VT420 or higher
    12F2VT420 or higher
    13F3VT420 or higher
    14F4VT420 or higher
    15F5VT420 or higher
    17F6
    18F7
    19F8
    20F9
    21F10
    23F11Shift+Alt+F1 on keyboards with 12 function keys.
    24F12Shift+Alt+F2 on keyboards with 12 function keys.
    25F13Shift+Alt+F3 on keyboards with 12 function keys.
    26F14Shift+Alt+F4 on keyboards with 12 function keys.
    28F15The HELP key on an LK450 keyboard. Shift+Alt+F5 on keyboards with 12 function keys.
    29F16The DO key on an LK450 keyboard. Shift+Alt+F6 on keyboards with 12 function keys.
    31F17Shift+Alt+F7 on keyboards with 12 function keys.
    32F18Shift+Alt+F8 on keyboards with 12 function keys.
    33F19Shift+Alt+F9 on keyboards with 12 function keys.
    34F20Shift+Alt+F10 on keyboards with 12 function keys.
    + +

    + The key definition (Kstn) is written as a sequence of hex + digit pairs, which are the charactes in the following + ranges: +

    +
      +
    • 0 through 9
    • +
    • A through F
    • +
    • a through f
    • +
    +

    + Each pair of hex digits represents a single 8-bit byte. + For example the hex digits 4B represent the letter + K. The digits 4B65726D697420393521 represent the + string Kermit 95!. This string could be bound to + Shift+F6 with the DCS sequence + DCS0;1|18/4B65726D697420393521ST + which would erase all key definitions, assign the string to + key 18 (F7), then finish leaving key definitions unlocked. +

    +

    + If a key definition contains an uneven number of hex digits + this is an error, and Kermit 95 will ignore the final hex + digit in keeping with the DEC terminals it emulates. +

    +

    + The characters HT (TAB), LF, VT, FF and CR can be included + in the key definition string for formatting purposes (they + are ignored when DECUDK is processed). +

    +

    + Kermits 95s \fhexify function may be useful for + converting strings to hex format. For example, typing + echo \fhexify(Hello!) at the K95 prompt will output + 48656C6C6F21 which you can then use with DECUDK. + The reverse of this function, \funhexify, is also + available if you wish to decode key definitions. +

    +

    + As a final example, you could bind the string "Hello, " to + Shift+F6 and "Kermit 95!" to Shift=F7 with the following + DCS sequence: + DCS0;1|17/48656C6C6F2C20;18/4B65726D697420393521ST +

    +
    +
    +

    + The DECUDK specification leaves some behaviour undefined. + Where possible, Kermit 95 attempts to match the behaviour of + the DEC products it emulates regardless, though at the time + this was feature was last updated only a VT220, VT420 and + VT520 were available for testing. Kermit 95s other terminal + emulations may not exactly match their respective terminals. +

    +

    + The following bytes have behaviours undefined by the DECUDK + specification, and so kermit 95 assigns them meaning as + described: +

    +
    +
    0x00 through 0x17, 0x19, 0x1C through 0x2E, 0x3A, + 0x3C through 0x40, 0x47 through 0x60, 0x67 through 0x7F, + 0x80 (VT220 only), 0xA0 through 0xAF, 0xBA through 0xC0, + 0xC7 through 0xE0, 0xE7 through 0xFF +
    +
    Ignored
    + +
    0xB0 through 0xB9
    +
    Treated as 0x30 through 0x39 (the digits 0...9)
    + +
    0xC1 through 0xC6
    +
    Treated as 0x41 through 0xF6 (the digits A...F)
    + +
    0xE1 through 0xE6
    +
    Treated as 0x61 through 0x66 (the digits a...f)
    + +
    0x18, 0x1A, 0x1B, 0x80 (VT320+), 0x81 through 0x9F
    +
    Aborts the DECUDK sequence; the byte and remainder of + the DECUDK sequence will be processed as normal input + potentially being dumped to the terminal. SUB (0x1A) + will print a reverse question mark, IND (0x84) and NEL + (0x85) will go down a line, etc. +
    +
    + +
    +
    -

    K95 does not currently - support specifying the shift-state of function keys, or the direction the - response to pressing the key is to be sent in.

    +

    + While Kermit 95 supports some features of DECUDK as it + exists on the VT420 and VT500 such as being able to program + F1 through F5, it does not currently support specifying + the modifier keys or direction the keys response should be + sent in. These features will arrive in some future release + that includes VT420 emulation. +

    @@ -6147,8 +6643,8 @@ VT420: indicates if the protected attribute is set
  • Sflag is a single byte in the ASCII range where bit 1 indicates DECOM is set, - bit 2 indicates SS2 is pending, - bit 3 indicates SS3 is pending, + bit 2 indicates SS2 is pending, + bit 3 indicates SS3 is pending, and bit 4 indicates the last column flag is set.
  • Spgl is a number from 0 to 3 indicating which of G0, G1, G2 or G3 is invoked into GL
  • From 0ca1cfcbb644f0e96de73ba481b40f5044d8c507 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 1 Nov 2026 20:27:55 +1300 Subject: [PATCH 19/23] Update changes --- doc/changes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/changes.md b/doc/changes.md index be29ac74c..2543867db 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -572,6 +572,7 @@ as part of K95 at this time, the default terminal remains VT220 for now. - Fixed null key definitions causing the remainder of a DECUDK sequence to be dumped to the terminal. This behaviour was inconsistent with the VT220, VT420, and VT520. Null key definitions are now ignored as per DEC STD 070. + - Fixed DECUDK not correctly ignoring certain bytes in the command string. - Fixed C1 control code SCI being interpreted as DECID - Fixed APC causing all subsequent OSC, DCS and other string-type escape sequences to be processed as APC (and so likely producing errors on the From 9f2f3ea09760be461e544a282b63705925742999 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 1 Nov 2026 20:31:51 +1300 Subject: [PATCH 20/23] Fix comment xterm behaves as the VT520 does, and Alt+Shift+F1..10 is mapped to K_UDF10...20, not 1...10. --- kermit/k95/ckokey.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kermit/k95/ckokey.c b/kermit/k95/ckokey.c index b8e231500..7cbf0d9ec 100644 --- a/kermit/k95/ckokey.c +++ b/kermit/k95/ckokey.c @@ -6028,8 +6028,8 @@ defk95km( int tt) { /* Function Keys 13-24 */ #ifdef COMMENT /* Shift+F1...10 are assigned to K_UDKF1...10 as in VT emulations. For - * compatibility with xterm, UDKs are initialised to what xterm sends - * for Shift+F1...10 over in function udkreset() in ckoco3.c. */ + * compatibility with the VT500 and xterm, UDKs are initialised to + * send DECFNK over in function udkreset() in ckoco3.c. */ insertkeymap( tt, 880, mkliteralevt("\033[1;2P")) || /* Shift+F1 */ insertkeymap( tt, 881, mkliteralevt("\033[1;2Q")) || /* Shift+F2 */ insertkeymap( tt, 882, mkliteralevt("\033[1;2R")) || /* Shift+F3 */ @@ -6100,9 +6100,9 @@ defk95km( int tt) { /* Function Keys 61-63, Alt+Shift+F4-12 */ #ifdef COMMENT - /* Alt+Shift+F1...10 are assigned to K_UDKF1...10 as in VT emulations. - * For compatibility with xterm, UDKs are initialised to what xterm - * sends for Alt+Shift+F1...10 over in function udkreset() in ckoco3.c.*/ + /* Alt+Shift+F1...10 are assigned to K_UDKF10...20 as in VT emulations. + * For compatibility with the VT500 and xterm, UDKs are initialised to + * send DECFNK over in function udkreset() in ckoco3.c. */ insertkeymap( tt, 2928, mkliteralevt("\033[1;4P" )) || /* Alt+Shift+F1 */ insertkeymap( tt, 2929, mkliteralevt("\033[1;4Q" )) || /* Alt+Shift+F2 */ insertkeymap( tt, 2930, mkliteralevt("\033[1;4R" )) || /* Alt+Shift+F3 */ From 95a1334bde2bef081ab5ebbad974f27017e20d15 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Sun, 1 Nov 2026 20:36:59 +1300 Subject: [PATCH 21/23] Fix another comment. --- kermit/k95/ckoco3.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index df4f9a8ac..9ca00c775 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -10426,10 +10426,12 @@ udkreset( void ) } } - /* xterm treats Shift+F1..F12 as function keys F13-F24. To retain - * compatibility with DECUDK, we preload the UDK slots with what xterm sends - * for Shift+F1..F12. */ - if (ISK95(tt_type)) { + /* xterm (and the VT520 with certain keyboards) treats Shift+F1..F12 as + * function keys F13-F24. And both xterm and the VT520 send DECFNK when a + * key has not had something assigned to it via DECUDK. So for now we + * pre-initialise these with DECFNK. + * */ + if (ISK95(tt_type) /* || ISVT520(tt_type) */) { udkfkeys[0] = strdup("\033[1;2P"); /* F1 */ udkfkeys[1] = strdup("\033[1;2Q"); udkfkeys[2] = strdup("\033[1;2R"); From fec4d62c536a522923d5d1a244951ad4c28c804f Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Mon, 2 Nov 2026 08:09:39 +1300 Subject: [PATCH 22/23] Fix handling of empty key definition --- doc/changes.md | 2 ++ kermit/k95/ckoco3.c | 1 + 2 files changed, 3 insertions(+) diff --git a/doc/changes.md b/doc/changes.md index 2543867db..796513da6 100644 --- a/doc/changes.md +++ b/doc/changes.md @@ -573,6 +573,8 @@ as part of K95 at this time, the default terminal remains VT220 for now. dumped to the terminal. This behaviour was inconsistent with the VT220, VT420, and VT520. Null key definitions are now ignored as per DEC STD 070. - Fixed DECUDK not correctly ignoring certain bytes in the command string. + - Fixed DECUDK not correctly handling an empty key definition resulting in the + key being defined to garbage - Fixed C1 control code SCI being interpreted as DECID - Fixed APC causing all subsequent OSC, DCS and other string-type escape sequences to be processed as APC (and so likely producing errors on the diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 9ca00c775..5ac445e86 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -17952,6 +17952,7 @@ dodcs( void ) /* Get the key definition */ l = 0 ; /* characters in definition */ i = 0 ; /* which pass? */ + keydef[l] = '\0'; /* Handle empty key definition */ while ( apcbuf[dcsnext] != ';' && dcsnext < apclength ) { achar = get_udk_dcs_byte(&dcsnext); From a339c9da9d3ec8daf0c75884c92f31a9069d70f2 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Mon, 2 Nov 2026 12:47:57 +1300 Subject: [PATCH 23/23] Fix an empty key definition not returning the UDK to sending DECFNK for the K95 terminal type --- kermit/k95/ckoco3.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kermit/k95/ckoco3.c b/kermit/k95/ckoco3.c index 5ac445e86..ea7781f13 100644 --- a/kermit/k95/ckoco3.c +++ b/kermit/k95/ckoco3.c @@ -18045,7 +18045,8 @@ dodcs( void ) } if ( i>= 0 ) { - if ( udkfkeys[i] ) { + /* TODO: For VT520, do as for K95 */ + if ( udkfkeys[i] && (!ISK95(tt_type) || strlen(keydef) ) ) { free( udkfkeys[i] ) ; udkfkeys[i]=NULL; }