void irc_notify_set_server_option (struct t_irc_server *server) { char *str, *str2; struct t_irc_notify *ptr_notify; int total_length, length; if (!server) return; if (server->notify_list) { str = NULL; total_length = 0; for (ptr_notify = server->notify_list; ptr_notify; ptr_notify = ptr_notify->next_notify) { length = strlen (ptr_notify->nick) + 32; if (!str) { total_length += length + 1; str = malloc (total_length); if (str) str[0] = '\0'; } else { total_length += length; str2 = realloc (str, total_length); if (!str2) { if (str) free (str); return; } str = str2; } if (str) { if (str[0]) strcat (str, ","); strcat (str, ptr_notify->nick); if (ptr_notify->check_away) strcat (str, " away"); } } if (str) { weechat_config_option_set (server->options[IRC_SERVER_OPTION_NOTIFY], str, 0); free (str); } } else { weechat_config_option_set (server->options[IRC_SERVER_OPTION_NOTIFY], "", 0); } }
void script_config_unhold (const char *name_with_extension) { char **items, *hold; int num_items, i, length; length = strlen (weechat_config_string (script_config_scripts_hold)) + 1; hold = malloc (length); if (hold) { hold[0] = '\0'; items = weechat_string_split (weechat_config_string (script_config_scripts_hold), ",", 0, 0, &num_items); if (items) { for (i = 0; i < num_items; i++) { if (strcmp (items[i], name_with_extension) != 0) { if (hold[0]) strcat (hold, ","); strcat (hold, items[i]); } } weechat_string_free_split (items); } weechat_config_option_set (script_config_scripts_hold, hold, 0); free (hold); } }
/** * Called when a profile option is read. */ int twc_config_profile_read_callback(void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, const char *value) { int rc = WEECHAT_CONFIG_OPTION_SET_ERROR; if (option_name) { char *dot_pos = strrchr(option_name, '.'); if (dot_pos) { char *profile_name = weechat_strndup(option_name, dot_pos-option_name); char *option_name = dot_pos + 1; if (profile_name) { int option_index = twc_config_profile_option_search(option_name); if (option_index >= 0) { struct t_twc_profile *profile = twc_profile_search_name(profile_name); if (!profile) profile = twc_profile_new(profile_name); if (profile) { rc = weechat_config_option_set(profile->options[option_index], value, 1); } else { weechat_printf(NULL, "%s%s: error creating profile \"%s\"", weechat_prefix("error"), weechat_plugin->name, profile_name); } } free(profile_name); } } } if (rc == WEECHAT_CONFIG_OPTION_SET_ERROR) { weechat_printf(NULL, "%s%s: error creating profile option \"%s\"", weechat_prefix("error"), weechat_plugin->name, option_name); } return rc; }
int logger_config_mask_create_option (void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, const char *value) { struct t_config_option *ptr_option; int rc; /* make C compiler happy */ (void) data; rc = WEECHAT_CONFIG_OPTION_SET_ERROR; if (option_name) { ptr_option = weechat_config_search_option (config_file, section, option_name); if (ptr_option) { if (value && value[0]) rc = weechat_config_option_set (ptr_option, value, 1); else { weechat_config_option_free (ptr_option); rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } else { if (value && value[0]) { ptr_option = weechat_config_new_option ( config_file, section, option_name, "string", _("file mask for log file; local buffer variables are " "permitted"), NULL, 0, 0, "", value, 0, NULL, NULL, &logger_config_mask_change, NULL, NULL, NULL); rc = (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; } else rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } if (!logger_config_loading) { logger_stop_all (); logger_start_buffer_all (); } return rc; }
int logger_config_level_create_option (const void *pointer, void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, const char *value) { struct t_config_option *ptr_option; int rc; /* make C compiler happy */ (void) pointer; (void) data; rc = WEECHAT_CONFIG_OPTION_SET_ERROR; if (option_name) { ptr_option = weechat_config_search_option (config_file, section, option_name); if (ptr_option) { if (value && value[0]) rc = weechat_config_option_set (ptr_option, value, 1); else { weechat_config_option_free (ptr_option); rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } else { if (value && value[0]) { ptr_option = weechat_config_new_option ( config_file, section, option_name, "integer", _("logging level for this buffer (0 = logging disabled, " "1 = a few messages (most important) .. 9 = all messages)"), NULL, 0, 9, "9", value, 0, NULL, NULL, NULL, &logger_config_level_change, NULL, NULL, NULL, NULL, NULL); rc = (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; } else rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } if (!logger_config_loading) logger_start_buffer_all (1); return rc; }
int charset_config_create_option (void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, const char *value) { struct t_config_option *ptr_option; int rc; /* make C compiler happy */ (void) data; rc = WEECHAT_CONFIG_OPTION_SET_ERROR; if (option_name) { ptr_option = weechat_config_search_option (config_file, section, option_name); if (ptr_option) { if (value && value[0]) rc = weechat_config_option_set (ptr_option, value, 1); else { weechat_config_option_free (ptr_option); rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } else { if (value && value[0]) { ptr_option = weechat_config_new_option ( config_file, section, option_name, "string", NULL, NULL, 0, 0, "", value, 0, NULL, NULL, NULL, NULL, NULL, NULL); rc = (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; } else rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } if (rc == WEECHAT_CONFIG_OPTION_SET_ERROR) { weechat_printf (NULL, _("%s%s: error creating charset \"%s\" => \"%s\""), weechat_prefix ("error"), CHARSET_PLUGIN_NAME, option_name, value); } return rc; }
void trigger_command_set_enabled (struct t_trigger *trigger, int enable, const char *enable_string, int display_error) { if (trigger->hook_running) { trigger_command_error_running (trigger, enable_string); return; } if (enable == 2) { if (weechat_config_boolean (trigger->options[TRIGGER_OPTION_ENABLED])) { trigger_hook (trigger); weechat_printf_date_tags (NULL, 0, "no_trigger", _("Trigger \"%s\" restarted"), trigger->name); } else if (display_error) { weechat_printf_date_tags (NULL, 0, "no_trigger", _("%s%s: a disabled trigger can not be " "restarted"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); } } else { if (enable < 0) { enable = weechat_config_boolean (trigger->options[TRIGGER_OPTION_ENABLED]) ? 0 : 1; } weechat_config_option_set (trigger->options[TRIGGER_OPTION_ENABLED], (enable) ? "on" : "off", 1); weechat_printf_date_tags (NULL, 0, "no_trigger", (enable) ? _("Trigger \"%s\" enabled") : _("Trigger \"%s\" disabled"), trigger->name); } }
void script_config_hold (const char *name_with_extension) { char **items, *hold; int num_items, i, length; length = strlen (weechat_config_string (script_config_scripts_hold)) + 1 + strlen (name_with_extension) + 1; hold = malloc (length); if (hold) { hold[0] = '\0'; items = weechat_string_split ( weechat_config_string (script_config_scripts_hold), ",", WEECHAT_STRING_SPLIT_STRIP_LEFT | WEECHAT_STRING_SPLIT_STRIP_RIGHT | WEECHAT_STRING_SPLIT_COLLAPSE_SEPS, 0, &num_items); if (items) { for (i = 0; i < num_items; i++) { if (strcmp (items[i], name_with_extension) != 0) { if (hold[0]) strcat (hold, ","); strcat (hold, items[i]); } } weechat_string_free_split (items); } if (hold[0]) strcat (hold, ","); strcat (hold, name_with_extension); weechat_config_option_set (script_config_scripts_hold, hold, 0); free (hold); } }
int weechat_aspell_config_dict_create_option (void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, const char *value) { struct t_config_option *ptr_option; int rc; /* make C compiler happy */ (void) data; rc = WEECHAT_CONFIG_OPTION_SET_ERROR; if (value && value[0]) weechat_aspell_speller_check_dictionaries (value); if (option_name) { ptr_option = weechat_config_search_option (config_file, section, option_name); if (ptr_option) { if (value && value[0]) rc = weechat_config_option_set (ptr_option, value, 1); else { weechat_config_option_free (ptr_option); rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } else { if (value && value[0]) { ptr_option = weechat_config_new_option ( config_file, section, option_name, "string", _("comma separated list of dictionaries to use on this buffer"), NULL, 0, 0, "", value, 0, NULL, NULL, &weechat_aspell_config_dict_change, NULL, NULL, NULL); rc = (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; } else rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } if (rc == WEECHAT_CONFIG_OPTION_SET_ERROR) { weechat_printf (NULL, _("%s%s: error creating aspell dictionary \"%s\" => \"%s\""), weechat_prefix ("error"), ASPELL_PLUGIN_NAME, option_name, value); } else weechat_aspell_create_spellers (weechat_current_buffer ()); return rc; }
int weechat_aspell_config_option_create_option (const void *pointer, void *data, struct t_config_file *config_file, struct t_config_section *section, const char *option_name, const char *value) { struct t_config_option *ptr_option; int rc; /* make C compiler happy */ (void) pointer; (void) data; rc = WEECHAT_CONFIG_OPTION_SET_ERROR; if (option_name) { ptr_option = weechat_config_search_option (config_file, section, option_name); if (ptr_option) { if (value && value[0]) rc = weechat_config_option_set (ptr_option, value, 1); else { weechat_config_option_free (ptr_option); rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } else { if (value && value[0]) { ptr_option = weechat_config_new_option ( config_file, section, option_name, "string", _("option for aspell (for list of available options and " "format, run command \"aspell config\" in a shell)"), NULL, 0, 0, "", value, 0, NULL, NULL, NULL, &weechat_aspell_config_option_change, NULL, NULL, NULL, NULL, NULL); rc = (ptr_option) ? WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR; } else rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } if (rc == WEECHAT_CONFIG_OPTION_SET_ERROR) { weechat_printf (NULL, _("%s%s: error creating aspell option \"%s\" => \"%s\""), weechat_prefix ("error"), ASPELL_PLUGIN_NAME, option_name, value); } else { weechat_hashtable_remove_all (weechat_aspell_speller_buffer); if (!weechat_aspell_config_loading) weechat_aspell_speller_remove_unused (); } return rc; }
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 trigger_command_trigger (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_trigger *ptr_trigger, *ptr_trigger2; struct t_trigger_regex *regex; char *value, **sargv, **items, input[1024], str_pos[16]; int rc, i, type, count, index_option, enable, sargc, num_items, add_rc; int regex_count, regex_rc; /* make C compiler happy */ (void) data; rc = WEECHAT_RC_OK; sargv = NULL; /* list all triggers */ if ((argc == 1) || ((argc == 2) && (weechat_strcasecmp (argv[1], "list") == 0))) { trigger_command_list (_("List of triggers:"), 0); goto end; } /* full list of all triggers */ if ((argc == 2) && (weechat_strcasecmp (argv[1], "listfull") == 0)) { trigger_command_list (_("List of triggers:"), 1); goto end; } /* list of default triggers */ if ((argc == 2) && (weechat_strcasecmp (argv[1], "listdefault") == 0)) { trigger_command_list_default (1); goto end; } /* add a trigger */ if ((weechat_strcasecmp (argv[1], "add") == 0) || (weechat_strcasecmp (argv[1], "addoff") == 0) || (weechat_strcasecmp (argv[1], "addreplace") == 0)) { sargv = weechat_string_split_shell (argv_eol[2], &sargc); if (!sargv || (sargc < 2)) goto error; if (!trigger_name_valid (sargv[0])) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid name for trigger"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; } type = trigger_search_hook_type (sargv[1]); if (type < 0) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid hook type \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[1]); goto end; } if ((sargc > 4) && sargv[4][0]) { regex_count = 0; regex = NULL; regex_rc = trigger_regex_split (sargv[4], ®ex_count, ®ex); trigger_regex_free (®ex_count, ®ex); switch (regex_rc) { case 0: /* OK */ break; case -1: /* format error */ weechat_printf (NULL, _("%s%s: invalid format for regular " "expression"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; break; case -2: /* regex compilation error */ weechat_printf (NULL, _("%s%s: invalid regular expression " "(compilation failed)"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; break; case -3: /* memory error */ weechat_printf (NULL, _("%s%s: not enough memory"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; break; } } if ((sargc > 6) && sargv[6][0] && (trigger_search_return_code (sargv[6]) < 0)) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid return code \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[6]); goto end; } ptr_trigger = trigger_search (sargv[0]); if (ptr_trigger) { if (weechat_strcasecmp (argv[1], "addreplace") == 0) { if (ptr_trigger) trigger_free (ptr_trigger); } else { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" already exists " "(choose another name or use option " "\"addreplace\" to overwrite it)"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[0]); goto end; } } ptr_trigger = trigger_alloc (sargv[0]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: failed to create trigger \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[0]); goto end; } ptr_trigger = trigger_new ( sargv[0], /* name */ (weechat_strcasecmp (argv[1], "addoff") == 0) ? "off" : "on", sargv[1], /* hook */ (sargc > 2) ? sargv[2] : "", /* arguments */ (sargc > 3) ? sargv[3] : "", /* conditions */ (sargc > 4) ? sargv[4] : "", /* regex */ (sargc > 5) ? sargv[5] : "", /* command */ (sargc > 6) ? sargv[6] : ""); /* return code */ if (ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("Trigger \"%s\" created"), sargv[0]); } else { weechat_printf_tags (NULL, "no_trigger", _("%s%s: failed to create trigger \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, sargv[0]); } goto end; } /* add trigger command in input (to help trigger creation) */ if (weechat_strcasecmp (argv[1], "addinput") == 0) { type = TRIGGER_HOOK_SIGNAL; if (argc >= 3) { type = trigger_search_hook_type (argv[2]); if (type < 0) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid hook type \"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } } items = weechat_string_split (trigger_hook_default_rc[type], ",", 0, 0, &num_items); snprintf (input, sizeof (input), "/trigger add name %s \"%s\" \"%s\" \"%s\" \"%s\"%s%s%s", trigger_hook_type_string[type], trigger_hook_default_arguments[type], TRIGGER_HOOK_DEFAULT_CONDITIONS, TRIGGER_HOOK_DEFAULT_REGEX, TRIGGER_HOOK_DEFAULT_COMMAND, (items && (num_items > 0)) ? " \"" : "", (items && (num_items > 0)) ? items[0] : "", (items && (num_items > 0)) ? "\"" : ""); weechat_buffer_set (buffer, "input", input); weechat_buffer_set (buffer, "input_pos", "13"); goto end; } /* * get command to create a trigger, and according to option: * - input: put the command in input * - output: send the command to the buffer * - recreate: same as input, but the trigger is first deleted */ if ((weechat_strcasecmp (argv[1], "input") == 0) || (weechat_strcasecmp (argv[1], "output") == 0) || (weechat_strcasecmp (argv[1], "recreate") == 0)) { if (argc < 3) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } add_rc = trigger_hook_default_rc[weechat_config_integer (ptr_trigger->options[TRIGGER_OPTION_HOOK])][0]; snprintf (input, sizeof (input), "//trigger %s %s %s \"%s\" \"%s\" \"%s\" \"%s\"%s%s%s", (weechat_strcasecmp (argv[1], "recreate") == 0) ? "addreplace" : "add", ptr_trigger->name, weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_HOOK]), weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_ARGUMENTS]), weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_CONDITIONS]), weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_REGEX]), weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_COMMAND]), (add_rc) ? " \"" : "", (add_rc) ? weechat_config_string (ptr_trigger->options[TRIGGER_OPTION_RETURN_CODE]) : "", (add_rc) ? "\"" : ""); if (weechat_strcasecmp (argv[1], "output") == 0) { weechat_command (buffer, input); } else { weechat_buffer_set (buffer, "input", input + 1); snprintf (str_pos, sizeof (str_pos), "%d", weechat_utf8_strlen (input + 1)); weechat_buffer_set (buffer, "input_pos", str_pos); } goto end; } /* set option in a trigger */ if (weechat_strcasecmp (argv[1], "set") == 0) { if (argc < 5) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } if (weechat_strcasecmp (argv[3], "name") == 0) { trigger_command_rename (ptr_trigger, argv[4]); goto end; } value = weechat_string_remove_quotes (argv_eol[4], "'\""); if (value) { index_option = trigger_search_option (argv[3]); if (index_option >= 0) { weechat_config_option_set (ptr_trigger->options[index_option], value, 1); weechat_printf_tags (NULL, "no_trigger", _("Trigger \"%s\" updated"), ptr_trigger->name); } else { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger option \"%s\" not " "found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[3]); } free (value); } goto end; } /* rename a trigger */ if (weechat_strcasecmp (argv[1], "rename") == 0) { if (argc < 4) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } trigger_command_rename (ptr_trigger, argv[3]); goto end; } /* copy a trigger */ if (weechat_strcasecmp (argv[1], "copy") == 0) { if (argc < 4) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } /* check that new name is valid */ if (!trigger_name_valid (argv[3])) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: invalid name for trigger"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); goto end; } /* check that no trigger already exists with the new name */ if (trigger_search (argv[3])) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" already " "exists"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[3]); goto end; } /* copy the trigger */ ptr_trigger2 = trigger_copy (ptr_trigger, argv[3]); if (ptr_trigger2) { weechat_printf_tags (NULL, "no_trigger", _("Trigger \"%s\" copied to \"%s\""), ptr_trigger->name, ptr_trigger2->name); } else { weechat_printf_tags (NULL, "no_trigger", _("%s%s: failed to copy trigger " "\"%s\""), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, ptr_trigger->name); } goto end; } /* enable/disable/toggle/restart trigger(s) */ if ((weechat_strcasecmp (argv[1], "enable") == 0) || (weechat_strcasecmp (argv[1], "disable") == 0) || (weechat_strcasecmp (argv[1], "toggle") == 0) || (weechat_strcasecmp (argv[1], "restart") == 0)) { if (argc < 3) { if (weechat_strcasecmp (argv[1], "restart") == 0) goto error; if (weechat_strcasecmp (argv[1], "enable") == 0) weechat_config_option_set (trigger_config_look_enabled, "1", 1); else if (weechat_strcasecmp (argv[1], "disable") == 0) weechat_config_option_set (trigger_config_look_enabled, "0", 1); else if (weechat_strcasecmp (argv[1], "toggle") == 0) { weechat_config_option_set (trigger_config_look_enabled, (trigger_enabled) ? "0" : "1", 1); } trigger_command_display_status (); goto end; } enable = -1; if (weechat_strcasecmp (argv[1], "enable") == 0) enable = 1; else if (weechat_strcasecmp (argv[1], "disable") == 0) enable = 0; else if (weechat_strcasecmp (argv[1], "restart") == 0) enable = 2; if (weechat_strcasecmp (argv[2], "-all") == 0) { for (ptr_trigger = triggers; ptr_trigger; ptr_trigger = ptr_trigger->next_trigger) { trigger_command_set_enabled (ptr_trigger, enable, 0); } } else { for (i = 2; i < argc; i++) { ptr_trigger = trigger_search (argv[i]); if (ptr_trigger) trigger_command_set_enabled (ptr_trigger, enable, 1); else { weechat_printf_tags (NULL, "no_trigger", _("%sTrigger \"%s\" not found"), weechat_prefix ("error"), argv[i]); } } } goto end; } /* delete trigger(s) */ if (weechat_strcasecmp (argv[1], "del") == 0) { if (argc < 3) goto error; if (weechat_strcasecmp (argv[2], "-all") == 0) { count = triggers_count; trigger_free_all (); if (count > 0) weechat_printf_tags (NULL, "no_trigger", _("%d triggers removed"), count); } else { for (i = 2; i < argc; i++) { ptr_trigger = trigger_search (argv[i]); if (ptr_trigger) { trigger_free (ptr_trigger); weechat_printf_tags (NULL, "no_trigger", _("Trigger \"%s\" removed"), argv[i]); } else { weechat_printf_tags (NULL, "no_trigger", _("%sTrigger \"%s\" not found"), weechat_prefix ("error"), argv[i]); } } } goto end; } /* show detailed info on a trigger */ if (weechat_strcasecmp (argv[1], "show") == 0) { if (argc < 3) goto error; ptr_trigger = trigger_search (argv[2]); if (!ptr_trigger) { weechat_printf_tags (NULL, "no_trigger", _("%s%s: trigger \"%s\" not found"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME, argv[2]); goto end; } weechat_printf_tags (NULL, "no_trigger", ""); weechat_printf_tags (NULL, "no_trigger", _("Trigger:")); trigger_command_display_trigger (ptr_trigger, 2); goto end; } /* restore default triggers */ if (weechat_strcasecmp (argv[1], "default") == 0) { if ((argc >= 3) && (weechat_strcasecmp (argv[2], "-yes") == 0)) { trigger_free_all (); trigger_create_default (); trigger_command_list (_("Default triggers restored:"), 0); } else { weechat_printf (NULL, _("%s%s: \"-yes\" argument is required for " "restoring default triggers (security reason)"), weechat_prefix ("error"), TRIGGER_PLUGIN_NAME); } goto end; } /* open the trigger monitor buffer */ if (weechat_strcasecmp (argv[1], "monitor") == 0) { trigger_buffer_open ((argc > 2) ? argv_eol[2] : NULL, 1); goto end; } error: rc = WEECHAT_RC_ERROR; end: if (sargv) weechat_string_free_split (sargv); return rc; }
int weechat_aspell_command_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *dicts; const char *default_dict; struct t_infolist *infolist; int number; /* make C compiler happy */ (void) data; if (argc == 1) { /* display aspell status */ weechat_printf (NULL, ""); weechat_printf (NULL, /* TRANSLATORS: second "%s" is "aspell" or "enchant" */ _("%s (using %s)"), (aspell_enabled) ? _("Spell checking is enabled") : _("Spell checking is disabled"), #ifdef USE_ENCHANT "enchant" #else "aspell" #endif ); default_dict = weechat_config_string (weechat_aspell_config_check_default_dict); weechat_printf (NULL, _("Default dictionary: %s"), (default_dict && default_dict[0]) ? default_dict : _("(not set)")); number = 0; infolist = weechat_infolist_get ("option", NULL, "aspell.dict.*"); if (infolist) { while (weechat_infolist_next (infolist)) { if (number == 0) weechat_printf (NULL, _("Specific dictionaries on buffers:")); number++; weechat_printf (NULL, " %s: %s", weechat_infolist_string (infolist, "option_name"), weechat_infolist_string (infolist, "value")); } weechat_infolist_free (infolist); } return WEECHAT_RC_OK; } /* enable aspell */ if (weechat_strcasecmp (argv[1], "enable") == 0) { weechat_config_option_set (weechat_aspell_config_check_enabled, "1", 1); weechat_printf (NULL, _("Aspell enabled")); return WEECHAT_RC_OK; } /* disable aspell */ if (weechat_strcasecmp (argv[1], "disable") == 0) { weechat_config_option_set (weechat_aspell_config_check_enabled, "0", 1); weechat_printf (NULL, _("Aspell disabled")); return WEECHAT_RC_OK; } /* toggle aspell */ if (weechat_strcasecmp (argv[1], "toggle") == 0) { if (aspell_enabled) { weechat_config_option_set (weechat_aspell_config_check_enabled, "0", 1); weechat_printf (NULL, _("Aspell disabled")); } else { weechat_config_option_set (weechat_aspell_config_check_enabled, "1", 1); weechat_printf (NULL, _("Aspell enabled")); } return WEECHAT_RC_OK; } /* list of dictionaries */ if (weechat_strcasecmp (argv[1], "listdict") == 0) { weechat_aspell_command_speller_list_dicts (); return WEECHAT_RC_OK; } /* set dictionary for current buffer */ if (weechat_strcasecmp (argv[1], "setdict") == 0) { if (argc < 3) return WEECHAT_RC_ERROR; dicts = weechat_string_replace (argv_eol[2], " ", ""); weechat_aspell_command_set_dict (buffer, (dicts) ? dicts : argv[2]); if (dicts) free (dicts); return WEECHAT_RC_OK; } /* delete dictionary used on current buffer */ if (weechat_strcasecmp (argv[1], "deldict") == 0) { weechat_aspell_command_set_dict (buffer, NULL); return WEECHAT_RC_OK; } /* add word to personal dictionary */ if (weechat_strcasecmp (argv[1], "addword") == 0) { if (argc < 3) return WEECHAT_RC_ERROR; if (argc > 3) { /* use a given dict */ weechat_aspell_command_add_word (buffer, argv[2], argv_eol[3]); } else { /* use default dict */ weechat_aspell_command_add_word (buffer, NULL, argv_eol[2]); } return WEECHAT_RC_OK; } return WEECHAT_RC_ERROR; }
int weechat_aspell_command_cb (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *dicts; const char *default_dict; struct t_infolist *infolist; int number; /* make C compiler happy */ (void) data; if (argc == 1) { /* display aspell status */ weechat_printf (NULL, ""); weechat_printf (NULL, "%s", (aspell_enabled) ? _("Aspell is enabled") : _("Aspell is disabled")); default_dict = weechat_config_string (weechat_aspell_config_check_default_dict); weechat_printf (NULL, _("Default dictionary: %s"), (default_dict && default_dict[0]) ? default_dict : _("(not set)")); number = 0; infolist = weechat_infolist_get ("option", NULL, "aspell.dict.*"); if (infolist) { while (weechat_infolist_next (infolist)) { if (number == 0) weechat_printf (NULL, _("Specific dictionaries on buffers:")); number++; weechat_printf (NULL, " %s: %s", weechat_infolist_string (infolist, "option_name"), weechat_infolist_string (infolist, "value")); } weechat_infolist_free (infolist); } return WEECHAT_RC_OK; } /* enable aspell */ if (weechat_strcasecmp (argv[1], "enable") == 0) { weechat_config_option_set (weechat_aspell_config_check_enabled, "1", 1); weechat_printf (NULL, _("Aspell enabled")); return WEECHAT_RC_OK; } /* disable aspell */ if (weechat_strcasecmp (argv[1], "disable") == 0) { weechat_config_option_set (weechat_aspell_config_check_enabled, "0", 1); weechat_printf (NULL, _("Aspell disabled")); return WEECHAT_RC_OK; } /* toggle aspell */ if (weechat_strcasecmp (argv[1], "toggle") == 0) { if (aspell_enabled) { weechat_config_option_set (weechat_aspell_config_check_enabled, "0", 1); weechat_printf (NULL, _("Aspell disabled")); } else { weechat_config_option_set (weechat_aspell_config_check_enabled, "1", 1); weechat_printf (NULL, _("Aspell enabled")); } return WEECHAT_RC_OK; } /* list of dictionaries */ if (weechat_strcasecmp (argv[1], "listdict") == 0) { weechat_aspell_speller_list_dicts (); return WEECHAT_RC_OK; } /* set dictionary for current buffer */ if (weechat_strcasecmp (argv[1], "setdict") == 0) { if (argc > 2) { dicts = weechat_string_replace (argv_eol[2], " ", ""); weechat_aspell_set_dict (buffer, (dicts) ? dicts : argv[2]); if (dicts) free (dicts); } return WEECHAT_RC_OK; } /* delete dictionary used on current buffer */ if (weechat_strcasecmp (argv[1], "deldict") == 0) { weechat_aspell_set_dict (buffer, NULL); return WEECHAT_RC_OK; } /* add word to personal dictionary */ if (weechat_strcasecmp (argv[1], "addword") == 0) { if (argc > 3) weechat_aspell_add_word (argv[2], argv_eol[3]); else { if (!weechat_aspell_spellers) { weechat_printf (NULL, _("%s%s: no dictionary on this buffer for " "adding word"), weechat_prefix ("error"), ASPELL_PLUGIN_NAME); } else if (weechat_aspell_spellers->next_speller) { weechat_printf (NULL, _("%s%s: many dictionaries are defined for " "this buffer, please specify dictionary"), weechat_prefix ("error"), ASPELL_PLUGIN_NAME); } else weechat_aspell_add_word (weechat_aspell_spellers->lang, argv_eol[2]); } return WEECHAT_RC_OK; } return WEECHAT_RC_ERROR; }