From fc02f02dde9445c8d6d1eb938bf9c63a2be698a5 Mon Sep 17 00:00:00 2001 From: piaip Date: Tue, 11 Mar 2008 17:52:35 +0000 Subject: - vt100/200 key conversion: improve error handling (may cause endless loop) for HOME/INS family. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3993 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/io.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/io.c b/mbbsd/io.c index 66418259..ae78bbcd 100644 --- a/mbbsd/io.c +++ b/mbbsd/io.c @@ -452,29 +452,41 @@ igetch(void) /* ~: Ins Del Home End PgUp PgDn */ if(ch == '~') - return KEY_HOME + (last - '1'); + { + // vt220 style + if (last >= '1' && last <= '6') + return KEY_HOME + (last - '1'); + // else, unknown. + return KEY_UNKNOWN; + } else if (last == '1') { if (ch >= '1' && ch <= '6') { - dogetch(); /* must be '~' */ - return KEY_F1 + ch - '1'; + // use num_in_buf() to prevent waiting keys + if (num_in_buf() && dogetch() == '~') /* must be '~' */ + return KEY_F1 + ch - '1'; } else if (ch >= '7' && ch <= '9') { - dogetch(); /* must be '~' */ - return KEY_F6 + ch - '7'; + // use num_in_buf() to prevent waiting keys + if (num_in_buf() && dogetch() == '~') /* must be '~' */ + return KEY_F6 + ch - '7'; } - else return KEY_UNKNOWN; - } else if (last == '2') + return KEY_UNKNOWN; + } + else if (last == '2') { if (ch >= '0' && ch <= '4') { - dogetch(); /* hope you are '~' */ - return KEY_F9 + ch - '0'; + // use inbuf() to prevent waiting keys + if (num_in_buf() && dogetch() == '~') /* hope you are '~' */ + return KEY_F9 + ch - '0'; } - else return KEY_UNKNOWN; + return KEY_UNKNOWN; } + // if fall here, then escape sequence is broken. + return KEY_UNKNOWN; } else // here is switch for default keys switch (ch) { // XXX: indent error -- cgit v1.2.3