diff options
Diffstat (limited to 'drivers/tty/vt/selection.c')
-rw-r--r-- | drivers/tty/vt/selection.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/drivers/tty/vt/selection.c b/drivers/tty/vt/selection.c index 90ea1cc52b7a..07496c711d7d 100644 --- a/drivers/tty/vt/selection.c +++ b/drivers/tty/vt/selection.c @@ -57,11 +57,13 @@ static inline void highlight_pointer(const int where) complement_pos(sel_cons, where); } -static u16 +static u32 sel_pos(int n) { + if (use_unicode) + return screen_glyph_unicode(sel_cons, n / 2); return inverse_translate(sel_cons, screen_glyph(sel_cons, n), - use_unicode); + 0); } /** @@ -90,7 +92,8 @@ static u32 inwordLut[]={ 0x07FFFFFE, /* lowercase */ }; -static inline int inword(const u16 c) { +static inline int inword(const u32 c) +{ return c > 0x7f || (( inwordLut[c>>5] >> (c & 0x1F) ) & 1); } @@ -116,14 +119,8 @@ static inline int atedge(const int p, int size_row) return (!(p % size_row) || !((p + 2) % size_row)); } -/* constrain v such that v <= u */ -static inline unsigned short limit(const unsigned short v, const unsigned short u) -{ - return (v > u) ? u : v; -} - -/* stores the char in UTF8 and returns the number of bytes used (1-3) */ -static int store_utf8(u16 c, char *p) +/* stores the char in UTF8 and returns the number of bytes used (1-4) */ +static int store_utf8(u32 c, char *p) { if (c < 0x80) { /* 0******* */ @@ -134,13 +131,26 @@ static int store_utf8(u16 c, char *p) p[0] = 0xc0 | (c >> 6); p[1] = 0x80 | (c & 0x3f); return 2; - } else { + } else if (c < 0x10000) { /* 1110**** 10****** 10****** */ p[0] = 0xe0 | (c >> 12); p[1] = 0x80 | ((c >> 6) & 0x3f); p[2] = 0x80 | (c & 0x3f); return 3; - } + } else if (c < 0x110000) { + /* 11110*** 10****** 10****** 10****** */ + p[0] = 0xf0 | (c >> 18); + p[1] = 0x80 | ((c >> 12) & 0x3f); + p[2] = 0x80 | ((c >> 6) & 0x3f); + p[3] = 0x80 | (c & 0x3f); + return 4; + } else { + /* outside Unicode, replace with U+FFFD */ + p[0] = 0xef; + p[1] = 0xbf; + p[2] = 0xbd; + return 3; + } } /** @@ -160,17 +170,17 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t struct tiocl_selection v; char *bp, *obp; int i, ps, pe, multiplier; - u16 c; + u32 c; int mode; poke_blanked_console(); if (copy_from_user(&v, sel, sizeof(*sel))) return -EFAULT; - v.xs = limit(v.xs - 1, vc->vc_cols - 1); - v.ys = limit(v.ys - 1, vc->vc_rows - 1); - v.xe = limit(v.xe - 1, vc->vc_cols - 1); - v.ye = limit(v.ye - 1, vc->vc_rows - 1); + v.xs = min_t(u16, v.xs - 1, vc->vc_cols - 1); + v.ys = min_t(u16, v.ys - 1, vc->vc_rows - 1); + v.xe = min_t(u16, v.xe - 1, vc->vc_cols - 1); + v.ye = min_t(u16, v.ye - 1, vc->vc_rows - 1); ps = v.ys * vc->vc_size_row + (v.xs << 1); pe = v.ye * vc->vc_size_row + (v.xe << 1); @@ -279,7 +289,7 @@ int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *t sel_end = new_sel_end; /* Allocate a new buffer before freeing the old one ... */ - multiplier = use_unicode ? 3 : 1; /* chars can take up to 3 bytes */ + multiplier = use_unicode ? 4 : 1; /* chars can take up to 4 bytes */ bp = kmalloc_array((sel_end - sel_start) / 2 + 1, multiplier, GFP_KERNEL); if (!bp) { |