7752
|
1 |
--- vte-0.11.11/src/vte.c 2004-11-05 11:32:07.000000000 +0530
|
|
2 |
+++ vte-0.11.11-new/src/vte.c 2004-11-05 11:55:19.350582000 +0530
|
|
3 |
@@ -1530,6 +1530,91 @@ vte_terminal_match_add(VteTerminal *term
|
|
4 |
return new_regex.tag;
|
|
5 |
}
|
|
6 |
|
|
7 |
+
|
|
8 |
+
|
|
9 |
+
|
|
10 |
+
|
|
11 |
+static gboolean find_url(const char *data, int cursor, int *start, int *end)
|
|
12 |
+{
|
|
13 |
+ const char *allowed = "-_$.+!*(),;:@&=/?~#%";
|
|
14 |
+ const char *trim = ".),";
|
|
15 |
+ const char *starts[] = { "news://", "telnet://", "nttp://", "file://",
|
|
16 |
+ "http://", "ftp://", "https://",
|
|
17 |
+ "www", "ftp" };
|
|
18 |
+ const int nstarts = sizeof(starts) / sizeof(*starts);
|
|
19 |
+ gboolean dot;
|
|
20 |
+ int i, j;
|
|
21 |
+
|
|
22 |
+ /* Back up to just after the most recent non-URL character. */
|
|
23 |
+ for (i = cursor; i > 0; i--) {
|
|
24 |
+ if (!isalnum(data[i - 1]) && !strchr(allowed, data[i - 1]))
|
|
25 |
+ break;
|
|
26 |
+ }
|
|
27 |
+
|
|
28 |
+ /* Find an appropriate beginning. */
|
|
29 |
+ for (; i <= cursor; i++) {
|
|
30 |
+ if (!strchr("fhntw", data[i]))
|
|
31 |
+ continue;
|
|
32 |
+ for (j = 0; j < nstarts; j++) {
|
|
33 |
+ if (strncmp(data + i, starts[j],
|
|
34 |
+ strlen(starts[j])) == 0)
|
|
35 |
+ break;
|
|
36 |
+ }
|
|
37 |
+ if (j < nstarts)
|
|
38 |
+ break;
|
|
39 |
+ }
|
|
40 |
+ if (i > cursor)
|
|
41 |
+ return FALSE;
|
|
42 |
+ *start = i;
|
|
43 |
+ i += strlen(starts[j]);
|
|
44 |
+
|
|
45 |
+ /* Find end of domain part. We must see at least one dot if
|
|
46 |
+ * our beginning wasn't a real URL scheme. */
|
|
47 |
+ dot = FALSE;
|
|
48 |
+ for (; data[i]; i++) {
|
|
49 |
+ if (data[i] == '.')
|
|
50 |
+ dot = TRUE;
|
|
51 |
+ else if (!isalnum(data[i]) && data[i] != '-')
|
|
52 |
+ break;
|
|
53 |
+ }
|
|
54 |
+ if (!dot && !strchr(starts[j], ':'))
|
|
55 |
+ return FALSE;
|
|
56 |
+
|
|
57 |
+ if (data[i] == ':')
|
|
58 |
+ {
|
|
59 |
+ i++;
|
|
60 |
+ while (isdigit(data[i]))
|
|
61 |
+ i++;
|
|
62 |
+ }
|
|
63 |
+
|
|
64 |
+ /* If we've passed the cursor, then we only want this part. */
|
|
65 |
+ if (i > cursor) {
|
|
66 |
+ *end = i;
|
|
67 |
+ return TRUE;
|
|
68 |
+ }
|
|
69 |
+
|
|
70 |
+ if (data[i++] != '/')
|
|
71 |
+ return FALSE;
|
|
72 |
+
|
|
73 |
+ /* Find the end of the URL. */
|
|
74 |
+ for (; data[i]; i++) {
|
|
75 |
+ if (!isalnum(data[i]) && !strchr(allowed, data[i]))
|
|
76 |
+ break;
|
|
77 |
+ }
|
|
78 |
+ if (i <= cursor)
|
|
79 |
+ return FALSE;
|
|
80 |
+
|
|
81 |
+ /* If the last character looks like ending punctuation, trim it. */
|
|
82 |
+ *end = (strchr(trim, data[i - 1]) != NULL) ? i - 1 : i;
|
|
83 |
+ return TRUE;
|
|
84 |
+}
|
|
85 |
+
|
|
86 |
+
|
|
87 |
+
|
|
88 |
+
|
|
89 |
+
|
|
90 |
+
|
|
91 |
+
|
|
92 |
/**
|
|
93 |
* vte_terminal_match_set_cursor:
|
|
94 |
* @terminal: a #VteTerminal
|
|
95 |
@@ -1590,7 +1675,7 @@ vte_terminal_match_check_internal(VteTer
|
|
96 |
long column, glong row,
|
|
97 |
int *tag, int *start, int *end)
|
|
98 |
{
|
|
99 |
- int i, j, ret, offset;
|
|
100 |
+ int i, j, ret, offset, st, en;
|
|
101 |
struct vte_match_regex *regex = NULL;
|
|
102 |
struct _VteCharAttributes *attr = NULL;
|
|
103 |
gssize coffset;
|
|
104 |
@@ -1655,98 +1740,17 @@ vte_terminal_match_check_internal(VteTer
|
|
105 |
return NULL;
|
|
106 |
}
|
|
107 |
|
|
108 |
- /* Now iterate over each regex we need to match against. */
|
|
109 |
- for (i = 0; i < terminal->pvt->match_regexes->len; i++) {
|
|
110 |
- regex = &g_array_index(terminal->pvt->match_regexes,
|
|
111 |
- struct vte_match_regex,
|
|
112 |
- i);
|
|
113 |
- /* Skip holes. */
|
|
114 |
- if (regex->tag < 0) {
|
|
115 |
- continue;
|
|
116 |
- }
|
|
117 |
- /* We'll only match the first item in the buffer which
|
|
118 |
- * matches, so we'll have to skip each match until we
|
|
119 |
- * stop getting matches. */
|
|
120 |
- coffset = 0;
|
|
121 |
- ret = _vte_regex_exec(regex->reg,
|
|
122 |
- terminal->pvt->match_contents + coffset,
|
|
123 |
- G_N_ELEMENTS(matches),
|
|
124 |
- matches);
|
|
125 |
- while (ret == 0) {
|
|
126 |
- for (j = 0;
|
|
127 |
- (j < G_N_ELEMENTS(matches)) &&
|
|
128 |
- (matches[j].rm_so != -1);
|
|
129 |
- j++) {
|
|
130 |
- /* The offsets should be "sane". */
|
|
131 |
- g_assert(matches[j].rm_so + coffset <
|
|
132 |
- terminal->pvt->match_attributes->len);
|
|
133 |
- g_assert(matches[j].rm_eo + coffset <=
|
|
134 |
- terminal->pvt->match_attributes->len);
|
|
135 |
-#ifdef VTE_DEBUG
|
|
136 |
- if (_vte_debug_on(VTE_DEBUG_MISC)) {
|
|
137 |
- char *match;
|
|
138 |
- struct _VteCharAttributes *sattr, *eattr;
|
|
139 |
- match = g_strndup(terminal->pvt->match_contents + matches[j].rm_so + coffset,
|
|
140 |
- matches[j].rm_eo - matches[j].rm_so);
|
|
141 |
- sattr = &g_array_index(terminal->pvt->match_attributes,
|
|
142 |
- struct _VteCharAttributes,
|
|
143 |
- matches[j].rm_so + coffset);
|
|
144 |
- eattr = &g_array_index(terminal->pvt->match_attributes,
|
|
145 |
- struct _VteCharAttributes,
|
|
146 |
- matches[j].rm_eo + coffset - 1);
|
|
147 |
- fprintf(stderr, "Match %d `%s' from %d(%ld,%ld) to %d(%ld,%ld) (%d).\n",
|
|
148 |
- j, match,
|
|
149 |
- matches[j].rm_so + coffset,
|
|
150 |
- sattr->column,
|
|
151 |
- sattr->row,
|
|
152 |
- matches[j].rm_eo + coffset - 1,
|
|
153 |
- eattr->column,
|
|
154 |
- eattr->row,
|
|
155 |
- offset);
|
|
156 |
- g_free(match);
|
|
157 |
+
|
|
158 |
+ if (find_url(terminal->pvt->match_contents, offset, &st, &en)) {
|
|
159 |
+ if (tag)
|
|
160 |
+ *tag = 0;
|
|
161 |
+ if (start)
|
|
162 |
+ *start = st;
|
|
163 |
+ if (end)
|
|
164 |
+ *end = en - 1;
|
|
165 |
+ return g_strndup(terminal->pvt->match_contents + st, en - st);
|
|
166 |
|
|
167 |
}
|
|
168 |
-#endif
|
|
169 |
- /* Snip off any final newlines. */
|
|
170 |
- while ((matches[j].rm_eo > matches[j].rm_so) &&
|
|
171 |
- (terminal->pvt->match_contents[coffset + matches[j].rm_eo - 1] == '\n')) {
|
|
172 |
- matches[j].rm_eo--;
|
|
173 |
- }
|
|
174 |
- /* If the pointer is in this substring,
|
|
175 |
- * then we're done. */
|
|
176 |
- if ((offset >= (matches[j].rm_so + coffset)) &&
|
|
177 |
- (offset < (matches[j].rm_eo + coffset))) {
|
|
178 |
- if (tag != NULL) {
|
|
179 |
- *tag = regex->tag;
|
|
180 |
- }
|
|
181 |
- if (start != NULL) {
|
|
182 |
- *start = coffset +
|
|
183 |
- matches[j].rm_so;
|
|
184 |
- }
|
|
185 |
- if (end != NULL) {
|
|
186 |
- *end = coffset +
|
|
187 |
- matches[j].rm_eo - 1;
|
|
188 |
- }
|
|
189 |
- if (GTK_WIDGET_REALIZED(GTK_WIDGET(terminal))) {
|
|
190 |
- gdk_window_set_cursor((GTK_WIDGET(terminal))->window,
|
|
191 |
- regex->cursor);
|
|
192 |
- }
|
|
193 |
- terminal->pvt->match_previous = regex->tag;
|
|
194 |
- return g_strndup(terminal->pvt->match_contents + coffset + matches[j].rm_so,
|
|
195 |
- matches[j].rm_eo - matches[j].rm_so);
|
|
196 |
- }
|
|
197 |
- }
|
|
198 |
- /* Skip past the beginning of this match to
|
|
199 |
- * look for more. */
|
|
200 |
- coffset += (matches[0].rm_so + 1);
|
|
201 |
- ret = _vte_regex_exec(regex->reg,
|
|
202 |
- terminal->pvt->match_contents +
|
|
203 |
- coffset,
|
|
204 |
- G_N_ELEMENTS(matches),
|
|
205 |
- matches);
|
|
206 |
- }
|
|
207 |
- }
|
|
208 |
- terminal->pvt->match_previous = -1;
|
|
209 |
return NULL;
|
|
210 |
}
|
|
211 |
|
|
212 |
@@ -11832,6 +11836,7 @@ vte_terminal_finalize(GObject *object)
|
|
213 |
terminal);
|
|
214 |
g_object_unref(G_OBJECT(terminal->pvt->pty_reaper));
|
|
215 |
}
|
|
216 |
+ terminal->pvt->pty_pid = -1;
|
|
217 |
terminal->pvt->pty_reaper = NULL;
|
|
218 |
|
|
219 |
/* Stop processing input. */
|