diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/core/wee-command.c | 50 | ||||
-rw-r--r-- | src/core/wee-command.h | 1 | ||||
-rw-r--r-- | src/core/wee-config-file.c | 138 | ||||
-rw-r--r-- | src/core/wee-config-file.h | 3 | ||||
-rw-r--r-- | src/core/wee-config.c | 22 | ||||
-rw-r--r-- | src/core/wee-config.h | 1 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 4 | ||||
-rw-r--r-- | src/plugins/plugin-config.c | 50 | ||||
-rw-r--r-- | src/plugins/plugin-config.h | 2 | ||||
-rw-r--r-- | src/plugins/plugin.c | 1 |
11 files changed, 240 insertions, 39 deletions
@@ -1,10 +1,15 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2007-09-19 +ChangeLog - 2007-12-01 Version 0.2.7 (under dev!): + * added /reload command to reload WeeChat and plugins config files + * new plugins: IRC, fifo, logger, trigger, demo + * new plugin API with many new functions: hooks, buffer management, + config files, lists + * new display engine, with prefix and message for each line * fixed nick completion bug (missing space after nick) Version 0.2.6 (2007-09-06): diff --git a/src/core/wee-command.c b/src/core/wee-command.c index acaf8bbb2..05967700f 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -153,12 +153,16 @@ struct command weechat_commands[] = "Without argument, /plugin command lists loaded plugins."), "list|listfull|load|autoload|reload|unload %P", 0, 2, 0, command_plugin }, { "quit", - "", "", "", + N_("quit WeeChat"), "", "", NULL, 0, 0, 0, command_quit }, + { "reload", + N_("reload WeeChat and plugins configuration files from disk"), + "", "", + NULL, 0, 0, 0, command_reload }, { "save", - N_("save configuration files to disk"), + N_("save WeeChat and plugins configuration files to disk"), "", "", - NULL, 0, 1, 0, command_save }, + NULL, 0, 0, 0, command_save }, { "set", N_("set config options"), N_("[option [ = value]]"), N_("option: name of an option (if name is full " @@ -1516,6 +1520,43 @@ command_quit (struct t_gui_buffer *buffer, } /* + * command_reload: reload WeeChat and plugins options from disk + */ + +int +command_reload (struct t_gui_buffer *buffer, + int argc, char **argv, char **argv_eol) +{ + /* make C compiler happy */ + (void) buffer; + (void) argc; + (void) argv; + (void) argv_eol; + + /* reload WeeChat configuration */ + if (config_weechat_reload () == 0) + gui_chat_printf (NULL, + _("%sWeeChat configuration file reloaded"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); + else + gui_chat_printf (NULL, + _("%sError: failed to read WeeChat configuration " + "file"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); + + /* reload plugins configuration */ + if (plugin_config_reload () == 0) + gui_chat_printf (NULL, _("%sPlugins options reloaded"), + gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); + else + gui_chat_printf (NULL, + _("%sError: failed to read plugins options"), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); + + return 0; +} + +/* * command_save: save WeeChat and plugins options to disk */ @@ -1536,7 +1577,8 @@ command_save (struct t_gui_buffer *buffer, gui_chat_prefix[GUI_CHAT_PREFIX_INFO]); else gui_chat_printf (NULL, - _("%sError: failed to save configuration file"), + _("%sError: failed to save WeeChat configuration " + "file"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); /* save plugins configuration */ diff --git a/src/core/wee-command.h b/src/core/wee-command.h index d36787d19..2a31ae73c 100644 --- a/src/core/wee-command.h +++ b/src/core/wee-command.h @@ -61,6 +61,7 @@ extern int command_history (struct t_gui_buffer *, int, char **, char **); extern int command_key (struct t_gui_buffer *, int, char **, char **); extern int command_plugin (struct t_gui_buffer *, int, char **, char **); extern int command_quit (struct t_gui_buffer *, int, char **, char **); +extern int command_reload (struct t_gui_buffer *, int, char **, char **); extern int command_save (struct t_gui_buffer *, int, char **, char **); extern int command_set (struct t_gui_buffer *, int, char **, char **); extern int command_setp (struct t_gui_buffer *, int, char **, char **); diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index a29e3ba97..572de2142 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -161,6 +161,7 @@ config_file_new_option_boolean (struct t_config_section *section, char *name, new_option->value = malloc (sizeof (char)); *((char *)new_option->value) = default_value; new_option->callback_change = callback_change; + new_option->loaded = 0; new_option->prev_option = section->last_option; new_option->next_option = NULL; @@ -203,6 +204,7 @@ config_file_new_option_integer (struct t_config_section *section, char *name, new_option->value = malloc (sizeof (int)); *((int *)new_option->value) = default_value; new_option->callback_change = callback_change; + new_option->loaded = 0; new_option->prev_option = section->last_option; new_option->next_option = NULL; @@ -249,6 +251,7 @@ config_file_new_option_integer_with_string (struct t_config_section *section, new_option->value = malloc (sizeof (int)); *((int *)new_option->value) = default_value; new_option->callback_change = callback_change; + new_option->loaded = 0; new_option->prev_option = section->last_option; new_option->next_option = NULL; @@ -292,6 +295,7 @@ config_file_new_option_string (struct t_config_section *section, new_option->value = strdup (default_value) ? strdup (default_value) : NULL; new_option->callback_change = callback_change; + new_option->loaded = 0; new_option->prev_option = section->last_option; new_option->next_option = NULL; @@ -335,6 +339,7 @@ config_file_new_option_color (struct t_config_section *section, new_option->value = malloc (sizeof (int)); *((int *)new_option->value) = *((int *)new_option->default_value); new_option->callback_change = callback_change; + new_option->loaded = 0; new_option->prev_option = section->last_option; new_option->next_option = NULL; @@ -509,6 +514,61 @@ config_file_option_set (struct t_config_option *option, char *new_value) } /* + * config_file_option_reset: set default value for an option + * return: 2 if ok (value changed) + * 1 if ok (value is the same) + * 0 if failed + */ + +int +config_file_option_reset (struct t_config_option *option) +{ + int rc; + + if (!option) + return 0; + + switch (option->type) + { + case CONFIG_OPTION_BOOLEAN: + if (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_DEFAULT(option)) + return 1; + CONFIG_BOOLEAN(option) = CONFIG_BOOLEAN_DEFAULT(option); + return 2; + case CONFIG_OPTION_INTEGER: + if (CONFIG_INTEGER(option) == CONFIG_INTEGER_DEFAULT(option)) + return 1; + CONFIG_INTEGER(option) = CONFIG_INTEGER_DEFAULT(option); + return 2; + case CONFIG_OPTION_STRING: + rc = 1; + if ((!option->value && option->default_value) + || (option->value && !option->default_value) + || (strcmp ((char *)option->value, + (char *)option->default_value) != 0)) + rc = 2; + if (option->value) + free (option->value); + if (option->default_value) + { + option->value = strdup ((char *)option->default_value); + if (!option->value) + return 0; + } + else + option->value = NULL; + return rc; + case CONFIG_OPTION_COLOR: + if (CONFIG_COLOR(option) == CONFIG_COLOR_DEFAULT(option)) + return 1; + CONFIG_COLOR(option) = CONFIG_COLOR_DEFAULT(option); + return 2; + } + + return 0; +} + +/* * config_file_read: read a configuration file * return: 0 = successful * -1 = config file file not found @@ -652,7 +712,10 @@ config_file_read (struct t_config_file *config_file) ptr_section, line); if (ptr_option) + { rc = config_file_option_set (ptr_option, pos); + ptr_option->loaded = 1; + } else { /* option not found: use read callback */ @@ -711,6 +774,55 @@ config_file_read (struct t_config_file *config_file) } /* + * config_file_reload: reload a configuration file + * return: 0 = successful + * -1 = config file file not found + * -2 = error in config file + */ + +int +config_file_reload (struct t_config_file *config_file) +{ + struct t_config_section *ptr_section; + struct t_config_option *ptr_option; + int rc; + + /* init "loaded" flag for all options */ + for (ptr_section = config_file->sections; ptr_section; + ptr_section = ptr_section->next_section) + { + for (ptr_option = ptr_section->options; ptr_option; + ptr_option = ptr_option->next_option) + { + ptr_option->loaded = 0; + } + } + + /* read configuration file */ + rc = config_file_read (config_file); + + /* reset options not found in configuration file */ + for (ptr_section = config_file->sections; ptr_section; + ptr_section = ptr_section->next_section) + { + for (ptr_option = ptr_section->options; ptr_option; + ptr_option = ptr_option->next_option) + { + if (!ptr_option->loaded) + { + if (config_file_option_reset (ptr_option) == 2) + { + if (ptr_option->callback_change) + (void) (ptr_option->callback_change) (); + } + } + } + } + + return rc; +} + +/* * config_file_write_option: write an option in a config file */ @@ -1007,39 +1119,41 @@ config_file_print_log () { case CONFIG_OPTION_BOOLEAN: log_printf (" value (boolean). . . : %s\n", - (*((int *)ptr_option->value) == CONFIG_BOOLEAN_TRUE) ? + (CONFIG_BOOLEAN(ptr_option) == CONFIG_BOOLEAN_TRUE) ? "true" : "false"); log_printf (" default value. . . . : %s\n", - (*((int *)ptr_option->default_value) == CONFIG_BOOLEAN_TRUE) ? + (CONFIG_BOOLEAN_DEFAULT(ptr_option) == CONFIG_BOOLEAN_TRUE) ? "true" : "false"); break; case CONFIG_OPTION_INTEGER: if (ptr_option->string_values) { log_printf (" value (integer/str). : '%s'\n", - ptr_option->string_values[*((int *)ptr_option->value)]); + ptr_option->string_values[CONFIG_INTEGER(ptr_option)]); log_printf (" default value. . . . : '%s'\n", - ptr_option->string_values[*((int *)ptr_option->default_value)]); + ptr_option->string_values[CONFIG_INTEGER_DEFAULT(ptr_option)]); } else { - log_printf (" value (integer). . . : %d\n", *((int *)ptr_option->value)); - log_printf (" default value. . . . : %d\n", *((int *)ptr_option->default_value)); + log_printf (" value (integer). . . : %d\n", CONFIG_INTEGER(ptr_option)); + log_printf (" default value. . . . : %d\n", CONFIG_INTEGER_DEFAULT(ptr_option)); } break; case CONFIG_OPTION_STRING: - log_printf (" value (string) . . . : '%s'\n", (char *)ptr_option->value); - log_printf (" default value. . . . : '%s'\n", (char *)ptr_option->default_value); + log_printf (" value (string) . . . : '%s'\n", CONFIG_STRING(ptr_option)); + log_printf (" default value. . . . : '%s'\n", CONFIG_STRING_DEFAULT(ptr_option)); break; case CONFIG_OPTION_COLOR: log_printf (" value (color). . . . : %d ('%s')\n", - *((int *)ptr_option->value), - gui_color_get_name (*((int *)ptr_option->value))); + CONFIG_COLOR(ptr_option), + gui_color_get_name (CONFIG_COLOR(ptr_option))); log_printf (" default value. . . . : %d ('%s')\n", - *((int *)ptr_option->default_value), - gui_color_get_name (*((int *)ptr_option->default_value))); + CONFIG_COLOR_DEFAULT(ptr_option), + gui_color_get_name (CONFIG_COLOR_DEFAULT(ptr_option))); break; } + log_printf (" callback_change. . . : 0x%X\n", ptr_option->callback_change); + log_printf (" loaded . . . . . . . : %d\n", ptr_option->loaded); log_printf (" prev_option. . . . . : 0x%X\n", ptr_option->prev_option); log_printf (" next_option. . . . . : 0x%X\n", ptr_option->next_option); } diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index d7876b6d7..9254cc11c 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -79,6 +79,7 @@ struct t_config_option void *default_value; /* default value */ void *value; /* value */ void (*callback_change)(); /* called when value is changed */ + int loaded; /* 1 if opt was found in config */ struct t_config_option *prev_option; /* link to previous option */ struct t_config_option *next_option; /* link to next option */ }; @@ -117,8 +118,10 @@ extern struct t_config_option *config_file_search_option (struct t_config_file * struct t_config_section *, char *); extern int config_file_option_set (struct t_config_option *, char *); +extern int config_file_option_reset (struct t_config_option *); extern int config_file_read (struct t_config_file *); +extern int config_file_reload (struct t_config_file *); extern void config_file_write_line (struct t_config_file *, char *, char *); extern int config_file_write (struct t_config_file *, int); extern void config_file_print_stdout (struct t_config_file *); diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 4de2f29c2..e8fb7fe69 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -485,7 +485,7 @@ config_weechat_write_keys (struct t_config_file *config_file) } /* - * config_weechat_init: init options with default values + * config_weechat_init: init WeeChat config structure */ void @@ -1128,6 +1128,26 @@ config_weechat_read () } /* + * config_weechat_reload: reload WeeChat configuration file + * return: 0 = successful + * -1 = configuration file file not found + * -2 = error in configuration file + */ + +int +config_weechat_reload () +{ + /* remove all alias */ + alias_free_all (); + + /* remove all keys */ + gui_keyboard_free_all (); + + /* reload configuration file */ + return config_file_reload (weechat_config); +} + +/* * config_weechat_write: write WeeChat configuration file * return: 0 if ok * < 0 if error diff --git a/src/core/wee-config.h b/src/core/wee-config.h index d7ac9748a..c7debced2 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -178,6 +178,7 @@ extern void config_change_nicks_colors (); extern void config_weechat_init (); extern int config_weechat_read (); +extern int config_weechat_reload (); extern int config_weechat_write (); extern void config_weechat_print_stdout (); diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 7c91277e3..1dbb9372d 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -1219,10 +1219,8 @@ plugin_api_plugin_config_set (struct t_weechat_plugin *plugin, return 0; if (plugin_config_set (plugin->name, option_name, value)) - { - plugin_config_write (); return 1; - } + return 0; } diff --git a/src/plugins/plugin-config.c b/src/plugins/plugin-config.c index b621e0a71..d21418101 100644 --- a/src/plugins/plugin-config.c +++ b/src/plugins/plugin-config.c @@ -280,36 +280,50 @@ plugin_config_write_options (struct t_config_file *config_file) } /* - * plugin_config_read: read WeeChat plugins configuration file + * plugin_config_init: init plugins config structure + */ + +void +plugin_config_init () +{ + plugin_config = config_file_new (PLUGIN_CONFIG_FILENAME); + if (plugin_config) + { + config_file_new_section (plugin_config, "plugin", + &plugin_config_read_option, + &plugin_config_write_options, + NULL); + } +} + +/* + * plugin_config_read: read plugins configuration file * return: 0 = successful * -1 = config file file not found * -2 = error in config file - * -3 = not enough memory */ int plugin_config_read () { - if (!plugin_config) - { - plugin_config = config_file_new (PLUGIN_CONFIG_FILENAME); - if (plugin_config) - { - config_file_new_section (plugin_config, "plugin", - &plugin_config_read_option, - &plugin_config_write_options, - NULL); - } - } - - if (!plugin_config) - return -3; - return config_file_read (plugin_config); } /* - * plugin_config_write: write WeeChat configuration file + * plugin_config_reload: read plugins configuration file + * return: 0 = successful + * -1 = config file file not found + * -2 = error in config file + */ + +int +plugin_config_reload () +{ + return config_file_reload (plugin_config); +} + +/* + * plugin_config_write: write plugins configuration file * return: 0 if ok * < 0 if error */ diff --git a/src/plugins/plugin-config.h b/src/plugins/plugin-config.h index 7558388ba..24e67101d 100644 --- a/src/plugins/plugin-config.h +++ b/src/plugins/plugin-config.h @@ -29,7 +29,9 @@ extern struct t_config_option *plugin_config_search_internal (char *); extern struct t_config_option *plugin_config_search (char *, char *); extern int plugin_config_set_internal (char *, char *); extern int plugin_config_set (char *, char *, char *); +extern void plugin_config_init (); extern int plugin_config_read (); +extern int plugin_config_reload (); extern int plugin_config_write (); #endif /* plugin-config.h */ diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 54eea1191..b8fa1597d 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -566,6 +566,7 @@ void plugin_init (int auto_load) { /* read plugins options on disk */ + plugin_config_init (); plugin_config_read (); /* auto-load plugins if asked */ |