Use '\033' (portable) instead of '\e' (GNU extension), simplify
the control character handling by checking for ESC directly, and
fix the SCS boundary check to only match complete sequences.
Signed-off-by: Karel Zak <kzak@redhat.com>
last = p + (bufsz - 1);
while (p && *p && p <= last) {
- if (iscntrl((unsigned char) *p)) {
- char ctrl_char = *p;
+ if (*p == '\033') {
p++;
- /* only process escape sequences if the control char is ESC */
- if (ctrl_char != '\e')
- continue;
-
/* try detect "\e[x;ym" and skip on success */
if (*p && *p == '[') {
const char *e = p;
p = e + 1;
}
/* try detect SCS sequences "\e(X", "\e)X", "\e*X", "\e+X" and skip on success */
- else if (*p && (*p == '(' || *p == ')' || *p == '*' || *p == '+')) {
- p++; /* skip the SCS introducer */
- if (p <= last)
- p++; /* skip the character */
- }
+ else if (p < last && (*p == '(' || *p == ')' || *p == '*' || *p == '+'))
+ p += 2; /* skip the SCS sequence */
+ continue;
+ }
+ if (iscntrl((unsigned char) *p)) {
+ p++;
continue;
}
#ifdef HAVE_WIDECHAR