summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Albright <eric_albright@sil.org>2007-11-28 08:41:40 +0000
committerEric Albright <eric_albright@sil.org>2007-11-28 08:41:40 +0000
commitd47afd3ae1fa9d114442e37d62e73f7fb7d66512 (patch)
tree80e63c1e4246d8776d2f0198ed5451d87136190c
parentdb7b4940bf979b3c05a4fc92796fd00bf0e1ccd6 (diff)
downloadenchant-d47afd3ae1fa9d114442e37d62e73f7fb7d66512.tar.gz
Refactor: move code to add word to pwl file from enchant_pwl_add_to_trie when flagged to enchant_pwl_add
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@22344 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/pwl.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/pwl.c b/src/pwl.c
index 34ca445..e948d37 100644
--- a/src/pwl.c
+++ b/src/pwl.c
@@ -165,8 +165,7 @@ typedef struct str_enchant_sugg_list
*/
static void enchant_pwl_add_to_trie(EnchantPWL *pwl,
- const char *const word, size_t len,
- gboolean add_to_file);
+ const char *const word, size_t len);
static void enchant_pwl_check_cb(char* match,EnchantTrieMatcher* matcher);
static void enchant_pwl_suggest_cb(char* match,EnchantTrieMatcher* matcher);
@@ -282,7 +281,7 @@ EnchantPWL* enchant_pwl_init_with_file(const char * file)
line[l] = '\0';
if(g_utf8_validate(line, -1, NULL))
- enchant_pwl_add_to_trie(pwl, line, strlen(line), FALSE);
+ enchant_pwl_add_to_trie(pwl, line, strlen(line));
else
g_warning ("Bad UTF-8 sequence in %s at line:%u\n", pwl->filename, line_number);
@@ -309,8 +308,7 @@ void enchant_pwl_free(EnchantPWL *pwl)
}
static void enchant_pwl_add_to_trie(EnchantPWL *pwl,
- const char *const word, size_t len,
- gboolean add_to_file)
+ const char *const word, size_t len)
{
char * normalized_word;
@@ -323,21 +321,6 @@ static void enchant_pwl_add_to_trie(EnchantPWL *pwl,
g_hash_table_insert (pwl->words_in_trie, normalized_word, g_strndup(word,len));
pwl->trie = enchant_trie_insert(pwl->trie, normalized_word);
-
- if (add_to_file && (pwl->filename != NULL))
- {
- FILE *f;
-
- f = g_fopen(pwl->filename, "a");
- if (f)
- {
- enchant_lock_file (f);
- fwrite (word, sizeof(char), len, f);
- fwrite ("\n", sizeof(char), 1, f);
- enchant_unlock_file (f);
- fclose (f);
- }
- }
}
static void enchant_pwl_remove_from_trie(EnchantPWL *pwl,
@@ -358,7 +341,22 @@ static void enchant_pwl_remove_from_trie(EnchantPWL *pwl,
void enchant_pwl_add(EnchantPWL *pwl,
const char *const word, size_t len)
{
- enchant_pwl_add_to_trie(pwl, word, len, TRUE);
+ enchant_pwl_add_to_trie(pwl, word, len);
+
+ if (pwl->filename != NULL)
+ {
+ FILE *f;
+
+ f = g_fopen(pwl->filename, "a");
+ if (f)
+ {
+ enchant_lock_file (f);
+ fwrite (word, sizeof(char), len, f);
+ fwrite ("\n", sizeof(char), 1, f);
+ enchant_unlock_file (f);
+ fclose (f);
+ }
+ }
}
void enchant_pwl_remove(EnchantPWL *pwl,