| 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() |
| 165 |
{ |
{ |
| 166 |
continue; |
continue; |
| 167 |
} |
} |
| 168 |
else if (ch == BACKSPACE) |
else if (ch == BACKSPACE || ch == KEY_DEL) |
| 169 |
{ |
{ |
| 170 |
if (offset > 0) |
if (offset > 0) |
| 171 |
{ |
{ |
| 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", 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 |
} |
} |
| 223 |
|
|
| 224 |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 225 |
{ |
{ |
| 226 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 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 |
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 |
{ |
{ |
| 356 |
|
|
| 357 |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 358 |
{ |
{ |
| 359 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 360 |
} |
} |
| 361 |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 362 |
|
|
| 430 |
|
|
| 431 |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 432 |
{ |
{ |
| 433 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 434 |
} |
} |
| 435 |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 436 |
|
|
| 462 |
|
|
| 463 |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
if (mbstowcs(wcs, buffer + offset, 1) == (size_t)-1) |
| 464 |
{ |
{ |
| 465 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 466 |
} |
} |
| 467 |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 468 |
|
|
| 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", 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 |
} |
} |
| 545 |
|
|
| 546 |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
if (mbstowcs(wcs, input_str, 1) == (size_t)-1) |
| 547 |
{ |
{ |
| 548 |
log_error("mbstowcs() error\n"); |
log_error("mbstowcs() error"); |
| 549 |
} |
} |
| 550 |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
wc_len = (UTF8_fixed_width ? 2 : wcwidth(wcs[0])); |
| 551 |
|
|
| 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"); |
| 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"); |
| 720 |
goto cleanup; |
goto cleanup; |
| 721 |
case KEY_TIMEOUT: |
case KEY_TIMEOUT: |
| 722 |
log_error("User input timeout\n"); |
log_debug("User input timeout"); |
| 723 |
goto cleanup; |
goto cleanup; |
| 724 |
case KEY_HOME: |
case KEY_HOME: |
| 725 |
if (line_current - output_current_row < 0) // Reach begin |
if (line_current - output_current_row < 0) // Reach begin |
| 829 |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
| 830 |
if (len >= sizeof(buffer)) |
if (len >= sizeof(buffer)) |
| 831 |
{ |
{ |
| 832 |
log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld \n", |
log_error("Buffer overflow: len=%ld(%ld - %ld) line=%ld ", |
| 833 |
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); |
| 834 |
len = sizeof(buffer) - 1; |
len = sizeof(buffer) - 1; |
| 835 |
} |
} |
| 836 |
else if (len < 0) |
else if (len < 0) |
| 837 |
{ |
{ |
| 838 |
log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld \n", |
log_error("Incorrect line offsets: len=%ld(%ld - %ld) line=%ld ", |
| 839 |
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); |
| 840 |
len = 0; |
len = 0; |
| 841 |
} |
} |
| 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; |
| 880 |
|
|
| 881 |
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) |
| 882 |
{ |
{ |
| 883 |
log_error("get_file_shm(%s) error\n", filename); |
log_error("get_file_shm(%s) error", filename); |
| 884 |
return KEY_NULL; |
return KEY_NULL; |
| 885 |
} |
} |
| 886 |
|
|
| 887 |
if (user_online_update("VIEW_FILE") < 0) |
if (user_online_update("VIEW_FILE") < 0) |
| 888 |
{ |
{ |
| 889 |
log_error("user_online_update(VIEW_FILE) error\n"); |
log_error("user_online_update(VIEW_FILE) error"); |
| 890 |
} |
} |
| 891 |
|
|
| 892 |
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); |
| 893 |
|
|
| 894 |
if (detach_file_shm(p_shm) < 0) |
if (detach_file_shm(p_shm) < 0) |
| 895 |
{ |
{ |
| 896 |
log_error("detach_file_shm(%s) error\n", filename); |
log_error("detach_file_shm(%s) error", filename); |
| 897 |
} |
} |
| 898 |
|
|
| 899 |
return ret; |
return ret; |
| 1006 |
{ |
{ |
| 1007 |
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) |
| 1008 |
{ |
{ |
| 1009 |
log_error("get_file_shm(%s) error\n", DATA_ACTIVE_BOARD); |
log_error("get_file_shm(%s) error", DATA_ACTIVE_BOARD); |
| 1010 |
return KEY_NULL; |
return KEY_NULL; |
| 1011 |
} |
} |
| 1012 |
} |
} |
| 1028 |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
len = p_line_offsets[line_current + 1] - p_line_offsets[line_current]; |
| 1029 |
if (len >= LINE_BUFFER_LEN) |
if (len >= LINE_BUFFER_LEN) |
| 1030 |
{ |
{ |
| 1031 |
log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld \n", |
log_error("buffer overflow: len=%ld(%ld - %ld) line=%ld ", |
| 1032 |
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); |
| 1033 |
len = LINE_BUFFER_LEN - 1; |
len = LINE_BUFFER_LEN - 1; |
| 1034 |
} |
} |