| 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> |
|
#include <sys/shm.h> |
|
| 31 |
#include <sys/types.h> |
#include <sys/types.h> |
| 32 |
|
|
| 33 |
const char CTRL_SEQ_CLR_LINE[] = "\033[K"; |
const char CTRL_SEQ_CLR_LINE[] = "\033[K"; |
| 88 |
void clearscr() |
void clearscr() |
| 89 |
{ |
{ |
| 90 |
prints("\033[2J"); |
prints("\033[2J"); |
| 91 |
moveto(0, 0); |
moveto(1, 1); |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
inline int press_any_key() |
inline int press_any_key() |
| 139 |
int offset = 0; |
int offset = 0; |
| 140 |
int eol; |
int eol; |
| 141 |
int display_len; |
int display_len; |
| 142 |
char input_str[4]; |
char input_str[5]; |
| 143 |
int str_len = 0; |
int str_len = 0; |
| 144 |
|
wchar_t wcs[2]; |
| 145 |
char c; |
char c; |
| 146 |
|
|
| 147 |
buffer[buf_size - 1] = '\0'; |
buffer[buf_size - 1] = '\0'; |
| 209 |
ch = igetch(100); // 0.1 second |
ch = igetch(100); // 0.1 second |
| 210 |
if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input |
if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input |
| 211 |
{ |
{ |
| 212 |
#ifdef _DEBUG |
log_debug("Ignore %d bytes of incomplete UTF8 character\n", str_len); |
|
log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len); |
|
|
#endif |
|
| 213 |
str_len = 0; |
str_len = 0; |
| 214 |
break; |
break; |
| 215 |
} |
} |
| 216 |
} |
} |
| 217 |
|
input_str[str_len] = '\0'; |
| 218 |
|
|
| 219 |
if (str_len == 0) // Incomplete input |
if (str_len == 0) // Incomplete input |
| 220 |
{ |
{ |
| 221 |
continue; |
continue; |
| 222 |
} |
} |
| 223 |
|
|
| 224 |
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) |
| 225 |
|
{ |
| 226 |
|
log_error("mbstowcs() error\n"); |
| 227 |
|
} |
| 228 |
|
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 |
| 229 |
{ |
{ |
| 230 |
outc('\a'); |
outc('\a'); |
| 231 |
iflush(); |
iflush(); |
| 303 |
int offset = 0; |
int offset = 0; |
| 304 |
int eol; |
int eol; |
| 305 |
int display_len; |
int display_len; |
| 306 |
char input_str[4]; |
char input_str[5]; |
| 307 |
int str_len = 0; |
int str_len = 0; |
| 308 |
|
wchar_t wcs[2]; |
| 309 |
|
int wc_len; |
| 310 |
char c; |
char c; |
| 311 |
|
|
| 312 |
buffer[buf_size - 1] = '\0'; |
buffer[buf_size - 1] = '\0'; |
| 353 |
str_len++; |
str_len++; |
| 354 |
offset--; |
offset--; |
| 355 |
} |
} |
| 356 |
display_len--; |
|
| 357 |
col_cur--; |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 358 |
|
{ |
| 359 |
|
log_error("mbstowcs() error\n"); |
| 360 |
|
} |
| 361 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 362 |
|
|
| 363 |
|
if (wc_len == 2) |
| 364 |
|
{ |
| 365 |
|
display_len--; |
| 366 |
|
col_cur--; |
| 367 |
|
} |
| 368 |
} |
} |
| 369 |
|
|
| 370 |
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)); |
| 427 |
str_len++; |
str_len++; |
| 428 |
offset--; |
offset--; |
| 429 |
} |
} |
| 430 |
col_cur--; |
|
| 431 |
|
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 432 |
|
{ |
| 433 |
|
log_error("mbstowcs() error\n"); |
| 434 |
|
} |
| 435 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 436 |
|
|
| 437 |
|
if (wc_len == 2) |
| 438 |
|
{ |
| 439 |
|
col_cur--; |
| 440 |
|
} |
| 441 |
} |
} |
| 442 |
col_cur--; |
col_cur--; |
| 443 |
|
|
| 459 |
str_len++; |
str_len++; |
| 460 |
c = (c & 0x7f) << 1; |
c = (c & 0x7f) << 1; |
| 461 |
} |
} |
| 462 |
col_cur++; |
|
| 463 |
|
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 464 |
|
{ |
| 465 |
|
log_error("mbstowcs() error\n"); |
| 466 |
|
} |
| 467 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 468 |
|
|
| 469 |
|
if (wc_len == 2) |
| 470 |
|
{ |
| 471 |
|
col_cur++; |
| 472 |
|
} |
| 473 |
} |
} |
| 474 |
else |
else |
| 475 |
{ |
{ |
| 531 |
ch = igetch(100); // 0.1 second |
ch = igetch(100); // 0.1 second |
| 532 |
if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input |
if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Ignore received bytes if no futher input |
| 533 |
{ |
{ |
| 534 |
#ifdef _DEBUG |
log_debug("Ignore %d bytes of incomplete UTF8 character\n", str_len); |
|
log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len); |
|
|
#endif |
|
| 535 |
str_len = 0; |
str_len = 0; |
| 536 |
break; |
break; |
| 537 |
} |
} |
| 538 |
} |
} |
| 539 |
|
input_str[str_len] = '\0'; |
| 540 |
|
|
| 541 |
if (str_len == 0) // Incomplete input |
if (str_len == 0) // Incomplete input |
| 542 |
{ |
{ |
| 543 |
continue; |
continue; |
| 544 |
} |
} |
| 545 |
|
|
| 546 |
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) |
| 547 |
|
{ |
| 548 |
|
log_error("mbstowcs() error\n"); |
| 549 |
|
} |
| 550 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 551 |
|
|
| 552 |
|
if (len + str_len > buf_size - 1 || |
| 553 |
|
display_len + wc_len > max_display_len) // No enough space for Chinese character |
| 554 |
{ |
{ |
| 555 |
outc('\a'); |
outc('\a'); |
| 556 |
iflush(); |
iflush(); |
| 561 |
memcpy(buffer + offset, input_str, (size_t)str_len); |
memcpy(buffer + offset, input_str, (size_t)str_len); |
| 562 |
len += str_len; |
len += str_len; |
| 563 |
buffer[len] = '\0'; |
buffer[len] = '\0'; |
| 564 |
display_len += 2; |
display_len += wc_len; |
| 565 |
|
|
| 566 |
moveto(row, col_cur); |
moveto(row, col_cur); |
| 567 |
prints("%s", buffer + offset); |
prints("%s", buffer + offset); |
| 568 |
prints("%*s", max_display_len - display_len, ""); |
prints("%*s", max_display_len - display_len, ""); |
| 569 |
|
|
| 570 |
col_cur += 2; |
col_cur += wc_len; |
| 571 |
|
|
| 572 |
moveto(row, col_cur); |
moveto(row, col_cur); |
| 573 |
iflush(); |
iflush(); |
| 638 |
loop = 1; |
loop = 1; |
| 639 |
while (!SYS_server_exit && loop) |
while (!SYS_server_exit && loop) |
| 640 |
{ |
{ |
| 641 |
if (eof_exit > 0 && line_current >= display_line_total && display_line_total <= screen_row_total) |
if (eof_exit > 0 && line_current >= display_line_total) |
| 642 |
{ |
{ |
| 643 |
if (eof_exit == 1) |
if (eof_exit == 1) |
| 644 |
{ |
{ |
| 699 |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 700 |
{ |
{ |
| 701 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 702 |
|
|
| 703 |
|
// Refresh current action |
| 704 |
|
if (user_online_update(NULL) < 0) |
| 705 |
|
{ |
| 706 |
|
log_error("user_online_update(NULL) error\n"); |
| 707 |
|
} |
| 708 |
} |
} |
| 709 |
|
|
| 710 |
// extended key handler |
// extended key handler |
| 716 |
switch (ch) |
switch (ch) |
| 717 |
{ |
{ |
| 718 |
case KEY_NULL: |
case KEY_NULL: |
| 719 |
log_error("KEY_NULL\n"); |
log_debug("KEY_NULL\n"); |
| 720 |
goto cleanup; |
goto cleanup; |
| 721 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 722 |
log_error("User input timeout\n"); |
log_error("User input timeout\n"); |
| 854 |
return ch; |
return ch; |
| 855 |
} |
} |
| 856 |
|
|
| 857 |
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) |
| 858 |
{ |
{ |
| 859 |
switch (*p_key) |
switch (*p_key) |
| 860 |
{ |
{ |
| 872 |
int display_file(const char *filename, int eof_exit) |
int display_file(const char *filename, int eof_exit) |
| 873 |
{ |
{ |
| 874 |
int ret; |
int ret; |
| 875 |
const void *p_shm; |
void *p_shm; |
| 876 |
size_t data_len; |
size_t data_len; |
| 877 |
long line_total; |
long line_total; |
| 878 |
const void *p_data; |
const void *p_data; |
| 946 |
int len; |
int len; |
| 947 |
int len_username; |
int len_username; |
| 948 |
char str_tm_online[LINE_BUFFER_LEN]; |
char str_tm_online[LINE_BUFFER_LEN]; |
| 949 |
|
int len_str_tm_online; |
| 950 |
|
|
| 951 |
len_str_time = (int)get_time_str(str_time, sizeof(str_time)); |
len_str_time = (int)get_time_str(str_time, sizeof(str_time)); |
| 952 |
|
|
| 976 |
"\033[36m%d\033[33m:\033[36m%.2d", |
"\033[36m%d\033[33m:\033[36m%.2d", |
| 977 |
tm_online->tm_hour, tm_online->tm_min); |
tm_online->tm_hour, tm_online->tm_min); |
| 978 |
} |
} |
| 979 |
|
len_str_tm_online = str_length(str_tm_online, 1); |
| 980 |
|
|
| 981 |
moveto(SCREEN_ROWS, 0); |
moveto(SCREEN_ROWS, 0); |
| 982 |
clrtoeol(); |
clrtoeol(); |
| 983 |
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", |
| 984 |
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, |
| 985 |
|
"", BBS_username, str_tm_online); |
| 986 |
|
|
| 987 |
return 0; |
return 0; |
| 988 |
} |
} |