summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDom Lachowicz <domlachowicz@gmail.com>2006-01-14 00:17:53 +0000
committerDom Lachowicz <domlachowicz@gmail.com>2006-01-14 00:17:53 +0000
commit23ec7628a7ee57603d8a6cd76a88b922804c7354 (patch)
tree909dc5b05cdc1cc7714f29a7ddc4157cde1963cf
parent59b8531c8ae272a146176e006d8c68e2f19a6b2b (diff)
downloadenchant-23ec7628a7ee57603d8a6cd76a88b922804c7354.tar.gz
re-implement exists() in terms of list_dicts() if exists() doesn't exist; move aspell 0.50 hackery around for upcoming configure.in magic
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@21085 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/aspell/aspell_provider.c61
-rw-r--r--src/enchant.c57
2 files changed, 59 insertions, 59 deletions
diff --git a/src/aspell/aspell_provider.c b/src/aspell/aspell_provider.c
index 6f1215b..750e5af 100644
--- a/src/aspell/aspell_provider.c
+++ b/src/aspell/aspell_provider.c
@@ -184,52 +184,11 @@ aspell_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict)
g_free (dict);
}
-static int
-aspell_provider_dictionary_exists (struct str_enchant_provider * me,
- const char *const tag)
-{
- /* TODO: get kevina to apply my patch */
- EnchantDict * dict;
- int exists = 0;
-
-#ifdef ASPELL_DICT_DIR
- char * file, * ext;
-
- /* hack for a quick existence test */
-
- ext = g_strdup_printf ("%s.dat", tag);
- file = g_build_filename (ASPELL_DICT_DIR, ext, NULL);
- if (g_file_test (file, G_FILE_TEST_EXISTS))
- exists = 1;
- g_free (file);
- g_free (ext);
-
- if (strlen (tag) > 2 && tag[2] == '_') {
- ext = g_strdup_printf ("%c%c.dat", tag[0], tag[1]);
- file = g_build_filename (ASPELL_DICT_DIR, ext, NULL);
- if (g_file_test (file, G_FILE_TEST_EXISTS))
- exists = 1;
- g_free (file);
- g_free (ext);
- }
-#endif
-
- if (!exists) {
- dict = aspell_provider_request_dict (me, tag);
- if (dict) {
- exists = 1;
- aspell_provider_dispose_dict (me, dict);
- }
- }
-
- return exists;
-}
-
+#if ASPELL_0_50_0
static char **
aspell_provider_list_dicts (EnchantProvider * me,
size_t * out_n_dicts)
{
-#if ASPELL_0_50_0
PspellConfig * spell_config;
AspellDictInfoList * dlist;
AspellDictInfoEnumeration * dels;
@@ -265,16 +224,8 @@ aspell_provider_list_dicts (EnchantProvider * me,
delete_pspell_config (spell_config);
return out_list;
-#else
-
-#ifdef __GNUC__
-#warning "You're using an ancient aspell. aspell_provider_list_dicts() is not implemented."
-#endif
-
- *out_n_dicts = 0;
- return NULL;
-#endif
}
+#endif
static void
aspell_provider_free_string_list (EnchantProvider * me, char **str_list)
@@ -313,10 +264,16 @@ init_enchant_provider (void)
provider->dispose = aspell_provider_dispose;
provider->request_dict = aspell_provider_request_dict;
provider->dispose_dict = aspell_provider_dispose_dict;
- provider->dictionary_exists = aspell_provider_dictionary_exists;
provider->identify = aspell_provider_identify;
provider->describe = aspell_provider_describe;
+
+#if ASPELL_0_50_0
provider->list_dicts = aspell_provider_list_dicts;
+#else
+# ifdef __GNUC__
+# warning "You're using an ancient aspell. aspell_provider_list_dicts() is not implemented."
+# endif
+#endif
provider->free_string_list = aspell_provider_free_string_list;
return provider;
diff --git a/src/enchant.c b/src/enchant.c
index 3d5ebb0..9e581c8 100644
--- a/src/enchant.c
+++ b/src/enchant.c
@@ -1283,8 +1283,8 @@ enchant_broker_list_dicts (EnchantBroker * broker,
char ** dicts;
dicts = (*provider->list_dicts) (provider, &n_dicts);
- name = (*provider->identify) (provider);
- desc = (*provider->describe) (provider);
+ name = (provider->identify ? (*provider->identify) (provider) : "");
+ desc = (provider->describe ? (*provider->describe) (provider) : "");
file = g_module_name (module);
for (i = 0; i < n_dicts; i++)
@@ -1329,6 +1329,51 @@ enchant_broker_free_dict (EnchantBroker * broker, EnchantDict * dict)
g_hash_table_remove (broker->dict_map, session->personal_filename);
}
+static int
+_enchant_provider_dictionary_exists (EnchantProvider * provider,
+ const char * const tag)
+{
+ int exists = 0;
+
+ if (provider->dictionary_exists)
+ {
+ exists = (*provider->dictionary_exists) (provider, tag);
+ }
+ else if (provider->list_dicts)
+ {
+ const char * tag, * name, * desc, * file;
+ size_t n_dicts, i;
+ char ** dicts;
+
+ dicts = (*provider->list_dicts) (provider, &n_dicts);
+
+ for (i = 0; i < n_dicts; i++)
+ {
+ if (!strcmp(dicts[i], tag))
+ {
+ exists = 1;
+ break;
+ }
+ }
+
+ enchant_provider_free_string_list (provider, dicts);
+ }
+ else if (provider->request_dict)
+ {
+ EnchantDict *dict = NULL;
+
+ dict = (*provider->request_dict) (provider, tag);
+ if (dict)
+ {
+ if (provider->dispose)
+ (*provider->dispose) (provider);
+ exists = 1;
+ }
+ }
+
+ return exists;
+}
+
/**
* enchant_broker_dict_exists
* @broker: A non-null #EnchantBroker
@@ -1361,12 +1406,10 @@ enchant_broker_dict_exists (EnchantBroker * broker,
{
provider = (EnchantProvider *) list->data;
- if (provider->dictionary_exists)
+ if (_enchant_provider_dictionary_exists (provider, normalized_tag))
{
- if ((*provider->dictionary_exists) (provider, normalized_tag)) {
- g_free (normalized_tag);
- return 1;
- }
+ g_free (normalized_tag);
+ return 1;
}
}