summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancis J Franklin <fjf@svn.abisource.com>2004-11-21 21:45:32 +0000
committerFrancis J Franklin <fjf@svn.abisource.com>2004-11-21 21:45:32 +0000
commit98521be908e3f1b6cf8aa0a77fd82549a291613b (patch)
tree7b41b631dc5b5da7f807954c1f850f956bf5495a
parent3b5e538f08783b5bc9d521b04cc604fe4f10a1ac (diff)
downloadenchant-98521be908e3f1b6cf8aa0a77fd82549a291613b.tar.gz
o add in optional Objective-C code to load bundled AppleSpell module
[AppleSpell module based on submission by Remi Payette] o optional addition module entry point to configure for module directory [allows module to look for associated configuration (etc.) files] git-svn-id: svn+ssh://svn.abisource.com/svnroot/enchant/trunk@20987 bcba8976-2d24-0410-9c9c-aab3bd5fdfd6
-rw-r--r--src/applespell/AppleSpell.config12
-rw-r--r--src/applespell/applespell_checker.h52
-rw-r--r--src/applespell/applespell_checker.mm449
-rw-r--r--src/enchant.c48
-rw-r--r--src/enchant_cocoa.h50
-rw-r--r--src/enchant_cocoa.m83
-rw-r--r--src/ispell/ispell_checker.cpp19
7 files changed, 703 insertions, 10 deletions
diff --git a/src/applespell/AppleSpell.config b/src/applespell/AppleSpell.config
new file mode 100644
index 0000000..a4e8cd7
--- /dev/null
+++ b/src/applespell/AppleSpell.config
@@ -0,0 +1,12 @@
+de_DE de Deutsch
+en_US en English
+en_AU en_AU Australian English
+en_CA en_CA Canadian English
+en_GB en_GB British English
+es_ES es Español
+fr_FR fr Français
+it_IT it Italiano
+nl_NL nl Nederlands
+pt_PT pt Português
+pt_BR pt_BR Português do Brasil
+sv_SE sv Svenska
diff --git a/src/applespell/applespell_checker.h b/src/applespell/applespell_checker.h
new file mode 100644
index 0000000..f387d11
--- /dev/null
+++ b/src/applespell/applespell_checker.h
@@ -0,0 +1,52 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* enchant
+ * Copyright (C) 2004 Remi Payette
+ * Copyright (C) 2004 Francis James Franklin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+#include "enchant-provider.h"
+
+ENCHANT_PLUGIN_DECLARE("AppleSpell")
+
+class AppleSpellChecker
+{
+ public:
+ AppleSpellChecker();
+
+ ~AppleSpellChecker();
+
+ void parseConfigFile (const char * configFile);
+
+ bool checkWord (const char * word, size_t len, NSString * lang);
+ char ** suggestWord (const char * const word, size_t len, size_t * nsug, NSString * lang);
+
+ NSString * requestDictionary (const char * const code);
+ private:
+ NSString * dictionaryForCode (NSString * code);
+
+ NSSpellChecker * m_checker;
+ NSMutableDictionary * m_languages;
+};
+
+typedef struct
+{
+ AppleSpellChecker * AppleSpell;
+ NSString * DictionaryName;
+} AppleSpellDictionary;
diff --git a/src/applespell/applespell_checker.mm b/src/applespell/applespell_checker.mm
new file mode 100644
index 0000000..e68e436
--- /dev/null
+++ b/src/applespell/applespell_checker.mm
@@ -0,0 +1,449 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* enchant
+ * Copyright (C) 2004 Remi Payette
+ * Copyright (C) 2004 Francis James Franklin
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include <glib.h>
+#include <gmodule.h>
+
+#include "applespell_checker.h"
+
+AppleSpellChecker::AppleSpellChecker()
+{
+ // NSLog (@"AppleSpellChecker::AppleSpellChecker");
+
+ m_checker = [NSSpellChecker sharedSpellChecker];
+
+ m_languages = [[NSMutableDictionary alloc] initWithCapacity:16];
+}
+
+AppleSpellChecker::~AppleSpellChecker()
+{
+ // NSLog (@"AppleSpellChecker::~AppleSpellChecker");
+
+ if (m_languages)
+ {
+ [m_languages release];
+ m_languages = 0;
+ }
+}
+
+void AppleSpellChecker::parseConfigFile (const char * configFile)
+{
+ if (!m_languages || !configFile)
+ return;
+
+ // NSLog (@"AppleSpellChecker::parseConfigFile: file=\"%s\"", configFile);
+
+ if (FILE * in = fopen (configFile, "r"))
+ {
+ char line[1024];
+ char code[1024];
+ char name[1024];
+ char lang[1024];
+
+ while (fgets (line, sizeof(line), in))
+ if (sscanf (line, "%s %s %s", code, name, lang) == 3)
+ {
+ NSString * key = [[NSString alloc] initWithUTF8String:code];
+ NSString * value = [[NSString alloc] initWithUTF8String:name];
+ NSString * language = [[NSString alloc] initWithUTF8String:lang];
+
+ if (key && value)
+ {
+ // NSLog (@"AppleSpellChecker: %@ -> %@ (%@)", key, value, language);
+ [m_languages setObject:value forKey:key];
+ }
+
+ if (key)
+ [key release];
+ if (value)
+ [value release];
+ if (language)
+ [language release];
+ }
+ fclose (in);
+ }
+}
+
+NSString * AppleSpellChecker::dictionaryForCode (NSString * code)
+{
+ if (!m_languages)
+ return 0;
+
+ return [m_languages objectForKey:code];
+}
+
+bool AppleSpellChecker::checkWord (const char * word, size_t len, NSString * lang)
+{
+ // NSLog(@"AppleSpellChecker::checkWord: lang=\"%@\"", lang);
+
+ if (!m_checker || !lang)
+ return false;
+
+ NSString * str = [[NSString alloc] initWithBytes:word length:len encoding:NSUTF8StringEncoding];
+ if (!str)
+ return false;
+
+ // NSLog (@"AppleSpellChecker::checkWord: word=\"%@\"", str);
+
+ [m_checker setLanguage:lang];
+
+ NSRange result = [m_checker checkSpellingOfString:str startingAt:0];
+
+ [str release];
+
+ return (result.length ? true : false);
+}
+
+char ** AppleSpellChecker::suggestWord (const char * const word, size_t len, size_t * nsug, NSString * lang)
+{
+ // NSLog (@"AppleSpellChecker::suggestWord: lang=\"%@\"", lang);
+
+ if (!m_checker || !word || !len || !nsug || !lang)
+ return 0;
+
+ *nsug = 0;
+
+ [m_checker setLanguage:lang];
+
+ NSString * str = [[NSString alloc] initWithBytes:word length:len encoding:NSUTF8StringEncoding];
+ if (!str)
+ return 0;
+
+ // NSLog (@"AppleSpellChecker::suggestWord: word=\"%@\"", str);
+
+ NSArray * result = [m_checker guessesForWord:str];
+
+ [str release];
+
+ char ** sug = 0;
+
+ if (unsigned int count = [result count])
+ {
+ sug = g_new0 (char *, static_cast<size_t>(count) + 1);
+ if (sug)
+ {
+ for (unsigned int i = 0; i < count; i++)
+ {
+ str = [result objectAtIndex:i];
+
+ sug[*nsug] = g_strdup ([str UTF8String]);
+
+ if (sug[*nsug])
+ *nsug = *nsug + 1;
+ }
+ }
+ }
+ return sug;
+}
+
+NSString * AppleSpellChecker::requestDictionary (const char * const code)
+{
+ // NSLog (@"AppleSpellChecker::requestDictionary: code=\"%s\"", code);
+
+ if (!m_checker || !code)
+ return 0;
+
+ NSString * dictionary = dictionaryForCode ([NSString stringWithUTF8String:code]);
+ if (dictionary)
+ {
+ NSString * language = [m_checker language];
+ // NSLog (@"AppleSpellChecker::requestDictionary: ld language=\"%@\", new language=\"%@\"", language, dictionary);
+ if (![m_checker setLanguage:dictionary])
+ {
+ // NSLog (@"AppleSpellChecker::requestDictionary: failed to set new language!");
+ dictionary = 0;
+ }
+ if (language)
+ [m_checker setLanguage:language];
+ }
+ return dictionary;
+}
+
+/*
+ * Enchant
+ */
+
+static char ** appleSpell_dict_suggest (EnchantDict * me, const char * const word, size_t len, size_t * out_n_suggs)
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // NSLog (@"appleSpell_dict_suggest word=\"%s\"", word);
+
+ if (!me || !word || !len || !out_n_suggs)
+ {
+ if (pool) [pool release];
+ return 0;
+ }
+
+ char ** result = 0;
+
+ if (AppleSpellDictionary * ASD = static_cast<AppleSpellDictionary *>(me->user_data))
+ {
+ result = ASD->AppleSpell->suggestWord (word, len, out_n_suggs, ASD->DictionaryName);
+ }
+
+ if (pool) [pool release];
+ return result;
+}
+
+static int appleSpell_dict_check (EnchantDict * me, const char * const word, size_t len)
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // NSLog (@"appleSpell_dict_check");
+
+ if (!me || !word || !len)
+ {
+ if (pool) [pool release];
+ return 0;
+ }
+
+ int result = 0;
+
+ if (AppleSpellDictionary * ASD = static_cast<AppleSpellDictionary *>(me->user_data))
+ {
+ result = ASD->AppleSpell->checkWord (word, len, ASD->DictionaryName);
+ }
+
+ if (pool) [pool release];
+ return result;
+}
+
+static void appleSpell_dict_free_suggestions (EnchantDict * me, char ** str_list)
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // NSLog (@"appleSpell_dict_free_suggestions");
+
+ if (str_list)
+ g_strfreev (str_list);
+
+ if (pool) [pool release];
+}
+
+static EnchantDict * appleSpell_provider_request_dict (EnchantProvider * me, const char * const tag)
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // NSLog (@"appleSpell_provider_request_dict");
+
+ if (!me || !tag)
+ {
+ if (pool) [pool release];
+ return 0;
+ }
+
+ AppleSpellChecker * checker = static_cast<AppleSpellChecker *>(me->user_data);
+ if (!checker)
+ {
+ if (pool) [pool release];
+ return 0;
+ }
+
+ EnchantDict * dict = g_new0 (EnchantDict, 1);
+ if (!dict)
+ {
+ if (pool) [pool release];
+ return 0;
+ }
+
+ dict->check = appleSpell_dict_check;
+ dict->suggest = appleSpell_dict_suggest;
+ dict->free_string_list = appleSpell_dict_free_suggestions;
+
+ AppleSpellDictionary * ASD = g_new0 (AppleSpellDictionary, 1);
+ if (!ASD)
+ {
+ g_free (dict);
+ if (pool) [pool release];
+ return 0;
+ }
+
+ ASD->AppleSpell = checker;
+ ASD->DictionaryName = checker->requestDictionary (tag);
+
+ if (ASD->DictionaryName)
+ {
+ [ASD->DictionaryName retain];
+ // NSLog (@"appleSpell_provider_request_dict: providing dictionary \"%@\"", ASD->DictionaryName);
+ dict->user_data = (void *) ASD;
+ }
+ else
+ {
+ g_free (ASD);
+ g_free (dict);
+ dict = 0;
+ }
+
+ if (pool) [pool release];
+ return dict;
+}
+
+static void appleSpell_provider_dispose_dict (EnchantProvider * me, EnchantDict * dict)
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // NSLog (@"appleSpell_provider_dispose_dict");
+
+ if (dict)
+ {
+ AppleSpellDictionary * ASD = static_cast<AppleSpellDictionary *>(dict->user_data);
+ if (ASD)
+ {
+ [ASD->DictionaryName release];
+ g_free (ASD);
+ }
+ g_free (dict);
+ }
+ if (pool) [pool release];
+}
+
+static int appleSpell_provider_dictionary_exists (EnchantProvider * me, const char * const tag)
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // NSLog (@"appleSpell_provider_dictionary_exists: tag=\"%s\"", tag);
+
+ int result = 0;
+
+ AppleSpellChecker * checker = static_cast<AppleSpellChecker *>(me->user_data);
+ if (checker)
+ result = (checker->requestDictionary (tag) ? 1 : 0);
+
+ if (pool) [pool release];
+ return result;
+}
+
+static void appleSpell_provider_dispose (EnchantProvider * me)
+{
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // NSLog (@"appleSpell_provider_dispose");
+
+ if (me)
+ {
+ AppleSpellChecker * checker = static_cast<AppleSpellChecker *>(me->user_data);
+ if (checker)
+ delete checker;
+
+ g_free (me);
+ }
+ if (pool) [pool release];
+}
+
+static char * appleSpell_provider_identify (EnchantProvider * me)
+{
+ return "AppleSpell";
+}
+
+static char * appleSpell_provider_describe (EnchantProvider * me)
+{
+ return "AppleSpell Provider";
+}
+
+extern "C" {
+ ENCHANT_MODULE_EXPORT (EnchantProvider *)
+ init_enchant_provider (void)
+ {
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // NSLog (@"init_enchant_provider");
+
+ EnchantProvider * provider = g_new0 (EnchantProvider, 1);
+ if (!provider)
+ {
+ if (pool) [pool release];
+ return 0;
+ }
+
+ provider->dispose = appleSpell_provider_dispose;
+ provider->request_dict = appleSpell_provider_request_dict;
+ provider->dispose_dict = appleSpell_provider_dispose_dict;
+ provider->dictionary_exists = appleSpell_provider_dictionary_exists;
+ provider->identify = appleSpell_provider_identify;
+ provider->describe = appleSpell_provider_describe;
+
+ AppleSpellChecker * checker = 0;
+ try
+ {
+ checker = new AppleSpellChecker;
+ }
+ catch (...)
+ {
+ checker = 0;
+ }
+ if (checker)
+ {
+ provider->user_data = (void *) checker;
+ }
+ else
+ {
+ g_free (provider);
+ provider = 0;
+ }
+
+ if (pool) [pool release];
+ return provider;
+ }
+
+ static bool s_bReloadSelf = true;
+
+ void configure_enchant_provider (EnchantProvider * me, const char * module_dir)
+ {
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // NSLog (@"configure_enchant_provider");
+
+ if (!me || !module_dir)
+ {
+ if (pool) [pool release];
+ return;
+ }
+
+ AppleSpellChecker * checker = static_cast<AppleSpellChecker *>(me->user_data);
+ if (checker)
+ {
+ if (s_bReloadSelf)
+ if (gchar * moduleFile = g_build_filename (module_dir, "AppleSpell.so", NULL))
+ {
+ /* ugly hack :-(
+ * Darwin linker doesn't like unloading Obj-C modules;
+ * reload once to suppress unloading...
+ */
+ g_module_open (moduleFile, (GModuleFlags) 0);
+
+ g_free (moduleFile);
+
+ s_bReloadSelf = false;
+ }
+
+ if (gchar * configFile = g_build_filename (module_dir, "AppleSpell.config", NULL))
+ {
+ checker->parseConfigFile (configFile);
+
+ g_free (configFile);
+ }
+ }
+
+ if (pool) [pool release];
+ return;
+ }
+}
diff --git a/src/enchant.c b/src/enchant.c
index 6643242..0901e92 100644
--- a/src/enchant.c
+++ b/src/enchant.c
@@ -43,6 +43,16 @@
#include "enchant.h"
#include "enchant-provider.h"
+#ifdef XP_TARGET_COCOA
+#import "enchant_cocoa.h"
+#endif
+
+#ifdef XP_TARGET_COCOA
+#define ENCHANT_USER_PATH_EXTENSION "Library", "Application Support", "Enchant"
+#else
+#define ENCHANT_USER_PATH_EXTENSION ".enchant"
+#endif
+
ENCHANT_PLUGIN_DECLARE("Enchant")
/********************************************************************************/
@@ -73,6 +83,7 @@ typedef struct str_enchant_session
} EnchantSession;
typedef EnchantProvider *(*EnchantProviderInitFunc) (void);
+typedef void (*EnchantPreConfigureFunc) (EnchantProvider * provider, const char * module_dir);
#ifndef BUFSIZ
#define BUFSIZ 1024
@@ -108,6 +119,9 @@ enchant_unlock_file (FILE * f)
static char *
enchant_get_module_dir (void)
{
+#ifdef XP_TARGET_COCOA
+ return g_strdup ([[EnchantResourceProvider instance] moduleFolder]);
+#endif
char * module_dir = NULL;
module_dir = enchant_get_registry_value ("Config", "Module_Dir");
@@ -124,6 +138,9 @@ enchant_get_module_dir (void)
static char *
enchant_get_conf_dir (void)
{
+#ifdef XP_TARGET_COCOA
+ return g_strdup ([[EnchantResourceProvider instance] configFolder]);
+#endif
char * ordering_dir = NULL;
ordering_dir = enchant_get_registry_value ("Config", "Data_Dir");
@@ -286,7 +303,7 @@ enchant_session_new (EnchantProvider *provider, const char * const lang)
{
filename = g_strdup_printf ("%s.dic", lang);
dic = g_build_filename (home_dir,
- ".enchant",
+ ENCHANT_USER_PATH_EXTENSION,
filename,
NULL);
g_free (filename);
@@ -711,6 +728,7 @@ enchant_load_providers_in_dir (EnchantBroker * broker, const char *dir_name)
EnchantProvider *provider;
EnchantProviderInitFunc init_func;
+ EnchantPreConfigureFunc conf_func;
dir = g_dir_open (dir_name, 0, NULL);
if (!dir)
@@ -720,6 +738,8 @@ enchant_load_providers_in_dir (EnchantBroker * broker, const char *dir_name)
while ((dir_entry = g_dir_read_name (dir)) != NULL)
{
+ provider = 0;
+
entry_len = strlen (dir_entry);
if ((entry_len > g_module_suffix_len) &&
!strcmp(dir_entry+(entry_len-g_module_suffix_len), G_MODULE_SUFFIX))
@@ -753,6 +773,17 @@ enchant_load_providers_in_dir (EnchantBroker * broker, const char *dir_name)
g_free (filename);
}
+ if (provider)
+ {
+ /* optional entry point to allow modules to look for associated files
+ */
+ if (g_module_symbol
+ (module, "configure_enchant_provider", (gpointer *) (&conf_func))
+ && conf_func)
+ {
+ conf_func (provider, dir_name);
+ }
+ }
}
g_dir_close (dir);
@@ -761,7 +792,7 @@ enchant_load_providers_in_dir (EnchantBroker * broker, const char *dir_name)
static void
enchant_load_providers (EnchantBroker * broker)
{
- gchar *user_dir, *home_dir;
+ gchar *user_dir, *home_dir, *system_dir;
/* load USER providers first. since the GSList is ordered,
this intentionally gives preference to USER providers */
@@ -770,13 +801,18 @@ enchant_load_providers (EnchantBroker * broker)
if (home_dir)
{
- user_dir = g_build_filename (home_dir, ".enchant", NULL);
+ user_dir = g_build_filename (home_dir, ENCHANT_USER_PATH_EXTENSION, NULL);
enchant_load_providers_in_dir (broker, user_dir);
g_free (user_dir);
g_free (home_dir);
}
-
- enchant_load_providers_in_dir (broker, ENCHANT_GLOBAL_MODULE_DIR);
+
+ system_dir = enchant_get_module_dir ();
+ if (system_dir)
+ {
+ enchant_load_providers_in_dir (broker, system_dir);
+ g_free (system_dir);
+ }
}
static void
@@ -832,7 +868,7 @@ enchant_load_provider_ordering (EnchantBroker * broker)
if (home_dir)
{
- ordering_file = g_build_filename (home_dir, ".enchant", "enchant.ordering", NULL);
+ ordering_file = g_build_filename (home_dir, ENCHANT_USER_PATH_EXTENSION, "enchant.ordering", NULL);
enchant_load_ordering_from_file (broker, ordering_file);
g_free (ordering_file);
g_free (home_dir);
diff --git a/src/enchant_cocoa.h b/src/enchant_cocoa.h
new file mode 100644
index 0000000..52f2d62
--- /dev/null
+++ b/src/enchant_cocoa.h
@@ -0,0 +1,50 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* enchant
+ * Copyright (C) 2004 Francis James Franklin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * In addition, as a special exception, Dom Lachowicz
+ * gives permission to link the code of this program with
+ * non-LGPL Spelling Provider libraries (eg: a MSFT Office
+ * spell checker backend) and distribute linked combinations including
+ * the two. You must obey the GNU Lesser General Public License in all
+ * respects for all of the code used other than said providers. If you modify
+ * this file, you may extend this exception to your version of the
+ * file, but you are not obligated to do so. If you do not wish to
+ * do so, delete this exception statement from your version.
+ */
+
+#ifndef ENCHANT_COCOA_H
+#define ENCHANT_COCOA_H
+
+#import <Cocoa/Cocoa.h>
+
+@interface EnchantResourceProvider : NSObject
+{
+ NSString * ModuleFolder;
+ NSString * ConfigFolder;
+}
++ (EnchantResourceProvider *)instance;
+
+- (id)init;
+- (void)dealloc;
+
+- (const char *)moduleFolder;
+- (const char *)configFolder;
+@end
+
+#endif /* ENCHANT_COCOA_H */
diff --git a/src/enchant_cocoa.m b/src/enchant_cocoa.m
new file mode 100644
index 0000000..bb4bc50
--- /dev/null
+++ b/src/enchant_cocoa.m
@@ -0,0 +1,83 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* enchant
+ * Copyright (C) 2004 Francis James Franklin
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * In addition, as a special exception, Dom Lachowicz
+ * gives permission to link the code of this program with
+ * non-LGPL Spelling Provider libraries (eg: a MSFT Office
+ * spell checker backend) and distribute linked combinations including
+ * the two. You must obey the GNU Lesser General Public License in all
+ * respects for all of the code used other than said providers. If you modify
+ * this file, you may extend this exception to your version of the
+ * file, but you are not obligated to do so. If you do not wish to
+ * do so, delete this exception statement from your version.
+ */
+
+#import "enchant_cocoa.h"
+
+static EnchantResourceProvider * s_instance = 0;
+
+@implementation EnchantResourceProvider
+
++ (EnchantResourceProvider *)instance
+{
+ if (!s_instance)
+ {
+ s_instance = [[EnchantResourceProvider alloc] init];
+ }
+ return s_instance;
+}
+
+- (id)init
+{
+ if (self = [super init])
+ {
+ ModuleFolder = [[NSBundle bundleForClass:[self class]] resourcePath];
+ [ModuleFolder retain];
+
+ ConfigFolder = [[NSString alloc] initWithUTF8String:"/Library/Application Support/Enchant"];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ if (ModuleFolder)
+ {
+ [ModuleFolder release];
+ ModuleFolder = 0;
+ }
+ if (ConfigFolder)
+ {
+ [ConfigFolder release];
+ ConfigFolder = 0;
+ }
+ [super dealloc];
+}
+
+- (const char *)moduleFolder
+{
+ return [ModuleFolder UTF8String];
+}
+
+- (const char *)configFolder
+{
+ return [ConfigFolder UTF8String];
+}
+
+@end
diff --git a/src/ispell/ispell_checker.cpp b/src/ispell/ispell_checker.cpp
index 9121723..501d3db 100644
--- a/src/ispell/ispell_checker.cpp
+++ b/src/ispell/ispell_checker.cpp
@@ -40,6 +40,10 @@
#include "enchant.h"
#include "enchant-provider.h"
+#ifndef ENCHANT_ISPELL_HOME_DIR
+#define ENCHANT_ISPELL_HOME_DIR ".enchant", "ispell"
+#endif
+
ENCHANT_PLUGIN_DECLARE("Ispell")
#define G_ICONV_INVALID (GIConv)-1
@@ -354,12 +358,15 @@ ISpellChecker::suggestWord(const char * const utf8Word, size_t length,
static char *
ispell_checker_get_prefix (void)
{
+ /* until I work out how to link the modules against enchant in MacOSX - fjf
+ */
+#ifndef XP_TARGET_COCOA
char * ispell_prefix = NULL;
ispell_prefix = enchant_get_registry_value ("Ispell", "Data_Dir");
if (ispell_prefix)
return ispell_prefix;
-
+#endif
#ifdef ENCHANT_ISPELL_DICT_DIR
return g_strdup (ENCHANT_ISPELL_DICT_DIR);
#else
@@ -374,11 +381,15 @@ s_buildHashNames (std::vector<std::string> & names, const char * dict)
names.clear ();
+ /* until I work out how to link the modules against enchant in MacOSX - fjf
+ */
+#ifndef XP_TARGET_COCOA
home_dir = enchant_get_user_home_dir ();
-
+#else
+ home_dir = getenv ("HOME");
+#endif
if (home_dir) {
- private_dir = g_build_filename (home_dir, ".enchant",
- "ispell", NULL);
+ private_dir = g_build_filename (home_dir, ENCHANT_ISPELL_HOME_DIR, NULL);
tmp = g_build_filename (private_dir, dict, NULL);
names.push_back (tmp);