summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-06-09 00:44:52 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-06-09 00:44:52 +0800
commit1b48c6b5e274d2744286e70300a36e758763aa7e (patch)
tree7f49901dcc5ce34c8d8a2b173adca50da6fb98e2
parent5dbeb280ea47e6cd317da0a5ec9a1d47a71d81bd (diff)
downloadpttbbs-1b48c6b5e274d2744286e70300a36e758763aa7e.tar
pttbbs-1b48c6b5e274d2744286e70300a36e758763aa7e.tar.gz
pttbbs-1b48c6b5e274d2744286e70300a36e758763aa7e.tar.bz2
pttbbs-1b48c6b5e274d2744286e70300a36e758763aa7e.tar.lz
pttbbs-1b48c6b5e274d2744286e70300a36e758763aa7e.tar.xz
pttbbs-1b48c6b5e274d2744286e70300a36e758763aa7e.tar.zst
pttbbs-1b48c6b5e274d2744286e70300a36e758763aa7e.zip
debug mode: raw key escape codes checker
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2809 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--mbbsd/io.c92
-rw-r--r--mbbsd/menu.c11
2 files changed, 98 insertions, 5 deletions
diff --git a/mbbsd/io.c b/mbbsd/io.c
index a57d005c..620bec77 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -220,6 +220,80 @@ dogetch(void)
return (unsigned char)inbuf[icurrchar++];
}
+#ifdef DEBUG
+/*
+ * These are for terminal keys debug
+ */
+void
+_debug_print_ibuffer()
+{
+ static int y = 0;
+ int i = 0;
+
+ move(y % b_lines, 0);
+ for (i = 0; i < t_columns; i++)
+ outc(' ');
+ move(y % b_lines, 0);
+ prints("%d. Current Buffer: %d/%d, ", y+1, icurrchar, ibufsize);
+ outs(ANSI_COLOR(1) "[" ANSI_RESET);
+ for (i = 0; i < ibufsize; i++)
+ {
+ int c = (unsigned char)inbuf[i];
+ if(c < ' ')
+ {
+ prints(ANSI_COLOR(1;33) "0x%02x" ANSI_RESET, c);
+ } else {
+ outc(c);
+ }
+ }
+ outs(ANSI_COLOR(1) "]" ANSI_RESET);
+ y++;
+ move(y % b_lines, 0);
+ for (i = 0; i < t_columns; i++)
+ outc(' ');
+}
+
+int
+_debug_check_keyinput()
+{
+ int dbcsaware = 0;
+ int flExit = 0;
+
+ clear();
+ while(!flExit)
+ {
+ int i = 0;
+ move(b_lines, 0);
+ for(i=0; i<t_columns; i++)
+ outc(' ');
+ move(b_lines, 0);
+ if(dbcsaware)
+ {
+ prints( ANSI_COLOR(7) "游標在此" ANSI_RESET
+ " 測試中文模式會不會亂送鍵。 'q' 離開, 'd' 回英文模式 ");
+ move(b_lines, 4);
+ } else {
+ outs("Waiting for key input. 'q' to exit, 'd' to try dbcs-aware");
+ }
+ wait_input(-1, 1);
+ switch(dogetch())
+ {
+ case 'd':
+ dbcsaware = !dbcsaware;
+ break;
+ case 'q':
+ flExit = 1;
+ break;
+ }
+ _debug_print_ibuffer();
+ while(num_in_buf() > 0)
+ dogetch();
+ }
+ return 0;
+}
+
+#endif
+
static int water_which_flag = 0;
int
@@ -516,6 +590,7 @@ igetch(void)
/*
* wait user input anything for f seconds.
+ * if f < 0, then wait forever.
* Return 1 if anything available.
*/
int
@@ -523,9 +598,9 @@ wait_input(float f, int flDoRefresh)
{
int sel = 0;
fd_set readfds;
- struct timeval tv;
+ struct timeval tv, *ptv = &tv;
- if(num_in_buf() > 0)
+ if(num_in_buf() > 0) // for EINTR
return 1;
FD_ZERO(&readfds);
@@ -533,15 +608,22 @@ wait_input(float f, int flDoRefresh)
if(flDoRefresh)
refresh();
- tv.tv_sec = (long) f;
- tv.tv_usec = (f - (long)f) * 1000000L;
+
+ if(f > 0)
+ {
+ tv.tv_sec = (long) f;
+ tv.tv_usec = (f - (long)f) * 1000000L;
+ } else
+ ptv = NULL;
#ifdef STATINC
STATINC(STAT_SYSSELECT);
#endif
do {
- sel = select(1, &readfds, NULL, NULL, &tv);
+ if(num_in_buf() > 0)
+ return 1;
+ sel = select(1, &readfds, NULL, NULL, ptv);
} while (sel < 0 && errno == EINTR);
/* EINTR, interrupted. I don't care! */
diff --git a/mbbsd/menu.c b/mbbsd/menu.c
index 2d524374..ad11a72a 100644
--- a/mbbsd/menu.c
+++ b/mbbsd/menu.c
@@ -411,8 +411,14 @@ static const commands_t userlist[] = {
{NULL, 0, NULL}
};
+#ifdef DEBUG
+int _debug_check_keyinput();
+#endif
+
/* XYZ tool menu */
static const commands_t xyzlist[] = {
+#ifndef DEBUG
+ /* All these are useless in debug mode. */
#ifdef HAVE_LICENSE
{x_gpl, 0, "LLicense GNU 使用執照"},
#endif
@@ -429,6 +435,11 @@ static const commands_t xyzlist[] = {
{x_today, 0, "TToday 《今日上線人次統計》"},
{x_yesterday, 0, "YYesterday 《昨日上線人次統計》"},
{x_user100 ,0, "UUsers 《使用者百大排行榜》"},
+#else
+ {_debug_check_keyinput, 0,
+ "MMKeycode 檢查按鍵控制碼工具"},
+#endif
+
{p_sysinfo, 0, "XXinfo 《查看系統資訊》"},
{NULL, 0, NULL}
};