From befb437411d7393dcbc5be438efb2642727f5dd5 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 4 Jul 2019 19:35:01 +0200 Subject: vt: improve logging of invalid and unimplemented sequences --- vt.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'vt.c') diff --git a/vt.c b/vt.c index 0c2cd1c7..8ef16bfb 100644 --- a/vt.c +++ b/vt.c @@ -552,19 +552,24 @@ static const enum action exit_actions[] = { [STATE_SOS_PM_APC_STRING] = ACTION_NONE, }; -static bool -esc_dispatch(struct terminal *term, uint8_t final) +static const char * +esc_as_string(struct terminal *term, uint8_t final) { -#if defined(_DEBUG) && defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG - char log[1024]; - int c = snprintf(log, sizeof(log), "ESC: "); + static char msg[1024]; + int c = snprintf(msg, sizeof(msg), "\E"); for (size_t i = 0; i < term->vt.intermediates.idx; i++) - c += snprintf(&log[c], sizeof(log) - c, "%c", term->vt.intermediates.data[i]); + c += snprintf(&msg[c], sizeof(msg) - c, "%c", term->vt.intermediates.data[i]); - c += snprintf(&log[c], sizeof(log) - c, "%c", final); - LOG_DBG("%s", log); -#endif + c += snprintf(&msg[c], sizeof(msg) - c, "%c", final); + return msg; + +} + +static bool +esc_dispatch(struct terminal *term, uint8_t final) +{ + LOG_DBG("ESC: %s", esc_as_string(term, final)); switch (final) { case '7': @@ -588,7 +593,7 @@ esc_dispatch(struct terminal *term, uint8_t final) case '+': term->charset[3] = CHARSET_ASCII; break; default: - LOG_ERR("%cB: invalid charset identifier", param); + LOG_ERR("%s: invalid charset identifier", esc_as_string(term, final)); return false; } break; @@ -605,7 +610,7 @@ esc_dispatch(struct terminal *term, uint8_t final) case '+': term->charset[3] = CHARSET_GRAPHIC; break; default: - LOG_ERR("%c0: invalid charset identifier", param); + LOG_ERR("%s: invalid charset identifier", esc_as_string(term, final)); return false; } break; @@ -627,7 +632,7 @@ esc_dispatch(struct terminal *term, uint8_t final) break; default: - LOG_ERR("ESC: unimplemented final: %c", final); + LOG_ERR("unimplemented: ESC: %s", esc_as_string(term, final)); return false; } -- cgit v1.3