| 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" |
| 28 |
#include <wchar.h> |
#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() |
| 306 |
int eol; |
int eol; |
| 307 |
int display_len; |
int display_len; |
| 308 |
char input_str[5]; |
char input_str[5]; |
|
wchar_t wcs[2]; |
|
| 309 |
int str_len = 0; |
int str_len = 0; |
| 310 |
|
wchar_t wcs[2]; |
| 311 |
|
int wc_len; |
| 312 |
char c; |
char c; |
| 313 |
|
|
| 314 |
buffer[buf_size - 1] = '\0'; |
buffer[buf_size - 1] = '\0'; |
| 355 |
str_len++; |
str_len++; |
| 356 |
offset--; |
offset--; |
| 357 |
} |
} |
| 358 |
display_len--; |
|
| 359 |
col_cur--; |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 360 |
|
{ |
| 361 |
|
log_error("mbstowcs() error\n"); |
| 362 |
|
} |
| 363 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 364 |
|
|
| 365 |
|
if (wc_len == 2) |
| 366 |
|
{ |
| 367 |
|
display_len--; |
| 368 |
|
col_cur--; |
| 369 |
|
} |
| 370 |
} |
} |
| 371 |
|
|
| 372 |
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)); |
| 429 |
str_len++; |
str_len++; |
| 430 |
offset--; |
offset--; |
| 431 |
} |
} |
| 432 |
col_cur--; |
|
| 433 |
|
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 434 |
|
{ |
| 435 |
|
log_error("mbstowcs() error\n"); |
| 436 |
|
} |
| 437 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 438 |
|
|
| 439 |
|
if (wc_len == 2) |
| 440 |
|
{ |
| 441 |
|
col_cur--; |
| 442 |
|
} |
| 443 |
} |
} |
| 444 |
col_cur--; |
col_cur--; |
| 445 |
|
|
| 461 |
str_len++; |
str_len++; |
| 462 |
c = (c & 0x7f) << 1; |
c = (c & 0x7f) << 1; |
| 463 |
} |
} |
| 464 |
col_cur++; |
|
| 465 |
|
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 466 |
|
{ |
| 467 |
|
log_error("mbstowcs() error\n"); |
| 468 |
|
} |
| 469 |
|
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 470 |
|
|
| 471 |
|
if (wc_len == 2) |
| 472 |
|
{ |
| 473 |
|
col_cur++; |
| 474 |
|
} |
| 475 |
} |
} |
| 476 |
else |
else |
| 477 |
{ |
{ |
| 551 |
{ |
{ |
| 552 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error\n"); |
| 553 |
} |
} |
| 554 |
if (len + str_len > buf_size - 1 || display_len + (UTF8_fixed_width ? 2 : wcwidth(wcs[0])) > max_display_len) // No enough space for Chinese character |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 555 |
|
|
| 556 |
|
if (len + str_len > buf_size - 1 || |
| 557 |
|
display_len + wc_len > max_display_len) // No enough space for Chinese character |
| 558 |
{ |
{ |
| 559 |
outc('\a'); |
outc('\a'); |
| 560 |
iflush(); |
iflush(); |
| 565 |
memcpy(buffer + offset, input_str, (size_t)str_len); |
memcpy(buffer + offset, input_str, (size_t)str_len); |
| 566 |
len += str_len; |
len += str_len; |
| 567 |
buffer[len] = '\0'; |
buffer[len] = '\0'; |
| 568 |
display_len += 2; |
display_len += wc_len; |
| 569 |
|
|
| 570 |
moveto(row, col_cur); |
moveto(row, col_cur); |
| 571 |
prints("%s", buffer + offset); |
prints("%s", buffer + offset); |
| 572 |
prints("%*s", max_display_len - display_len, ""); |
prints("%*s", max_display_len - display_len, ""); |
| 573 |
|
|
| 574 |
col_cur += 2; |
col_cur += wc_len; |
| 575 |
|
|
| 576 |
moveto(row, col_cur); |
moveto(row, col_cur); |
| 577 |
iflush(); |
iflush(); |
| 703 |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 704 |
{ |
{ |
| 705 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 706 |
|
|
| 707 |
|
// Refresh current action |
| 708 |
|
if (user_online_update(NULL) < 0) |
| 709 |
|
{ |
| 710 |
|
log_error("user_online_update(NULL) error\n"); |
| 711 |
|
} |
| 712 |
} |
} |
| 713 |
|
|
| 714 |
// extended key handler |
// extended key handler |
| 720 |
switch (ch) |
switch (ch) |
| 721 |
{ |
{ |
| 722 |
case KEY_NULL: |
case KEY_NULL: |
| 723 |
|
#ifdef _DEBUG |
| 724 |
log_error("KEY_NULL\n"); |
log_error("KEY_NULL\n"); |
| 725 |
|
#endif |
| 726 |
goto cleanup; |
goto cleanup; |
| 727 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 728 |
log_error("User input timeout\n"); |
log_error("User input timeout\n"); |
| 878 |
int display_file(const char *filename, int eof_exit) |
int display_file(const char *filename, int eof_exit) |
| 879 |
{ |
{ |
| 880 |
int ret; |
int ret; |
| 881 |
const void *p_shm; |
void *p_shm; |
| 882 |
size_t data_len; |
size_t data_len; |
| 883 |
long line_total; |
long line_total; |
| 884 |
const void *p_data; |
const void *p_data; |