diff --git a/src/main.c b/src/main.c index 4af4812..0436868 100644 --- a/src/main.c +++ b/src/main.c @@ -128,7 +128,8 @@ static inline void char_to_buffer(const unsigned char c) #endif #endif -static inline __attribute__((always_inline)) void just_strip_it(void) +static inline __attribute__((always_inline)) void +just_strip_it(bool ignore_sgr_errors) { enum parser_state { @@ -240,13 +241,18 @@ static inline __attribute__((always_inline)) void just_strip_it(void) current_sgr_value *= 10; current_sgr_value += c - '0'; if (current_sgr_value > 255) - ERROR( - "SGR sequence contains invalid number " - "'%d' " - "at %zu characters read / %zu in SGR sequence " - "which begun at %zu characters read.\n", - current_sgr_value, read, sgr_chars_len, begun_at - ); + { + if (ignore_sgr_errors) + state = STATE_TEXT; + else + ERROR( + "SGR sequence contains invalid number " + "'%d' " + "at %zu characters read / %zu in SGR sequence " + "which begun at %zu characters read.\n", + current_sgr_value, read, sgr_chars_len, begun_at + ); + } } else if (c == ';') { @@ -257,12 +263,17 @@ static inline __attribute__((always_inline)) void just_strip_it(void) state = STATE_TEXT; } else - ERROR( - "SGR sequence contains invalid character " - "'%c' at %zu characters read / %zu in SGR sequence " - "which begun at %zu characters read.\n", - c, read, sgr_chars_len, begun_at - ); + { + if (ignore_sgr_errors) + state = STATE_TEXT; + else + ERROR( + "SGR sequence contains invalid character " + "'%c' at %zu characters read / %zu in SGR sequence " + "which begun at %zu characters read.\n", + c, read, sgr_chars_len, begun_at + ); + } } else { @@ -585,6 +596,7 @@ static inline __attribute__((always_inline)) void ansi2html( " --help Show this help.\n" \ " --strip, -S Strip all ANSI, rather than HTML " \ "encode.\n" \ + " --ignore-sgr-errors For --strip only.\n" \ " --list-palettes, -l List the names of valid/known palettes.\n" \ " --palette, -p Use the named palette. Default is vga.\n" \ " " WITH_ITERM2_COLOR_SCHEMES " iTerm2-Color-Schemes palettes.\n" \ @@ -605,8 +617,8 @@ static inline __attribute__((always_inline)) void ansi2html( " --pre-add-style