diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2017-06-28 19:59:45 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2017-06-28 19:59:45 +0200 |
commit | 987ef9e45485fac3de052ee81ef0678296bbd86c (patch) | |
tree | bfede195a27fda79d9bc6d617368e857a0f3648a /src/plugins | |
parent | f851246ff667a5ab9fb03675a368988028180f9c (diff) | |
download | weechat-987ef9e45485fac3de052ee81ef0678296bbd86c.zip |
fset: replace hashtable by a simple structure for max length of fields
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/fset/fset-buffer.c | 98 | ||||
-rw-r--r-- | src/plugins/fset/fset-command.c | 15 | ||||
-rw-r--r-- | src/plugins/fset/fset-option.c | 192 | ||||
-rw-r--r-- | src/plugins/fset/fset-option.h | 29 |
4 files changed, 193 insertions, 141 deletions
diff --git a/src/plugins/fset/fset-buffer.c b/src/plugins/fset/fset-buffer.c index f5ff012d6..a8ced404a 100644 --- a/src/plugins/fset/fset-buffer.c +++ b/src/plugins/fset/fset-buffer.c @@ -103,8 +103,7 @@ fset_buffer_set_title () } /* - * Fills a field with spaces (according to max length in hashtable - * "fset_option_max_length_field" for this field. + * Fills a field with spaces (according to max length for this field). * * If fill_right == 1, fills with spaces on the right. Otherwise * fills with spaces on the left before the value. @@ -112,24 +111,17 @@ fset_buffer_set_title () void fset_buffer_fills_field (char *field, char *field_spaces, int size, - const char *field_name, int default_max_length, - int fill_right) + int max_length, int fill_right) { - int length, length_screen, *ptr_length, num_spaces; + int length, length_screen, num_spaces; length = strlen (field); length_screen = weechat_strlen_screen (field); - ptr_length = (field_name) ? - (int *)weechat_hashtable_get (fset_option_max_length_field, field_name) : - NULL; - if (!ptr_length) - ptr_length = &default_max_length; + if (max_length > size - 1) + max_length = size - 1; - if (*ptr_length > size - 1) - *ptr_length = size - 1; - - num_spaces = *ptr_length - length_screen; + num_spaces = max_length - length_screen; if (num_spaces > 0) { if (length + num_spaces >= size) @@ -150,8 +142,8 @@ fset_buffer_fills_field (char *field, char *field_spaces, int size, } /* field with spaces */ - memset (field_spaces, ' ', *ptr_length); - field_spaces[*ptr_length] = '\0'; + memset (field_spaces, ' ', max_length); + field_spaces[max_length] = '\0'; } /* @@ -161,7 +153,8 @@ fset_buffer_fills_field (char *field, char *field_spaces, int size, void fset_buffer_display_option (struct t_fset_option *fset_option) { - char *line, str_color_line[128], *color_line, **lines, str_field[4096], str_field2[4096]; + char *line, str_color_line[128], *color_line, **lines; + char str_field[4096], str_field2[4096]; char str_color_value[128], str_color_quotes[128], str_number[64]; int selected_line, y, i, num_lines; int default_value_undef, value_undef, value_changed; @@ -194,7 +187,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->file) ? fset_option->file : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_file", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "file", 16, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->file, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "file", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -214,7 +208,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->section) ? fset_option->section : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_section", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "section", 16, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->section, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "section", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -234,7 +229,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->option) ? fset_option->option : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_option", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "option", 16, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->option, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "option", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -254,7 +250,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->name) ? fset_option->name : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_name", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "name", 64, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->name, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "name", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -270,7 +267,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->parent_name) ? fset_option->parent_name : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_parent_name", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "parent_name", 64, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->parent_name, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "parent_name", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -287,7 +285,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) _(fset_option_type_string[fset_option->type])); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_type", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "type", 8, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->type, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "type", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -304,7 +303,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) fset_option_type_string[fset_option->type]); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_type_en", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "type_en", 8, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->type_en, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "type_en", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -321,7 +321,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) fset_option_type_string_short[fset_option->type]); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_type_short", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "type_short", 4, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->type_short, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "type_short", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -338,7 +339,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) fset_option_type_string_tiny[fset_option->type]); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_type_tiny", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "type_tiny", 1, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->type_tiny, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "type_tiny", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -367,7 +369,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (add_quotes) ? "\"" : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_default_value", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "default_value", 16, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->default_value, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "default_value", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -435,7 +438,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (add_quotes) ? "\"" : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_value", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "value", 16, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->value, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "value", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -468,7 +472,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (add_quotes_parent) ? "\"" : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_value2", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "value2", 32, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->value2, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "value2", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -491,7 +496,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (add_quotes) ? "\"" : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_value2", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "value2", 32, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->value2, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "value2", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -517,7 +523,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (add_quotes_parent) ? "\"" : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_parent_value", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "parent_value", 16, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->parent_value, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "parent_value", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -530,7 +537,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) "__parent_value", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_parent_value", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "parent_value", 16, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->parent_value, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "parent_value", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -547,7 +555,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->min) ? fset_option->min : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_min", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "min", 8, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->min, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "min", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -563,7 +572,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->max) ? fset_option->max : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_max", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "max", 8, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->max, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "max", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -580,7 +590,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->description && fset_option->description[0]) ? _(fset_option->description) : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_description", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "description", 64, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->description, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "description", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -597,7 +608,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->description && fset_option->description[0]) ? _(fset_option->description) : _("(no description)")); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_description2", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "description2", 64, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->description2, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "description2", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -613,7 +625,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->description) ? fset_option->description : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_description_en", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "description_en", 64, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->description_en, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "description_en", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -630,7 +643,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->description && fset_option->description[0]) ? fset_option->description : "(no description)"); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_description_en2", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "description_en2", 64, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->description_en2, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "description_en2", str_field); @@ -644,7 +658,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) (fset_option->string_values) ? fset_option->string_values : ""); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_string_values", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "string_values", 32, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->string_values, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "string_values", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -668,7 +683,8 @@ fset_buffer_display_option (struct t_fset_option *fset_option) weechat_config_string (fset_config_look_unmarked_string)); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "_marked", str_field); - fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), "marked", 2, 1); + fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), + fset_option_max_length->marked, 1); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "marked", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, @@ -687,7 +703,7 @@ fset_buffer_display_option (struct t_fset_option *fset_option) snprintf (str_number, sizeof (str_number), "%d", weechat_arraylist_size (fset_options)); fset_buffer_fills_field (str_field, str_field2, sizeof (str_field), - NULL, strlen (str_number), 0); + strlen (str_number), 0); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, "index", str_field); weechat_hashtable_set (fset_buffer_hashtable_extra_vars, diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c index 8cc72e6f9..ee2fef084 100644 --- a/src/plugins/fset/fset-command.c +++ b/src/plugins/fset/fset-command.c @@ -459,7 +459,8 @@ fset_command_run_set_cb (const void *pointer, void *data, const char *ptr_condition; int rc, argc, old_count_marked, old_buffer_selected_line, condition_ok; struct t_arraylist *old_options; - struct t_hashtable *old_max_length_field, *eval_extra_vars, *eval_options; + struct t_fset_option_max_length *old_max_length; + struct t_hashtable *eval_extra_vars, *eval_options; /* make C compiler happy */ (void) pointer; @@ -495,8 +496,8 @@ fset_command_run_set_cb (const void *pointer, void *data, old_options = fset_options; fset_options = fset_option_get_arraylist_options (); old_count_marked = fset_option_count_marked; - old_max_length_field = fset_option_max_length_field; - fset_option_max_length_field = fset_option_get_hashtable_max_length_field (); + old_max_length = fset_option_max_length; + fset_option_max_length = fset_option_get_max_length (); old_filter = (fset_option_filter) ? strdup (fset_option_filter) : NULL; fset_option_set_filter ((argc > 1) ? argv[1] : NULL); old_buffer_selected_line = fset_buffer_selected_line; @@ -543,8 +544,8 @@ fset_command_run_set_cb (const void *pointer, void *data, { if (old_options) weechat_arraylist_free (old_options); - if (old_max_length_field) - weechat_hashtable_free (old_max_length_field); + if (old_max_length) + free (old_max_length); if (old_filter) free (old_filter); @@ -562,8 +563,8 @@ fset_command_run_set_cb (const void *pointer, void *data, weechat_arraylist_free (fset_options); fset_options = old_options; fset_option_count_marked = old_count_marked; - weechat_hashtable_free (fset_option_max_length_field); - fset_option_max_length_field = old_max_length_field; + free (fset_option_max_length); + fset_option_max_length = old_max_length; fset_option_set_filter (old_filter); if (old_filter) free (old_filter); diff --git a/src/plugins/fset/fset-option.c b/src/plugins/fset/fset-option.c index f6d4deafd..b95a62415 100644 --- a/src/plugins/fset/fset-option.c +++ b/src/plugins/fset/fset-option.c @@ -34,7 +34,7 @@ /* options */ struct t_arraylist *fset_options = NULL; int fset_option_count_marked = 0; -struct t_hashtable *fset_option_max_length_field = NULL; +struct t_fset_option_max_length *fset_option_max_length = NULL; /* filters */ char *fset_option_filter = NULL; @@ -564,20 +564,6 @@ fset_option_set_values (struct t_fset_option *fset_option, } /* - * Sets max length for a field in hashtable "fset_option_max_length_field". - */ - -void -fset_option_set_max_length_field (const char *field, int length) -{ - int *value; - - value = weechat_hashtable_get (fset_option_max_length_field, field); - if (!value || (length > *value)) - weechat_hashtable_set (fset_option_max_length_field, field, &length); -} - -/* * Sets max length for fields, for one option. */ @@ -587,45 +573,50 @@ fset_option_set_max_length_fields_option (struct t_fset_option *fset_option) int length, length_value, length_parent_value; /* file */ - fset_option_set_max_length_field ( - "file", weechat_strlen_screen (fset_option->file)); + length = weechat_strlen_screen (fset_option->file); + if (length > fset_option_max_length->file) + fset_option_max_length->file = length; /* section */ - fset_option_set_max_length_field ( - "section", weechat_strlen_screen (fset_option->section)); + length = weechat_strlen_screen (fset_option->section); + if (length > fset_option_max_length->section) + fset_option_max_length->section = length; /* option */ - fset_option_set_max_length_field ( - "option", weechat_strlen_screen (fset_option->option)); + length = weechat_strlen_screen (fset_option->option); + if (length > fset_option_max_length->option) + fset_option_max_length->option = length; /* name */ - fset_option_set_max_length_field ( - "name", weechat_strlen_screen (fset_option->name)); + length = weechat_strlen_screen (fset_option->name); + if (length > fset_option_max_length->name) + fset_option_max_length->name = length; /* parent_name */ - fset_option_set_max_length_field ( - "parent_name", - (fset_option->parent_name) ? weechat_strlen_screen (fset_option->parent_name) : 0); + length = (fset_option->parent_name) ? + weechat_strlen_screen (fset_option->name) : 0; + if (length > fset_option_max_length->parent_name) + fset_option_max_length->parent_name = length; /* type */ - fset_option_set_max_length_field ( - "type", - weechat_strlen_screen (_(fset_option_type_string[fset_option->type]))); + length = weechat_strlen_screen (_(fset_option_type_string[fset_option->type])); + if (length > fset_option_max_length->type) + fset_option_max_length->type = length; /* type_en */ - fset_option_set_max_length_field ( - "type_en", - weechat_strlen_screen (fset_option_type_string[fset_option->type])); + length = weechat_strlen_screen (fset_option_type_string[fset_option->type]); + if (length > fset_option_max_length->type_en) + fset_option_max_length->type_en = length; /* type_short */ - fset_option_set_max_length_field ( - "type_short", - weechat_strlen_screen (fset_option_type_string_short[fset_option->type])); + length = weechat_strlen_screen (fset_option_type_string_short[fset_option->type]); + if (length > fset_option_max_length->type_short) + fset_option_max_length->type_short = length; /* type_tiny */ - fset_option_set_max_length_field ( - "type_tiny", - weechat_strlen_screen (fset_option_type_string_tiny[fset_option->type])); + length = weechat_strlen_screen (fset_option_type_string_tiny[fset_option->type]); + if (length > fset_option_max_length->type_tiny) + fset_option_max_length->type_tiny = length; /* default_value */ if (fset_option->default_value) @@ -638,7 +629,8 @@ fset_option_set_max_length_fields_option (struct t_fset_option *fset_option) { length = weechat_strlen_screen (FSET_OPTION_VALUE_NULL); } - fset_option_set_max_length_field ("default_value", length); + if (length > fset_option_max_length->default_value) + fset_option_max_length->default_value = length; /* value */ if (fset_option->value) @@ -651,7 +643,8 @@ fset_option_set_max_length_fields_option (struct t_fset_option *fset_option) { length_value = weechat_strlen_screen (FSET_OPTION_VALUE_NULL); } - fset_option_set_max_length_field ("value", length_value); + if (length_value > fset_option_max_length->value) + fset_option_max_length->value = length_value; /* parent_value */ if (fset_option->parent_value) @@ -664,60 +657,73 @@ fset_option_set_max_length_fields_option (struct t_fset_option *fset_option) { length_parent_value = weechat_strlen_screen (FSET_OPTION_VALUE_NULL); } - fset_option_set_max_length_field ("parent_value", length_parent_value); + if (length_parent_value > fset_option_max_length->parent_value) + fset_option_max_length->parent_value = length_parent_value; /* value2 */ length = length_value; if (!fset_option->value) length += 4 + length_parent_value; - fset_option_set_max_length_field ("value2", length); + if (length > fset_option_max_length->value2) + fset_option_max_length->value2 = length; /* min */ - fset_option_set_max_length_field ( - "min", weechat_strlen_screen (fset_option->min)); + length = weechat_strlen_screen (fset_option->min); + if (length > fset_option_max_length->min) + fset_option_max_length->min = length; /* max */ - fset_option_set_max_length_field ( - "max", weechat_strlen_screen (fset_option->max)); + length = weechat_strlen_screen (fset_option->max); + if (length > fset_option_max_length->max) + fset_option_max_length->max = length; /* description */ - fset_option_set_max_length_field ( - "description", - weechat_strlen_screen ( - (fset_option->description && fset_option->description[0]) ? - _(fset_option->description) : "")); + length = (fset_option->description && fset_option->description[0]) ? + weechat_strlen_screen (_(fset_option->description)) : 0; + if (length > fset_option_max_length->description) + fset_option_max_length->description = length; /* description2 */ - fset_option_set_max_length_field ( - "description2", - weechat_strlen_screen ( - (fset_option->description && fset_option->description[0]) ? - _(fset_option->description) : _("(no description)"))); + length = weechat_strlen_screen ( + (fset_option->description && fset_option->description[0]) ? + _(fset_option->description) : _("(no description)")); + if (length > fset_option_max_length->description2) + fset_option_max_length->description2 = length; /* description_en */ - fset_option_set_max_length_field ( - "description_en", weechat_strlen_screen (fset_option->description)); + length = weechat_strlen_screen (fset_option->description); + if (length > fset_option_max_length->description_en) + fset_option_max_length->description_en = length; /* description_en2 */ - fset_option_set_max_length_field ( - "description_en2", - weechat_strlen_screen ( - (fset_option->description && fset_option->description[0]) ? - fset_option->description : "(no description)")); + length = weechat_strlen_screen ( + (fset_option->description && fset_option->description[0]) ? + fset_option->description : _("(no description)")); + if (length > fset_option_max_length->description_en2) + fset_option_max_length->description_en2 = length; /* string_values */ - fset_option_set_max_length_field ( - "string_values", weechat_strlen_screen (fset_option->string_values)); + length = weechat_strlen_screen (fset_option->string_values); + if (length > fset_option_max_length->string_values) + fset_option_max_length->string_values = length; /* marked */ - fset_option_set_max_length_field ( - "marked", - weechat_strlen_screen ( - weechat_config_string (fset_config_look_marked_string))); - fset_option_set_max_length_field ( - "marked", - weechat_strlen_screen ( - weechat_config_string (fset_config_look_unmarked_string))); + length = weechat_strlen_screen (weechat_config_string (fset_config_look_marked_string)); + if (length > fset_option_max_length->marked) + fset_option_max_length->marked = length; + length = weechat_strlen_screen (weechat_config_string (fset_config_look_unmarked_string)); + if (length > fset_option_max_length->marked) + fset_option_max_length->marked = length; +} + +/* + * Initializes max length for fields. + */ + +void +fset_option_init_max_length (struct t_fset_option_max_length *max_length) +{ + memset (max_length, 0, sizeof (*max_length)); } /* @@ -731,7 +737,7 @@ fset_option_set_max_length_fields_all () struct t_fset_option *ptr_fset_option; /* first clear all max lengths */ - weechat_hashtable_remove_all (fset_option_max_length_field); + fset_option_init_max_length (fset_option_max_length); /* set max length for fields, for all options */ num_options = weechat_arraylist_size (fset_options); @@ -917,7 +923,7 @@ fset_option_free_cb (void *data, struct t_arraylist *arraylist, void *pointer) } /* - * Gets the arraylist to store options. + * Allocates and returns the arraylist to store options. */ struct t_arraylist * @@ -929,16 +935,19 @@ fset_option_get_arraylist_options () } /* - * Gets the hashtable to store max length of fields. + * Allocates and returns the structure to store max length of fields. */ -struct t_hashtable * -fset_option_get_hashtable_max_length_field () +struct t_fset_option_max_length * +fset_option_get_max_length () { - return weechat_hashtable_new (128, - WEECHAT_HASHTABLE_STRING, - WEECHAT_HASHTABLE_INTEGER, - NULL, NULL); + struct t_fset_option_max_length *max_length; + + max_length = malloc (sizeof (*fset_option_max_length)); + if (max_length) + fset_option_init_max_length (max_length); + + return max_length; } /* @@ -978,7 +987,7 @@ fset_option_get_options () /* clear options */ weechat_arraylist_clear (fset_options); fset_option_count_marked = 0; - weechat_hashtable_remove_all (fset_option_max_length_field); + fset_option_init_max_length (fset_option_max_length); /* get options */ ptr_config = weechat_hdata_get_list (fset_hdata_config_file, @@ -1714,8 +1723,9 @@ fset_option_init () if (!fset_options) return 0; fset_option_count_marked = 0; - fset_option_max_length_field = fset_option_get_hashtable_max_length_field (); - if (!fset_option_max_length_field) + + fset_option_max_length = fset_option_get_max_length (); + if (!fset_option_max_length) { weechat_arraylist_free (fset_options); return 0; @@ -1729,7 +1739,7 @@ fset_option_init () if (!fset_option_filter_hashtable_pointers) { weechat_arraylist_free (fset_options); - weechat_hashtable_free (fset_option_max_length_field); + free (fset_option_max_length); return 0; } fset_option_filter_hashtable_extra_vars = weechat_hashtable_new ( @@ -1740,7 +1750,7 @@ fset_option_init () if (!fset_option_filter_hashtable_extra_vars) { weechat_arraylist_free (fset_options); - weechat_hashtable_free (fset_option_max_length_field); + free (fset_option_max_length); weechat_hashtable_free (fset_option_filter_hashtable_pointers); return 0; } @@ -1752,7 +1762,7 @@ fset_option_init () if (!fset_option_filter_hashtable_options) { weechat_arraylist_free (fset_options); - weechat_hashtable_free (fset_option_max_length_field); + free (fset_option_max_length); weechat_hashtable_free (fset_option_filter_hashtable_pointers); weechat_hashtable_free (fset_option_filter_hashtable_extra_vars); return 0; @@ -1776,10 +1786,10 @@ fset_option_end () fset_options = NULL; } fset_option_count_marked = 0; - if (fset_option_max_length_field) + if (fset_option_max_length) { - weechat_hashtable_free (fset_option_max_length_field); - fset_option_max_length_field = NULL; + free (fset_option_max_length); + fset_option_max_length = NULL; } if (fset_option_filter) { diff --git a/src/plugins/fset/fset-option.h b/src/plugins/fset/fset-option.h index 438d89340..6ac4f3c40 100644 --- a/src/plugins/fset/fset-option.h +++ b/src/plugins/fset/fset-option.h @@ -53,9 +53,34 @@ struct t_fset_option struct t_fset_option *next_option; /* link to next option */ }; +struct t_fset_option_max_length +{ + int file; + int section; + int option; + int name; + int parent_name; + int type; + int type_en; + int type_short; + int type_tiny; + int default_value; + int value; + int parent_value; + int value2; + int min; + int max; + int description; + int description2; + int description_en; + int description_en2; + int string_values; + int marked; +}; + extern struct t_arraylist *fset_options; extern int fset_option_count_marked; -extern struct t_hashtable *fset_option_max_length_field; +extern struct t_fset_option_max_length *fset_option_max_length; extern char *fset_option_filter; extern char *fset_option_type_string[]; extern char *fset_option_type_string_short[]; @@ -68,7 +93,7 @@ extern int fset_option_value_is_changed (struct t_fset_option *option); extern void fset_option_set_max_length_fields_all (); extern void fset_option_free (struct t_fset_option *fset_option); extern struct t_arraylist *fset_option_get_arraylist_options (); -extern struct t_hashtable *fset_option_get_hashtable_max_length_field (); +extern struct t_fset_option_max_length *fset_option_get_max_length (); extern void fset_option_get_options (); extern void fset_option_set_filter (const char *filter); extern void fset_option_filter_options (const char *filter); |