Example #1
0
SpellCheck::SpellCheck(QObject *parent) :
    QObject(parent),
    config(NULL),
    spell_checker(NULL)
{
    config = new_aspell_config();

    aspell_config_replace(config, "encoding", "utf-8");
    aspell_config_replace(config, "personal", (dcpp::Util::getPath(dcpp::Util::PATH_USER_CONFIG)+"dict").c_str());

#if defined(Q_WS_WIN)
    aspell_config_replace(config, "data-dir", "./aspell/data");
    aspell_config_replace(config, "dict-dir", "./aspell/dict");
#endif

    if (config) {
        AspellCanHaveError *error = new_aspell_speller(config);

        if (aspell_error(error)) {
            delete_aspell_config(config);

            printf("%s\n", aspell_error_message(error));

            config = NULL;
        }
        else
            spell_checker = to_aspell_speller(error);
    }
}
void AspellAdapterImpl::passOptionsToAspellConfig(
                const boost::program_options::variables_map& options) {

    if (options.count("limit")) {
        limitCandidates_ = options["limit"].as<unsigned int>();
    } else {
        limitCandidates_ = 0;
    }

    std::list<std::string> stringOptions =
        boost::assign::list_of
        (std::string("size"))
        (std::string("personal"))
        (std::string("repl"))
        (std::string("keyboard"))
        (std::string("sug-mode"))
        ;

    BOOST_FOREACH (std::string & optionName, stringOptions) {
        if (options.count(optionName.c_str())) {
            std::string optionValue = options[optionName.c_str()].as<std::string>();
            aspell_config_replace(aspellConfig_, optionName.c_str(), optionValue.c_str());
        }
    }

    if (options.count("ignore-case")) {
        aspell_config_replace(aspellConfig_, "ignore-case", "true");
    }

    if (options.count("ignore")) {
        int ignoreLength = options["ignore"].as<int>();
        std::string ignoreLengthString = boost::lexical_cast<std::string>( ignoreLength);
        aspell_config_replace(aspellConfig_, "ignore", ignoreLengthString.c_str());
    }
}
struct spelling *
spelling_init(char *lang)
{
	AspellConfig *config;
	AspellCanHaveError *ret;
	struct spelling *spelling = malloc(sizeof(struct spelling));

	if (spelling == NULL) {
		warn("malloc(spelling)");
		return NULL;
	}

	config = new_aspell_config();

	aspell_config_replace(config, "lang", spelling_lookup_lang(lang));
	aspell_config_replace(config, "dict-dir", bfile("data/dict/"));
	aspell_config_replace(config, "encoding", "iso-8859-1");

	ret = new_aspell_speller(config);
	delete_aspell_config(config);
	spelling->speller = to_aspell_speller(ret);

	if (aspell_error(ret) != 0) {
		printf("Error: %s\n", aspell_speller_error_message(spelling->speller));
		delete_aspell_can_have_error(ret);
		return NULL;
	}

	spelling->conv = iconv_open("iso-8859-1", "utf-8");
	spelling->conv_out = iconv_open("utf-8", "iso-8859-1");

	return spelling;
}
Example #4
0
SpellChecker::SpellChecker(QTextEdit *textEdit): m_textEdit(textEdit)
{
    m_regExp = new QRegExp("[^\\s]*");
    //m_cursor= new QTextCursor(m_textEdit->document());
    spell_config1 = new_aspell_config();
    spell_config2 = new_aspell_config();
    aspell_config_replace(spell_config1, "lang", m_lang1.toAscii());
    aspell_config_replace(spell_config2, "lang", m_lang2.toAscii());
    aspell_config_replace(spell_config1, "encoding", "utf-8");
    aspell_config_replace(spell_config2, "encoding", "utf-8");
    m_map = new StringMap();
    m_map->insert("ara", "ar");
    m_map->insert("ruseng", "ru");
    m_map->insert("rus", "ru");
    m_map->insert("bul", "bg");
    m_map->insert("cze", "cs");
    m_map->insert("dan", "da");
    m_map->insert("dut", "nl");
    m_map->insert("nld", "nl");
    m_map->insert("ell", "el");
    m_map->insert("eng", "en");
    m_map->insert("est", "et");
    m_map->insert("fin", "fi");
    m_map->insert("fra", "fr");
    m_map->insert("ger", "de");
    m_map->insert("deu", "de");
    m_map->insert("deu-frak", "de-alt");
    m_map->insert("heb", "he");
    m_map->insert("hin", "hi");
    m_map->insert("hrv", "hr");
    m_map->insert("hun", "hu");
    m_map->insert("ind", "in");
    m_map->insert("isl", "is");
    m_map->insert("ita", "it");
    m_map->insert("lav", "lv");
    m_map->insert("lit", "lt");
    m_map->insert("mkd", "mk");
    m_map->insert("msa", "ms");
    m_map->insert("nor", "no");
    m_map->insert("pol", "pl");
    m_map->insert("por", "pt_PT");
    m_map->insert("rum", "ro");
    //m_map->insert("rus", "ru");
    m_map->insert("ron", "ro");
    m_map->insert("slo", "sl");
    m_map->insert("slk", "sk");
    m_map->insert("spa", "es");
    m_map->insert("srp", "sr");
    m_map->insert("swa", "sw");
    m_map->insert("swe", "sv");
    m_map->insert("swef", "sv");
    m_map->insert("tur", "tr");
    m_map->insert("ukr", "uk");
    m_map->insert("vie", "vi");
    spell_checker1 = 0;
    spell_checker2 = 0;
    setLanguage("ruseng");
    dictList = new QStringList();
}
AspellSpeller *
weechat_aspell_speller_new (const char *lang)
{
    AspellConfig *config;
    AspellCanHaveError *ret;
    AspellSpeller *new_speller;
    struct t_infolist *infolist;

    if (!lang)
        return NULL;

    if (weechat_aspell_plugin->debug)
    {
        weechat_printf (NULL,
                        "%s: creating new speller for lang \"%s\"",
                        ASPELL_PLUGIN_NAME, lang);
    }

    /* create a speller instance for the newly created cell */
    config = new_aspell_config();
    aspell_config_replace (config, "lang", lang);

    /* apply all options on speller */
    infolist = weechat_infolist_get ("option", NULL, "aspell.option.*");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            aspell_config_replace (config,
                                   weechat_infolist_string (infolist, "option_name"),
                                   weechat_infolist_string (infolist, "value"));
        }
        weechat_infolist_free (infolist);
    }

    ret = new_aspell_speller (config);

    if (aspell_error (ret) != 0)
    {
        weechat_printf (NULL,
                        "%s%s: error: %s",
                        weechat_prefix ("error"), ASPELL_PLUGIN_NAME,
                        aspell_error_message (ret));
        delete_aspell_config (config);
        delete_aspell_can_have_error (ret);
        return NULL;
    }

    new_speller = to_aspell_speller (ret);
    weechat_hashtable_set (weechat_aspell_spellers, lang, new_speller);

    /* free configuration */
    delete_aspell_config (config);

    return new_speller;
}
Example #6
0
ASpellChecker::ASpellChecker()
    : config_(new_aspell_config())
{
    aspell_config_replace(config_, "encoding", "utf-8");
#ifdef Q_OS_WIN
    aspell_config_replace(config_, "conf-dir", QDir::homePath().toLocal8Bit().data());
    aspell_config_replace(config_, "data-dir", QString("%1/aspell").arg(QCoreApplication::applicationDirPath()).toLocal8Bit().data());
    aspell_config_replace(config_, "dict-dir", QString("%1/aspell").arg(QCoreApplication::applicationDirPath()).toLocal8Bit().data());
#endif
    setActiveLanguages(getAllLanguages());
}
Example #7
0
bool SpellChecker::addCheckedLang(QString &name)
{
	if (checkers.find(name) != checkers.end())
		return true;

	aspell_config_replace(spellConfig, "lang", name.toAscii());

	// create spell checker using prepared configuration
	AspellCanHaveError* possibleErr = new_aspell_speller(spellConfig);
	if (aspell_error_number(possibleErr) != 0)
	{
		MessageBox::msg(aspell_error_message(possibleErr));
		return false;
	}
	else
		checkers[name] = to_aspell_speller(possibleErr);

	if (checkers.size() == 1)
	{
		foreach(ChatWidget *chat, ChatWidgetManager::instance()->chats())
			chatCreated(chat);
	}

	return true;
}
bool KAspellChecker::init()
{
    QString locale = QString(QLocale::system().name()).left(2);

    if (locale.length() < 2)
        locale = "en";

    AspellConfig * config = new_aspell_config();
    aspell_config_replace(config, "lang", locale.toLocal8Bit().data());

    AspellCanHaveError * ret = new_aspell_speller(config);
    delete_aspell_config(config);

    if (aspell_error(ret) != 0) {
        qDebug("Error: %s\n",aspell_error_message(ret));
        delete_aspell_can_have_error(ret);

        return false;
    }

    m_speller = to_aspell_speller(ret);
    config = aspell_speller_config(m_speller);

    qDebug() << "USING LANG= " << aspell_config_retrieve(config, "lang");
	
    return true;
}
Example #9
0
SpellCheck::SpellCheck(QObject *parent) :
    QObject(parent),
    config(NULL),
    spell_checker(NULL)
{
    config = new_aspell_config();

    aspell_config_replace(config, "encoding", "utf-8");
    aspell_config_replace(config, "personal", (QDir::homePath()+QDir::separator()+".eiskaltdc++"+QDir::separator()+"dict").toAscii().constData());

    if (config){
        /*const AspellDictInfoList *dicts = get_aspell_dict_info_list(config);
        AspellDictInfoEnumeration *enumer = aspell_dict_info_list_elements(dicts);
        const AspellDictInfo *info = NULL;

        QStringList all;

        while ((info = aspell_dict_info_enumeration_next(enumer)) != NULL)
            all.append(QString::fromUtf8(info->code, strlen(info->code)));

        if (WSGET(WS_APP_ASPELL_LANG).isEmpty()){
            QString lc_prefix = QLocale::system().name();

            if (all.contains(lc_prefix))//Loading dictionary from system locale
                aspell_config_replace(config, "lang", lc_prefix.toAscii().constData());
            else if (all.contains(lc_prefix.left(lc_prefix.indexOf("_")))) {
                aspell_config_replace(config, "lang", lc_prefix.left(lc_prefix.indexOf("_")).toAscii().constData());
            }
        }
        else
            aspell_config_replace(config, "lang", WSGET(WS_APP_ASPELL_LANG).toAscii().constData());*/
        AspellCanHaveError *error = new_aspell_speller(config);

        if (aspell_error(error) != 0){
            delete_aspell_config(config);

            printf("%s\n", aspell_error_message(error));

            config = NULL;
        }
        else
            spell_checker = to_aspell_speller(error);
    }
}
Example #10
0
ASpellChecker::ASpellChecker()
{
	config_ = NULL;
	speller_ = NULL;
	config_ = new_aspell_config();
	aspell_config_replace(config_, "encoding", "utf-8");
#ifdef Q_WS_WIN
	aspell_config_replace(config_, "conf-dir", QDir::homeDirPath());
	aspell_config_replace(config_, "data-dir", QString("%1/aspell/data").arg(QCoreApplication::applicationDirPath()));
	aspell_config_replace(config_, "dict-dir", QString("%1/aspell/dict").arg(QCoreApplication::applicationDirPath()));
#endif
	AspellCanHaveError* ret = new_aspell_speller(config_);
	if (aspell_error_number(ret) == 0) {
		speller_ = to_aspell_speller(ret);
	}
	else {
		qWarning(QString("Aspell error: %1").arg(aspell_error_message(ret)).toAscii());
	}
}
Example #11
0
/**
 * Set a specific option, that is known by aspell.
 * @param config the config object of a specific spellchecker.
 * @param key the option to set (eg: lang).
 * @param value the value of the option to set (eg: "us_US").
 * @exception Exception if key not known, or value undefined.
 */
static void set_option(AspellConfig *config, char *key, char *value) {
    //printf("set option: %s = %s\n", key, value);
    if (aspell_config_replace(config, key, value) == 0) {
        rb_raise(cAspellError, "%s", aspell_config_error_message(config));
    }
    //check config:
    if (aspell_config_error(config) != 0) {
        rb_raise(cAspellError, "%s", aspell_config_error_message(config));
    }
}
Example #12
0
SpellChecker::SpellChecker()
{
	connect(ChatWidgetManager::instance(), SIGNAL(chatWidgetCreated(ChatWidget *)), this, SLOT(chatCreated(ChatWidget *)));

	// prepare configuration of spellchecker
	spellConfig = new_aspell_config();
	aspell_config_replace(spellConfig, "encoding", "utf-8");

	createDefaultConfiguration();
	// load mark settings
	buildMarkTag();
}
Example #13
0
SpellChecker::SpellChecker( QObject * parent ) 
	: QObject(parent)
{
	m_spell_config_ru = new_aspell_config();
	aspell_config_replace(m_spell_config_ru, "dict-dir", "./dict");
	aspell_config_replace(m_spell_config_ru, "encoding", "utf-8");
	aspell_config_replace(m_spell_config_ru, "lang", "ru");
	AspellCanHaveError * possible_err = new_aspell_speller(m_spell_config_ru);
	m_spell_checker_ru = 0;
	if (aspell_error_number(possible_err) != 0){
		puts(aspell_error_message(possible_err));
	}
	else{
		m_spell_checker_ru = to_aspell_speller(possible_err); 
	}


	m_spell_config_en = new_aspell_config();
	aspell_config_replace(m_spell_config_en, "dict-dir", "./dict");
	aspell_config_replace(m_spell_config_en, "encoding", "utf-8");
	aspell_config_replace(m_spell_config_en, "lang", "en");
	possible_err = new_aspell_speller(m_spell_config_en);
	m_spell_checker_en = 0;
	if (aspell_error_number(possible_err) != 0){
		puts(aspell_error_message(possible_err));
	}
	else{
		m_spell_checker_en = to_aspell_speller(possible_err); 
	}

	m_codec = QTextCodec::codecForName("UTF-8");
}
Example #14
0
static gboolean
gtkspell_set_language_internal(GtkSpell *spell, const gchar *lang, GError **error) {
	AspellConfig *config;
	AspellCanHaveError *err;

	if (lang == NULL) {
		lang = g_getenv("LANG");
		if (lang) {
			if (g_strncasecmp(lang, "C", 1) == 0)
				lang = NULL;
			else if (lang[0] == 0)
				lang = NULL;
		}
	}

	config = new_aspell_config();
	if (lang)
		aspell_config_replace(config, "language-tag", lang);
	aspell_config_replace(config, "encoding", "utf-8");
	err = new_aspell_speller(config);
	delete_aspell_config(config);

	if (aspell_error_number(err) != 0) {
#ifdef USING_ASPELL
		g_set_error(error, GTKSPELL_ERROR, GTKSPELL_ERROR_BACKEND,
				"aspell: %s", aspell_error_message(err));
#elif defined USING_PSPELL
		g_set_error(error, GTKSPELL_ERROR, GTKSPELL_ERROR_BACKEND,
				"pspell: %s", aspell_error_message(err));
#endif
		return FALSE;
	} 
	if (spell->speller)
		delete_aspell_speller(spell->speller);
	spell->speller = to_aspell_speller(err);

	return TRUE;
}
Example #15
0
//__________________________________________________________________________
void Speller::Aspell::Suggest::setConfigOpt(const std::string& opt,
					    const std::string& val)
	throw( std::invalid_argument )
{
	aspell_config_replace( fconfig, opt.c_str(), val.c_str() );
	try
	{
		checkConfigError();
	}
	catch( const std::invalid_argument& err )
	{
		throw err;
	}
}
Example #16
0
bool SpellChecker::buildCheckers()
{
	foreach(AspellSpeller *speller, checkers.values())
		delete_aspell_speller(speller);

	checkers.clear();

	// load languages to check from configuration
	QString checkedStr = config_file.readEntry("ASpell", "Checked", "pl");
	QStringList checkedList = checkedStr.split(',', QString::SkipEmptyParts);

	if (config_file.readBoolEntry("ASpell", "Accents", false))
		aspell_config_replace(spellConfig, "ignore-accents", "true");
	else
		aspell_config_replace(spellConfig, "ignore-accents", "false");

	if (config_file.readBoolEntry( "ASpell", "Case", false))
		aspell_config_replace(spellConfig, "ignore-case", "true");
	else
		aspell_config_replace(spellConfig, "ignore-case", "false");

	// create aspell checkers for each language
	for (unsigned int i = 0; i < checkedList.count(); i++)
	{
		addCheckedLang(checkedList[i]);
		/*
		if ( !addCheckedLang( checkedList[i] ) )
		{
			delete_aspell_config( spellConfig );
			delete config;
			return false;
		}
		*/
	}
	return true;
}
Example #17
0
void initAspell()
{
	spell_config = new_aspell_config();
	aspell_config_replace(spell_config, "lang", "en_US");	//set language
	possible_err = new_aspell_speller(spell_config);
	spell_checker = 0;

	if (aspell_error_number(possible_err) != 0) {
		printf("%s ", aspell_error_message(possible_err));
	}
	else {
		printf("Unscrambled words:\n");
		spell_checker = to_aspell_speller(possible_err);
	}
}
void ASpellChecker::setActiveLanguages(const QList<QString>& langs)
{
	clearSpellers();

	foreach(const QString& lang, langs)
	{
		AspellConfig* conf = aspell_config_clone(config_);
		aspell_config_replace(conf, "lang", lang.toUtf8().constData());
		AspellCanHaveError* ret = new_aspell_speller(conf);
		if (aspell_error_number(ret) == 0) {
			spellers_.append(to_aspell_speller(ret));
		}
		else {
			qDebug() << QString("Aspell error: %1").arg(aspell_error_message(ret));
		}
		delete_aspell_config(conf);
	}
bool AspellAdapterImpl::isDictionaryAvailable(const std::string & langCode) {
    AspellConfig * tempAspellConfig = new_aspell_config();
    aspell_config_replace(tempAspellConfig, "lang", langCode.c_str());
    AspellCanHaveError * possibleError = new_aspell_speller(tempAspellConfig);

    bool result = true;
    if (aspell_error_number(possibleError) != 0) {
        result = false;
    } else {
        AspellSpeller * tempSpeller = to_aspell_speller(possibleError);
        delete_aspell_speller(tempSpeller);
    }

    delete_aspell_config(tempAspellConfig);
    
    return result;
}
Example #20
0
void ASpellChecker::setActiveLanguages(const QSet<LanguageManager::LangId>& langs)
{
    clearSpellers();

    for(auto const &lang: langs)
    {
        AspellConfig* conf = aspell_config_clone(config_);
        aspell_config_replace(conf, "lang", LanguageManager::toString(lang)
                              .replace(QLatin1Char('-'),QLatin1Char('_')).toUtf8().constData());
        AspellCanHaveError* ret = new_aspell_speller(conf);
        if (aspell_error_number(ret) == 0) {
            spellers_.append(to_aspell_speller(ret));
        }
        else {
            qDebug() << QString("Aspell error: %1").arg(aspell_error_message(ret));
        }
        delete_aspell_config(conf);
    }
}
/**
 * Create a spell checker for a language
 * @param language the language code e.g. en_GB or it
 * @return a checker or NULL
 */
static checker *checker_create( const char *language )
{
    int err = 0;
    checker *c = calloc( 1, sizeof(checker) );
    if ( c != NULL )
    {
        strncpy(c->lang,language,24);
        c->spell_config = new_aspell_config();
        if ( c->spell_config != NULL )
        {
            aspell_config_replace( c->spell_config, "lang", language );
            AspellCanHaveError *possible_err 
                = new_aspell_speller(c->spell_config);
            c->spell_checker = 0;
            if (aspell_error_number(possible_err) != 0)
            {
                fprintf(stderr,"%s\n",aspell_error_message(possible_err));
                err = 1;
            }
            else
            {
                c->spell_checker = to_aspell_speller(possible_err);
                if ( c->spell_checker == NULL )
                {
                    fprintf(stderr,"checker: failed to initialise speller\n");
                    err = 1;
                }
            }
            if ( err )
            {
                checker_dispose( c );
                c = NULL;
            }
        }
        else
            fprintf(stderr,"checker: failed to create speller\n");
    }
    else
        fprintf(stderr,"checker: failed to create object\n");
    return c;
}
Example #22
0
/**
 * create a neew spell-checker for the language 'lang'
 */
void * spellcheck_create(const char * lang)
{
    struct linkgrammar_aspell *aspell = NULL;
    size_t i = 0;
    AspellCanHaveError *spell_err = NULL;

    for (i = 0; i < sizeof(spellcheck_lang_mapping)/sizeof(char *); i += 2)
    {
        if (0 != strcmp(lang, spellcheck_lang_mapping[i])) continue;
        aspell = (struct linkgrammar_aspell *)malloc(sizeof(struct linkgrammar_aspell));
        if (!aspell) {
            prt_error("Error: out of memory. Aspell not used.\n");
            aspell = NULL;
            break;
        }
        aspell->config = NULL;
        aspell->speller = NULL;
        aspell->config = new_aspell_config();
        if (aspell_config_replace(aspell->config, ASPELL_LANG_KEY,
                                  spellcheck_lang_mapping[i]) == 0) {
            prt_error("Error: failed to set language in aspell: %s\n", lang);
            delete_aspell_config(aspell->config);
            free(aspell);
            aspell = NULL;
            break;
        }
        spell_err = new_aspell_speller(aspell->config);
        if (aspell_error_number(spell_err) != 0) {
            prt_error("Error: Aspell: %s\n", aspell_error_message(spell_err));
            delete_aspell_can_have_error(spell_err);
            delete_aspell_config(aspell->config);
            free(aspell);
            aspell = NULL;
            break;
        }
        aspell->speller = to_aspell_speller(spell_err);
        break;
    }
    return aspell;
}
Example #23
0
int SpellerConfig::setKey(const char *key, const char *val)
{
    if (cfg == NULL)
        return -1;
    return aspell_config_replace(cfg, key, val);
}
Example #24
0
static int get_aspell_hits(const char *word, int len)
{
	if (len < 2) 
	{
		log_message(DEBUG, "   [-]Skip aspell checking (word is very short)");
		return NO_LANGUAGE;	
	}

	AspellConfig *spell_config = new_aspell_config();
	
	for (int lang = 0; lang < xconfig->total_languages; lang++)
	{
		char *lang_word = (char *) malloc(1 * sizeof(char));
		if (lang_word == NULL)
			continue;
		lang_word[0] = NULLSYM;

		for (int i = 0; i < len; i++)
		{
			KeyCode kc;
			int modifier;
			main_window->xkeymap->char_to_keycode(main_window->xkeymap, word[i], &kc, &modifier);

			char *symbol = keycode_to_symbol(kc, lang, modifier);
			if ((symbol == NULL) || (lang_word == NULL))
				continue;
			lang_word = (char *) realloc(lang_word, (strlen(lang_word) + strlen(symbol) + 1) * sizeof(char));
			if (lang_word != NULL)
				strcat(lang_word, symbol);

			free(symbol);
		}
		
		if (lang_word == NULL)
			continue;

		aspell_config_replace(spell_config, "lang", xconfig->languages[lang].dir);
		AspellCanHaveError *possible_err = new_aspell_speller(spell_config);
		AspellSpeller *spell_checker = 0;

		if (aspell_error_number(possible_err) == 0)
		{
			spell_checker = to_aspell_speller(possible_err);
			int correct = aspell_speller_check(spell_checker, lang_word, strlen(lang_word));
			if (correct)
			{
				log_message(DEBUG, "   [+]Found this word in %s aspell dictionary", xconfig->get_lang_name(xconfig, lang));
				delete_aspell_speller(spell_checker);
				free(lang_word);
				return lang;
			}
		}
		else
		{
			log_message(DEBUG, "   [!]Error aspell checking for %s aspell dictionary", xconfig->get_lang_name(xconfig, lang));
		}
	
		delete_aspell_speller(spell_checker);
		free(lang_word);
	}
	
	log_message(DEBUG, "   [-]This word has no hits for all aspell dictionaries");
	return NO_LANGUAGE;
}
Example #25
0
/* Create a new speller *******************************************************/
static PyObject* new_speller(PyObject* self, PyObject* args) {
	aspell_AspellObject* newobj;

	AspellSpeller* speller = 0;
	AspellConfig*  config;
	AspellCanHaveError* possible_error;

	int i;
	int n; /* arg count */
	char *key, *value;

	config = new_aspell_config();
	if (config == NULL) {
		PyErr_SetString(_AspellModuleException, "can't create config");
		return NULL;
	}

	/* check constructor arguments */
	n = PyTuple_Size(args);
	switch (n) {
		case 0: /* no arguments passed */
			break;

		case 2: /* constructor is called with single pair: key & value */
			if (PyArg_ParseTuple(args, "ss", &key, &value)) {
				if (!aspell_config_replace(config, key, value)) {
					PyErr_SetString(_AspellConfigException, aspell_config_error_message(config));
					goto arg_error;
				}
				break;
			}
			PyErr_Clear();
		default: /* list of tuples key&value */
			for (i=0; i<n; i++) {
				if (!PyArg_ParseTuple(PyTuple_GetItem(args, i), "ss", &key, &value)) {
					PyErr_Format(PyExc_TypeError, "argument %d: tuple of two strings (key, value) expeced", i);
					goto arg_error;
				}
				if (!aspell_config_replace(config, key, value)) {
					PyErr_SetString(_AspellConfigException, aspell_config_error_message(config));
					goto arg_error;
				}
			}
			Py_DECREF(args);
			break;
	}

	/* try to create a new speller */
	possible_error = new_aspell_speller(config);
	delete_aspell_config(config);

	if (aspell_error_number(possible_error) == 0)
		/* save a speller */
		speller = to_aspell_speller(possible_error);
	else {
		/* or raise an exception */
		PyErr_SetString(_AspellSpellerException, aspell_error_message(possible_error));
		delete_aspell_can_have_error(possible_error);
		return NULL;
	}

	/* create a new py-object */
  newobj = (aspell_AspellObject*)PyObject_New(aspell_AspellObject, &aspell_AspellType);
	newobj->speller = speller;

	return (PyObject*)newobj;

/* argument error: before return NULL we need to
   delete speller's config we've created */
arg_error:
	delete_aspell_config(config);
	return NULL;
}
Example #26
0
AspellSpeller *
#endif /* USE_ENCHANT */
weechat_aspell_speller_new (const char *lang)
{
#ifdef USE_ENCHANT
    EnchantDict *new_speller;
#else
    AspellConfig *config;
    AspellCanHaveError *ret;
    AspellSpeller *new_speller;
#endif /* USE_ENCHANT */
    struct t_infolist *infolist;

    if (!lang)
        return NULL;

    if (weechat_aspell_plugin->debug)
    {
        weechat_printf (NULL,
                        "%s: creating new speller for lang \"%s\"",
                        ASPELL_PLUGIN_NAME, lang);
    }

#ifdef USE_ENCHANT
    new_speller = enchant_broker_request_dict (broker, lang);
    if (!new_speller)
    {
        weechat_printf (NULL,
                        _("%s%s: error: unable to create speller for lang \"%s\""),
                        weechat_prefix ("error"), ASPELL_PLUGIN_NAME,
                        lang);
        return NULL;
    }
#else
    /* create a speller instance for the newly created cell */
    config = new_aspell_config ();
    aspell_config_replace (config, "lang", lang);
#endif /* USE_ENCHANT */

    /* apply all options */
    infolist = weechat_infolist_get ("option", NULL, "aspell.option.*");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
#ifdef USE_ENCHANT
            /* TODO: set option with enchant */
#else
            aspell_config_replace (config,
                                   weechat_infolist_string (infolist, "option_name"),
                                   weechat_infolist_string (infolist, "value"));
#endif /* USE_ENCHANT */
        }
        weechat_infolist_free (infolist);
    }

#ifndef USE_ENCHANT
    ret = new_aspell_speller (config);

    if (aspell_error (ret) != 0)
    {
        weechat_printf (NULL,
                        "%s%s: error: %s",
                        weechat_prefix ("error"), ASPELL_PLUGIN_NAME,
                        aspell_error_message (ret));
        delete_aspell_config (config);
        delete_aspell_can_have_error (ret);
        return NULL;
    }

    new_speller = to_aspell_speller (ret);
#endif /* USE_ENCHANT */

    weechat_hashtable_set (weechat_aspell_spellers, lang, new_speller);

#ifndef USE_ENCHANT
    /* free configuration */
    delete_aspell_config (config);
#endif /* USE_ENCHANT */

    return new_speller;
}
Example #27
0
void SpellChecker::setLanguage(const QString &lang)
{
    if (lang.isEmpty()) return;
    delete_aspell_speller(spell_checker1);
    delete_aspell_speller(spell_checker2);
    bad_language.clear();

    m_lang2 = "en";
    m_lang1 = m_map->value(lang, QString("en"));
    if (lang.contains("+")) {
        QStringList sl = lang.split("+");
        m_lang1 = m_map->value(sl[0], QString("en"));
        m_lang2 = m_map->value(sl[1], QString("en"));
        if ((m_lang1 == "deu")||(lang == "ger")) {
            m_lang1 = "de_DE";
        }
        if ((m_lang2 == "deu")||(lang == "ger")) {
            m_lang2 = "de_DE";
        }
    }
    if (lang == "rus_fra") {
        m_lang1 = "ru";
        m_lang2 = "fr";
    } else if (lang == "rus_ger") {
        m_lang1 = "ru";
        m_lang2 = "de";
    } else if (lang == "rus_spa") {
        m_lang1 = "ru";
        m_lang2 = "es";
    }
    if ((lang == "deu")||(lang == "ger")) {
        m_lang1 = "de_DE";
        m_lang2 = "de_AT";

    }
    if (lang == "ruseng") {
        m_lang1 = "ru";
        m_lang2 = "en";

    }
    aspell_config_replace(spell_config1, "lang", m_lang1.toAscii());
    aspell_config_replace(spell_config2, "lang", m_lang2.toAscii());
    AspellCanHaveError *possible_err = new_aspell_speller(spell_config1);
    spell_checker1 = 0;
    if (aspell_error_number(possible_err) == 0)
        spell_checker1 = to_aspell_speller(possible_err);
    else
        delete_aspell_can_have_error(possible_err);
    possible_err = new_aspell_speller(spell_config2);
    spell_checker2 = 0;
    if (aspell_error_number(possible_err) == 0)
        spell_checker2 = to_aspell_speller(possible_err);
    else
        delete_aspell_can_have_error(possible_err);

    // Check absent dictionary
    if (spell_checker1 == 0)
        bad_language = m_lang1;
    if (spell_checker2 == 0)
        bad_language = m_lang2;

}
/**
 * Create a userdata object
 * @param language the language e.g. "en_GB"
 * @param rules recipe file path to recipe file
 * @param fmt the format object containing function pointers
 * @return a complete userdata object or NULL
 */
userdata *userdata_create( const char *language, char *barefile, recipe *rules, 
    format *fmt, hh_exceptions *hhe )
{
    int err = 0;
    userdata *u = calloc( 1, sizeof(userdata) );
    if ( u != NULL )
    {
        u->rules = rules;
        if ( hhe != NULL )
            u->hhe = hhe;
        u->spell_config = new_aspell_config();
        if ( u->spell_config != NULL )
        {
            aspell_config_replace( u->spell_config, "lang", language );
            AspellCanHaveError *possible_err 
                = new_aspell_speller(u->spell_config);
            u->spell_checker = 0;
            if (aspell_error_number(possible_err) != 0)
            {
                fprintf(stderr,"%s\n",aspell_error_message(possible_err));
                err = 1;
            }
            else
            {
                u->spell_checker = to_aspell_speller(possible_err);
                if ( u->spell_checker == NULL )
                {
                    fprintf(stderr,"userdata: failed to initialise speller\n");
                    err = 1;
                }
            }
            u->range_stack = stack_create();
            if ( u->range_stack == NULL )
            {
                err = 1;
                fprintf(stderr, 
                    "stripper: failed to allocate store for range stack" );
            }
            u->ignoring = stack_create();
            if ( u->ignoring == NULL )
            {
                err = 1;
                fprintf(stderr, 
                    "stripper: failed to allocate store for ignore stack" );
            }
            if ( !open_dest_files(u,barefile,fmt) )
            {
                err = 1;
                fprintf(stderr,"stripper: couldn't open dest files\n");
            }
        }
        else
        {
            fprintf(stderr, "userdata: failed to initialise speller\n");
            err = 1;
        }
    }
    else
        fprintf(stderr, "userdata:failed to allocate object\n");
    if ( err )
    {
        userdata_dispose( u );
        u = NULL;
    }
    return u;
}
Example #29
0
StyleDialog::StyleDialog (
    wxWindow *parent,
    wxIcon icon,
    const std::string& bufferParameterUtf8,
    const wxString& fileNameParameter,
    const wxString& ruleSetDirectoryParameter,
    const wxString& filterDirectoryParameter,
    const wxString& ruleSetPresetParameter,
    const wxString& filterPresetParameter,
#if !defined(USE_ENCHANT) && defined(__WXMSW__)
    const wxString& aspellDataPathParameter,
    const wxString& aspellDictPathParameter,
#endif
    int typeParameter,
    bool readOnlyParameter,
    wxPoint position,
    wxSize size )
		: wxDialog (
		    parent,
		    wxID_ANY,
		    wxString ( ( typeParameter == ID_TYPE_STYLE) ? _ ( "Style" ) : _ ( "Spelling" ) ),
		    position,
		    size,
		    wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX ),
		indexForContextMenu ( -1 ),
		bufferUtf8 ( bufferParameterUtf8 ),
#if !defined(USE_ENCHANT) && defined(__WXMSW__)
		aspellDataPath ( aspellDataPathParameter ),
		aspellDictPath ( aspellDictPathParameter ),
#endif
		fileName ( fileNameParameter ),
		ruleSetDirectory ( ruleSetDirectoryParameter ),
		filterDirectory ( filterDirectoryParameter ),
		ruleSetPreset ( ruleSetPresetParameter ),
		filterPreset ( filterPresetParameter ),
		type(typeParameter),
		readOnly ( readOnlyParameter )
{
	SetIcon ( icon );


	// top box
	ruleSetCombo = new wxComboBox (
	    this,
	    ID_STYLE_COMBO_RULESET,
	    _T ( "" ),
	    wxDefaultPosition,
	    wxSize ( 200, -1 )
	);
	
	int width, height;
	ruleSetCombo->GetSize ( &width, &height );
	wxSize buttonSize ( 100, height );

    	filterCombo = new wxComboBox (
		this,
		ID_STYLE_COMBO_FILTER,
		_T ( "" ),
		wxDefaultPosition,
		wxSize ( 200, -1 ) );
	//if (type != ID_TYPE_STYLE) // from v. 1.1.0.7: never show
		filterCombo->Show ( false );

	wxButton *createReportButton = new wxButton (
	    this,
	    ID_STYLE_REPORT,
	    _ ( "&Check" ),
	    wxDefaultPosition,
	    buttonSize,
	    0 );

	wxBoxSizer *comboSizer = new wxBoxSizer ( wxHORIZONTAL );
	comboSizer->Add ( ruleSetCombo, 0, wxRIGHT, 10 );
	comboSizer->Add ( filterCombo, 0, wxRIGHT, 10 );
	comboSizer->Add ( createReportButton, 0, wxRIGHT, 10 );

	// middle box
	wxListCtrl *myTable = new wxListCtrl (
	    this,
	    ID_STYLE_TABLE,
	    wxPoint ( 0, 0 ),
	    wxSize ( -1, -1 ),
	    wxLC_REPORT );
	int widthUnit = 35;
	myTable->InsertColumn ( 0, _ ( "No." ), wxLIST_FORMAT_LEFT, widthUnit * 1 );
	myTable->InsertColumn ( 1, _ ( "Context" ), wxLIST_FORMAT_RIGHT, widthUnit * 3 );
	myTable->InsertColumn ( 2, _ ( "Error" ), wxLIST_FORMAT_CENTER, widthUnit * 3 );
	myTable->InsertColumn ( 3, _ ( "Context" ), wxLIST_FORMAT_LEFT, widthUnit * 3 );
	myTable->InsertColumn ( 4, _ ( "Suggestion" ), wxLIST_FORMAT_LEFT, widthUnit * 3 );
	
	myTable->InsertColumn ( 5, _ ( "Rule" ), wxLIST_FORMAT_LEFT, widthUnit * 3 );
	myTable->InsertColumn ( 6, _ ( "Action" ), wxLIST_FORMAT_LEFT, widthUnit * 3 );
	table = myTable;

	// lower box
	wxButton *editItemsButton =
	    new wxButton (
	    this,
	    ID_STYLE_EDIT,
	    _ ( "&Apply changes" ),
	    wxDefaultPosition,
	    wxSize ( -1, buttonSize.GetHeight() ),
	    0 );
	wxButton *webReportButton =
	    new wxButton (
	    this,
	    ID_STYLE_WEB_REPORT,
	    _ ( "&Printable report" ),
	    wxDefaultPosition,
	    wxSize ( -1, buttonSize.GetHeight() ),
	    0 );
	wxButton *webSummaryButton =
	    new wxButton (
	    this,
	    ID_STYLE_WEB_SUMMARY,
	    _ ( "Pr&intable summary" ),
	    wxDefaultPosition,
	    wxSize ( -1, buttonSize.GetHeight() ),
	    0 );
	wxButton *selectAllButton =
	    new wxButton (
	    this,
	    ID_STYLE_CHANGE_ALL,
	    _ ( "C&hange all" ),
	    wxDefaultPosition,
	    wxSize ( -1, buttonSize.GetHeight() ),
	    0 );
	wxButton *deselectAllButton =
	    new wxButton (
	    this,
	    ID_STYLE_IGNORE_ALL,
	    _ ( "I&gnore all" ),
	    wxDefaultPosition,
	    wxSize ( -1, buttonSize.GetHeight() ),
	    0 );
	wxButton *cancelButton =
	    new wxButton (
	    this,
	    wxID_CANCEL,
	    _ ( "Ca&ncel" ),
	    wxDefaultPosition,
	    wxSize ( -1, buttonSize.GetHeight() ),
	    0 );

	wxBoxSizer *reportButtonSizer = new wxBoxSizer ( wxHORIZONTAL );
	reportButtonSizer->Add ( editItemsButton, 0, wxRIGHT, 10 );
	reportButtonSizer->Add ( webReportButton, 0, wxLEFT | wxRIGHT, 10 );
	reportButtonSizer->Add ( webSummaryButton, 0, wxRIGHT, 10 );
	reportButtonSizer->Add ( selectAllButton, 0, wxLEFT | wxRIGHT, 10 );
	reportButtonSizer->Add ( deselectAllButton, 0, wxRIGHT, 10 );
	reportButtonSizer->Add ( cancelButton, 0, wxLEFT, 10 );

	// status bar
	status = new wxStatusBar ( this, wxID_ANY );

	// overall sizer
	wxBoxSizer *reportTopSizer = new wxBoxSizer ( wxVERTICAL );
	reportTopSizer->Add ( comboSizer, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5 );
	reportTopSizer->Add ( table, 1, wxEXPAND | wxALL, 5 );
	reportTopSizer->Add ( reportButtonSizer, 0, wxALL, 5 );
	reportTopSizer->Add ( status, 0, wxEXPAND | wxALL );
	this->SetSizer ( reportTopSizer );

	createReportButton->SetFocus();

	if ( readOnly )
		filterCombo->Enable ( false );

	// keyboard shortcuts
	wxAcceleratorEntry entries[7];
	entries[0].Set ( wxACCEL_ALT, ( int ) 'C', ID_STYLE_REPORT );
	entries[1].Set ( wxACCEL_ALT, ( int ) 'A', ID_STYLE_EDIT );
	entries[2].Set ( wxACCEL_ALT, ( int ) 'W', ID_STYLE_WEB_REPORT );
	entries[3].Set ( wxACCEL_ALT, ( int ) 'B', ID_STYLE_WEB_SUMMARY );
	entries[4].Set ( wxACCEL_ALT, ( int ) 'H', ID_STYLE_CHANGE_ALL );
	entries[5].Set ( wxACCEL_ALT, ( int ) 'I', ID_STYLE_IGNORE_ALL );
	entries[6].Set ( wxACCEL_ALT, ( int ) 'N', wxID_CANCEL );

	wxAcceleratorTable accel ( 7, entries );
	this->SetAcceleratorTable ( accel );
	
	// update combo lists

	// special case spellcheck
	if (type == ID_TYPE_SPELL)
	{
#ifdef USE_ENCHANT
		EnchantBroker *broker = enchant_broker_init();
		dictdetect adetected(ruleSetCombo);
		enchant_broker_list_dicts(broker, EnchantDictDescribe, &adetected);
		bool anyFound = !adetected.empty();
#else
		AspellConfig *config;
		AspellDictInfoList *dlist;
		AspellDictInfoEnumeration *dels;
		const AspellDictInfo *entry;
		
		config = new_aspell_config();
		
#ifdef __WXMSW__
		aspell_config_replace ( config, "data-dir", aspellDataPath.mb_str() ); //ASPELL_DATA_PATH );
		aspell_config_replace ( config, "dict-dir", aspellDictPath.mb_str() ); //ASPELL_DICT_PATH );
#endif
		dlist = get_aspell_dict_info_list( config );
		
		delete_aspell_config ( config );
		
		dels = aspell_dict_info_list_elements ( dlist );
		
		bool anyFound = false;
		while ( ( entry = aspell_dict_info_enumeration_next ( dels ) ) != 0 )
		{
			anyFound = true;
			std::string stdEntry = entry->name;
			wxString entry = wxString ( stdEntry.c_str(), wxConvUTF8, stdEntry.size() );
			ruleSetCombo->Append ( entry );
		}
#endif
		
		if ( anyFound )
		{
			if ( ruleSetPreset.empty() )
				ruleSetPreset = _ ( "en_US" );
			ruleSetCombo->SetValue ( ruleSetPreset );
		}
		else
		{
			ruleSetCombo->Append ( _ ( "(No dictionaries found)" ) );
			ruleSetCombo->Select ( 0 );
			createReportButton->Enable ( false );
		}
		
		return;
	}

	// all other branches
	if ( wxDirExists ( ruleSetDirectory ) )
	{
		wxString ruleMask, ruleFile;
		ruleMask = ruleSetDirectory + wxFileName::GetPathSeparator() + _T ( "*.xml" );
		ruleFile = wxFindFirstFile ( ruleMask, wxFILE );

		if ( !ruleFile.empty() )
		{
			ruleFile.Replace ( _T ( ".xml" ), _T ( "" ) );
			ruleFile.Replace ( _T ( "_" ), _T ( " " ) );
			ruleSetCombo->Append ( wxFileNameFromPath ( ruleFile ) );
			for ( ;; )
			{
				ruleFile = wxFindNextFile();
				if ( ruleFile.empty() )
					break;
				ruleFile.Replace ( _T ( ".xml" ), _T ( "" ) );
				ruleFile.Replace ( _T ( "_" ), _T ( " " ) );
				ruleSetCombo->Append ( wxFileNameFromPath ( ruleFile ) );
			}
		}
		if ( ruleSetPreset.empty() )
			ruleSetPreset = _ ( "Default" );
		ruleSetCombo->SetValue ( ruleSetPreset );
	}
	else
	{
		ruleSetCombo->Append ( _ ( "(No rule sets found)" ) );
		ruleSetCombo->Select ( 0 );
	}

	if ( wxDirExists ( filterDirectory ) )
	{
		filterCombo->Append ( _ ( "(No filter)" ) );
		wxString filterMask, filterFile;
		filterMask = filterDirectory + wxFileName::GetPathSeparator() + _T ( "*.xml" );

		filterFile = wxFindFirstFile ( filterMask, wxFILE );

		if ( !filterFile.empty() )
		{
			filterFile.Replace ( _T ( ".xml" ), _T ( "" ) );
			filterCombo->Append ( wxFileNameFromPath ( filterFile ) );
			for ( ;; )
			{
				filterFile = wxFindNextFile();
				if ( filterFile.empty() )
					break;
				filterFile.Replace ( _T ( ".xml" ), _T ( "" ) );
				filterCombo->Append ( wxFileNameFromPath ( filterFile ) );
			}
		}
		filterCombo->SetValue ( filterPreset );
	}
	else
	{
		filterCombo->Append ( _ ( "(No filters found)" ) );
		filterCombo->Select ( 0 );
	}
}
void AspellAdapterImpl::initAspell(const std::string & langCode) {
    langCode_ = langCode;
    aspell_config_replace(aspellConfig_, "lang", langCode.c_str());
    aspell_config_replace(aspellConfig_, "encoding", "utf-8");
}