From 56faca42660d65aefc440a223aef6b5f9628cfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 18:24:32 +0100 Subject: [PATCH 01/20] vt: use a switch instead of a top-level state lookup table Remove the top-level state lookup table, which mapped from a state enum to a state transition table, and replace it with a switch. --- vt.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/vt.c b/vt.c index 38ce9f5f..7adab9d9 100644 --- a/vt.c +++ b/vt.c @@ -515,6 +515,7 @@ static const struct state_transition state_sos_pm_apc_string[256] = { [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; +#if 0 static const struct state_transition* states[] = { [STATE_GROUND] = state_ground, [STATE_ESCAPE] = state_escape, @@ -531,6 +532,7 @@ static const struct state_transition* states[] = { [STATE_DCS_PASSTHROUGH] = state_dcs_passthrough, [STATE_SOS_PM_APC_STRING] = state_sos_pm_apc_string, }; +#endif static const enum action entry_actions[] = { [STATE_SAME] = ACTION_NONE, @@ -1075,7 +1077,30 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) continue; } - const struct state_transition *transition = &states[current_state][data[i]]; + const struct state_transition *table = NULL; + + switch (current_state) { + case STATE_GROUND: table = state_ground; break; + case STATE_ESCAPE: table = state_escape; break; + case STATE_ESCAPE_INTERMEDIATE: table = state_escape_intermediate; break; + case STATE_CSI_ENTRY: table = state_csi_entry; break; + case STATE_CSI_PARAM: table = state_csi_param; break; + case STATE_CSI_INTERMEDIATE: table = state_csi_intermediate; break; + case STATE_CSI_IGNORE: table = state_csi_ignore; break; + case STATE_OSC_STRING: table = state_osc_string; break; + case STATE_DCS_ENTRY: table = state_dcs_entry; break; + case STATE_DCS_PARAM: table = state_dcs_param; break; + case STATE_DCS_INTERMEDIATE: table = state_dcs_intermediate; break; + case STATE_DCS_IGNORE: table = state_dcs_ignore; break; + case STATE_DCS_PASSTHROUGH: table = state_dcs_passthrough; break; + case STATE_SOS_PM_APC_STRING: table = state_sos_pm_apc_string; break; + + case STATE_SAME: + case STATE_UTF8_COLLECT: assert(false); break; + } + + assert(table != NULL); + const struct state_transition *transition = &table[data[i]]; if (transition->state != STATE_SAME) { enum action exit_action = exit_actions[current_state]; From b2f091d243dd700c53a9d492e806628660cef301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 19:16:52 +0100 Subject: [PATCH 02/20] vt: replace GROUND, ESCAPE and ESCAPE_INTERMEDIATE tables with switches --- vt.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 115 insertions(+), 5 deletions(-) diff --git a/vt.c b/vt.c index 7adab9d9..b1a54af0 100644 --- a/vt.c +++ b/vt.c @@ -145,6 +145,7 @@ static const struct state_transition state_anywhere[256] = { }; #endif +#if 0 static const struct state_transition state_ground[256] = { [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, [0x19] = {.action = ACTION_EXECUTE}, @@ -228,6 +229,7 @@ static const struct state_transition state_escape_intermediate[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; +#endif static const struct state_transition state_csi_entry[256] = { [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, @@ -1062,12 +1064,120 @@ action(struct terminal *term, enum action _action, uint8_t c) } } +static enum state +state_ground_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* (no exit) current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + + case 0x20 ... 0x7f: action(term, ACTION_PRINT, data); return STATE_GROUND; + + case 0xc0 ... 0xdf: action(term, ACTION_UTF8_2_ENTRY, data); return STATE_UTF8_COLLECT; + case 0xe0 ... 0xef: action(term, ACTION_UTF8_3_ENTRY, data); return STATE_UTF8_COLLECT; + case 0xf0 ... 0xf7: action(term, ACTION_UTF8_4_ENTRY, data); return STATE_UTF8_COLLECT; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_GROUND; + } +} + +static enum state +state_escape_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* (no exit) current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_ESCAPE; + + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x4f: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x50: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x51 ... 0x57: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x58: return STATE_SOS_PM_APC_STRING; + case 0x59: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x5a: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x5b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x5c: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x5d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x5e ... 0x5f: return STATE_SOS_PM_APC_STRING; + case 0x60 ... 0x7e: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_ESCAPE; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_ESCAPE; + } +} + +static enum state +state_escape_intermediate_switch(struct terminal *term, uint8_t data) +{ + assert(false); + switch (data) { + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_ESCAPE_INTERMEDIATE; + + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x7e: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_ESCAPE_INTERMEDIATE; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_ESCAPE_INTERMEDIATE; + } +} + void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { //LOG_DBG("input: 0x%02x", data[i]); - enum state current_state = term->vt.state; - + enum state current_state = term->vt.state +; for (size_t i = 0; i < len; i++) { if (current_state == STATE_UTF8_COLLECT) { @@ -1080,9 +1190,9 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) const struct state_transition *table = NULL; switch (current_state) { - case STATE_GROUND: table = state_ground; break; - case STATE_ESCAPE: table = state_escape; break; - case STATE_ESCAPE_INTERMEDIATE: table = state_escape_intermediate; break; + case STATE_GROUND: term->vt.state = current_state = state_ground_switch(term, data[i]); continue; + case STATE_ESCAPE: term->vt.state = current_state = state_escape_switch(term, data[i]); continue; + case STATE_ESCAPE_INTERMEDIATE: term->vt.state = current_state = state_escape_intermediate_switch(term, data[i]); continue; case STATE_CSI_ENTRY: table = state_csi_entry; break; case STATE_CSI_PARAM: table = state_csi_param; break; case STATE_CSI_INTERMEDIATE: table = state_csi_intermediate; break; From a5f238b388c28e057ae4fdd8566c22ffc90b1eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 20:43:31 +0100 Subject: [PATCH 03/20] vt: re-align switches --- vt.c | 135 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/vt.c b/vt.c index b1a54af0..afabfb0f 100644 --- a/vt.c +++ b/vt.c @@ -1068,33 +1068,33 @@ static enum state state_ground_switch(struct terminal *term, uint8_t data) { switch (data) { - /* (no exit) current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x20 ... 0x7f: action(term, ACTION_PRINT, data); return STATE_GROUND; + case 0x20 ... 0x7f: action(term, ACTION_PRINT, data); return STATE_GROUND; - case 0xc0 ... 0xdf: action(term, ACTION_UTF8_2_ENTRY, data); return STATE_UTF8_COLLECT; - case 0xe0 ... 0xef: action(term, ACTION_UTF8_3_ENTRY, data); return STATE_UTF8_COLLECT; - case 0xf0 ... 0xf7: action(term, ACTION_UTF8_4_ENTRY, data); return STATE_UTF8_COLLECT; + case 0xc0 ... 0xdf: action(term, ACTION_UTF8_2_ENTRY, data); return STATE_UTF8_COLLECT; + case 0xe0 ... 0xef: action(term, ACTION_UTF8_3_ENTRY, data); return STATE_UTF8_COLLECT; + case 0xf0 ... 0xf7: action(term, ACTION_UTF8_4_ENTRY, data); return STATE_UTF8_COLLECT; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_GROUND; + default: return STATE_GROUND; } } @@ -1102,41 +1102,41 @@ static enum state state_escape_switch(struct terminal *term, uint8_t data) { switch (data) { - /* (no exit) current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_ESCAPE; + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_ESCAPE; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x4f: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x50: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x51 ... 0x57: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x58: return STATE_SOS_PM_APC_STRING; - case 0x59: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x5a: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x5b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; - case 0x5c: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x5d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; - case 0x5e ... 0x5f: return STATE_SOS_PM_APC_STRING; - case 0x60 ... 0x7e: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_ESCAPE; + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x4f: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x50: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x51 ... 0x57: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x58: return STATE_SOS_PM_APC_STRING; + case 0x59: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x5a: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x5b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x5c: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x5d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x5e ... 0x5f: return STATE_SOS_PM_APC_STRING; + case 0x60 ... 0x7e: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_ESCAPE; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_ESCAPE; + default: return STATE_ESCAPE; } } @@ -1145,30 +1145,31 @@ state_escape_intermediate_switch(struct terminal *term, uint8_t data) { assert(false); switch (data) { + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x7e: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x7e: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_ESCAPE_INTERMEDIATE; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_ESCAPE_INTERMEDIATE; + default: return STATE_ESCAPE_INTERMEDIATE; } } From b1fd960b4b29c2467a871b0790d086beccfc875f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 20:57:38 +0100 Subject: [PATCH 04/20] vt: convert CSI entry from table lookup to switch --- vt.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/vt.c b/vt.c index afabfb0f..655e375f 100644 --- a/vt.c +++ b/vt.c @@ -229,7 +229,6 @@ static const struct state_transition state_escape_intermediate[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; -#endif static const struct state_transition state_csi_entry[256] = { [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, @@ -257,6 +256,7 @@ static const struct state_transition state_csi_entry[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; +#endif static const struct state_transition state_csi_param[256] = { [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, @@ -1173,6 +1173,41 @@ state_escape_intermediate_switch(struct terminal *term, uint8_t data) } } +static enum state +state_csi_entry_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_CSI_ENTRY; + + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_CSI_INTERMEDIATE; + case 0x30 ... 0x39: action(term, ACTION_PARAM, data); return STATE_CSI_PARAM; + case 0x3a ... 0x3b: return STATE_CSI_PARAM; + case 0x3c ... 0x3f: action(term, ACTION_COLLECT, data); return STATE_CSI_PARAM; + case 0x40 ... 0x7e: action(term, ACTION_CSI_DISPATCH, data); return STATE_GROUND; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_CSI_ENTRY; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_CSI_ENTRY; + } +} + void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { @@ -1191,10 +1226,10 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) const struct state_transition *table = NULL; switch (current_state) { - case STATE_GROUND: term->vt.state = current_state = state_ground_switch(term, data[i]); continue; - case STATE_ESCAPE: term->vt.state = current_state = state_escape_switch(term, data[i]); continue; + case STATE_GROUND: term->vt.state = current_state = state_ground_switch(term, data[i]); continue; + case STATE_ESCAPE: term->vt.state = current_state = state_escape_switch(term, data[i]); continue; case STATE_ESCAPE_INTERMEDIATE: term->vt.state = current_state = state_escape_intermediate_switch(term, data[i]); continue; - case STATE_CSI_ENTRY: table = state_csi_entry; break; + case STATE_CSI_ENTRY: term->vt.state = current_state = state_csi_entry_switch(term, data[i]); continue; case STATE_CSI_PARAM: table = state_csi_param; break; case STATE_CSI_INTERMEDIATE: table = state_csi_intermediate; break; case STATE_CSI_IGNORE: table = state_csi_ignore; break; From 23a6c6b711e6120e838d7ca0c71743c1e151b46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 20:58:02 +0100 Subject: [PATCH 05/20] vt: add missing 'entry' actions to 'anywhere' sections --- vt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vt.c b/vt.c index 655e375f..7063be94 100644 --- a/vt.c +++ b/vt.c @@ -1124,7 +1124,7 @@ state_escape_switch(struct terminal *term, uint8_t data) /* Anywhere */ case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: return STATE_ESCAPE; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; @@ -1157,7 +1157,7 @@ state_escape_intermediate_switch(struct terminal *term, uint8_t data) /* Anywhere */ case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: return STATE_ESCAPE; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; From d325ae10ee8f027bb2b93e06da3a8dd9e85587fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 21:04:47 +0100 Subject: [PATCH 06/20] vt: convert CSI param from table lookup to switch --- vt.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/vt.c b/vt.c index 7063be94..dd598d94 100644 --- a/vt.c +++ b/vt.c @@ -256,7 +256,6 @@ static const struct state_transition state_csi_entry[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; -#endif static const struct state_transition state_csi_param[256] = { [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, @@ -284,6 +283,7 @@ static const struct state_transition state_csi_param[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; +#endif static const struct state_transition state_csi_intermediate[256] = { [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, @@ -1208,6 +1208,43 @@ state_csi_entry_switch(struct terminal *term, uint8_t data) } } +static enum state +state_csi_param_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_CSI_PARAM; + + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_CSI_INTERMEDIATE; + + case 0x30 ... 0x39: + case 0x3a ... 0x3b: action(term, ACTION_PARAM, data); return STATE_CSI_PARAM; + + case 0x3c ... 0x3f: return STATE_CSI_IGNORE; + case 0x40 ... 0x7e: action(term, ACTION_CSI_DISPATCH, data); return STATE_GROUND; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_CSI_PARAM; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_CSI_PARAM; + } +} + void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { @@ -1230,7 +1267,7 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) case STATE_ESCAPE: term->vt.state = current_state = state_escape_switch(term, data[i]); continue; case STATE_ESCAPE_INTERMEDIATE: term->vt.state = current_state = state_escape_intermediate_switch(term, data[i]); continue; case STATE_CSI_ENTRY: term->vt.state = current_state = state_csi_entry_switch(term, data[i]); continue; - case STATE_CSI_PARAM: table = state_csi_param; break; + case STATE_CSI_PARAM: term->vt.state = current_state = state_csi_param_switch(term, data[i]); continue; case STATE_CSI_INTERMEDIATE: table = state_csi_intermediate; break; case STATE_CSI_IGNORE: table = state_csi_ignore; break; case STATE_OSC_STRING: table = state_osc_string; break; From 0d6555bea9220aca8ddb498a9eab2f4765da8fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 21:09:00 +0100 Subject: [PATCH 07/20] vt: convert CSI intermediate from table lookup to switch --- vt.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/vt.c b/vt.c index dd598d94..8f5948ed 100644 --- a/vt.c +++ b/vt.c @@ -283,7 +283,6 @@ static const struct state_transition state_csi_param[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; -#endif static const struct state_transition state_csi_intermediate[256] = { [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, @@ -309,6 +308,7 @@ static const struct state_transition state_csi_intermediate[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; +#endif static const struct state_transition state_csi_ignore[256] = { [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, @@ -1245,6 +1245,39 @@ state_csi_param_switch(struct terminal *term, uint8_t data) } } +static enum state +state_csi_intermediate_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_CSI_INTERMEDIATE; + + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_CSI_INTERMEDIATE; + case 0x30 ... 0x3f: return STATE_CSI_IGNORE; + case 0x40 ... 0x7e: action(term, ACTION_CSI_DISPATCH, data); return STATE_GROUND; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_CSI_INTERMEDIATE; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_CSI_INTERMEDIATE; + } +} + void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { @@ -1268,7 +1301,7 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) case STATE_ESCAPE_INTERMEDIATE: term->vt.state = current_state = state_escape_intermediate_switch(term, data[i]); continue; case STATE_CSI_ENTRY: term->vt.state = current_state = state_csi_entry_switch(term, data[i]); continue; case STATE_CSI_PARAM: term->vt.state = current_state = state_csi_param_switch(term, data[i]); continue; - case STATE_CSI_INTERMEDIATE: table = state_csi_intermediate; break; + case STATE_CSI_INTERMEDIATE: term->vt.state = current_state = state_csi_intermediate_switch(term, data[i]); continue; case STATE_CSI_IGNORE: table = state_csi_ignore; break; case STATE_OSC_STRING: table = state_osc_string; break; case STATE_DCS_ENTRY: table = state_dcs_entry; break; From dca403e100a4e42c14f4a7e9dc2f52559b3adc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 21:13:06 +0100 Subject: [PATCH 08/20] vt: convert CSI ignore from table lookup to switch --- vt.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/vt.c b/vt.c index 8f5948ed..d9346aed 100644 --- a/vt.c +++ b/vt.c @@ -308,7 +308,6 @@ static const struct state_transition state_csi_intermediate[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; -#endif static const struct state_transition state_csi_ignore[256] = { [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, @@ -333,6 +332,7 @@ static const struct state_transition state_csi_ignore[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; +#endif static const struct state_transition state_osc_string[256] = { [0x00 ... 0x06] = {.action = ACTION_IGNORE}, @@ -1278,6 +1278,38 @@ state_csi_intermediate_switch(struct terminal *term, uint8_t data) } } +static enum state +state_csi_ignore_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_CSI_IGNORE; + + case 0x20 ... 0x3f: action(term, ACTION_IGNORE, data); return STATE_CSI_IGNORE; + case 0x40 ... 0x7e: return STATE_GROUND; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_CSI_IGNORE; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_CSI_IGNORE; + } +} + void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { @@ -1302,7 +1334,7 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) case STATE_CSI_ENTRY: term->vt.state = current_state = state_csi_entry_switch(term, data[i]); continue; case STATE_CSI_PARAM: term->vt.state = current_state = state_csi_param_switch(term, data[i]); continue; case STATE_CSI_INTERMEDIATE: term->vt.state = current_state = state_csi_intermediate_switch(term, data[i]); continue; - case STATE_CSI_IGNORE: table = state_csi_ignore; break; + case STATE_CSI_IGNORE: term->vt.state = current_state = state_csi_ignore_switch(term, data[i]); continue; case STATE_OSC_STRING: table = state_osc_string; break; case STATE_DCS_ENTRY: table = state_dcs_entry; break; case STATE_DCS_PARAM: table = state_dcs_param; break; From ad1773d7bc144c93ae44483e11560662fda8113d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 21:48:04 +0100 Subject: [PATCH 09/20] vt: convert DCS from table lookup to switch --- vt.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 195 insertions(+), 7 deletions(-) diff --git a/vt.c b/vt.c index d9346aed..da8a746d 100644 --- a/vt.c +++ b/vt.c @@ -332,7 +332,6 @@ static const struct state_transition state_csi_ignore[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; -#endif static const struct state_transition state_osc_string[256] = { [0x00 ... 0x06] = {.action = ACTION_IGNORE}, @@ -495,6 +494,7 @@ static const struct state_transition state_dcs_passthrough[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; +#endif static const struct state_transition state_sos_pm_apc_string[256] = { [0x00 ... 0x17] = {.action = ACTION_IGNORE}, @@ -1310,6 +1310,194 @@ state_csi_ignore_switch(struct terminal *term, uint8_t data) } } +static enum state +state_osc_string_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + + /* Note: original was 20-7f, but I changed to 20-ff to include utf-8. Don't forget to add EXECUTE to 8-bit C1 if we implement that. */ + default: action(term, ACTION_OSC_PUT, data); return STATE_OSC_STRING; + + case 0x07: action(term, ACTION_OSC_END, data); return STATE_GROUND; + + case 0x00 ... 0x06: + case 0x08 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_IGNORE, data); return STATE_OSC_STRING; + + + case 0x18: + case 0x1a: action(term, ACTION_OSC_END, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; + + case 0x1b: action(term, ACTION_OSC_END, data); action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + } +} + +static enum state +state_dcs_entry_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_IGNORE, data); return STATE_DCS_ENTRY; + + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action(term, ACTION_PARAM, data); return STATE_DCS_PARAM; + case 0x3a: return STATE_DCS_IGNORE; + case 0x3b: action(term, ACTION_PARAM, data); return STATE_DCS_PARAM; + case 0x3c ... 0x3f: action(term, ACTION_COLLECT, data); return STATE_DCS_PARAM; + case 0x40 ... 0x7e: action(term, ACTION_HOOK, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_ENTRY; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_DCS_ENTRY; + } +} + +static enum state +state_dcs_param_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_IGNORE, data); return STATE_DCS_PARAM; + + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action(term, ACTION_PARAM, data); return STATE_DCS_PARAM; + case 0x3a: return STATE_DCS_IGNORE; + case 0x3b: action(term, ACTION_PARAM, data); return STATE_DCS_PARAM; + case 0x3c ... 0x3f: return STATE_DCS_IGNORE; + case 0x40 ... 0x7e: action(term, ACTION_HOOK, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_PARAM; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_DCS_PARAM; + } +} + +static enum state +state_dcs_intermediate_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: action(term, ACTION_IGNORE, data); return STATE_DCS_INTERMEDIATE; + + case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x3f: return STATE_DCS_IGNORE; + case 0x40 ... 0x7e: action(term, ACTION_HOOK, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_INTERMEDIATE; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_DCS_INTERMEDIATE; + } +} + +static enum state +state_dcs_ignore_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x1f: + case 0x20 ... 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_IGNORE; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_DCS_IGNORE; + } +} + +static enum state +state_dcs_passthrough_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x7e: action(term, ACTION_PUT, data); return STATE_DCS_PASSTHROUGH; + + case 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_PASSTHROUGH; + + /* Anywhere */ + case 0x18: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_UNHOOK, data); action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_UNHOOK, data); action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: action(term, ACTION_UNHOOK, data); return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_UNHOOK, data); action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: action(term, ACTION_UNHOOK, data); return STATE_GROUND; + case 0x9d: action(term, ACTION_UNHOOK, data); action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: action(term, ACTION_UNHOOK, data); return STATE_SOS_PM_APC_STRING; + + default: return STATE_DCS_PASSTHROUGH; + } +} + void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { @@ -1335,12 +1523,12 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) case STATE_CSI_PARAM: term->vt.state = current_state = state_csi_param_switch(term, data[i]); continue; case STATE_CSI_INTERMEDIATE: term->vt.state = current_state = state_csi_intermediate_switch(term, data[i]); continue; case STATE_CSI_IGNORE: term->vt.state = current_state = state_csi_ignore_switch(term, data[i]); continue; - case STATE_OSC_STRING: table = state_osc_string; break; - case STATE_DCS_ENTRY: table = state_dcs_entry; break; - case STATE_DCS_PARAM: table = state_dcs_param; break; - case STATE_DCS_INTERMEDIATE: table = state_dcs_intermediate; break; - case STATE_DCS_IGNORE: table = state_dcs_ignore; break; - case STATE_DCS_PASSTHROUGH: table = state_dcs_passthrough; break; + case STATE_OSC_STRING: term->vt.state = current_state = state_osc_string_switch(term, data[i]); continue; + case STATE_DCS_ENTRY: term->vt.state = current_state = state_dcs_entry_switch(term, data[i]); continue; + case STATE_DCS_PARAM: term->vt.state = current_state = state_dcs_param_switch(term, data[i]); continue; + case STATE_DCS_INTERMEDIATE: term->vt.state = current_state = state_dcs_intermediate_switch(term, data[i]); continue; + case STATE_DCS_IGNORE: term->vt.state = current_state = state_dcs_ignore_switch(term, data[i]); continue; + case STATE_DCS_PASSTHROUGH: term->vt.state = current_state = state_dcs_passthrough_switch(term, data[i]); continue; case STATE_SOS_PM_APC_STRING: table = state_sos_pm_apc_string; break; case STATE_SAME: From 2d79497093e7975d5fc24fc63dfc46c09a3ad501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 21:50:54 +0100 Subject: [PATCH 10/20] vt: convert SOS/PM/APC string from table lookup to switch --- vt.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/vt.c b/vt.c index da8a746d..ed1ea4c1 100644 --- a/vt.c +++ b/vt.c @@ -494,7 +494,6 @@ static const struct state_transition state_dcs_passthrough[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; -#endif static const struct state_transition state_sos_pm_apc_string[256] = { [0x00 ... 0x17] = {.action = ACTION_IGNORE}, @@ -516,6 +515,7 @@ static const struct state_transition state_sos_pm_apc_string[256] = { [0x9d] = { .state = STATE_OSC_STRING}, [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, }; +#endif #if 0 static const struct state_transition* states[] = { @@ -1498,6 +1498,34 @@ state_dcs_passthrough_switch(struct terminal *term, uint8_t data) } } +static enum state +state_sos_pm_apc_string_switch(struct terminal *term, uint8_t data) +{ + switch (data) { + /* exit current enter new state */ + case 0x00 ... 0x17: + case 0x19: + case 0x1c ... 0x7f: action(term, ACTION_IGNORE, data); return STATE_SOS_PM_APC_STRING; + + /* Anywhere */ + case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + + default: return STATE_SOS_PM_APC_STRING; + } +} + void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { @@ -1529,7 +1557,7 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) case STATE_DCS_INTERMEDIATE: term->vt.state = current_state = state_dcs_intermediate_switch(term, data[i]); continue; case STATE_DCS_IGNORE: term->vt.state = current_state = state_dcs_ignore_switch(term, data[i]); continue; case STATE_DCS_PASSTHROUGH: term->vt.state = current_state = state_dcs_passthrough_switch(term, data[i]); continue; - case STATE_SOS_PM_APC_STRING: table = state_sos_pm_apc_string; break; + case STATE_SOS_PM_APC_STRING: term->vt.state = current_state = state_sos_pm_apc_string_switch(term, data[i]); continue; case STATE_SAME: case STATE_UTF8_COLLECT: assert(false); break; From d29de6f90a27a3f29d1ca0d01c26aa799c8aaa6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 22:10:27 +0100 Subject: [PATCH 11/20] vt: don't special case UTF-8 collect state --- vt.c | 79 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/vt.c b/vt.c index ed1ea4c1..c653f4a1 100644 --- a/vt.c +++ b/vt.c @@ -20,8 +20,6 @@ /* https://vt100.net/emu/dec_ansi_parser */ enum state { - STATE_SAME, /* For state_transition */ - STATE_GROUND, STATE_ESCAPE, STATE_ESCAPE_INTERMEDIATE, @@ -41,12 +39,12 @@ enum state { STATE_SOS_PM_APC_STRING, - STATE_UTF8_COLLECT, + STATE_UTF8_COLLECT_1, + STATE_UTF8_COLLECT_2, + STATE_UTF8_COLLECT_3, }; enum action { - ACTION_NONE, /* For state_transition */ - ACTION_IGNORE, ACTION_CLEAR, ACTION_EXECUTE, @@ -68,13 +66,11 @@ enum action { ACTION_UTF8_2_ENTRY, ACTION_UTF8_3_ENTRY, ACTION_UTF8_4_ENTRY, - ACTION_UTF8_COLLECT, ACTION_UTF8_PRINT, }; #if defined(_DEBUG) && defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG && 0 static const char *const state_names[] = { - [STATE_SAME] = "no change", [STATE_GROUND] = "ground", [STATE_ESCAPE] = "escape", @@ -95,11 +91,11 @@ static const char *const state_names[] = { [STATE_SOS_PM_APC_STRING] = "sos/pm/apc string", - [STATE_UTF8_COLLECT] = "UTF-8", + [STATE_UTF8_COLLECT_1] = "UTF8 collect (1 left)", + [STATE_UTF8_COLLECT_2] = "UTF8 collect (2 left)", + [STATE_UTF8_COLLECT_3] = "UTF8 collect (3 left)", }; -#endif static const char *const action_names[] __attribute__((unused)) = { - [ACTION_NONE] = "no action", [ACTION_IGNORE] = "ignore", [ACTION_CLEAR] = "clear", [ACTION_EXECUTE] = "execute", @@ -118,15 +114,16 @@ static const char *const action_names[] __attribute__((unused)) = { [ACTION_UTF8_2_ENTRY] = "UTF-8 (2 chars) begin", [ACTION_UTF8_3_ENTRY] = "UTF-8 (3 chars) begin", [ACTION_UTF8_4_ENTRY] = "UTF-8 (4 chars) begin", - [ACTION_UTF8_COLLECT] = "UTF-8 collect", [ACTION_UTF8_PRINT] = "UTF-8 print", }; +#endif +#if 0 struct state_transition { enum action action; enum state state; }; - +#endif #if 0 static const struct state_transition state_anywhere[256] = { [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, @@ -535,7 +532,7 @@ static const struct state_transition* states[] = { [STATE_SOS_PM_APC_STRING] = state_sos_pm_apc_string, }; #endif - +#if 0 static const enum action entry_actions[] = { [STATE_SAME] = ACTION_NONE, [STATE_GROUND] = ACTION_NONE, @@ -571,7 +568,7 @@ static const enum action exit_actions[] = { [STATE_DCS_PASSTHROUGH] = ACTION_UNHOOK, [STATE_SOS_PM_APC_STRING] = ACTION_NONE, }; - +#endif #if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG static const char * esc_as_string(struct terminal *term, uint8_t final) @@ -845,9 +842,6 @@ static void action(struct terminal *term, enum action _action, uint8_t c) { switch (_action) { - case ACTION_NONE: - break; - case ACTION_IGNORE: break; @@ -1054,6 +1048,7 @@ action(struct terminal *term, enum action _action, uint8_t c) term->vt.utf8.left--; break; +#if 0 case ACTION_UTF8_COLLECT: term->vt.utf8.data[term->vt.utf8.idx++] = c; if (--term->vt.utf8.left == 0) { @@ -1061,6 +1056,7 @@ action(struct terminal *term, enum action _action, uint8_t c) action_print_utf8(term); } break; +#endif } } @@ -1075,9 +1071,9 @@ state_ground_switch(struct terminal *term, uint8_t data) case 0x20 ... 0x7f: action(term, ACTION_PRINT, data); return STATE_GROUND; - case 0xc0 ... 0xdf: action(term, ACTION_UTF8_2_ENTRY, data); return STATE_UTF8_COLLECT; - case 0xe0 ... 0xef: action(term, ACTION_UTF8_3_ENTRY, data); return STATE_UTF8_COLLECT; - case 0xf0 ... 0xf7: action(term, ACTION_UTF8_4_ENTRY, data); return STATE_UTF8_COLLECT; + case 0xc0 ... 0xdf: action(term, ACTION_UTF8_2_ENTRY, data); return STATE_UTF8_COLLECT_1; + case 0xe0 ... 0xef: action(term, ACTION_UTF8_3_ENTRY, data); return STATE_UTF8_COLLECT_2; + case 0xf0 ... 0xf7: action(term, ACTION_UTF8_4_ENTRY, data); return STATE_UTF8_COLLECT_3; /* Anywhere */ case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; @@ -1526,6 +1522,37 @@ state_sos_pm_apc_string_switch(struct terminal *term, uint8_t data) } } +static enum state +state_utf8_collect_1_switch(struct terminal *term, uint8_t data) +{ + term->vt.utf8.data[term->vt.utf8.idx++] = data; + term->vt.utf8.left--; + + assert(term->vt.utf8.left == 0); + action(term, ACTION_UTF8_PRINT, data); + return STATE_GROUND; +} + +static enum state +state_utf8_collect_2_switch(struct terminal *term, uint8_t data) +{ + term->vt.utf8.data[term->vt.utf8.idx++] = data; + term->vt.utf8.left--; + + assert(term->vt.utf8.left == 1); + return STATE_UTF8_COLLECT_1; +} + +static enum state +state_utf8_collect_3_switch(struct terminal *term, uint8_t data) +{ + term->vt.utf8.data[term->vt.utf8.idx++] = data; + term->vt.utf8.left--; + + assert(term->vt.utf8.left == 2); + return STATE_UTF8_COLLECT_2; +} + void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { @@ -1533,15 +1560,15 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) enum state current_state = term->vt.state ; for (size_t i = 0; i < len; i++) { - +#if 0 if (current_state == STATE_UTF8_COLLECT) { action(term, ACTION_UTF8_COLLECT, data[i]); current_state = term->vt.state; continue; } - const struct state_transition *table = NULL; +#endif switch (current_state) { case STATE_GROUND: term->vt.state = current_state = state_ground_switch(term, data[i]); continue; @@ -1559,10 +1586,13 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) case STATE_DCS_PASSTHROUGH: term->vt.state = current_state = state_dcs_passthrough_switch(term, data[i]); continue; case STATE_SOS_PM_APC_STRING: term->vt.state = current_state = state_sos_pm_apc_string_switch(term, data[i]); continue; - case STATE_SAME: - case STATE_UTF8_COLLECT: assert(false); break; + case STATE_UTF8_COLLECT_1: term->vt.state = current_state = state_utf8_collect_1_switch(term, data[i]); continue; + case STATE_UTF8_COLLECT_2: term->vt.state = current_state = state_utf8_collect_2_switch(term, data[i]); continue; + case STATE_UTF8_COLLECT_3: term->vt.state = current_state = state_utf8_collect_3_switch(term, data[i]); continue; + } +#if 0 assert(table != NULL); const struct state_transition *transition = &table[data[i]]; @@ -1584,5 +1614,6 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) enum action entry_action = entry_actions[transition->state]; action(term, entry_action, data[i]); } +#endif } } From f36752f4d05c8c93a9e5c6585d3aabdfedb0c3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 22:11:35 +0100 Subject: [PATCH 12/20] vt: remove dead code --- vt.c | 495 ----------------------------------------------------------- 1 file changed, 495 deletions(-) diff --git a/vt.c b/vt.c index c653f4a1..ea2f6498 100644 --- a/vt.c +++ b/vt.c @@ -118,457 +118,6 @@ static const char *const action_names[] __attribute__((unused)) = { }; #endif -#if 0 -struct state_transition { - enum action action; - enum state state; -}; -#endif -#if 0 -static const struct state_transition state_anywhere[256] = { - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; -#endif - -#if 0 -static const struct state_transition state_ground[256] = { - [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, - [0x19] = {.action = ACTION_EXECUTE}, - [0x1c ... 0x1f] = {.action = ACTION_EXECUTE}, - [0x20 ... 0x7f] = {.action = ACTION_PRINT}, - - [0xc0 ... 0xdf] = {.action = ACTION_UTF8_2_ENTRY, .state = STATE_UTF8_COLLECT}, - [0xe0 ... 0xef] = {.action = ACTION_UTF8_3_ENTRY, .state = STATE_UTF8_COLLECT}, - [0xf0 ... 0xf7] = {.action = ACTION_UTF8_4_ENTRY, .state = STATE_UTF8_COLLECT}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_escape[256] = { - [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, - [0x19] = {.action = ACTION_EXECUTE}, - [0x1c ... 0x1f] = {.action = ACTION_EXECUTE}, - [0x20 ... 0x2f] = {.action = ACTION_COLLECT, .state = STATE_ESCAPE_INTERMEDIATE}, - [0x30 ... 0x4f] = {.action = ACTION_ESC_DISPATCH, .state = STATE_GROUND}, - [0x50] = { .state = STATE_DCS_ENTRY}, - [0x51 ... 0x57] = {.action = ACTION_ESC_DISPATCH, .state = STATE_GROUND}, - [0x58] = { .state = STATE_SOS_PM_APC_STRING}, - [0x59] = {.action = ACTION_ESC_DISPATCH, .state = STATE_GROUND}, - [0x5a] = {.action = ACTION_ESC_DISPATCH, .state = STATE_GROUND}, - [0x5b] = { .state = STATE_CSI_ENTRY}, - [0x5c] = {.action = ACTION_ESC_DISPATCH, .state = STATE_GROUND}, - [0x5d] = { .state = STATE_OSC_STRING}, - [0x5e ... 0x5f] = { .state = STATE_SOS_PM_APC_STRING}, - [0x60 ... 0x7e] = {.action = ACTION_ESC_DISPATCH, .state = STATE_GROUND}, - [0x7f] = {.action = ACTION_IGNORE}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_escape_intermediate[256] = { - [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, - [0x19] = {.action = ACTION_EXECUTE}, - [0x1c ... 0x1f] = {.action = ACTION_EXECUTE}, - [0x20 ... 0x2f] = {.action = ACTION_COLLECT}, - [0x30 ... 0x7e] = {.action = ACTION_ESC_DISPATCH, .state = STATE_GROUND}, - [0x7f] = {.action = ACTION_IGNORE}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_csi_entry[256] = { - [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, - [0x19] = {.action = ACTION_EXECUTE}, - [0x1c ... 0x1f] = {.action = ACTION_EXECUTE}, - [0x20 ... 0x2f] = {.action = ACTION_COLLECT, .state = STATE_CSI_INTERMEDIATE}, - [0x30 ... 0x39] = {.action = ACTION_PARAM, .state = STATE_CSI_PARAM}, - [0x3a ... 0x3b] = { .state = STATE_CSI_PARAM}, - [0x3c ... 0x3f] = {.action = ACTION_COLLECT, .state = STATE_CSI_PARAM}, - [0x40 ... 0x7e] = {.action = ACTION_CSI_DISPATCH, .state = STATE_GROUND}, - [0x7f] = {.action = ACTION_IGNORE}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_csi_param[256] = { - [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, - [0x19] = {.action = ACTION_EXECUTE}, - [0x1c ... 0x1f] = {.action = ACTION_EXECUTE}, - [0x20 ... 0x2f] = {.action = ACTION_COLLECT, .state = STATE_CSI_INTERMEDIATE}, - [0x30 ... 0x39] = {.action = ACTION_PARAM}, - [0x3a ... 0x3b] = {.action = ACTION_PARAM}, - [0x3c ... 0x3f] = { .state = STATE_CSI_IGNORE}, - [0x40 ... 0x7e] = {.action = ACTION_CSI_DISPATCH, .state = STATE_GROUND}, - [0x7f] = {.action = ACTION_IGNORE}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_csi_intermediate[256] = { - [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, - [0x19] = {.action = ACTION_EXECUTE}, - [0x1c ... 0x1f] = {.action = ACTION_EXECUTE}, - [0x20 ... 0x2f] = {.action = ACTION_COLLECT}, - [0x30 ... 0x3f] = { .state = STATE_CSI_IGNORE}, - [0x40 ... 0x7e] = {.action = ACTION_CSI_DISPATCH, .state = STATE_GROUND}, - [0x7f] = {.action = ACTION_IGNORE}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_csi_ignore[256] = { - [0x00 ... 0x17] = {.action = ACTION_EXECUTE}, - [0x19] = {.action = ACTION_EXECUTE}, - [0x1c ... 0x1f] = {.action = ACTION_EXECUTE}, - [0x20 ... 0x3f] = {.action = ACTION_IGNORE}, - [0x40 ... 0x7e] = { .state = STATE_GROUND}, - [0x7f] = {.action = ACTION_IGNORE}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_osc_string[256] = { - [0x00 ... 0x06] = {.action = ACTION_IGNORE}, - [0x07] = { .state = STATE_GROUND}, - [0x08 ... 0x17] = {.action = ACTION_IGNORE}, - [0x19] = {.action = ACTION_IGNORE}, - [0x1c ... 0x1f] = {.action = ACTION_IGNORE}, - - [0x20 ... 0xff] = {.action = ACTION_OSC_PUT}, - - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, -#if 0 - [0x20 ... 0x7f] = {.action = ACTION_OSC_PUT}, - [0x9c] = { .state = STATE_GROUND}, - - [0xc0 ... 0xdf] = {.action = ACTION_OSC_PUT}, - [0xe0 ... 0xef] = {.action = ACTION_OSC_PUT}, - [0xf0 ... 0xf7] = {.action = ACTION_OSC_PUT}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -#endif -}; - -static const struct state_transition state_dcs_entry[256] = { - [0x00 ... 0x17] = {.action = ACTION_IGNORE}, - [0x19] = {.action = ACTION_IGNORE}, - [0x1c ... 0x1f] = {.action = ACTION_IGNORE}, - [0x20 ... 0x2f] = {.action = ACTION_COLLECT, .state = STATE_DCS_INTERMEDIATE}, - [0x30 ... 0x39] = {.action = ACTION_PARAM, .state = STATE_DCS_PARAM}, - [0x3a] = { .state = STATE_DCS_IGNORE}, - [0x3b] = {.action = ACTION_PARAM, .state = STATE_DCS_PARAM}, - [0x3c ... 0x3f] = {.action = ACTION_COLLECT, .state = STATE_DCS_PARAM}, - [0x40 ... 0x7e] = { .state = STATE_DCS_PASSTHROUGH}, - [0x7f] = {.action = ACTION_IGNORE}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_dcs_param[256] = { - [0x00 ... 0x17] = {.action = ACTION_IGNORE}, - [0x19] = {.action = ACTION_IGNORE}, - [0x1c ... 0x1f] = {.action = ACTION_IGNORE}, - [0x20 ... 0x2f] = {.action = ACTION_COLLECT, .state = STATE_DCS_INTERMEDIATE}, - [0x30 ... 0x39] = {.action = ACTION_PARAM}, - [0x3a] = { .state = STATE_DCS_IGNORE}, - [0x3b] = {.action = ACTION_PARAM}, - [0x3c ... 0x3f] = { .state = STATE_DCS_IGNORE}, - [0x40 ... 0x7e] = { .state = STATE_DCS_PASSTHROUGH}, - [0x7f] = {.action = ACTION_IGNORE}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_dcs_intermediate[256] = { - [0x00 ... 0x17] = {.action = ACTION_IGNORE}, - [0x19] = {.action = ACTION_IGNORE}, - [0x1c ... 0x1f] = {.action = ACTION_IGNORE}, - [0x20 ... 0x2f] = {.action = ACTION_COLLECT}, - [0x30 ... 0x3f] = { .state = STATE_DCS_IGNORE}, - [0x40 ... 0x7e] = { .state = STATE_DCS_PASSTHROUGH}, - [0x7f] = {.action = ACTION_IGNORE}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9c] = { .state = STATE_GROUND}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_dcs_ignore[256] = { - [0x00 ... 0x17] = {.action = ACTION_IGNORE}, - [0x19] = {.action = ACTION_IGNORE}, - [0x1c ... 0x1f] = {.action = ACTION_IGNORE}, - [0x20 ... 0x7f] = {.action = ACTION_IGNORE}, - [0x9c] = { .state = STATE_GROUND}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_dcs_passthrough[256] = { - [0x00 ... 0x17] = {.action = ACTION_PUT}, - [0x19] = {.action = ACTION_PUT}, - [0x1c ... 0x7e] = {.action = ACTION_PUT}, - [0x7f] = {.action = ACTION_IGNORE}, - [0x9c] = { .state = STATE_GROUND}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; - -static const struct state_transition state_sos_pm_apc_string[256] = { - [0x00 ... 0x17] = {.action = ACTION_IGNORE}, - [0x19] = {.action = ACTION_IGNORE}, - [0x1c ... 0x7f] = {.action = ACTION_IGNORE}, - [0x9c] = { .state = STATE_GROUND}, - - /* Anywhere */ - [0x18] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x1b] = { .state = STATE_ESCAPE}, - [0x80 ... 0x8f] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x90] = { .state = STATE_DCS_ENTRY}, - [0x91 ... 0x97] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x98] = { .state = STATE_SOS_PM_APC_STRING}, - [0x99] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9a] = {.action = ACTION_EXECUTE, .state = STATE_GROUND}, - [0x9b] = { .state = STATE_CSI_ENTRY}, - [0x9d] = { .state = STATE_OSC_STRING}, - [0x9e ... 0x9f] = { .state = STATE_SOS_PM_APC_STRING}, -}; -#endif - -#if 0 -static const struct state_transition* states[] = { - [STATE_GROUND] = state_ground, - [STATE_ESCAPE] = state_escape, - [STATE_ESCAPE_INTERMEDIATE] = state_escape_intermediate, - [STATE_CSI_ENTRY] = state_csi_entry, - [STATE_CSI_PARAM] = state_csi_param, - [STATE_CSI_INTERMEDIATE] = state_csi_intermediate, - [STATE_CSI_IGNORE] = state_csi_ignore, - [STATE_OSC_STRING] = state_osc_string, - [STATE_DCS_ENTRY] = state_dcs_entry, - [STATE_DCS_PARAM] = state_dcs_param, - [STATE_DCS_INTERMEDIATE] = state_dcs_intermediate, - [STATE_DCS_IGNORE] = state_dcs_ignore, - [STATE_DCS_PASSTHROUGH] = state_dcs_passthrough, - [STATE_SOS_PM_APC_STRING] = state_sos_pm_apc_string, -}; -#endif -#if 0 -static const enum action entry_actions[] = { - [STATE_SAME] = ACTION_NONE, - [STATE_GROUND] = ACTION_NONE, - [STATE_ESCAPE] = ACTION_CLEAR, - [STATE_CSI_ENTRY] = ACTION_CLEAR, - [STATE_CSI_PARAM] = ACTION_NONE, - [STATE_CSI_INTERMEDIATE] = ACTION_NONE, - [STATE_CSI_IGNORE] = ACTION_NONE, - [STATE_OSC_STRING] = ACTION_OSC_START, - [STATE_UTF8_COLLECT] = ACTION_NONE, - [STATE_DCS_ENTRY] = ACTION_CLEAR, - [STATE_DCS_PARAM] = ACTION_NONE, - [STATE_DCS_INTERMEDIATE] = ACTION_NONE, - [STATE_DCS_IGNORE] = ACTION_NONE, - [STATE_DCS_PASSTHROUGH] = ACTION_HOOK, - [STATE_SOS_PM_APC_STRING] = ACTION_NONE, -}; - -static const enum action exit_actions[] = { - [STATE_SAME] = ACTION_NONE, - [STATE_GROUND] = ACTION_NONE, - [STATE_ESCAPE] = ACTION_NONE, - [STATE_CSI_ENTRY] = ACTION_NONE, - [STATE_CSI_PARAM] = ACTION_NONE, - [STATE_CSI_INTERMEDIATE] = ACTION_NONE, - [STATE_CSI_IGNORE] = ACTION_NONE, - [STATE_OSC_STRING] = ACTION_OSC_END, - [STATE_UTF8_COLLECT] = ACTION_NONE, - [STATE_DCS_ENTRY] = ACTION_NONE, - [STATE_DCS_PARAM] = ACTION_NONE, - [STATE_DCS_INTERMEDIATE] = ACTION_NONE, - [STATE_DCS_IGNORE] = ACTION_NONE, - [STATE_DCS_PASSTHROUGH] = ACTION_UNHOOK, - [STATE_SOS_PM_APC_STRING] = ACTION_NONE, -}; -#endif #if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG static const char * esc_as_string(struct terminal *term, uint8_t final) @@ -1047,16 +596,6 @@ action(struct terminal *term, enum action _action, uint8_t c) term->vt.utf8.data[term->vt.utf8.idx++] = c; term->vt.utf8.left--; break; - -#if 0 - case ACTION_UTF8_COLLECT: - term->vt.utf8.data[term->vt.utf8.idx++] = c; - if (--term->vt.utf8.left == 0) { - term->vt.state = STATE_GROUND; - action_print_utf8(term); - } - break; -#endif } } @@ -1560,16 +1099,6 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) enum state current_state = term->vt.state ; for (size_t i = 0; i < len; i++) { -#if 0 - if (current_state == STATE_UTF8_COLLECT) { - action(term, ACTION_UTF8_COLLECT, data[i]); - - current_state = term->vt.state; - continue; - } - const struct state_transition *table = NULL; -#endif - switch (current_state) { case STATE_GROUND: term->vt.state = current_state = state_ground_switch(term, data[i]); continue; case STATE_ESCAPE: term->vt.state = current_state = state_escape_switch(term, data[i]); continue; @@ -1591,29 +1120,5 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) case STATE_UTF8_COLLECT_3: term->vt.state = current_state = state_utf8_collect_3_switch(term, data[i]); continue; } - -#if 0 - assert(table != NULL); - const struct state_transition *transition = &table[data[i]]; - - if (transition->state != STATE_SAME) { - enum action exit_action = exit_actions[current_state]; - action(term, exit_action, data[i]); - } - - action(term, transition->action, data[i]); - - if (transition->state != STATE_SAME) { - /* - * LOG_DBG("transition: %s -> %s", state_names[current_state], - * state_names[transition->state]); - */ - term->vt.state = transition->state; - current_state = transition->state; - - enum action entry_action = entry_actions[transition->state]; - action(term, entry_action, data[i]); - } -#endif } } From ee8a9674c45d7e552f1f98beef4223312d86874d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 22:12:35 +0100 Subject: [PATCH 13/20] vt: no need to assign to term->vt.state for *every* input byte --- vt.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/vt.c b/vt.c index ea2f6498..84a20d44 100644 --- a/vt.c +++ b/vt.c @@ -1100,25 +1100,27 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) ; for (size_t i = 0; i < len; i++) { switch (current_state) { - case STATE_GROUND: term->vt.state = current_state = state_ground_switch(term, data[i]); continue; - case STATE_ESCAPE: term->vt.state = current_state = state_escape_switch(term, data[i]); continue; - case STATE_ESCAPE_INTERMEDIATE: term->vt.state = current_state = state_escape_intermediate_switch(term, data[i]); continue; - case STATE_CSI_ENTRY: term->vt.state = current_state = state_csi_entry_switch(term, data[i]); continue; - case STATE_CSI_PARAM: term->vt.state = current_state = state_csi_param_switch(term, data[i]); continue; - case STATE_CSI_INTERMEDIATE: term->vt.state = current_state = state_csi_intermediate_switch(term, data[i]); continue; - case STATE_CSI_IGNORE: term->vt.state = current_state = state_csi_ignore_switch(term, data[i]); continue; - case STATE_OSC_STRING: term->vt.state = current_state = state_osc_string_switch(term, data[i]); continue; - case STATE_DCS_ENTRY: term->vt.state = current_state = state_dcs_entry_switch(term, data[i]); continue; - case STATE_DCS_PARAM: term->vt.state = current_state = state_dcs_param_switch(term, data[i]); continue; - case STATE_DCS_INTERMEDIATE: term->vt.state = current_state = state_dcs_intermediate_switch(term, data[i]); continue; - case STATE_DCS_IGNORE: term->vt.state = current_state = state_dcs_ignore_switch(term, data[i]); continue; - case STATE_DCS_PASSTHROUGH: term->vt.state = current_state = state_dcs_passthrough_switch(term, data[i]); continue; - case STATE_SOS_PM_APC_STRING: term->vt.state = current_state = state_sos_pm_apc_string_switch(term, data[i]); continue; - - case STATE_UTF8_COLLECT_1: term->vt.state = current_state = state_utf8_collect_1_switch(term, data[i]); continue; - case STATE_UTF8_COLLECT_2: term->vt.state = current_state = state_utf8_collect_2_switch(term, data[i]); continue; - case STATE_UTF8_COLLECT_3: term->vt.state = current_state = state_utf8_collect_3_switch(term, data[i]); continue; + case STATE_GROUND: current_state = state_ground_switch(term, data[i]); continue; + case STATE_ESCAPE: current_state = state_escape_switch(term, data[i]); continue; + case STATE_ESCAPE_INTERMEDIATE: current_state = state_escape_intermediate_switch(term, data[i]); continue; + case STATE_CSI_ENTRY: current_state = state_csi_entry_switch(term, data[i]); continue; + case STATE_CSI_PARAM: current_state = state_csi_param_switch(term, data[i]); continue; + case STATE_CSI_INTERMEDIATE: current_state = state_csi_intermediate_switch(term, data[i]); continue; + case STATE_CSI_IGNORE: current_state = state_csi_ignore_switch(term, data[i]); continue; + case STATE_OSC_STRING: current_state = state_osc_string_switch(term, data[i]); continue; + case STATE_DCS_ENTRY: current_state = state_dcs_entry_switch(term, data[i]); continue; + case STATE_DCS_PARAM: current_state = state_dcs_param_switch(term, data[i]); continue; + case STATE_DCS_INTERMEDIATE: current_state = state_dcs_intermediate_switch(term, data[i]); continue; + case STATE_DCS_IGNORE: current_state = state_dcs_ignore_switch(term, data[i]); continue; + case STATE_DCS_PASSTHROUGH: current_state = state_dcs_passthrough_switch(term, data[i]); continue; + case STATE_SOS_PM_APC_STRING: current_state = state_sos_pm_apc_string_switch(term, data[i]); continue; + case STATE_UTF8_COLLECT_1: current_state = state_utf8_collect_1_switch(term, data[i]); continue; + case STATE_UTF8_COLLECT_2: current_state = state_utf8_collect_2_switch(term, data[i]); continue; + case STATE_UTF8_COLLECT_3: current_state = state_utf8_collect_3_switch(term, data[i]); continue; } } + + + term->vt.state = current_state; } From 914b96cc9a552dd020f27df1bd2ae7d073fd7b80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 22:13:23 +0100 Subject: [PATCH 14/20] vt: use break, not continue --- vt.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/vt.c b/vt.c index 84a20d44..387819fe 100644 --- a/vt.c +++ b/vt.c @@ -1100,24 +1100,24 @@ vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) ; for (size_t i = 0; i < len; i++) { switch (current_state) { - case STATE_GROUND: current_state = state_ground_switch(term, data[i]); continue; - case STATE_ESCAPE: current_state = state_escape_switch(term, data[i]); continue; - case STATE_ESCAPE_INTERMEDIATE: current_state = state_escape_intermediate_switch(term, data[i]); continue; - case STATE_CSI_ENTRY: current_state = state_csi_entry_switch(term, data[i]); continue; - case STATE_CSI_PARAM: current_state = state_csi_param_switch(term, data[i]); continue; - case STATE_CSI_INTERMEDIATE: current_state = state_csi_intermediate_switch(term, data[i]); continue; - case STATE_CSI_IGNORE: current_state = state_csi_ignore_switch(term, data[i]); continue; - case STATE_OSC_STRING: current_state = state_osc_string_switch(term, data[i]); continue; - case STATE_DCS_ENTRY: current_state = state_dcs_entry_switch(term, data[i]); continue; - case STATE_DCS_PARAM: current_state = state_dcs_param_switch(term, data[i]); continue; - case STATE_DCS_INTERMEDIATE: current_state = state_dcs_intermediate_switch(term, data[i]); continue; - case STATE_DCS_IGNORE: current_state = state_dcs_ignore_switch(term, data[i]); continue; - case STATE_DCS_PASSTHROUGH: current_state = state_dcs_passthrough_switch(term, data[i]); continue; - case STATE_SOS_PM_APC_STRING: current_state = state_sos_pm_apc_string_switch(term, data[i]); continue; + case STATE_GROUND: current_state = state_ground_switch(term, data[i]); break; + case STATE_ESCAPE: current_state = state_escape_switch(term, data[i]); break; + case STATE_ESCAPE_INTERMEDIATE: current_state = state_escape_intermediate_switch(term, data[i]); break; + case STATE_CSI_ENTRY: current_state = state_csi_entry_switch(term, data[i]); break; + case STATE_CSI_PARAM: current_state = state_csi_param_switch(term, data[i]); break; + case STATE_CSI_INTERMEDIATE: current_state = state_csi_intermediate_switch(term, data[i]); break; + case STATE_CSI_IGNORE: current_state = state_csi_ignore_switch(term, data[i]); break; + case STATE_OSC_STRING: current_state = state_osc_string_switch(term, data[i]); break; + case STATE_DCS_ENTRY: current_state = state_dcs_entry_switch(term, data[i]); break; + case STATE_DCS_PARAM: current_state = state_dcs_param_switch(term, data[i]); break; + case STATE_DCS_INTERMEDIATE: current_state = state_dcs_intermediate_switch(term, data[i]); break; + case STATE_DCS_IGNORE: current_state = state_dcs_ignore_switch(term, data[i]); break; + case STATE_DCS_PASSTHROUGH: current_state = state_dcs_passthrough_switch(term, data[i]); break; + case STATE_SOS_PM_APC_STRING: current_state = state_sos_pm_apc_string_switch(term, data[i]); break; - case STATE_UTF8_COLLECT_1: current_state = state_utf8_collect_1_switch(term, data[i]); continue; - case STATE_UTF8_COLLECT_2: current_state = state_utf8_collect_2_switch(term, data[i]); continue; - case STATE_UTF8_COLLECT_3: current_state = state_utf8_collect_3_switch(term, data[i]); continue; + case STATE_UTF8_COLLECT_1: current_state = state_utf8_collect_1_switch(term, data[i]); break; + case STATE_UTF8_COLLECT_2: current_state = state_utf8_collect_2_switch(term, data[i]); break; + case STATE_UTF8_COLLECT_3: current_state = state_utf8_collect_3_switch(term, data[i]); break; } } From 9ad9e4ccaf1678aa3e77d14f477e0627de7b4aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 23:00:07 +0100 Subject: [PATCH 15/20] vt: use a pointer that we increment, instead of indexing --- vt.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/vt.c b/vt.c index 387819fe..66cdc302 100644 --- a/vt.c +++ b/vt.c @@ -1095,29 +1095,29 @@ state_utf8_collect_3_switch(struct terminal *term, uint8_t data) void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { - //LOG_DBG("input: 0x%02x", data[i]); - enum state current_state = term->vt.state -; - for (size_t i = 0; i < len; i++) { - switch (current_state) { - case STATE_GROUND: current_state = state_ground_switch(term, data[i]); break; - case STATE_ESCAPE: current_state = state_escape_switch(term, data[i]); break; - case STATE_ESCAPE_INTERMEDIATE: current_state = state_escape_intermediate_switch(term, data[i]); break; - case STATE_CSI_ENTRY: current_state = state_csi_entry_switch(term, data[i]); break; - case STATE_CSI_PARAM: current_state = state_csi_param_switch(term, data[i]); break; - case STATE_CSI_INTERMEDIATE: current_state = state_csi_intermediate_switch(term, data[i]); break; - case STATE_CSI_IGNORE: current_state = state_csi_ignore_switch(term, data[i]); break; - case STATE_OSC_STRING: current_state = state_osc_string_switch(term, data[i]); break; - case STATE_DCS_ENTRY: current_state = state_dcs_entry_switch(term, data[i]); break; - case STATE_DCS_PARAM: current_state = state_dcs_param_switch(term, data[i]); break; - case STATE_DCS_INTERMEDIATE: current_state = state_dcs_intermediate_switch(term, data[i]); break; - case STATE_DCS_IGNORE: current_state = state_dcs_ignore_switch(term, data[i]); break; - case STATE_DCS_PASSTHROUGH: current_state = state_dcs_passthrough_switch(term, data[i]); break; - case STATE_SOS_PM_APC_STRING: current_state = state_sos_pm_apc_string_switch(term, data[i]); break; + enum state current_state = term->vt.state; - case STATE_UTF8_COLLECT_1: current_state = state_utf8_collect_1_switch(term, data[i]); break; - case STATE_UTF8_COLLECT_2: current_state = state_utf8_collect_2_switch(term, data[i]); break; - case STATE_UTF8_COLLECT_3: current_state = state_utf8_collect_3_switch(term, data[i]); break; + const uint8_t *p = data; + for (size_t i = 0; i < len; i++, p++) { + switch (current_state) { + case STATE_GROUND: current_state = state_ground_switch(term, *p); break; + case STATE_ESCAPE: current_state = state_escape_switch(term, *p); break; + case STATE_ESCAPE_INTERMEDIATE: current_state = state_escape_intermediate_switch(term, *p); break; + case STATE_CSI_ENTRY: current_state = state_csi_entry_switch(term, *p); break; + case STATE_CSI_PARAM: current_state = state_csi_param_switch(term, *p); break; + case STATE_CSI_INTERMEDIATE: current_state = state_csi_intermediate_switch(term, *p); break; + case STATE_CSI_IGNORE: current_state = state_csi_ignore_switch(term, *p); break; + case STATE_OSC_STRING: current_state = state_osc_string_switch(term, *p); break; + case STATE_DCS_ENTRY: current_state = state_dcs_entry_switch(term, *p); break; + case STATE_DCS_PARAM: current_state = state_dcs_param_switch(term, *p); break; + case STATE_DCS_INTERMEDIATE: current_state = state_dcs_intermediate_switch(term, *p); break; + case STATE_DCS_IGNORE: current_state = state_dcs_ignore_switch(term, *p); break; + case STATE_DCS_PASSTHROUGH: current_state = state_dcs_passthrough_switch(term, *p); break; + case STATE_SOS_PM_APC_STRING: current_state = state_sos_pm_apc_string_switch(term, *p); break; + + case STATE_UTF8_COLLECT_1: current_state = state_utf8_collect_1_switch(term, *p); break; + case STATE_UTF8_COLLECT_2: current_state = state_utf8_collect_2_switch(term, *p); break; + case STATE_UTF8_COLLECT_3: current_state = state_utf8_collect_3_switch(term, *p); break; } } From 032f478661cb69e99debe7fc486db1cf54c3d4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 23:26:18 +0100 Subject: [PATCH 16/20] vt: remove debug assert --- vt.c | 1 - 1 file changed, 1 deletion(-) diff --git a/vt.c b/vt.c index 66cdc302..cb76ec65 100644 --- a/vt.c +++ b/vt.c @@ -678,7 +678,6 @@ state_escape_switch(struct terminal *term, uint8_t data) static enum state state_escape_intermediate_switch(struct terminal *term, uint8_t data) { - assert(false); switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: From 5a0e27fd6cbb80c3163a1c58cc3e91d1fed84b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 23:27:15 +0100 Subject: [PATCH 17/20] vt: remove enum action; add separate functions for each action instead --- vt.c | 1037 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 502 insertions(+), 535 deletions(-) diff --git a/vt.c b/vt.c index cb76ec65..7f57f902 100644 --- a/vt.c +++ b/vt.c @@ -44,31 +44,6 @@ enum state { STATE_UTF8_COLLECT_3, }; -enum action { - ACTION_IGNORE, - ACTION_CLEAR, - ACTION_EXECUTE, - ACTION_PRINT, - ACTION_PARAM, - ACTION_COLLECT, - - ACTION_ESC_DISPATCH, - ACTION_CSI_DISPATCH, - - ACTION_OSC_START, - ACTION_OSC_END, - ACTION_OSC_PUT, - - ACTION_HOOK, - ACTION_UNHOOK, - ACTION_PUT, - - ACTION_UTF8_2_ENTRY, - ACTION_UTF8_3_ENTRY, - ACTION_UTF8_4_ENTRY, - ACTION_UTF8_PRINT, -}; - #if defined(_DEBUG) && defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG && 0 static const char *const state_names[] = { [STATE_GROUND] = "ground", @@ -95,27 +70,6 @@ static const char *const state_names[] = { [STATE_UTF8_COLLECT_2] = "UTF8 collect (2 left)", [STATE_UTF8_COLLECT_3] = "UTF8 collect (3 left)", }; -static const char *const action_names[] __attribute__((unused)) = { - [ACTION_IGNORE] = "ignore", - [ACTION_CLEAR] = "clear", - [ACTION_EXECUTE] = "execute", - [ACTION_PRINT] = "print", - [ACTION_PARAM] = "param", - [ACTION_COLLECT] = "collect", - [ACTION_ESC_DISPATCH] = "ESC dispatch", - [ACTION_CSI_DISPATCH] = "CSI dispatch", - [ACTION_OSC_START] = "OSC start", - [ACTION_OSC_END] = "OSC end", - [ACTION_OSC_PUT] = "OSC put", - [ACTION_HOOK] = "hook", - [ACTION_UNHOOK] = "unhook", - [ACTION_PUT] = "put", - - [ACTION_UTF8_2_ENTRY] = "UTF-8 (2 chars) begin", - [ACTION_UTF8_3_ENTRY] = "UTF-8 (3 chars) begin", - [ACTION_UTF8_4_ENTRY] = "UTF-8 (4 chars) begin", - [ACTION_UTF8_PRINT] = "UTF-8 print", -}; #endif #if defined(LOG_ENABLE_DBG) && LOG_ENABLE_DBG @@ -139,8 +93,239 @@ esc_as_string(struct terminal *term, uint8_t final) } #endif +static inline void +pre_print(struct terminal *term) +{ + if (likely(!term->cursor.lcf)) + return; + if (unlikely(!term->auto_margin)) + return; + + if (term->cursor.point.row == term->scroll_region.end - 1) { + term_scroll(term, 1); + term_cursor_to(term, term->cursor.point.row, 0); + } else + term_cursor_to(term, min(term->cursor.point.row + 1, term->rows - 1), 0); +} + +static inline void +post_print(struct terminal *term) +{ + if (term->cursor.point.col < term->cols - 1) + term_cursor_right(term, 1); + else + term->cursor.lcf = true; +} + +static inline void +print_insert(struct terminal *term, int width) +{ + assert(width > 0); + if (unlikely(term->insert_mode)) { + struct row *row = term->grid->cur_row; + const size_t move_count = max(0, term->cols - term->cursor.point.col - width); + + memmove( + &row->cells[term->cursor.point.col + width], + &row->cells[term->cursor.point.col], + move_count * sizeof(struct cell)); + + /* Mark moved cells as dirty */ + for (size_t i = term->cursor.point.col + width; i < term->cols; i++) + row->cells[i].attrs.clean = 0; + } +} + static void -esc_dispatch(struct terminal *term, uint8_t final) +action_ignore(struct terminal *term) +{ +} + +static void +action_clear(struct terminal *term) +{ + term->vt.params.idx = 0; + term->vt.private[0] = 0; + term->vt.private[1] = 0; + term->vt.utf8.idx = 0; +} + +static void +action_execute(struct terminal *term, uint8_t c) +{ + LOG_DBG("execute: 0x%02x", c); + switch (c) { + + /* + * 7-bit C0 control characters + */ + + case '\0': + break; + + case '\n': + /* LF - line feed */ + term_linefeed(term); + break; + + case '\r': + /* FF - form feed */ + term_cursor_left(term, term->cursor.point.col); + break; + + case '\b': + /* backspace */ + term_cursor_left(term, 1); + break; + + case '\x07': + /* BEL */ + // LOG_INFO("BELL"); + // term_flash(term, 50); + break; + + case '\x09': { + /* HT - horizontal tab */ + int new_col = term->cols - 1; + tll_foreach(term->tab_stops, it) { + if (it->item > term->cursor.point.col) { + new_col = it->item; + break; + } + } + assert(new_col >= term->cursor.point.col); + term_cursor_right(term, new_col - term->cursor.point.col); + break; + } + + case '\x0b': + /* VT - vertical tab */ + term_cursor_down(term, 1); + break; + + case '\x0e': + /* SO - shift out */ + term->charsets.selected = 1; /* G1 */ + break; + + case '\x0f': + /* SI - shift in */ + term->charsets.selected = 0; /* G0 */ + break; + + /* + * 8-bit C1 control characters + * + * We ignore these, but keep them here for reference, along + * with their corresponding 7-bit variants. + * + * As far as I can tell, XTerm also ignores these _when in + * UTF-8 mode_. Which would be the normal mode of operation + * these days. And since we _only_ support UTF-8... + */ +#if 0 + case '\x84': /* IND -> ESC D */ + case '\x85': /* NEL -> ESC E */ + case '\x88': /* Tab Set -> ESC H */ + case '\x8d': /* RI -> ESC M */ + case '\x8e': /* SS2 -> ESC N */ + case '\x8f': /* SS3 -> ESC O */ + case '\x90': /* DCS -> ESC P */ + case '\x96': /* SPA -> ESC V */ + case '\x97': /* EPA -> ESC W */ + case '\x98': /* SOS -> ESC X */ + case '\x9a': /* DECID -> ESC Z (obsolete form of CSI c) */ + case '\x9b': /* CSI -> ESC [ */ + case '\x9c': /* ST -> ESC \ */ + case '\x9d': /* OSC -> ESC ] */ + case '\x9e': /* PM -> ESC ^ */ + case '\x9f': /* APC -> ESC _ */ + break; +#endif + + default: + break; + } +} + +static void +action_print(struct terminal *term, uint8_t c) +{ + pre_print(term); + + struct row *row = term->grid->cur_row; + struct cell *cell = &row->cells[term->cursor.point.col]; + + row->dirty = true; + cell->attrs.clean = 0; + + print_insert(term, 1); + + /* 0x60 - 0x7e */ + static const wchar_t vt100_0[] = { + L'◆', L'▒', L'␉', L'␌', L'␍', L'␊', L'°', L'±', /* ` - g */ + L'␤', L'␋', L'┘', L'┐', L'┌', L'└', L'┼', L'⎺', /* h - o */ + L'⎻', L'─', L'⎼', L'⎽', L'├', L'┤', L'┴', L'┬', /* p - w */ + L'│', L'≤', L'≥', L'π', L'≠', L'£', L'·', /* x - ~ */ + }; + + if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) && + c >= 0x60 && c <= 0x7e) + { + cell->wc = vt100_0[c - 0x60]; + } else { + // LOG_DBG("print: ASCII: %c (0x%04x)", c, c); + cell->wc = c; + } + + cell->attrs = term->vt.attrs; + post_print(term); +} + +static void +action_param(struct terminal *term, uint8_t c) +{ + if (term->vt.params.idx == 0) { + struct vt_param *param = &term->vt.params.v[0]; + param->value = 0; + param->sub.idx = 0; + term->vt.params.idx = 1; + } + + if (c == ';') { + struct vt_param *param = &term->vt.params.v[term->vt.params.idx++]; + param->value = 0; + param->sub.idx = 0; + } else if (c == ':') { + struct vt_param *param = &term->vt.params.v[term->vt.params.idx - 1]; + param->sub.value[param->sub.idx++] = 0; + } else { + assert(term->vt.params.idx >= 0); + struct vt_param *param = &term->vt.params.v[term->vt.params.idx - 1]; + + unsigned *value = param->sub.idx > 0 + ? ¶m->sub.value[param->sub.idx - 1] + : ¶m->value; + + *value *= 10; + *value += c - '0'; + } +} + +static void +action_collect(struct terminal *term, uint8_t c) +{ + LOG_DBG("collect"); + if (term->vt.private[0] == 0) + term->vt.private[0] = c; + else if (term->vt.private[1] == 0) + term->vt.private[1] = c; + else + LOG_DBG("only two private/intermediate characters supported"); +} + +static void +action_esc_dispatch(struct terminal *term, uint8_t final) { LOG_DBG("ESC: %s", esc_as_string(term, final)); @@ -265,51 +450,79 @@ esc_dispatch(struct terminal *term, uint8_t final) } } -static inline void -pre_print(struct terminal *term) +static void +action_csi_dispatch(struct terminal *term, uint8_t c) { - if (likely(!term->cursor.lcf)) - return; - if (unlikely(!term->auto_margin)) - return; - - if (term->cursor.point.row == term->scroll_region.end - 1) { - term_scroll(term, 1); - term_cursor_to(term, term->cursor.point.row, 0); - } else - term_cursor_to(term, min(term->cursor.point.row + 1, term->rows - 1), 0); -} - -static inline void -post_print(struct terminal *term) -{ - if (term->cursor.point.col < term->cols - 1) - term_cursor_right(term, 1); - else - term->cursor.lcf = true; -} - -static inline void -print_insert(struct terminal *term, int width) -{ - assert(width > 0); - if (unlikely(term->insert_mode)) { - struct row *row = term->grid->cur_row; - const size_t move_count = max(0, term->cols - term->cursor.point.col - width); - - memmove( - &row->cells[term->cursor.point.col + width], - &row->cells[term->cursor.point.col], - move_count * sizeof(struct cell)); - - /* Mark moved cells as dirty */ - for (size_t i = term->cursor.point.col + width; i < term->cols; i++) - row->cells[i].attrs.clean = 0; - } + csi_dispatch(term, c); } static void -action_print_utf8(struct terminal *term) +action_osc_start(struct terminal *term, uint8_t c) +{ + term->vt.osc.idx = 0; +} + +static void +action_osc_end(struct terminal *term, uint8_t c) +{ + if (!osc_ensure_size(term, term->vt.osc.idx + 1)) + return; + term->vt.osc.data[term->vt.osc.idx] = '\0'; + osc_dispatch(term); +} + +static void +action_osc_put(struct terminal *term, uint8_t c) +{ + if (!osc_ensure_size(term, term->vt.osc.idx + 1)) + return; + term->vt.osc.data[term->vt.osc.idx++] = c; +} + +static void +action_hook(struct terminal *term, uint8_t c) +{ +} + +static void +action_unhook(struct terminal *term, uint8_t c) +{ +} + +static void +action_put(struct terminal *term, uint8_t c) +{ +} + +static void +action_utf8_2_entry(struct terminal *term, uint8_t c) +{ + term->vt.utf8.idx = 0; + term->vt.utf8.left = 2; + term->vt.utf8.data[term->vt.utf8.idx++] = c; + term->vt.utf8.left--; +} + +static void +action_utf8_3_entry(struct terminal *term, uint8_t c) +{ + term->vt.utf8.idx = 0; + term->vt.utf8.left = 3; + term->vt.utf8.data[term->vt.utf8.idx++] = c; + term->vt.utf8.left--; +} + +static void +action_utf8_4_entry(struct terminal *term, uint8_t c) +{ + term->vt.utf8.idx = 0; + term->vt.utf8.left = 4; + term->vt.utf8.data[term->vt.utf8.idx++] = c; + term->vt.utf8.left--; +} + +static void +action_utf8_print(struct terminal *term, uint8_t c) { pre_print(term); @@ -353,252 +566,6 @@ action_print_utf8(struct terminal *term) post_print(term); } -static void -action_print(struct terminal *term, uint8_t c) -{ - pre_print(term); - - struct row *row = term->grid->cur_row; - struct cell *cell = &row->cells[term->cursor.point.col]; - - row->dirty = true; - cell->attrs.clean = 0; - - print_insert(term, 1); - - /* 0x60 - 0x7e */ - static const wchar_t vt100_0[] = { - L'◆', L'▒', L'␉', L'␌', L'␍', L'␊', L'°', L'±', /* ` - g */ - L'␤', L'␋', L'┘', L'┐', L'┌', L'└', L'┼', L'⎺', /* h - o */ - L'⎻', L'─', L'⎼', L'⎽', L'├', L'┤', L'┴', L'┬', /* p - w */ - L'│', L'≤', L'≥', L'π', L'≠', L'£', L'·', /* x - ~ */ - }; - - if (unlikely(term->charsets.set[term->charsets.selected] == CHARSET_GRAPHIC) && - c >= 0x60 && c <= 0x7e) - { - cell->wc = vt100_0[c - 0x60]; - } else { - // LOG_DBG("print: ASCII: %c (0x%04x)", c, c); - cell->wc = c; - } - - cell->attrs = term->vt.attrs; - post_print(term); -} - -static void -action(struct terminal *term, enum action _action, uint8_t c) -{ - switch (_action) { - case ACTION_IGNORE: - break; - - case ACTION_EXECUTE: - LOG_DBG("execute: 0x%02x", c); - switch (c) { - - /* - * 7-bit C0 control characters - */ - - case '\0': - break; - - case '\n': - /* LF - line feed */ - term_linefeed(term); - break; - - case '\r': - /* FF - form feed */ - term_cursor_left(term, term->cursor.point.col); - break; - - case '\b': - /* backspace */ - term_cursor_left(term, 1); - break; - - case '\x07': - /* BEL */ - // LOG_INFO("BELL"); - // term_flash(term, 50); - break; - - case '\x09': { - /* HT - horizontal tab */ - int new_col = term->cols - 1; - tll_foreach(term->tab_stops, it) { - if (it->item > term->cursor.point.col) { - new_col = it->item; - break; - } - } - assert(new_col >= term->cursor.point.col); - term_cursor_right(term, new_col - term->cursor.point.col); - break; - } - - case '\x0b': - /* VT - vertical tab */ - term_cursor_down(term, 1); - break; - - case '\x0e': - /* SO - shift out */ - term->charsets.selected = 1; /* G1 */ - break; - - case '\x0f': - /* SI - shift in */ - term->charsets.selected = 0; /* G0 */ - break; - - /* - * 8-bit C1 control characters - * - * We ignore these, but keep them here for reference, along - * with their corresponding 7-bit variants. - * - * As far as I can tell, XTerm also ignores these _when in - * UTF-8 mode_. Which would be the normal mode of operation - * these days. And since we _only_ support UTF-8... - */ -#if 0 - case '\x84': /* IND -> ESC D */ - case '\x85': /* NEL -> ESC E */ - case '\x88': /* Tab Set -> ESC H */ - case '\x8d': /* RI -> ESC M */ - case '\x8e': /* SS2 -> ESC N */ - case '\x8f': /* SS3 -> ESC O */ - case '\x90': /* DCS -> ESC P */ - case '\x96': /* SPA -> ESC V */ - case '\x97': /* EPA -> ESC W */ - case '\x98': /* SOS -> ESC X */ - case '\x9a': /* DECID -> ESC Z (obsolete form of CSI c) */ - case '\x9b': /* CSI -> ESC [ */ - case '\x9c': /* ST -> ESC \ */ - case '\x9d': /* OSC -> ESC ] */ - case '\x9e': /* PM -> ESC ^ */ - case '\x9f': /* APC -> ESC _ */ - break; -#endif - - default: - break; - } - - break; - - case ACTION_CLEAR: - term->vt.params.idx = 0; - term->vt.private[0] = 0; - term->vt.private[1] = 0; - term->vt.utf8.idx = 0; - break; - - case ACTION_PRINT: - action_print(term, c); - break; - - case ACTION_UTF8_PRINT: - action_print_utf8(term); - break; - - case ACTION_PARAM: - if (term->vt.params.idx == 0) { - struct vt_param *param = &term->vt.params.v[0]; - param->value = 0; - param->sub.idx = 0; - term->vt.params.idx = 1; - } - - if (c == ';') { - struct vt_param *param = &term->vt.params.v[term->vt.params.idx++]; - param->value = 0; - param->sub.idx = 0; - } else if (c == ':') { - struct vt_param *param = &term->vt.params.v[term->vt.params.idx - 1]; - param->sub.value[param->sub.idx++] = 0; - } else { - assert(term->vt.params.idx >= 0); - struct vt_param *param = &term->vt.params.v[term->vt.params.idx - 1]; - - unsigned *value = param->sub.idx > 0 - ? ¶m->sub.value[param->sub.idx - 1] - : ¶m->value; - - *value *= 10; - *value += c - '0'; - } - break; - - case ACTION_COLLECT: - LOG_DBG("collect"); - if (term->vt.private[0] == 0) - term->vt.private[0] = c; - else if (term->vt.private[1] == 0) - term->vt.private[1] = c; - else - LOG_DBG("only two private/intermediate characters supported"); - break; - - case ACTION_ESC_DISPATCH: - esc_dispatch(term, c); - break; - - case ACTION_CSI_DISPATCH: - csi_dispatch(term, c); - break; - - case ACTION_OSC_START: - term->vt.osc.idx = 0; - break; - - case ACTION_OSC_PUT: - if (!osc_ensure_size(term, term->vt.osc.idx + 1)) - break; - - term->vt.osc.data[term->vt.osc.idx++] = c; - break; - - case ACTION_OSC_END: - if (!osc_ensure_size(term, term->vt.osc.idx + 1)) - break; - term->vt.osc.data[term->vt.osc.idx] = '\0'; - osc_dispatch(term); - break; - - case ACTION_HOOK: - case ACTION_PUT: - case ACTION_UNHOOK: - /* We have no parent terminal to pass through to */ - break; - - case ACTION_UTF8_2_ENTRY: - term->vt.utf8.idx = 0; - term->vt.utf8.left = 2; - term->vt.utf8.data[term->vt.utf8.idx++] = c; - term->vt.utf8.left--; - break; - - case ACTION_UTF8_3_ENTRY: - term->vt.utf8.idx = 0; - term->vt.utf8.left = 3; - term->vt.utf8.data[term->vt.utf8.idx++] = c; - term->vt.utf8.left--; - break; - - case ACTION_UTF8_4_ENTRY: - term->vt.utf8.idx = 0; - term->vt.utf8.left = 4; - term->vt.utf8.data[term->vt.utf8.idx++] = c; - term->vt.utf8.left--; - break; - } -} - static enum state state_ground_switch(struct terminal *term, uint8_t data) { @@ -606,27 +573,27 @@ state_ground_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_GROUND; - case 0x20 ... 0x7f: action(term, ACTION_PRINT, data); return STATE_GROUND; + case 0x20 ... 0x7f: action_print(term, data); return STATE_GROUND; - case 0xc0 ... 0xdf: action(term, ACTION_UTF8_2_ENTRY, data); return STATE_UTF8_COLLECT_1; - case 0xe0 ... 0xef: action(term, ACTION_UTF8_3_ENTRY, data); return STATE_UTF8_COLLECT_2; - case 0xf0 ... 0xf7: action(term, ACTION_UTF8_4_ENTRY, data); return STATE_UTF8_COLLECT_3; + case 0xc0 ... 0xdf: action_utf8_2_entry(term, data); return STATE_UTF8_COLLECT_1; + case 0xe0 ... 0xef: action_utf8_3_entry(term, data); return STATE_UTF8_COLLECT_2; + case 0xf0 ... 0xf7: action_utf8_4_entry(term, data); return STATE_UTF8_COLLECT_3; - /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + /* Anywhere */ + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_GROUND; @@ -640,35 +607,35 @@ state_escape_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_ESCAPE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x4f: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x50: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x51 ... 0x57: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x4f: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x50: action_clear(term); return STATE_DCS_ENTRY; + case 0x51 ... 0x57: action_esc_dispatch(term, data); return STATE_GROUND; case 0x58: return STATE_SOS_PM_APC_STRING; - case 0x59: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x5a: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x5b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; - case 0x5c: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x5d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x59: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x5a: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x5b: action_clear(term); return STATE_CSI_ENTRY; + case 0x5c: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x5d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x5e ... 0x5f: return STATE_SOS_PM_APC_STRING; - case 0x60 ... 0x7e: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_ESCAPE; + case 0x60 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_ESCAPE; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_ESCAPE; @@ -682,25 +649,25 @@ state_escape_intermediate_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x7e: action(term, ACTION_ESC_DISPATCH, data); return STATE_GROUND; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_ESCAPE_INTERMEDIATE; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_ESCAPE_INTERMEDIATE; @@ -714,28 +681,28 @@ state_csi_entry_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_CSI_ENTRY; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_ENTRY; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_CSI_INTERMEDIATE; - case 0x30 ... 0x39: action(term, ACTION_PARAM, data); return STATE_CSI_PARAM; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, data); return STATE_CSI_PARAM; case 0x3a ... 0x3b: return STATE_CSI_PARAM; - case 0x3c ... 0x3f: action(term, ACTION_COLLECT, data); return STATE_CSI_PARAM; - case 0x40 ... 0x7e: action(term, ACTION_CSI_DISPATCH, data); return STATE_GROUND; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_CSI_ENTRY; + case 0x3c ... 0x3f: action_collect(term, data); return STATE_CSI_PARAM; + case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_CSI_ENTRY; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_ENTRY; @@ -749,30 +716,30 @@ state_csi_param_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_CSI_PARAM; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_PARAM; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_CSI_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; case 0x30 ... 0x39: - case 0x3a ... 0x3b: action(term, ACTION_PARAM, data); return STATE_CSI_PARAM; + case 0x3a ... 0x3b: action_param(term, data); return STATE_CSI_PARAM; case 0x3c ... 0x3f: return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: action(term, ACTION_CSI_DISPATCH, data); return STATE_GROUND; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_CSI_PARAM; + case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_CSI_PARAM; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_PARAM; @@ -786,26 +753,26 @@ state_csi_intermediate_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_CSI_INTERMEDIATE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_INTERMEDIATE; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_CSI_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; case 0x30 ... 0x3f: return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: action(term, ACTION_CSI_DISPATCH, data); return STATE_GROUND; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_CSI_INTERMEDIATE; + case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_CSI_INTERMEDIATE; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_INTERMEDIATE; @@ -819,25 +786,25 @@ state_csi_ignore_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_EXECUTE, data); return STATE_CSI_IGNORE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_IGNORE; - case 0x20 ... 0x3f: action(term, ACTION_IGNORE, data); return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: return STATE_GROUND; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_CSI_IGNORE; + case 0x20 ... 0x3f: action_ignore(term); return STATE_CSI_IGNORE; + case 0x40 ... 0x7e: return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_CSI_IGNORE; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_IGNORE; @@ -851,20 +818,20 @@ state_osc_string_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ /* Note: original was 20-7f, but I changed to 20-ff to include utf-8. Don't forget to add EXECUTE to 8-bit C1 if we implement that. */ - default: action(term, ACTION_OSC_PUT, data); return STATE_OSC_STRING; + default: action_osc_put(term, data); return STATE_OSC_STRING; - case 0x07: action(term, ACTION_OSC_END, data); return STATE_GROUND; + case 0x07: action_osc_end(term, data); return STATE_GROUND; case 0x00 ... 0x06: case 0x08 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_IGNORE, data); return STATE_OSC_STRING; + case 0x1c ... 0x1f: action_ignore(term); return STATE_OSC_STRING; case 0x18: - case 0x1a: action(term, ACTION_OSC_END, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x1a: action_osc_end(term, data); action_execute(term, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_OSC_END, data); action(term, ACTION_CLEAR, data); return STATE_ESCAPE; + case 0x1b: action_osc_end(term, data); action_clear(term); return STATE_ESCAPE; } } @@ -875,29 +842,29 @@ state_dcs_entry_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_IGNORE, data); return STATE_DCS_ENTRY; + case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_ENTRY; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_DCS_INTERMEDIATE; - case 0x30 ... 0x39: action(term, ACTION_PARAM, data); return STATE_DCS_PARAM; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; case 0x3a: return STATE_DCS_IGNORE; - case 0x3b: action(term, ACTION_PARAM, data); return STATE_DCS_PARAM; - case 0x3c ... 0x3f: action(term, ACTION_COLLECT, data); return STATE_DCS_PARAM; - case 0x40 ... 0x7e: action(term, ACTION_HOOK, data); return STATE_DCS_PASSTHROUGH; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_ENTRY; + case 0x3b: action_param(term, data); return STATE_DCS_PARAM; + case 0x3c ... 0x3f: action_collect(term, data); return STATE_DCS_PARAM; + case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action_ignore(term); return STATE_DCS_ENTRY; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_ENTRY; @@ -911,29 +878,29 @@ state_dcs_param_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_IGNORE, data); return STATE_DCS_PARAM; + case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_PARAM; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_DCS_INTERMEDIATE; - case 0x30 ... 0x39: action(term, ACTION_PARAM, data); return STATE_DCS_PARAM; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; case 0x3a: return STATE_DCS_IGNORE; - case 0x3b: action(term, ACTION_PARAM, data); return STATE_DCS_PARAM; + case 0x3b: action_param(term, data); return STATE_DCS_PARAM; case 0x3c ... 0x3f: return STATE_DCS_IGNORE; - case 0x40 ... 0x7e: action(term, ACTION_HOOK, data); return STATE_DCS_PASSTHROUGH; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_PARAM; + case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action_ignore(term); return STATE_DCS_PARAM; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_PARAM; @@ -947,26 +914,26 @@ state_dcs_intermediate_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action(term, ACTION_IGNORE, data); return STATE_DCS_INTERMEDIATE; + case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_INTERMEDIATE; - case 0x20 ... 0x2f: action(term, ACTION_COLLECT, data); return STATE_DCS_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; case 0x30 ... 0x3f: return STATE_DCS_IGNORE; - case 0x40 ... 0x7e: action(term, ACTION_HOOK, data); return STATE_DCS_PASSTHROUGH; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_INTERMEDIATE; + case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action_ignore(term); return STATE_DCS_INTERMEDIATE; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_INTERMEDIATE; @@ -981,21 +948,21 @@ state_dcs_ignore_switch(struct terminal *term, uint8_t data) case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x1f: - case 0x20 ... 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_IGNORE; + case 0x20 ... 0x7f: action_ignore(term); return STATE_DCS_IGNORE; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_IGNORE; @@ -1009,24 +976,24 @@ state_dcs_passthrough_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x7e: action(term, ACTION_PUT, data); return STATE_DCS_PASSTHROUGH; + case 0x1c ... 0x7e: action_put(term, data); return STATE_DCS_PASSTHROUGH; - case 0x7f: action(term, ACTION_IGNORE, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action_ignore(term); return STATE_DCS_PASSTHROUGH; /* Anywhere */ - case 0x18: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_UNHOOK, data); action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_UNHOOK, data); action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x98: action(term, ACTION_UNHOOK, data); return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_UNHOOK, data); action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_UNHOOK, data); action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; - case 0x9c: action(term, ACTION_UNHOOK, data); return STATE_GROUND; - case 0x9d: action(term, ACTION_UNHOOK, data); action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: action(term, ACTION_UNHOOK, data); return STATE_SOS_PM_APC_STRING; + case 0x18: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x1a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x1b: action_unhook(term, data); action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x90: action_unhook(term, data); action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x98: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; + case 0x99: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x9a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x9b: action_unhook(term, data); action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: action_unhook(term, data); return STATE_GROUND; + case 0x9d: action_unhook(term, data); action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_PASSTHROUGH; } @@ -1039,21 +1006,21 @@ state_sos_pm_apc_string_switch(struct terminal *term, uint8_t data) /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x7f: action(term, ACTION_IGNORE, data); return STATE_SOS_PM_APC_STRING; + case 0x1c ... 0x7f: action_ignore(term); return STATE_SOS_PM_APC_STRING; /* Anywhere */ - case 0x18: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x1b: action(term, ACTION_CLEAR, data); return STATE_ESCAPE; - case 0x80 ... 0x8f: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x90: action(term, ACTION_CLEAR, data); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action(term, ACTION_EXECUTE, data); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9a: action(term, ACTION_EXECUTE, data); return STATE_GROUND; - case 0x9b: action(term, ACTION_CLEAR, data); return STATE_CSI_ENTRY; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action(term, ACTION_OSC_START, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_SOS_PM_APC_STRING; @@ -1067,7 +1034,7 @@ state_utf8_collect_1_switch(struct terminal *term, uint8_t data) term->vt.utf8.left--; assert(term->vt.utf8.left == 0); - action(term, ACTION_UTF8_PRINT, data); + action_utf8_print(term, data); return STATE_GROUND; } From 1bc8562026a42118771784c58299e213c187e2cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 23:38:16 +0100 Subject: [PATCH 18/20] vt: visually compact the switch tables --- vt.c | 542 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 271 insertions(+), 271 deletions(-) diff --git a/vt.c b/vt.c index 7f57f902..114aba02 100644 --- a/vt.c +++ b/vt.c @@ -570,33 +570,33 @@ static enum state state_ground_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_GROUND; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_GROUND; - case 0x20 ... 0x7f: action_print(term, data); return STATE_GROUND; + case 0x20 ... 0x7f: action_print(term, data); return STATE_GROUND; - case 0xc0 ... 0xdf: action_utf8_2_entry(term, data); return STATE_UTF8_COLLECT_1; - case 0xe0 ... 0xef: action_utf8_3_entry(term, data); return STATE_UTF8_COLLECT_2; - case 0xf0 ... 0xf7: action_utf8_4_entry(term, data); return STATE_UTF8_COLLECT_3; + case 0xc0 ... 0xdf: action_utf8_2_entry(term, data); return STATE_UTF8_COLLECT_1; + case 0xe0 ... 0xef: action_utf8_3_entry(term, data); return STATE_UTF8_COLLECT_2; + case 0xf0 ... 0xf7: action_utf8_4_entry(term, data); return STATE_UTF8_COLLECT_3; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_GROUND; + default: return STATE_GROUND; } } @@ -604,41 +604,41 @@ static enum state state_escape_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x4f: action_esc_dispatch(term, data); return STATE_GROUND; - case 0x50: action_clear(term); return STATE_DCS_ENTRY; - case 0x51 ... 0x57: action_esc_dispatch(term, data); return STATE_GROUND; - case 0x58: return STATE_SOS_PM_APC_STRING; - case 0x59: action_esc_dispatch(term, data); return STATE_GROUND; - case 0x5a: action_esc_dispatch(term, data); return STATE_GROUND; - case 0x5b: action_clear(term); return STATE_CSI_ENTRY; - case 0x5c: action_esc_dispatch(term, data); return STATE_GROUND; - case 0x5d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x5e ... 0x5f: return STATE_SOS_PM_APC_STRING; - case 0x60 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; - case 0x7f: action_ignore(term); return STATE_ESCAPE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x4f: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x50: action_clear(term); return STATE_DCS_ENTRY; + case 0x51 ... 0x57: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x58: return STATE_SOS_PM_APC_STRING; + case 0x59: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x5a: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x5b: action_clear(term); return STATE_CSI_ENTRY; + case 0x5c: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x5d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x5e ... 0x5f: return STATE_SOS_PM_APC_STRING; + case 0x60 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_ESCAPE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_ESCAPE; + default: return STATE_ESCAPE; } } @@ -646,31 +646,31 @@ static enum state state_escape_intermediate_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; - case 0x7f: action_ignore(term); return STATE_ESCAPE_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_ESCAPE_INTERMEDIATE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_ESCAPE_INTERMEDIATE; + default: return STATE_ESCAPE_INTERMEDIATE; } } @@ -678,34 +678,34 @@ static enum state state_csi_entry_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_ENTRY; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_ENTRY; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; - case 0x30 ... 0x39: action_param(term, data); return STATE_CSI_PARAM; - case 0x3a ... 0x3b: return STATE_CSI_PARAM; - case 0x3c ... 0x3f: action_collect(term, data); return STATE_CSI_PARAM; - case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; - case 0x7f: action_ignore(term); return STATE_CSI_ENTRY; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, data); return STATE_CSI_PARAM; + case 0x3a ... 0x3b: return STATE_CSI_PARAM; + case 0x3c ... 0x3f: action_collect(term, data); return STATE_CSI_PARAM; + case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_CSI_ENTRY; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_CSI_ENTRY; + default: return STATE_CSI_ENTRY; } } @@ -713,36 +713,36 @@ static enum state state_csi_param_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_PARAM; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_PARAM; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; case 0x30 ... 0x39: - case 0x3a ... 0x3b: action_param(term, data); return STATE_CSI_PARAM; + case 0x3a ... 0x3b: action_param(term, data); return STATE_CSI_PARAM; - case 0x3c ... 0x3f: return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; - case 0x7f: action_ignore(term); return STATE_CSI_PARAM; + case 0x3c ... 0x3f: return STATE_CSI_IGNORE; + case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_CSI_PARAM; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_CSI_PARAM; + default: return STATE_CSI_PARAM; } } @@ -750,32 +750,32 @@ static enum state state_csi_intermediate_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_INTERMEDIATE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_INTERMEDIATE; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; - case 0x30 ... 0x3f: return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; - case 0x7f: action_ignore(term); return STATE_CSI_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; + case 0x30 ... 0x3f: return STATE_CSI_IGNORE; + case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_CSI_INTERMEDIATE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_CSI_INTERMEDIATE; + default: return STATE_CSI_INTERMEDIATE; } } @@ -783,31 +783,31 @@ static enum state state_csi_ignore_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_IGNORE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_IGNORE; - case 0x20 ... 0x3f: action_ignore(term); return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: return STATE_GROUND; - case 0x7f: action_ignore(term); return STATE_CSI_IGNORE; + case 0x20 ... 0x3f: action_ignore(term); return STATE_CSI_IGNORE; + case 0x40 ... 0x7e: return STATE_GROUND; + case 0x7f: action_ignore(term); return STATE_CSI_IGNORE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_CSI_IGNORE; + default: return STATE_CSI_IGNORE; } } @@ -815,23 +815,23 @@ static enum state state_osc_string_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ /* Note: original was 20-7f, but I changed to 20-ff to include utf-8. Don't forget to add EXECUTE to 8-bit C1 if we implement that. */ - default: action_osc_put(term, data); return STATE_OSC_STRING; + default: action_osc_put(term, data); return STATE_OSC_STRING; - case 0x07: action_osc_end(term, data); return STATE_GROUND; + case 0x07: action_osc_end(term, data); return STATE_GROUND; case 0x00 ... 0x06: case 0x08 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_ignore(term); return STATE_OSC_STRING; + case 0x1c ... 0x1f: action_ignore(term); return STATE_OSC_STRING; case 0x18: - case 0x1a: action_osc_end(term, data); action_execute(term, data); return STATE_GROUND; + case 0x1a: action_osc_end(term, data); action_execute(term, data); return STATE_GROUND; - case 0x1b: action_osc_end(term, data); action_clear(term); return STATE_ESCAPE; + case 0x1b: action_osc_end(term, data); action_clear(term); return STATE_ESCAPE; } } @@ -839,35 +839,35 @@ static enum state state_dcs_entry_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_ENTRY; + case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_ENTRY; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; - case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; - case 0x3a: return STATE_DCS_IGNORE; - case 0x3b: action_param(term, data); return STATE_DCS_PARAM; - case 0x3c ... 0x3f: action_collect(term, data); return STATE_DCS_PARAM; - case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; - case 0x7f: action_ignore(term); return STATE_DCS_ENTRY; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; + case 0x3a: return STATE_DCS_IGNORE; + case 0x3b: action_param(term, data); return STATE_DCS_PARAM; + case 0x3c ... 0x3f: action_collect(term, data); return STATE_DCS_PARAM; + case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action_ignore(term); return STATE_DCS_ENTRY; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_DCS_ENTRY; + default: return STATE_DCS_ENTRY; } } @@ -875,35 +875,35 @@ static enum state state_dcs_param_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_PARAM; + case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_PARAM; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; - case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; - case 0x3a: return STATE_DCS_IGNORE; - case 0x3b: action_param(term, data); return STATE_DCS_PARAM; - case 0x3c ... 0x3f: return STATE_DCS_IGNORE; - case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; - case 0x7f: action_ignore(term); return STATE_DCS_PARAM; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; + case 0x3a: return STATE_DCS_IGNORE; + case 0x3b: action_param(term, data); return STATE_DCS_PARAM; + case 0x3c ... 0x3f: return STATE_DCS_IGNORE; + case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action_ignore(term); return STATE_DCS_PARAM; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_DCS_PARAM; + default: return STATE_DCS_PARAM; } } @@ -911,32 +911,32 @@ static enum state state_dcs_intermediate_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_INTERMEDIATE; + case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_INTERMEDIATE; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; - case 0x30 ... 0x3f: return STATE_DCS_IGNORE; - case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; - case 0x7f: action_ignore(term); return STATE_DCS_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x3f: return STATE_DCS_IGNORE; + case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; + case 0x7f: action_ignore(term); return STATE_DCS_INTERMEDIATE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_DCS_INTERMEDIATE; + default: return STATE_DCS_INTERMEDIATE; } } @@ -944,28 +944,28 @@ static enum state state_dcs_ignore_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x1f: - case 0x20 ... 0x7f: action_ignore(term); return STATE_DCS_IGNORE; + case 0x20 ... 0x7f: action_ignore(term); return STATE_DCS_IGNORE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_DCS_IGNORE; + default: return STATE_DCS_IGNORE; } } @@ -973,29 +973,29 @@ static enum state state_dcs_passthrough_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x7e: action_put(term, data); return STATE_DCS_PASSTHROUGH; + case 0x1c ... 0x7e: action_put(term, data); return STATE_DCS_PASSTHROUGH; - case 0x7f: action_ignore(term); return STATE_DCS_PASSTHROUGH; + case 0x7f: action_ignore(term); return STATE_DCS_PASSTHROUGH; /* Anywhere */ - case 0x18: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x1a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x1b: action_unhook(term, data); action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x90: action_unhook(term, data); action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x98: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; - case 0x99: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x9a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x9b: action_unhook(term, data); action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: action_unhook(term, data); return STATE_GROUND; - case 0x9d: action_unhook(term, data); action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; + case 0x18: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x1a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x1b: action_unhook(term, data); action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x90: action_unhook(term, data); action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x98: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; + case 0x99: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x9a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x9b: action_unhook(term, data); action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: action_unhook(term, data); return STATE_GROUND; + case 0x9d: action_unhook(term, data); action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; - default: return STATE_DCS_PASSTHROUGH; + default: return STATE_DCS_PASSTHROUGH; } } @@ -1003,27 +1003,27 @@ static enum state state_sos_pm_apc_string_switch(struct terminal *term, uint8_t data) { switch (data) { - /* exit current enter new state */ + /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x7f: action_ignore(term); return STATE_SOS_PM_APC_STRING; + case 0x1c ... 0x7f: action_ignore(term); return STATE_SOS_PM_APC_STRING; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; - case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; - case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; - case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; - case 0x9b: action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x1b: action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x90: action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x98: return STATE_SOS_PM_APC_STRING; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x9b: action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: return STATE_GROUND; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; - default: return STATE_SOS_PM_APC_STRING; + default: return STATE_SOS_PM_APC_STRING; } } From a575204bc77c711047740d2328d26043e8c976cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 23:45:21 +0100 Subject: [PATCH 19/20] vt: refactor --- vt.c | 409 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 208 insertions(+), 201 deletions(-) diff --git a/vt.c b/vt.c index 114aba02..5992ee9c 100644 --- a/vt.c +++ b/vt.c @@ -567,33 +567,33 @@ action_utf8_print(struct terminal *term, uint8_t c) } static enum state -state_ground_switch(struct terminal *term, uint8_t data) +state_ground_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_GROUND; + case 0x1c ... 0x1f: action_execute(term, c); return STATE_GROUND; - case 0x20 ... 0x7f: action_print(term, data); return STATE_GROUND; + case 0x20 ... 0x7f: action_print(term, c); return STATE_GROUND; - case 0xc0 ... 0xdf: action_utf8_2_entry(term, data); return STATE_UTF8_COLLECT_1; - case 0xe0 ... 0xef: action_utf8_3_entry(term, data); return STATE_UTF8_COLLECT_2; - case 0xf0 ... 0xf7: action_utf8_4_entry(term, data); return STATE_UTF8_COLLECT_3; + case 0xc0 ... 0xdf: action_utf8_2_entry(term, c); return STATE_UTF8_COLLECT_1; + case 0xe0 ... 0xef: action_utf8_3_entry(term, c); return STATE_UTF8_COLLECT_2; + case 0xf0 ... 0xf7: action_utf8_4_entry(term, c); return STATE_UTF8_COLLECT_3; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_GROUND; @@ -601,41 +601,41 @@ state_ground_switch(struct terminal *term, uint8_t data) } static enum state -state_escape_switch(struct terminal *term, uint8_t data) +state_escape_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE; + case 0x1c ... 0x1f: action_execute(term, c); return STATE_ESCAPE; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x4f: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x20 ... 0x2f: action_collect(term, c); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x4f: action_esc_dispatch(term, c); return STATE_GROUND; case 0x50: action_clear(term); return STATE_DCS_ENTRY; - case 0x51 ... 0x57: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x51 ... 0x57: action_esc_dispatch(term, c); return STATE_GROUND; case 0x58: return STATE_SOS_PM_APC_STRING; - case 0x59: action_esc_dispatch(term, data); return STATE_GROUND; - case 0x5a: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x59: action_esc_dispatch(term, c); return STATE_GROUND; + case 0x5a: action_esc_dispatch(term, c); return STATE_GROUND; case 0x5b: action_clear(term); return STATE_CSI_ENTRY; - case 0x5c: action_esc_dispatch(term, data); return STATE_GROUND; - case 0x5d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x5c: action_esc_dispatch(term, c); return STATE_GROUND; + case 0x5d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x5e ... 0x5f: return STATE_SOS_PM_APC_STRING; - case 0x60 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x60 ... 0x7e: action_esc_dispatch(term, c); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_ESCAPE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_ESCAPE; @@ -643,31 +643,31 @@ state_escape_switch(struct terminal *term, uint8_t data) } static enum state -state_escape_intermediate_switch(struct terminal *term, uint8_t data) +state_escape_intermediate_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x1c ... 0x1f: action_execute(term, c); return STATE_ESCAPE_INTERMEDIATE; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x20 ... 0x2f: action_collect(term, c); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x7e: action_esc_dispatch(term, c); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_ESCAPE_INTERMEDIATE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_ESCAPE_INTERMEDIATE; @@ -675,34 +675,34 @@ state_escape_intermediate_switch(struct terminal *term, uint8_t data) } static enum state -state_csi_entry_switch(struct terminal *term, uint8_t data) +state_csi_entry_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_ENTRY; + case 0x1c ... 0x1f: action_execute(term, c); return STATE_CSI_ENTRY; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; - case 0x30 ... 0x39: action_param(term, data); return STATE_CSI_PARAM; + case 0x20 ... 0x2f: action_collect(term, c); return STATE_CSI_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, c); return STATE_CSI_PARAM; case 0x3a ... 0x3b: return STATE_CSI_PARAM; - case 0x3c ... 0x3f: action_collect(term, data); return STATE_CSI_PARAM; - case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; + case 0x3c ... 0x3f: action_collect(term, c); return STATE_CSI_PARAM; + case 0x40 ... 0x7e: action_csi_dispatch(term, c); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_CSI_ENTRY; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_ENTRY; @@ -710,36 +710,36 @@ state_csi_entry_switch(struct terminal *term, uint8_t data) } static enum state -state_csi_param_switch(struct terminal *term, uint8_t data) +state_csi_param_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_PARAM; + case 0x1c ... 0x1f: action_execute(term, c); return STATE_CSI_PARAM; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, c); return STATE_CSI_INTERMEDIATE; case 0x30 ... 0x39: - case 0x3a ... 0x3b: action_param(term, data); return STATE_CSI_PARAM; + case 0x3a ... 0x3b: action_param(term, c); return STATE_CSI_PARAM; case 0x3c ... 0x3f: return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; + case 0x40 ... 0x7e: action_csi_dispatch(term, c); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_CSI_PARAM; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_PARAM; @@ -747,32 +747,32 @@ state_csi_param_switch(struct terminal *term, uint8_t data) } static enum state -state_csi_intermediate_switch(struct terminal *term, uint8_t data) +state_csi_intermediate_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_INTERMEDIATE; + case 0x1c ... 0x1f: action_execute(term, c); return STATE_CSI_INTERMEDIATE; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, c); return STATE_CSI_INTERMEDIATE; case 0x30 ... 0x3f: return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; + case 0x40 ... 0x7e: action_csi_dispatch(term, c); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_CSI_INTERMEDIATE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_INTERMEDIATE; @@ -780,31 +780,31 @@ state_csi_intermediate_switch(struct terminal *term, uint8_t data) } static enum state -state_csi_ignore_switch(struct terminal *term, uint8_t data) +state_csi_ignore_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_IGNORE; + case 0x1c ... 0x1f: action_execute(term, c); return STATE_CSI_IGNORE; case 0x20 ... 0x3f: action_ignore(term); return STATE_CSI_IGNORE; case 0x40 ... 0x7e: return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_CSI_IGNORE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_IGNORE; @@ -812,15 +812,15 @@ state_csi_ignore_switch(struct terminal *term, uint8_t data) } static enum state -state_osc_string_switch(struct terminal *term, uint8_t data) +state_osc_string_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ /* Note: original was 20-7f, but I changed to 20-ff to include utf-8. Don't forget to add EXECUTE to 8-bit C1 if we implement that. */ - default: action_osc_put(term, data); return STATE_OSC_STRING; + default: action_osc_put(term, c); return STATE_OSC_STRING; - case 0x07: action_osc_end(term, data); return STATE_GROUND; + case 0x07: action_osc_end(term, c); return STATE_GROUND; case 0x00 ... 0x06: case 0x08 ... 0x17: @@ -829,42 +829,42 @@ state_osc_string_switch(struct terminal *term, uint8_t data) case 0x18: - case 0x1a: action_osc_end(term, data); action_execute(term, data); return STATE_GROUND; + case 0x1a: action_osc_end(term, c); action_execute(term, c); return STATE_GROUND; - case 0x1b: action_osc_end(term, data); action_clear(term); return STATE_ESCAPE; + case 0x1b: action_osc_end(term, c); action_clear(term); return STATE_ESCAPE; } } static enum state -state_dcs_entry_switch(struct terminal *term, uint8_t data) +state_dcs_entry_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_ENTRY; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; - case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; + case 0x20 ... 0x2f: action_collect(term, c); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, c); return STATE_DCS_PARAM; case 0x3a: return STATE_DCS_IGNORE; - case 0x3b: action_param(term, data); return STATE_DCS_PARAM; - case 0x3c ... 0x3f: action_collect(term, data); return STATE_DCS_PARAM; - case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; + case 0x3b: action_param(term, c); return STATE_DCS_PARAM; + case 0x3c ... 0x3f: action_collect(term, c); return STATE_DCS_PARAM; + case 0x40 ... 0x7e: action_hook(term, c); return STATE_DCS_PASSTHROUGH; case 0x7f: action_ignore(term); return STATE_DCS_ENTRY; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_ENTRY; @@ -872,35 +872,35 @@ state_dcs_entry_switch(struct terminal *term, uint8_t data) } static enum state -state_dcs_param_switch(struct terminal *term, uint8_t data) +state_dcs_param_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_PARAM; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; - case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; + case 0x20 ... 0x2f: action_collect(term, c); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, c); return STATE_DCS_PARAM; case 0x3a: return STATE_DCS_IGNORE; - case 0x3b: action_param(term, data); return STATE_DCS_PARAM; + case 0x3b: action_param(term, c); return STATE_DCS_PARAM; case 0x3c ... 0x3f: return STATE_DCS_IGNORE; - case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; + case 0x40 ... 0x7e: action_hook(term, c); return STATE_DCS_PASSTHROUGH; case 0x7f: action_ignore(term); return STATE_DCS_PARAM; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_PARAM; @@ -908,32 +908,32 @@ state_dcs_param_switch(struct terminal *term, uint8_t data) } static enum state -state_dcs_intermediate_switch(struct terminal *term, uint8_t data) +state_dcs_intermediate_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_INTERMEDIATE; - case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, c); return STATE_DCS_INTERMEDIATE; case 0x30 ... 0x3f: return STATE_DCS_IGNORE; - case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; + case 0x40 ... 0x7e: action_hook(term, c); return STATE_DCS_PASSTHROUGH; case 0x7f: action_ignore(term); return STATE_DCS_INTERMEDIATE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_INTERMEDIATE; @@ -941,9 +941,9 @@ state_dcs_intermediate_switch(struct terminal *term, uint8_t data) } static enum state -state_dcs_ignore_switch(struct terminal *term, uint8_t data) +state_dcs_ignore_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: @@ -951,18 +951,18 @@ state_dcs_ignore_switch(struct terminal *term, uint8_t data) case 0x20 ... 0x7f: action_ignore(term); return STATE_DCS_IGNORE; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_IGNORE; @@ -970,57 +970,57 @@ state_dcs_ignore_switch(struct terminal *term, uint8_t data) } static enum state -state_dcs_passthrough_switch(struct terminal *term, uint8_t data) +state_dcs_passthrough_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x7e: action_put(term, data); return STATE_DCS_PASSTHROUGH; + case 0x1c ... 0x7e: action_put(term, c); return STATE_DCS_PASSTHROUGH; case 0x7f: action_ignore(term); return STATE_DCS_PASSTHROUGH; /* Anywhere */ - case 0x18: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x1a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x1b: action_unhook(term, data); action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x90: action_unhook(term, data); action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x98: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; - case 0x99: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x9a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; - case 0x9b: action_unhook(term, data); action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: action_unhook(term, data); return STATE_GROUND; - case 0x9d: action_unhook(term, data); action_osc_start(term, data); return STATE_OSC_STRING; - case 0x9e ... 0x9f: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; + case 0x18: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; + case 0x1a: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; + case 0x1b: action_unhook(term, c); action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; + case 0x90: action_unhook(term, c); action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; + case 0x98: action_unhook(term, c); return STATE_SOS_PM_APC_STRING; + case 0x99: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; + case 0x9a: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; + case 0x9b: action_unhook(term, c); action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: action_unhook(term, c); return STATE_GROUND; + case 0x9d: action_unhook(term, c); action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9e ... 0x9f: action_unhook(term, c); return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_PASSTHROUGH; } } static enum state -state_sos_pm_apc_string_switch(struct terminal *term, uint8_t data) +state_sos_pm_apc_string_switch(struct terminal *term, uint8_t c) { - switch (data) { + switch (c) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x7f: action_ignore(term); return STATE_SOS_PM_APC_STRING; /* Anywhere */ - case 0x18: action_execute(term, data); return STATE_GROUND; - case 0x1a: action_execute(term, data); return STATE_GROUND; + case 0x18: action_execute(term, c); return STATE_GROUND; + case 0x1a: action_execute(term, c); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, data); return STATE_GROUND; - case 0x9a: action_execute(term, data); return STATE_GROUND; + case 0x99: action_execute(term, c); return STATE_GROUND; + case 0x9a: action_execute(term, c); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_SOS_PM_APC_STRING; @@ -1028,20 +1028,20 @@ state_sos_pm_apc_string_switch(struct terminal *term, uint8_t data) } static enum state -state_utf8_collect_1_switch(struct terminal *term, uint8_t data) +state_utf8_collect_1_switch(struct terminal *term, uint8_t c) { - term->vt.utf8.data[term->vt.utf8.idx++] = data; + term->vt.utf8.data[term->vt.utf8.idx++] = c; term->vt.utf8.left--; assert(term->vt.utf8.left == 0); - action_utf8_print(term, data); + action_utf8_print(term, c); return STATE_GROUND; } static enum state -state_utf8_collect_2_switch(struct terminal *term, uint8_t data) +state_utf8_collect_2_switch(struct terminal *term, uint8_t c) { - term->vt.utf8.data[term->vt.utf8.idx++] = data; + term->vt.utf8.data[term->vt.utf8.idx++] = c; term->vt.utf8.left--; assert(term->vt.utf8.left == 1); @@ -1049,44 +1049,51 @@ state_utf8_collect_2_switch(struct terminal *term, uint8_t data) } static enum state -state_utf8_collect_3_switch(struct terminal *term, uint8_t data) +state_utf8_collect_3_switch(struct terminal *term, uint8_t c) { - term->vt.utf8.data[term->vt.utf8.idx++] = data; + term->vt.utf8.data[term->vt.utf8.idx++] = c; term->vt.utf8.left--; assert(term->vt.utf8.left == 2); return STATE_UTF8_COLLECT_2; } +static inline enum state +vt_state_machine_progress(struct terminal *term, enum state current_state, uint8_t c) +{ + switch (current_state) { + case STATE_GROUND: return state_ground_switch(term, c); + case STATE_ESCAPE: return state_escape_switch(term, c); + case STATE_ESCAPE_INTERMEDIATE: return state_escape_intermediate_switch(term, c); + case STATE_CSI_ENTRY: return state_csi_entry_switch(term, c); + case STATE_CSI_PARAM: return state_csi_param_switch(term, c); + case STATE_CSI_INTERMEDIATE: return state_csi_intermediate_switch(term, c); + case STATE_CSI_IGNORE: return state_csi_ignore_switch(term, c); + case STATE_OSC_STRING: return state_osc_string_switch(term, c); + case STATE_DCS_ENTRY: return state_dcs_entry_switch(term, c); + case STATE_DCS_PARAM: return state_dcs_param_switch(term, c); + case STATE_DCS_INTERMEDIATE: return state_dcs_intermediate_switch(term, c); + case STATE_DCS_IGNORE: return state_dcs_ignore_switch(term, c); + case STATE_DCS_PASSTHROUGH: return state_dcs_passthrough_switch(term, c); + case STATE_SOS_PM_APC_STRING: return state_sos_pm_apc_string_switch(term, c); + + case STATE_UTF8_COLLECT_1: return state_utf8_collect_1_switch(term, c); + case STATE_UTF8_COLLECT_2: return state_utf8_collect_2_switch(term, c); + case STATE_UTF8_COLLECT_3: return state_utf8_collect_3_switch(term, c); + } + + assert(false); + return STATE_GROUND; +} + void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { enum state current_state = term->vt.state; const uint8_t *p = data; - for (size_t i = 0; i < len; i++, p++) { - switch (current_state) { - case STATE_GROUND: current_state = state_ground_switch(term, *p); break; - case STATE_ESCAPE: current_state = state_escape_switch(term, *p); break; - case STATE_ESCAPE_INTERMEDIATE: current_state = state_escape_intermediate_switch(term, *p); break; - case STATE_CSI_ENTRY: current_state = state_csi_entry_switch(term, *p); break; - case STATE_CSI_PARAM: current_state = state_csi_param_switch(term, *p); break; - case STATE_CSI_INTERMEDIATE: current_state = state_csi_intermediate_switch(term, *p); break; - case STATE_CSI_IGNORE: current_state = state_csi_ignore_switch(term, *p); break; - case STATE_OSC_STRING: current_state = state_osc_string_switch(term, *p); break; - case STATE_DCS_ENTRY: current_state = state_dcs_entry_switch(term, *p); break; - case STATE_DCS_PARAM: current_state = state_dcs_param_switch(term, *p); break; - case STATE_DCS_INTERMEDIATE: current_state = state_dcs_intermediate_switch(term, *p); break; - case STATE_DCS_IGNORE: current_state = state_dcs_ignore_switch(term, *p); break; - case STATE_DCS_PASSTHROUGH: current_state = state_dcs_passthrough_switch(term, *p); break; - case STATE_SOS_PM_APC_STRING: current_state = state_sos_pm_apc_string_switch(term, *p); break; - - case STATE_UTF8_COLLECT_1: current_state = state_utf8_collect_1_switch(term, *p); break; - case STATE_UTF8_COLLECT_2: current_state = state_utf8_collect_2_switch(term, *p); break; - case STATE_UTF8_COLLECT_3: current_state = state_utf8_collect_3_switch(term, *p); break; - } - } - + for (size_t i = 0; i < len; i++, p++) + current_state = vt_state_machine_progress(term, current_state, *p); term->vt.state = current_state; } From 56824e459dc67668a4b89743b5747b941ce93615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 20 Dec 2019 23:59:23 +0100 Subject: [PATCH 20/20] Revert "vt: refactor" This reverts commit a575204bc77c711047740d2328d26043e8c976cb. --- vt.c | 409 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 201 insertions(+), 208 deletions(-) diff --git a/vt.c b/vt.c index 5992ee9c..114aba02 100644 --- a/vt.c +++ b/vt.c @@ -567,33 +567,33 @@ action_utf8_print(struct terminal *term, uint8_t c) } static enum state -state_ground_switch(struct terminal *term, uint8_t c) +state_ground_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, c); return STATE_GROUND; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_GROUND; - case 0x20 ... 0x7f: action_print(term, c); return STATE_GROUND; + case 0x20 ... 0x7f: action_print(term, data); return STATE_GROUND; - case 0xc0 ... 0xdf: action_utf8_2_entry(term, c); return STATE_UTF8_COLLECT_1; - case 0xe0 ... 0xef: action_utf8_3_entry(term, c); return STATE_UTF8_COLLECT_2; - case 0xf0 ... 0xf7: action_utf8_4_entry(term, c); return STATE_UTF8_COLLECT_3; + case 0xc0 ... 0xdf: action_utf8_2_entry(term, data); return STATE_UTF8_COLLECT_1; + case 0xe0 ... 0xef: action_utf8_3_entry(term, data); return STATE_UTF8_COLLECT_2; + case 0xf0 ... 0xf7: action_utf8_4_entry(term, data); return STATE_UTF8_COLLECT_3; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_GROUND; @@ -601,41 +601,41 @@ state_ground_switch(struct terminal *term, uint8_t c) } static enum state -state_escape_switch(struct terminal *term, uint8_t c) +state_escape_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, c); return STATE_ESCAPE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE; - case 0x20 ... 0x2f: action_collect(term, c); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x4f: action_esc_dispatch(term, c); return STATE_GROUND; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x4f: action_esc_dispatch(term, data); return STATE_GROUND; case 0x50: action_clear(term); return STATE_DCS_ENTRY; - case 0x51 ... 0x57: action_esc_dispatch(term, c); return STATE_GROUND; + case 0x51 ... 0x57: action_esc_dispatch(term, data); return STATE_GROUND; case 0x58: return STATE_SOS_PM_APC_STRING; - case 0x59: action_esc_dispatch(term, c); return STATE_GROUND; - case 0x5a: action_esc_dispatch(term, c); return STATE_GROUND; + case 0x59: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x5a: action_esc_dispatch(term, data); return STATE_GROUND; case 0x5b: action_clear(term); return STATE_CSI_ENTRY; - case 0x5c: action_esc_dispatch(term, c); return STATE_GROUND; - case 0x5d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x5c: action_esc_dispatch(term, data); return STATE_GROUND; + case 0x5d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x5e ... 0x5f: return STATE_SOS_PM_APC_STRING; - case 0x60 ... 0x7e: action_esc_dispatch(term, c); return STATE_GROUND; + case 0x60 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_ESCAPE; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_ESCAPE; @@ -643,31 +643,31 @@ state_escape_switch(struct terminal *term, uint8_t c) } static enum state -state_escape_intermediate_switch(struct terminal *term, uint8_t c) +state_escape_intermediate_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, c); return STATE_ESCAPE_INTERMEDIATE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_ESCAPE_INTERMEDIATE; - case 0x20 ... 0x2f: action_collect(term, c); return STATE_ESCAPE_INTERMEDIATE; - case 0x30 ... 0x7e: action_esc_dispatch(term, c); return STATE_GROUND; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_ESCAPE_INTERMEDIATE; + case 0x30 ... 0x7e: action_esc_dispatch(term, data); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_ESCAPE_INTERMEDIATE; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_ESCAPE_INTERMEDIATE; @@ -675,34 +675,34 @@ state_escape_intermediate_switch(struct terminal *term, uint8_t c) } static enum state -state_csi_entry_switch(struct terminal *term, uint8_t c) +state_csi_entry_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, c); return STATE_CSI_ENTRY; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_ENTRY; - case 0x20 ... 0x2f: action_collect(term, c); return STATE_CSI_INTERMEDIATE; - case 0x30 ... 0x39: action_param(term, c); return STATE_CSI_PARAM; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, data); return STATE_CSI_PARAM; case 0x3a ... 0x3b: return STATE_CSI_PARAM; - case 0x3c ... 0x3f: action_collect(term, c); return STATE_CSI_PARAM; - case 0x40 ... 0x7e: action_csi_dispatch(term, c); return STATE_GROUND; + case 0x3c ... 0x3f: action_collect(term, data); return STATE_CSI_PARAM; + case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_CSI_ENTRY; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_ENTRY; @@ -710,36 +710,36 @@ state_csi_entry_switch(struct terminal *term, uint8_t c) } static enum state -state_csi_param_switch(struct terminal *term, uint8_t c) +state_csi_param_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, c); return STATE_CSI_PARAM; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_PARAM; - case 0x20 ... 0x2f: action_collect(term, c); return STATE_CSI_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; case 0x30 ... 0x39: - case 0x3a ... 0x3b: action_param(term, c); return STATE_CSI_PARAM; + case 0x3a ... 0x3b: action_param(term, data); return STATE_CSI_PARAM; case 0x3c ... 0x3f: return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: action_csi_dispatch(term, c); return STATE_GROUND; + case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_CSI_PARAM; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_PARAM; @@ -747,32 +747,32 @@ state_csi_param_switch(struct terminal *term, uint8_t c) } static enum state -state_csi_intermediate_switch(struct terminal *term, uint8_t c) +state_csi_intermediate_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, c); return STATE_CSI_INTERMEDIATE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_INTERMEDIATE; - case 0x20 ... 0x2f: action_collect(term, c); return STATE_CSI_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_CSI_INTERMEDIATE; case 0x30 ... 0x3f: return STATE_CSI_IGNORE; - case 0x40 ... 0x7e: action_csi_dispatch(term, c); return STATE_GROUND; + case 0x40 ... 0x7e: action_csi_dispatch(term, data); return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_CSI_INTERMEDIATE; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_INTERMEDIATE; @@ -780,31 +780,31 @@ state_csi_intermediate_switch(struct terminal *term, uint8_t c) } static enum state -state_csi_ignore_switch(struct terminal *term, uint8_t c) +state_csi_ignore_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x1f: action_execute(term, c); return STATE_CSI_IGNORE; + case 0x1c ... 0x1f: action_execute(term, data); return STATE_CSI_IGNORE; case 0x20 ... 0x3f: action_ignore(term); return STATE_CSI_IGNORE; case 0x40 ... 0x7e: return STATE_GROUND; case 0x7f: action_ignore(term); return STATE_CSI_IGNORE; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_CSI_IGNORE; @@ -812,15 +812,15 @@ state_csi_ignore_switch(struct terminal *term, uint8_t c) } static enum state -state_osc_string_switch(struct terminal *term, uint8_t c) +state_osc_string_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ /* Note: original was 20-7f, but I changed to 20-ff to include utf-8. Don't forget to add EXECUTE to 8-bit C1 if we implement that. */ - default: action_osc_put(term, c); return STATE_OSC_STRING; + default: action_osc_put(term, data); return STATE_OSC_STRING; - case 0x07: action_osc_end(term, c); return STATE_GROUND; + case 0x07: action_osc_end(term, data); return STATE_GROUND; case 0x00 ... 0x06: case 0x08 ... 0x17: @@ -829,42 +829,42 @@ state_osc_string_switch(struct terminal *term, uint8_t c) case 0x18: - case 0x1a: action_osc_end(term, c); action_execute(term, c); return STATE_GROUND; + case 0x1a: action_osc_end(term, data); action_execute(term, data); return STATE_GROUND; - case 0x1b: action_osc_end(term, c); action_clear(term); return STATE_ESCAPE; + case 0x1b: action_osc_end(term, data); action_clear(term); return STATE_ESCAPE; } } static enum state -state_dcs_entry_switch(struct terminal *term, uint8_t c) +state_dcs_entry_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_ENTRY; - case 0x20 ... 0x2f: action_collect(term, c); return STATE_DCS_INTERMEDIATE; - case 0x30 ... 0x39: action_param(term, c); return STATE_DCS_PARAM; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; case 0x3a: return STATE_DCS_IGNORE; - case 0x3b: action_param(term, c); return STATE_DCS_PARAM; - case 0x3c ... 0x3f: action_collect(term, c); return STATE_DCS_PARAM; - case 0x40 ... 0x7e: action_hook(term, c); return STATE_DCS_PASSTHROUGH; + case 0x3b: action_param(term, data); return STATE_DCS_PARAM; + case 0x3c ... 0x3f: action_collect(term, data); return STATE_DCS_PARAM; + case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; case 0x7f: action_ignore(term); return STATE_DCS_ENTRY; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_ENTRY; @@ -872,35 +872,35 @@ state_dcs_entry_switch(struct terminal *term, uint8_t c) } static enum state -state_dcs_param_switch(struct terminal *term, uint8_t c) +state_dcs_param_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_PARAM; - case 0x20 ... 0x2f: action_collect(term, c); return STATE_DCS_INTERMEDIATE; - case 0x30 ... 0x39: action_param(term, c); return STATE_DCS_PARAM; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; + case 0x30 ... 0x39: action_param(term, data); return STATE_DCS_PARAM; case 0x3a: return STATE_DCS_IGNORE; - case 0x3b: action_param(term, c); return STATE_DCS_PARAM; + case 0x3b: action_param(term, data); return STATE_DCS_PARAM; case 0x3c ... 0x3f: return STATE_DCS_IGNORE; - case 0x40 ... 0x7e: action_hook(term, c); return STATE_DCS_PASSTHROUGH; + case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; case 0x7f: action_ignore(term); return STATE_DCS_PARAM; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_PARAM; @@ -908,32 +908,32 @@ state_dcs_param_switch(struct terminal *term, uint8_t c) } static enum state -state_dcs_intermediate_switch(struct terminal *term, uint8_t c) +state_dcs_intermediate_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x1f: action_ignore(term); return STATE_DCS_INTERMEDIATE; - case 0x20 ... 0x2f: action_collect(term, c); return STATE_DCS_INTERMEDIATE; + case 0x20 ... 0x2f: action_collect(term, data); return STATE_DCS_INTERMEDIATE; case 0x30 ... 0x3f: return STATE_DCS_IGNORE; - case 0x40 ... 0x7e: action_hook(term, c); return STATE_DCS_PASSTHROUGH; + case 0x40 ... 0x7e: action_hook(term, data); return STATE_DCS_PASSTHROUGH; case 0x7f: action_ignore(term); return STATE_DCS_INTERMEDIATE; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_INTERMEDIATE; @@ -941,9 +941,9 @@ state_dcs_intermediate_switch(struct terminal *term, uint8_t c) } static enum state -state_dcs_ignore_switch(struct terminal *term, uint8_t c) +state_dcs_ignore_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: @@ -951,18 +951,18 @@ state_dcs_ignore_switch(struct terminal *term, uint8_t c) case 0x20 ... 0x7f: action_ignore(term); return STATE_DCS_IGNORE; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_IGNORE; @@ -970,57 +970,57 @@ state_dcs_ignore_switch(struct terminal *term, uint8_t c) } static enum state -state_dcs_passthrough_switch(struct terminal *term, uint8_t c) +state_dcs_passthrough_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: - case 0x1c ... 0x7e: action_put(term, c); return STATE_DCS_PASSTHROUGH; + case 0x1c ... 0x7e: action_put(term, data); return STATE_DCS_PASSTHROUGH; case 0x7f: action_ignore(term); return STATE_DCS_PASSTHROUGH; /* Anywhere */ - case 0x18: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; - case 0x1a: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; - case 0x1b: action_unhook(term, c); action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; - case 0x90: action_unhook(term, c); action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; - case 0x98: action_unhook(term, c); return STATE_SOS_PM_APC_STRING; - case 0x99: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; - case 0x9a: action_unhook(term, c); action_execute(term, c); return STATE_GROUND; - case 0x9b: action_unhook(term, c); action_clear(term); return STATE_CSI_ENTRY; - case 0x9c: action_unhook(term, c); return STATE_GROUND; - case 0x9d: action_unhook(term, c); action_osc_start(term, c); return STATE_OSC_STRING; - case 0x9e ... 0x9f: action_unhook(term, c); return STATE_SOS_PM_APC_STRING; + case 0x18: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x1a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x1b: action_unhook(term, data); action_clear(term); return STATE_ESCAPE; + case 0x80 ... 0x8f: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x90: action_unhook(term, data); action_clear(term); return STATE_DCS_ENTRY; + case 0x91 ... 0x97: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x98: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; + case 0x99: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x9a: action_unhook(term, data); action_execute(term, data); return STATE_GROUND; + case 0x9b: action_unhook(term, data); action_clear(term); return STATE_CSI_ENTRY; + case 0x9c: action_unhook(term, data); return STATE_GROUND; + case 0x9d: action_unhook(term, data); action_osc_start(term, data); return STATE_OSC_STRING; + case 0x9e ... 0x9f: action_unhook(term, data); return STATE_SOS_PM_APC_STRING; default: return STATE_DCS_PASSTHROUGH; } } static enum state -state_sos_pm_apc_string_switch(struct terminal *term, uint8_t c) +state_sos_pm_apc_string_switch(struct terminal *term, uint8_t data) { - switch (c) { + switch (data) { /* exit current enter new state */ case 0x00 ... 0x17: case 0x19: case 0x1c ... 0x7f: action_ignore(term); return STATE_SOS_PM_APC_STRING; /* Anywhere */ - case 0x18: action_execute(term, c); return STATE_GROUND; - case 0x1a: action_execute(term, c); return STATE_GROUND; + case 0x18: action_execute(term, data); return STATE_GROUND; + case 0x1a: action_execute(term, data); return STATE_GROUND; case 0x1b: action_clear(term); return STATE_ESCAPE; - case 0x80 ... 0x8f: action_execute(term, c); return STATE_GROUND; + case 0x80 ... 0x8f: action_execute(term, data); return STATE_GROUND; case 0x90: action_clear(term); return STATE_DCS_ENTRY; - case 0x91 ... 0x97: action_execute(term, c); return STATE_GROUND; + case 0x91 ... 0x97: action_execute(term, data); return STATE_GROUND; case 0x98: return STATE_SOS_PM_APC_STRING; - case 0x99: action_execute(term, c); return STATE_GROUND; - case 0x9a: action_execute(term, c); return STATE_GROUND; + case 0x99: action_execute(term, data); return STATE_GROUND; + case 0x9a: action_execute(term, data); return STATE_GROUND; case 0x9b: action_clear(term); return STATE_CSI_ENTRY; case 0x9c: return STATE_GROUND; - case 0x9d: action_osc_start(term, c); return STATE_OSC_STRING; + case 0x9d: action_osc_start(term, data); return STATE_OSC_STRING; case 0x9e ... 0x9f: return STATE_SOS_PM_APC_STRING; default: return STATE_SOS_PM_APC_STRING; @@ -1028,20 +1028,20 @@ state_sos_pm_apc_string_switch(struct terminal *term, uint8_t c) } static enum state -state_utf8_collect_1_switch(struct terminal *term, uint8_t c) +state_utf8_collect_1_switch(struct terminal *term, uint8_t data) { - term->vt.utf8.data[term->vt.utf8.idx++] = c; + term->vt.utf8.data[term->vt.utf8.idx++] = data; term->vt.utf8.left--; assert(term->vt.utf8.left == 0); - action_utf8_print(term, c); + action_utf8_print(term, data); return STATE_GROUND; } static enum state -state_utf8_collect_2_switch(struct terminal *term, uint8_t c) +state_utf8_collect_2_switch(struct terminal *term, uint8_t data) { - term->vt.utf8.data[term->vt.utf8.idx++] = c; + term->vt.utf8.data[term->vt.utf8.idx++] = data; term->vt.utf8.left--; assert(term->vt.utf8.left == 1); @@ -1049,51 +1049,44 @@ state_utf8_collect_2_switch(struct terminal *term, uint8_t c) } static enum state -state_utf8_collect_3_switch(struct terminal *term, uint8_t c) +state_utf8_collect_3_switch(struct terminal *term, uint8_t data) { - term->vt.utf8.data[term->vt.utf8.idx++] = c; + term->vt.utf8.data[term->vt.utf8.idx++] = data; term->vt.utf8.left--; assert(term->vt.utf8.left == 2); return STATE_UTF8_COLLECT_2; } -static inline enum state -vt_state_machine_progress(struct terminal *term, enum state current_state, uint8_t c) -{ - switch (current_state) { - case STATE_GROUND: return state_ground_switch(term, c); - case STATE_ESCAPE: return state_escape_switch(term, c); - case STATE_ESCAPE_INTERMEDIATE: return state_escape_intermediate_switch(term, c); - case STATE_CSI_ENTRY: return state_csi_entry_switch(term, c); - case STATE_CSI_PARAM: return state_csi_param_switch(term, c); - case STATE_CSI_INTERMEDIATE: return state_csi_intermediate_switch(term, c); - case STATE_CSI_IGNORE: return state_csi_ignore_switch(term, c); - case STATE_OSC_STRING: return state_osc_string_switch(term, c); - case STATE_DCS_ENTRY: return state_dcs_entry_switch(term, c); - case STATE_DCS_PARAM: return state_dcs_param_switch(term, c); - case STATE_DCS_INTERMEDIATE: return state_dcs_intermediate_switch(term, c); - case STATE_DCS_IGNORE: return state_dcs_ignore_switch(term, c); - case STATE_DCS_PASSTHROUGH: return state_dcs_passthrough_switch(term, c); - case STATE_SOS_PM_APC_STRING: return state_sos_pm_apc_string_switch(term, c); - - case STATE_UTF8_COLLECT_1: return state_utf8_collect_1_switch(term, c); - case STATE_UTF8_COLLECT_2: return state_utf8_collect_2_switch(term, c); - case STATE_UTF8_COLLECT_3: return state_utf8_collect_3_switch(term, c); - } - - assert(false); - return STATE_GROUND; -} - void vt_from_slave(struct terminal *term, const uint8_t *data, size_t len) { enum state current_state = term->vt.state; const uint8_t *p = data; - for (size_t i = 0; i < len; i++, p++) - current_state = vt_state_machine_progress(term, current_state, *p); + for (size_t i = 0; i < len; i++, p++) { + switch (current_state) { + case STATE_GROUND: current_state = state_ground_switch(term, *p); break; + case STATE_ESCAPE: current_state = state_escape_switch(term, *p); break; + case STATE_ESCAPE_INTERMEDIATE: current_state = state_escape_intermediate_switch(term, *p); break; + case STATE_CSI_ENTRY: current_state = state_csi_entry_switch(term, *p); break; + case STATE_CSI_PARAM: current_state = state_csi_param_switch(term, *p); break; + case STATE_CSI_INTERMEDIATE: current_state = state_csi_intermediate_switch(term, *p); break; + case STATE_CSI_IGNORE: current_state = state_csi_ignore_switch(term, *p); break; + case STATE_OSC_STRING: current_state = state_osc_string_switch(term, *p); break; + case STATE_DCS_ENTRY: current_state = state_dcs_entry_switch(term, *p); break; + case STATE_DCS_PARAM: current_state = state_dcs_param_switch(term, *p); break; + case STATE_DCS_INTERMEDIATE: current_state = state_dcs_intermediate_switch(term, *p); break; + case STATE_DCS_IGNORE: current_state = state_dcs_ignore_switch(term, *p); break; + case STATE_DCS_PASSTHROUGH: current_state = state_dcs_passthrough_switch(term, *p); break; + case STATE_SOS_PM_APC_STRING: current_state = state_sos_pm_apc_string_switch(term, *p); break; + + case STATE_UTF8_COLLECT_1: current_state = state_utf8_collect_1_switch(term, *p); break; + case STATE_UTF8_COLLECT_2: current_state = state_utf8_collect_2_switch(term, *p); break; + case STATE_UTF8_COLLECT_3: current_state = state_utf8_collect_3_switch(term, *p); break; + } + } + term->vt.state = current_state; }