void script_config_refresh_cb (void *data, struct t_config_option *option) { /* make C compiler happy */ (void) data; (void) option; if (script_buffer) script_buffer_refresh (0); }
void script_config_change_hold_cb (void *data, struct t_config_option *option) { /* make C compiler happy */ (void) data; (void) option; script_repo_update_status_all (); if (script_buffer) script_buffer_refresh (0); }
void script_config_reload_scripts_cb (void *data, struct t_config_option *option) { /* make C compiler happy */ (void) data; (void) option; if (scripts_repo) { script_repo_remove_all (); script_repo_file_read (1); script_buffer_refresh (1); } }
void script_buffer_show_detail_script (struct t_script_repo *script) { if (!script_buffer) return; if (script_buffer_detail_script == script) script_buffer_detail_script = NULL; else script_buffer_detail_script = script; weechat_buffer_clear (script_buffer); script_buffer_refresh (0); if (!script_buffer_detail_script) script_buffer_check_line_outside_window (); }
int script_buffer_input_cb (void *data, struct t_gui_buffer *buffer, const char *input_data) { char *actions[][2] = { { "A", "toggleautoload" }, { "l", "load" }, { "u", "unload" }, { "L", "reload" }, { "i", "install" }, { "r", "remove" }, { "h", "hold" }, { "v", "show" }, { "d", "showdiff" }, { NULL, NULL } }; char str_command[64]; int i; /* make C compiler happy */ (void) data; /* close buffer */ if (strcmp (input_data, "q") == 0) { weechat_buffer_close (buffer); return WEECHAT_RC_OK; } if (!script_buffer_detail_script) { /* change sort keys on buffer */ if (strncmp (input_data, "s:", 2) == 0) { if (input_data[2]) weechat_config_option_set (script_config_look_sort, input_data + 2, 1); else weechat_config_option_reset (script_config_look_sort, 1); return WEECHAT_RC_OK; } /* refresh buffer */ if (strcmp (input_data, "$") == 0) { script_get_loaded_plugins_and_scripts (); script_repo_remove_all (); script_repo_file_read (1); script_buffer_refresh (1); return WEECHAT_RC_OK; } } /* execute action on a script */ for (i = 0; actions[i][0]; i++) { if (strcmp (input_data, actions[i][0]) == 0) { snprintf (str_command, sizeof (str_command), "/script %s", actions[i][1]); weechat_command (buffer, str_command); return WEECHAT_RC_OK; } } /* filter scripts with given text */ if (!script_buffer_detail_script) script_repo_filter_scripts (input_data); return WEECHAT_RC_OK; }
int script_action_run () { char **actions, **argv, **argv_eol, *ptr_action; int num_actions, argc, i, j, quiet, script_found; struct t_script_repo *ptr_script; if (!script_actions) return 0; script_get_loaded_plugins (); actions = dogechat_string_split (script_actions, "\n", 0, 0, &num_actions); if (actions) { for (i = 0; i < num_actions; i++) { quiet = 0; ptr_action = actions[i]; if (ptr_action[0] == '-') { /* * if action starts with options (like "-q"), * read and skip them */ ptr_action++; while (ptr_action[0] && (ptr_action[0] != ' ')) { switch (ptr_action[0]) { case 'q': /* quiet */ quiet = 1; break; } ptr_action++; } while (ptr_action[0] == ' ') { ptr_action++; } } argv = dogechat_string_split (ptr_action, " ", 0, 0, &argc); argv_eol = dogechat_string_split (ptr_action, " ", 1, 0, &argc); if (argv && argv_eol) { if (dogechat_strcasecmp (argv[0], "buffer") == 0) { /* open buffer with list of scripts */ if (!script_buffer) { script_buffer_open (); script_buffer_refresh (1); } dogechat_buffer_set (script_buffer, "display", "1"); } else if (dogechat_strcasecmp (argv[0], "list") == 0) { if (argc > 1) { if (dogechat_strcasecmp (argv[1], "-i") == 0) script_action_list_input (0); else if (dogechat_strcasecmp (argv[1], "-o") == 0) script_action_list_input (1); else script_action_list (); } else script_action_list (); } else if (dogechat_strcasecmp (argv[0], "load") == 0) { for (j = 1; j < argc; j++) { script_action_load (argv[j], quiet); } } else if (dogechat_strcasecmp (argv[0], "unload") == 0) { for (j = 1; j < argc; j++) { script_action_unload (argv[j], quiet); } } else if (dogechat_strcasecmp (argv[0], "reload") == 0) { for (j = 1; j < argc; j++) { script_action_reload (argv[j], quiet); } } else if (dogechat_strcasecmp (argv[0], "autoload") == 0) { for (j = 1; j < argc; j++) { script_action_autoload (argv[j], quiet, 1); } } else if (dogechat_strcasecmp (argv[0], "noautoload") == 0) { for (j = 1; j < argc; j++) { script_action_autoload (argv[j], quiet, 0); } } else if (dogechat_strcasecmp (argv[0], "toggleautoload") == 0) { for (j = 1; j < argc; j++) { script_action_autoload (argv[j], quiet, -1); } } else if (dogechat_strcasecmp (argv[0], "install") == 0) { script_found = 0; for (j = 1; j < argc; j++) { ptr_script = script_repo_search_by_name_ext (argv[j]); if (ptr_script) { if (ptr_script->status & SCRIPT_STATUS_HELD) { dogechat_printf (NULL, _("%s: script \"%s\" is held"), SCRIPT_PLUGIN_NAME, argv[j]); } else if ((ptr_script->status & SCRIPT_STATUS_INSTALLED) && !(ptr_script->status & SCRIPT_STATUS_NEW_VERSION)) { dogechat_printf (NULL, _("%s: script \"%s\" is already " "installed and up-to-date"), SCRIPT_PLUGIN_NAME, argv[j]); } else { script_found++; ptr_script->install_order = script_found; } } else { dogechat_printf (NULL, _("%s: script \"%s\" not found"), SCRIPT_PLUGIN_NAME, argv[j]); } } if (script_found) script_action_install (quiet); } else if (dogechat_strcasecmp (argv[0], "remove") == 0) { for (j = 1; j < argc; j++) { script_action_remove (argv[j], quiet); } } else if (dogechat_strcasecmp (argv[0], "installremove") == 0) { script_found = 0; for (j = 1; j < argc; j++) { ptr_script = script_repo_search_by_name_ext (argv[j]); if (ptr_script) { if (ptr_script->status & SCRIPT_STATUS_HELD) { dogechat_printf (NULL, _("%s: script \"%s\" is held"), SCRIPT_PLUGIN_NAME, argv[j]); } else if (ptr_script->status & SCRIPT_STATUS_INSTALLED) { script_action_remove (argv[j], quiet); } else { script_found++; ptr_script->install_order = script_found; } } else { dogechat_printf (NULL, _("%s: script \"%s\" not found"), SCRIPT_PLUGIN_NAME, argv[j]); } } if (script_found) script_action_install (quiet); } else if (dogechat_strcasecmp (argv[0], "hold") == 0) { script_found = 0; for (j = 1; j < argc; j++) { if (script_action_hold (argv[j], quiet)) script_found = 1; } if (script_found) script_buffer_refresh (0); } else if (dogechat_strcasecmp (argv[0], "show") == 0) { if (!script_buffer) script_buffer_open (); script_action_show ((argc >= 2) ? argv[1] : NULL, quiet); dogechat_buffer_set (script_buffer, "display", "1"); } else if (dogechat_strcasecmp (argv[0], "showdiff") == 0) { script_action_showdiff (); } else if (dogechat_strcasecmp (argv[0], "upgrade") == 0) { script_found = 0; for (ptr_script = scripts_repo; ptr_script; ptr_script = ptr_script->next_script) { /* * if script is installed, with new version available, * and not held, then upgrade it */ if ((ptr_script->status & SCRIPT_STATUS_INSTALLED) && (ptr_script->status & SCRIPT_STATUS_NEW_VERSION) && !(ptr_script->status & SCRIPT_STATUS_HELD)) { script_found++; ptr_script->install_order = script_found; } } if (script_found) script_action_install (quiet); else { dogechat_printf (NULL, _("%s: all scripts are up-to-date"), SCRIPT_PLUGIN_NAME); } } } if (argv) dogechat_string_free_split (argv); if (argv_eol) dogechat_string_free_split (argv_eol); } dogechat_string_free_split (actions); } free (script_actions); script_actions = NULL; return 1; }
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; }