diff options
Diffstat (limited to 'gdb/ui-style.c')
-rw-r--r-- | gdb/ui-style.c | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/gdb/ui-style.c b/gdb/ui-style.c index b8d73ab..c8f2e11 100644 --- a/gdb/ui-style.c +++ b/gdb/ui-style.c @@ -21,12 +21,14 @@ #include "gdbsupport/gdb_regex.h" /* A regular expression that is used for matching ANSI terminal escape - sequences. */ + sequences. Note that this will actually match any prefix of such a + sequence. This property is used so that other code can buffer + incomplete sequences as needed. */ static const char ansi_regex_text[] = - /* Introduction. */ - "^\033\\[" -#define DATA_SUBEXP 1 + /* Introduction. Only the escape character is truly required. */ + "^\033(\\[" +#define DATA_SUBEXP 2 /* Capture parameter and intermediate bytes. */ "(" /* Parameter bytes. */ @@ -36,12 +38,12 @@ static const char ansi_regex_text[] = /* End the first capture. */ ")" /* The final byte. */ -#define FINAL_SUBEXP 2 - "([\x40-\x7e])"; +#define FINAL_SUBEXP 3 + "([\x40-\x7e]))?"; /* The number of subexpressions to allocate space for, including the "0th" whole match subexpression. */ -#define NUM_SUBEXPRESSIONS 3 +#define NUM_SUBEXPRESSIONS 4 /* The compiled form of ansi_regex_text. */ @@ -371,6 +373,15 @@ ui_file_style::parse (const char *buf, size_t *n_read) *n_read = 0; return false; } + + /* If the final subexpression did not match, then that means there + was an incomplete sequence. These are ignored here. */ + if (subexps[FINAL_SUBEXP].rm_so == -1) + { + *n_read = 0; + return false; + } + /* Other failures mean the regexp is broken. */ gdb_assert (match == 0); /* The regexp is anchored. */ @@ -527,17 +538,25 @@ ui_file_style::parse (const char *buf, size_t *n_read) /* See ui-style.h. */ -bool -skip_ansi_escape (const char *buf, int *n_read) +ansi_escape_result +examine_ansi_escape (const char *buf, int *n_read) { + gdb_assert (*buf == '\033'); + regmatch_t subexps[NUM_SUBEXPRESSIONS]; int match = ansi_regex.exec (buf, ARRAY_SIZE (subexps), subexps, 0); - if (match == REG_NOMATCH || buf[subexps[FINAL_SUBEXP].rm_so] != 'm') - return false; + if (match == REG_NOMATCH) + return ansi_escape_result::NO_MATCH; + + if (subexps[FINAL_SUBEXP].rm_so == -1) + return ansi_escape_result::INCOMPLETE; + + if (buf[subexps[FINAL_SUBEXP].rm_so] != 'm') + return ansi_escape_result::NO_MATCH; *n_read = subexps[FINAL_SUBEXP].rm_eo; - return true; + return ansi_escape_result::MATCHED; } /* See ui-style.h. */ |