Mercurial > pidgin.yaz
annotate src/gtkspell.c @ 2461:0edec72bc72f
[gaim-migrate @ 2474]
be more assertive. this was a bug in gtkspell even before my patch, i think; it's just easier to check with my patch ;)
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 09 Oct 2001 19:24:16 +0000 |
parents | e6b9246b33fd |
children | 9cee43e4903d |
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; |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
318 buf = g_strdup_printf("^%s\n", word); /* guard against ispell control chars */ |
1117 | 319 writetext(buf); |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
320 g_free(buf); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
321 buf = readresponse(); |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
322 |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
323 if (!buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
324 return 0; |
1117 | 325 |
326 if (buf[0] == 0) { | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
327 g_free(buf); |
1117 | 328 return 0; |
1467
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1415
diff
changeset
|
329 } else if (buf[0] == '&' || buf[0] == '#' || buf[0] == '?') { |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
330 g_free(buf); |
1117 | 331 return 1; |
332 } | |
333 | |
334 error_print("Unsupported spell command '%c'.\n" | |
335 "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
|
336 error_print("Input [%s]\nOutput [%s]\n", word, buf); |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
337 g_free(buf); |
1117 | 338 return -1; |
339 } | |
340 | |
341 static gboolean iswordsep(char c) { | |
342 return !isalpha(c) && c != '\''; | |
343 } | |
344 | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
345 static gboolean get_word_from_pos(GtkText* gtktext, int pos, char** buf, |
1117 | 346 int *pstart, int *pend) { |
347 gint start, end; | |
348 | |
349 if (iswordsep(GTK_TEXT_INDEX(gtktext, pos))) return FALSE; | |
350 | |
351 for (start = pos; start >= 0; --start) { | |
352 if (iswordsep(GTK_TEXT_INDEX(gtktext, start))) break; | |
353 } | |
354 start++; | |
355 | |
356 for (end = pos; end <= gtk_text_get_length(gtktext); end++) { | |
357 if (iswordsep(GTK_TEXT_INDEX(gtktext, end))) break; | |
358 } | |
359 | |
2457
e6b9246b33fd
[gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2456
diff
changeset
|
360 if (buf && (end - start + 1 > 0)) { |
e6b9246b33fd
[gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2456
diff
changeset
|
361 *buf = g_malloc(end - start + 1); |
1117 | 362 for (pos = start; pos < end; pos++) |
2457
e6b9246b33fd
[gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2456
diff
changeset
|
363 (*buf)[pos-start] = GTK_TEXT_INDEX(gtktext, pos); |
e6b9246b33fd
[gaim-migrate @ 2470]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2456
diff
changeset
|
364 (*buf)[pos-start] = 0; |
1117 | 365 } |
366 | |
367 if (pstart) *pstart = start; | |
368 if (pend) *pend = end; | |
369 | |
370 return TRUE; | |
371 } | |
372 | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
373 static gboolean get_curword(GtkText* gtktext, char** buf, |
1117 | 374 int *pstart, int *pend) { |
375 int pos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
376 return get_word_from_pos(gtktext, pos, buf, pstart, pend); | |
377 } | |
378 | |
379 static void change_color(GtkText *gtktext, | |
380 int start, int end, GdkColor *color) { | |
381 char *newtext = gtk_editable_get_chars(GTK_EDITABLE(gtktext), start, end); | |
382 gtk_text_freeze(gtktext); | |
383 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), | |
384 GTK_SIGNAL_FUNC(entry_insert_cb), NULL); | |
385 | |
386 gtk_text_set_point(gtktext, start); | |
387 gtk_text_forward_delete(gtktext, end-start); | |
388 | |
389 if (newtext && end-start > 0) | |
390 gtk_text_insert(gtktext, NULL, color, NULL, newtext, end-start); | |
391 | |
392 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), | |
393 GTK_SIGNAL_FUNC(entry_insert_cb), NULL); | |
394 gtk_text_thaw(gtktext); | |
1415
3dfd2a83fb5e
[gaim-migrate @ 1425]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1127
diff
changeset
|
395 g_free(newtext); |
1117 | 396 } |
397 | |
398 static gboolean check_at(GtkText *gtktext, int from_pos) { | |
399 int start, end; | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
400 char *buf = NULL; |
1117 | 401 |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
402 if (!get_word_from_pos(gtktext, from_pos, &buf, &start, &end)) { |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
403 if (buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
404 g_free(buf); |
1117 | 405 return FALSE; |
406 } | |
407 | |
408 if (misspelled_test(buf)) { | |
409 if (highlight.pixel == 0) { | |
410 /* add an entry for the highlight in the color map. */ | |
411 GdkColormap *gc = gtk_widget_get_colormap(GTK_WIDGET(gtktext)); | |
412 gdk_colormap_alloc_color(gc, &highlight, FALSE, TRUE);; | |
413 } | |
414 change_color(gtktext, start, end, &highlight); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
415 if (buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
416 g_free(buf); |
1117 | 417 return TRUE; |
418 } else { | |
419 change_color(gtktext, start, end, | |
420 &(GTK_WIDGET(gtktext)->style->fg[0])); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
421 if (buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
422 g_free(buf); |
1117 | 423 return FALSE; |
424 } | |
425 } | |
426 | |
427 void gtkspell_check_all(GtkText *gtktext) { | |
428 guint origpos; | |
429 guint pos = 0; | |
430 guint len; | |
431 float adj_value; | |
432 | |
433 if (!gtkspell_running()) return; | |
434 | |
435 len = gtk_text_get_length(gtktext); | |
436 | |
437 adj_value = gtktext->vadj->value; | |
438 gtk_text_freeze(gtktext); | |
439 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
440 while (pos < len) { | |
441 while (pos < len && iswordsep(GTK_TEXT_INDEX(gtktext, pos))) | |
442 pos++; | |
443 while (pos < len && !iswordsep(GTK_TEXT_INDEX(gtktext, pos))) | |
444 pos++; | |
445 if (pos > 0) | |
446 check_at(gtktext, pos-1); | |
447 } | |
448 gtk_text_thaw(gtktext); | |
449 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); | |
450 } | |
451 | |
452 static void entry_insert_cb(GtkText *gtktext, | |
453 gchar *newtext, guint len, guint *ppos, gpointer d) { | |
454 int origpos; | |
455 | |
456 if (!gtkspell_running()) return; | |
457 | |
458 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), | |
459 GTK_SIGNAL_FUNC(entry_insert_cb), | |
460 NULL); | |
461 gtk_text_insert(GTK_TEXT(gtktext), NULL, | |
462 &(GTK_WIDGET(gtktext)->style->fg[0]), NULL, newtext, len); | |
463 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), | |
464 GTK_SIGNAL_FUNC(entry_insert_cb), | |
465 NULL); | |
466 gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "insert-text"); | |
467 *ppos += len; | |
468 | |
469 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
470 | |
471 if (iswordsep(newtext[0])) { | |
472 /* did we just end a word? */ | |
473 if (*ppos >= 2) check_at(gtktext, *ppos-2); | |
474 | |
475 /* did we just split a word? */ | |
476 if (*ppos < gtk_text_get_length(gtktext)) | |
477 check_at(gtktext, *ppos+1); | |
478 } else { | |
479 /* check as they type, *except* if they're typing at the end (the most | |
480 * common case. | |
481 */ | |
482 if (*ppos < gtk_text_get_length(gtktext) && | |
483 !iswordsep(GTK_TEXT_INDEX(gtktext, *ppos))) | |
484 check_at(gtktext, *ppos-1); | |
485 } | |
486 | |
487 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); | |
1496
d33bf6548543
[gaim-migrate @ 1506]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1467
diff
changeset
|
488 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos); |
1117 | 489 } |
490 | |
491 static void entry_delete_cb(GtkText *gtktext, | |
492 gint start, gint end, gpointer d) { | |
493 int origpos; | |
494 | |
495 if (!gtkspell_running()) return; | |
496 | |
497 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
498 check_at(gtktext, start-1); | |
499 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); | |
500 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos); | |
501 /* this is to *UNDO* the selection, in case they were holding shift | |
502 * while hitting backspace. */ | |
503 } | |
504 | |
505 static void replace_word(GtkWidget *w, gpointer d) { | |
506 int start, end; | |
507 char *newword; | |
508 | |
509 /* we don't save their position, | |
510 * because the cursor is moved by the click. */ | |
511 | |
512 gtk_text_freeze(GTK_TEXT(d)); | |
513 | |
514 gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), &newword); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
515 get_curword(GTK_TEXT(d), NULL, &start, &end); |
1117 | 516 |
517 gtk_text_set_point(GTK_TEXT(d), end); | |
518 gtk_text_backward_delete(GTK_TEXT(d), end-start); | |
519 gtk_text_insert(GTK_TEXT(d), NULL, NULL, NULL, newword, strlen(newword)); | |
520 | |
521 gtk_text_thaw(GTK_TEXT(d)); | |
522 } | |
523 | |
524 static GtkMenu *make_menu(GList *l, GtkText *gtktext) { | |
525 GtkWidget *menu, *item; | |
526 char *caption; | |
527 menu = gtk_menu_new(); { | |
528 caption = g_strdup_printf("Not in dictionary: %s", (char*)l->data); | |
529 item = gtk_menu_item_new_with_label(caption); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
530 g_free(caption); |
1117 | 531 /* I'd like to make it so this item is never selectable, like |
532 * the menu titles in the GNOME panel... unfortunately, the GNOME | |
533 * panel creates their own custom widget to do this! */ | |
534 gtk_widget_show(item); | |
535 gtk_menu_append(GTK_MENU(menu), item); | |
536 | |
537 item = gtk_menu_item_new(); | |
538 gtk_widget_show(item); | |
539 gtk_menu_append(GTK_MENU(menu), item); | |
540 | |
541 l = l->next; | |
542 if (l == NULL) { | |
543 item = gtk_menu_item_new_with_label("(no suggestions)"); | |
544 gtk_widget_show(item); | |
545 gtk_menu_append(GTK_MENU(menu), item); | |
546 } else { | |
547 GtkWidget *curmenu = menu; | |
548 int count = 0; | |
549 do { | |
550 if (l->data == NULL && l->next != NULL) { | |
551 count = 0; | |
552 curmenu = gtk_menu_new(); | |
553 item = gtk_menu_item_new_with_label("Other Possibilities..."); | |
554 gtk_widget_show(item); | |
555 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu); | |
556 gtk_menu_append(GTK_MENU(curmenu), item); | |
557 l = l->next; | |
558 } else if (count > MENUCOUNT) { | |
559 count -= MENUCOUNT; | |
560 item = gtk_menu_item_new_with_label("More..."); | |
561 gtk_widget_show(item); | |
562 gtk_menu_append(GTK_MENU(curmenu), item); | |
563 curmenu = gtk_menu_new(); | |
564 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu); | |
565 } | |
566 item = gtk_menu_item_new_with_label((char*)l->data); | |
567 gtk_signal_connect(GTK_OBJECT(item), "activate", | |
568 GTK_SIGNAL_FUNC(replace_word), gtktext); | |
569 gtk_widget_show(item); | |
570 gtk_menu_append(GTK_MENU(curmenu), item); | |
571 count++; | |
572 } while ((l = l->next) != NULL); | |
573 } | |
574 } | |
575 return GTK_MENU(menu); | |
576 } | |
577 | |
578 static void popup_menu(GtkText *gtktext, GdkEventButton *eb) { | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
579 char *buf = NULL; |
1117 | 580 GList *list, *l; |
581 | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
582 get_curword(gtktext, &buf, NULL, NULL); |
1117 | 583 |
584 list = misspelled_suggest(buf); | |
2454
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
585 if (buf) |
64e20158271e
[gaim-migrate @ 2467]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1815
diff
changeset
|
586 g_free(buf); |
1117 | 587 if (list != NULL) { |
588 gtk_menu_popup(make_menu(list, gtktext), NULL, NULL, NULL, NULL, | |
589 eb->button, eb->time); | |
590 for (l = list; l != NULL; l = l->next) | |
591 g_free(l->data); | |
592 g_list_free(list); | |
593 } | |
594 } | |
595 | |
596 /* ok, this is pretty wacky: | |
597 * we need to let the right-mouse-click go through, so it moves the cursor, | |
598 * but we *can't* let it go through, because GtkText interprets rightclicks as | |
599 * weird selection modifiers. | |
600 * | |
601 * so what do we do? forge rightclicks as leftclicks, then popup the menu. | |
602 * HACK HACK HACK. | |
603 */ | |
604 static gint button_press_intercept_cb(GtkText *gtktext, GdkEvent *e, gpointer d) { | |
605 GdkEventButton *eb; | |
606 gboolean retval; | |
607 | |
608 if (!gtkspell_running()) return FALSE; | |
609 | |
610 if (e->type != GDK_BUTTON_PRESS) return FALSE; | |
611 eb = (GdkEventButton*) e; | |
612 | |
613 if (eb->button != 3) return FALSE; | |
614 | |
615 /* forge the leftclick */ | |
616 eb->button = 1; | |
617 | |
618 gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), | |
619 GTK_SIGNAL_FUNC(button_press_intercept_cb), d); | |
620 gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "button-press-event", | |
621 e, &retval); | |
622 gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), | |
623 GTK_SIGNAL_FUNC(button_press_intercept_cb), d); | |
624 gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "button-press-event"); | |
625 | |
626 /* now do the menu wackiness */ | |
627 popup_menu(gtktext, eb); | |
628 return TRUE; | |
629 } | |
630 | |
631 void gtkspell_uncheck_all(GtkText *gtktext) { | |
632 int origpos; | |
633 char *text; | |
634 float adj_value; | |
635 | |
636 adj_value = gtktext->vadj->value; | |
637 gtk_text_freeze(gtktext); | |
638 origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext)); | |
639 text = gtk_editable_get_chars(GTK_EDITABLE(gtktext), 0, -1); | |
640 gtk_text_set_point(gtktext, 0); | |
641 gtk_text_forward_delete(gtktext, gtk_text_get_length(gtktext)); | |
642 gtk_text_insert(gtktext, NULL, NULL, NULL, text, strlen(text)); | |
643 gtk_text_thaw(gtktext); | |
1794
60b3fd819cce
[gaim-migrate @ 1804]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1496
diff
changeset
|
644 g_free(text); |
1117 | 645 |
646 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); | |
647 gtk_adjustment_set_value(gtktext->vadj, adj_value); | |
648 } | |
649 | |
650 void gtkspell_attach(GtkText *gtktext) { | |
651 gtk_signal_connect(GTK_OBJECT(gtktext), "insert-text", | |
652 GTK_SIGNAL_FUNC(entry_insert_cb), NULL); | |
653 gtk_signal_connect_after(GTK_OBJECT(gtktext), "delete-text", | |
654 GTK_SIGNAL_FUNC(entry_delete_cb), NULL); | |
655 gtk_signal_connect(GTK_OBJECT(gtktext), "button-press-event", | |
656 GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL); | |
657 } | |
658 | |
659 void gtkspell_detach(GtkText *gtktext) { | |
660 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext), | |
661 GTK_SIGNAL_FUNC(entry_insert_cb), NULL); | |
662 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext), | |
663 GTK_SIGNAL_FUNC(entry_delete_cb), NULL); | |
664 gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext), | |
665 GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL); | |
666 | |
667 gtkspell_uncheck_all(gtktext); | |
668 } | |
669 | |
670 static void sigchld(int param) { | |
671 if (gtkspell_running() && | |
672 (waitpid(spell_pid, NULL, WNOHANG) == spell_pid)) { | |
673 spell_pid = 0; | |
674 } else { | |
675 /* a default SIGCHLD handler. | |
676 * what else to do here? */ | |
677 waitpid(-1, NULL, WNOHANG); | |
678 } | |
679 } | |
680 | |
681 static void set_up_signal() { | |
682 struct sigaction sigact; | |
683 memset(&sigact, 0, sizeof(struct sigaction)); | |
684 | |
685 sigact.sa_handler = sigchld; | |
686 sigaction(SIGCHLD, &sigact, NULL); | |
687 } |