Ejemplo n.º 1
0
void
weechat_aspell_create_spellers (struct t_gui_buffer *buffer)
{
    const char *dict_list;
    char **argv;
    int argc, i;

    if (buffer)
    {
        dict_list = weechat_aspell_get_dict (buffer);
        if (!weechat_aspell_spellers_already_ok (dict_list))
        {
            weechat_aspell_speller_free_all ();
            if (dict_list)
            {
                argv = weechat_string_split (dict_list, ",", 0, 0, &argc);
                if (argv)
                {
                    for (i = 0; i < argc; i++)
                    {
                        weechat_aspell_speller_new (argv[i]);
                    }
                    weechat_string_free_split (argv);
                }
            }
        }
    }
}
Ejemplo n.º 2
0
struct t_aspell_speller_buffer *
weechat_aspell_speller_buffer_new (struct t_gui_buffer *buffer)
{
    const char *buffer_dicts;
    char **dicts;
    int num_dicts, i;
    struct t_aspell_speller_buffer *new_speller_buffer;
    AspellSpeller *ptr_speller;

    if (!buffer)
        return NULL;

    weechat_hashtable_remove (weechat_aspell_speller_buffer, buffer);

    new_speller_buffer = malloc (sizeof (*new_speller_buffer));
    if (!new_speller_buffer)
        return NULL;

    new_speller_buffer->spellers = NULL;
    new_speller_buffer->modifier_string = NULL;
    new_speller_buffer->input_pos = -1;
    new_speller_buffer->modifier_result = NULL;

    buffer_dicts = weechat_aspell_get_dict (buffer);
    if (buffer_dicts)
    {
        dicts = weechat_string_split (buffer_dicts, ",", 0, 0, &num_dicts);
        if (dicts && (num_dicts > 0))
        {
            new_speller_buffer->spellers =
                malloc ((num_dicts + 1) * sizeof (AspellSpeller *));
            if (new_speller_buffer->spellers)
            {
                for (i = 0; i < num_dicts; i++)
                {
                    ptr_speller = weechat_hashtable_get (weechat_aspell_spellers,
                                                         dicts[i]);
                    if (!ptr_speller)
                        ptr_speller = weechat_aspell_speller_new (dicts[i]);
                    new_speller_buffer->spellers[i] = ptr_speller;
                }
                new_speller_buffer->spellers[num_dicts] = NULL;
            }
        }
        if (dicts)
            weechat_string_free_split (dicts);
    }

    weechat_hashtable_set (weechat_aspell_speller_buffer,
                           buffer,
                           new_speller_buffer);

    weechat_bar_item_update ("aspell_dict");

    return new_speller_buffer;
}
Ejemplo n.º 3
0
void
weechat_aspell_add_word (const char *lang, const char *word)
{
    struct t_aspell_speller *new_speller, *ptr_speller;

    new_speller = NULL;
    ptr_speller = weechat_aspell_speller_search (lang);
    if (!ptr_speller)
    {
        if (!weechat_aspell_speller_exists (lang))
        {
            weechat_printf (NULL,
                            _("%s: error: dictionary \"%s\" is not "
                              "available on your system"),
                            ASPELL_PLUGIN_NAME, lang);
            return;
        }
        new_speller = weechat_aspell_speller_new (lang);
        if (!new_speller)
            return;
        ptr_speller = new_speller;
    }

    if (aspell_speller_add_to_personal (ptr_speller->speller,
                                        word,
                                        strlen (word)) == 1)
    {
        weechat_printf (NULL,
                        _("%s: word \"%s\" added to personal dictionary"),
                        ASPELL_PLUGIN_NAME, word);
    }
    else
    {
        weechat_printf (NULL,
                        _("%s%s: failed to add word to personal "
                          "dictionary"),
                        weechat_prefix ("error"), ASPELL_PLUGIN_NAME);
    }

    if (new_speller)
        weechat_aspell_speller_free (new_speller);
}
Ejemplo n.º 4
0
void
weechat_aspell_command_add_word (struct t_gui_buffer *buffer, const char *dict,
                                 const char *word)
{
    struct t_aspell_speller_buffer *ptr_speller_buffer;
#ifdef USE_ENCHANT
    EnchantDict *new_speller, *ptr_speller;
#else
    AspellSpeller *new_speller, *ptr_speller;
#endif

    new_speller = NULL;

    if (dict)
    {
        ptr_speller = weechat_hashtable_get (weechat_aspell_spellers, dict);
        if (!ptr_speller)
        {
            if (!weechat_aspell_speller_dict_supported (dict))
            {
                weechat_printf (NULL,
                                _("%s: error: dictionary \"%s\" is not "
                                  "available on your system"),
                                ASPELL_PLUGIN_NAME, dict);
                return;
            }
            new_speller = weechat_aspell_speller_new (dict);
            if (!new_speller)
                return;
            ptr_speller = new_speller;
        }
    }
    else
    {
        ptr_speller_buffer = weechat_hashtable_get (weechat_aspell_speller_buffer,
                                                    buffer);
        if (!ptr_speller_buffer)
            ptr_speller_buffer = weechat_aspell_speller_buffer_new (buffer);
        if (!ptr_speller_buffer)
            goto error;
        if (!ptr_speller_buffer->spellers || !ptr_speller_buffer->spellers[0])
        {
            weechat_printf (NULL,
                            _("%s%s: no dictionary on this buffer for "
                              "adding word"),
                            weechat_prefix ("error"),
                            ASPELL_PLUGIN_NAME);
            return;
        }
        else if (ptr_speller_buffer->spellers[1])
        {
            weechat_printf (NULL,
                            _("%s%s: many dictionaries are defined for "
                              "this buffer, please specify dictionary"),
                            weechat_prefix ("error"),
                            ASPELL_PLUGIN_NAME);
            return;
        }
        ptr_speller = ptr_speller_buffer->spellers[0];
    }

#ifdef USE_ENCHANT
    enchant_dict_add (ptr_speller, word, strlen (word));
#else
    if (aspell_speller_add_to_personal (ptr_speller,
                                        word,
                                        strlen (word)) == 1)
    {
        weechat_printf (NULL,
                        _("%s: word \"%s\" added to personal dictionary"),
                        ASPELL_PLUGIN_NAME, word);
    }
    else
        goto error;
#endif

    goto end;

error:
    weechat_printf (NULL,
                    _("%s%s: failed to add word to personal "
                      "dictionary"),
                    weechat_prefix ("error"), ASPELL_PLUGIN_NAME);

end:
    if (new_speller)
        weechat_hashtable_remove (weechat_aspell_spellers, dict);
}