Пример #1
0
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
    /* make C compiler happy */
    (void) argc;
    (void) argv;

    weechat_plugin = plugin;

    rmodifier_count = 0;

    rmodifier_hook_list = weechat_list_new ();

    if (!rmodifier_config_init ())
    {
        weechat_printf (NULL,
                        _("%s%s: error creating configuration file"),
                        weechat_prefix("error"), RMODIFIER_PLUGIN_NAME);
        return WEECHAT_RC_ERROR;
    }
    rmodifier_config_read ();

    rmodifier_command_init ();
    rmodifier_completion_init ();

    rmodifier_info_init ();

    rmodifier_debug_init ();

    return WEECHAT_RC_OK;
}
Пример #2
0
struct t_weelist *
script_buffer_get_script_usage (struct t_script_repo *script)
{
    struct t_weelist *list;
    char hdata_name[128], str_option[256], str_info[1024];
    int config_files;
    const char *ptr_name_hdata_callback, *type;
    struct t_hdata *ptr_hdata_script, *ptr_hdata_callback;
    struct t_hdata *ptr_hdata_config_file, *ptr_hdata_bar_item;
    void *ptr_script, *ptr_callback;
    struct t_config_file *ptr_config_file;
    struct t_hook *ptr_hook;
    struct t_gui_bar_item *ptr_bar_item;
    struct t_infolist *infolist;

    config_files = 0;

    snprintf (hdata_name, sizeof (hdata_name),
              "%s_script", script_language[script->language]);
    ptr_hdata_script = weechat_hdata_get (hdata_name);
    if (!ptr_hdata_script)
        return NULL;

    ptr_script = script_buffer_get_script_pointer (script, ptr_hdata_script);
    if (!ptr_script)
        return NULL;

    ptr_name_hdata_callback = weechat_hdata_get_var_hdata (ptr_hdata_script,
                                                           "callbacks");
    if (!ptr_name_hdata_callback)
        return NULL;
    ptr_hdata_callback = weechat_hdata_get (ptr_name_hdata_callback);
    if (!ptr_hdata_callback)
        return NULL;

    list = weechat_list_new ();

    ptr_hdata_config_file = weechat_hdata_get ("config_file");
    ptr_hdata_bar_item = weechat_hdata_get ("bar_item");

    ptr_callback = weechat_hdata_pointer (ptr_hdata_script,
                                          ptr_script,
                                          "callbacks");
    while (ptr_callback)
    {
        str_info[0] = '\0';
        ptr_config_file = weechat_hdata_pointer (ptr_hdata_callback,
                                                 ptr_callback,
                                                 "config_file");
        ptr_hook = weechat_hdata_pointer (ptr_hdata_callback,
                                          ptr_callback,
                                          "hook");
        ptr_bar_item = weechat_hdata_pointer (ptr_hdata_callback,
                                              ptr_callback,
                                              "bar_item");
        if (ptr_config_file)
        {
            snprintf (str_info, sizeof (str_info),
                      _("configuration file \"%s\" (options %s.*)"),
                      weechat_hdata_string (ptr_hdata_config_file,
                                            ptr_config_file,
                                            "filename"),
                      weechat_hdata_string (ptr_hdata_config_file,
                                            ptr_config_file,
                                            "name"));
            config_files++;
        }
        else if (ptr_hook)
        {
            infolist = weechat_infolist_get ("hook", ptr_hook, NULL);
            if (infolist)
            {
                if (weechat_infolist_next (infolist))
                {
                    type = weechat_infolist_string (infolist, "type");
                    if (type)
                    {
                        if (strcmp (type, "command") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      _("command /%s"),
                                      weechat_infolist_string (infolist,
                                                               "command"));
                        }
                        else if (strcmp (type, "completion") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      _("completion %%(%s)"),
                                      weechat_infolist_string (infolist,
                                                               "completion_item"));
                        }
                        else if (strcmp (type, "info") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      "info \"%s\"",
                                      weechat_infolist_string (infolist,
                                                               "info_name"));
                        }
                        else if (strcmp (type, "info_hashtable") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      "info_hashtable \"%s\"",
                                      weechat_infolist_string (infolist,
                                                               "info_name"));
                        }
                        else if (strcmp (type, "infolist") == 0)
                        {
                            snprintf (str_info, sizeof (str_info),
                                      "infolist \"%s\"",
                                      weechat_infolist_string (infolist,
                                                               "infolist_name"));
                        }
                    }
                }
                weechat_infolist_free (infolist);
            }
        }
        else if (ptr_bar_item)
        {
            snprintf (str_info, sizeof (str_info),
                      _("bar item \"%s\""),
                      weechat_hdata_string (ptr_hdata_bar_item,
                                            ptr_bar_item,
                                            "name"));
        }
        if (str_info[0])
        {
            weechat_list_add (list, str_info,
                              WEECHAT_LIST_POS_END, NULL);
        }
        ptr_callback = weechat_hdata_move (ptr_hdata_callback,
                                           ptr_callback,
                                           1);
    }

    snprintf (str_option, sizeof (str_option),
              "plugins.var.%s.%s.*",
              script_language[script->language],
              weechat_hdata_string (ptr_hdata_script, ptr_script, "name"));
    infolist = weechat_infolist_get ("option", NULL, str_option);
    if (infolist)
    {
        if (weechat_infolist_next (infolist))
        {
            snprintf (str_info, sizeof (str_info),
                      _("options %s%s%s"),
                      str_option,
                      (config_files > 0) ? " " : "",
                      (config_files > 0) ? _("(old options?)") : "");
            weechat_list_add (list, str_info,
                              WEECHAT_LIST_POS_END, NULL);
        }
        weechat_infolist_free (infolist);
    }

    return list;
}
Пример #3
0
struct t_weelist *
script_buffer_get_script_usage (struct t_script_repo *script)
{
    struct t_weelist *list;
    char hdata_name[128], str_option[256], str_info[1024];
    int config_files;
    struct t_hdata *hdata_script, *hdata_config, *hdata_bar_item;
    void *ptr_script, *callback_pointer;
    struct t_config_file *ptr_config;
    struct t_gui_bar_item *ptr_bar_item;
    struct t_infolist *infolist;

    config_files = 0;

    snprintf (hdata_name, sizeof (hdata_name),
              "%s_script", script_language[script->language]);
    hdata_script = weechat_hdata_get (hdata_name);
    if (!hdata_script)
        return NULL;

    ptr_script = script_buffer_get_script_pointer (script, hdata_script);
    if (!ptr_script)
        return NULL;

    list = weechat_list_new ();

    /* get configuration files created by the script */
    hdata_config = weechat_hdata_get ("config_file");
    ptr_config = weechat_hdata_get_list (hdata_config, "config_files");
    while (ptr_config)
    {
        callback_pointer = weechat_hdata_pointer (
            hdata_config, ptr_config, "callback_reload_pointer");
        if (callback_pointer == ptr_script)
        {
            snprintf (str_info, sizeof (str_info),
                      _("configuration file \"%s\" (options %s.*)"),
                      weechat_hdata_string (hdata_config, ptr_config,
                                            "filename"),
                      weechat_hdata_string (hdata_config, ptr_config,
                                            "name"));
            weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            config_files++;
        }
        ptr_config = weechat_hdata_move (hdata_config, ptr_config, 1);
    }

    /* get the commands created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "command");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          _("command /%s"),
                          weechat_infolist_string (infolist,
                                                   "command"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the completions created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "completion");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          _("completion %%(%s)"),
                          weechat_infolist_string (infolist,
                                                   "completion_item"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the infos created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "info");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          "info \"%s\"",
                          weechat_infolist_string (infolist,
                                                   "info_name"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the infos (hashtable) created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "info_hashtable");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          "info_hashtable \"%s\"",
                          weechat_infolist_string (infolist,
                                                   "info_name"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the infolists created by the script */
    infolist = weechat_infolist_get ("hook", NULL, "infolist");
    if (infolist)
    {
        while (weechat_infolist_next (infolist))
        {
            callback_pointer = weechat_infolist_pointer (infolist,
                                                         "callback_pointer");
            if (callback_pointer == ptr_script)
            {
                snprintf (str_info, sizeof (str_info),
                          "infolist \"%s\"",
                          weechat_infolist_string (infolist,
                                                   "infolist_name"));
                weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
            }
        }
        weechat_infolist_free (infolist);
    }

    /* get the bar items created by the script */
    hdata_bar_item = weechat_hdata_get ("bar_item");
    ptr_bar_item = weechat_hdata_get_list (hdata_bar_item, "gui_bar_items");
    while (ptr_bar_item)
    {
        callback_pointer = weechat_hdata_pointer (hdata_bar_item, ptr_bar_item,
                                                  "build_callback_pointer");
        if (callback_pointer == ptr_script)
        {
            snprintf (str_info, sizeof (str_info),
                      _("bar item \"%s\""),
                      weechat_hdata_string (hdata_bar_item,
                                            ptr_bar_item,
                                            "name"));
            weechat_list_add (list, str_info, WEECHAT_LIST_POS_END, NULL);
        }
        ptr_bar_item = weechat_hdata_move (hdata_bar_item, ptr_bar_item, 1);
    }

    /* get the script options (in plugins.var) */
    snprintf (str_option, sizeof (str_option),
              "plugins.var.%s.%s.*",
              script_language[script->language],
              weechat_hdata_string (hdata_script, ptr_script, "name"));
    infolist = weechat_infolist_get ("option", NULL, str_option);
    if (infolist)
    {
        if (weechat_infolist_next (infolist))
        {
            snprintf (str_info, sizeof (str_info),
                      _("options %s%s%s"),
                      str_option,
                      (config_files > 0) ? " " : "",
                      (config_files > 0) ? _("(old options?)") : "");
            weechat_list_add (list, str_info,
                              WEECHAT_LIST_POS_END, NULL);
        }
        weechat_infolist_free (infolist);
    }

    return list;
}
Пример #4
0
int
irc_completion_channels_cb (const void *pointer, void *data,
                            const char *completion_item,
                            struct t_gui_buffer *buffer,
                            struct t_gui_completion *completion)
{
    struct t_irc_server *ptr_server2;
    struct t_irc_channel *ptr_channel2;
    struct t_weelist *channels_current_server;
    int i;

    IRC_BUFFER_GET_SERVER_CHANNEL(buffer);

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

    channels_current_server = weechat_list_new ();

    for (ptr_server2 = irc_servers; ptr_server2;
         ptr_server2 = ptr_server2->next_server)
    {
        for (ptr_channel2 = ptr_server2->channels; ptr_channel2;
             ptr_channel2 = ptr_channel2->next_channel)
        {
            if (ptr_channel2->type == IRC_CHANNEL_TYPE_CHANNEL)
            {
                if (ptr_server2 == ptr_server)
                {
                    /* will be added later to completions */
                    weechat_list_add (channels_current_server,
                                      ptr_channel2->name,
                                      WEECHAT_LIST_POS_SORT,
                                      NULL);
                }
                else
                {
                    weechat_hook_completion_list_add (completion,
                                                      ptr_channel2->name,
                                                      0,
                                                      WEECHAT_LIST_POS_SORT);
                }
            }
        }
    }

    /* add channels of current server first in list */
    for (i = weechat_list_size (channels_current_server) - 1; i >= 0; i--)
    {
        weechat_hook_completion_list_add (
            completion,
            weechat_list_string (
                weechat_list_get (channels_current_server, i)),
            0,
            WEECHAT_LIST_POS_BEGINNING);
    }
    weechat_list_free (channels_current_server);

    /* add current channel first in list */
    if (ptr_channel)
    {
        weechat_hook_completion_list_add (completion, ptr_channel->name,
                                          0, WEECHAT_LIST_POS_BEGINNING);
    }

    return WEECHAT_RC_OK;
}