diff options
author | Dom Lachowicz <domlachowicz@gmail.com> | 2008-06-17 21:45:57 +0000 |
---|---|---|
committer | Dom Lachowicz <domlachowicz@gmail.com> | 2008-06-17 21:45:57 +0000 |
commit | cbc508b0f65748f79928ef126f6cd38cb895f1f3 (patch) | |
tree | 9ef71ae9f9d31d1f88a5b2669412baba0503489d | |
parent | e6814b614036f5aff972953c6f73595d7d4bb0be (diff) | |
download | enchant-cbc508b0f65748f79928ef126f6cd38cb895f1f3.tar.gz |
Various fixes from TML to build Enchant on Win32 using MinGW/MSYS
git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@24261 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r-- | src/aspell/aspell_provider.c | 30 | ||||
-rw-r--r-- | src/enchant.c | 27 | ||||
-rw-r--r-- | src/myspell/myspell_checker.cpp | 6 | ||||
-rw-r--r-- | src/pwl.c | 19 |
4 files changed, 52 insertions, 30 deletions
diff --git a/src/aspell/aspell_provider.c b/src/aspell/aspell_provider.c index 4573d7e..9df1bf9 100644 --- a/src/aspell/aspell_provider.c +++ b/src/aspell/aspell_provider.c @@ -338,14 +338,14 @@ init_enchant_provider (void) #if defined(_WIN32) -static WCHAR* GetDirectoryOfThisLibrary() +static WCHAR* GetDirectoryOfThisLibrary(void) { WCHAR dll_path[MAX_PATH]; gchar* utf8_dll_path; gchar* utf8_prefix; gunichar2* utf16_prefix; - if(!GetModuleFileName(s_hModule,dll_path,MAX_PATH)) + if(!GetModuleFileNameW(s_hModule,dll_path,MAX_PATH)) { /* unable to determine filename of this library */ return NULL; } @@ -372,7 +372,7 @@ static HMODULE LoadLibraryFromPath(const WCHAR* path, const WCHAR* libraryName) wcscat(wszFullLibraryPath, L"\\"); wcscat(wszFullLibraryPath, libraryName); - h = LoadLibrary(wszFullLibraryPath); + h = LoadLibraryW(wszFullLibraryPath); g_free(wszFullLibraryPath); return h; @@ -385,13 +385,13 @@ static WCHAR* GetRegistryValue(HKEY baseKey, const WCHAR * uKeyName, const WCHAR DWORD dwSize; WCHAR* wszValue = NULL; - if(RegOpenKeyEx(baseKey, uKeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + if(RegOpenKeyExW(baseKey, uKeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { /* Determine size of string */ - if(RegQueryValueEx( hKey, uKey, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS) + if(RegQueryValueExW( hKey, uKey, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS) { wszValue = g_new0(WCHAR, dwSize + 1); - RegQueryValueEx(hKey, uKey, NULL, &lType, (LPBYTE) wszValue, &dwSize); + RegQueryValueExW(hKey, uKey, NULL, &lType, (LPBYTE) wszValue, &dwSize); } } @@ -399,10 +399,9 @@ static WCHAR* GetRegistryValue(HKEY baseKey, const WCHAR * uKeyName, const WCHAR } #endif -void configure_enchant_provider(EnchantProvider * me, const char *dir_name) -{ #if defined(_WIN32) - const WCHAR* aspell_module_name = L"aspell-15.dll"; +gboolean try(EnchantProvider * me, const char *dir_name, const WCHAR *aspell_module_name) +{ HMODULE aspell_module = NULL; char* szModule; @@ -413,7 +412,7 @@ void configure_enchant_provider(EnchantProvider * me, const char *dir_name) WCHAR* wszModule; wszModule = g_utf8_to_utf16 (szModule, -1, NULL, NULL, NULL); - aspell_module = LoadLibrary(wszModule); + aspell_module = LoadLibraryW(wszModule); g_free(wszModule); } @@ -442,7 +441,7 @@ void configure_enchant_provider(EnchantProvider * me, const char *dir_name) if (aspell_module == NULL) { /* then try default lookup */ - aspell_module = LoadLibrary(aspell_module_name); + aspell_module = LoadLibraryW(aspell_module_name); } if (aspell_module == NULL) @@ -452,9 +451,18 @@ void configure_enchant_provider(EnchantProvider * me, const char *dir_name) me->request_dict = NULL; me->dispose_dict = NULL; me->list_dicts = NULL; + return FALSE; } + return TRUE; +} #endif +void configure_provider(EnchantProvider * me, const char *dir_name) +{ +#if defined(_WIN32) + try(me, dir_name, L"aspell-15.dll") || + try(me, dir_name, L"libaspell-15.dll"); +#endif } diff --git a/src/enchant.c b/src/enchant.c index 7c0caea..2765f56 100644 --- a/src/enchant.c +++ b/src/enchant.c @@ -314,13 +314,13 @@ enchant_get_registry_value_ex (int current_user, const char * const prefix, cons uKeyName = g_utf8_to_utf16 (keyName, -1, NULL, NULL, NULL); uKey = g_utf8_to_utf16 (key, -1, NULL, NULL, NULL); - if(RegOpenKeyEx(baseKey, uKeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + if(RegOpenKeyExW(baseKey, uKeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { /* Determine size of string */ - if(RegQueryValueEx( hKey, uKey, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS) + if(RegQueryValueExW( hKey, uKey, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS) { wszValue = g_new0(WCHAR, dwSize + 1); - RegQueryValueEx(hKey, uKey, NULL, &lType, (LPBYTE) wszValue, &dwSize); + RegQueryValueExW(hKey, uKey, NULL, &lType, (LPBYTE) wszValue, &dwSize); } } @@ -2160,17 +2160,18 @@ enchant_get_prefix_dir(void) #ifdef _WIN32 if (!prefix) { /* Dynamically locate library and return containing directory */ - HINSTANCE hInstance = GetModuleHandle(L"libenchant"); - if(hInstance != NULL) + WCHAR dll_path[MAX_PATH]; + + if(GetModuleFileNameW(s_hModule,dll_path,MAX_PATH)) { - WCHAR dll_path[MAX_PATH]; - - if(GetModuleFileName(hInstance,dll_path,MAX_PATH)) - { - gchar* utf8_dll_path = g_utf16_to_utf8 (dll_path, -1, NULL, NULL, NULL); - prefix = g_path_get_dirname(utf8_dll_path); - g_free(utf8_dll_path); - } + gchar* utf8_dll_path = g_utf16_to_utf8 (dll_path, -1, NULL, NULL, NULL); + prefix = g_path_get_dirname(utf8_dll_path); + g_free(utf8_dll_path); + /* Strip off "bin" subfolder if present */ + if (strlen(prefix) >=6 && + G_IS_DIR_SEPARATOR(prefix[strlen(prefix)-4]) && + g_ascii_strcasecmp(prefix+strlen(prefix)-3, "bin") == 0) + prefix[strlen(prefix)-4] = '\0'; } } #endif diff --git a/src/myspell/myspell_checker.cpp b/src/myspell/myspell_checker.cpp index 0379206..add4f41 100644 --- a/src/myspell/myspell_checker.cpp +++ b/src/myspell/myspell_checker.cpp @@ -81,13 +81,13 @@ static WCHAR* GetRegistryValue(HKEY baseKey, const WCHAR * uKeyName, const WCHAR DWORD dwSize; WCHAR* wszValue = NULL; - if(RegOpenKeyEx(baseKey, uKeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + if(RegOpenKeyExW(baseKey, uKeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) { /* Determine size of string */ - if(RegQueryValueEx( hKey, uKey, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS) + if(RegQueryValueExW( hKey, uKey, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS) { wszValue = g_new0(WCHAR, dwSize + 1); - RegQueryValueEx(hKey, uKey, NULL, &lType, (LPBYTE) wszValue, &dwSize); + RegQueryValueExW(hKey, uKey, NULL, &lType, (LPBYTE) wszValue, &dwSize); } } @@ -60,7 +60,8 @@ #include <fcntl.h> #ifdef _WIN32 -#include <io.h> +#define WIN32_LEAN_AND_MEAN +#include <windows.h> #endif #include <glib.h> @@ -197,7 +198,13 @@ enchant_lock_file (FILE * f) #elif defined(HAVE_LOCKF) lockf (fileno (f), F_LOCK, 0); #elif defined(_WIN32) - _lock_file(f); + OVERLAPPED overlapped; + + overlapped.Offset = 0; + overlapped.OffsetHigh = 0; + overlapped.hEvent = NULL; + if (!LockFileEx ((HANDLE) _get_osfhandle (fileno (f)), LOCKFILE_EXCLUSIVE_LOCK, 0, 0, 0x80000000, &overlapped)) + g_warning ("Could not lock file\n"); #else /* TODO: UNIX fcntl. This race condition probably isn't too bad. */ #endif /* HAVE_FLOCK */ @@ -211,7 +218,13 @@ enchant_unlock_file (FILE * f) #elif defined(HAVE_LOCKF) lockf (fileno (f), F_ULOCK, 0); #elif defined(_WIN32) - _unlock_file(f); + OVERLAPPED overlapped; + + overlapped.Offset = 0; + overlapped.OffsetHigh = 0; + overlapped.hEvent = NULL; + if (!UnlockFileEx ((HANDLE) _get_osfhandle (fileno (f)), 0, 0, 0x80000000, &overlapped)) + g_warning ("Could not unlock file\n"); #else /* TODO: UNIX fcntl. This race condition probably isn't too bad. */ #endif /* HAVE_FLOCK */ |