Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

gtkspell.c File Reference

#include "intl.h"
#include <gtk/gtk.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>

Include dependency graph for gtkspell.c:

Include dependency graph

Go to the source code of this file.

Defines

#define BUFSIZE   1024
#define MENUCOUNT   20
#define BUGEMAIL   "gtkspell-devel@lists.sourceforge.net"

Functions

void entry_insert_cb (GtkText *gtktext, gchar *newtext, guint len, guint *ppos, gpointer d)
void set_up_signal ()
int gtkspell_running ()
void error_print (const char *fmt,...)
void writetext (char *text)
int readpipe (char *buf, int bufsize)
int readline (char *buf)
int readresponse (char *buf)
void gtkspell_stop ()
int gtkspell_start (char *path, char *args[])
GList * misspelled_suggest (char *word)
int misspelled_test (char *word)
gboolean iswordsep (char c)
gboolean get_word_from_pos (GtkText *gtktext, int pos, char *buf, int *pstart, int *pend)
gboolean get_curword (GtkText *gtktext, char *buf, int *pstart, int *pend)
void change_color (GtkText *gtktext, int start, int end, GdkColor *color)
gboolean check_at (GtkText *gtktext, int from_pos)
void gtkspell_check_all (GtkText *gtktext)
void entry_delete_cb (GtkText *gtktext, gint start, gint end, gpointer d)
void replace_word (GtkWidget *w, gpointer d)
GtkMenu * make_menu (GList *l, GtkText *gtktext)
void popup_menu (GtkText *gtktext, GdkEventButton *eb)
gint button_press_intercept_cb (GtkText *gtktext, GdkEvent *e, gpointer d)
void gtkspell_uncheck_all (GtkText *gtktext)
void gtkspell_attach (GtkText *gtktext)
void gtkspell_detach (GtkText *gtktext)
void sigchld (int param)

Variables

pid_t spell_pid = -1
int fd_write [2]
int fd_read [2]
int signal_set_up = 0
GdkColor highlight = { 0, 255*256, 0, 0 }


Define Documentation

#define BUFSIZE   1024
 

Definition at line 44 of file gtkspell.c.

Referenced by check_at(), gtkspell_start(), misspelled_suggest(), misspelled_test(), popup_menu(), readline(), readresponse(), and replace_word().

#define BUGEMAIL   "gtkspell-devel@lists.sourceforge.net"
 

Definition at line 47 of file gtkspell.c.

Referenced by misspelled_suggest(), and misspelled_test().

#define MENUCOUNT   20
 

Definition at line 46 of file gtkspell.c.

Referenced by make_menu().


Function Documentation

gint button_press_intercept_cb GtkText *    gtktext,
GdkEvent *    e,
gpointer    d
[static]
 

Definition at line 545 of file gtkspell.c.

References button_press_intercept_cb(), gtkspell_running(), and popup_menu().

Referenced by button_press_intercept_cb(), gtkspell_attach(), and gtkspell_detach().

00545                                                                                  {
00546     GdkEventButton *eb;
00547     gboolean retval;
00548 
00549     if (!gtkspell_running()) return FALSE;
00550 
00551     if (e->type != GDK_BUTTON_PRESS) return FALSE;
00552     eb = (GdkEventButton*) e;
00553 
00554     if (eb->button != 3) return FALSE;
00555 
00556     /* forge the leftclick */
00557     eb->button = 1;
00558 
00559     gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), 
00560             GTK_SIGNAL_FUNC(button_press_intercept_cb), d);
00561     gtk_signal_emit_by_name(GTK_OBJECT(gtktext), "button-press-event",
00562             e, &retval);
00563     gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), 
00564             GTK_SIGNAL_FUNC(button_press_intercept_cb), d);
00565     gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "button-press-event");
00566 
00567     /* now do the menu wackiness */
00568     popup_menu(gtktext, eb);
00569     return TRUE;
00570 }

void change_color GtkText *    gtktext,
int    start,
int    end,
GdkColor *    color
[static]
 

Definition at line 323 of file gtkspell.c.

References entry_insert_cb().

Referenced by check_at().

00324                                              {
00325     char *newtext = gtk_editable_get_chars(GTK_EDITABLE(gtktext), start, end);
00326     gtk_text_freeze(gtktext);
00327     gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext), 
00328             GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
00329     
00330     gtk_text_set_point(gtktext, start);
00331 
00332     if(newtext && end-start > 0)
00333     {
00334         gtk_text_forward_delete(gtktext, end-start);
00335         gtk_text_insert(gtktext, NULL, color, NULL, newtext, end-start);
00336     }
00337 
00338     gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext), 
00339             GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
00340     gtk_text_thaw(gtktext);
00341     g_free(newtext);
00342 }

gboolean check_at GtkText *    gtktext,
int    from_pos
[static]
 

Definition at line 344 of file gtkspell.c.

References BUFSIZE, change_color(), get_word_from_pos(), highlight, and misspelled_test().

Referenced by entry_delete_cb(), entry_insert_cb(), and gtkspell_check_all().

00344                                                          {
00345     int start, end;
00346     char buf[BUFSIZE];
00347 
00348     if (!get_word_from_pos(gtktext, from_pos, buf, &start, &end)) {
00349         return FALSE;
00350     }
00351 
00352     if (misspelled_test(buf)) {
00353         if (highlight.pixel == 0) {
00354             /* add an entry for the highlight in the color map. */
00355             GdkColormap *gc = gtk_widget_get_colormap(GTK_WIDGET(gtktext));
00356             gdk_colormap_alloc_color(gc, &highlight, FALSE, TRUE);;
00357         }
00358         change_color(gtktext, start, end, &highlight);
00359         return TRUE;
00360     } else { 
00361         change_color(gtktext, start, end, 
00362                 &(GTK_WIDGET(gtktext)->style->fg[0]));
00363         return FALSE;
00364     }
00365 }

void entry_delete_cb GtkText *    gtktext,
gint    start,
gint    end,
gpointer    d
[static]
 

Definition at line 430 of file gtkspell.c.

References check_at(), and gtkspell_running().

Referenced by gtkspell_attach(), and gtkspell_detach().

00431                                           {
00432     int origpos;
00433 
00434     if (!gtkspell_running()) return;
00435 
00436     origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
00437     check_at(gtktext, start-1);
00438     gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
00439     gtk_editable_select_region(GTK_EDITABLE(gtktext), origpos, origpos);
00440     /* this is to *UNDO* the selection, in case they were holding shift
00441      * while hitting backspace. */
00442 }

void entry_insert_cb GtkText *    gtktext,
gchar *    newtext,
guint    len,
guint *    ppos,
gpointer    d
[static]
 

Definition at line 392 of file gtkspell.c.

References check_at(), entry_insert_cb(), gtkspell_running(), and iswordsep().

Referenced by change_color(), entry_insert_cb(), gtkspell_attach(), and gtkspell_detach().

00393                                                             {
00394     int origpos;
00395 
00396     if (!gtkspell_running()) return;
00397 
00398     gtk_signal_handler_block_by_func(GTK_OBJECT(gtktext),
00399                                      GTK_SIGNAL_FUNC(entry_insert_cb),
00400                                      NULL);
00401     gtk_text_insert(GTK_TEXT(gtktext), NULL,
00402             &(GTK_WIDGET(gtktext)->style->fg[0]), NULL, newtext, len);
00403     gtk_signal_handler_unblock_by_func(GTK_OBJECT(gtktext),
00404                                      GTK_SIGNAL_FUNC(entry_insert_cb),
00405                                      NULL);
00406     gtk_signal_emit_stop_by_name(GTK_OBJECT(gtktext), "insert-text");
00407     *ppos += len;
00408 
00409     origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
00410 
00411     if (iswordsep(newtext[0])) {
00412         /* did we just end a word? */
00413         if (*ppos >= 2) check_at(gtktext, *ppos-2);
00414 
00415         /* did we just split a word? */
00416         if (*ppos < gtk_text_get_length(gtktext))
00417             check_at(gtktext, *ppos+1);
00418     } else {
00419         /* check as they type, *except* if they're typing at the end (the most
00420          * common case.
00421          */
00422         if (*ppos < gtk_text_get_length(gtktext) && 
00423                 !iswordsep(GTK_TEXT_INDEX(gtktext, *ppos)))
00424             check_at(gtktext, *ppos-1);
00425     }
00426 
00427     gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
00428 }

void error_print const char *    fmt,
...   
[static]
 

Definition at line 67 of file gtkspell.c.

Referenced by gtkspell_start(), misspelled_suggest(), misspelled_test(), and readpipe().

00067                                               {
00068     va_list ap;
00069     va_start(ap, fmt);
00070     fprintf(stderr, "gtkspell: ");
00071     vfprintf(stderr, fmt, ap);
00072     va_end(ap);
00073 }

gboolean get_curword GtkText *    gtktext,
char *    buf,
int *    pstart,
int *    pend
[static]
 

Definition at line 317 of file gtkspell.c.

References get_word_from_pos().

Referenced by popup_menu(), and replace_word().

00318                                 {
00319     int pos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
00320     return get_word_from_pos(gtktext, pos, buf, pstart, pend);
00321 }

gboolean get_word_from_pos GtkText *    gtktext,
int    pos,
char *    buf,
int *    pstart,
int *    pend
[static]
 

Definition at line 290 of file gtkspell.c.

References iswordsep().

Referenced by check_at(), and get_curword().

00291                                 {
00292     gint start, end;
00293 
00294     if (iswordsep(GTK_TEXT_INDEX(gtktext, pos))) return FALSE;
00295 
00296     for (start = pos; start >= 0; --start) {
00297         if (iswordsep(GTK_TEXT_INDEX(gtktext, start))) break;
00298     }
00299     start++;
00300 
00301     for (end = pos; end <= gtk_text_get_length(gtktext); end++) {
00302         if (iswordsep(GTK_TEXT_INDEX(gtktext, end))) break;
00303     }
00304 
00305     if (buf) {
00306         for (pos = start; pos < end; pos++) 
00307             buf[pos-start] = GTK_TEXT_INDEX(gtktext, pos);
00308         buf[pos-start] = 0;
00309     }
00310 
00311     if (pstart) *pstart = start;
00312     if (pend) *pend = end;
00313 
00314     return TRUE;
00315 }

void gtkspell_attach GtkText *    gtktext
 

Definition at line 590 of file gtkspell.c.

References button_press_intercept_cb(), entry_delete_cb(), and entry_insert_cb().

Referenced by eb_chat_window_new().

00590                                        {
00591     gtk_signal_connect(GTK_OBJECT(gtktext), "insert-text",
00592         GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
00593     gtk_signal_connect_after(GTK_OBJECT(gtktext), "delete-text",
00594         GTK_SIGNAL_FUNC(entry_delete_cb), NULL);
00595     gtk_signal_connect(GTK_OBJECT(gtktext), "button-press-event",
00596             GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL);
00597 }

void gtkspell_check_all GtkText *    gtktext
 

Definition at line 367 of file gtkspell.c.

References check_at(), gtkspell_running(), and iswordsep().

00367                                           {
00368     guint origpos;
00369     guint pos = 0;
00370     guint len;
00371     float adj_value;
00372     
00373     if (!gtkspell_running()) return;
00374     
00375     len = gtk_text_get_length(gtktext);
00376 
00377     adj_value = gtktext->vadj->value;
00378     gtk_text_freeze(gtktext);
00379     origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
00380     while (pos < len) {
00381         while (pos < len && iswordsep(GTK_TEXT_INDEX(gtktext, pos)))
00382             pos++;
00383         while (pos < len && !iswordsep(GTK_TEXT_INDEX(gtktext, pos)))
00384             pos++;
00385         if (pos > 0)
00386             check_at(gtktext, pos-1);
00387     }
00388     gtk_text_thaw(gtktext);
00389     gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
00390 }

void gtkspell_detach GtkText *    gtktext
 

Definition at line 599 of file gtkspell.c.

References button_press_intercept_cb(), entry_delete_cb(), entry_insert_cb(), and gtkspell_uncheck_all().

00599                                        {
00600     gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
00601         GTK_SIGNAL_FUNC(entry_insert_cb), NULL);
00602     gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext),
00603         GTK_SIGNAL_FUNC(entry_delete_cb), NULL);
00604     gtk_signal_disconnect_by_func(GTK_OBJECT(gtktext), 
00605             GTK_SIGNAL_FUNC(button_press_intercept_cb), NULL);
00606 
00607     gtkspell_uncheck_all(gtktext);
00608 }

int gtkspell_running  
 

Definition at line 63 of file gtkspell.c.

References spell_pid.

Referenced by button_press_intercept_cb(), destroy(), eb_chat_window_new(), entry_delete_cb(), entry_insert_cb(), gtkspell_check_all(), gtkspell_start(), gtkspell_stop(), and sigchld().

00063                        {
00064     return (spell_pid > 0);
00065 }

int gtkspell_start char *    path,
char *    args[]
 

Definition at line 127 of file gtkspell.c.

References BUFSIZE, error_print(), fd_read, fd_write, gtkspell_running(), gtkspell_stop(), readline(), set_up_signal(), signal_set_up, spell_pid, and writetext().

Referenced by eb_chat_window_new().

00127                                               {
00128 #ifndef __MINGW32__
00129     int fd_error[2];
00130     char buf[BUFSIZE];
00131 
00132     if (gtkspell_running()) {
00133         error_print("gtkspell_start called while already running.\n");
00134         gtkspell_stop();
00135     }
00136 
00137     if (!signal_set_up) {
00138         set_up_signal();
00139         signal_set_up = 1;
00140     }
00141 
00142     pipe(fd_write);
00143     pipe(fd_read);
00144     pipe(fd_error);
00145 
00146     spell_pid = fork();
00147     if (spell_pid < 0) {
00148         error_print("fork: %s\n", strerror(errno));
00149         return -1;
00150     } else if (spell_pid == 0) {
00151         dup2(fd_write[0], 0);
00152         dup2(fd_read[1], 1);
00153         dup2(fd_error[1], 2);
00154         close(fd_read[0]);
00155         close(fd_error[0]);
00156         close(fd_write[1]);
00157 
00158         if (path == NULL) {
00159             if (execvp(args[0], args) < 0) 
00160                 error_print("execvp('%s'): %s\n", args[0], strerror(errno));
00161         } else {
00162             if (execv(path, args) < 0) 
00163                 error_print("execv('%s'): %s\n", path, strerror(errno));
00164         }
00165         /* if we get here, we failed.
00166          * send some text on the pipe to indicate status.
00167          */
00168         write(fd_read[1], "!", 1);
00169 
00170         _exit(0);
00171     } else {
00172         /* there are at least two ways to fail:
00173          * - the exec() can fail
00174          * - the exec() can succeed, but the program can dump the help screen
00175          * we must check for both.
00176          */
00177 
00178         #if HAVE_POLL_H
00179         struct pollfd fds[2];
00180 
00181         fds[0].fd = fd_error[0];
00182         fds[0].events = POLLIN | POLLERR;
00183         fds[1].fd = fd_read[0];
00184         fds[1].events = POLLIN | POLLERR;
00185         if (poll(fds, 2, 2000) <= 0) {
00186             /* FIXME: is this needed? */
00187             error_print("Timed out waiting for spell command.\n");
00188             gtkspell_stop();
00189             return -1;
00190         }
00191         
00192 
00193         if (fds[0].revents) { /* stderr readable? */
00194             error_print("Spell command printed on stderr -- probably failed.\n");
00195             gtkspell_stop();
00196             return -1;
00197         }
00198         
00199         #endif
00200         
00201         readline(buf);
00202         /* ispell should print something like this:
00203          * @(#) International Ispell Version 3.1.20 10/10/95
00204          * if it doesn't, it's an error. */
00205         if (buf[0] != '@') {
00206             gtkspell_stop();
00207             return -1;
00208         }
00209     }
00210 
00211     /* put ispell into terse mode.  
00212      * this makes it not respond on correctly spelled words. */
00213     sprintf(buf, "!\n");
00214     writetext(buf);
00215 #endif
00216     return 0;
00217 }

void gtkspell_stop  
 

Definition at line 118 of file gtkspell.c.

References gtkspell_running(), and spell_pid.

Referenced by destroy(), and gtkspell_start().

00118                      {
00119 #ifndef __MINGW32__
00120     if (gtkspell_running()) {
00121         kill(spell_pid, SIGQUIT); /* FIXME: is this the correct signal? */
00122         spell_pid = -1;
00123     }
00124 #endif
00125 }

void gtkspell_uncheck_all GtkText *    gtktext
 

Definition at line 572 of file gtkspell.c.

Referenced by gtkspell_detach().

00572                                             {
00573     int origpos;
00574     char *text;
00575     float adj_value;
00576 
00577     adj_value = gtktext->vadj->value;
00578     gtk_text_freeze(gtktext);
00579     origpos = gtk_editable_get_position(GTK_EDITABLE(gtktext));
00580     text = gtk_editable_get_chars(GTK_EDITABLE(gtktext), 0, -1);
00581     gtk_text_set_point(gtktext, 0);
00582     gtk_text_forward_delete(gtktext, gtk_text_get_length(gtktext));
00583     gtk_text_insert(gtktext, NULL, NULL, NULL, text, strlen(text));
00584     gtk_text_thaw(gtktext);
00585 
00586     gtk_editable_set_position(GTK_EDITABLE(gtktext), origpos);
00587     gtk_adjustment_set_value(gtktext->vadj, adj_value);
00588 }

gboolean iswordsep char    c [static]
 

Definition at line 286 of file gtkspell.c.

Referenced by entry_insert_cb(), get_word_from_pos(), and gtkspell_check_all().

00286                                   {
00287     return !isalpha(c) && c != '\'';
00288 }

GtkMenu* make_menu GList *    l,
GtkText *    gtktext
[static]
 

Definition at line 468 of file gtkspell.c.

References MENUCOUNT, and replace_word().

Referenced by popup_menu().

00468                                                       {
00469     GtkWidget *menu, *item;
00470     char *caption;
00471     menu = gtk_menu_new(); {
00472         caption = g_strdup_printf("Not in dictionary: %s", (char*)l->data);
00473         item = gtk_menu_item_new_with_label(caption);
00474         /* I'd like to make it so this item is never selectable, like
00475          * the menu titles in the GNOME panel... unfortunately, the GNOME
00476          * panel creates their own custom widget to do this! */
00477         gtk_widget_show(item);
00478         gtk_menu_append(GTK_MENU(menu), item);
00479 
00480         item = gtk_menu_item_new();
00481         gtk_widget_show(item);
00482         gtk_menu_append(GTK_MENU(menu), item);
00483 
00484         l = l->next;
00485         if (l == NULL) {
00486             item = gtk_menu_item_new_with_label("(no suggestions)");
00487             gtk_widget_show(item);
00488             gtk_menu_append(GTK_MENU(menu), item);
00489         } else {
00490             GtkWidget *curmenu = menu;
00491             int count = 0;
00492             do {
00493                 if (l->data == NULL && l->next != NULL) {
00494                     count = 0;
00495                     curmenu = gtk_menu_new();
00496                     item = gtk_menu_item_new_with_label("Other Possibilities...");
00497                     gtk_widget_show(item);
00498                     gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu);
00499                     gtk_menu_append(GTK_MENU(curmenu), item);
00500                     l = l->next;
00501                 } else if (count > MENUCOUNT) {
00502                     count -= MENUCOUNT;
00503                     item = gtk_menu_item_new_with_label("More...");
00504                     gtk_widget_show(item);
00505                     gtk_menu_append(GTK_MENU(curmenu), item);
00506                     curmenu = gtk_menu_new();
00507                     gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), curmenu);
00508                 }
00509                 item = gtk_menu_item_new_with_label((char*)l->data);
00510                 gtk_signal_connect(GTK_OBJECT(item), "activate",
00511                         GTK_SIGNAL_FUNC(replace_word), gtktext);
00512                 gtk_widget_show(item);
00513                 gtk_menu_append(GTK_MENU(curmenu), item);
00514                 count++;
00515             } while ((l = l->next) != NULL);
00516         }
00517     }
00518     return GTK_MENU(menu);
00519 }

GList* misspelled_suggest char *    word [static]
 

Definition at line 219 of file gtkspell.c.

References BUFSIZE, BUGEMAIL, error_print(), readresponse(), and writetext().

Referenced by popup_menu().

00219                                              {
00220     char buf[BUFSIZE];
00221     char *newword;
00222     GList *l = NULL;
00223     int count;
00224 
00225     sprintf(buf, "^%s\n", word); /* guard against ispell control chars */
00226     writetext(buf);
00227     readresponse(buf);
00228 
00229     switch (buf[0]) { /* first char is ispell command. */
00230         case 0: /* no response: word is ok. */
00231             return NULL;
00232         case '&': /* misspelled, with suggestions */
00233             /* & <orig> <count> <ofs>: <miss>, <miss>, <guess>, ... */
00234             strtok(buf, " "); /* & */
00235             newword = strtok(NULL, " "); /* orig */
00236             l = g_list_append(l, g_strdup(newword));
00237             newword = strtok(NULL, " "); /* count */
00238             count = atoi(newword);
00239             strtok(NULL, " "); /* ofs: */
00240 
00241             while ((newword = strtok(NULL, ",")) != NULL) {
00242                 int len = strlen(newword);
00243                 if (newword[len-1] == ' ' || newword[len-1] == '\n') 
00244                     newword[len-1] = 0;
00245                 if (count == 0) {
00246                     g_list_append(l, NULL); /* signal the "suggestions" */
00247                 }
00248                 /* add it to the list, skipping the initial space. */
00249                 l = g_list_append(l, 
00250                         g_strdup(newword[0] == ' ' ? newword+1 : newword));
00251 
00252                 count--;
00253             }
00254             return l;
00255 
00256         case '#': /* misspelled, no suggestions */
00257             /* # <orig> <ofs> */
00258             strtok(buf, " "); /* & */
00259             newword = strtok(NULL, " "); /* orig */
00260             l = g_list_append(l, g_strdup(newword));
00261             return l;
00262         default:
00263             error_print("Unsupported spell command '%c'.\n"
00264                     "This is a bug; mail " BUGEMAIL " about it.\n", buf[0]);
00265     }
00266     return NULL;
00267 }

int misspelled_test char *    word [static]
 

Definition at line 269 of file gtkspell.c.

References BUFSIZE, BUGEMAIL, error_print(), readresponse(), and writetext().

Referenced by check_at().

00269                                        {
00270     char buf[BUFSIZE];
00271     sprintf(buf, "^%s\n", word); /* guard against ispell control chars */
00272     writetext(buf);
00273     readresponse(buf);
00274 
00275     if (buf[0] == 0) {
00276         return 0;
00277     } else if (buf[0] == '&' || buf[0] == '#') {
00278         return 1;
00279     }
00280     
00281     error_print("Unsupported spell command '%c'.\n"
00282             "This is a bug; mail " BUGEMAIL " about it.\n", buf[0]);
00283     return -1;
00284 }

void popup_menu GtkText *    gtktext,
GdkEventButton *    eb
[static]
 

Definition at line 521 of file gtkspell.c.

References BUFSIZE, get_curword(), make_menu(), and misspelled_suggest().

Referenced by button_press_intercept_cb().

00521                                                              {
00522     char buf[BUFSIZE];
00523     GList *list, *l;
00524 
00525     get_curword(gtktext, buf, NULL, NULL);
00526 
00527     list = misspelled_suggest(buf);
00528     if (list != NULL) {
00529         gtk_menu_popup(make_menu(list, gtktext), NULL, NULL, NULL, NULL,
00530                 eb->button, eb->time);
00531         for (l = list; l != NULL; l = l->next)
00532             g_free(l->data);
00533         g_list_free(list);
00534     }
00535 }

int readline char *    buf [static]
 

Definition at line 95 of file gtkspell.c.

References BUFSIZE, and readpipe().

Referenced by gtkspell_start().

00095                                {
00096     return readpipe(buf, BUFSIZE);
00097 }

int readpipe char *    buf,
int    bufsize
[static]
 

Definition at line 79 of file gtkspell.c.

References error_print(), and fd_read.

Referenced by readline(), and readresponse().

00079                                             {
00080     int len;
00081     len = read(fd_read[0], buf, bufsize-1);
00082     if (len < 0) {
00083         error_print("read: %s\n", strerror(errno));
00084         return -1;
00085     } else if (len == 0) {
00086         error_print("pipe closed.\n");
00087         return -1;
00088     } else if (len == bufsize-1) {
00089         error_print("buffer overflowed?\n");
00090     }
00091 
00092     buf[len] = 0;
00093     return len;
00094 }

int readresponse char *    buf [static]
 

Definition at line 99 of file gtkspell.c.

References BUFSIZE, and readpipe().

Referenced by misspelled_suggest(), and misspelled_test().

00099                                    {
00100     int len;
00101     len = readpipe(buf, BUFSIZE);
00102 
00103     /* all ispell responses of any reasonable length should end in \n\n.
00104      * depending on the speed of the spell checker, this may require more
00105      * reading. */
00106     if (len >= 2 && (buf[len-1] != '\n' || buf[len-2] != '\n')) {
00107         len += readpipe(buf+len, BUFSIZE-len);
00108     }
00109 
00110     /* now we can remove all of the the trailing newlines. */
00111     while (len > 0 && buf[len-1] == '\n')
00112         buf[--len] = 0;
00113 
00114     return len;
00115 }

void replace_word GtkWidget *    w,
gpointer    d
[static]
 

Definition at line 444 of file gtkspell.c.

References BUFSIZE, and get_curword().

Referenced by make_menu().

00444                                                    {
00445     int start, end, newword_len;
00446     char *newword;
00447     char buf[BUFSIZE];
00448 
00449     /* we don't save their position, 
00450      * because the cursor is moved by the click. */
00451 
00452     gtk_text_freeze(GTK_TEXT(d));
00453 
00454     gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), &newword);
00455     get_curword(GTK_TEXT(d), buf, &start, &end);
00456 
00457     newword_len = strlen(newword);
00458 
00459     gtk_text_set_point(GTK_TEXT(d), end);
00460     gtk_text_backward_delete(GTK_TEXT(d), end-start);
00461     gtk_text_insert(GTK_TEXT(d), NULL, NULL, NULL, newword, newword_len);
00462 
00463     gtk_text_thaw(GTK_TEXT(d));
00464 
00465     gtk_editable_set_position(GTK_EDITABLE(d), start+newword_len);
00466 }

void set_up_signal   [static]
 

Definition at line 623 of file gtkspell.c.

References sigchld().

Referenced by gtkspell_start().

00623                             {
00624 #ifndef __MINGW32__
00625     struct sigaction sigact;
00626     memset(&sigact, 0, sizeof(struct sigaction));
00627 
00628     sigact.sa_handler = sigchld;
00629     sigaction(SIGCHLD, &sigact, NULL);
00630 #endif
00631 }

void sigchld int    param [static]
 

Definition at line 610 of file gtkspell.c.

References gtkspell_running(), and spell_pid.

Referenced by set_up_signal().

00610                                {
00611 #ifndef __MINGW32__
00612     if (gtkspell_running() &&
00613         (waitpid(spell_pid, NULL, WNOHANG) == spell_pid)) {
00614         spell_pid = 0;
00615     } else {
00616         /* a default SIGCHLD handler.
00617          * what else to do here? */
00618         waitpid(-1, NULL, WNOHANG);
00619     }
00620 #endif
00621 }

void writetext char *    text [static]
 

Definition at line 76 of file gtkspell.c.

References fd_write.

Referenced by gtkspell_start(), misspelled_suggest(), and misspelled_test().

00076                                   {
00077     write(fd_write[1], text, strlen(text));
00078 }


Variable Documentation

int fd_read[2] [static]
 

Definition at line 53 of file gtkspell.c.

Referenced by gtkspell_start(), and readpipe().

int fd_write[2] [static]
 

Definition at line 53 of file gtkspell.c.

Referenced by gtkspell_start(), and writetext().

GdkColor highlight = { 0, 255*256, 0, 0 } [static]
 

Definition at line 57 of file gtkspell.c.

Referenced by check_at().

int signal_set_up = 0 [static]
 

Definition at line 54 of file gtkspell.c.

Referenced by gtkspell_start().

pid_t spell_pid = -1 [static]
 

Definition at line 52 of file gtkspell.c.

Referenced by gtkspell_running(), gtkspell_start(), gtkspell_stop(), and sigchld().


Contact: Andy Maloney     [Documentation generated by doxygen]