summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2012-07-13 09:12:01 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-07-13 09:12:01 +0000
commit89251d17d7e9427141397bd13c406dffbabe5620 (patch)
tree880e74b52e1c52db7c38eedf312903e377a42488 /src/bin
parent7b8304692b6380e672a7b0f25097fed50c9219db (diff)
factor out link finding algorithm to its own file.
SVN revision: 73800
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/Makefile.am1
-rw-r--r--src/bin/termio.c212
-rw-r--r--src/bin/termio.h3
-rw-r--r--src/bin/termiolink.c181
-rw-r--r--src/bin/termiolink.h2
5 files changed, 211 insertions, 188 deletions
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index 4f2f0f8..f2dec31 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -25,6 +25,7 @@ options_video.c options_video.h \
25options_theme.c options_theme.h \ 25options_theme.c options_theme.h \
26options_wallpaper.c options_wallpaper.h \ 26options_wallpaper.c options_wallpaper.h \
27termio.c termio.h \ 27termio.c termio.h \
28termiolink.c termiolink.h \
28termpty.c termpty.h \ 29termpty.c termpty.h \
29termptydbl.c termptydbl.h \ 30termptydbl.c termptydbl.h \
30termptyesc.c termptyesc.h \ 31termptyesc.c termptyesc.h \
diff --git a/src/bin/termio.c b/src/bin/termio.c
index d31cb97..5d7792d 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -4,6 +4,7 @@
4#include <Elementary.h> 4#include <Elementary.h>
5#include <Ecore_Input.h> 5#include <Ecore_Input.h>
6#include "termio.h" 6#include "termio.h"
7#include "termiolink.h"
7#include "termpty.h" 8#include "termpty.h"
8#include "utf8.h" 9#include "utf8.h"
9#include "col.h" 10#include "col.h"
@@ -76,193 +77,6 @@ static Evas_Smart_Class _parent_sc = EVAS_SMART_CLASS_INIT_NULL;
76 77
77static void _smart_calculate(Evas_Object *obj); 78static void _smart_calculate(Evas_Object *obj);
78 79
79static Eina_Bool
80coord_back(Termio *sd, int *x, int *y)
81{
82 (*x)--;
83 if ((*x) < 0)
84 {
85 if ((*y) <= 0)
86 {
87 (*x)++;
88 return EINA_FALSE;
89 }
90 (*x) = sd->grid.w - 1;
91 (*y)--;
92 }
93 return EINA_TRUE;
94}
95
96static Eina_Bool
97coord_forward(Termio *sd, int *x, int *y)
98{
99 (*x)++;
100 if ((*x) >= sd->grid.w)
101 {
102 if ((*y) >= (sd->grid.h - 1))
103 {
104 (*x)--;
105 return EINA_FALSE;
106 }
107 (*x) = 0;
108 (*y)++;
109 }
110 return EINA_TRUE;
111}
112
113static char *
114_magic_string_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r, int *y2r)
115{
116 Termio *sd = evas_object_smart_data_get(obj);
117 char *s;
118 char endmatch = 0;
119 int x1, x2, y1, y2, len;
120 Eina_Bool goback = EINA_TRUE, goforward = EINA_FALSE, extend = EINA_FALSE;
121
122 if (!sd) return NULL;
123 x1 = cx;
124 y1 = cy;
125 x2 = cx;
126 y2 = cy;
127 if (!coord_back(sd, &x1, &y1)) goback = EINA_FALSE;
128 for (;;)
129 {
130 s = termio_selection_get(obj,
131 x1, y1 - sd->scroll,
132 x2, y2 - sd->scroll);
133 if (!s) break;
134 if (goback)
135 {
136 if ((!strncasecmp(s, "http://", 7))||
137 (!strncasecmp(s, "https://", 8)) ||
138 (!strncasecmp(s, "file://", 7)) ||
139 (!strncasecmp(s, "ftp://", 6)))
140 {
141 goback = EINA_FALSE;
142 coord_back(sd, &x1, &y1);
143 free(s);
144 s = termio_selection_get(obj,
145 x1, y1 - sd->scroll,
146 x2, y2 - sd->scroll);
147 if (!s) break;
148 if (s[0] == '"') endmatch = '"';
149 else if (s[0] == '\'') endmatch = '\'';
150 else if (s[0] == '<') endmatch = '>';
151 coord_forward(sd, &x1, &y1);
152 free(s);
153 s = termio_selection_get(obj,
154 x1, y1 - sd->scroll,
155 x2, y2 - sd->scroll);
156 if (!s) break;
157 }
158 else if ((isspace(s[0])) ||
159 (s[0] == '"') ||
160 (s[0] == '\'') ||
161 (s[0] == '<') ||
162 (s[0] == '='))
163 {
164 if (s[0] == '"') endmatch = '"';
165 else if (s[0] == '\'') endmatch = '\'';
166 else if (s[0] == '<') endmatch = '>';
167 if ((!strncasecmp((s + 1), "www.", 4)) ||
168 (!strncasecmp((s + 1), "ftp.", 4)) ||
169 (!strncasecmp((s + 1), "/", 1)))
170 {
171 goback = EINA_FALSE;
172 coord_forward(sd, &x1, &y1);
173 }
174 else if (strchr((s + 2), '@'))
175 {
176 goback = EINA_FALSE;
177 coord_forward(sd, &x1, &y1);
178 }
179 else if (s[0] == '=')
180 {
181 }
182 else
183 {
184 free(s);
185 s = NULL;
186 break;
187 }
188 }
189 }
190 if (goforward)
191 {
192 len = strlen(s);
193 if (len > 1)
194 {
195 if (((endmatch) && (s[len - 1] == endmatch)) ||
196 ((!endmatch) &&
197 ((isspace(s[len - 1])) || (s[len - 1] == '>'))
198 ))
199 {
200 goforward = EINA_FALSE;
201 coord_back(sd, &x2, &y2);
202 }
203 }
204 }
205
206 if (goforward)
207 {
208 if (!coord_forward(sd, &x2, &y2)) goforward = EINA_FALSE;
209 }
210 if (goback)
211 {
212 if (!coord_back(sd, &x1, &y1)) goback = EINA_FALSE;
213 }
214 if ((!extend) && (!goback))
215 {
216 goforward = EINA_TRUE;
217 extend = EINA_TRUE;
218 }
219 if ((!goback) && (!goforward))
220 {
221 free(s);
222 s = termio_selection_get(obj,
223 x1, y1 - sd->scroll,
224 x2, y2 - sd->scroll);
225 break;
226 }
227 free(s);
228 s = NULL;
229 }
230 if (s)
231 {
232 len = strlen(s);
233 while (len > 1)
234 {
235 if (isspace(s[len - 1]))
236 {
237 s[len - 1] = 0;
238 len--;
239 }
240 else break;
241 }
242 if ((!isspace(s[0])) && (len > 1))
243 {
244 if ((strchr(s, '@')) ||
245 (!strncasecmp(s, "http://", 7))||
246 (!strncasecmp(s, "https://", 8)) ||
247 (!strncasecmp(s, "ftp://", 6)) ||
248 (!strncasecmp(s, "file://", 7)) ||
249 (!strncasecmp(s, "www.", 4)) ||
250 (!strncasecmp(s, "ftp.", 4)) ||
251 (!strncasecmp(s, "/", 1))
252 )
253 {
254 if (x1r) *x1r = x1;
255 if (y1r) *y1r = y1;
256 if (x2r) *x2r = x2;
257 if (y2r) *y2r = y2;
258 return s;
259 }
260 }
261 free(s);
262 }
263 return NULL;
264}
265
266static void 80static void
267_activate_link(Evas_Object *obj) 81_activate_link(Evas_Object *obj)
268{ 82{
@@ -511,7 +325,7 @@ _smart_mouseover_apply(Evas_Object *obj)
511 325
512 if (!sd) return; 326 if (!sd) return;
513 327
514 s = _magic_string_find(obj, sd->mouse.cx, sd->mouse.cy, 328 s = _termio_link_find(obj, sd->mouse.cx, sd->mouse.cy,
515 &x1, &y1, &x2, &y2); 329 &x1, &y1, &x2, &y2);
516 if (!s) 330 if (!s)
517 { 331 {
@@ -2530,3 +2344,25 @@ termio_mouseover_suspend_pushpop(Evas_Object *obj, int dir)
2530 if (sd->link.suspend < 0) sd->link.suspend = 0; 2344 if (sd->link.suspend < 0) sd->link.suspend = 0;
2531 _smart_update_queue(obj, sd); 2345 _smart_update_queue(obj, sd);
2532} 2346}
2347
2348void
2349termio_size_get(Evas_Object *obj, int *w, int *h)
2350{
2351 Termio *sd = evas_object_smart_data_get(obj);
2352 if (!sd)
2353 {
2354 if (w) *w = 0;
2355 if (h) *h = 0;
2356 return;
2357 }
2358 if (w) *w = sd->grid.w;
2359 if (h) *h = sd->grid.h;
2360}
2361
2362int
2363termio_scroll_get(Evas_Object *obj)
2364{
2365 Termio *sd = evas_object_smart_data_get(obj);
2366 if (!sd) return 0;
2367 return sd->scroll;
2368}
diff --git a/src/bin/termio.h b/src/bin/termio.h
index 108d535..781a69e 100644
--- a/src/bin/termio.h
+++ b/src/bin/termio.h
@@ -12,4 +12,7 @@ void termio_copy_clipboard(Evas_Object *obj);
12void termio_paste_clipboard(Evas_Object *obj); 12void termio_paste_clipboard(Evas_Object *obj);
13const char *termio_link_get(const Evas_Object *obj); 13const char *termio_link_get(const Evas_Object *obj);
14void termio_mouseover_suspend_pushpop(Evas_Object *obj, int dir); 14void termio_mouseover_suspend_pushpop(Evas_Object *obj, int dir);
15void termio_size_get(Evas_Object *obj, int *w, int *h);
16int termio_scroll_get(Evas_Object *obj);
17
15#endif 18#endif
diff --git a/src/bin/termiolink.c b/src/bin/termiolink.c
new file mode 100644
index 0000000..4bd6c84
--- /dev/null
+++ b/src/bin/termiolink.c
@@ -0,0 +1,181 @@
1#include "private.h"
2#include <Elementary.h>
3#include "termio.h"
4
5static Eina_Bool
6coord_back(int *x, int *y, int w, int h __UNUSED__)
7{
8 (*x)--;
9 if ((*x) < 0)
10 {
11 if ((*y) <= 0)
12 {
13 (*x)++;
14 return EINA_FALSE;
15 }
16 (*x) = w - 1;
17 (*y)--;
18 }
19 return EINA_TRUE;
20}
21
22static Eina_Bool
23coord_forward(int *x, int *y, int w, int h)
24{
25 (*x)++;
26 if ((*x) >= w)
27 {
28 if ((*y) >= (h - 1))
29 {
30 (*x)--;
31 return EINA_FALSE;
32 }
33 (*x) = 0;
34 (*y)++;
35 }
36 return EINA_TRUE;
37}
38
39char *
40_termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r, int *y2r)
41{
42 char *s;
43 char endmatch = 0;
44 int x1, x2, y1, y2, len, w = 0, h = 0, sc;
45 Eina_Bool goback = EINA_TRUE, goforward = EINA_FALSE, extend = EINA_FALSE;
46
47 x1 = x2 = cx;
48 y1 = y2 = cy;
49 termio_size_get(obj, &w, &h);
50 sc = termio_scroll_get(obj);
51 if ((w <= 0) || (h <= 0)) return NULL;
52 if (!coord_back(&x1, &y1, w, h)) goback = EINA_FALSE;
53 for (;;)
54 {
55 s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc);
56 if (!s) break;
57 if (goback)
58 {
59 if ((!strncasecmp(s, "http://", 7))||
60 (!strncasecmp(s, "https://", 8)) ||
61 (!strncasecmp(s, "file://", 7)) ||
62 (!strncasecmp(s, "ftp://", 6)))
63 {
64 goback = EINA_FALSE;
65 coord_back(&x1, &y1, w, h);
66 free(s);
67 s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc);
68 if (!s) break;
69 if (s[0] == '"') endmatch = '"';
70 else if (s[0] == '\'') endmatch = '\'';
71 else if (s[0] == '<') endmatch = '>';
72 coord_forward(&x1, &y1, w, h);
73 free(s);
74 s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc);
75 if (!s) break;
76 }
77 else if ((isspace(s[0])) ||
78 (s[0] == '"') ||
79 (s[0] == '\'') ||
80 (s[0] == '<') ||
81 (s[0] == '='))
82 {
83 if (s[0] == '"') endmatch = '"';
84 else if (s[0] == '\'') endmatch = '\'';
85 else if (s[0] == '<') endmatch = '>';
86 if ((!strncasecmp((s + 1), "www.", 4)) ||
87 (!strncasecmp((s + 1), "ftp.", 4)) ||
88 (!strncasecmp((s + 1), "/", 1)))
89 {
90 goback = EINA_FALSE;
91 coord_forward(&x1, &y1, w, h);
92 }
93 else if (strchr((s + 2), '@'))
94 {
95 goback = EINA_FALSE;
96 coord_forward(&x1, &y1, w, h);
97 }
98 else if (s[0] == '=')
99 {
100 }
101 else
102 {
103 free(s);
104 s = NULL;
105 break;
106 }
107 }
108 }
109 if (goforward)
110 {
111 len = strlen(s);
112 if (len > 1)
113 {
114 if (((endmatch) && (s[len - 1] == endmatch)) ||
115 ((!endmatch) &&
116 ((isspace(s[len - 1])) || (s[len - 1] == '>'))
117 ))
118 {
119 goforward = EINA_FALSE;
120 coord_back(&x2, &y2, w, h);
121 }
122 }
123 }
124
125 if (goforward)
126 {
127 if (!coord_forward(&x2, &y2, w, h)) goforward = EINA_FALSE;
128 }
129 if (goback)
130 {
131 if (!coord_back(&x1, &y1, w, h)) goback = EINA_FALSE;
132 }
133 if ((!extend) && (!goback))
134 {
135 goforward = EINA_TRUE;
136 extend = EINA_TRUE;
137 }
138 if ((!goback) && (!goforward))
139 {
140 free(s);
141 s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc);
142 break;
143 }
144 free(s);
145 s = NULL;
146 }
147 if (s)
148 {
149 len = strlen(s);
150 while (len > 1)
151 {
152 if (isspace(s[len - 1]))
153 {
154 s[len - 1] = 0;
155 len--;
156 }
157 else break;
158 }
159 if ((!isspace(s[0])) && (len > 1))
160 {
161 if ((strchr(s, '@')) ||
162 (!strncasecmp(s, "http://", 7))||
163 (!strncasecmp(s, "https://", 8)) ||
164 (!strncasecmp(s, "ftp://", 6)) ||
165 (!strncasecmp(s, "file://", 7)) ||
166 (!strncasecmp(s, "www.", 4)) ||
167 (!strncasecmp(s, "ftp.", 4)) ||
168 (!strncasecmp(s, "/", 1))
169 )
170 {
171 if (x1r) *x1r = x1;
172 if (y1r) *y1r = y1;
173 if (x2r) *x2r = x2;
174 if (y2r) *y2r = y2;
175 return s;
176 }
177 }
178 free(s);
179 }
180 return NULL;
181}
diff --git a/src/bin/termiolink.h b/src/bin/termiolink.h
new file mode 100644
index 0000000..c082a5f
--- /dev/null
+++ b/src/bin/termiolink.h
@@ -0,0 +1,2 @@
1char *_termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r, int *y2r);
2