Home | History | Annotate | Download | only in patches
      1 --- enchant-1.3.0/src/enchant.c.orig	2007-04-28 19:28:02.683333000 +0800
      2 +++ enchant-1.3.0/src/enchant.c	2007-04-28 19:26:37.381393000 +0800
      3 @@ -31,6 +31,8 @@
      4  #include <stdio.h>
      5  #include <stdlib.h>
      6  #include <string.h>
      7 +#include <fcntl.h>
      8 +#include <sys/stat.h>
      9  
     10  #include <glib.h>
     11  #include <gmodule.h>
     12 @@ -316,7 +318,101 @@
     13  	return session;
     14  }
     15  
     16 -static EnchantSession *
     17 +/*if no personal dictionary exists, check for Aspell dictionaries
     18 +convert aspell personal dict to myspell format and create enchant 
     19 +this function returns the dictionary file name of the converted
     20 +dictionary*/
     21 +static void
     22 +convert_from_aspell (const char * tag, const char * filename)
     23 +{
     24 +	char * dic = NULL;
     25 +	char * home_dir = NULL;
     26 +	char * tmpdic = NULL;
     27 +	char * tmp = NULL;
     28 +	char * tmptag = NULL;
     29 +	char * tagdir = NULL;
     30 +	char * enchant_path = NULL;
     31 +       
     32 +	home_dir = enchant_get_user_home_dir ();
     33 +	if (home_dir) {
     34 +                tmpdic = g_build_filename (home_dir, g_strconcat(".aspell.", tag, ".pws", NULL), 
     35 +                                                                NULL);
     36 +                if (g_file_test(tmpdic, G_FILE_TEST_EXISTS)) {
     37 +                        dic = g_strdup (tmpdic);
     38 +                	g_free (tmpdic);
     39 +		}
     40 +		else {
     41 +			char * shortened;
     42 +			char * end;
     43 +			shortened = g_strdup (tag);
     44 +			end = shortened;
     45 +			while (*end != '\0')
     46 +				end++;
     47 +			while (end != shortened) {
     48 +				end --;
     49 +				if (*end == '_') {
     50 +					*end = '\0';
     51 +					tmpdic = g_build_filename (home_dir, g_strconcat (".aspell.", shortened, ".pws", NULL), NULL);	
     52 +					if (g_file_test(tmpdic, G_FILE_TEST_EXISTS)) {
     53 +						dic = g_strdup (tmpdic);		
     54 +						g_free (tmpdic);
     55 +						break;
     56 +					}
     57 +					g_free (tmpdic);
     58 +				}
     59 +			}
     60 +			g_free (shortened);
     61 +                }
     62 + 
     63 +		tagdir = g_build_filename (home_dir, ENCHANT_USER_PATH_EXTENSION, "tags", NULL);
     64 +		if (!g_file_test (tagdir, G_FILE_TEST_EXISTS)) {
     65 +			mkdir (tagdir, 0700);
     66 +			g_free (tagdir);
     67 +		}
     68 +		tmptag = g_build_filename (home_dir, ENCHANT_USER_PATH_EXTENSION, "tags",
     69 +					g_strconcat(".aspell.", tag, NULL), NULL);
     70 +		if (g_file_test(tmptag, G_FILE_TEST_EXISTS)) {
     71 +		//Aspell dictionary has been converted.
     72 +			g_free (tmptag);
     73 +			g_free (home_dir);
     74 +			return;
     75 +		}
     76 +	}
     77 +
     78 +	if (dic) {
     79 +		char * directory;
     80 +		char line[BUFSIZ];
     81 +		char *aspell = NULL;
     82 +		FILE * perspell = NULL;
     83 +
     84 +               if (aspell = fopen (dic, "r")) {
     85 +			if (g_file_test (filename, G_FILE_TEST_EXISTS))
     86 +				perspell = fopen (filename, "a");
     87 +			else 
     88 +				perspell = fopen (filename, "w");
     89 +
     90 +			if (perspell)
     91 +			{
     92 +				/*intentionaly discard the first line in aspell dictionary
     93 +				becaues it is the identification of aspell dicts, which 
     94 +				is useless for enchant dictionaries*/
     95 +				if (fgets (line, sizeof (line), aspell)) {
     96 +					while (fgets (line, sizeof (line), aspell))
     97 +						fputs (line, perspell);
     98 +				}
     99 +
    100 +				creat (tmptag, 0600);
    101 +				fclose (perspell);
    102 +			}
    103 +			fclose (aspell);
    104 +		}
    105 +	}
    106 +	g_free (home_dir);
    107 +	g_free (tmptag);
    108 +	g_free (dic);
    109 +}
    110 +
    111 +static EnchantSession *       
    112  enchant_session_new (EnchantProvider *provider, const char * const lang)
    113  {
    114  	EnchantSession * session;
    115 @@ -335,6 +431,7 @@
    116  			g_free (home_dir);
    117  		}
    118  
    119 +	convert_from_aspell (lang, dic);
    120  	session = enchant_session_new_with_pwl (provider, dic, lang, FALSE);	
    121  	
    122  	if (dic)
    123