--- lbbs/src/screen.c 2025/05/08 08:05:58 1.40 +++ lbbs/src/screen.c 2025/05/11 11:50:03 1.46 @@ -22,10 +22,11 @@ #include "screen.h" #include #include -#include -#include #include #include +#include +#include +#include #define ACTIVE_BOARD_HEIGHT 8 @@ -81,7 +82,7 @@ int press_any_key() prints(" \033[1;33m°´ÈÎÒâ¼ü¼ÌÐø...\033[0;37m"); iflush(); - return igetch_t(60); + return igetch_t(MIN(MAX_DELAY_TIME, 60)); } void set_input_echo(int echo) @@ -108,20 +109,25 @@ static int _str_input(char *buffer, int int hz = 0; buffer[buf_size - 1] = '\0'; - for (offset = 0; offset < buf_size - 1 && buffer[offset] != '\0'; offset++); + for (offset = 0; offset < buf_size - 1 && buffer[offset] != '\0'; offset++) + ; - while ((c = igetch_t(60))) + while (!SYS_server_exit && (c = igetch_t(MIN(MAX_DELAY_TIME, 60)))) { - if (c == KEY_NULL || c == KEY_TIMEOUT || c == CR) + if (c == CR) { igetch(1); // Cleanup remaining '\n' in the buffer break; } - if (c == LF) + else if (c == KEY_TIMEOUT || c == KEY_NULL) // timeout or broken pipe + { + return -1; + } + else if (c == LF || c == '\0') { continue; } - if (c == BACKSPACE) + else if (c == BACKSPACE) { if (offset > 0) { @@ -142,11 +148,11 @@ static int _str_input(char *buffer, int } continue; } - if (c > 255 || iscntrl(c)) + else if (c > 255 || iscntrl(c)) { continue; } - if (c > 127 && c <= 255) + else if (c > 127 && c <= 255) { if (!hz && offset + 2 > buf_size - 1) // No enough space for Chinese character { @@ -157,14 +163,17 @@ static int _str_input(char *buffer, int } hz = (!hz); } + if (offset + 1 > buf_size - 1) { outc('\a'); iflush(); continue; } + buffer[offset++] = (char)c; buffer[offset] = '\0'; + switch (echo_mode) { case DOECHO: @@ -269,7 +278,7 @@ int display_file_ex(const char *filename line = begin_line; max_lines = screen_rows - 1; - while (loop) + while (!SYS_server_exit && loop) { if (c_line_current >= c_line_total && c_line_total <= screen_rows - 2) { @@ -304,12 +313,15 @@ int display_file_ex(const char *filename iflush(); input_ok = 0; - while (!input_ok) + while (!SYS_server_exit && !input_ok) { ch = igetch_t(MAX_DELAY_TIME); input_ok = 1; switch (ch) { + case KEY_NULL: + case KEY_TIMEOUT: + goto cleanup; case KEY_UP: if (c_line_current - line < 0) // Reach top { @@ -366,8 +378,6 @@ int display_file_ex(const char *filename max_lines = screen_rows - 1; clrline(begin_line, screen_rows); break; - case KEY_NULL: - case KEY_TIMEOUT: case KEY_LEFT: case 'q': case 'Q': @@ -396,6 +406,8 @@ int display_file_ex(const char *filename input_ok = 0; break; } + + BBS_last_access_tm = time(0); } continue; @@ -420,6 +432,7 @@ int display_file_ex(const char *filename line++; } +cleanup: free(p_line_offsets); fclose(fin);