diff options
author | Dom Lachowicz <domlachowicz@gmail.com> | 2005-11-24 20:20:35 +0000 |
---|---|---|
committer | Dom Lachowicz <domlachowicz@gmail.com> | 2005-11-24 20:20:35 +0000 |
commit | c9cfa44b713e31311a73bbd63b80094f20d7175b (patch) | |
tree | ef273d2931fb75a3439350b77927faabdc3d3157 | |
parent | 30859ff83d24fb6eca0818bd86a033641a3b274d (diff) | |
download | enchant-c9cfa44b713e31311a73bbd63b80094f20d7175b.tar.gz |
bug 9234 - relocatable library support on win32 - largely from Ryan Kelly <ryan-bugs@rfk.id.au>
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@21077 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | src/enchant-provider.h | 5 | ||||
-rw-r--r-- | src/enchant.c | 82 | ||||
-rw-r--r-- | src/ispell/ispell_checker.cpp | 11 | ||||
-rw-r--r-- | src/myspell/myspell_checker.cpp | 11 | ||||
-rw-r--r-- | src/uspell/uspell_provider.cpp | 17 | ||||
-rw-r--r-- | tests/enchant-ispell.c | 2 | ||||
-rw-r--r-- | tests/enchant-lsmod.c | 2 |
8 files changed, 110 insertions, 22 deletions
diff --git a/configure.in b/configure.in index 23bc6ae..c79919d 100644 --- a/configure.in +++ b/configure.in @@ -11,7 +11,7 @@ ENCHANT_MINOR_VERSION=2 dnl 3) Increment when interfaces not changed at all, dnl only bug fixes or internal changes made. dnl 4b) Set to zero when adding, removing or changing interfaces. -ENCHANT_MICRO_VERSION=0 +ENCHANT_MICRO_VERSION=1 dnl dnl Set this too MAJOR_VERSION_PLUS_MINOR_VERSION=`expr $ENCHANT_MAJOR_VERSION + $ENCHANT_MINOR_VERSION` diff --git a/src/enchant-provider.h b/src/enchant-provider.h index a9b68f0..df7817a 100644 --- a/src/enchant-provider.h +++ b/src/enchant-provider.h @@ -44,7 +44,7 @@ extern "C" { /* private */ ENCHANT_MODULE_EXPORT(char *) - _enchant_get_user_language(void); + enchant_get_user_language(void); #ifdef _WIN32 #define ENCHANT_PLUGIN_DECLARE(name) static HANDLE s_hModule = (HANDLE)(NULL); BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { s_hModule = hModule; return TRUE; } @@ -60,6 +60,9 @@ ENCHANT_MODULE_EXPORT (char *) ENCHANT_MODULE_EXPORT (char *) enchant_get_registry_value (const char * const prefix, const char * const key); +ENCHANT_MODULE_EXPORT(char *) + enchant_get_prefix_dir(void); + ENCHANT_MODULE_EXPORT(void) enchant_dict_set_error (EnchantDict * dict, const char * const err); diff --git a/src/enchant.c b/src/enchant.c index 3fd19a2..3d5ebb0 100644 --- a/src/enchant.c +++ b/src/enchant.c @@ -124,18 +124,28 @@ enchant_unlock_file (FILE * f) static char * enchant_get_module_dir (void) { + char * module_dir = NULL; + #ifdef XP_TARGET_COCOA return g_strdup ([[EnchantResourceProvider instance] moduleFolder]); #endif - char * module_dir = NULL; + /* Look for explicitly set registry values */ module_dir = enchant_get_registry_value ("Config", "Module_Dir"); if (module_dir) return module_dir; -#ifdef ENABLE_BINRELOC - return g_strdup (BR_LIBDIR ("/enchant")); -#elif defined(ENCHANT_GLOBAL_MODULE_DIR) + /* Dynamically locate library and search for modules relative to it. */ + char * prefix = NULL; + prefix = enchant_get_prefix_dir(); + if(prefix) + { + module_dir = g_build_filename(prefix,"lib","enchant",NULL); + g_free(prefix); + return module_dir; + } + +#if defined(ENCHANT_GLOBAL_MODULE_DIR) return g_strdup (ENCHANT_GLOBAL_MODULE_DIR); #else return NULL; @@ -148,15 +158,23 @@ enchant_get_conf_dir (void) #ifdef XP_TARGET_COCOA return g_strdup ([[EnchantResourceProvider instance] configFolder]); #endif - char * ordering_dir = NULL; + char * ordering_dir = NULL, * prefix = NULL;; + /* Look for explicitly set registry values */ ordering_dir = enchant_get_registry_value ("Config", "Data_Dir"); if (ordering_dir) return ordering_dir; -#ifdef ENABLE_BINRELOC - return g_strdup (BR_DATADIR ("/enchant")); -#elif defined(ENCHANT_GLOBAL_ORDERING) + /* Dynamically locate library and search for files relative to it. */ + prefix = enchant_get_prefix_dir(); + if(prefix) + { + ordering_dir = g_build_filename(prefix,"share","enchant",NULL); + g_free(prefix); + return ordering_dir; + } + +#if defined(ENCHANT_GLOBAL_ORDERING) return g_strdup (ENCHANT_GLOBAL_ORDERING); #else return NULL; @@ -1103,21 +1121,25 @@ enchant_broker_request_pwl_dict (EnchantBroker * broker, const char *const pwl) { EnchantSession *session; EnchantDict *dict = NULL; + char * normalized_pwl; g_return_val_if_fail (broker, NULL); g_return_val_if_fail (pwl && strlen(pwl), NULL); enchant_broker_clear_error (broker); - dict = (EnchantDict*)g_hash_table_lookup (broker->dict_map, (gpointer) pwl); + normalized_pwl = enchant_normalize_dictionary_tag (pwl); + dict = (EnchantDict*)g_hash_table_lookup (broker->dict_map, (gpointer) normalized_pwl); if (dict) { + g_free (normalized_pwl); return dict; } session = enchant_session_new_with_pwl (NULL, pwl, "Personal WordList", TRUE); if (!session) { - broker->error = g_strdup_printf ("Couldn't open personal wordlist '%s'", pwl); + broker->error = g_strdup_printf ("Couldn't open personal wordlist '%s'", normalized_pwl); + g_free (normalized_pwl); return NULL; } @@ -1126,7 +1148,7 @@ enchant_broker_request_pwl_dict (EnchantBroker * broker, const char *const pwl) dict = g_new0 (EnchantDict, 1); dict->enchant_private_data = (void *)session; - g_hash_table_insert (broker->dict_map, (gpointer)g_strdup (pwl), dict); + g_hash_table_insert (broker->dict_map, (gpointer)g_strdup (normalized_pwl), dict); return dict; } @@ -1438,7 +1460,7 @@ enchant_broker_get_error (EnchantBroker * broker) /* private */ ENCHANT_MODULE_EXPORT(char *) -_enchant_get_user_language(void) +enchant_get_user_language(void) { char * locale = NULL; @@ -1465,3 +1487,39 @@ _enchant_get_user_language(void) return locale; } + + +/** + * enchant_get_prefix_dir + * + * Returns a string giving the location of the base directory + * of the enchant installation. This corresponds roughly to + * the --prefix option given to ./configure when enchant is + * compiled, except it is determined at runtime based on the location + * of the enchant library. + * + * This API is private to the providers. + * + */ +ENCHANT_MODULE_EXPORT (char *) +enchant_get_prefix_dir(void) +{ + char * prefix = NULL; + +#ifdef _WIN32 + /* Dynamically locate library and return containing directory */ + HINSTANCE hInstance = GetModuleHandle("libenchant-1"); + if(hInstance != NULL) + { + char dll_path[MAX_PATH]; + + if(GetModuleFileName(hInstance,dll_path,MAX_PATH)) + prefix = g_path_get_dirname(dll_path); + } +#elif defined(ENABLE_BINRELOC) + /* Use standard binreloc PREFIX macro */ + prefix = g_strdup (PREFIX); +#endif + + return prefix; +} diff --git a/src/ispell/ispell_checker.cpp b/src/ispell/ispell_checker.cpp index 1b50de2..28d4a91 100644 --- a/src/ispell/ispell_checker.cpp +++ b/src/ispell/ispell_checker.cpp @@ -363,10 +363,21 @@ ispell_checker_get_prefix (void) #ifndef XP_TARGET_COCOA char * ispell_prefix = NULL; + /* Look for explicitly set registry values */ ispell_prefix = enchant_get_registry_value ("Ispell", "Data_Dir"); if (ispell_prefix) return ispell_prefix; #endif + + /* Dynamically locate library and search for modules relative to it. */ + char * enchant_prefix = enchant_get_prefix_dir(); + if(enchant_prefix) + { + ispell_prefix = g_build_filename(enchant_prefix, "share", "enchant", "ispell", NULL); + g_free(enchant_prefix); + return ispell_prefix; + } + #ifdef ENCHANT_ISPELL_DICT_DIR return g_strdup (ENCHANT_ISPELL_DICT_DIR); #else diff --git a/src/myspell/myspell_checker.cpp b/src/myspell/myspell_checker.cpp index 7a01179..8c6f9e4 100644 --- a/src/myspell/myspell_checker.cpp +++ b/src/myspell/myspell_checker.cpp @@ -76,10 +76,21 @@ myspell_checker_get_prefix (void) { char * data_dir = NULL; + /* Look for explicitly set registry values */ data_dir = enchant_get_registry_value ("Myspell", "Data_Dir"); if (data_dir) return data_dir; + /* Dynamically locate library and search for modules relative to it. */ + char * prefix = enchant_get_prefix_dir(); + if(prefix) + { + data_dir = g_build_filename(prefix, "share", "enchant", "myspell", NULL); + g_free(prefix); + return data_dir; + } + + #ifdef ENCHANT_MYSPELL_DICT_DIR return g_strdup (ENCHANT_MYSPELL_DICT_DIR); #else diff --git a/src/uspell/uspell_provider.cpp b/src/uspell/uspell_provider.cpp index 929ca0e..7164b1f 100644 --- a/src/uspell/uspell_provider.cpp +++ b/src/uspell/uspell_provider.cpp @@ -59,6 +59,15 @@ uspell_checker_get_prefix (void) if (data_dir) return data_dir; + /* Dynamically locate library and search for modules relative to it. */ + char * enchant_prefix = _enchant_get_prefix_dir(); + if(enchant_prefix) + { + uspell_prefix = g_build_filename(enchant_prefix, "share", "enchant", "uspell", NULL); + g_free(enchant_prefix); + return uspell_prefix; + } + #ifdef ENCHANT_USPELL_DICT_DIR return g_strdup (ENCHANT_USPELL_DICT_DIR); #else @@ -81,9 +90,7 @@ uspell_dict_check (EnchantDict * me, const char *const word, size_t len) curBuf = buf1; otherBuf = buf2; manager = reinterpret_cast<uSpell *>(me->user_data); -#ifdef DEBUG - fprintf(stdout, "Checking [%s]\n", word); -#endif + length = utf8_wide(curBuf, myWord, MAXCHARS); if (manager->isSpelledRight(curBuf, length)) { return 0; // correct the first time @@ -301,9 +308,7 @@ uspell_request_manager (const char * private_dir, size_t mapIndex) auxFileName = g_build_filename (home_dir, ".enchant", transPart, NULL); g_free (transPart); g_free (home_dir); -#ifdef DEBUG - fprintf(stdout, "Trying to assimilate file [%s]\n", auxFileName); -#endif + (void) manager->assimilateFile (auxFileName); g_free (auxFileName); } diff --git a/tests/enchant-ispell.c b/tests/enchant-ispell.c index ce329ff..9e212ce 100644 --- a/tests/enchant-ispell.c +++ b/tests/enchant-ispell.c @@ -250,7 +250,7 @@ parse_file (FILE * in, FILE * out, IspellMode_t mode, int countLines) if (mode == MODE_A) print_version (out); - lang = _enchant_get_user_language(); + lang = enchant_get_user_language(); if(!lang) return 1; diff --git a/tests/enchant-lsmod.c b/tests/enchant-lsmod.c index 79ace0b..0de2de5 100644 --- a/tests/enchant-lsmod.c +++ b/tests/enchant-lsmod.c @@ -82,7 +82,7 @@ main (int argc, char **argv) if (i < (argc - 1)) { lang_tag = g_strdup (argv[++i]); } else { - lang_tag = _enchant_get_user_language(); + lang_tag = enchant_get_user_language(); if (!lang_tag || !strcmp (lang_tag, "C")) { if (lang_tag) /* lang might be "C" */ |