termptyesc: export termptyesc_safechar()

This commit is contained in:
Boris Faure 2020-11-15 13:48:20 +01:00
parent 76687b2ea2
commit 05b95705ae
Signed by: borisfaure
GPG Key ID: 35C0410516166BE8
2 changed files with 17 additions and 12 deletions

View File

@ -77,8 +77,8 @@ static const char *const ASCII_CHARS_TABLE[] =
"US" // '\037' "US" // '\037'
}; };
static const char * EINA_PURE const char * EINA_PURE
_safechar(const unsigned int c) termptyesc_safechar(const unsigned int c)
{ {
static char _str[9]; static char _str[9];
@ -3329,7 +3329,7 @@ _handle_esc_csi(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
*b = 0; *b = 0;
be = b; be = b;
b = buf; b = buf;
DBG(" CSI: '%s' args '%s'", _safechar(*cc), (char *) buf); DBG(" CSI: '%s' args '%s'", termptyesc_safechar(*cc), (char *) buf);
switch (*cc) switch (*cc)
{ {
/* sorted by ascii value */ /* sorted by ascii value */
@ -3589,7 +3589,7 @@ unhandled:
else else
eina_strbuf_append_char(bf, c[i]); eina_strbuf_append_char(bf, c[i]);
} }
WRN("unhandled CSI '%s': %s", _safechar(*cc), eina_strbuf_string_get(bf)); WRN("unhandled CSI '%s': %s", termptyesc_safechar(*cc), eina_strbuf_string_get(bf));
eina_strbuf_free(bf); eina_strbuf_free(bf);
} }
#endif #endif
@ -4511,7 +4511,8 @@ _handle_esc_dcs(Termpty *ty,
/* Request status string */ /* Request status string */
if (len > 1 && buf[1] != 'q') if (len > 1 && buf[1] != 'q')
{ {
WRN("invalid/unhandled dsc esc '$%s' (expected '$q')", _safechar(buf[1])); WRN("invalid/unhandled dsc esc '$%s' (expected '$q')",
termptyesc_safechar(buf[1]));
ty->decoding_error = EINA_TRUE; ty->decoding_error = EINA_TRUE;
goto end; goto end;
} }
@ -4534,7 +4535,8 @@ _handle_esc_dcs(Termpty *ty,
} }
else else
{ {
WRN("invalid/unhandled dsc esc '$q\"%s'", _safechar(buf[3])); WRN("invalid/unhandled dsc esc '$q\"%s'",
termptyesc_safechar(buf[3]));
ty->decoding_error = EINA_TRUE; ty->decoding_error = EINA_TRUE;
goto end; goto end;
} }
@ -4545,13 +4547,14 @@ _handle_esc_dcs(Termpty *ty,
/* TODO: */ /* TODO: */
default: default:
ty->decoding_error = EINA_TRUE; ty->decoding_error = EINA_TRUE;
WRN("unhandled dsc request status string '$q%s'", _safechar(buf[2])); WRN("unhandled dsc request status string '$q%s'",
termptyesc_safechar(buf[2]));
goto end; goto end;
} }
break; break;
default: default:
// many others // many others
WRN("Unhandled DCS escape '%s'", _safechar(buf[0])); WRN("Unhandled DCS escape '%s'", termptyesc_safechar(buf[0]));
ty->decoding_error = EINA_TRUE; ty->decoding_error = EINA_TRUE;
break; break;
} }
@ -4698,7 +4701,7 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
int len = ce - c; int len = ce - c;
if (len < 1) return 0; if (len < 1) return 0;
DBG("ESC: '%s'", _safechar(c[0])); DBG("ESC: '%s'", termptyesc_safechar(c[0]));
switch (c[0]) switch (c[0])
{ {
case '[': case '[':
@ -4822,7 +4825,8 @@ _handle_esc(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
*/ */
default: default:
ty->decoding_error = EINA_TRUE; ty->decoding_error = EINA_TRUE;
WRN("Unhandled escape '%s' (0x%02x)", _safechar(c[0]), (unsigned int) c[0]); WRN("Unhandled escape '%s' (0x%02x)",
termptyesc_safechar(c[0]), (unsigned int) c[0]);
return 1; return 1;
} }
return 0; return 0;
@ -4942,7 +4946,7 @@ termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce)
while ((cc < ce) && (*cc >= 0x20) && (*cc != DEL) && (*cc != CSI) while ((cc < ce) && (*cc >= 0x20) && (*cc != DEL) && (*cc != CSI)
&& (*cc != OSC)) && (*cc != OSC))
{ {
DBG("%s", _safechar(*cc)); DBG("%s", termptyesc_safechar(*cc));
cc++; cc++;
len++; len++;
} }
@ -4961,7 +4965,7 @@ end:
if ((c[j] < ' ') || (c[j] >= 0x7f)) if ((c[j] < ' ') || (c[j] >= 0x7f))
printf("\033[35m%08x\033[0m", c[j]); printf("\033[35m%08x\033[0m", c[j]);
else else
printf("%s", _safechar(c[j])); printf("%s", termptyesc_safechar(c[j]));
} }
printf("\n"); printf("\n");
} }

View File

@ -2,5 +2,6 @@
#define _TERMPTY_ESC_H__ 1 #define _TERMPTY_ESC_H__ 1
int termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce); int termpty_handle_seq(Termpty *ty, const Eina_Unicode *c, const Eina_Unicode *ce);
const char * EINA_PURE termptyesc_safechar(const unsigned int c);
#endif #endif