diff options
author | Reuben Thomas <rrt@sc3d.org> | 2017-03-06 22:11:29 +0000 |
---|---|---|
committer | Reuben Thomas <rrt@sc3d.org> | 2017-03-06 23:30:36 +0000 |
commit | 8c2daf870b6edb5e2504c0da44cf363880b61511 (patch) | |
tree | 6a49d275c60b393251d79941d260a8183788bd57 /providers | |
parent | d5aafe00da470b88f41f5f0ecc296ccbf1d2f0ba (diff) | |
download | enchant-8c2daf870b6edb5e2504c0da44cf363880b61511.tar.gz |
Overhaul configuration mechanisms
Have only one user_config_dir, so change API to enchant_get_user_config_dir,
returning a char *. Make ENCHANT_CONFIG_DIR override it, not supplement it:
this is intended for use by applications embedding Enchant which want to cut
off its external configuration, and for testing.
Look for modules only in one place, under the given prefix (which can be
overridden by ENCHANT_PREFIX_DIR).
The system enchant.ordering is moved to sysconfdir from pkglibdir. Little
point having two separate files, but make it configurable by the sysadmin.
Fix default path relative to g_get_system_data_dirs for finding hunspell
dictionaries (was still using one more suited to myspell).
Make a couple of C++ fixes to the uspell provider. Not currently being built.
Don’t look for Enchant config directly in home directory any more.
Rename some internal functions without leadiing underscore. No point doing
this for merely static functions, as we don’t with most names. Only leave
underscores where there is already a function with the name without the
underscore.
Reverse the order of directories in enchant_get_conf_dirs, so it doesn’t
have to be reversed by its only caller.
Update relevant tests.
Diffstat (limited to 'providers')
-rw-r--r-- | providers/enchant_hunspell.cpp | 31 | ||||
-rw-r--r-- | providers/enchant_uspell.cpp | 22 |
2 files changed, 14 insertions, 39 deletions
diff --git a/providers/enchant_hunspell.cpp b/providers/enchant_hunspell.cpp index 5a77f00..e286dcf 100644 --- a/providers/enchant_hunspell.cpp +++ b/providers/enchant_hunspell.cpp @@ -173,31 +173,16 @@ HunspellChecker::suggestWord(const char* const utf8Word, size_t len, size_t *nsu static GSList * hunspell_checker_get_dictionary_dirs () { - GSList *dirs = NULL; + GSList *dirs = nullptr; - { - GSList *config_dirs, *iter; - - config_dirs = enchant_get_user_config_dirs (); - - for (iter = config_dirs; iter; iter = iter->next) - { - dirs = g_slist_append (dirs, g_build_filename (static_cast<const gchar *>(iter->data), - "hunspell", nullptr)); - } - - g_slist_free_full (config_dirs, free); - } + char * config_dir = enchant_get_user_config_dir (); + dirs = g_slist_append (dirs, g_build_filename (config_dir, "hunspell", nullptr)); + g_free (config_dir); - { - const gchar* const * system_data_dirs = g_get_system_data_dirs (); - const gchar* const * iter; - - for (iter = system_data_dirs; *iter; iter++) - { - dirs = g_slist_append (dirs, g_build_filename (*iter, "hunspell", "dicts", nullptr)); - } - } + for (const gchar* const * iter = g_get_system_data_dirs (); *iter; iter++) + { + dirs = g_slist_append (dirs, g_build_filename (*iter, "hunspell", nullptr)); + } /* Dynamically locate library and search for modules relative to it. */ char * enchant_prefix = enchant_get_prefix_dir(); diff --git a/providers/enchant_uspell.cpp b/providers/enchant_uspell.cpp index 9ed0c88..bd7bdab 100644 --- a/providers/enchant_uspell.cpp +++ b/providers/enchant_uspell.cpp @@ -55,21 +55,11 @@ static const size_t MAXCHARS = 100; // maximum number of bytes of utf8 or chars static GSList * uspell_checker_get_dictionary_dirs (EnchantBroker * broker) { - GSList *dirs = NULL; + GSList *dirs = nullptr; - { - GSList *config_dirs, *iter; - - config_dirs = enchant_get_user_config_dirs (); - - for (iter = config_dirs; iter; iter = iter->next) - { - dirs = g_slist_append (dirs, g_build_filename ((const gchar *)iter->data, - "uspell", NULL)); - } - - g_slist_free_full (config_dirs, free); - } + char * config_dir = enchant_get_user_config_dir (); + dirs = g_slist_append (dirs, g_build_filename (config_dir, "uspell", nullptr)); + g_free (config_dir); { const gchar* const * system_data_dirs = g_get_system_data_dirs (); @@ -77,7 +67,7 @@ uspell_checker_get_dictionary_dirs (EnchantBroker * broker) for (iter = system_data_dirs; *iter; iter++) { - dirs = g_slist_append (dirs, g_build_filename (*iter, "uspell", "dicts", NULL)); + dirs = g_slist_append (dirs, g_build_filename (*iter, "uspell", "dicts", nullptr)); } } @@ -85,7 +75,7 @@ uspell_checker_get_dictionary_dirs (EnchantBroker * broker) char * enchant_prefix = enchant_get_prefix_dir(); if(enchant_prefix) { - char * uspell_prefix = g_build_filename(enchant_prefix, "share", "enchant", "uspell", NULL); + char * uspell_prefix = g_build_filename(enchant_prefix, "share", "enchant", "uspell", nullptr); g_free(enchant_prefix); dirs = g_slist_append (dirs, uspell_prefix); } |