struct t_trigger * trigger_new (const char *name, const char *enabled, const char *hook, const char *arguments, const char *conditions, const char *regex, const char *command, const char *return_code, const char *post_action) { struct t_config_option *option[TRIGGER_NUM_OPTIONS]; const char *value[TRIGGER_NUM_OPTIONS]; struct t_trigger *new_trigger; int i; /* look for type */ if (trigger_search_hook_type (hook) < 0) return NULL; /* look for return code */ if (return_code && return_code[0] && (trigger_search_return_code (return_code) < 0)) { return NULL; } /* look for post action */ if (post_action && post_action[0] && (trigger_search_post_action (post_action) < 0)) { return NULL; } value[TRIGGER_OPTION_ENABLED] = enabled; value[TRIGGER_OPTION_HOOK] = hook; value[TRIGGER_OPTION_ARGUMENTS] = arguments; value[TRIGGER_OPTION_CONDITIONS] = conditions; value[TRIGGER_OPTION_REGEX] = regex; value[TRIGGER_OPTION_COMMAND] = command; value[TRIGGER_OPTION_RETURN_CODE] = return_code; value[TRIGGER_OPTION_POST_ACTION] = post_action; for (i = 0; i < TRIGGER_NUM_OPTIONS; i++) { option[i] = trigger_config_create_trigger_option (name, i, value[i]); } new_trigger = trigger_new_with_options (name, option); if (!new_trigger) { for (i = 0; i < TRIGGER_NUM_OPTIONS; i++) { weechat_config_option_free (option[i]); } } return new_trigger; }
void trigger_config_use_temp_triggers () { struct t_trigger *ptr_temp_trigger, *next_temp_trigger; int i, num_options_ok; for (ptr_temp_trigger = triggers_temp; ptr_temp_trigger; ptr_temp_trigger = ptr_temp_trigger->next_trigger) { num_options_ok = 0; for (i = 0; i < TRIGGER_NUM_OPTIONS; i++) { if (!ptr_temp_trigger->options[i]) { ptr_temp_trigger->options[i] = trigger_config_create_trigger_option (ptr_temp_trigger->name, i, trigger_option_default[i]); } if (ptr_temp_trigger->options[i]) num_options_ok++; } if (num_options_ok == TRIGGER_NUM_OPTIONS) { trigger_new_with_options (ptr_temp_trigger->name, ptr_temp_trigger->options); } else { for (i = 0; i < TRIGGER_NUM_OPTIONS; i++) { if (ptr_temp_trigger->options[i]) { weechat_config_option_free (ptr_temp_trigger->options[i]); ptr_temp_trigger->options[i] = NULL; } } } } /* free all temporary triggers */ while (triggers_temp) { next_temp_trigger = triggers_temp->next_trigger; if (triggers_temp->name) free (triggers_temp->name); free (triggers_temp); triggers_temp = next_temp_trigger; } last_trigger_temp = NULL; }