summaryrefslogtreecommitdiff
path: root/drivers/tty/vt
diff options
context:
space:
mode:
authorJiri Slaby (SUSE) <jirislaby@kernel.org>2024-02-02 09:55:57 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-02-06 17:37:38 +0300
commitce66f8e387cda44e01a0db4d506b1d0a130d5005 (patch)
tree0e7944a00ecb402b92f9f375eb8871d994f8eb21 /drivers/tty/vt
parenta8ccce55a8d87df4013ac277ed382e8cbf672a96 (diff)
downloadlinux-ce66f8e387cda44e01a0db4d506b1d0a130d5005.tar.xz
tty: vt: extract ascii handling to handle_ascii()
To make the do_con_trol() a bit more understandable, extract the ASCII handling (the switch-case) to a separate function. Other nested switch-cases will follow in the next patches. Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org> Link: https://lore.kernel.org/r/20240202065608.14019-12-jirislaby@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/vt')
-rw-r--r--drivers/tty/vt/vt.c58
1 files changed, 37 insertions, 21 deletions
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 451a852ed234..7cda1a958c5e 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -2197,28 +2197,26 @@ enum {
ASCII_EXT_CSI = 128 + ASCII_ESCAPE,
};
-/* console_lock is held */
-static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
+/*
+ * Handle ascii characters in control sequences and change states accordingly.
+ * E.g. ESC sets the state of vc to ESesc.
+ *
+ * Returns: true if @c handled.
+ */
+static bool handle_ascii(struct tty_struct *tty, struct vc_data *vc, u8 c)
{
- /*
- * Control characters can be used in the _middle_
- * of an escape sequence, aside from ANSI control strings.
- */
- if (ansi_control_string(vc->vc_state) && c >= ASCII_IGNORE_FIRST &&
- c <= ASCII_IGNORE_LAST)
- return;
switch (c) {
case ASCII_NULL:
- return;
+ return true;
case ASCII_BELL:
if (ansi_control_string(vc->vc_state))
vc->vc_state = ESnormal;
else if (vc->vc_bell_duration)
kd_mksound(vc->vc_bell_pitch, vc->vc_bell_duration);
- return;
+ return true;
case ASCII_BACKSPACE:
bs(vc);
- return;
+ return true;
case ASCII_HTAB:
vc->vc_pos -= (vc->state.x << 1);
@@ -2230,41 +2228,59 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
vc->vc_pos += (vc->state.x << 1);
notify_write(vc, '\t');
- return;
+ return true;
case ASCII_LINEFEED:
case ASCII_VTAB:
case ASCII_FORMFEED:
lf(vc);
if (!is_kbd(vc, lnm))
- return;
+ return true;
fallthrough;
case ASCII_CAR_RET:
cr(vc);
- return;
+ return true;
case ASCII_SHIFTOUT:
vc->state.charset = 1;
vc->vc_translate = set_translate(vc->state.Gx_charset[1], vc);
vc->vc_disp_ctrl = 1;
- return;
+ return true;
case ASCII_SHIFTIN:
vc->state.charset = 0;
vc->vc_translate = set_translate(vc->state.Gx_charset[0], vc);
vc->vc_disp_ctrl = 0;
- return;
+ return true;
case ASCII_CANCEL:
case ASCII_SUBSTITUTE:
vc->vc_state = ESnormal;
- return;
+ return true;
case ASCII_ESCAPE:
vc->vc_state = ESesc;
- return;
+ return true;
case ASCII_DEL:
del(vc);
- return;
+ return true;
case ASCII_EXT_CSI:
vc->vc_state = ESsquare;
- return;
+ return true;
}
+
+ return false;
+}
+
+/* console_lock is held */
+static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
+{
+ /*
+ * Control characters can be used in the _middle_
+ * of an escape sequence, aside from ANSI control strings.
+ */
+ if (ansi_control_string(vc->vc_state) && c >= ASCII_IGNORE_FIRST &&
+ c <= ASCII_IGNORE_LAST)
+ return;
+
+ if (handle_ascii(tty, vc, c))
+ return;
+
switch(vc->vc_state) {
case ESesc:
vc->vc_state = ESnormal;