| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
|
#ifdef HAVE_CONFIG_H |
| 10 |
|
#include "config.h" |
| 11 |
|
#endif |
| 12 |
|
|
| 13 |
#include "bbs.h" |
#include "bbs.h" |
| 14 |
#include "common.h" |
#include "common.h" |
| 15 |
#include "editor.h" |
#include "editor.h" |
| 25 |
#include <string.h> |
#include <string.h> |
| 26 |
#include <stdlib.h> |
#include <stdlib.h> |
| 27 |
#include <unistd.h> |
#include <unistd.h> |
| 28 |
|
#include <wchar.h> |
| 29 |
#include <sys/param.h> |
#include <sys/param.h> |
| 30 |
#include <sys/stat.h> |
#include <sys/stat.h> |
| 31 |
#include <sys/shm.h> |
#include <sys/shm.h> |
| 32 |
#include <sys/types.h> |
#include <sys/types.h> |
| 33 |
|
|
| 34 |
#define ACTIVE_BOARD_HEIGHT 8 |
const char CTRL_SEQ_CLR_LINE[] = "\033[K"; |
| 35 |
|
|
| 36 |
#define STR_TOP_LEFT_MAX_LEN 80 |
static const int ACTIVE_BOARD_HEIGHT = 8; |
| 37 |
#define STR_TOP_MIDDLE_MAX_LEN 40 |
|
| 38 |
#define STR_TOP_RIGHT_MAX_LEN 80 |
static const int STR_TOP_LEFT_MAX_LEN = 80; |
| 39 |
|
static const int STR_TOP_MIDDLE_MAX_LEN = 40; |
| 40 |
|
static const int STR_TOP_RIGHT_MAX_LEN = 80; |
| 41 |
|
|
| 42 |
static size_t get_time_str(char *s, size_t len) |
static size_t get_time_str(char *s, size_t len) |
| 43 |
{ |
{ |
| 134 |
iflush(); |
iflush(); |
| 135 |
} |
} |
| 136 |
|
|
| 137 |
static int _str_input(char *buffer, int buf_size, int max_display_len, int echo_mode) |
static int _str_input(char *buffer, int buf_size, int max_display_len, enum io_echo_t echo_mode) |
| 138 |
{ |
{ |
| 139 |
int ch; |
int ch; |
| 140 |
int offset = 0; |
int offset = 0; |
| 141 |
int eol; |
int eol; |
| 142 |
int display_len; |
int display_len; |
| 143 |
char input_str[4]; |
char input_str[5]; |
| 144 |
int str_len = 0; |
int str_len = 0; |
| 145 |
|
wchar_t wcs[2]; |
| 146 |
char c; |
char c; |
| 147 |
|
|
| 148 |
buffer[buf_size - 1] = '\0'; |
buffer[buf_size - 1] = '\0'; |
| 217 |
break; |
break; |
| 218 |
} |
} |
| 219 |
} |
} |
| 220 |
|
input_str[str_len] = '\0'; |
| 221 |
|
|
| 222 |
if (str_len == 0) // Incomplete input |
if (str_len == 0) // Incomplete input |
| 223 |
{ |
{ |
| 224 |
continue; |
continue; |
| 225 |
} |
} |
| 226 |
|
|
| 227 |
if (offset + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 228 |
|
{ |
| 229 |
|
log_error("mbstowcs() error\n"); |
| 230 |
|
} |
| 231 |
|
if (offset + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character |
| 232 |
{ |
{ |
| 233 |
outc('\a'); |
outc('\a'); |
| 234 |
iflush(); |
iflush(); |
| 284 |
return offset; |
return offset; |
| 285 |
} |
} |
| 286 |
|
|
| 287 |
int str_input(char *buffer, int buf_size, int echo_mode) |
int str_input(char *buffer, int buf_size, enum io_echo_t echo_mode) |
| 288 |
{ |
{ |
| 289 |
int len; |
int len; |
| 290 |
|
|
| 306 |
int offset = 0; |
int offset = 0; |
| 307 |
int eol; |
int eol; |
| 308 |
int display_len; |
int display_len; |
| 309 |
char input_str[4]; |
char input_str[5]; |
| 310 |
int str_len = 0; |
int str_len = 0; |
| 311 |
|
wchar_t wcs[2]; |
| 312 |
|
int wc_len; |
| 313 |
char c; |
char c; |
| 314 |
|
|
| 315 |
buffer[buf_size - 1] = '\0'; |
buffer[buf_size - 1] = '\0'; |
| 356 |
str_len++; |
str_len++; |
| 357 |
offset--; |
offset--; |
| 358 |
} |
} |
| 359 |
display_len--; |
|
| 360 |
col_cur--; |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 361 |
|
{ |
| 362 |
|
log_error("mbstowcs() error\n"); |
| 363 |
|
} |
| 364 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 365 |
|
|
| 366 |
|
if (wc_len == 2) |
| 367 |
|
{ |
| 368 |
|
display_len--; |
| 369 |
|
col_cur--; |
| 370 |
|
} |
| 371 |
} |
} |
| 372 |
|
|
| 373 |
memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len)); |
memmove(buffer + offset, buffer + offset + str_len, (size_t)(len - offset - str_len)); |
| 430 |
str_len++; |
str_len++; |
| 431 |
offset--; |
offset--; |
| 432 |
} |
} |
| 433 |
col_cur--; |
|
| 434 |
|
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 435 |
|
{ |
| 436 |
|
log_error("mbstowcs() error\n"); |
| 437 |
|
} |
| 438 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 439 |
|
|
| 440 |
|
if (wc_len == 2) |
| 441 |
|
{ |
| 442 |
|
col_cur--; |
| 443 |
|
} |
| 444 |
} |
} |
| 445 |
col_cur--; |
col_cur--; |
| 446 |
|
|
| 462 |
str_len++; |
str_len++; |
| 463 |
c = (c & 0x7f) << 1; |
c = (c & 0x7f) << 1; |
| 464 |
} |
} |
| 465 |
col_cur++; |
|
| 466 |
|
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 467 |
|
{ |
| 468 |
|
log_error("mbstowcs() error\n"); |
| 469 |
|
} |
| 470 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 471 |
|
|
| 472 |
|
if (wc_len == 2) |
| 473 |
|
{ |
| 474 |
|
col_cur++; |
| 475 |
|
} |
| 476 |
} |
} |
| 477 |
else |
else |
| 478 |
{ |
{ |
| 541 |
break; |
break; |
| 542 |
} |
} |
| 543 |
} |
} |
| 544 |
|
input_str[str_len] = '\0'; |
| 545 |
|
|
| 546 |
if (str_len == 0) // Incomplete input |
if (str_len == 0) // Incomplete input |
| 547 |
{ |
{ |
| 548 |
continue; |
continue; |
| 549 |
} |
} |
| 550 |
|
|
| 551 |
if (len + str_len > buf_size - 1 || display_len + 2 > max_display_len) // No enough space for Chinese character |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 552 |
|
{ |
| 553 |
|
log_error("mbstowcs() error\n"); |
| 554 |
|
} |
| 555 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 556 |
|
|
| 557 |
|
if (len + str_len > buf_size - 1 || |
| 558 |
|
display_len + wc_len > max_display_len) // No enough space for Chinese character |
| 559 |
{ |
{ |
| 560 |
outc('\a'); |
outc('\a'); |
| 561 |
iflush(); |
iflush(); |
| 566 |
memcpy(buffer + offset, input_str, (size_t)str_len); |
memcpy(buffer + offset, input_str, (size_t)str_len); |
| 567 |
len += str_len; |
len += str_len; |
| 568 |
buffer[len] = '\0'; |
buffer[len] = '\0'; |
| 569 |
display_len += 2; |
display_len += wc_len; |
| 570 |
|
|
| 571 |
moveto(row, col_cur); |
moveto(row, col_cur); |
| 572 |
prints("%s", buffer + offset); |
prints("%s", buffer + offset); |
| 573 |
prints("%*s", max_display_len - display_len, ""); |
prints("%*s", max_display_len - display_len, ""); |
| 574 |
|
|
| 575 |
col_cur += 2; |
col_cur += wc_len; |
| 576 |
|
|
| 577 |
moveto(row, col_cur); |
moveto(row, col_cur); |
| 578 |
iflush(); |
iflush(); |
| 643 |
loop = 1; |
loop = 1; |
| 644 |
while (!SYS_server_exit && loop) |
while (!SYS_server_exit && loop) |
| 645 |
{ |
{ |
| 646 |
if (eof_exit > 0 && line_current >= display_line_total && display_line_total <= screen_row_total) |
if (eof_exit > 0 && line_current >= display_line_total) |
| 647 |
{ |
{ |
| 648 |
if (eof_exit == 1) |
if (eof_exit == 1) |
| 649 |
{ |
{ |
| 853 |
return ch; |
return ch; |
| 854 |
} |
} |
| 855 |
|
|
| 856 |
static int display_file_key_handler(int *p_key, DISPLAY_CTX *p_ctx) |
int display_file_key_handler(int *p_key, DISPLAY_CTX *p_ctx) |
| 857 |
{ |
{ |
| 858 |
switch (*p_key) |
switch (*p_key) |
| 859 |
{ |
{ |
| 945 |
int len; |
int len; |
| 946 |
int len_username; |
int len_username; |
| 947 |
char str_tm_online[LINE_BUFFER_LEN]; |
char str_tm_online[LINE_BUFFER_LEN]; |
| 948 |
|
int len_str_tm_online; |
| 949 |
|
|
| 950 |
len_str_time = (int)get_time_str(str_time, sizeof(str_time)); |
len_str_time = (int)get_time_str(str_time, sizeof(str_time)); |
| 951 |
|
|
| 975 |
"\033[36m%d\033[33m:\033[36m%.2d", |
"\033[36m%d\033[33m:\033[36m%.2d", |
| 976 |
tm_online->tm_hour, tm_online->tm_min); |
tm_online->tm_hour, tm_online->tm_min); |
| 977 |
} |
} |
| 978 |
|
len_str_tm_online = str_length(str_tm_online, 1); |
| 979 |
|
|
| 980 |
moveto(SCREEN_ROWS, 0); |
moveto(SCREEN_ROWS, 0); |
| 981 |
clrtoeol(); |
clrtoeol(); |
| 982 |
prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m用户[\033[36m%s\033[33m][%s\033[33m]\033[m", |
prints("\033[1;44;33m时间[\033[36m%s\033[33m]%s%*s \033[33m用户[\033[36m%s\033[33m][%s\033[33m]\033[m", |
| 983 |
str_time, msg_f, 61 - len_str_time - len_msg - len_username, "", BBS_username, str_tm_online); |
str_time, msg_f, 65 - len_str_time - len_msg - len_username - len_str_tm_online, |
| 984 |
|
"", BBS_username, str_tm_online); |
| 985 |
|
|
| 986 |
return 0; |
return 0; |
| 987 |
} |
} |