Commit 555b4ef7 authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman

vt: selection, localize use_unicode

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: default avatarJiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20200219073951.16151-4-jslaby@suse.czSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 101f227c
...@@ -41,7 +41,6 @@ extern void poke_blanked_console(void); ...@@ -41,7 +41,6 @@ extern void poke_blanked_console(void);
/* Variables for selection control. */ /* Variables for selection control. */
/* Use a dynamic buffer, instead of static (Dec 1994) */ /* Use a dynamic buffer, instead of static (Dec 1994) */
struct vc_data *sel_cons; /* must not be deallocated */ struct vc_data *sel_cons; /* must not be deallocated */
static int use_unicode;
static volatile int sel_start = -1; /* cleared by clear_selection */ static volatile int sel_start = -1; /* cleared by clear_selection */
static int sel_end; static int sel_end;
static int sel_buffer_lth; static int sel_buffer_lth;
...@@ -64,9 +63,9 @@ static inline void highlight_pointer(const int where) ...@@ -64,9 +63,9 @@ static inline void highlight_pointer(const int where)
} }
static u32 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 screen_glyph_unicode(sel_cons, n / 2);
return inverse_translate(sel_cons, screen_glyph(sel_cons, n), return inverse_translate(sel_cons, screen_glyph(sel_cons, n),
0); 0);
...@@ -194,6 +193,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty) ...@@ -194,6 +193,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
int i, ps, pe; int i, ps, pe;
u32 c; u32 c;
int ret = 0; int ret = 0;
bool unicode;
poke_blanked_console(); poke_blanked_console();
...@@ -224,7 +224,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty) ...@@ -224,7 +224,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
clear_selection(); clear_selection();
sel_cons = vc_cons[fg_console].d; 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) switch (v->sel_mode)
{ {
...@@ -233,21 +233,21 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty) ...@@ -233,21 +233,21 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
new_sel_end = pe; new_sel_end = pe;
break; break;
case TIOCL_SELWORD: /* word-by-word selection */ 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) for (new_sel_start = ps; ; ps -= 2)
{ {
if ((spc && !isspace(sel_pos(ps))) || if ((spc && !isspace(sel_pos(ps, unicode))) ||
(!spc && !inword(sel_pos(ps)))) (!spc && !inword(sel_pos(ps, unicode))))
break; break;
new_sel_start = ps; new_sel_start = ps;
if (!(ps % vc->vc_size_row)) if (!(ps % vc->vc_size_row))
break; break;
} }
spc = isspace(sel_pos(pe)); spc = isspace(sel_pos(pe, unicode));
for (new_sel_end = pe; ; pe += 2) for (new_sel_end = pe; ; pe += 2)
{ {
if ((spc && !isspace(sel_pos(pe))) || if ((spc && !isspace(sel_pos(pe, unicode))) ||
(!spc && !inword(sel_pos(pe)))) (!spc && !inword(sel_pos(pe, unicode))))
break; break;
new_sel_end = pe; new_sel_end = pe;
if (!((pe + 2) % vc->vc_size_row)) if (!((pe + 2) % vc->vc_size_row))
...@@ -273,12 +273,12 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty) ...@@ -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 */ /* select to end of line if on trailing space */
if (new_sel_end > new_sel_start && if (new_sel_end > new_sel_start &&
!atedge(new_sel_end, vc->vc_size_row) && !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) 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)) atedge(pe, vc->vc_size_row))
break; break;
if (isspace(sel_pos(pe))) if (isspace(sel_pos(pe, unicode)))
new_sel_end = pe; new_sel_end = pe;
} }
if (sel_start == -1) /* no current selection */ if (sel_start == -1) /* no current selection */
...@@ -309,7 +309,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty) ...@@ -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 ... */ /* Allocate a new buffer before freeing the old one ... */
/* chars can take up to 4 bytes with unicode */ /* 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); GFP_KERNEL);
if (!bp) { if (!bp) {
printk(KERN_WARNING "selection: kmalloc() failed\n"); printk(KERN_WARNING "selection: kmalloc() failed\n");
...@@ -322,8 +322,8 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty) ...@@ -322,8 +322,8 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
obp = bp; obp = bp;
for (i = sel_start; i <= sel_end; i += 2) { for (i = sel_start; i <= sel_end; i += 2) {
c = sel_pos(i); c = sel_pos(i, unicode);
if (use_unicode) if (unicode)
bp += store_utf8(c, bp); bp += store_utf8(c, bp);
else else
*bp++ = c; *bp++ = c;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment