Beispiel #1
0
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
    weechat_guile_plugin = plugin;

    guile_stdout = NULL;

    scm_init_guile ();

    guile_module_weechat = scm_c_define_module ("weechat",
                                                &weechat_guile_api_module_init,
                                                NULL);
    scm_c_use_module ("weechat");
    weechat_guile_catch (scm_gc_protect_object, (void *)guile_module_weechat);

    guile_quiet = 1;
    script_init (weechat_guile_plugin,
                 argc,
                 argv,
                 &weechat_guile_command_cb,
                 &weechat_guile_completion_cb,
                 &weechat_guile_infolist_cb,
                 &weechat_guile_signal_debug_dump_cb,
                 &weechat_guile_signal_buffer_closed_cb,
                 &weechat_guile_signal_script_action_cb,
                 &weechat_guile_load_cb);
    guile_quiet = 0;

    script_display_short_list (weechat_guile_plugin,
                               guile_scripts);

    /* init ok */
    return WEECHAT_RC_OK;
}
Beispiel #2
0
void
weechat_guile_unload (struct t_plugin_script *script)
{
    int *rc;

    if ((weechat_guile_plugin->debug >= 1) || !guile_quiet)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s: unloading script \"%s\""),
                        GUILE_PLUGIN_NAME, script->name);
    }

    if (script->shutdown_func && script->shutdown_func[0])
    {
        rc = (int *)weechat_guile_exec (script, WEECHAT_SCRIPT_EXEC_INT,
                                        script->shutdown_func, NULL, NULL);
        if (rc)
            free (rc);
    }

    weechat_guile_catch (scm_gc_unprotect_object, script->interpreter);

    if (guile_current_script == script)
        guile_current_script = (guile_current_script->prev_script) ?
            guile_current_script->prev_script : guile_current_script->next_script;

    script_remove (weechat_guile_plugin, &guile_scripts, &last_guile_script,
                   script);
}
Beispiel #3
0
int
weechat_guile_load (const char *filename)
{
    char *filename2, *ptr_base_name, *base_name;
    SCM module;

    if ((weechat_guile_plugin->debug >= 2) || !guile_quiet)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s: loading script \"%s\""),
                        GUILE_PLUGIN_NAME, filename);
    }

    guile_current_script = NULL;
    guile_registered_script = NULL;
    guile_current_script_filename = filename;

    filename2 = strdup (filename);
    if (!filename2)
        return 0;

    ptr_base_name = basename (filename2);
    base_name = strdup (ptr_base_name);
    module = scm_c_define_module (base_name,
                                  &weechat_guile_module_init_script, filename2);
    free (filename2);

    if (!guile_registered_script)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s%s: function \"register\" not "
                                         "found (or failed) in file \"%s\""),
                        weechat_prefix ("error"), GUILE_PLUGIN_NAME, filename);
        return 0;
    }

    weechat_guile_catch (scm_gc_protect_object, (void *)module);

    guile_current_script = guile_registered_script;

    /*
     * set input/close callbacks for buffers created by this script
     * (to restore callbacks after upgrade)
     */
    plugin_script_set_buffer_callbacks (weechat_guile_plugin,
                                        guile_scripts,
                                        guile_current_script,
                                        &weechat_guile_api_buffer_input_data_cb,
                                        &weechat_guile_api_buffer_close_cb);

    (void) weechat_hook_signal_send ("guile_script_loaded",
                                     WEECHAT_HOOK_SIGNAL_STRING,
                                     guile_current_script->filename);

    return 1;
}
Beispiel #4
0
void
weechat_guile_module_init_script (void *data)
{
    SCM rc;

    weechat_guile_catch (scm_c_eval_string, "(use-modules (weechat))");
    rc = weechat_guile_catch (scm_c_primitive_load, data);

    /* error loading script? */
    if (rc == SCM_BOOL_F)
    {
        /* if script was registered, remove it from list */
        if (guile_current_script)
        {
            plugin_script_remove (weechat_guile_plugin,
                                  &guile_scripts, &last_guile_script,
                                  guile_current_script);
        }
        guile_current_script = NULL;
        guile_registered_script = NULL;
    }
}
Beispiel #5
0
SCM
weechat_guile_exec_function (const char *function, SCM args)
{
    SCM func, func2, value;
    struct t_guile_function guile_function;

    func = weechat_guile_catch (scm_c_lookup, (void *)function);
    func2 = weechat_guile_catch (scm_variable_ref, func);

    if (args)
    {
        guile_function.proc = func2;
        guile_function.args = args;
        value = weechat_guile_catch (weechat_guile_scm_call_1, &guile_function);
    }
    else
    {
        value = weechat_guile_catch (scm_call_0, func2);
    }

    return value;
}
Beispiel #6
0
int
weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
{
    struct t_plugin_script_init init;

    weechat_guile_plugin = plugin;

    guile_stdout = NULL;

#ifdef HAVE_GUILE_GMP_MEMORY_FUNCTIONS
    /*
     * prevent guile to use its own gmp allocator, because it can conflict
     * with other plugins using GnuTLS like relay, which can crash WeeChat
     * on unload (or exit)
     */
    scm_install_gmp_memory_functions = 0;
#endif /* HAVE_GUILE_GMP_MEMORY_FUNCTIONS */

    scm_init_guile ();

    guile_module_weechat = scm_c_define_module ("weechat",
                                                &weechat_guile_api_module_init,
                                                NULL);
    scm_c_use_module ("weechat");
    weechat_guile_catch (scm_gc_protect_object, (void *)guile_module_weechat);

    init.callback_command = &weechat_guile_command_cb;
    init.callback_completion = &weechat_guile_completion_cb;
    init.callback_hdata = &weechat_guile_hdata_cb;
    init.callback_infolist = &weechat_guile_infolist_cb;
    init.callback_signal_debug_dump = &weechat_guile_signal_debug_dump_cb;
    init.callback_signal_debug_libs = &weechat_guile_signal_debug_libs_cb;
    init.callback_signal_buffer_closed = &weechat_guile_signal_buffer_closed_cb;
    init.callback_signal_script_action = &weechat_guile_signal_script_action_cb;
    init.callback_load_file = &weechat_guile_load_cb;

    guile_quiet = 1;
    plugin_script_init (weechat_guile_plugin, argc, argv, &init);
    guile_quiet = 0;

    plugin_script_display_short_list (weechat_guile_plugin,
                                      guile_scripts);

    /* init OK */
    return WEECHAT_RC_OK;
}
Beispiel #7
0
void
weechat_guile_unload (struct t_plugin_script *script)
{
    int *rc;
    void *interpreter;
    char *filename;

    if ((weechat_guile_plugin->debug >= 2) || !guile_quiet)
    {
        weechat_printf (NULL,
                        weechat_gettext ("%s: unloading script \"%s\""),
                        GUILE_PLUGIN_NAME, script->name);
    }

    if (script->shutdown_func && script->shutdown_func[0])
    {
        rc = (int *)weechat_guile_exec (script, WEECHAT_SCRIPT_EXEC_INT,
                                        script->shutdown_func, NULL, NULL);
        if (rc)
            free (rc);
    }

    filename = strdup (script->filename);
    interpreter = script->interpreter;

    if (guile_current_script == script)
        guile_current_script = (guile_current_script->prev_script) ?
            guile_current_script->prev_script : guile_current_script->next_script;

    plugin_script_remove (weechat_guile_plugin, &guile_scripts, &last_guile_script,
                          script);

    if (interpreter)
        weechat_guile_catch (scm_gc_unprotect_object, interpreter);

    if (guile_current_script)
        scm_set_current_module ((SCM)(guile_current_script->interpreter));

    (void) weechat_hook_signal_send ("guile_script_unloaded",
                                     WEECHAT_HOOK_SIGNAL_STRING, filename);
    if (filename)
        free (filename);
}
Beispiel #8
0
int
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
    /* unload all scripts */
    guile_quiet = 1;
    script_end (plugin, &guile_scripts, &weechat_guile_unload_all);
    guile_quiet = 0;

    /* unprotect module */
    weechat_guile_catch (scm_gc_unprotect_object, (void *)guile_module_weechat);

    /* free some data */
    if (guile_action_install_list)
        free (guile_action_install_list);
    if (guile_action_remove_list)
        free (guile_action_remove_list);

    return WEECHAT_RC_OK;
}
Beispiel #9
0
int
weechat_guile_command_cb (void *data, struct t_gui_buffer *buffer,
                          int argc, char **argv, char **argv_eol)
{
    char *ptr_name, *path_script;
    SCM value;

    /* make C compiler happy */
    (void) data;
    (void) buffer;

    if (argc == 1)
    {
        plugin_script_display_list (weechat_guile_plugin, guile_scripts,
                                    NULL, 0);
    }
    else if (argc == 2)
    {
        if (weechat_strcasecmp (argv[1], "list") == 0)
        {
            plugin_script_display_list (weechat_guile_plugin, guile_scripts,
                                        NULL, 0);
        }
        else if (weechat_strcasecmp (argv[1], "listfull") == 0)
        {
            plugin_script_display_list (weechat_guile_plugin, guile_scripts,
                                        NULL, 1);
        }
        else if (weechat_strcasecmp (argv[1], "autoload") == 0)
        {
            plugin_script_auto_load (weechat_guile_plugin, &weechat_guile_load_cb);
        }
        else if (weechat_strcasecmp (argv[1], "reload") == 0)
        {
            weechat_guile_unload_all ();
            plugin_script_auto_load (weechat_guile_plugin, &weechat_guile_load_cb);
        }
        else if (weechat_strcasecmp (argv[1], "unload") == 0)
        {
            weechat_guile_unload_all ();
        }
        else
            return WEECHAT_RC_ERROR;
    }
    else
    {
        if (weechat_strcasecmp (argv[1], "list") == 0)
        {
            plugin_script_display_list (weechat_guile_plugin, guile_scripts,
                                        argv_eol[2], 0);
        }
        else if (weechat_strcasecmp (argv[1], "listfull") == 0)
        {
            plugin_script_display_list (weechat_guile_plugin, guile_scripts,
                                        argv_eol[2], 1);
        }
        else if ((weechat_strcasecmp (argv[1], "load") == 0)
                 || (weechat_strcasecmp (argv[1], "reload") == 0)
                 || (weechat_strcasecmp (argv[1], "unload") == 0))
        {
            ptr_name = argv_eol[2];
            if (strncmp (ptr_name, "-q ", 3) == 0)
            {
                guile_quiet = 1;
                ptr_name += 3;
                while (ptr_name[0] == ' ')
                {
                    ptr_name++;
                }
            }
            if (weechat_strcasecmp (argv[1], "load") == 0)
            {
                /* load guile script */
                path_script = plugin_script_search_path (weechat_guile_plugin,
                                                         ptr_name);
                weechat_guile_load ((path_script) ? path_script : ptr_name);
                if (path_script)
                    free (path_script);
            }
            else if (weechat_strcasecmp (argv[1], "reload") == 0)
            {
                /* reload one guile script */
                weechat_guile_reload_name (ptr_name);
            }
            else if (weechat_strcasecmp (argv[1], "unload") == 0)
            {
                /* unload guile script */
                weechat_guile_unload_name (ptr_name);
            }
            guile_quiet = 0;
        }
        else if (weechat_strcasecmp (argv[1], "eval") == 0)
        {
            /* eval guile code */
            value = weechat_guile_catch (scm_c_eval_string, argv_eol[2]);
            if (!SCM_EQ_P (value, SCM_UNDEFINED)
                && !SCM_EQ_P (value, SCM_UNSPECIFIED))
            {
                scm_display (value, guile_port);
            }
            weechat_guile_stdout_flush ();
        }
        else
            return WEECHAT_RC_ERROR;
    }

    return WEECHAT_RC_OK;
}
Beispiel #10
0
int
weechat_guile_command_cb (void *data, struct t_gui_buffer *buffer,
                          int argc, char **argv, char **argv_eol)
{
    char *path_script;
    SCM value;

    /* make C compiler happy */
    (void) data;
    (void) buffer;

    if (argc == 1)
    {
        script_display_list (weechat_guile_plugin, guile_scripts,
                             NULL, 0);
    }
    else if (argc == 2)
    {
        if (weechat_strcasecmp (argv[1], "list") == 0)
        {
            script_display_list (weechat_guile_plugin, guile_scripts,
                                 NULL, 0);
        }
        else if (weechat_strcasecmp (argv[1], "listfull") == 0)
        {
            script_display_list (weechat_guile_plugin, guile_scripts,
                                 NULL, 1);
        }
        else if (weechat_strcasecmp (argv[1], "autoload") == 0)
        {
            script_auto_load (weechat_guile_plugin, &weechat_guile_load_cb);
        }
        else if (weechat_strcasecmp (argv[1], "reload") == 0)
        {
            weechat_guile_unload_all ();
            script_auto_load (weechat_guile_plugin, &weechat_guile_load_cb);
        }
        else if (weechat_strcasecmp (argv[1], "unload") == 0)
        {
            weechat_guile_unload_all ();
        }
    }
    else
    {
        if (weechat_strcasecmp (argv[1], "list") == 0)
        {
            script_display_list (weechat_guile_plugin, guile_scripts,
                                 argv_eol[2], 0);
        }
        else if (weechat_strcasecmp (argv[1], "listfull") == 0)
        {
            script_display_list (weechat_guile_plugin, guile_scripts,
                                 argv_eol[2], 1);
        }
        else if (weechat_strcasecmp (argv[1], "load") == 0)
        {
            /* load Guile script */
            path_script = script_search_path (weechat_guile_plugin,
                                              argv_eol[2]);
            weechat_guile_load ((path_script) ? path_script : argv_eol[2]);
            if (path_script)
                free (path_script);
        }
        else if (weechat_strcasecmp (argv[1], "reload") == 0)
        {
            /* reload one Guile script */
            weechat_guile_reload_name (argv_eol[2]);
        }
        else if (weechat_strcasecmp (argv[1], "unload") == 0)
        {
            /* unload Guile script */
            weechat_guile_unload_name (argv_eol[2]);
        }
        else if (weechat_strcasecmp (argv[1], "eval") == 0)
        {
            /* eval Guile code */
            value = weechat_guile_catch (scm_c_eval_string, argv_eol[2]);
            if (!SCM_EQ_P (value, SCM_UNDEFINED)
                && !SCM_EQ_P (value, SCM_UNSPECIFIED))
            {
                scm_display (value, guile_port);
            }
            weechat_guile_stdout_flush ();
        }
        else
        {
            weechat_printf (NULL,
                            weechat_gettext ("%s%s: unknown option for "
                                             "command \"%s\""),
                            weechat_prefix ("error"), GUILE_PLUGIN_NAME,
                            "guile");
        }
    }

    return WEECHAT_RC_OK;
}