Exemple #1
0
void
script_action_schedule (const char *action, int need_repository, int quiet)
{
    script_action_add (action);

    /* create again "script" directory, just in case it has been removed */
    dogechat_mkdir_home (SCRIPT_PLUGIN_NAME, 0755);

    if (need_repository)
    {
        if (script_repo_file_is_uptodate ())
        {
            if (!scripts_repo)
                script_repo_file_read (quiet);
            script_action_run ();
        }
        else
            script_repo_file_update (quiet);
    }
    else
        script_action_run ();
}
Exemple #2
0
int
script_command_script (void *data, struct t_gui_buffer *buffer, int argc,
                       char **argv, char **argv_eol)
{
    char *error;
    long value;
    int line;

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

    if (argc == 1)
    {
        script_action_schedule ("buffer", 1, 0);
        return WEECHAT_RC_OK;
    }

    if (weechat_strcasecmp (argv[1], "go") == 0)
    {
        if ((argc > 2) && script_buffer && !script_buffer_detail_script)
        {
            error = NULL;
            value = strtol (argv[2], &error, 10);
            if (error && !error[0])
            {
                script_buffer_set_current_line (value);
            }
        }
        return WEECHAT_RC_OK;
    }

    if (weechat_strcasecmp (argv[1], "search") == 0)
    {
        if (scripts_repo)
            script_repo_filter_scripts ((argc > 2) ? argv_eol[2] : NULL);
        else
            script_repo_set_filter ((argc > 2) ? argv_eol[2] : NULL);
        script_action_schedule ("buffer", 1, 0);
        return WEECHAT_RC_OK;
    }

    if (weechat_strcasecmp (argv[1], "list") == 0)
    {
        script_action_schedule (argv_eol[1], 1, 0);
        return WEECHAT_RC_OK;
    }

    if ((weechat_strcasecmp (argv[1], "load") == 0)
        || (weechat_strcasecmp (argv[1], "unload") == 0)
        || (weechat_strcasecmp (argv[1], "reload") == 0))
    {
        script_command_action (buffer,
                               argv[1],
                               (argc > 2) ? argv_eol[2] : NULL,
                               0);
        return WEECHAT_RC_OK;
    }

    if ((weechat_strcasecmp (argv[1], "install") == 0)
        || (weechat_strcasecmp (argv[1], "remove") == 0)
        || (weechat_strcasecmp (argv[1], "installremove") == 0)
        || (weechat_strcasecmp (argv[1], "hold") == 0)
        || (weechat_strcasecmp (argv[1], "show") == 0)
        || (weechat_strcasecmp (argv[1], "showdiff") == 0))
    {
        script_command_action (buffer,
                               argv[1],
                               (argc > 2) ? argv_eol[2] : NULL,
                               1);
        return WEECHAT_RC_OK;
    }

    if (weechat_strcasecmp (argv[1], "upgrade") == 0)
    {
        script_action_schedule ("upgrade", 1, 0);
        return WEECHAT_RC_OK;
    }

    if (weechat_strcasecmp (argv[1], "update") == 0)
    {
        script_repo_file_update (0);
        return WEECHAT_RC_OK;
    }

    if (!script_buffer)
        script_buffer_open ();

    if (script_buffer)
    {
        weechat_buffer_set (script_buffer, "display", "1");

        if (argc > 1)
        {
            if (!script_buffer_detail_script
                && (script_buffer_selected_line >= 0)
                && (script_repo_count_displayed > 0))
            {
                if (strcmp (argv[1], "up") == 0)
                {
                    value = 1;
                    if (argc > 2)
                    {
                        error = NULL;
                        value = strtol (argv[2], &error, 10);
                        if (!error || error[0])
                            value = 1;
                    }
                    line = script_buffer_selected_line - value;
                    if (line < 0)
                        line = 0;
                    if (line != script_buffer_selected_line)
                    {
                        script_buffer_set_current_line (line);
                        script_buffer_check_line_outside_window ();
                    }
                    return WEECHAT_RC_OK;
                }
                else if (strcmp (argv[1], "down") == 0)
                {
                    value = 1;
                    if (argc > 2)
                    {
                        error = NULL;
                        value = strtol (argv[2], &error, 10);
                        if (!error || error[0])
                            value = 1;
                    }
                    line = script_buffer_selected_line + value;
                    if (line >= script_repo_count_displayed)
                        line = script_repo_count_displayed - 1;
                    if (line != script_buffer_selected_line)
                    {
                        script_buffer_set_current_line (line);
                        script_buffer_check_line_outside_window ();
                    }
                    return WEECHAT_RC_OK;
                }
            }
        }
    }

    script_buffer_refresh (0);

    return WEECHAT_RC_OK;
}