/src/core/wee-config.c
C | 1925 lines | 1417 code | 247 blank | 261 comment | 161 complexity | 5a998593537af7767ebc0b1b3a945f50 MD5 | raw file
Possible License(s): GPL-3.0
Large files files are truncated, but you can click here to view the full file
- /*
- * Copyright (C) 2003-2012 Sebastien Helleu <flashcode@flashtux.org>
- * Copyright (C) 2005-2006 Emmanuel Bouthenot <kolter@openics.org>
- *
- * This file is part of WeeChat, the extensible chat client.
- *
- * WeeChat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * WeeChat is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
- */
- /*
- * wee-config.c: WeeChat configuration options (file weechat.conf)
- */
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include <stdlib.h>
- #include <unistd.h>
- #include <errno.h>
- #include <stdio.h>
- #include <string.h>
- #include <limits.h>
- #include <time.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <regex.h>
- #include "weechat.h"
- #include "wee-config.h"
- #include "wee-hook.h"
- #include "wee-log.h"
- #include "wee-network.h"
- #include "wee-utf8.h"
- #include "wee-util.h"
- #include "wee-list.h"
- #include "wee-proxy.h"
- #include "wee-string.h"
- #include "../gui/gui-bar.h"
- #include "../gui/gui-buffer.h"
- #include "../gui/gui-chat.h"
- #include "../gui/gui-color.h"
- #include "../gui/gui-filter.h"
- #include "../gui/gui-hotlist.h"
- #include "../gui/gui-key.h"
- #include "../gui/gui-layout.h"
- #include "../gui/gui-line.h"
- #include "../gui/gui-main.h"
- #include "../gui/gui-mouse.h"
- #include "../gui/gui-nicklist.h"
- #include "../gui/gui-window.h"
- #include "../plugins/plugin.h"
- struct t_config_file *weechat_config_file = NULL;
- struct t_config_section *weechat_config_section_debug = NULL;
- struct t_config_section *weechat_config_section_color = NULL;
- struct t_config_section *weechat_config_section_proxy = NULL;
- struct t_config_section *weechat_config_section_bar = NULL;
- struct t_config_section *weechat_config_section_notify = NULL;
- /* config, startup section */
- struct t_config_option *config_startup_command_after_plugins;
- struct t_config_option *config_startup_command_before_plugins;
- struct t_config_option *config_startup_display_logo;
- struct t_config_option *config_startup_display_version;
- /* config, look & feel section */
- struct t_config_option *config_look_align_end_of_lines;
- struct t_config_option *config_look_bar_more_left;
- struct t_config_option *config_look_bar_more_right;
- struct t_config_option *config_look_bar_more_up;
- struct t_config_option *config_look_bar_more_down;
- struct t_config_option *config_look_buffer_notify_default;
- struct t_config_option *config_look_buffer_time_format;
- struct t_config_option *config_look_color_basic_force_bold;
- struct t_config_option *config_look_color_inactive_window;
- struct t_config_option *config_look_color_inactive_buffer;
- struct t_config_option *config_look_color_inactive_time;
- struct t_config_option *config_look_color_inactive_prefix_buffer;
- struct t_config_option *config_look_color_inactive_prefix;
- struct t_config_option *config_look_color_inactive_message;
- struct t_config_option *config_look_color_pairs_auto_reset;
- struct t_config_option *config_look_color_real_white;
- struct t_config_option *config_look_command_chars;
- struct t_config_option *config_look_confirm_quit;
- struct t_config_option *config_look_day_change;
- struct t_config_option *config_look_day_change_time_format;
- struct t_config_option *config_look_eat_newline_glitch;
- struct t_config_option *config_look_highlight;
- struct t_config_option *config_look_highlight_regex;
- struct t_config_option *config_look_highlight_tags;
- struct t_config_option *config_look_hotlist_add_buffer_if_away;
- struct t_config_option *config_look_hotlist_buffer_separator;
- struct t_config_option *config_look_hotlist_count_max;
- struct t_config_option *config_look_hotlist_count_min_msg;
- struct t_config_option *config_look_hotlist_names_count;
- struct t_config_option *config_look_hotlist_names_length;
- struct t_config_option *config_look_hotlist_names_level;
- struct t_config_option *config_look_hotlist_names_merged_buffers;
- struct t_config_option *config_look_hotlist_short_names;
- struct t_config_option *config_look_hotlist_sort;
- struct t_config_option *config_look_hotlist_unique_numbers;
- struct t_config_option *config_look_input_cursor_scroll;
- struct t_config_option *config_look_input_share;
- struct t_config_option *config_look_input_share_overwrite;
- struct t_config_option *config_look_input_undo_max;
- struct t_config_option *config_look_item_time_format;
- struct t_config_option *config_look_item_buffer_filter;
- struct t_config_option *config_look_jump_current_to_previous_buffer;
- struct t_config_option *config_look_jump_previous_buffer_when_closing;
- struct t_config_option *config_look_mouse;
- struct t_config_option *config_look_mouse_timer_delay;
- struct t_config_option *config_look_nickmode;
- struct t_config_option *config_look_nickmode_empty;
- struct t_config_option *config_look_paste_bracketed;
- struct t_config_option *config_look_paste_bracketed_timer_delay;
- struct t_config_option *config_look_paste_max_lines;
- struct t_config_option *config_look_prefix[GUI_CHAT_NUM_PREFIXES];
- struct t_config_option *config_look_prefix_align;
- struct t_config_option *config_look_prefix_align_max;
- struct t_config_option *config_look_prefix_align_min;
- struct t_config_option *config_look_prefix_align_more;
- struct t_config_option *config_look_prefix_buffer_align;
- struct t_config_option *config_look_prefix_buffer_align_max;
- struct t_config_option *config_look_prefix_buffer_align_more;
- struct t_config_option *config_look_prefix_same_nick;
- struct t_config_option *config_look_prefix_suffix;
- struct t_config_option *config_look_read_marker;
- struct t_config_option *config_look_read_marker_always_show;
- struct t_config_option *config_look_read_marker_string;
- struct t_config_option *config_look_save_config_on_exit;
- struct t_config_option *config_look_save_layout_on_exit;
- struct t_config_option *config_look_scroll_amount;
- struct t_config_option *config_look_scroll_bottom_after_switch;
- struct t_config_option *config_look_scroll_page_percent;
- struct t_config_option *config_look_search_text_not_found_alert;
- struct t_config_option *config_look_separator_horizontal;
- struct t_config_option *config_look_separator_vertical;
- struct t_config_option *config_look_set_title;
- struct t_config_option *config_look_time_format;
- /* config, colors section */
- struct t_config_option *config_color_separator;
- struct t_config_option *config_color_bar_more;
- struct t_config_option *config_color_chat;
- struct t_config_option *config_color_chat_bg;
- struct t_config_option *config_color_chat_inactive_window;
- struct t_config_option *config_color_chat_inactive_buffer;
- struct t_config_option *config_color_chat_time;
- struct t_config_option *config_color_chat_time_delimiters;
- struct t_config_option *config_color_chat_prefix_buffer;
- struct t_config_option *config_color_chat_prefix_buffer_inactive_buffer;
- struct t_config_option *config_color_chat_prefix[GUI_CHAT_NUM_PREFIXES];
- struct t_config_option *config_color_chat_prefix_more;
- struct t_config_option *config_color_chat_prefix_suffix;
- struct t_config_option *config_color_chat_buffer;
- struct t_config_option *config_color_chat_server;
- struct t_config_option *config_color_chat_channel;
- struct t_config_option *config_color_chat_nick;
- struct t_config_option *config_color_chat_nick_colors;
- struct t_config_option *config_color_chat_nick_self;
- struct t_config_option *config_color_chat_nick_other;
- struct t_config_option *config_color_chat_host;
- struct t_config_option *config_color_chat_delimiters;
- struct t_config_option *config_color_chat_highlight;
- struct t_config_option *config_color_chat_highlight_bg;
- struct t_config_option *config_color_chat_read_marker;
- struct t_config_option *config_color_chat_read_marker_bg;
- struct t_config_option *config_color_chat_tags;
- struct t_config_option *config_color_chat_text_found;
- struct t_config_option *config_color_chat_text_found_bg;
- struct t_config_option *config_color_chat_value;
- struct t_config_option *config_color_status_number;
- struct t_config_option *config_color_status_name;
- struct t_config_option *config_color_status_name_ssl;
- struct t_config_option *config_color_status_filter;
- struct t_config_option *config_color_status_data_msg;
- struct t_config_option *config_color_status_data_private;
- struct t_config_option *config_color_status_data_highlight;
- struct t_config_option *config_color_status_data_other;
- struct t_config_option *config_color_status_count_msg;
- struct t_config_option *config_color_status_count_private;
- struct t_config_option *config_color_status_count_highlight;
- struct t_config_option *config_color_status_count_other;
- struct t_config_option *config_color_status_more;
- struct t_config_option *config_color_status_time;
- struct t_config_option *config_color_input_text_not_found;
- struct t_config_option *config_color_input_actions;
- struct t_config_option *config_color_nicklist_group;
- struct t_config_option *config_color_nicklist_away;
- struct t_config_option *config_color_nicklist_offline;
- /* config, completion section */
- struct t_config_option *config_completion_base_word_until_cursor;
- struct t_config_option *config_completion_default_template;
- struct t_config_option *config_completion_nick_add_space;
- struct t_config_option *config_completion_nick_completer;
- struct t_config_option *config_completion_nick_first_only;
- struct t_config_option *config_completion_nick_ignore_chars;
- struct t_config_option *config_completion_partial_completion_alert;
- struct t_config_option *config_completion_partial_completion_command;
- struct t_config_option *config_completion_partial_completion_command_arg;
- struct t_config_option *config_completion_partial_completion_other;
- struct t_config_option *config_completion_partial_completion_count;
- /* config, history section */
- struct t_config_option *config_history_max_buffer_lines_number;
- struct t_config_option *config_history_max_buffer_lines_minutes;
- struct t_config_option *config_history_max_commands;
- struct t_config_option *config_history_max_visited_buffers;
- struct t_config_option *config_history_display_default;
- /* config, network section */
- struct t_config_option *config_network_connection_timeout;
- struct t_config_option *config_network_gnutls_ca_file;
- struct t_config_option *config_network_gnutls_handshake_timeout;
- /* config, plugin section */
- struct t_config_option *config_plugin_autoload;
- struct t_config_option *config_plugin_debug;
- struct t_config_option *config_plugin_extension;
- struct t_config_option *config_plugin_path;
- struct t_config_option *config_plugin_save_config_on_unload;
- /* other */
- int config_length_prefix_same_nick = 0;
- struct t_hook *config_day_change_timer = NULL;
- int config_day_change_old_day = -1;
- regex_t *config_highlight_regex = NULL;
- char **config_highlight_tags = NULL;
- int config_num_highlight_tags = 0;
- char **config_plugin_extensions = NULL;
- int config_num_plugin_extensions = 0;
- /*
- * config_change_save_config_on_exit: called when "save_config_on_exit" flag is changed
- */
- void
- config_change_save_config_on_exit (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (gui_init_ok && !CONFIG_BOOLEAN(config_look_save_config_on_exit))
- {
- gui_chat_printf (NULL,
- _("Warning: you should now issue /save to write "
- "\"save_config_on_exit\" option in configuration "
- "file"));
- }
- }
- /*
- * config_change_title: called when title is changed
- */
- void
- config_change_title (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (CONFIG_BOOLEAN(config_look_set_title))
- gui_window_set_title (PACKAGE_NAME " " PACKAGE_VERSION);
- }
- /*
- * config_change_buffers: called when buffers change (for example nicklist)
- */
- void
- config_change_buffers (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- gui_window_ask_refresh (1);
- }
- /*
- * config_change_buffer_content: called when content of a buffer changes
- */
- void
- config_change_buffer_content (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (gui_init_ok)
- gui_current_window->refresh_needed = 1;
- }
- /*
- * config_change_mouse: called when mouse state is changed
- */
- void
- config_change_mouse (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (gui_init_ok)
- {
- if (CONFIG_BOOLEAN(config_look_mouse))
- gui_mouse_enable ();
- else
- gui_mouse_disable ();
- }
- }
- /*
- * config_change_buffer_notify_default: called when buffer default notify changes
- */
- void
- config_change_buffer_notify_default (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- gui_buffer_notify_set_all ();
- }
- /*
- * config_change_buffer_time_format: called when buffer time format changes
- */
- void
- config_change_buffer_time_format (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- gui_chat_time_length = gui_chat_get_time_length ();
- gui_chat_change_time_format ();
- if (gui_init_ok)
- gui_window_ask_refresh (1);
- }
- /*
- * config_compute_prefix_max_length_all_buffers: compute the "prefix_max_length"
- * on all buffers
- */
- void
- config_compute_prefix_max_length_all_buffers ()
- {
- struct t_gui_buffer *ptr_buffer;
- for (ptr_buffer = gui_buffers; ptr_buffer;
- ptr_buffer = ptr_buffer->next_buffer)
- {
- if (ptr_buffer->own_lines)
- gui_line_compute_prefix_max_length (ptr_buffer->own_lines);
- if (ptr_buffer->mixed_lines)
- gui_line_compute_prefix_max_length (ptr_buffer->mixed_lines);
- }
- }
- /*
- * config_change_prefix_same_nick: called when "prefix for same nick" changes
- */
- void
- config_change_prefix_same_nick (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- config_length_prefix_same_nick =
- gui_chat_strlen_screen (CONFIG_STRING(config_look_prefix_same_nick));
- config_compute_prefix_max_length_all_buffers ();
- gui_window_ask_refresh (1);
- }
- /*
- * config_change_eat_newline_glitch: called when eat_newline_glitch changes
- */
- void
- config_change_eat_newline_glitch (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (gui_init_ok)
- {
- if (CONFIG_BOOLEAN(config_look_eat_newline_glitch))
- {
- gui_chat_printf (NULL,
- _("WARNING: this option can cause serious display "
- "bugs, if you have such problems, you must "
- "turn off this option."));
- gui_term_set_eat_newline_glitch (0);
- }
- else
- gui_term_set_eat_newline_glitch (1);
- }
- }
- /*
- * config_change_highlight_regex: called when highlight_regex changes
- */
- void
- config_change_highlight_regex (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (config_highlight_regex)
- {
- regfree (config_highlight_regex);
- free (config_highlight_regex);
- config_highlight_regex = NULL;
- }
- if (CONFIG_STRING(config_look_highlight_regex)
- && CONFIG_STRING(config_look_highlight_regex)[0])
- {
- config_highlight_regex = malloc (sizeof (*config_highlight_regex));
- if (config_highlight_regex)
- {
- if (string_regcomp (config_highlight_regex,
- CONFIG_STRING(config_look_highlight_regex),
- REG_EXTENDED | REG_ICASE) != 0)
- {
- free (config_highlight_regex);
- config_highlight_regex = NULL;
- }
- }
- }
- }
- /*
- * config_change_highlight_tags: called when highlight_tags changes
- */
- void
- config_change_highlight_tags (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (config_highlight_tags)
- {
- string_free_split (config_highlight_tags);
- config_highlight_tags = NULL;
- }
- config_num_highlight_tags = 0;
- if (CONFIG_STRING(config_look_highlight_tags)
- && CONFIG_STRING(config_look_highlight_tags)[0])
- {
- config_highlight_tags = string_split (CONFIG_STRING(config_look_highlight_tags),
- ",", 0, 0, &config_num_highlight_tags);
- }
- }
- /*
- * config_change_hotlist: called when hotlist changes
- */
- void
- config_change_hotlist (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- gui_hotlist_resort ();
- }
- /*
- * config_change_paste_bracketed: called when bracketed paste mode is changed
- */
- void
- config_change_paste_bracketed (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (gui_init_ok)
- gui_window_set_bracketed_paste_mode (CONFIG_BOOLEAN(config_look_paste_bracketed));
- }
- /*
- * config_change_read_marker: called when read marker is changed
- */
- void
- config_change_read_marker (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- gui_window_ask_refresh (1);
- }
- /*
- * config_change_prefix: called when a prefix is changed
- */
- void
- config_change_prefix (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- gui_chat_prefix_build ();
- }
- /*
- * config_change_prefix_align_min: called when prefix_align_min is changed
- */
- void
- config_change_prefix_align_min (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- config_compute_prefix_max_length_all_buffers ();
- gui_window_ask_refresh (1);
- }
- /*
- * config_check_prefix_align_more: check string "prefix align more" (must be
- * max one char wide on screen)
- */
- int
- config_check_prefix_align_more (void *data, struct t_config_option *option,
- const char *value)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- return (utf8_strlen_screen (value) == 1) ? 1 : 0;
- }
- /*
- * config_check_prefix_buffer_align_more: check string "prefix buffer align more"
- * (must be max one char wide on screen)
- */
- int
- config_check_prefix_buffer_align_more (void *data,
- struct t_config_option *option,
- const char *value)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- return (utf8_strlen_screen (value) == 1) ? 1 : 0;
- }
- /*
- * config_change_color: called when a color is changed by /set command
- */
- void
- config_change_color (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (gui_init_ok)
- {
- gui_color_init_weechat ();
- gui_window_ask_refresh (1);
- }
- }
- /*
- * config_change_nick_colors: called when nick colors are changed
- */
- void
- config_change_nick_colors (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- gui_color_buffer_display ();
- }
- /*
- * config_change_network_gnutls_ca_file: called when gnutls_ca_file is changed
- */
- void
- config_change_network_gnutls_ca_file (void *data,
- struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (network_init_ok)
- network_set_gnutls_ca_file ();
- }
- /*
- * config_change_plugin_extension: called when plugin extension is changed
- */
- void
- config_change_plugin_extension (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- if (config_plugin_extensions)
- {
- string_free_split (config_plugin_extensions);
- config_plugin_extensions = NULL;
- }
- config_num_plugin_extensions = 0;
- if (CONFIG_STRING(config_plugin_extension)
- && CONFIG_STRING(config_plugin_extension)[0])
- {
- config_plugin_extensions = string_split (CONFIG_STRING(config_plugin_extension),
- ",", 0, 0, &config_num_plugin_extensions);
- }
- }
- /*
- * config_day_change_timer_cb: timer callback for displaying
- * "Day changed to xxx" message
- */
- int
- config_day_change_timer_cb (void *data, int remaining_calls)
- {
- struct timeval tv_time;
- struct tm *local_time;
- int new_mday;
- char text_time[256], *text_time2;
- struct t_gui_buffer *ptr_buffer;
- /* make C compiler happy */
- (void) data;
- (void) remaining_calls;
- gettimeofday (&tv_time, NULL);
- local_time = localtime (&tv_time.tv_sec);
- new_mday = local_time->tm_mday;
- if ((config_day_change_old_day >= 0)
- && (new_mday != config_day_change_old_day))
- {
- if (CONFIG_BOOLEAN(config_look_day_change))
- {
- strftime (text_time, sizeof (text_time),
- CONFIG_STRING(config_look_day_change_time_format),
- local_time);
- text_time2 = string_iconv_to_internal (NULL, text_time);
- gui_add_hotlist = 0;
- for (ptr_buffer = gui_buffers; ptr_buffer;
- ptr_buffer = ptr_buffer->next_buffer)
- {
- if (ptr_buffer->type == GUI_BUFFER_TYPE_FORMATTED)
- {
- gui_chat_printf (ptr_buffer,
- _("\t\tDay changed to %s"),
- (text_time2) ?
- text_time2 : text_time);
- }
- }
- if (text_time2)
- free (text_time2);
- gui_add_hotlist = 1;
- }
- /* send signal "day_changed" */
- strftime (text_time, sizeof (text_time), "%Y-%m-%d", local_time);
- hook_signal_send ("day_changed", WEECHAT_HOOK_SIGNAL_STRING, text_time);
- }
- config_day_change_old_day = new_mday;
- return WEECHAT_RC_OK;
- }
- /*
- * config_weechat_init_after_read: initialize some things after reading (or
- * reloading) configuration file
- */
- void
- config_weechat_init_after_read ()
- {
- int i;
- gui_buffer_notify_set_all ();
- proxy_use_temp_proxies ();
- gui_bar_use_temp_bars ();
- if (gui_bars)
- {
- /*
- * at least one bar defined => just ensure that at least one bar is
- * using item "input_text"
- */
- gui_bar_create_default_input ();
- }
- else
- {
- /* no bar defined => create default bars */
- gui_bar_create_default ();
- }
- /* if no key was found config file, then we use default bindings */
- for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
- {
- if (!gui_keys[i])
- gui_key_default_bindings (i);
- }
- /* apply filters on all buffers */
- gui_filter_all_buffers ();
- }
- /*
- * config_weechat_reload_cb: reload WeeChat configuration file
- * return one of these values:
- * WEECHAT_CONFIG_READ_OK
- * WEECHAT_CONFIG_READ_MEMORY_ERROR
- * WEECHAT_CONFIG_READ_FILE_NOT_FOUND
- */
- int
- config_weechat_reload_cb (void *data, struct t_config_file *config_file)
- {
- int i, rc;
- /* make C compiler happy */
- (void) data;
- /* remove all keys */
- for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++)
- {
- gui_key_free_all (&gui_keys[i], &last_gui_key[i],
- &gui_keys_count[i]);
- }
- /* remove all proxies */
- proxy_free_all ();
- /* remove all bars */
- gui_bar_free_all ();
- /* remove layout */
- gui_layout_buffer_reset (&gui_layout_buffers, &last_gui_layout_buffer);
- gui_layout_window_reset (&gui_layout_windows);
- /* remove all notify levels */
- config_file_section_free_options (weechat_config_section_notify);
- /* remove all filters */
- gui_filter_free_all ();
- rc = config_file_reload (config_file);
- config_weechat_init_after_read ();
- return rc;
- }
- /*
- * config_weechat_debug_get: get debug level for a plugin (or "core")
- */
- struct t_config_option *
- config_weechat_debug_get (const char *plugin_name)
- {
- return config_file_search_option (weechat_config_file,
- weechat_config_section_debug,
- plugin_name);
- }
- /*
- * config_weechat_debug_set_all: set debug for "core" and all plugins, using
- * values from [debug] section
- */
- void
- config_weechat_debug_set_all ()
- {
- struct t_config_option *ptr_option;
- struct t_weechat_plugin *ptr_plugin;
- /* set debug for core */
- ptr_option = config_weechat_debug_get (PLUGIN_CORE);
- weechat_debug_core = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0;
- /* set debug for plugins */
- for (ptr_plugin = weechat_plugins; ptr_plugin;
- ptr_plugin = ptr_plugin->next_plugin)
- {
- ptr_option = config_weechat_debug_get (ptr_plugin->name);
- ptr_plugin->debug = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0;
- }
- }
- /*
- * config_weechat_debug_change_cb: called when a debug option is changed
- */
- void
- config_weechat_debug_change_cb (void *data,
- struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- config_weechat_debug_set_all ();
- }
- /*
- * config_weechat_debug_create_option_cb: create option in "debug" section
- */
- int
- config_weechat_debug_create_option_cb (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 = config_file_search_option (config_file, section,
- option_name);
- if (ptr_option)
- {
- if (value && value[0])
- rc = config_file_option_set (ptr_option, value, 1);
- else
- {
- config_file_option_free (ptr_option);
- rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
- }
- }
- else
- {
- if (value && value[0])
- {
- ptr_option = config_file_new_option (
- config_file, section,
- option_name, "integer",
- _("debug level for plugin (\"core\" for WeeChat core)"),
- NULL, 0, 32, "0", value, 0, NULL, NULL,
- &config_weechat_debug_change_cb, 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;
- }
- }
- /* set debug level for "core" and all plugins */
- config_weechat_debug_set_all ();
- return rc;
- }
- /*
- * config_weechat_debug_delete_option_cb: delete option in "debug" section
- */
- int
- config_weechat_debug_delete_option_cb (void *data,
- struct t_config_file *config_file,
- struct t_config_section *section,
- struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) config_file;
- (void) section;
- config_file_option_free (option);
- config_weechat_debug_set_all ();
- return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
- }
- /*
- * config_weechat_debug_set: set debug level for a plugin (or "core")
- */
- int
- config_weechat_debug_set (const char *plugin_name, const char *value)
- {
- return config_weechat_debug_create_option_cb (NULL,
- weechat_config_file,
- weechat_config_section_debug,
- plugin_name,
- value);
- }
- /*
- * config_weechat_palette_change_cb: called when a palette option is changed
- */
- void
- config_weechat_palette_change_cb (void *data,
- struct t_config_option *option)
- {
- char *error;
- int number;
- /* make C compiler happy */
- (void) data;
- (void) option;
- error = NULL;
- number = (int)strtol (option->name, &error, 10);
- if (error && !error[0])
- {
- gui_color_palette_add (number, CONFIG_STRING(option));
- }
- }
- /*
- * config_weechat_palette_create_option_cb: create option in "palette" section
- */
- int
- config_weechat_palette_create_option_cb (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;
- char *error;
- int rc, number;
- /* make C compiler happy */
- (void) data;
- rc = WEECHAT_CONFIG_OPTION_SET_ERROR;
- error = NULL;
- number = (int)strtol (option_name, &error, 10);
- if (error && !error[0])
- {
- if (option_name)
- {
- ptr_option = config_file_search_option (config_file, section,
- option_name);
- if (ptr_option)
- {
- if (value)
- rc = config_file_option_set (ptr_option, value, 1);
- else
- {
- config_file_option_free (ptr_option);
- rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
- }
- }
- else
- {
- if (value)
- {
- ptr_option = config_file_new_option (
- config_file, section,
- option_name, "string",
- _("alias for color"),
- NULL, 0, 0, "", value, 0, NULL, NULL,
- &config_weechat_palette_change_cb, NULL,
- NULL, NULL);
- rc = (ptr_option) ?
- WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE : WEECHAT_CONFIG_OPTION_SET_ERROR;
- if (ptr_option)
- gui_color_palette_add (number, value);
- }
- else
- rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
- }
- }
- }
- else
- {
- gui_chat_printf (NULL,
- _("%sError: palette option must be numeric"),
- gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
- }
- return rc;
- }
- /*
- * config_weechat_palette_delete_option_cb: delete option in "palette" section
- */
- int
- config_weechat_palette_delete_option_cb (void *data,
- struct t_config_file *config_file,
- struct t_config_section *section,
- struct t_config_option *option)
- {
- char *error;
- int number;
- /* make C compiler happy */
- (void) data;
- (void) config_file;
- (void) section;
- error = NULL;
- number = (int)strtol (option->name, &error, 10);
- if (error && !error[0])
- gui_color_palette_remove (number);
- config_file_option_free (option);
- return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
- }
- /*
- * config_weechat_proxy_read_cb: read proxy option in config file
- */
- int
- config_weechat_proxy_read_cb (void *data, struct t_config_file *config_file,
- struct t_config_section *section,
- const char *option_name, const char *value)
- {
- char *pos_option, *proxy_name;
- struct t_proxy *ptr_temp_proxy;
- int index_option;
- /* make C compiler happy */
- (void) data;
- (void) config_file;
- (void) section;
- if (option_name)
- {
- pos_option = strchr (option_name, '.');
- if (pos_option)
- {
- proxy_name = string_strndup (option_name, pos_option - option_name);
- if (proxy_name)
- {
- pos_option++;
- for (ptr_temp_proxy = weechat_temp_proxies; ptr_temp_proxy;
- ptr_temp_proxy = ptr_temp_proxy->next_proxy)
- {
- if (strcmp (ptr_temp_proxy->name, proxy_name) == 0)
- break;
- }
- if (!ptr_temp_proxy)
- {
- /* create new temp proxy */
- ptr_temp_proxy = proxy_alloc (proxy_name);
- if (ptr_temp_proxy)
- {
- /* add new temp proxy at end of queue */
- ptr_temp_proxy->prev_proxy = last_weechat_temp_proxy;
- ptr_temp_proxy->next_proxy = NULL;
- if (!weechat_temp_proxies)
- weechat_temp_proxies = ptr_temp_proxy;
- else
- last_weechat_temp_proxy->next_proxy = ptr_temp_proxy;
- last_weechat_temp_proxy = ptr_temp_proxy;
- }
- }
- if (ptr_temp_proxy)
- {
- index_option = proxy_search_option (pos_option);
- if (index_option >= 0)
- {
- proxy_create_option_temp (ptr_temp_proxy, index_option,
- value);
- }
- }
- free (proxy_name);
- }
- }
- }
- return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
- }
- /*
- * config_weechat_bar_read_cb: read bar option in config file
- */
- int
- config_weechat_bar_read_cb (void *data, struct t_config_file *config_file,
- struct t_config_section *section,
- const char *option_name, const char *value)
- {
- char *pos_option, *bar_name;
- struct t_gui_bar *ptr_temp_bar;
- int index_option;
- /* make C compiler happy */
- (void) data;
- (void) config_file;
- (void) section;
- if (option_name)
- {
- pos_option = strchr (option_name, '.');
- if (pos_option)
- {
- bar_name = string_strndup (option_name, pos_option - option_name);
- if (bar_name)
- {
- pos_option++;
- for (ptr_temp_bar = gui_temp_bars; ptr_temp_bar;
- ptr_temp_bar = ptr_temp_bar->next_bar)
- {
- if (strcmp (ptr_temp_bar->name, bar_name) == 0)
- break;
- }
- if (!ptr_temp_bar)
- {
- /* create new temp bar */
- ptr_temp_bar = gui_bar_alloc (bar_name);
- if (ptr_temp_bar)
- {
- /* add new temp bar at end of queue */
- ptr_temp_bar->prev_bar = last_gui_temp_bar;
- ptr_temp_bar->next_bar = NULL;
- if (!gui_temp_bars)
- gui_temp_bars = ptr_temp_bar;
- else
- last_gui_temp_bar->next_bar = ptr_temp_bar;
- last_gui_temp_bar = ptr_temp_bar;
- }
- }
- if (ptr_temp_bar)
- {
- index_option = gui_bar_search_option (pos_option);
- if (index_option >= 0)
- {
- gui_bar_create_option_temp (ptr_temp_bar, index_option,
- value);
- }
- }
- free (bar_name);
- }
- }
- }
- return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
- }
- /*
- * config_weechat_layout_read_cb: read layout option in config file
- */
- int
- config_weechat_layout_read_cb (void *data, struct t_config_file *config_file,
- struct t_config_section *section,
- const char *option_name, const char *value)
- {
- int argc;
- char **argv, *error1, *error2, *error3, *error4;
- long number1, number2, number3, number4;
- struct t_gui_layout_window *parent;
- /* make C compiler happy */
- (void) data;
- (void) config_file;
- (void) section;
- if (option_name && value && value[0])
- {
- if (string_strcasecmp (option_name, "buffer") == 0)
- {
- argv = string_split (value, ";", 0, 0, &argc);
- if (argv)
- {
- if (argc >= 3)
- {
- error1 = NULL;
- number1 = strtol (argv[2], &error1, 10);
- if (error1 && !error1[0])
- {
- gui_layout_buffer_add (&gui_layout_buffers,
- &last_gui_layout_buffer,
- argv[0], argv[1], number1);
- }
- }
- string_free_split (argv);
- }
- }
- else if (string_strcasecmp (option_name, "window") == 0)
- {
- argv = string_split (value, ";", 0, 0, &argc);
- if (argv)
- {
- if (argc >= 6)
- {
- error1 = NULL;
- number1 = strtol (argv[0], &error1, 10);
- error2 = NULL;
- number2 = strtol (argv[1], &error2, 10);
- error3 = NULL;
- number3 = strtol (argv[2], &error3, 10);
- error4 = NULL;
- number4 = strtol (argv[3], &error4, 10);
- if (error1 && !error1[0] && error2 && !error2[0]
- && error3 && !error3[0] && error4 && !error4[0])
- {
- parent = gui_layout_window_search_by_id (gui_layout_windows,
- number2);
- gui_layout_window_add (&gui_layout_windows,
- number1,
- parent,
- number3,
- number4,
- (strcmp (argv[4], "-") != 0) ?
- argv[4] : NULL,
- (strcmp (argv[4], "-") != 0) ?
- argv[5] : NULL);
- }
- }
- string_free_split (argv);
- }
- }
- }
- return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
- }
- /*
- * config_weechat_layout_write: write windows layout in configuration file
- */
- int
- config_weechat_layout_write_tree (struct t_config_file *config_file,
- struct t_gui_layout_window *layout_window)
- {
- if (!config_file_write_line (config_file, "window", "\"%d;%d;%d;%d;%s;%s\"",
- layout_window->internal_id,
- (layout_window->parent_node) ?
- layout_window->parent_node->internal_id : 0,
- layout_window->split_pct,
- layout_window->split_horiz,
- (layout_window->plugin_name) ?
- layout_window->plugin_name : "-",
- (layout_window->buffer_name) ?
- layout_window->buffer_name : "-"))
- return WEECHAT_CONFIG_WRITE_ERROR;
- if (layout_window->child1)
- {
- if (config_weechat_layout_write_tree (config_file,
- layout_window->child1) != WEECHAT_CONFIG_WRITE_OK)
- return WEECHAT_CONFIG_WRITE_ERROR;
- }
- if (layout_window->child2)
- {
- if (config_weechat_layout_write_tree (config_file,
- layout_window->child2) != WEECHAT_CONFIG_WRITE_OK)
- return WEECHAT_CONFIG_WRITE_ERROR;
- }
- return WEECHAT_CONFIG_WRITE_OK;
- }
- /*
- * config_weechat_layout_write_cb: write layout section in configuration file
- */
- int
- config_weechat_layout_write_cb (void *data, struct t_config_file *config_file,
- const char *section_name)
- {
- struct t_gui_layout_buffer *ptr_layout_buffer;
- /* make C compiler happy */
- (void) data;
- if (!config_file_write_line (config_file, section_name, NULL))
- return WEECHAT_CONFIG_WRITE_ERROR;
- for (ptr_layout_buffer = gui_layout_buffers; ptr_layout_buffer;
- ptr_layout_buffer = ptr_layout_buffer->next_layout)
- {
- if (!config_file_write_line (config_file, "buffer", "\"%s;%s;%d\"",
- ptr_layout_buffer->plugin_name,
- ptr_layout_buffer->buffer_name,
- ptr_layout_buffer->number))
- return WEECHAT_CONFIG_WRITE_ERROR;
- }
- if (gui_layout_windows)
- {
- if (config_weechat_layout_write_tree (config_file,
- gui_layout_windows) != WEECHAT_CONFIG_WRITE_OK)
- return WEECHAT_CONFIG_WRITE_ERROR;
- }
- return WEECHAT_CONFIG_WRITE_OK;
- }
- /*
- * config_weechat_notify_change_cb: callback when notify option is changed
- */
- void
- config_weechat_notify_change_cb (void *data, struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) option;
- gui_buffer_notify_set_all ();
- }
- /*
- * config_weechat_notify_create_option_cb: callback to create option in "notify"
- * section
- */
- int
- config_weechat_notify_create_option_cb (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 = config_file_search_option (config_file, section,
- option_name);
- if (ptr_option)
- {
- if (value && value[0])
- rc = config_file_option_set (ptr_option, value, 1);
- else
- {
- config_file_option_free (ptr_option);
- rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
- }
- }
- else
- {
- if (value && value[0])
- {
- ptr_option = config_file_new_option (
- config_file, section,
- option_name, "integer", _("Notify level for buffer"),
- "none|highlight|message|all",
- 0, 0, "", value, 0, NULL, NULL,
- &config_weechat_notify_change_cb, 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)
- gui_buffer_notify_set_all ();
- return rc;
- }
- /*
- * config_weechat_notify_delete_option_cb: called when a notify option is
- * deleted
- */
- int
- config_weechat_notify_delete_option_cb (void *data,
- struct t_config_file *config_file,
- struct t_config_section *section,
- struct t_config_option *option)
- {
- /* make C compiler happy */
- (void) data;
- (void) config_file;
- (void) section;
- config_file_option_free (option);
- gui_buffer_notify_set_all ();
- return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED;
- }
- /*
- * config_weechat_notify_set: set a notify level for a buffer
- * negative value will reset notify for buffer to
- * default value (and remove buffer from config file)
- * return 1 if ok, 0 if error
- */
- int
- config_weechat_notify_set (struct t_gui_buffer *buffer, const char *notify)
- {
- int i, value;
- if (!buffer || !notify)
- return 0;
- value = -1;
- for (i = 0; i < GUI_BUFFER_NUM_NOTIFY; i++)
- {
- if (strcmp (gui_buffer_notify_string[i], notify) == 0)
- {
- value = i;
- break;
- }
- }
- if ((value < 0) && (strcmp (notify, "reset") != 0))
- return 0;
- /* create/update option */
- config_weechat_notify_create_option_cb (NULL,
- weechat_config_file,
- weechat_config_section_notify,
- buffer->full_name,
- (value < 0) ?
- NULL : gui_buffer_notify_string[value]);
- return 1;
- }
- /*
- * config_weechat_filter_read_cb: read filter option from config file
- */
- int
- config_weechat_filter_read_cb (void *data,
- struct t_config_file *config_file,
- struct t_config_section *section,
- const char *option_name, const char *value)
- {
- char **argv, **argv_eol;
- int argc;
- /* make C compiler happy */
- (void) data;
- (void) config_file;
- (void) section;
- if (option_name && value && value[0])
- {
- argv = string_split (value, ";", 0, 0, &argc);
- argv_eol = string_split (value, ";", 1, 0, NULL);
- if (argv && argv_eol && (argc >= 4))
- {
- gui_filter_new ((string_strcasecmp (argv[0], "on") == 0) ? 1 : 0,
- option_name, argv[1], argv[2], argv_eol[3]);
- }
- if (argv)
- string_free_split (argv);
- if (argv_eol)
- string_free_split (argv_eol);
- }
- return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
- }
- /*
- * config_weechat_filter_write_cb: write filter section in configuration file
- */
- int
- config_weechat_filter_write_cb (void *data, struct t_config_file *config_file,
- const char *section_name)
- {
- struct t_gui_filter *ptr_filter;
- /* make C compiler happy */
- (void) data;
- if (!config_file_write_line (config_file, section_name, NULL))
- return WEECHAT_CONFIG_WRITE_ERROR;
- for (ptr_filter = gui_filters; ptr_filter;
- ptr_filter = ptr_filter->next_filter)
- {
- if (!config_file_write_line (config_file,
- ptr_filter->name,
- "%s;%s;%s;%s",
- (ptr_filter->enabled) ? "on" : "off",
- ptr_filter->buffer_name,
- ptr_filter->tags,
- ptr_filter->regex))
- return WEECHAT_CONFIG_WRITE_ERROR;
- }
- return WEECHAT_CONFIG_WRITE_OK;
- }
- /*
- * config_weechat_key_read_cb: read key option in config file
- */
- int
- config_weechat_key_read_cb (void *data, struct t_config_file *config_file,
- struct t_config_section *section,
- const char *option_name, const char *value)
- {
- int context;
- char *pos;
- /* make C compiler happy */
- (void) data;
- (void) config_file;
- if (option_name)
- {
- context = GUI_KEY_CONTEXT_DEFAULT;
- pos = strchr (section->name, '_');
- if (pos)
- {
- context = gui_key_search_context (pos + 1);
- if (context < 0)
- context = GUI_KEY_CONTEXT_DEFAULT;
- }
- if (value && value[0])
- {
- /* bind key (overwrite any binding with same key) */
- gui_key_bind (NULL, context, option_name, value);
- }
- else
- {
- /* unbind key if no value given */
- gui_key_unbind (NULL, context, option_name);
- }
- }
- return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE;
- }
- /*
- * config_weechat_key_write_cb: write key section in configuration file
- */
- int
- config_weechat_key_write_cb (void *data, struct t_config_file *config_file,
- const char *section_name)
- {
- struct t_gui_key *ptr_key;
- char *pos, *expanded_name;
- int rc, context;
- /* make C compiler happy */
- …
Large files files are truncated, but you can click here to view the full file