Mercurial > pidgin
annotate src/gtkspell.c @ 2563:29d09f9ce85f
[gaim-migrate @ 2576]
Fixed an unused variable warning.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Sun, 21 Oct 2001 00:14:41 +0000 |
parents | 9cee43e4903d |
children | f6f2871d77c2 |
rev | line source |
---|---|
1117 | 1 /* gtkspell - a spell-checking addon for GtkText |
2 * Copyright (c) 2000 Evan Martin. | |
3 * vim: ts=4 sw=4 | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Lesser General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Lesser General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Lesser General Public | |
15 * License along with this library; if not, write to the Free Software | |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
17 */ | |
18 | |
19 #include <gtk/gtk.h> | |
20 | |
21 #include <sys/types.h> | |
22 #include <sys/wait.h> | |
23 #include <sys/time.h> | |
24 #include <unistd.h> | |
25 #include <stdio.h> | |
26 #include <signal.h> | |
27 #include <ctype.h> | |
28 #include <string.h> | |
29 #include <stdlib.h> | |
30 #include <errno.h> | |
31 | |
32 /* TODO: | |
33 * handle dictionary changes | |
34 * asynchronous lookups | |
35 */ | |
36 | |
37 /* size of the text buffer used in various word-processing routines. */ | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
38 /* #define BUFSIZE 1024 */ |
1117 | 39 /* number of suggestions to display on each menu. */ |
40 #define MENUCOUNT 10 | |
41 #define BUGEMAIL "gtkspell-devel@lists.sourceforge.net" | |
42 | |
43 /* because we keep only one copy of the spell program running, | |
44 * all ispell-related variables can be static. | |
45 */ | |
46 static pid_t spell_pid = -1; | |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
47 static int fd_write[2] = {0}, fd_read[2] = {0}; |
1117 | 48 static int signal_set_up = 0; |
49 | |
50 /* FIXME? */ | |
51 static GdkColor highlight = { 0, 255*256, 0, 0 }; | |
52 | |
53 static void entry_insert_cb(GtkText *gtktext, | |
54 gchar *newtext, guint len, guint *ppos, gpointer d); | |
55 static void set_up_signal(); | |
56 | |
57 int gtkspell_running() { | |
58 return (spell_pid > 0); | |
59 } | |
60 | |
1794
60b3fd819cce
[gaim-migrate @ 1804]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1496
diff
changeset
|
61 /* |
1117 | 62 static void error_print(const char *fmt, ...) { |
63 va_list ap; | |
64 va_start(ap, fmt); | |
65 fprintf(stderr, "gtkspell: "); | |
66 vfprintf(stderr, fmt, ap); | |
67 va_end(ap); | |
68 } | |
1794
60b3fd819cce
[gaim-migrate @ 1804]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1496
diff
changeset
|
69 */ |
1815
f15d449b3167
[gaim-migrate @ 1825]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1794
diff
changeset
|
70 extern void debug_printf(char *, ...); |
1794
60b3fd819cce
[gaim-migrate @ 1804]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1496
diff
changeset
|
71 #define error_print debug_printf |
1117 | 72 |
73 /* functions to interface with pipe */ | |
74 static void writetext(char *text) { | |
75 write(fd_write[1], text, strlen(text)); | |
76 } | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
77 |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
78 static char *readline() { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
79 int len = 1024; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
80 gchar *buf = g_malloc(len); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
81 int pos = 0; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
82 do { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
83 int val = read(fd_read[0], buf + pos, 1); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
84 if (val <= 0) { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
85 error_print("read: %s\n", strerror(errno)); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
86 g_free(buf); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
87 return NULL; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
88 } |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
89 pos += val; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
90 if (pos == len) { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
91 len *= 2; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
92 buf = g_realloc(buf, len); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
93 } |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
94 } while (buf[pos - 1] != '\n'); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
95 |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
96 buf = g_realloc(buf, pos + 1); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
97 buf[pos] = 0; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
98 return buf; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
99 } |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
100 |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
101 static char *readresponse() { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
102 char *r1, *r2, *result; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
103 |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
104 r1 = readline(); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
105 if (!r1) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
106 return NULL; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
107 if (*r1 == '\n') { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
108 g_strchomp(r1); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
109 return r1; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
110 } |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
111 r2 = readline(); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
112 if (!r2) { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
113 g_free(r1); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
114 return NULL; |
1117 | 115 } |
116 | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
117 while (r2 && *r2 != '\n') { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
118 char *tmp = r1; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
119 r1 = g_strconcat(tmp, r2, NULL); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
120 g_free(tmp); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
121 g_free(r2); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
122 r2 = readline(); |
1117 | 123 } |
124 | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
125 if (!r2) { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
126 g_free(r1); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
127 return NULL; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
128 } |
1117 | 129 |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
130 result = g_strconcat(r1, r2, NULL); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
131 g_free(r1); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
132 g_free(r2); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
133 g_strchomp(result); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
134 return result; |
1117 | 135 } |
136 | |
137 | |
138 void gtkspell_stop() { | |
139 if (gtkspell_running()) { | |
1415
3dfd2a83fb5e
[gaim-migrate @ 1425]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1127
diff
changeset
|
140 kill(spell_pid, SIGHUP); |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
141 spell_pid = 0; |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
142 close(fd_read[0]); |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
143 close(fd_write[1]); |
1117 | 144 } |
145 } | |
146 | |
147 int gtkspell_start(char *path, char * args[]) { | |
148 int fd_error[2]; | |
149 | |
150 if (gtkspell_running()) { | |
151 error_print("gtkspell_start called while already running.\n"); | |
152 gtkspell_stop(); | |
153 } | |
154 | |
155 if (!signal_set_up) { | |
156 set_up_signal(); | |
157 signal_set_up = 1; | |
158 } | |
159 | |
160 pipe(fd_write); | |
161 pipe(fd_read); | |
162 pipe(fd_error); | |
163 | |
164 spell_pid = fork(); | |
165 if (spell_pid < 0) { | |
166 error_print("fork: %s\n", strerror(errno)); | |
167 return -1; | |
168 } else if (spell_pid == 0) { | |
169 dup2(fd_write[0], 0); | |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
170 close(fd_write[0]); |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
171 close(fd_write[1]); |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
172 |
1117 | 173 dup2(fd_read[1], 1); |
174 close(fd_read[0]); | |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
175 close(fd_read[1]); |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
176 |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
177 dup2(fd_error[1], 2); |
1117 | 178 close(fd_error[0]); |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
179 close(fd_error[1]); |
1117 | 180 |
181 if (path == NULL) { | |
182 if (execvp(args[0], args) < 0) | |
183 error_print("execvp('%s'): %s\n", args[0], strerror(errno)); | |
184 } else { | |
185 if (execv(path, args) < 0) | |
186 error_print("execv('%s'): %s\n", path, strerror(errno)); | |
187 } | |
188 /* if we get here, we failed. | |
189 * send some text on the pipe to indicate status. | |
190 */ | |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
191 write(0, "!", 1); /* stdout _is_ the pipe. */ |
1117 | 192 |
193 _exit(0); | |
194 } else { | |
195 /* there are at least two ways to fail: | |
196 * - the exec() can fail | |
197 * - the exec() can succeed, but the program can dump the help screen | |
198 * we must check for both. | |
199 */ | |
200 fd_set rfds; | |
201 struct timeval tv; | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
202 char *buf; |
1117 | 203 |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
204 close(fd_write[0]); |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
205 close(fd_read[1]); |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
206 |
1117 | 207 FD_ZERO(&rfds); |
208 FD_SET(fd_error[0], &rfds); | |
209 FD_SET(fd_read[0], &rfds); | |
210 tv.tv_sec = 2; | |
211 tv.tv_usec = 0; | |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
212 |
1117 | 213 if (select(MAX(fd_error[0], fd_read[0])+1, |
214 &rfds, NULL, NULL, &tv) < 0) { | |
215 /* FIXME: is this needed? */ | |
216 error_print("Timed out waiting for spell command.\n"); | |
217 gtkspell_stop(); | |
218 return -1; | |
219 } | |
220 | |
221 if (FD_ISSET(fd_error[0], &rfds)) { /* stderr readable? */ | |
222 error_print("Spell command printed on stderr -- probably failed.\n"); | |
223 gtkspell_stop(); | |
224 return -1; | |
225 } | |
226 | |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
227 /* we're done with stderr, now. */ |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
228 close(fd_error[0]); |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
229 close(fd_error[1]); |
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
230 |
1117 | 231 /* otherwise, fd_read[0] is set. */ |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
232 buf = readline(); |
1117 | 233 |
234 /* ispell should print something like this: | |
235 * @(#) International Ispell Version 3.1.20 10/10/95 | |
236 * if it doesn't, it's an error. */ | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
237 if (!buf || buf[0] != '@') { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
238 if (buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
239 g_free(buf); |
1117 | 240 gtkspell_stop(); |
241 return -1; | |
242 } | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
243 g_free(buf); |
1117 | 244 } |
245 | |
246 /* put ispell into terse mode. | |
247 * this makes it not respond on correctly spelled words. */ | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
248 writetext("!\n"); |
1117 | 249 return 0; |
250 } | |
251 | |
252 static GList* misspelled_suggest(char *word) { | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
253 char *buf; |
1117 | 254 char *newword; |
255 GList *l = NULL; | |
256 int count; | |
257 | |
2461
0edec72bc72f
[gaim-migrate @ 2474]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2457
diff
changeset
|
258 if (!word) |
0edec72bc72f
[gaim-migrate @ 2474]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2457
diff
changeset
|
259 return NULL; |
0edec72bc72f
[gaim-migrate @ 2474]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2457
diff
changeset
|
260 |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
261 buf = g_strdup_printf("^%s\n", word); /* guard against ispell control chars */ |
1117 | 262 writetext(buf); |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
263 g_free(buf); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
264 buf = readresponse(); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
265 |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
266 if (!buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
267 return NULL; |
1117 | 268 |
269 switch (buf[0]) { /* first char is ispell command. */ | |
270 case 0: /* no response: word is ok. */ | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
271 g_free(buf); |
1117 | 272 return NULL; |
273 case '&': /* misspelled, with suggestions */ | |
274 /* & <orig> <count> <ofs>: <miss>, <miss>, <guess>, ... */ | |
275 strtok(buf, " "); /* & */ | |
276 newword = strtok(NULL, " "); /* orig */ | |
277 l = g_list_append(l, g_strdup(newword)); | |
278 newword = strtok(NULL, " "); /* count */ | |
279 count = atoi(newword); | |
280 strtok(NULL, " "); /* ofs: */ | |
281 | |
282 while ((newword = strtok(NULL, ",")) != NULL) { | |
283 int len = strlen(newword); | |
284 if (newword[len-1] == ' ' || newword[len-1] == '\n') | |
285 newword[len-1] = 0; | |
286 if (count == 0) { | |
287 g_list_append(l, NULL); /* signal the "suggestions" */ | |
288 } | |
289 /* add it to the list, skipping the initial space. */ | |
290 l = g_list_append(l, | |
291 g_strdup(newword[0] == ' ' ? newword+1 : newword)); | |
292 | |
293 count--; | |
294 } | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
295 g_free(buf); |
1117 | 296 return l; |
297 | |
298 case '#': /* misspelled, no suggestions */ | |
1467
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1415
diff
changeset
|
299 case '?': /* ispell is guessing. */ |
1117 | 300 /* # <orig> <ofs> */ |
301 strtok(buf, " "); /* & */ | |
302 newword = strtok(NULL, " "); /* orig */ | |
303 l = g_list_append(l, g_strdup(newword)); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
304 g_free(buf); |
1117 | 305 return l; |
306 default: | |
307 error_print("Unsupported spell command '%c'.\n" | |
308 "This is a bug; mail " BUGEMAIL " about it.\n", buf[0]); | |
1467
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1415
diff
changeset
|
309 error_print("Input [%s]\nOutput [%s]\n", word, buf); |
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1415
diff
changeset
|
310 |
1117 | 311 } |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
312 g_free(buf); |
1117 | 313 return NULL; |
314 } | |
315 | |
316 static int misspelled_test(char *word) { | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
317 char *buf; |
2517
9cee43e4903d
[gaim-migrate @ 2530]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2461
diff
changeset
|
318 |
9cee43e4903d
[gaim-migrate @ 2530]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2461
diff
changeset
|
319 if (word == NULL) |
9cee43e4903d
[gaim-migrate @ 2530]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2461
diff
changeset
|
320 return 0; |
9cee43e4903d
[gaim-migrate @ 2530]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2461
diff
changeset
|
321 |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
322 buf = g_strdup_printf("^%s\n", word); /* guard against ispell control chars */ |
1117 | 323 writetext(buf); |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
324 g_free(buf); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
325 buf = readresponse(); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
326 |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
327 if (!buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
328 return 0; |
1117 | 329 |
330 if (buf[0] == 0) { | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
331 g_free(buf); |
1117 | 332 return 0; |
1467
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1415
diff
changeset
|
333 } else if (buf[0] == '&' || buf[0] == '#' || buf[0] == '?') { |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
334 g_free(buf); |
1117 | 335 return 1; |
336 } | |
337 | |
338 error_print("Unsupported spell command '%c'.\n" | |
339 "This is a bug; mail " BUGEMAIL " about it.\n", buf[0]); | |
1467
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1415
diff
changeset
|
340 error_print("Input [%s]\nOutput [%s]\n", word, buf); |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
341 g_free(buf); |
1117 | 342 return -1; |
343 } | |
344 | |
345 static gboolean iswordsep(char c) { | |
346 return !isalpha(c) && c != '\''; | |
347 } | |
348 | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
349 static gboolean get_word_from_pos(GtkText* gtktext, int pos, char** buf, |
1117 | 350 int *pstart, int *pend) { |
351 gint start, end; | |
352 | |
353 if (iswordsep(GTK_TEXT_INDEX(gtktext, pos))) return FALSE; | |
354 | |
355 for (start = pos; start >= 0; --start) { | |
356 if (iswordsep(GTK_TEXT_INDEX(gtktext, start))) break; | |
357 } | |
358 start++; | |
359 | |
360 for (end = pos; end <= gtk_text_get_length(gtktext); end++) { | |
361 if (iswordsep(GTK_TEXT_INDEX(gtktext, end))) break; | |
362 } | |
363 | |
2457
e6b9246b33fd
[gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2456
diff
changeset
|
364 if (buf && (end - start + 1 > 0)) { |
e6b9246b33fd
[gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2456
diff
changeset
|
365 *buf = g_malloc(end - start + 1); |
1117 | 366 for (pos = start; pos < end; pos++) |
2457
e6b9246b33fd
[gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2456
diff
changeset
|
367 (*buf)[pos-start] = GTK_TEXT_INDEX(gtktext, pos); |
e6b9246b33fd
[gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2456
diff
changeset
|
368 (*buf)[pos-start] = 0; |
1117 | 369 } |
370 | |
371 if (pstart) *pstart = start; | |
372 if (pend) *pend = end; | |
373 | |
374 return TRUE; | |
375 } | |
376 | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
377 static gboolean get_curword(GtkText* gtktext, char** buf, |
1117 | 378 int *pstart, int *pend) { |
379 int pos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
380 return get_word_from_pos(gtktext, pos, buf, pstart, pend); | |
381 } | |
382 | |
383 static void change_color(GtkText *gtktext, | |
384 int start, int end, GdkColor *color) { | |
385 char *newtext = gtk_editable_get_chars(GTK_EDITABLE(gtktext), start, end); | |
386 gtk_text_freeze(gtktext); | |
387 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), | |
388 GTK_SIGNAL_FUNC(entry_insert_cb), NULL); | |
389 | |
390 gtk_text_set_point(gtktext, start); | |
391 gtk_text_forward_delete(gtktext, end-start); | |
392 | |
393 if (newtext && end-start > 0) | |
394 gtk_text_insert(gtktext, NULL, color, NULL, newtext, end-start); | |
395 | |
396 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), | |
397 GTK_SIGNAL_FUNC(entry_insert_cb), NULL); | |
398 gtk_text_thaw(gtktext); | |
1415
3dfd2a83fb5e
[gaim-migrate @ 1425]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1127
diff
changeset
|
399 g_free(newtext); |
1117 | 400 } |
401 | |
402 static gboolean check_at(GtkText *gtktext, int from_pos) { | |
403 int start, end; | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
404 char *buf = NULL; |
1117 | 405 |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
406 if (!get_word_from_pos(gtktext, from_pos, &buf, &start, &end)) { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
407 if (buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
408 g_free(buf); |
1117 | 409 return FALSE; |
410 } | |
411 | |
412 if (misspelled_test(buf)) { | |
413 if (highlight.pixel == 0) { | |
414 /* add an entry for the highlight in the color map. */ | |
415 GdkColormap *gc = gtk_widget_get_colormap(GTK_WIDGET(gtktext)); | |
416 gdk_colormap_alloc_color(gc, &highlight, FALSE, TRUE);; | |
417 } | |
418 change_color(gtktext, start, end, &highlight); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
419 if (buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
420 g_free(buf); |
1117 | 421 return TRUE; |
422 } else { | |
423 change_color(gtktext, start, end, | |
424 &(GTK_WIDGET(gtktext)->style->fg[0])); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
425 if (buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
426 g_free(buf); |
1117 | 427 return FALSE; |
428 } | |
429 } | |
430 | |
431 void gtkspell_check_all(GtkText *gtktext) { | |
432 guint origpos; | |
433 guint pos = 0; | |
434 guint len; | |
435 float adj_value; | |
436 | |
437 if (!gtkspell_running()) return; | |
438 | |
439 len = gtk_text_get_length(gtktext); | |
440 | |
441 adj_value = gtktext->vadj->value; | |
442 gtk_text_freeze(gtktext); | |
443 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
444 while (pos < len) { | |
445 while (pos < len && iswordsep(GTK_TEXT_INDEX(gtktext, pos))) | |
446 pos++; | |
447 while (pos < len && !iswordsep(GTK_TEXT_INDEX(gtktext, pos))) | |
448 pos++; | |
449 if (pos > 0) | |
450 check_at(gtktext, pos-1); | |
451 } | |
452 gtk_text_thaw(gtktext); | |
453 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); | |
454 } | |
455 | |
456 static void entry_insert_cb(GtkText *gtktext, | |
457 gchar *newtext, guint len, guint *ppos, gpointer d) { | |
458 int origpos; | |
459 | |
460 if (!gtkspell_running()) return; | |
461 | |
462 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), | |
463 GTK_SIGNAL_FUNC(entry_insert_cb), | |
464 NULL); | |
465 gtk_text_insert(GTK_TEXT(gtktext), NULL, | |
466 &(GTK_WIDGET(gtktext)->style->fg[0]), NULL, newtext, len); | |
467 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), | |
468 GTK_SIGNAL_FUNC(entry_insert_cb), | |
469 NULL); | |
470 gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "insert-text"); | |
471 *ppos += len; | |
472 | |
473 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
474 | |
475 if (iswordsep(newtext[0])) { | |
476 /* did we just end a word? */ | |
477 if (*ppos >= 2) check_at(gtktext, *ppos-2); | |
478 | |
479 /* did we just split a word? */ | |
480 if (*ppos < gtk_text_get_length(gtktext)) | |
481 check_at(gtktext, *ppos+1); | |
482 } else { | |
483 /* check as they type, *except* if they're typing at the end (the most | |
484 * common case. | |
485 */ | |
486 if (*ppos < gtk_text_get_length(gtktext) && | |
487 !iswordsep(GTK_TEXT_INDEX(gtktext, *ppos))) | |
488 check_at(gtktext, *ppos-1); | |
489 } | |
490 | |
491 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); | |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
492 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos); |
1117 | 493 } |
494 | |
495 static void entry_delete_cb(GtkText *gtktext, | |
496 gint start, gint end, gpointer d) { | |
497 int origpos; | |
498 | |
499 if (!gtkspell_running()) return; | |
500 | |
501 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
502 check_at(gtktext, start-1); | |
503 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); | |
504 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos); | |
505 /* this is to *UNDO* the selection, in case they were holding shift | |
506 * while hitting backspace. */ | |
507 } | |
508 | |
509 static void replace_word(GtkWidget *w, gpointer d) { | |
510 int start, end; | |
511 char *newword; | |
512 | |
513 /* we don't save their position, | |
514 * because the cursor is moved by the click. */ | |
515 | |
516 gtk_text_freeze(GTK_TEXT(d)); | |
517 | |
518 gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), &newword); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
519 get_curword(GTK_TEXT(d), NULL, &start, &end); |
1117 | 520 |
521 gtk_text_set_point(GTK_TEXT(d), end); | |
522 gtk_text_backward_delete(GTK_TEXT(d), end-start); | |
523 gtk_text_insert(GTK_TEXT(d), NULL, NULL, NULL, newword, strlen(newword)); | |
524 | |
525 gtk_text_thaw(GTK_TEXT(d)); | |
526 } | |
527 | |
528 static GtkMenu *make_menu(GList *l, GtkText *gtktext) { | |
529 GtkWidget *menu, *item; | |
530 char *caption; | |
531 menu = gtk_menu_new(); { | |
532 caption = g_strdup_printf("Not in dictionary: %s", (char*)l->data); | |
533 item = gtk_menu_item_new_with_label(caption); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
534 g_free(caption); |
1117 | 535 /* I'd like to make it so this item is never selectable, like |
536 * the menu titles in the GNOME panel... unfortunately, the GNOME | |
537 * panel creates their own custom widget to do this! */ | |
538 gtk_widget_show(item); | |
539 gtk_menu_append(GTK_MENU(menu), item); | |
540 | |
541 item = gtk_menu_item_new(); | |
542 gtk_widget_show(item); | |
543 gtk_menu_append(GTK_MENU(menu), item); | |
544 | |
545 l = l->next; | |
546 if (l == NULL) { | |
547 item = gtk_menu_item_new_with_label("(no suggestions)"); | |
548 gtk_widget_show(item); | |
549 gtk_menu_append(GTK_MENU(menu), item); | |
550 } else { | |
551 GtkWidget *curmenu = menu; | |
552 int count = 0; | |
553 do { | |
554 if (l->data == NULL && l->next != NULL) { | |
555 count = 0; | |
556 curmenu = gtk_menu_new(); | |
557 item = gtk_menu_item_new_with_label("Other Possibilities..."); | |
558 gtk_widget_show(item); | |
559 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu); | |
560 gtk_menu_append(GTK_MENU(curmenu), item); | |
561 l = l->next; | |
562 } else if (count > MENUCOUNT) { | |
563 count -= MENUCOUNT; | |
564 item = gtk_menu_item_new_with_label("More..."); | |
565 gtk_widget_show(item); | |
566 gtk_menu_append(GTK_MENU(curmenu), item); | |
567 curmenu = gtk_menu_new(); | |
568 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu); | |
569 } | |
570 item = gtk_menu_item_new_with_label((char*)l->data); | |
571 gtk_signal_connect(GTK_OBJECT(item), "activate", | |
572 GTK_SIGNAL_FUNC(replace_word), gtktext); | |
573 gtk_widget_show(item); | |
574 gtk_menu_append(GTK_MENU(curmenu), item); | |
575 count++; | |
576 } while ((l = l->next) != NULL); | |
577 } | |
578 } | |
579 return GTK_MENU(menu); | |
580 } | |
581 | |
582 static void popup_menu(GtkText *gtktext, GdkEventButton *eb) { | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
583 char *buf = NULL; |
1117 | 584 GList *list, *l; |
585 | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
586 get_curword(gtktext, &buf, NULL, NULL); |
1117 | 587 |
588 list = misspelled_suggest(buf); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
589 if (buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
590 g_free(buf); |
1117 | 591 if (list != NULL) { |
592 gtk_menu_popup(make_menu(list, gtktext), NULL, NULL, NULL, NULL, | |
593 eb->button, eb->time); | |
594 for (l = list; l != NULL; l = l->next) | |
595 g_free(l->data); | |
596 g_list_free(list); | |
597 } | |
598 } | |
599 | |
600 /* ok, this is pretty wacky: | |
601 * we need to let the right-mouse-click go through, so it moves the cursor, | |
602 * but we *can't* let it go through, because GtkText interprets rightclicks as | |
603 * weird selection modifiers. | |
604 * | |
605 * so what do we do? forge rightclicks as leftclicks, then popup the menu. | |
606 * HACK HACK HACK. | |
607 */ | |
608 static gint button_press_intercept_cb(GtkText *gtktext, GdkEvent *e, gpointer d) { | |
609 GdkEventButton *eb; | |
610 gboolean retval; | |
611 | |
612 if (!gtkspell_running()) return FALSE; | |
613 | |
614 if (e->type != GDK_BUTTON_PRESS) return FALSE; | |
615 eb = (GdkEventButton*) e; | |
616 | |
617 if (eb->button != 3) return FALSE; | |
618 | |
619 /* forge the leftclick */ | |
620 eb->button = 1; | |
621 | |
622 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), | |
623 GTK_SIGNAL_FUNC(button_press_intercept_cb), d); | |
624 gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "button-press-event", | |
625 e, &retval); | |
626 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), | |
627 GTK_SIGNAL_FUNC(button_press_intercept_cb), d); | |
628 gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "button-press-event"); | |
629 | |
630 /* now do the menu wackiness */ | |
631 popup_menu(gtktext, eb); | |
632 return TRUE; | |
633 } | |
634 | |
635 void gtkspell_uncheck_all(GtkText *gtktext) { | |
636 int origpos; | |
637 char *text; | |
638 float adj_value; | |
639 | |
640 adj_value = gtktext->vadj->value; | |
641 gtk_text_freeze(gtktext); | |
642 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
643 text = gtk_editable_get_chars(GTK_EDITABLE(gtktext), 0, -1); | |
644 gtk_text_set_point(gtktext, 0); | |
645 gtk_text_forward_delete(gtktext, gtk_text_get_length(gtktext)); | |
646 gtk_text_insert(gtktext, NULL, NULL, NULL, text, strlen(text)); | |
647 gtk_text_thaw(gtktext); | |
1794
60b3fd819cce
[gaim-migrate @ 1804]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1496
diff
changeset
|
648 g_free(text); |
1117 | 649 |
650 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); | |
651 gtk_adjustment_set_value(gtktext->vadj, adj_value); | |
652 } | |
653 | |
654 void gtkspell_attach(GtkText *gtktext) { | |
655 gtk_signal_connect(GTK_OBJECT(gtktext), "insert-text", | |
656 GTK_SIGNAL_FUNC(entry_insert_cb), NULL); | |
657 gtk_signal_connect_after(GTK_OBJECT(gtktext), "delete-text", | |
658 GTK_SIGNAL_FUNC(entry_delete_cb), NULL); | |
659 gtk_signal_connect(GTK_OBJECT(gtktext), "button-press-event", | |
660 GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL); | |
661 } | |
662 | |
663 void gtkspell_detach(GtkText *gtktext) { | |
664 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext), | |
665 GTK_SIGNAL_FUNC(entry_insert_cb), NULL); | |
666 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext), | |
667 GTK_SIGNAL_FUNC(entry_delete_cb), NULL); | |
668 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext), | |
669 GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL); | |
670 | |
671 gtkspell_uncheck_all(gtktext); | |
672 } | |
673 | |
674 static void sigchld(int param) { | |
675 if (gtkspell_running() && | |
676 (waitpid(spell_pid, NULL, WNOHANG) == spell_pid)) { | |
677 spell_pid = 0; | |
678 } else { | |
679 /* a default SIGCHLD handler. | |
680 * what else to do here? */ | |
681 waitpid(-1, NULL, WNOHANG); | |
682 } | |
683 } | |
684 | |
685 static void set_up_signal() { | |
686 struct sigaction sigact; | |
687 memset(&sigact, 0, sizeof(struct sigaction)); | |
688 | |
689 sigact.sa_handler = sigchld; | |
690 sigaction(SIGCHLD, &sigact, NULL); | |
691 } |