diff options
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/chat.c | 29 | ||||
-rw-r--r-- | mbbsd/visio.c | 39 |
2 files changed, 46 insertions, 22 deletions
diff --git a/mbbsd/chat.c b/mbbsd/chat.c index 4e931199..915ff749 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -312,10 +312,10 @@ t_chat(void) char chatroom[IDLEN+1] = "";/* Chat-Room Name */ char inbuf[80], chatid[20] = "", *ptr = ""; - struct sockaddr_in sin; + char hasnewmail = 0; + char fpath[PATHLEN]; int cfd; int chatting = YEA; - char fpath[PATHLEN]; struct ChatBuf chatbuf; ChatCbParam vgetparam = {0}; @@ -347,20 +347,12 @@ t_chat(void) memset(&chatbuf, 0, sizeof(chatbuf)); outs(" 驅車前往 請梢候........ "); - memset(&sin, 0, sizeof sin); -#ifdef __FreeBSD__ - sin.sin_len = sizeof(sin); -#endif - sin.sin_family = PF_INET; - sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - sin.sin_port = htons(NEW_CHATPORT); - cfd = socket(sin.sin_family, SOCK_STREAM, 0); - if (connect(cfd, (struct sockaddr *) & sin, sizeof sin) != 0) { + cfd = toconnect(XCHATD_ADDR); + if (cfd < 0) { outs("\n " "哇! 沒人在那邊耶...要有那地方的人先去開門啦!..."); system("bin/xchatd"); pressanykey(); - close(cfd); return -1; } @@ -428,7 +420,7 @@ t_chat(void) vgetparam.chatting = &chatting; while (chatting) { - print_chatid(chatid); + print_chatid(chatid); clrtobot(); move(b_lines-1, chatid_len); // chatid_len = 10, quote(:) occupies 1, so 79-11=68 @@ -481,7 +473,16 @@ t_chat(void) // print mail message if possible. if (ISNEWMAIL(currutmp)) - printchatline("◆ 噹!郵差又來了..."); + { + if (!hasnewmail) + { + printchatline("◆ 您有未讀的新信件。"); + hasnewmail = 1; + } + } else { + if (hasnewmail) + hasnewmail = 0; + } } close(cfd); diff --git a/mbbsd/visio.c b/mbbsd/visio.c index 5a72b698..35384ab8 100644 --- a/mbbsd/visio.c +++ b/mbbsd/visio.c @@ -726,7 +726,8 @@ vs_cols(const VCOL *cols, const VCOLW *ws, int n, ...) // History Helpers //////////////////////////////////////////////////////////////////////// // -#define IH_MAX_ENTRIES (12) +#define IH_MAX_ENTRIES (12) // buffer size = approx. 1k +#define IH_MIN_SIZE (2) // only keep string >= 2 bytes typedef struct { int icurr; // current retrival pointer @@ -737,21 +738,42 @@ typedef struct { static InputHistory ih; // everything intialized to zero. int -InputHistoryAdd(const char *s) +InputHistoryExists(const char *s) { int i = 0; - if (!s || !*s || !*(s+1)) - return 0; - // TODO if already in queue, change order...? for (i = 0; i < IH_MAX_ENTRIES; i++) if (strcmp(s, ih.buf[i]) == 0) - return 0; + return i+1; + + return 0; +} + +int +InputHistoryAdd(const char *s) +{ + int i = 0; + int l = strlen(s); + + if (l < IH_MIN_SIZE) + return 0; + + i = InputHistoryExists(s); + if (i > 0) // found + { + i--; // i points to valid index + assert(i < IH_MAX_ENTRIES); + // change order: just delete it. + ih.buf[i][0] = 0; + } + + // now append s. strlcpy(ih.buf[ih.iappend], s, sizeof(ih.buf[ih.iappend])); - ih.icurr = ih.iappend; ih.iappend ++; ih.iappend %= IH_MAX_ENTRIES; + ih.icurr = ih.iappend; + return 1; } @@ -901,7 +923,8 @@ vgetstring(char *_buf, int len, int flags, const char *defstr, const VGET_CALLBA } // NOECHO is already checked... - InputHistoryAdd(buf); + if (!InputHistoryExists(buf)) + InputHistoryAdd(buf); if (c == KEY_DOWN) InputHistoryNext(buf, len); |