mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Subject: [PATCH 15/22] tty: vt: name, reflow and document enum vc_ctl_state
Date: Fri,  2 Feb 2024 07:56:01 +0100	[thread overview]
Message-ID: <20240202065608.14019-16-jirislaby@kernel.org> (raw)
In-Reply-To: <20240202065608.14019-1-jirislaby@kernel.org>

The enum for states is currently compact and undocumented. Put each
definition on a separate line and document them all using kernel-doc.

Document the same on the use sites.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
---
 drivers/tty/vt/vt.c | 72 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 55 insertions(+), 17 deletions(-)

diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 1c832d04c0dc..6d08290fdfdf 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -2091,9 +2091,44 @@ static void restore_cur(struct vc_data *vc)
 	vc->vc_need_wrap = 0;
 }
 
-enum { ESnormal, ESesc, ESsquare, ESgetpars, ESfunckey,
-	EShash, ESsetG0, ESsetG1, ESpercent, EScsiignore, ESnonstd,
-	ESpalette, ESosc, ESapc, ESpm, ESdcs };
+/**
+ * enum vc_ctl_state - control characters state of a vt
+ *
+ * @ESnormal:		initial state, no control characters parsed
+ * @ESesc:		ESC parsed
+ * @ESsquare:		CSI parsed -- modifiers/parameters/ctrl chars expected
+ * @ESgetpars:		CSI parsed -- parameters/ctrl chars expected
+ * @ESfunckey:		CSI [ parsed
+ * @EShash:		ESC # parsed
+ * @ESsetG0:		ESC ( parsed
+ * @ESsetG1:		ESC ) parsed
+ * @ESpercent:		ESC % parsed
+ * @EScsiignore:	CSI [0x20-0x3f] parsed
+ * @ESnonstd:		OSC parsed
+ * @ESpalette:		OSC P parsed
+ * @ESosc:		OSC [0-9] parsed
+ * @ESapc:		ESC _ parsed
+ * @ESpm:		ESC ^ parsed
+ * @ESdcs:		ESC P parsed
+ */
+enum vc_ctl_state {
+	ESnormal,
+	ESesc,
+	ESsquare,
+	ESgetpars,
+	ESfunckey,
+	EShash,
+	ESsetG0,
+	ESsetG1,
+	ESpercent,
+	EScsiignore,
+	ESnonstd,
+	ESpalette,
+	ESosc,
+	ESapc,
+	ESpm,
+	ESdcs,
+};
 
 /* console_lock is held (except via vc_init()) */
 static void reset_terminal(struct vc_data *vc, int do_clear)
@@ -2527,10 +2562,10 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
 		return;
 
 	switch(vc->vc_state) {
-	case ESesc:
+	case ESesc:	/* ESC */
 		handle_esc(tty, vc, c);
 		return;
-	case ESnonstd:
+	case ESnonstd:	/* ESC ] aka OSC */
 		if (c=='P') {   /* palette escape sequence */
 			for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
 				vc->vc_par[vc->vc_npar] = 0;
@@ -2545,7 +2580,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
 		else
 			vc->vc_state = ESnormal;
 		return;
-	case ESpalette:
+	case ESpalette:	/* ESC ] P aka OSC P */
 		if (isxdigit(c)) {
 			vc->vc_par[vc->vc_npar++] = hex_to_bin(c);
 			if (vc->vc_npar == 7) {
@@ -2562,7 +2597,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
 		} else
 			vc->vc_state = ESnormal;
 		return;
-	case ESsquare:
+	case ESsquare:	/* ESC [ aka CSI, parameters or modifiers expected */
 		for (vc->vc_npar = 0; vc->vc_npar < NPAR; vc->vc_npar++)
 			vc->vc_par[vc->vc_npar] = 0;
 		vc->vc_npar = 0;
@@ -2587,7 +2622,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
 		}
 		vc->vc_priv = EPecma;
 		fallthrough;
-	case ESgetpars:
+	case ESgetpars: /* ESC [ aka CSI, parameters expected */
 		if (c == ';' && vc->vc_npar < NPAR - 1) {
 			vc->vc_npar++;
 			return;
@@ -2600,6 +2635,9 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
 			vc->vc_state = EScsiignore;
 			return;
 		}
+
+		/* parameters done, handle the control char @c */
+
 		vc->vc_state = ESnormal;
 
 		switch (vc->vc_priv) {
@@ -2617,7 +2655,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
 			return;
 		vc->vc_state = ESnormal;
 		return;
-	case ESpercent:
+	case ESpercent:	/* ESC % */
 		vc->vc_state = ESnormal;
 		switch (c) {
 		case '@':  /* defined in ISO 2022 */
@@ -2629,10 +2667,10 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
 			return;
 		}
 		return;
-	case ESfunckey:
+	case ESfunckey:	/* ESC [ [ aka CSI [ */
 		vc->vc_state = ESnormal;
 		return;
-	case EShash:
+	case EShash:	/* ESC # */
 		vc->vc_state = ESnormal;
 		if (c == '8') {
 			/* DEC screen alignment test. kludge :-) */
@@ -2644,21 +2682,21 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, u8 c)
 			do_update_region(vc, vc->vc_origin, vc->vc_screenbuf_size / 2);
 		}
 		return;
-	case ESsetG0:
+	case ESsetG0:	/* ESC ( */
 		vc_setGx(vc, 0, c);
 		vc->vc_state = ESnormal;
 		return;
-	case ESsetG1:
+	case ESsetG1:	/* ESC ) */
 		vc_setGx(vc, 1, c);
 		vc->vc_state = ESnormal;
 		return;
-	case ESapc:
+	case ESapc:	/* ESC _ */
 		return;
-	case ESosc:
+	case ESosc:	/* ESC ] [0-9] aka OSC [0-9] */
 		return;
-	case ESpm:
+	case ESpm:	/* ESC ^ */
 		return;
-	case ESdcs:
+	case ESdcs:	/* ESC P */
 		return;
 	default:
 		vc->vc_state = ESnormal;
-- 
2.43.0


  parent reply	other threads:[~2024-02-02  6:56 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02  6:55 [PATCH 00/22] tty: vt: cleanup ESC sequences handling Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 01/22] tty: vt: make rgb_from_256() slighly more comprehensible Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 02/22] tty: vt: define enums for CSI+h/l codes Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 03/22] tty: vt: rename set_mode() to csi_hl() Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 04/22] tty: vt: split DEC CSI+h/l handling into csi_DEC_hl() Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 05/22] tty: vt: remove unneeded assignment of EPecma to vc_priv Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 06/22] tty: vt: move CSI+n handling along to other ECMA CSIs Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 07/22] tty: vt: define an enum for CSI+] codes Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 08/22] tty: vt: rename setterm_command() to csi_RSB() Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 09/22] tty: vt: put cases on separate lines Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 10/22] tty: vt: accept u8 in do_con_trol() and vc_setGx() Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 11/22] tty: vt: extract ascii handling to handle_ascii() Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 12/22] tty: vt: separate ESesc state handling into handle_esc() Jiri Slaby (SUSE)
2024-02-02  6:55 ` [PATCH 13/22] tty: vt: move CSI DEC handling to a separate function Jiri Slaby (SUSE)
2024-02-02  6:56 ` [PATCH 14/22] tty: vt: move CSI ECMA " Jiri Slaby (SUSE)
2024-02-02  6:56 ` Jiri Slaby (SUSE) [this message]
2024-02-02  6:56 ` [PATCH 16/22] tty: vt: simplify ansi_control_string() Jiri Slaby (SUSE)
2024-02-02  6:56 ` [PATCH 17/22] tty: vt: handle CSI+[ inside preexisting switch-case Jiri Slaby (SUSE)
2024-02-02  6:56 ` [PATCH 18/22] tty: vt: add new helper for reseting vc parameters Jiri Slaby (SUSE)
2024-02-02  6:56 ` [PATCH 19/22] tty: vt: use switch+case in the ESnonstd case Jiri Slaby (SUSE)
2024-02-02  6:56 ` [PATCH 20/22] tty: vt: use switch+case in the ESgetpars case Jiri Slaby (SUSE)
2024-02-02  6:56 ` [PATCH 21/22] tty: vt: use ASCII enum constants in vt_console_print() Jiri Slaby (SUSE)
2024-02-02  6:56 ` [PATCH 22/22] tty: vt: decrypt magic constants in vc_is_control() Jiri Slaby (SUSE)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240202065608.14019-16-jirislaby@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®