comparison src/util.c @ 206:610b7ffc4821

[gaim-migrate @ 216] Yeah, I ripped off torrey's spell checking code and made it work with GAIM :) committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Mon, 01 May 2000 10:12:08 +0000
parents d7690984c0f1
children 6e9b375e30e7
comparison
equal deleted inserted replaced
205:5531861bf3f5 206:610b7ffc4821
743 free(tmp); 743 free(tmp);
744 free(cur_ver); 744 free(cur_ver);
745 } 745 }
746 746
747 747
748 /*
749
750 This function was taken from EveryBuddy and was written by
751 Torrey Searle. tsearle@valhalla.marko.net
752
753 http://www.everybuddy.com
754
755 */
756
757 void spell_check(GtkWidget * text)
758 {
759 int start = 0;
760 int end = 0;
761 int length = gtk_text_get_length(GTK_TEXT(text));
762 static GdkColor * color = NULL;
763 int ignore = 0;
764 int point = gtk_editable_get_position(GTK_EDITABLE(text));
765
766 GString * string;
767
768 if( color == NULL )
769 {
770 GdkColormap * gc = gtk_widget_get_colormap( text );
771 color = g_new0(GdkColor, 1);
772 color->red = 255 * 256;
773 gdk_colormap_alloc_color(gc, color, FALSE, TRUE);
774 }
775
776
777
778 end = point-1;
779 for( start = end-1; start >= 0; start-- )
780 {
781 if((isspace(GTK_TEXT_INDEX(GTK_TEXT(text), start)) || start == 0)
782 && !ignore)
783 {
784 char * word;
785 FILE * file;
786 char buff[1024];
787 word = gtk_editable_get_chars( GTK_EDITABLE(text), start, end );
788 g_snprintf(buff, 1024, "echo \"%s\" | ispell -l", word );
789 file = popen(buff, "r");
790
791 buff[0] = 0;
792 fgets(buff, 255, file);
793
794 if(strlen(buff) > 0 )
795 {
796 string = g_string_new(word);
797 gtk_text_set_point(GTK_TEXT(text), end);
798 gtk_text_backward_delete(GTK_TEXT(text), end-start);
799 gtk_text_insert( GTK_TEXT(text), NULL, color, NULL,
800 string->str, string->len );
801 g_string_free( string, TRUE );
802 }
803 else
804 {
805 string = g_string_new(word);
806 gtk_text_set_point(GTK_TEXT(text), end);
807 gtk_text_backward_delete(GTK_TEXT(text), end-start);
808 gtk_text_insert( GTK_TEXT(text), NULL, &(text->style->fg[0]), NULL,
809 string->str, string->len );
810 g_string_free( string, TRUE );
811 }
812 pclose( file);
813 break;
814 }
815 else if(!isalpha(GTK_TEXT_INDEX(GTK_TEXT(text), start)))
816 {
817 ignore = 1;
818 }
819 }
820 gtk_text_set_point(GTK_TEXT(text), point);
821
822 }
823