| 3 |
* screen |
* screen |
| 4 |
* - advanced telnet-based user interactive input / output features |
* - advanced telnet-based user interactive input / output features |
| 5 |
* |
* |
| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_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() |
| 98 |
|
|
| 99 |
int press_any_key_ex(const char *msg, int sec) |
int press_any_key_ex(const char *msg, int sec) |
| 100 |
{ |
{ |
|
int ch = 0; |
|
|
int duration = 0; |
|
|
time_t t_begin = time(NULL); |
|
|
|
|
| 101 |
moveto(SCREEN_ROWS, 0); |
moveto(SCREEN_ROWS, 0); |
| 102 |
clrtoeol(); |
clrtoeol(); |
| 103 |
|
|
| 104 |
prints(msg); |
prints(msg); |
| 105 |
iflush(); |
iflush(); |
| 106 |
|
|
| 107 |
|
return press_any_key_no_prompt(sec); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
inline int press_any_key_no_prompt(int sec) |
| 111 |
|
{ |
| 112 |
|
int ch = 0; |
| 113 |
|
int duration = 0; |
| 114 |
|
time_t t_begin = time(NULL); |
| 115 |
|
|
| 116 |
igetch_reset(); |
igetch_reset(); |
| 117 |
|
|
| 118 |
do |
do |
| 170 |
{ |
{ |
| 171 |
continue; |
continue; |
| 172 |
} |
} |
| 173 |
else if (ch == BACKSPACE) |
else if (ch == KEY_ESC) |
| 174 |
|
{ |
| 175 |
|
buffer[0] = '\0'; |
| 176 |
|
offset = 0; |
| 177 |
|
break; |
| 178 |
|
} |
| 179 |
|
else if (ch == BACKSPACE || ch == KEY_DEL) |
| 180 |
{ |
{ |
| 181 |
if (offset > 0) |
if (offset > 0) |
| 182 |
{ |
{ |
| 220 |
ch = igetch(100); // 0.1 second |
ch = igetch(100); // 0.1 second |
| 221 |
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 |
| 222 |
{ |
{ |
| 223 |
#ifdef _DEBUG |
log_debug("Ignore %d bytes of incomplete UTF8 character", str_len); |
|
log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len); |
|
|
#endif |
|
| 224 |
str_len = 0; |
str_len = 0; |
| 225 |
break; |
break; |
| 226 |
} |
} |
| 234 |
|
|
| 235 |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 236 |
{ |
{ |
| 237 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 238 |
} |
} |
| 239 |
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 |
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 |
| 240 |
{ |
{ |
| 351 |
{ |
{ |
| 352 |
continue; |
continue; |
| 353 |
} |
} |
| 354 |
|
else if (ch == KEY_ESC) |
| 355 |
|
{ |
| 356 |
|
buffer[0] = '\0'; |
| 357 |
|
len = 0; |
| 358 |
|
break; |
| 359 |
|
} |
| 360 |
else if (ch == BACKSPACE) |
else if (ch == BACKSPACE) |
| 361 |
{ |
{ |
| 362 |
if (offset > 0) |
if (offset > 0) |
| 373 |
|
|
| 374 |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 375 |
{ |
{ |
| 376 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 377 |
} |
} |
| 378 |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 379 |
|
|
| 447 |
|
|
| 448 |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 449 |
{ |
{ |
| 450 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 451 |
} |
} |
| 452 |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 453 |
|
|
| 479 |
|
|
| 480 |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 481 |
{ |
{ |
| 482 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 483 |
} |
} |
| 484 |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 485 |
|
|
| 548 |
ch = igetch(100); // 0.1 second |
ch = igetch(100); // 0.1 second |
| 549 |
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 |
| 550 |
{ |
{ |
| 551 |
#ifdef _DEBUG |
log_debug("Ignore %d bytes of incomplete UTF8 character", str_len); |
|
log_error("Ignore %d bytes of incomplete UTF8 character\n", str_len); |
|
|
#endif |
|
| 552 |
str_len = 0; |
str_len = 0; |
| 553 |
break; |
break; |
| 554 |
} |
} |
| 562 |
|
|
| 563 |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 564 |
{ |
{ |
| 565 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 566 |
} |
} |
| 567 |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 568 |
|
|
| 716 |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
if (ch != KEY_NULL && ch != KEY_TIMEOUT) |
| 717 |
{ |
{ |
| 718 |
BBS_last_access_tm = time(NULL); |
BBS_last_access_tm = time(NULL); |
| 719 |
|
|
| 720 |
|
// Refresh current action |
| 721 |
|
if (user_online_update(NULL) < 0) |
| 722 |
|
{ |
| 723 |
|
log_error("user_online_update(NULL) error"); |
| 724 |
|
} |
| 725 |
} |
} |
| 726 |
|
|
| 727 |
// extended key handler |
// extended key handler |
| 733 |
switch (ch) |
switch (ch) |
| 734 |
{ |
{ |
| 735 |
case KEY_NULL: |
case KEY_NULL: |
| 736 |
log_error("KEY_NULL\n"); |
log_debug("KEY_NULL"); |
| 737 |
goto cleanup; |
goto cleanup; |
| 738 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 739 |
log_error("User input timeout\n"); |
log_debug("User input timeout"); |
| 740 |
goto cleanup; |
goto cleanup; |
| 741 |
case KEY_HOME: |
case KEY_HOME: |
| 742 |
if (line_current - output_current_row < 0) // Reach begin |
if (line_current - output_current_row < 0) // Reach begin |
| 846 |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
| 847 |
if (len >= sizeof(buffer)) |
if (len >= sizeof(buffer)) |
| 848 |
{ |
{ |
| 849 |
log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld \n", |
log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld ", |
| 850 |
len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current); |
len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current); |
| 851 |
len = sizeof(buffer) - 1; |
len = sizeof(buffer) - 1; |
| 852 |
} |
} |
| 853 |
else if (len < 0) |
else if (len < 0) |
| 854 |
{ |
{ |
| 855 |
log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld \n", |
log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld ", |
| 856 |
len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current); |
len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current); |
| 857 |
len = 0; |
len = 0; |
| 858 |
} |
} |
| 897 |
|
|
| 898 |
if ((p_shm = get_file_shm_readonly(filename, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL) |
if ((p_shm = get_file_shm_readonly(filename, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL) |
| 899 |
{ |
{ |
| 900 |
log_error("get_file_shm(%s) error\n", filename); |
log_error("get_file_shm(%s) error", filename); |
| 901 |
return KEY_NULL; |
return KEY_NULL; |
| 902 |
} |
} |
| 903 |
|
|
| 904 |
if (user_online_update("VIEW_FILE") < 0) |
if (user_online_update("VIEW_FILE") < 0) |
| 905 |
{ |
{ |
| 906 |
log_error("user_online_update(VIEW_FILE) error\n"); |
log_error("user_online_update(VIEW_FILE) error"); |
| 907 |
} |
} |
| 908 |
|
|
| 909 |
ret = display_data(p_data, line_total, p_line_offsets, eof_exit, display_file_key_handler, DATA_READ_HELP); |
ret = display_data(p_data, line_total, p_line_offsets, eof_exit, display_file_key_handler, DATA_READ_HELP); |
| 910 |
|
|
| 911 |
if (detach_file_shm(p_shm) < 0) |
if (detach_file_shm(p_shm) < 0) |
| 912 |
{ |
{ |
| 913 |
log_error("detach_file_shm(%s) error\n", filename); |
log_error("detach_file_shm(%s) error", filename); |
| 914 |
} |
} |
| 915 |
|
|
| 916 |
return ret; |
return ret; |
| 1023 |
{ |
{ |
| 1024 |
if ((p_shm = get_file_shm_readonly(DATA_ACTIVE_BOARD, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL) |
if ((p_shm = get_file_shm_readonly(DATA_ACTIVE_BOARD, &data_len, &line_total, &p_data, &p_line_offsets)) == NULL) |
| 1025 |
{ |
{ |
| 1026 |
log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD); |
log_error("get_file_shm(%s) error", DATA_ACTIVE_BOARD); |
| 1027 |
return KEY_NULL; |
return KEY_NULL; |
| 1028 |
} |
} |
| 1029 |
} |
} |
| 1045 |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
| 1046 |
if (len >= LINE_BUFFER_LEN) |
if (len >= LINE_BUFFER_LEN) |
| 1047 |
{ |
{ |
| 1048 |
log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n", |
log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld ", |
| 1049 |
len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current); |
len, p_line_offsets[line_current + 1], p_line_offsets[line_current], line_current); |
| 1050 |
len = LINE_BUFFER_LEN - 1; |
len = LINE_BUFFER_LEN - 1; |
| 1051 |
} |
} |