| 24 |
#include <stdlib.h> |
#include <stdlib.h> |
| 25 |
#include <sys/param.h> |
#include <sys/param.h> |
| 26 |
#include <strings.h> |
#include <strings.h> |
|
|
|
|
#define _POSIX_C_SOURCE 200809L |
|
| 27 |
#include <string.h> |
#include <string.h> |
| 28 |
|
|
| 29 |
#define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m" |
#define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m" |
| 94 |
return NULL; |
return NULL; |
| 95 |
} |
} |
| 96 |
|
|
| 97 |
p_editor_data->display_line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_EDITOR_DATA_LINES + 1); |
p_editor_data->display_line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_EDITOR_DATA_LINES + 1, 0); |
| 98 |
|
|
| 99 |
for (i = 0; i < p_editor_data->display_line_total; i++) |
for (i = 0; i < p_editor_data->display_line_total; i++) |
| 100 |
{ |
{ |
| 136 |
p_data_line[current_data_line_length] = '\0'; |
p_data_line[current_data_line_length] = '\0'; |
| 137 |
} |
} |
| 138 |
|
|
| 139 |
bzero(p_editor_data->p_display_lines + p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES - (size_t)p_editor_data->display_line_total); |
memset(p_editor_data->p_display_lines + p_editor_data->display_line_total, 0, MAX_EDITOR_DATA_LINES - (size_t)p_editor_data->display_line_total); |
| 140 |
|
|
| 141 |
return p_editor_data; |
return p_editor_data; |
| 142 |
} |
} |
| 360 |
} |
} |
| 361 |
|
|
| 362 |
// Split current data line since beginning of current display line |
// Split current data line since beginning of current display line |
| 363 |
split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total); |
split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total, 0); |
| 364 |
|
|
| 365 |
for (i = 0; i < split_line_total; i++) |
for (i = 0; i < split_line_total; i++) |
| 366 |
{ |
{ |
| 373 |
// Terminate prior display line with \n, to avoid error on cleanup |
// Terminate prior display line with \n, to avoid error on cleanup |
| 374 |
if (display_line + i - 1 >= 0 && p_editor_data->display_line_lengths[display_line + i - 1] > 0) |
if (display_line + i - 1 >= 0 && p_editor_data->display_line_lengths[display_line + i - 1] > 0) |
| 375 |
{ |
{ |
| 376 |
len = split_line(p_editor_data->p_display_lines[display_line + i - 1], SCREEN_COLS - 1, &eol, &display_len); |
len = split_line(p_editor_data->p_display_lines[display_line + i - 1], SCREEN_COLS - 1, &eol, &display_len, 0); |
| 377 |
p_editor_data->p_display_lines[display_line + i - 1][len] = '\n'; |
p_editor_data->p_display_lines[display_line + i - 1][len] = '\n'; |
| 378 |
p_editor_data->p_display_lines[display_line + i - 1][len + 1] = '\0'; |
p_editor_data->p_display_lines[display_line + i - 1][len + 1] = '\0'; |
| 379 |
p_editor_data->display_line_lengths[display_line + i - 1] = len + 1; |
p_editor_data->display_line_lengths[display_line + i - 1] = len + 1; |
| 420 |
// Prevent the last display line from being over-length |
// Prevent the last display line from being over-length |
| 421 |
if (p_editor_data->display_line_total == MAX_EDITOR_DATA_LINES) |
if (p_editor_data->display_line_total == MAX_EDITOR_DATA_LINES) |
| 422 |
{ |
{ |
| 423 |
len = split_line(p_editor_data->p_display_lines[p_editor_data->display_line_total - 1], SCREEN_COLS - 1, &eol, &display_len); |
len = split_line(p_editor_data->p_display_lines[p_editor_data->display_line_total - 1], SCREEN_COLS - 1, &eol, &display_len, 0); |
| 424 |
p_editor_data->p_display_lines[p_editor_data->display_line_total - 1][len] = '\0'; |
p_editor_data->p_display_lines[p_editor_data->display_line_total - 1][len] = '\0'; |
| 425 |
p_editor_data->display_line_lengths[p_editor_data->display_line_total - 1] = len; |
p_editor_data->display_line_lengths[p_editor_data->display_line_total - 1] = len; |
| 426 |
if (*p_display_line + 1 >= p_editor_data->display_line_total) |
if (*p_display_line + 1 >= p_editor_data->display_line_total) |
| 562 |
split_line_total = last_display_line - display_line + 2; |
split_line_total = last_display_line - display_line + 2; |
| 563 |
|
|
| 564 |
// Split current data line since beginning of current display line |
// Split current data line since beginning of current display line |
| 565 |
split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total); |
split_line_total = split_data_lines(p_data_line, SCREEN_COLS, line_offsets, split_line_total, 0); |
| 566 |
|
|
| 567 |
for (i = 0; i < split_line_total; i++) |
for (i = 0; i < split_line_total; i++) |
| 568 |
{ |
{ |
| 607 |
{ |
{ |
| 608 |
case 0: // Set msg |
case 0: // Set msg |
| 609 |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 610 |
"| 退出[\033[32mCtrl-W\033[33m] | 帮助[\033[32mh\033[33m] |"); |
"| 退出[\033[32mCtrl-W\033[33m] |"); |
| 611 |
|
break; |
| 612 |
|
case KEY_CSI: |
| 613 |
|
*p_key = KEY_ESC; |
| 614 |
break; |
break; |
| 615 |
} |
} |
| 616 |
|
|
| 664 |
"%s", |
"%s", |
| 665 |
row_pos, col_pos, |
row_pos, col_pos, |
| 666 |
ctx.line_cursor, p_editor_data->display_line_total, |
ctx.line_cursor, p_editor_data->display_line_total, |
| 667 |
key_insert ? "插入" : "改写", |
key_insert ? "插入" : "替换", |
| 668 |
ctx.msg); |
ctx.msg); |
| 669 |
|
|
| 670 |
len = split_line(buffer, SCREEN_COLS, &eol, &display_len); |
len = split_line(buffer, SCREEN_COLS, &eol, &display_len, 1); |
| 671 |
for (; display_len < SCREEN_COLS; display_len++) |
for (; display_len < SCREEN_COLS; display_len++) |
| 672 |
{ |
{ |
| 673 |
buffer[len++] = ' '; |
buffer[len++] = ' '; |
| 681 |
moveto((int)row_pos, (int)col_pos); |
moveto((int)row_pos, (int)col_pos); |
| 682 |
iflush(); |
iflush(); |
| 683 |
|
|
| 684 |
|
str_len = 0; |
| 685 |
input_ok = 0; |
input_ok = 0; |
| 686 |
|
ch = igetch_t(MAX_DELAY_TIME); |
| 687 |
while (!SYS_server_exit && !input_ok) |
while (!SYS_server_exit && !input_ok) |
| 688 |
{ |
{ |
|
ch = igetch_t(MAX_DELAY_TIME); |
|
|
input_ok = 1; |
|
|
|
|
| 689 |
// extended key handler |
// extended key handler |
| 690 |
if (editor_display_key_handler(&ch, &ctx) != 0) |
if (editor_display_key_handler(&ch, &ctx) != 0) |
| 691 |
{ |
{ |
| 706 |
if ((ch >= 32 && ch < 127) || (ch > 127 && ch <= 255 && str_len == 2) || // Printable character or GBK |
if ((ch >= 32 && ch < 127) || (ch > 127 && ch <= 255 && str_len == 2) || // Printable character or GBK |
| 707 |
ch == CR || ch == KEY_ESC) // Special character |
ch == CR || ch == KEY_ESC) // Special character |
| 708 |
{ |
{ |
| 709 |
|
BBS_last_access_tm = time(NULL); |
| 710 |
|
|
| 711 |
if (str_len == 0) // ch >= 32 && ch < 127 |
if (str_len == 0) // ch >= 32 && ch < 127 |
| 712 |
{ |
{ |
| 713 |
input_str[0] = (char)ch; |
input_str[0] = (char)ch; |
| 766 |
col_pos = offset_out + 1; // Set col_pos to accurate pos |
col_pos = offset_out + 1; // Set col_pos to accurate pos |
| 767 |
} |
} |
| 768 |
|
|
| 769 |
|
if (display_line_out != display_line_in) // Output on line change |
| 770 |
|
{ |
| 771 |
|
break; |
| 772 |
|
} |
| 773 |
|
|
| 774 |
|
ch = igetch(0); |
| 775 |
|
if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input |
| 776 |
|
{ |
| 777 |
|
break; |
| 778 |
|
} |
| 779 |
|
|
| 780 |
str_len = 0; |
str_len = 0; |
| 781 |
continue; |
continue; |
| 782 |
} |
} |
| 783 |
else if (ch == KEY_DEL || ch == BACKSPACE) // Del |
else if (ch == KEY_DEL || ch == BACKSPACE) // Del |
| 784 |
{ |
{ |
| 785 |
|
BBS_last_access_tm = time(NULL); |
| 786 |
|
|
| 787 |
if (ch == BACKSPACE) |
if (ch == BACKSPACE) |
| 788 |
{ |
{ |
| 789 |
if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden |
if (line_current - output_current_row + row_pos <= 0 && col_pos <= 1) // Forbidden |
| 790 |
{ |
{ |
| 791 |
input_ok = 0; |
ch = igetch_t(MAX_DELAY_TIME); |
| 792 |
continue; |
continue; |
| 793 |
} |
} |
| 794 |
|
|
| 847 |
clrline(output_current_row, output_end_row); |
clrline(output_current_row, output_end_row); |
| 848 |
} |
} |
| 849 |
|
|
| 850 |
|
if (display_line_out != display_line_in) // Output on line change |
| 851 |
|
{ |
| 852 |
|
break; |
| 853 |
|
} |
| 854 |
|
|
| 855 |
|
ch = igetch(0); |
| 856 |
|
if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input |
| 857 |
|
{ |
| 858 |
|
break; |
| 859 |
|
} |
| 860 |
|
|
| 861 |
str_len = 0; |
str_len = 0; |
| 862 |
continue; |
continue; |
| 863 |
} |
} |
| 864 |
|
|
| 865 |
|
input_ok = 1; |
| 866 |
switch (ch) |
switch (ch) |
| 867 |
{ |
{ |
| 868 |
case KEY_NULL: |
case KEY_NULL: |
| 1059 |
break; |
break; |
| 1060 |
} |
} |
| 1061 |
|
|
| 1062 |
BBS_last_access_tm = time(0); |
BBS_last_access_tm = time(NULL); |
| 1063 |
|
|
| 1064 |
if (input_ok) |
if (input_ok) |
| 1065 |
{ |
{ |
| 1066 |
break; |
break; |
| 1067 |
} |
} |
| 1068 |
|
|
| 1069 |
|
ch = igetch_t(MAX_DELAY_TIME); |
| 1070 |
} |
} |
| 1071 |
|
|
| 1072 |
continue; |
continue; |