summaryrefslogtreecommitdiff
path: root/src/plugins/spell/spell-info.c
blob: a92da0122dedfcd2866f11abffe00d038d5363bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
 * spell-info.c - info for spell checker plugin
 *
 * Copyright (C) 2013-2019 Sébastien Helleu <flashcode@flashtux.org>
 *
 * This file is part of WeeChat, the extensible chat client.
 *
 * WeeChat 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 3 of the License, or
 * (at your option) any later version.
 *
 * WeeChat 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 WeeChat.  If not, see <https://www.gnu.org/licenses/>.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "../weechat-plugin.h"
#include "spell.h"


/*
 * Returns spell info "spell_dict".
 */

char *
spell_info_info_spell_dict_cb (const void *pointer, void *data,
                               const char *info_name,
                               const char *arguments)
{
    int rc;
    unsigned long value;
    struct t_gui_buffer *buffer;
    const char *buffer_full_name, *ptr_dict;

    /* make C compiler happy */
    (void) pointer;
    (void) data;
    (void) info_name;

    ptr_dict = NULL;

    if (!arguments)
        return NULL;

    buffer_full_name = NULL;
    if (strncmp (arguments, "0x", 2) == 0)
    {
        rc = sscanf (arguments, "%lx", &value);
        if ((rc != EOF) && (rc != 0))
        {
            buffer = (struct t_gui_buffer *)value;
            if (buffer)
            {
                buffer_full_name = weechat_buffer_get_string (buffer,
                                                              "full_name");
            }
        }
    }
    else
        buffer_full_name = arguments;

    if (buffer_full_name)
        ptr_dict = spell_get_dict_with_buffer_name (buffer_full_name);

    return (ptr_dict) ? strdup (ptr_dict) : NULL;
}

/*
 * Hooks info for spell plugin.
 */

void
spell_info_init ()
{
    /* info hooks */
    weechat_hook_info (
        "spell_dict",
        N_("comma-separated list of dictionaries used in buffer"),
        N_("buffer pointer (\"0x12345678\") or buffer full name "
           "(\"irc.freenode.#weechat\")"),
        &spell_info_info_spell_dict_cb, NULL, NULL);
}