diff options
-rw-r--r-- | pttbbs/include/proto.h | 26 | ||||
-rw-r--r-- | pttbbs/mbbsd/bbslua.c | 22 | ||||
-rw-r--r-- | pttbbs/mbbsd/ccw.c | 6 | ||||
-rw-r--r-- | pttbbs/mbbsd/io.c | 57 | ||||
-rw-r--r-- | pttbbs/mbbsd/register.c | 2 | ||||
-rw-r--r-- | pttbbs/mbbsd/stuff.c | 44 | ||||
-rw-r--r-- | pttbbs/mbbsd/vtuikit.c | 2 |
7 files changed, 78 insertions, 81 deletions
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index bbdcbf44..7a25c77b 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -270,6 +270,13 @@ int guess_main(void); void set_converting_type(int which); /* io */ + +// output +int ochar(int c); +void output(const char *s, int len); +void oflush(void); + +// input api (old flavor) int igetch(void); int num_in_buf(void); int input_isfull(); @@ -277,16 +284,11 @@ int wait_input(float f, int bIgnoreBuf); int peek_input(float f, int c); void drop_input(void); void add_io(int fd, int timeout); -int getdata(int line, int col, const char *prompt, char *buf, int len, int echo); -int getdata_str(int line, int col, const char *prompt, char *buf, int len, int echo, const char *defaultstr); -int getdata_buf(int line, int col, const char *prompt, char *buf, int len, int echo); -int ochar(int c); -void output(const char *s, int len); -void oflush(void); -// maple 3 API -int vget(int line, int col, const char *prompt, char *buf, int len, int mode); -// int vkey(void); // P.S: in PTT system the vkey() is just alias to igetch(). -#define vkey() igetch() + +// new input api +int vkey(); // identical to igetch +void vkey_flush(); // identical to drop_input +int vkey_is_full(); // identical to input_isfull /* kaede */ char*Ptt_prints(char *str, size_t size, int mode); @@ -542,6 +544,10 @@ int userid_is_BM(const char *userid, const char *list); int is_uBM(const char *list, const char *id); time4_t gettime(int line, time4_t dt, const char* head); unsigned DBCS_StringHash(const char *s); +// vgets/getdata utilities +int getdata(int line, int col, const char *prompt, char *buf, int len, int echo); +int getdata_str(int line, int col, const char *prompt, char *buf, int len, int echo, const char *defaultstr); +int getdata_buf(int line, int col, const char *prompt, char *buf, int len, int echo); #ifndef CRITICAL_MEMORY #define MALLOC(p) malloc(p) diff --git a/pttbbs/mbbsd/bbslua.c b/pttbbs/mbbsd/bbslua.c index 1982e7ef..37c0832f 100644 --- a/pttbbs/mbbsd/bbslua.c +++ b/pttbbs/mbbsd/bbslua.c @@ -176,11 +176,11 @@ bl_tv2double(const struct timeval *tv) static int bl_peekbreak(float f) { - if (input_isfull()) - drop_input(); + if (vkey_is_full()) + vkey_flush(); if (peek_input(f, BLCONF_BREAK_KEY)) { - drop_input(); + vkey_flush(); blrt.abort = 1; return 1; } @@ -385,7 +385,7 @@ bl_getch(lua_State* L) int c = vkey(); if (c == BLCONF_BREAK_KEY) { - drop_input(); + vkey_flush(); blrt.abort = 1; return lua_yield(L, 0); } @@ -435,7 +435,7 @@ bl_getstr(lua_State* L) // such workaround. if (buf[1] == Ctrl('C')) { - drop_input(); + vkey_flush(); blrt.abort = 1; return lua_yield(L, 0); } @@ -476,7 +476,7 @@ bl_kbreset(lua_State *L) if (bl_peekbreak(BLCONF_PEEK_TIME)) return lua_yield(L, 0); - drop_input(); + vkey_flush(); return 0; } @@ -580,7 +580,7 @@ bl_pause(lua_State* L) n = vmsg(s); if (n == BLCONF_BREAK_KEY) { - drop_input(); + vkey_flush(); blrt.abort = 1; return lua_yield(L, 0); } @@ -1033,7 +1033,7 @@ bbsluaHook(lua_State *L, lua_Debug* ar) // vmsg("bbslua HOOK!"); if (blrt.abort) { - drop_input(); + vkey_flush(); lua_yield(L, 0); return; } @@ -1045,8 +1045,8 @@ bbsluaHook(lua_State *L, lua_Debug* ar) #endif // now, peek and check - if (input_isfull()) - drop_input(); + if (vkey_is_full()) + vkey_flush(); // refresh(); @@ -1768,7 +1768,7 @@ bbslua(const char *fpath) lua_close(L); blrt.running =0; - drop_input(); + vkey_flush(); #ifdef BBSLUA_USAGE { double cputime; diff --git a/pttbbs/mbbsd/ccw.c b/pttbbs/mbbsd/ccw.c index 89b04f67..5f7c4993 100644 --- a/pttbbs/mbbsd/ccw.c +++ b/pttbbs/mbbsd/ccw.c @@ -1002,15 +1002,15 @@ ccw_chat_anti_flood(CCW_CTX *ctx) { // flush all input! unsigned char garbage[STRLEN]; - drop_input(); + vkey_flush(); while (wait_input(1, 0)) { if (num_in_buf()) - drop_input(); + vkey_flush(); else tty_read(garbage, sizeof(garbage)); } - drop_input(); + vkey_flush(); vmsg("請勿大量剪貼或造成洗板面的效果。"); // log? diff --git a/pttbbs/mbbsd/io.c b/pttbbs/mbbsd/io.c index 8b391611..a71a381f 100644 --- a/pttbbs/mbbsd/io.c +++ b/pttbbs/mbbsd/io.c @@ -182,7 +182,7 @@ num_in_buf(void) } inline int -input_isfull(void) +vkey_is_full(void) { return ibufsize >= IBUFSIZE; } @@ -567,7 +567,7 @@ process_pager_keys(int ch) static VtkbdCtx vtkbd_ctx; inline int -igetch(void) +vkey(void) { register int ch; @@ -622,14 +622,6 @@ igetch(void) return ch; } -#ifndef vkey -inline int -vkey(void) -{ - return igetch(); -} -#endif - /* * wait user input anything for f seconds. * if f < 0, then wait forever. @@ -673,7 +665,7 @@ wait_input(float f, int bIgnoreBuf) } void -drop_input(void) +vkey_flush(void) { icurrchar = ibufsize = 0; } @@ -703,48 +695,5 @@ peek_input(float f, int c) return 0; } -static int -getdata2vgetflag(int echo) -{ - assert(echo != GCARRY); - - if (echo == LCECHO) - echo = VGET_LOWERCASE; - else if (echo == NUMECHO) - echo = VGET_DIGITS; - else if (echo == NOECHO) - echo = VGETSET_PASSWORD; - else - echo = VGET_DEFAULT; - - return echo; -} - -/* Ptt */ -int -getdata_buf(int line, int col, const char *prompt, char *buf, int len, int echo) -{ - move(line, col); - if(prompt && *prompt) outs(prompt); - return vgetstr(buf, len, getdata2vgetflag(echo), buf); -} - - -int -getdata_str(int line, int col, const char *prompt, char *buf, int len, int echo, const char *defaultstr) -{ - move(line, col); - if(prompt && *prompt) outs(prompt); - return vgetstr(buf, len, getdata2vgetflag(echo), defaultstr); -} - -int -getdata(int line, int col, const char *prompt, char *buf, int len, int echo) -{ - move(line, col); - if(prompt && *prompt) outs(prompt); - return vgets(buf, len, getdata2vgetflag(echo)); -} - /* vim:sw=4 */ diff --git a/pttbbs/mbbsd/register.c b/pttbbs/mbbsd/register.c index 4897cc63..d143bdeb 100644 --- a/pttbbs/mbbsd/register.c +++ b/pttbbs/mbbsd/register.c @@ -454,7 +454,7 @@ static int verify_captcha() // flush out current input doupdate(); peek_input(0.1f, Ctrl('C')); - drop_input(); + vkey_flush(); sleep(1); } diff --git a/pttbbs/mbbsd/stuff.c b/pttbbs/mbbsd/stuff.c index a1febfa8..7a29cf8b 100644 --- a/pttbbs/mbbsd/stuff.c +++ b/pttbbs/mbbsd/stuff.c @@ -158,7 +158,7 @@ wait_penalty(int sec) sec = 5; sleep(sec); peek_input(0.1, Ctrl('C')); - drop_input(); + vkey_flush(); } lastWait = now; } @@ -356,6 +356,48 @@ show_helpfile(const char *helpfile) PRESSANYKEY(); } +// vgets/getdata compatible helpers +static int +getdata2vgetflag(int echo) +{ + assert(echo != GCARRY); + + if (echo == LCECHO) + echo = VGET_LOWERCASE; + else if (echo == NUMECHO) + echo = VGET_DIGITS; + else if (echo == NOECHO) + echo = VGETSET_PASSWORD; + else + echo = VGET_DEFAULT; + + return echo; +} + +int +getdata_buf(int line, int col, const char *prompt, char *buf, int len, int echo) +{ + move(line, col); + if(prompt && *prompt) outs(prompt); + return vgetstr(buf, len, getdata2vgetflag(echo), buf); +} + +int +getdata_str(int line, int col, const char *prompt, char *buf, int len, int echo, const char *defaultstr) +{ + move(line, col); + if(prompt && *prompt) outs(prompt); + return vgetstr(buf, len, getdata2vgetflag(echo), defaultstr); +} + +int +getdata(int line, int col, const char *prompt, char *buf, int len, int echo) +{ + move(line, col); + if(prompt && *prompt) outs(prompt); + return vgets(buf, len, getdata2vgetflag(echo)); +} + /* ----------------------------------------------------- */ /* use mmap() to malloc large memory in CRITICAL_MEMORY */ /* ----------------------------------------------------- */ diff --git a/pttbbs/mbbsd/vtuikit.c b/pttbbs/mbbsd/vtuikit.c index 1e84502c..1011e50f 100644 --- a/pttbbs/mbbsd/vtuikit.c +++ b/pttbbs/mbbsd/vtuikit.c @@ -1313,7 +1313,7 @@ vgetstring(char *_buf, int len, int flags, const char *defstr, const VGET_CALLBA if (c > 0x80 && num_in_buf() && len - rt.iend < 3) // we need 3 for DBCS+NUL. { - drop_input(); + vkey_flush(); bell(); continue; } |