--- lbbs/src/str_process.c 2025/05/03 06:25:17 1.1 +++ lbbs/src/str_process.c 2025/05/13 02:19:49 1.5 @@ -9,7 +9,7 @@ * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * + * the Free Software Foundation; either version 3 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ @@ -20,12 +20,12 @@ #include #include -int split_line(const char *buffer, int max_len, int *p_eol) +unsigned int split_line(const char *buffer, int max_len, int *p_eol, int *p_display_len) { - int len = strnlen(buffer, LINE_BUFFER_LEN); - int display_len = 0; - int i = 0; + size_t len = strnlen(buffer, LINE_BUFFER_LEN); + unsigned int i = 0; *p_eol = 0; + *p_display_len = 0; if (len == 0) { @@ -47,11 +47,11 @@ int split_line(const char *buffer, int m *p_eol = 1; break; } - + if (c == '\033' && buffer[i + 1] == '[') // Skip control sequence { i += 2; - while(i < len && buffer[i] != 'm') + while (i < len && buffer[i] != 'm') { i++; } @@ -60,45 +60,47 @@ int split_line(const char *buffer, int m if (c > 127 && c <= 255) // GBK chinese character { - if (display_len + 2 > max_len) + if (*p_display_len + 2 > max_len) { *p_eol = 1; break; } i++; - display_len += 2; + *p_display_len += 2; } else { - if (display_len >= max_len) + if (*p_display_len + 1 > max_len) { *p_eol = 1; break; } - display_len++; + (*p_display_len)++; } } return i; } -int split_file_lines(FILE *fin, int max_len, long *p_line_offsets, int max_line_cnt) +unsigned int split_file_lines(FILE *fin, int max_len, long *p_line_offsets, int max_line_cnt) { char buffer[LINE_BUFFER_LEN]; char *p_buf = buffer; - int line_cnt = 0; - int len = 0; + unsigned int line_cnt = 0; + unsigned int len = 0; int end_of_line = 0; + int display_len = 0; + p_line_offsets[line_cnt] = 0L; - while (fgets(p_buf, sizeof(buffer) - len, fin)) + while (fgets(p_buf, (int)(sizeof(buffer) - len), fin)) { p_buf = buffer; while (1) { - len = split_line(p_buf, max_len, &end_of_line); + len = split_line(p_buf, max_len, &end_of_line, &display_len); - if (len == 0 || !end_of_line) + if (len == 0 || !end_of_line) // !end_of_line == EOF { break; }