--- lbbs/src/str_process.c 2025/06/13 10:52:07 1.13 +++ lbbs/src/str_process.c 2025/06/21 02:15:18 1.18 @@ -14,13 +14,13 @@ * * ***************************************************************************/ -#include "str_process.h" #include "common.h" #include "log.h" +#include "str_process.h" #include #include -int split_line(const char *buffer, int max_display_len, int *p_eol, int *p_display_len) +int split_line(const char *buffer, int max_display_len, int *p_eol, int *p_display_len, int skip_ctrl_seq) { int i; *p_eol = 0; @@ -36,7 +36,7 @@ int split_line(const char *buffer, int m continue; } - if (c == '\033' && buffer[i + 1] == '[') // Skip control sequence + if (skip_ctrl_seq && c == '\033' && buffer[i + 1] == '[') // Skip control sequence { i += 2; while (buffer[i] != '\0' && buffer[i] != 'm') @@ -63,7 +63,7 @@ int split_line(const char *buffer, int m } (*p_display_len)++; - // \n is regarded as 1 character wide in terminal editor, which is different from Web version + // \n is regarded as 1 character wide in terminal editor, which is different from Web version if (c == '\n') { i++; @@ -76,7 +76,7 @@ int split_line(const char *buffer, int m return i; } -long split_data_lines(const char *p_buf, int max_display_len, long *p_line_offsets, long line_offsets_count) +long split_data_lines(const char *p_buf, int max_display_len, long *p_line_offsets, long line_offsets_count, int skip_ctrl_seq) { int line_cnt = 0; int len; @@ -87,12 +87,12 @@ long split_data_lines(const char *p_buf, do { - len = split_line(p_buf, max_display_len, &end_of_line, &display_len); + len = split_line(p_buf, max_display_len, &end_of_line, &display_len, skip_ctrl_seq); // Exceed max_line_cnt if (line_cnt + 1 >= line_offsets_count) { - log_error("Line count %d reaches limit %d\n", line_cnt + 1, line_offsets_count); + // log_error("Line count %d reaches limit %d\n", line_cnt + 1, line_offsets_count); return line_cnt; } @@ -103,3 +103,34 @@ long split_data_lines(const char *p_buf, return line_cnt; } + +int str_filter(char *buffer, int skip_ctrl_seq) +{ + int i; + int j; + + for (i = 0, j = 0; buffer[i] != '\0'; i++) + { + if (buffer[i] == '\r' || buffer[i] == '\7') // skip + { + continue; + } + + if (skip_ctrl_seq && buffer[i] == '\033' && buffer[i + 1] == '[') // Skip control sequence + { + i += 2; + while (buffer[i] != '\0' && buffer[i] != 'm') + { + i++; + } + continue; + } + + buffer[j] = buffer[i]; + j++; + } + + buffer[j] = '\0'; + + return j; +}