From e443776eb7025c569df22f801965f0ec84798e35 Mon Sep 17 00:00:00 2001 From: jack Date: Sun, 2 May 2004 21:58:08 +0000 Subject: merge trunk to branches and corrected confliction git-svn-id: http://opensvn.csie.org/pttbbs/branches/Jaky.i18n@1919 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/io.c | 118 ++++++++++++++++++------------------------------------------- 1 file changed, 35 insertions(+), 83 deletions(-) (limited to 'mbbsd/io.c') diff --git a/mbbsd/io.c b/mbbsd/io.c index 829386f8..78adddda 100644 --- a/mbbsd/io.c +++ b/mbbsd/io.c @@ -174,6 +174,7 @@ dogetch() if (len == 0 || errno != EINTR) abort_bbs(0); /* raise(SIGHUP); */ + } #ifdef SKIP_TELNET_CONTROL_SIGNAL } while( inbuf[0] == -1 ); @@ -198,9 +199,32 @@ static int water_which_flag = 0; int igetch() { - register int ch; - while ((ch = dogetch())) { + register int ch, mode = 0, last = 0; + while ((ch = dogetch())) { + if (mode == 0 && ch == KEY_ESC) // here is state machine for 2 bytes key + mode = 1; + else if (mode == 1) { /* Escape sequence */ + if (ch == '[' || ch == 'O') + mode = 2; + else if (ch == '1' || ch == '4') + { mode = 3; last = ch; } + else + { + KEY_ESC_arg = ch; + return KEY_ESC; + } + } else if (mode == 2 && ch >= 'A' && ch <= 'D') /* Cursor key */ + return KEY_UP + (ch - 'A'); + else if (mode == 2 && ch >= '1' && ch <= '6') + { mode = 3; last = ch; } + else if (mode == 3 && ch == '~') { /* Ins Del Home End PgUp PgDn */ + return KEY_HOME + (last - '1'); + } + else // here is switch for default keys switch (ch) { + case IAC: + case '\n': /* filters */ + continue; #ifdef DEBUG case Ctrl('Q'):{ struct rusage ru; @@ -234,8 +258,8 @@ igetch() free(screen0); redoscr(); continue; - } else - return (ch); + } + return ch; case KEY_TAB: if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) if (currutmp != NULL && watermode > 0) { @@ -244,8 +268,7 @@ igetch() t_display_new(); continue; } - return ch; - break; + return ch; case Ctrl('R'): if (currutmp == NULL) @@ -304,9 +327,7 @@ igetch() continue; } } - return ch; - case '\n': /* Ptt§â \n®³±¼ */ - continue; + return ch; case Ctrl('T'): if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) { if (watermode > 0) { @@ -318,7 +339,7 @@ igetch() continue; } } - return (ch); + return ch; case Ctrl('F'): if (WATERMODE(WATER_NEW)) { @@ -337,7 +358,7 @@ igetch() continue; } } - return ch; + return ch; case Ctrl('G'): if (WATERMODE(WATER_NEW)) { @@ -352,14 +373,10 @@ igetch() continue; } } - return ch; - case IAC: - // disallow user input telnet protocol leading char IAC chr(255) - // TODO parse telnet protocol - continue; + return ch; default: - return ch; + return ch; } } return 0; @@ -485,7 +502,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) edit_outs(buf); clen = currchar = strlen(buf); - while (move(y, x + currchar), (ch = igetkey()) != '\r') { + while (move(y, x + currchar), (ch = igetch()) != '\r') { switch (ch) { case KEY_DOWN: case Ctrl('N'): case KEY_UP: case Ctrl('P'): @@ -587,14 +604,6 @@ getdata_buf(int line, int col, char *prompt, char *buf, int len, int echo) return oldgetdata(line, col, prompt, buf, len, echo); } -char -getans(char *prompt) -{ - char ans[5]; - - getdata(b_lines, 0, prompt, ans, sizeof(ans), LCECHO); - return ans[0]; -} int getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) @@ -611,61 +620,4 @@ getdata(int line, int col, char *prompt, char *buf, int len, int echo) return oldgetdata(line, col, prompt, buf, len, echo); } -int -rget(int x, char *prompt) -{ - register int ch; - - move(x, 0); - clrtobot(); - outs(prompt); - refresh(); - ch = igetch(); - if (ch >= 'A' && ch <= 'Z') - ch = tolower(ch); - - return ch; -} - - -int -igetkey() -{ - int mode; - int ch, last; - - mode = last = 0; - while (1) { - if( !(ch = igetch()) ) - continue; - if (mode == 0) { - if (ch == KEY_ESC) - mode = 1; - else - return ch; /* Normal Key */ - } else if (mode == 1) { /* Escape sequence */ - if (ch == '[' || ch == 'O') - mode = 2; - else if (ch == '1' || ch == '4') - mode = 3; - else { - KEY_ESC_arg = ch; - return KEY_ESC; - } - } else if (mode == 2) { /* Cursor key */ - if (ch >= 'A' && ch <= 'D') - return KEY_UP + (ch - 'A'); - else if (ch >= '1' && ch <= '6') - mode = 3; - else - return ch; - } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */ - if (ch == '~') - return KEY_HOME + (last - '1'); - else - return ch; - } - last = ch; - } -} -- cgit v1.2.3