summaryrefslogtreecommitdiffstats
path: root/mbbsd/io.c
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-24 00:26:20 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-04-24 00:26:20 +0800
commit91f6682a7690a4dd6ae160804b2009a0a98f8122 (patch)
treed82c7c3071bd444ac397ad7f14e247be031914d3 /mbbsd/io.c
parentb640fe2c00e591888ecc1ca594e5e51336c3bf44 (diff)
downloadpttbbs-91f6682a7690a4dd6ae160804b2009a0a98f8122.tar
pttbbs-91f6682a7690a4dd6ae160804b2009a0a98f8122.tar.gz
pttbbs-91f6682a7690a4dd6ae160804b2009a0a98f8122.tar.bz2
pttbbs-91f6682a7690a4dd6ae160804b2009a0a98f8122.tar.lz
pttbbs-91f6682a7690a4dd6ae160804b2009a0a98f8122.tar.xz
pttbbs-91f6682a7690a4dd6ae160804b2009a0a98f8122.tar.zst
pttbbs-91f6682a7690a4dd6ae160804b2009a0a98f8122.zip
integrate igetkey igetch egetch
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1828 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/io.c')
-rw-r--r--mbbsd/io.c95
1 files changed, 37 insertions, 58 deletions
diff --git a/mbbsd/io.c b/mbbsd/io.c
index c0f5d721..3429a3c3 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,34 @@ static int water_which_flag = 0;
int
igetch()
{
- register int ch;
- while ((ch = dogetch())) {
+ register int ch, mode =0, last;
+ 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) { /* Cursor key */
+ if (ch >= 'A' && ch <= 'D')
+ return KEY_UP + (ch - 'A');
+ else if (ch >= '1' && ch <= '6')
+ { mode = 3; last = ch; }
+ } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */
+ if (ch == '~')
+ 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 +260,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 +270,7 @@ igetch()
t_display_new();
continue;
}
- return ch;
- break;
+ return ch;
case Ctrl('R'):
if (currutmp == NULL)
@@ -304,9 +329,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 +341,7 @@ igetch()
continue;
}
}
- return (ch);
+ return ch;
case Ctrl('F'):
if (WATERMODE(WATER_NEW)) {
@@ -337,7 +360,7 @@ igetch()
continue;
}
}
- return ch;
+ return ch;
case Ctrl('G'):
if (WATERMODE(WATER_NEW)) {
@@ -352,14 +375,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 +504,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'):
@@ -604,43 +623,3 @@ getdata(int line, int col, char *prompt, char *buf, int len, int echo)
}
-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;
- }
-}