diff options
Diffstat (limited to 'mbbsd/stuff.c')
-rw-r--r-- | mbbsd/stuff.c | 137 |
1 files changed, 86 insertions, 51 deletions
diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 7ce5e720..10e6d69b 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -64,7 +64,6 @@ void setbdir(char *buf, char *boardname) { sprintf(buf, str_board_file, boardname[0], boardname, - currmode & MODE_ETC ? ".ETC" : (currmode & MODE_DIGEST ? fn_mandex : str_dotdir)); } @@ -401,25 +400,28 @@ capture_screen() } } -void -pressanykey() +int +vmsg_lines(const int lines, const char msg[]) { int ch; - outmsg("\033[37;45;1m " - "● 請按 \033[33m(Space/Return)\033[37m 繼續 ●" - " \033[33m(^T)\033[37m 存暫存檔 \033[m"); - do { - ch = igetkey(); + move(lines, 0); + clrtoeol(); - if (ch == Ctrl('T')) { + if (msg) + outs((char *)msg); + else + outs("\033[45;1m \033[37m" + "\033[200m\033[1431m\033[506m□ 請按 \033[33m(Space/Return)\033[37m 繼續 □\033[201m (^T) 收到暫存檔 \033[m"); + + do { + if( (ch = igetch()) == Ctrl('T') ) capture_screen(); - break; - } - } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); - move(b_lines, 0); + } while( ch == 0 ); + + move(lines, 0); clrtoeol(); - refresh(); + return ch; } #ifdef PLAY_ANGEL @@ -427,11 +429,14 @@ void pressanykey_or_callangel(){ int ch; - outmsg("\033[37;45;1m \033[33m(h)\033[37m 呼叫小天使 " + move(b_lines, 0); + clrtoeol(); + + outs("\033[37;45;1m \033[33m(h)\033[37m 呼叫小天使 " "● 請按 \033[33m(Space/Return)\033[37m 繼續 ●" " \033[33m(^T)\033[37m 存暫存檔 \033[m"); do { - ch = igetkey(); + ch = igetch(); if (ch == Ctrl('T')) { capture_screen(); @@ -443,47 +448,49 @@ pressanykey_or_callangel(){ } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); move(b_lines, 0); clrtoeol(); - refresh(); } #endif -int -vmsg(const char *fmt,...) +char getans(const char *fmt,...) { - va_list ap; - char msg[80] = {0}; - int ch; - + char msg[256]; + char ans[5]; + va_list ap; va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); + vsnprintf(msg , 128, fmt, ap); va_end(ap); - move(b_lines, 0); - clrtoeol(); - - if (*msg) - prints("\033[1;36;44m ◆ %-55.54s \033[33;46m \033[200m\033[1431m\033[506m[請按任意鍵繼續]\033[201m \033[m", msg); - else - outs("\033[46;1m \033[37m" - "\033[200m\033[1431m\033[506m□ 請按 \033[33m(Space/Return)\033[37m 繼續 □\033[201m" - " \033[m"); - - do { - ch = igetkey(); - - if (ch == Ctrl('T')) { - capture_screen(); - break; - } - } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + getdata(b_lines, 0, msg, ans, sizeof(ans), LCECHO); + return ans[0]; +} +int +getkey(const char *fmt,...) +{ + char msg[256], i; + va_list ap; + va_start(ap, fmt); + i = vsnprintf(msg , 128, fmt, ap); + va_end(ap); + return vmsg_lines(b_lines, msg); +} - move(b_lines, 0); - clrtoeol(); - refresh(); - return ch; +int +vmsg(const char *fmt,...) +{ + char msg[256] = "\033[1;36;44m ◆ ", i; + va_list ap; + va_start(ap, fmt); + i = vsnprintf(msg + 14, 128, fmt, ap); + va_end(ap); + for(i = i + 14; i < 71; i++) + msg[(int)i] = ' '; + strcat(msg + 71, + "\033[33;46m \033[200m\033[1431m\033[506m[按任意鍵繼續]\033[201m \033[m"); + return vmsg_lines(b_lines, msg); } + void bell() { @@ -573,7 +580,7 @@ cursor_key(int row, int column) int ch; cursor_show(row, column); - ch = egetch(); + ch = igetch(); move(row, column); outs(STR_UNCUR); return ch; @@ -602,13 +609,41 @@ printdash(char *mesg) outch('\n'); } -int log_file(char *fn, char *buf, int ifcreate) +int +log_user(const char *fmt, ...) +{ + char msg[256], filename[256]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(msg , 128, fmt, ap); + va_end(ap); + + sethomefile(filename, cuser.userid, "USERLOG"); + return log_file(filename, LOG_CREAT | LOG_VF, + "%s: %s %s", cuser.userid, msg, Cdate(&now)); +} + +int log_file(char *fn, int flag, const char *fmt,...) { int fd; - if( (fd = open(fn, O_APPEND | O_WRONLY | (ifcreate ? O_CREAT : 0), - (ifcreate ? 0664 : 0))) < 0 ) + char msg[256]; + const char *realmsg; + if( !(flag & LOG_VF) ){ + realmsg = fmt; + } + else{ + va_list ap; + va_start(ap, fmt); + vsnprintf(msg , 128, fmt, ap); + va_end(ap); + realmsg = msg; + } + + if( (fd = open(fn, O_APPEND | O_WRONLY | ((flag & LOG_CREAT)? O_CREAT : 0), + ((flag & LOG_CREAT) ? 0664 : 0))) < 0 ) return -1; - if( write(fd, buf, strlen(buf)) < 0 ){ + if( write(fd, realmsg, strlen(realmsg)) < 0 ){ close(fd); return -1; } |