12 #include <linux/module.h>
13 #include <linux/tty.h>
14 #include <linux/sched.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
19 #include <asm/uaccess.h>
29 #define isspace(c) ((c) == ' ')
37 static int use_unicode;
38 static volatile int sel_start = -1;
40 static int sel_buffer_lth;
41 static char *sel_buffer;
47 static inline void highlight(
const int s,
const int e)
53 static inline void highlight_pointer(
const int where)
73 highlight_pointer(-1);
74 if (sel_start != -1) {
75 highlight(sel_start, sel_end);
84 static u32 inwordLut[8]={
95 static inline int inword(
const u16 c) {
96 return c > 0xff || (( inwordLut[c>>5] >> (c & 0x1F) ) & 1);
111 memcpy(inwordLut, tmplut, 32);
116 static inline int atedge(
const int p,
int size_row)
118 return (!(p % size_row) || !((p + 2) % size_row));
122 static inline unsigned short limit(
const unsigned short v,
const unsigned short u)
124 return (v > u) ? u :
v;
128 static int store_utf8(
u16 c,
char *p)
134 }
else if (c < 0x800) {
136 p[0] = 0xc0 | (c >> 6);
137 p[1] = 0x80 | (c & 0x3f);
141 p[0] = 0xe0 | (c >> 12);
142 p[1] = 0x80 | ((c >> 6) & 0x3f);
143 p[2] = 0x80 | (c & 0x3f);
161 int sel_mode, new_sel_start, new_sel_end,
spc;
163 int i,
ps, pe, multiplier;
178 xs--; ys--; xe--; ye--;
223 for (new_sel_start = ps; ; ps -= 2)
225 if ((spc && !
isspace(sel_pos(ps))) ||
226 (!spc && !inword(sel_pos(ps))))
233 for (new_sel_end = pe; ; pe += 2)
235 if ((spc && !
isspace(sel_pos(pe))) ||
236 (!spc && !inword(sel_pos(pe))))
249 highlight_pointer(pe);
256 highlight_pointer(-1);
259 if (new_sel_end > new_sel_start &&
261 isspace(sel_pos(new_sel_end))) {
262 for (pe = new_sel_end + 2; ; pe += 2)
270 highlight(new_sel_start, new_sel_end);
271 else if (new_sel_start == sel_start)
273 if (new_sel_end == sel_end)
275 else if (new_sel_end > sel_end)
276 highlight(sel_end + 2, new_sel_end);
278 highlight(new_sel_end + 2, sel_end);
280 else if (new_sel_end == sel_end)
282 if (new_sel_start < sel_start)
283 highlight(new_sel_start, sel_start - 2);
285 highlight(sel_start, new_sel_start - 2);
290 highlight(new_sel_start, new_sel_end);
292 sel_start = new_sel_start;
293 sel_end = new_sel_end;
296 multiplier = use_unicode ? 3 : 1;
307 for (i = sel_start; i <= sel_end; i += 2) {
310 bp += store_utf8(c, bp);
325 sel_buffer_lth = bp - sel_buffer;
356 while (sel_buffer && sel_buffer_lth > pasted) {
362 count = sel_buffer_lth - pasted;
364 tty->
ldisc->ops->receive_buf(tty, sel_buffer + pasted,