diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-05-29 21:11:23 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-06-25 16:35:27 +0200 |
commit | 7b5b123365855c8a51132a558b1bd9bb7fa09307 (patch) | |
tree | b735ca6b7b4389f7052358e0147d435cd0d64a02 | |
parent | fb363eb7232ef1cfef31ebaf1d19e3fc89634b37 (diff) | |
download | weechat-7b5b123365855c8a51132a558b1bd9bb7fa09307.zip |
fset: add different types of filters
Existing filter:
- by option name (part of name)
New filters:
- by configuration file ("f:xxx")
- by section name ("s:xxx")
- by options changed ("d:" or "d:xxx")
- by exact value ("==xxx")
- by value, format ("=xxx")
-rw-r--r-- | src/plugins/fset/fset-option.c | 107 | ||||
-rw-r--r-- | src/plugins/fset/fset-option.h | 1 |
2 files changed, 83 insertions, 25 deletions
diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c index ddf3546be..72d238a26 100644 --- a/src/plugins/fset/fset-option.c +++ b/src/plugins/fset/fset-option.c @@ -183,15 +183,53 @@ fset_option_set_value_string (struct t_config_option *option, */ int -fset_option_match_filters (const char *option_name) +fset_option_match_filters (const char *config_name, const char *section_name, + struct t_fset_option *fset_option) { - if (fset_option_filter - && !weechat_strcasestr (option_name, fset_option_filter)) + if (!fset_option_filter || !fset_option_filter[0]) + return 1; + + if (strncmp (fset_option_filter, "f:", 2) == 0) { - return 0; + /* filter by config name */ + return (weechat_strcasecmp (config_name, fset_option_filter + 2) == 0) ? 1 : 0; + } + else if (strncmp (fset_option_filter, "s:", 2) == 0) + { + /* filter by section name */ + return (weechat_strcasecmp (section_name, fset_option_filter + 2) == 0) ? 1 : 0; + } + else if (strncmp (fset_option_filter, "d:", 2) == 0) + { + /* filter by modified values */ + if (!fset_option_value_different_from_default (fset_option)) + return 0; + if (fset_option_filter[2] + && !weechat_strcasestr (fset_option->name, fset_option_filter + 2)) + { + return 0; + } + return 1; + } + else if (strncmp (fset_option_filter, "==", 2) == 0) + { + /* filter by exact value */ + return (weechat_strcasecmp ( + (fset_option->value) ? fset_option->value : FSET_OPTION_VALUE_NULL, + fset_option_filter + 2) == 0) ? 1 : 0; + } + else if (fset_option_filter[0] == '=') + { + /* filter by value */ + return (weechat_strcasestr ( + (fset_option->value) ? fset_option->value : FSET_OPTION_VALUE_NULL, + fset_option_filter + 1)) ? 1 : 0; + } + else + { + /* filter by option name */ + return (weechat_strcasestr (fset_option->name, fset_option_filter)) ? 1 : 0; } - - return 1; } /* @@ -415,12 +453,6 @@ fset_option_alloc (struct t_config_file *config_file, ptr_section_name, ptr_option_name); - if (!fset_option_match_filters (option_name)) - { - /* option does not match filters, ignore it */ - goto end; - } - new_fset_option = malloc (sizeof (*new_fset_option)); if (new_fset_option) { @@ -431,15 +463,22 @@ fset_option_alloc (struct t_config_file *config_file, new_fset_option->value = NULL; new_fset_option->parent_value = NULL; fset_option_set_values (new_fset_option, option); + if (!fset_option_match_filters (ptr_config_name, ptr_section_name, + new_fset_option)) + { + /* option does not match filters, ignore it */ + fset_option_free (new_fset_option); + new_fset_option = NULL; + goto end; + } fset_option_set_max_length_fields_option (new_fset_option); } - -end: - if (!new_fset_option) + else { - if (option_name) - free (option_name); + free (option_name); } + +end: return new_fset_option; } @@ -526,15 +565,10 @@ fset_option_compare_options_cb (void *data, struct t_arraylist *arraylist, */ void -fset_option_free_cb (void *data, struct t_arraylist *arraylist, void *pointer) +fset_option_free (struct t_fset_option *fset_option) { - struct t_fset_option *fset_option; - - /* make C compiler happy */ - (void) data; - (void) arraylist; - - fset_option = (struct t_fset_option *)pointer; + if (!fset_option) + return; if (fset_option->name) free (fset_option->name); @@ -552,6 +586,24 @@ fset_option_free_cb (void *data, struct t_arraylist *arraylist, void *pointer) free (fset_option); } +/* + * Frees an fset option (arraylist callback). + */ + +void +fset_option_free_cb (void *data, struct t_arraylist *arraylist, void *pointer) +{ + struct t_fset_option *fset_option; + + /* make C compiler happy */ + (void) data; + (void) arraylist; + + fset_option = (struct t_fset_option *)pointer; + + fset_option_free (fset_option); +} + /* * Gets all options to display in fset buffer. @@ -837,4 +889,9 @@ fset_option_end () weechat_hashtable_free (fset_option_max_length_field); fset_option_max_length_field = NULL; } + if (fset_option_filter) + { + free (fset_option_filter); + fset_option_filter = NULL; + } } diff --git a/src/plugins/fset/fset-option.h b/src/plugins/fset/fset-option.h index 93d581470..9b4421de1 100644 --- a/src/plugins/fset/fset-option.h +++ b/src/plugins/fset/fset-option.h @@ -43,6 +43,7 @@ extern struct t_fset_option *fset_option_search_by_name (const char *name, int *line); extern int fset_option_value_different_from_default (struct t_fset_option *option); extern void fset_option_set_filter (const char *filter); +extern void fset_option_free (struct t_fset_option *fset_option); extern void fset_option_get_options (); extern void fset_option_filter_options (const char *search); extern int fset_option_config_cb (const void *pointer, |