Mercurial > pidgin.yaz
comparison src/gtkspell.c @ 1496:d33bf6548543
[gaim-migrate @ 1506]
hrm.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 22 Feb 2001 00:42:55 +0000 |
parents | 7f7857c5036e |
children | 60b3fd819cce |
comparison
equal
deleted
inserted
replaced
1495:3d1c4e5f375b | 1496:d33bf6548543 |
---|---|
42 | 42 |
43 /* because we keep only one copy of the spell program running, | 43 /* because we keep only one copy of the spell program running, |
44 * all ispell-related variables can be static. | 44 * all ispell-related variables can be static. |
45 */ | 45 */ |
46 static pid_t spell_pid = -1; | 46 static pid_t spell_pid = -1; |
47 static int fd_write[2], fd_read[2]; | 47 static int fd_write[2] = {0}, fd_read[2] = {0}; |
48 static int signal_set_up = 0; | 48 static int signal_set_up = 0; |
49 | 49 |
50 /* FIXME? */ | 50 /* FIXME? */ |
51 static GdkColor highlight = { 0, 255*256, 0, 0 }; | 51 static GdkColor highlight = { 0, 255*256, 0, 0 }; |
52 | 52 |
110 | 110 |
111 | 111 |
112 void gtkspell_stop() { | 112 void gtkspell_stop() { |
113 if (gtkspell_running()) { | 113 if (gtkspell_running()) { |
114 kill(spell_pid, SIGHUP); | 114 kill(spell_pid, SIGHUP); |
115 spell_pid = 0; | |
116 close(fd_read[0]); | |
117 close(fd_write[1]); | |
115 } | 118 } |
116 } | 119 } |
117 | 120 |
118 int gtkspell_start(char *path, char * args[]) { | 121 int gtkspell_start(char *path, char * args[]) { |
119 int fd_error[2]; | 122 int fd_error[2]; |
137 if (spell_pid < 0) { | 140 if (spell_pid < 0) { |
138 error_print("fork: %s\n", strerror(errno)); | 141 error_print("fork: %s\n", strerror(errno)); |
139 return -1; | 142 return -1; |
140 } else if (spell_pid == 0) { | 143 } else if (spell_pid == 0) { |
141 dup2(fd_write[0], 0); | 144 dup2(fd_write[0], 0); |
145 close(fd_write[0]); | |
146 close(fd_write[1]); | |
147 | |
142 dup2(fd_read[1], 1); | 148 dup2(fd_read[1], 1); |
149 close(fd_read[0]); | |
150 close(fd_read[1]); | |
151 | |
143 dup2(fd_error[1], 2); | 152 dup2(fd_error[1], 2); |
144 close(fd_read[0]); | |
145 close(fd_error[0]); | 153 close(fd_error[0]); |
146 close(fd_write[1]); | 154 close(fd_error[1]); |
147 | 155 |
148 if (path == NULL) { | 156 if (path == NULL) { |
149 if (execvp(args[0], args) < 0) | 157 if (execvp(args[0], args) < 0) |
150 error_print("execvp('%s'): %s\n", args[0], strerror(errno)); | 158 error_print("execvp('%s'): %s\n", args[0], strerror(errno)); |
151 } else { | 159 } else { |
153 error_print("execv('%s'): %s\n", path, strerror(errno)); | 161 error_print("execv('%s'): %s\n", path, strerror(errno)); |
154 } | 162 } |
155 /* if we get here, we failed. | 163 /* if we get here, we failed. |
156 * send some text on the pipe to indicate status. | 164 * send some text on the pipe to indicate status. |
157 */ | 165 */ |
158 write(fd_read[1], "!", 1); | 166 write(0, "!", 1); /* stdout _is_ the pipe. */ |
159 | 167 |
160 _exit(0); | 168 _exit(0); |
161 } else { | 169 } else { |
162 /* there are at least two ways to fail: | 170 /* there are at least two ways to fail: |
163 * - the exec() can fail | 171 * - the exec() can fail |
165 * we must check for both. | 173 * we must check for both. |
166 */ | 174 */ |
167 fd_set rfds; | 175 fd_set rfds; |
168 struct timeval tv; | 176 struct timeval tv; |
169 | 177 |
178 close(fd_write[0]); | |
179 close(fd_read[1]); | |
180 | |
170 FD_ZERO(&rfds); | 181 FD_ZERO(&rfds); |
171 FD_SET(fd_error[0], &rfds); | 182 FD_SET(fd_error[0], &rfds); |
172 FD_SET(fd_read[0], &rfds); | 183 FD_SET(fd_read[0], &rfds); |
173 tv.tv_sec = 2; | 184 tv.tv_sec = 2; |
174 tv.tv_usec = 0; | 185 tv.tv_usec = 0; |
186 | |
175 if (select(MAX(fd_error[0], fd_read[0])+1, | 187 if (select(MAX(fd_error[0], fd_read[0])+1, |
176 &rfds, NULL, NULL, &tv) < 0) { | 188 &rfds, NULL, NULL, &tv) < 0) { |
177 /* FIXME: is this needed? */ | 189 /* FIXME: is this needed? */ |
178 error_print("Timed out waiting for spell command.\n"); | 190 error_print("Timed out waiting for spell command.\n"); |
179 gtkspell_stop(); | 191 gtkspell_stop(); |
183 if (FD_ISSET(fd_error[0], &rfds)) { /* stderr readable? */ | 195 if (FD_ISSET(fd_error[0], &rfds)) { /* stderr readable? */ |
184 error_print("Spell command printed on stderr -- probably failed.\n"); | 196 error_print("Spell command printed on stderr -- probably failed.\n"); |
185 gtkspell_stop(); | 197 gtkspell_stop(); |
186 return -1; | 198 return -1; |
187 } | 199 } |
200 | |
201 /* we're done with stderr, now. */ | |
202 close(fd_error[0]); | |
203 close(fd_error[1]); | |
188 | 204 |
189 /* otherwise, fd_read[0] is set. */ | 205 /* otherwise, fd_read[0] is set. */ |
190 readline(buf); | 206 readline(buf); |
191 | 207 |
192 /* ispell should print something like this: | 208 /* ispell should print something like this: |
414 !iswordsep(GTK_TEXT_INDEX(gtktext, *ppos))) | 430 !iswordsep(GTK_TEXT_INDEX(gtktext, *ppos))) |
415 check_at(gtktext, *ppos-1); | 431 check_at(gtktext, *ppos-1); |
416 } | 432 } |
417 | 433 |
418 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); | 434 gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos); |
435 gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos); | |
419 } | 436 } |
420 | 437 |
421 static void entry_delete_cb(GtkText *gtktext, | 438 static void entry_delete_cb(GtkText *gtktext, |
422 gint start, gint end, gpointer d) { | 439 gint start, gint end, gpointer d) { |
423 int origpos; | 440 int origpos; |