linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 4/9] vt: selection, localize use_unicode
Date: Wed, 19 Feb 2020 08:39:46 +0100	[thread overview]
Message-ID: <20200219073951.16151-4-jslaby@suse.cz> (raw)
In-Reply-To: <20200219073951.16151-1-jslaby@suse.cz>

use_unicode needs not be global. It is used only in set_selection_kernel
and sel_pos (a callee). It is also always set there prior calling
sel_pos. So make use_unicode local and rename it to plain shorter
"unicode". Finally, propagate it to sel_pos via parameter.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/vt/selection.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c
index 6541c09d8bba..33f94293f45e 100644
--- a/drivers/tty/vt/selection.c
+++ b/drivers/tty/vt/selection.c
@@ -41,7 +41,6 @@ extern void poke_blanked_console(void);
 /* Variables for selection control. */
 /* Use a dynamic buffer, instead of static (Dec 1994) */
 struct vc_data *sel_cons;		/* must not be deallocated */
-static int use_unicode;
 static volatile int sel_start = -1; 	/* cleared by clear_selection */
 static int sel_end;
 static int sel_buffer_lth;
@@ -64,9 +63,9 @@ static inline void highlight_pointer(const int where)
 }
 
 static u32
-sel_pos(int n)
+sel_pos(int n, bool unicode)
 {
-	if (use_unicode)
+	if (unicode)
 		return screen_glyph_unicode(sel_cons, n / 2);
 	return inverse_translate(sel_cons, screen_glyph(sel_cons, n),
 				0);
@@ -194,6 +193,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 	int i, ps, pe;
 	u32 c;
 	int ret = 0;
+	bool unicode;
 
 	poke_blanked_console();
 
@@ -224,7 +224,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 		clear_selection();
 		sel_cons = vc_cons[fg_console].d;
 	}
-	use_unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
+	unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
 
 	switch (v->sel_mode)
 	{
@@ -233,21 +233,21 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 			new_sel_end = pe;
 			break;
 		case TIOCL_SELWORD:	/* word-by-word selection */
-			spc = isspace(sel_pos(ps));
+			spc = isspace(sel_pos(ps, unicode));
 			for (new_sel_start = ps; ; ps -= 2)
 			{
-				if ((spc && !isspace(sel_pos(ps))) ||
-				    (!spc && !inword(sel_pos(ps))))
+				if ((spc && !isspace(sel_pos(ps, unicode))) ||
+				    (!spc && !inword(sel_pos(ps, unicode))))
 					break;
 				new_sel_start = ps;
 				if (!(ps % vc->vc_size_row))
 					break;
 			}
-			spc = isspace(sel_pos(pe));
+			spc = isspace(sel_pos(pe, unicode));
 			for (new_sel_end = pe; ; pe += 2)
 			{
-				if ((spc && !isspace(sel_pos(pe))) ||
-				    (!spc && !inword(sel_pos(pe))))
+				if ((spc && !isspace(sel_pos(pe, unicode))) ||
+				    (!spc && !inword(sel_pos(pe, unicode))))
 					break;
 				new_sel_end = pe;
 				if (!((pe + 2) % vc->vc_size_row))
@@ -273,12 +273,12 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 	/* select to end of line if on trailing space */
 	if (new_sel_end > new_sel_start &&
 		!atedge(new_sel_end, vc->vc_size_row) &&
-		isspace(sel_pos(new_sel_end))) {
+		isspace(sel_pos(new_sel_end, unicode))) {
 		for (pe = new_sel_end + 2; ; pe += 2)
-			if (!isspace(sel_pos(pe)) ||
+			if (!isspace(sel_pos(pe, unicode)) ||
 			    atedge(pe, vc->vc_size_row))
 				break;
-		if (isspace(sel_pos(pe)))
+		if (isspace(sel_pos(pe, unicode)))
 			new_sel_end = pe;
 	}
 	if (sel_start == -1)	/* no current selection */
@@ -309,7 +309,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 
 	/* Allocate a new buffer before freeing the old one ... */
 	/* chars can take up to 4 bytes with unicode */
-	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, use_unicode ? 4 : 1,
+	bp = kmalloc_array((sel_end - sel_start) / 2 + 1, unicode ? 4 : 1,
 			   GFP_KERNEL);
 	if (!bp) {
 		printk(KERN_WARNING "selection: kmalloc() failed\n");
@@ -322,8 +322,8 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
 
 	obp = bp;
 	for (i = sel_start; i <= sel_end; i += 2) {
-		c = sel_pos(i);
-		if (use_unicode)
+		c = sel_pos(i, unicode);
+		if (unicode)
 			bp += store_utf8(c, bp);
 		else
 			*bp++ = c;
-- 
2.25.0


  parent reply	other threads:[~2020-02-19  7:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19  7:39 [PATCH 1/9] vt: selection, introduce vc_is_sel Jiri Slaby
2020-02-19  7:39 ` [PATCH 2/9] vt: ioctl, switch VT_IS_IN_USE and VT_BUSY to inlines Jiri Slaby
2020-02-19  7:39 ` [PATCH 3/9] vt: selection, remove 2 local variables from set_selection_kernel Jiri Slaby
2020-02-21  9:32   ` Greg KH
2020-02-24  9:26     ` Jiri Slaby
2020-03-06  7:37       ` Greg KH
2020-02-19  7:39 ` Jiri Slaby [this message]
2020-02-19  7:39 ` [PATCH 5/9] vt: selection, create struct from console selection globals Jiri Slaby
2020-02-19  7:39 ` [PATCH 6/9] vt: switch vt_dont_switch to bool Jiri Slaby
2020-02-19  7:39 ` [PATCH 7/9] vt: vt_kern.h, remove extern from functions Jiri Slaby
2020-02-19  7:39 ` [PATCH 8/9] vt: selection, remove redeclaration of poke_blanked_console Jiri Slaby
2020-02-19  7:39 ` [PATCH 9/9] vt: selection, indent switch-case properly Jiri Slaby

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=20200219073951.16151-4-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --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;
as well as URLs for NNTP newsgroup(s).