--- lbbs/src/screen.c 2025/05/06 05:31:26 1.36 +++ lbbs/src/screen.c 2025/05/06 13:34:28 1.39 @@ -101,14 +101,14 @@ void set_input_echo(int echo) } } -static int _str_input(char *buffer, int buffer_length, int echo_mode) +static int _str_input(char *buffer, int buf_size, int echo_mode) { - int c, offset = 0, i, hz = 0; + int c; + int offset = 0; + int hz = 0; - for (i = 0; i < buffer_length && buffer[i] != '\0'; i++) - { - offset++; - } + buffer[buf_size - 1] = '\0'; + for (offset = 0; offset < buf_size - 1 && buffer[offset] != '\0'; offset++); while ((c = igetch_t(60))) { @@ -148,7 +148,7 @@ static int _str_input(char *buffer, int } if (c > 127 && c <= 255) { - if (!hz && offset + 2 > buffer_length) // No enough space for Chinese character + if (!hz && offset + 2 > buf_size - 1) // No enough space for Chinese character { igetch(1); // Cleanup remaining input outc('\a'); @@ -157,7 +157,7 @@ static int _str_input(char *buffer, int } hz = (!hz); } - if (offset >= buffer_length) + if (offset + 1 > buf_size - 1) { outc('\a'); iflush(); @@ -183,13 +183,13 @@ static int _str_input(char *buffer, int return offset; } -int str_input(char *buffer, int buffer_length, int echo_mode) +int str_input(char *buffer, int buf_size, int echo_mode) { int len; buffer[0] = '\0'; - len = _str_input(buffer, buffer_length, echo_mode); + len = _str_input(buffer, buf_size, echo_mode); prints("\r\n"); iflush(); @@ -197,7 +197,7 @@ int str_input(char *buffer, int buffer_l return len; }; -int get_data(int row, int col, char *prompt, char *buffer, int buffer_length, int echo_mode) +int get_data(int row, int col, char *prompt, char *buffer, int buf_size, int echo_mode) { int len; @@ -208,7 +208,7 @@ int get_data(int row, int col, char *pro prints(buffer); iflush(); - len = _str_input(buffer, buffer_length, echo_mode); + len = _str_input(buffer, buf_size, echo_mode); return len; } @@ -243,6 +243,7 @@ int display_file(const char *filename) int display_file_ex(const char *filename, int begin_line, int wait) { + static int show_help = 1; char buffer[LINE_BUFFER_LEN]; int ch = 0; int input_ok, line, max_lines; @@ -316,9 +317,9 @@ int display_file_ex(const char *filename } c_line_current -= line; line = begin_line; - max_lines = begin_line + 1; - prints("\033[T"); // Scroll down 1 line - // max_lines = screen_rows - 1; // Legacy Fterm only works with this line + // max_lines = begin_line + 1; + // prints("\033[T"); // Scroll down 1 line + max_lines = screen_rows - 1; // Legacy Fterm only works with this line break; case KEY_DOWN: case CR: @@ -375,8 +376,15 @@ int display_file_ex(const char *filename case '?': case 'h': case 'H': + if (!show_help) + { + break; + } + // Display help information + show_help = 0; display_file_ex(DATA_READ_HELP, begin_line, 1); + show_help = 1; // Refresh after display help information c_line_current -= (line - 1);