--- lbbs/src/editor.c 2025/10/01 02:49:13 1.43 +++ lbbs/src/editor.c 2025/10/18 12:06:10 1.48 @@ -49,7 +49,7 @@ int editor_memory_pool_init(void) } p_mp_editor_data = memory_pool_init(sizeof(EDITOR_DATA), 1, 1); - if (p_mp_data_line == NULL) + if (p_mp_editor_data == NULL) { log_error("Memory pool init error\n"); return -3; @@ -83,7 +83,7 @@ EDITOR_DATA *editor_data_load(const char if (p_data == NULL) { - log_error("editor_data_load() error: NULL pointer\n"); + log_error("NULL pointer error\n"); return NULL; } @@ -150,7 +150,7 @@ long editor_data_save(const EDITOR_DATA if (p_editor_data == NULL || p_data == NULL) { - log_error("editor_data_save() error: NULL pointer\n"); + log_error("NULL pointer error\n"); return -1; } @@ -224,7 +224,7 @@ int editor_data_insert(EDITOR_DATA *p_ed if (p_editor_data == NULL || p_last_updated_line == NULL) { - log_error("editor_data_op() error: NULL pointer\n"); + log_error("NULL pointer error\n"); return -1; } @@ -462,7 +462,7 @@ int editor_data_delete(EDITOR_DATA *p_ed if (p_editor_data == NULL || p_last_updated_line == NULL) { - log_error("editor_data_op() error: NULL pointer\n"); + log_error("NULL pointer error\n"); return -1; } @@ -504,14 +504,14 @@ int editor_data_delete(EDITOR_DATA *p_ed { str_len = 1; } - else if (p_data_line[offset_data_line] & 0b10000000) // head of multi-byte character + else if (p_data_line[offset_data_line] & 0x80) // head of multi-byte character { str_len = 1; - c = (p_data_line[offset_data_line] & 0b01110000) << 1; - while (c & 0b10000000) + c = (p_data_line[offset_data_line] & 0x70) << 1; + while (c & 0x80) { str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; } } else @@ -705,23 +705,28 @@ int editor_display(EDITOR_DATA *p_editor ch = igetch_t(MAX_DELAY_TIME); while (!SYS_server_exit) { + if (ch != KEY_NULL && ch != KEY_TIMEOUT) + { + BBS_last_access_tm = time(NULL); + } + // extended key handler if (editor_display_key_handler(&ch, &ctx) != 0) { goto cleanup; } - if (ch < 256 && (ch & 0b10000000)) // head of multi-byte character + if (ch < 256 && (ch & 0x80)) // head of multi-byte character { str_len = 0; - c = (char)(ch & 0b11110000); - while (c & 0b10000000) + c = (char)(ch & 0xf0); + while (c & 0x80) { input_str[str_len] = (char)(ch - 256); str_len++; - c = (c & 0b01111111) << 1; + c = (c & 0x7f) << 1; - if ((c & 0b10000000) == 0) // Input completed + if ((c & 0x80) == 0) // Input completed { break; } @@ -742,8 +747,6 @@ int editor_display(EDITOR_DATA *p_editor if ((ch >= 32 && ch < 127) || str_len >= 2 || // Printable character or multi-byte character ch == CR || ch == KEY_ESC) // Special character { - BBS_last_access_tm = time(NULL); - // Refresh current action while user input if (user_online_update(NULL) < 0) { @@ -837,8 +840,6 @@ int editor_display(EDITOR_DATA *p_editor } else if (ch == KEY_DEL || ch == BACKSPACE) // Del { - BBS_last_access_tm = time(NULL); - // Refresh current action while user input if (user_online_update(NULL) < 0) { @@ -930,7 +931,10 @@ int editor_display(EDITOR_DATA *p_editor switch (ch) { case KEY_NULL: + log_error("KEY_NULL\n"); + goto cleanup; case KEY_TIMEOUT: + log_error("User input timeout\n"); goto cleanup; case Ctrl('W'): case Ctrl('X'): @@ -1110,6 +1114,7 @@ int editor_display(EDITOR_DATA *p_editor col_pos = MIN(col_pos, MAX(1, p_editor_data->display_line_widths[line_current - output_current_row + row_pos])); clrline(output_current_row, SCREEN_ROWS); break; + case Ctrl('Q'): case KEY_F1: if (!show_help) // Not reentrant { @@ -1133,8 +1138,6 @@ int editor_display(EDITOR_DATA *p_editor break; } - BBS_last_access_tm = time(NULL); - // Refresh current action while user input if (user_online_update(NULL) < 0) {