summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pttbbs/include/proto.h9
-rw-r--r--pttbbs/mbbsd/bbslua.c24
-rw-r--r--pttbbs/mbbsd/ccw.c2
-rw-r--r--pttbbs/mbbsd/io.c65
-rw-r--r--pttbbs/mbbsd/nios.c33
-rw-r--r--pttbbs/mbbsd/pmore.c14
-rw-r--r--pttbbs/mbbsd/talk.c4
7 files changed, 68 insertions, 83 deletions
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h
index 32ac3f3c..74cda234 100644
--- a/pttbbs/include/proto.h
+++ b/pttbbs/include/proto.h
@@ -307,15 +307,6 @@ void oflush(void);
// pager hotkeys processor
int process_pager_keys(int ch);
-// input api (old flavor)
-int num_in_buf(void); // vkey_is_ready() / vkey_is_typeahead()
-int wait_input(float f, int bIgnoreBuf);// vkey_poll
-int peek_input(float f, int c); // vkey_prefetch() / vkey_is_prefeteched
-// int igetch(void); // -> vkey()
-// int input_isfull(); // -> vkey_is_full()
-// void drop_input(void); // -> vkey_purge()
-// void add_io(int fd, int timeout); // -> vkey_attach / vkey_detach
-
// new input api
/* nios.c / io.c */
///////// virtual key: convert from cin(fd) -> buffer -> virtual key //////////
diff --git a/pttbbs/mbbsd/bbslua.c b/pttbbs/mbbsd/bbslua.c
index b62cb657..4ba09eec 100644
--- a/pttbbs/mbbsd/bbslua.c
+++ b/pttbbs/mbbsd/bbslua.c
@@ -178,8 +178,9 @@ bl_peekbreak(float f)
{
if (vkey_is_full())
vkey_purge();
- if (peek_input(f, BLCONF_BREAK_KEY))
- {
+
+ if (vkey_prefetch(f * MILLISECONDS) &&
+ vkey_is_prefetched(BLCONF_BREAK_KEY)) {
vkey_purge();
blrt.abort = 1;
return 1;
@@ -461,8 +462,7 @@ bl_kbhit(lua_State *L)
if (f < BLCONF_KBHIT_TMIN) f = BLCONF_KBHIT_TMIN;
if (f > BLCONF_KBHIT_TMAX) f = BLCONF_KBHIT_TMAX;
- refresh();
- if (vkey_is_ready() || wait_input(f, 0))
+ if (vkey_is_ready() || vkey_poll(f * MILLISECONDS))
lua_pushboolean(L, 1);
else
lua_pushboolean(L, 0);
@@ -532,7 +532,7 @@ BLAPI_PROTO
bl_kball(lua_State *L)
{
// first, sleep by given seconds
- int r = 0, oldr = 0, i = 0;
+ int r = 0, i = 0;
r = bl_sleep(L);
if (blrt.abort)
@@ -543,23 +543,13 @@ bl_kball(lua_State *L)
#ifdef _WIN32
- while (peekch(0))
+ while (i < LUA_MINSTACK && peekch(0))
{
bl_k2s(L, vkey());
i++;
}
#else
- // next, collect all input and return.
- if (!vkey_is_ready())
- return 0;
-
- oldr = num_in_buf() +1;
- i = 0;
-
- while ( i < LUA_MINSTACK &&
- (r = num_in_buf()) > 0 && oldr > r)
- {
- oldr = r;
+ while (i < LUA_MINSTACK && vkey_is_ready()) {
bl_k2s(L, vkey());
i++;
}
diff --git a/pttbbs/mbbsd/ccw.c b/pttbbs/mbbsd/ccw.c
index 26e9b90d..b22fad2f 100644
--- a/pttbbs/mbbsd/ccw.c
+++ b/pttbbs/mbbsd/ccw.c
@@ -1016,7 +1016,7 @@ ccw_chat_anti_flood(CCW_CTX *ctx)
doupdate();
// flush all input!
vkey_purge();
- while (wait_input(1, 1))
+ while (vkey_poll(1 * MILLISECONDS))
vkey_purge();
vmsg(alert_msg);
diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c
index a3c2934a..dd0b3ee7 100644
--- a/pttbbs/mbbsd/io.c
+++ b/pttbbs/mbbsd/io.c
@@ -15,7 +15,8 @@
// #define DBG_OUTRPT
#endif
-static VBUF vout, *pvout = &vout, vin, *pvin = &vin;
+static VBUF vout, *pvout = &vout;
+static VBUF vin, *pvin = &vin;
// we've seen such pattern - make it accessible for movie mode.
#define CLIENT_ANTI_IDLE_STR ESC_STR "OA" ESC_STR "OB"
@@ -23,7 +24,6 @@ static VBUF vout, *pvout = &vout, vin, *pvin = &vin;
#ifdef DBG_OUTRPT
// output counter
static unsigned long szTotalOutput = 0, szLastOutput = 0;
-extern unsigned char fakeEscape;
unsigned char fakeEscape = 0;
static unsigned char fakeEscFilter(unsigned char c)
@@ -77,6 +77,7 @@ debug_print_input_buffer(char *s, size_t len)
move_ansi(y, x);
}
#endif
+
/* ----------------------------------------------------- */
/* Input Output System */
/* ----------------------------------------------------- */
@@ -154,8 +155,8 @@ process_pager_keys(int ch)
switch (ch)
{
case Ctrl('U') :
- if (!is_login_ready || !HasUserPerm(PERM_BASIC) ||
- HasUserPerm(PERM_VIOLATELAW))
+ if (!is_login_ready || !currutmp ||
+ !HasUserPerm(PERM_BASIC) || HasUserPerm(PERM_VIOLATELAW))
return ch;
if ( currutmp->mode == EDITING ||
currutmp->mode == LUSERS ||
@@ -305,7 +306,8 @@ process_pager_keys(int ch)
break;
check_water_init();
- water_which_flag = (water_which_flag + water_usies) % (water_usies + 1);
+ water_which_flag = (water_which_flag + water_usies) %
+ (water_usies + 1);
if (water_which_flag == 0)
water_which = &water[0];
else
@@ -318,6 +320,8 @@ process_pager_keys(int ch)
return ch;
}
+#ifndef EXP_NIOS
+
/* ----------------------------------------------------- */
/* input routines */
/* ----------------------------------------------------- */
@@ -327,7 +331,7 @@ process_pager_keys(int ch)
static int i_newfd = 0;
static struct timeval i_to, *i_top = NULL;
-inline void
+static inline void
add_io(int fd, int timeout)
{
i_newfd = fd;
@@ -340,7 +344,7 @@ add_io(int fd, int timeout)
i_top = NULL;
}
-inline int
+static inline int
num_in_buf(void)
{
return vbuf_size(pvin);
@@ -559,7 +563,7 @@ igetch(void)
* if f < 0, wait forever.
* Return 1 if anything available.
*/
-inline int
+static inline int
wait_input(float f, int bIgnoreBuf)
{
int sel = 0;
@@ -615,29 +619,7 @@ wait_input(float f, int bIgnoreBuf)
return 1;
}
-/*
- * wait user input for f seconds.
- * return 1 if control key c is available.
- * (if c == EOF, simply read into buffer and return 0)
- */
-inline int
-peek_input(float f, int c)
-{
- assert (c == EOF || (c > 0 && c < ' ')); // only ^x keys are safe to be detected.
- // other keys may fall into escape sequence.
-
- if (wait_input(f, 1) && vbuf_size(pvin) < IBUFSIZE)
- read_vin();
-
- if (c == EOF)
- return 0;
-
- return vbuf_strchr(pvin, c) >= 0 ? 1 : 0;
-}
-
-
-/* vkey system emulation */
-#ifndef USE_NIOS_VKEY
+/* nios vkey system emulation */
inline int
vkey_is_ready(void)
@@ -699,6 +681,27 @@ vkey_poll(int ms)
// XXX handle I_OTHERDATA?
return wait_input(ms / (double)MILLISECONDS, 0);
}
+
+int
+vkey_prefetch(int timeout) {
+ if (wait_input(timeout / (double)MILLISECONDS, 1) &&
+ vbuf_size(pvin) < IBUFSIZE)
+ read_vin();
+ return num_in_buf() > 0;
+}
+
+int
+vkey_is_prefetched(char c) {
+ // only ^x keys are safe to be detected.
+ // other keys may fall into escape sequence.
+ assert (c == EOF || (c > 0 && c < ' '));
+
+ if (c == EOF)
+ return 0;
+
+ return vbuf_strchr(pvin, c) >= 0 ? 1 : 0;
+}
+
#endif
/* vim:sw=4
diff --git a/pttbbs/mbbsd/nios.c b/pttbbs/mbbsd/nios.c
index 6b30ffb1..735194c6 100644
--- a/pttbbs/mbbsd/nios.c
+++ b/pttbbs/mbbsd/nios.c
@@ -260,7 +260,8 @@ CIN_PROTO void
cin_clear_fd(int fd)
{
CINDBGLOG("cin_clear_fd(%d)", fd);
- // method 1, use setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)(&optval), sizeof(optval));
+ // method 1, use setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)(&optval),
+ // sizeof(optval));
// method 2, fetch and discard
VBUF vgarbage, *v = &vgarbage;
char garbage[4096]; // any magic number works here
@@ -283,43 +284,47 @@ cin_clear_fd(int fd)
CIN_PROTO void
cin_fetch_fd(int fd)
{
+ CINDBGLOG("cin_fetch_fd(%d)", fd);
+
#ifdef STAT_SYSREADSOCKET
STATINC(STAT_SYSREADSOCKET);
#endif
assert(fd == cin_fd);
-#if 1
- // XXX we don't know how to deal with telnetctx/convert yet...
- // let's just keep using the old functions for now
+
+#ifdef NIOS_RAW_FETCH
+ // Try to read data from stdin (without any conversion).
+ vbuf_read(cin, fd, VBUF_RWSZ_MIN);
+#else // !NIOS_RAW_FETCH
+ // Legacy way to read data (with telnet context & converts).
char buf[sizeof(cin_buf)];
ssize_t sz = 0;
+
do {
if (vbuf_is_full(cin))
break;
if ((sz = tty_read((unsigned char*)buf, vbuf_space(cin))) < 0)
continue;
-#ifdef DBCSAWARE
+# ifdef DBCSAWARE
if (ISDBCSAWARE() && HasUserFlag(UF_DBCS_DROP_REPEAT))
- sz = vtkbd_ignore_dbcs_evil_repeats(buf, sz);
-#endif
+ sz = vtkbd_ignore_dbcs_evil_repeats((unsigned char*)buf, sz);
+# endif // DBCSAWARE
// for tty_read: sz<0 = EAGAIN
if (sz > 0)
{
-#ifdef CONVERT
+# ifdef CONVERT
sz = convert_read(cin, buf, sz);
-#else
+# else // !CONVERT
sz = vbuf_putblk(cin, buf, sz);
-#endif
// sz becomes -1/0/1 after putblk calls
+# endif // !CONVERT
if (sz < 1)
sz = -1;
}
} while (sz < 0);
-#else
- // try to read data from stdin
- vbuf_read(cin, fd, VBUF_RWSZ_MIN);
-#endif
+#endif // !NIOS_RAW_FETCH
+
#ifdef CIN_DEBUG
cin_debug_print_content();
#endif
diff --git a/pttbbs/mbbsd/pmore.c b/pttbbs/mbbsd/pmore.c
index b42eb209..e573f4c2 100644
--- a/pttbbs/mbbsd/pmore.c
+++ b/pttbbs/mbbsd/pmore.c
@@ -102,7 +102,7 @@
#define PMORE_USE_INTERNAL_HELP // display pmore internal help
#define PMORE_USE_REPLYKEY_HINTS // prompt user the keys to reply/commenting
#define PMORE_HAVE_SYNCNOW // system needs calling sync API
-#define PMORE_HAVE_NUMINBUF // input system have num_in_buf API
+#define PMORE_HAVE_VKEY // input system is vkey compatible
#define PMORE_IGNORE_UNKNOWN_NAVKEYS // does not return for all unknown keys
//#define PMORE_AUTONEXT_ON_PAGEFLIP // change file when page up/down reaches end
//#define PMORE_AUTONEXT_ON_RIGHTKEY // change file to next for right key
@@ -254,7 +254,7 @@
#undef PMORE_USE_INTERNAL_HELP
#undef PMORE_USE_REPLYKEY_HINTS
#undef PMORE_HAVE_SYNCNOW
- #undef PMORE_HAVE_NUMINBUF
+ #undef PMORE_HAVE_VKEY
#undef PMORE_IGNORE_UNKNOWN_NAVKEYS
#undef PMORE_AUTOEXIT_FIRSTPAGE
#define PMORE_AUTONEXT_ON_PAGEFLIP
@@ -3171,19 +3171,15 @@ mf_movieWaitKey(struct timeval *ptv, int dorefresh)
refresh();
do {
- // if already something in queue,
+ // Check if something already in input queue,
// detemine if ok to break.
-#ifdef PMORE_HAVE_NUMINBUF
-#ifdef EXP_NIOS
+#ifdef PMORE_HAVE_VKEY
while (vkey_is_typeahead())
-#else
- while (num_in_buf() > 0)
-#endif
{
if (!mf_movieMaskedInput((c = vkey())))
return c;
}
-#endif // PMORE_HAVE_NUMINBUF
+#endif // PMORE_HAVE_VKEY
// wait for real user interaction
FD_ZERO(&readfds);
diff --git a/pttbbs/mbbsd/talk.c b/pttbbs/mbbsd/talk.c
index 651a9480..e656f80d 100644
--- a/pttbbs/mbbsd/talk.c
+++ b/pttbbs/mbbsd/talk.c
@@ -1190,7 +1190,7 @@ int make_connection_to_somebody(userinfo_t *uin, int timeout){
return -1;
}
- vkey_attach(sock); // add_io(sock, timeout);
+ vkey_attach(sock);
while (1) {
if (vkey_poll(timeout * MILLISECONDS)) {
@@ -1215,7 +1215,7 @@ int make_connection_to_somebody(userinfo_t *uin, int timeout){
return -1;
} else {
// change to longer timeout
- timeout = 20; // add_io(sock, 20);
+ timeout = 20;
move(0, 0);
outs("¦A");
bell();