| 22 |
#include "str_process.h" |
#include "str_process.h" |
| 23 |
#include "memory_pool.h" |
#include "memory_pool.h" |
| 24 |
#include <stdlib.h> |
#include <stdlib.h> |
|
#include <sys/param.h> |
|
|
#include <strings.h> |
|
|
|
|
|
#define _POSIX_C_SOURCE 200809L |
|
| 25 |
#include <string.h> |
#include <string.h> |
| 26 |
|
#include <sys/param.h> |
| 27 |
|
|
| 28 |
#define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m" |
#define EDITOR_ESC_DISPLAY_STR "\033[32m*\033[m" |
| 29 |
#define EDITOR_MEM_POOL_LINE_PER_CHUNK 1000 |
#define EDITOR_MEM_POOL_LINE_PER_CHUNK 1000 |
| 135 |
p_data_line[current_data_line_length] = '\0'; |
p_data_line[current_data_line_length] = '\0'; |
| 136 |
} |
} |
| 137 |
|
|
| 138 |
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); |
| 139 |
|
|
| 140 |
return p_editor_data; |
return p_editor_data; |
| 141 |
} |
} |
| 278 |
{ |
{ |
| 279 |
if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES) |
if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES) |
| 280 |
{ |
{ |
| 281 |
// log_error("Split line error, display_line_total(%ld) reach limit(%d)\n", |
#ifdef _DEBUG |
| 282 |
// p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES); |
log_error("Split line error, display_line_total(%ld) reach limit(%d)\n", |
| 283 |
|
p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES); |
| 284 |
|
#endif |
| 285 |
|
|
| 286 |
return -2; |
return -2; |
| 287 |
} |
} |
| 288 |
|
|
| 371 |
// Insert blank display line after last_display_line |
// Insert blank display line after last_display_line |
| 372 |
if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES) |
if (p_editor_data->display_line_total >= MAX_EDITOR_DATA_LINES) |
| 373 |
{ |
{ |
| 374 |
// log_error("display_line_total over limit %d >= %d\n", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES); |
#ifdef _DEBUG |
| 375 |
|
log_error("display_line_total over limit %d >= %d\n", p_editor_data->display_line_total, MAX_EDITOR_DATA_LINES); |
| 376 |
|
#endif |
| 377 |
|
|
| 378 |
// Terminate prior display line with \n, to avoid error on cleanup |
// Terminate prior display line with \n, to avoid error on cleanup |
| 379 |
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) |
| 380 |
{ |
{ |
| 612 |
{ |
{ |
| 613 |
case 0: // Set msg |
case 0: // Set msg |
| 614 |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
snprintf(p_ctx->msg, sizeof(p_ctx->msg), |
| 615 |
"| Í˳ö[\033[32mCtrl-W\033[33m] | °ïÖú[\033[32mh\033[33m] |"); |
"| Í˳ö[\033[32mCtrl-W\033[33m] |"); |
| 616 |
break; |
break; |
| 617 |
case KEY_CSI: |
case KEY_CSI: |
| 618 |
*p_key = KEY_ESC; |
*p_key = KEY_ESC; |
| 686 |
moveto((int)row_pos, (int)col_pos); |
moveto((int)row_pos, (int)col_pos); |
| 687 |
iflush(); |
iflush(); |
| 688 |
|
|
| 689 |
|
str_len = 0; |
| 690 |
input_ok = 0; |
input_ok = 0; |
| 691 |
|
ch = igetch_t(MAX_DELAY_TIME); |
| 692 |
while (!SYS_server_exit && !input_ok) |
while (!SYS_server_exit && !input_ok) |
| 693 |
{ |
{ |
|
ch = igetch_t(MAX_DELAY_TIME); |
|
|
input_ok = 1; |
|
|
|
|
| 694 |
// extended key handler |
// extended key handler |
| 695 |
if (editor_display_key_handler(&ch, &ctx) != 0) |
if (editor_display_key_handler(&ch, &ctx) != 0) |
| 696 |
{ |
{ |
| 711 |
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 |
| 712 |
ch == CR || ch == KEY_ESC) // Special character |
ch == CR || ch == KEY_ESC) // Special character |
| 713 |
{ |
{ |
| 714 |
|
BBS_last_access_tm = time(NULL); |
| 715 |
|
|
| 716 |
if (str_len == 0) // ch >= 32 && ch < 127 |
if (str_len == 0) // ch >= 32 && ch < 127 |
| 717 |
{ |
{ |
| 718 |
input_str[0] = (char)ch; |
input_str[0] = (char)ch; |
| 771 |
col_pos = offset_out + 1; // Set col_pos to accurate pos |
col_pos = offset_out + 1; // Set col_pos to accurate pos |
| 772 |
} |
} |
| 773 |
|
|
| 774 |
|
if (display_line_out != display_line_in) // Output on line change |
| 775 |
|
{ |
| 776 |
|
break; |
| 777 |
|
} |
| 778 |
|
|
| 779 |
|
ch = igetch(0); |
| 780 |
|
if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input |
| 781 |
|
{ |
| 782 |
|
break; |
| 783 |
|
} |
| 784 |
|
|
| 785 |
str_len = 0; |
str_len = 0; |
| 786 |
continue; |
continue; |
| 787 |
} |
} |
| 788 |
else if (ch == KEY_DEL || ch == BACKSPACE) // Del |
else if (ch == KEY_DEL || ch == BACKSPACE) // Del |
| 789 |
{ |
{ |
| 790 |
|
BBS_last_access_tm = time(NULL); |
| 791 |
|
|
| 792 |
if (ch == BACKSPACE) |
if (ch == BACKSPACE) |
| 793 |
{ |
{ |
| 794 |
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 |
| 795 |
{ |
{ |
| 796 |
input_ok = 0; |
ch = igetch_t(MAX_DELAY_TIME); |
| 797 |
continue; |
continue; |
| 798 |
} |
} |
| 799 |
|
|
| 852 |
clrline(output_current_row, output_end_row); |
clrline(output_current_row, output_end_row); |
| 853 |
} |
} |
| 854 |
|
|
| 855 |
|
if (display_line_out != display_line_in) // Output on line change |
| 856 |
|
{ |
| 857 |
|
break; |
| 858 |
|
} |
| 859 |
|
|
| 860 |
|
ch = igetch(0); |
| 861 |
|
if (ch == KEY_NULL || ch == KEY_TIMEOUT) // Output if no futher input |
| 862 |
|
{ |
| 863 |
|
break; |
| 864 |
|
} |
| 865 |
|
|
| 866 |
str_len = 0; |
str_len = 0; |
| 867 |
continue; |
continue; |
| 868 |
} |
} |
| 869 |
|
|
| 870 |
|
input_ok = 1; |
| 871 |
switch (ch) |
switch (ch) |
| 872 |
{ |
{ |
| 873 |
case KEY_NULL: |
case KEY_NULL: |
| 1064 |
break; |
break; |
| 1065 |
} |
} |
| 1066 |
|
|
| 1067 |
BBS_last_access_tm = time(0); |
BBS_last_access_tm = time(NULL); |
| 1068 |
|
|
| 1069 |
if (input_ok) |
if (input_ok) |
| 1070 |
{ |
{ |
| 1071 |
break; |
break; |
| 1072 |
} |
} |
| 1073 |
|
|
| 1074 |
|
ch = igetch_t(MAX_DELAY_TIME); |
| 1075 |
} |
} |
| 1076 |
|
|
| 1077 |
continue; |
continue; |