diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2008-06-02 15:42:43 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2008-06-02 15:42:43 +0200 |
commit | 96a3481b69bb21a757ad1d225ccdc2a18a218023 (patch) | |
tree | 0f130e9248a44f5bd4958479ffacbf7d75d947cf /src/core | |
parent | 40ec612e731f0ebbf7a7121d0f542e1996c99da3 (diff) | |
download | weechat-96a3481b69bb21a757ad1d225ccdc2a18a218023.zip |
Add constants for config file read/write/set/unset callbacks
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-command.c | 21 | ||||
-rw-r--r-- | src/core/wee-config-file.c | 198 | ||||
-rw-r--r-- | src/core/wee-config.c | 28 |
3 files changed, 135 insertions, 112 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 910daee4f..7b0ec0576 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -48,6 +48,7 @@ #include "../gui/gui-color.h" #include "../gui/gui-filter.h" #include "../gui/gui-history.h" +#include "../gui/gui-hotlist.h" #include "../gui/gui-input.h" #include "../gui/gui-keyboard.h" #include "../gui/gui-status.h" @@ -481,20 +482,20 @@ command_buffer (void *data, struct t_gui_buffer *buffer, GUI_COLOR(GUI_COLOR_CHAT)); switch (number) { - case 0: + case GUI_HOTLIST_LOW: gui_chat_printf (NULL, _("(hotlist: never)")); break; - case 1: + case GUI_HOTLIST_MESSAGE: gui_chat_printf (NULL, _("(hotlist: highlights)")); break; - case 2: + case GUI_HOTLIST_PRIVATE: gui_chat_printf (NULL, _("(hotlist: highlights + " "messages)")); break; - case 3: + case GUI_HOTLIST_HIGHLIGHT: gui_chat_printf (NULL, _("(hotlist: highlights + " "messages + join/part " @@ -2051,13 +2052,13 @@ command_set (void *data, struct t_gui_buffer *buffer, free (value); switch (rc) { - case 0: + case WEECHAT_CONFIG_OPTION_SET_ERROR: gui_chat_printf (NULL, _("%sError: failed to set option \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], argv[1]); return WEECHAT_RC_ERROR; - case -1: + case WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND: gui_chat_printf (NULL, _("%sError: configuration option \"%s\" not " "found"), @@ -2127,21 +2128,21 @@ command_unset (void *data, struct t_gui_buffer *buffer, { switch (config_file_option_unset (ptr_option)) { - case -1: /* error */ + case WEECHAT_CONFIG_OPTION_UNSET_ERROR: gui_chat_printf (NULL, _("%sFailed to unset " "option \"%s\""), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], option_full_name); break; - case 0: /* unset not needed on this option */ + case WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET: break; - case 1: /* option reset */ + case WEECHAT_CONFIG_OPTION_UNSET_OK_RESET: command_set_display_option (ptr_option, _("Option reset: ")); number_reset++; break; - case 2: /* option removed */ + case WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED: gui_chat_printf (NULL, _("Option removed: %s"), option_full_name); diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 7ec4d0291..39604f506 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -37,6 +37,7 @@ #include "wee-string.h" #include "../gui/gui-color.h" #include "../gui/gui-chat.h" +#include "../plugins/plugin.h" struct t_config_file *config_files = NULL; @@ -734,9 +735,14 @@ config_file_string_to_boolean (char *text) /* * 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 + * return one of these values: + * WEECHAT_CONFIG_OPTION_SET_OK_CHANGED + * WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE + * WEECHAT_CONFIG_OPTION_SET_ERROR + * + * 2 if ok (value changed) + * 1 if ok (value is the same) + * 0 if failed */ int @@ -746,43 +752,43 @@ config_file_option_reset (struct t_config_option *option, int run_callback) char value[256], *option_full_name; if (!option) - return 0; + return WEECHAT_CONFIG_OPTION_SET_ERROR; - rc = 0; + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; value[0] = '\0'; switch (option->type) { case CONFIG_OPTION_TYPE_BOOLEAN: if (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_DEFAULT(option)) - rc = 1; + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { CONFIG_BOOLEAN(option) = CONFIG_BOOLEAN_DEFAULT(option); snprintf (value, sizeof (value), "%s", CONFIG_BOOLEAN(option) ? config_boolean_true[0] : config_boolean_false[0]); - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } break; case CONFIG_OPTION_TYPE_INTEGER: if (CONFIG_INTEGER(option) == CONFIG_INTEGER_DEFAULT(option)) - rc = 1; + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { CONFIG_INTEGER(option) = CONFIG_INTEGER_DEFAULT(option); snprintf (value, sizeof (value), "%d", CONFIG_INTEGER(option)); - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } break; case CONFIG_OPTION_TYPE_STRING: - rc = 1; + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; if ((!option->value && option->default_value) || (option->value && !option->default_value) || (strcmp ((char *)option->value, (char *)option->default_value) != 0)) - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; if (option->value) free (option->value); if (option->default_value) @@ -794,32 +800,33 @@ config_file_option_reset (struct t_config_option *option, int run_callback) CONFIG_STRING(option)); } else - rc = 0; + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; } else option->value = NULL; break; case CONFIG_OPTION_TYPE_COLOR: if (CONFIG_COLOR(option) == CONFIG_COLOR_DEFAULT(option)) - rc = 1; + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { CONFIG_COLOR(option) = CONFIG_COLOR_DEFAULT(option); snprintf (value, sizeof (value), "%d", CONFIG_COLOR(option)); - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } break; case CONFIG_NUM_OPTION_TYPES: break; } - if ((rc == 2) && run_callback && option->callback_change) + if ((rc == WEECHAT_CONFIG_OPTION_SET_OK_CHANGED) + && run_callback && option->callback_change) { (void)(option->callback_change)(option->callback_change_data, option); } - if (rc > 0) + if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) { if (option->config_file && option->section) { @@ -845,9 +852,10 @@ config_file_option_reset (struct t_config_option *option, int run_callback) /* * config_file_option_set: set value for an option * if value is NULL, then default value for option is set - * return: 2 if ok (value changed) - * 1 if ok (value is the same) - * 0 if failed + * return one of these values: + * WEECHAT_CONFIG_OPTION_SET_OK_CHANGED + * WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE + * WEECHAT_CONFIG_OPTION_SET_ERROR */ int @@ -859,9 +867,9 @@ config_file_option_set (struct t_config_option *option, char *value, char *error, *option_full_name; if (!option) - return 0; + return WEECHAT_CONFIG_OPTION_SET_ERROR; - rc = 0; + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; if (value && option->callback_check_value) { @@ -869,7 +877,7 @@ config_file_option_set (struct t_config_option *option, char *value, (option->callback_check_value_data, option, value)) - return 0; + return WEECHAT_CONFIG_OPTION_SET_ERROR; } switch (option->type) @@ -882,7 +890,7 @@ config_file_option_set (struct t_config_option *option, char *value, *((int *)option->value) = (*((int *)option->value) == CONFIG_BOOLEAN_TRUE) ? CONFIG_BOOLEAN_FALSE : CONFIG_BOOLEAN_TRUE; - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } else { @@ -890,11 +898,11 @@ config_file_option_set (struct t_config_option *option, char *value, { value_int = config_file_string_to_boolean (value); if (value_int == *((int *)option->value)) - rc = 1; + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { *((int *)option->value) = value_int; - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } } } @@ -943,11 +951,11 @@ config_file_option_set (struct t_config_option *option, char *value, if (value_int >= 0) { if (value_int == *((int *)option->value)) - rc = 1; + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { *((int *)option->value) = value_int; - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } } } @@ -991,29 +999,29 @@ config_file_option_set (struct t_config_option *option, char *value, if (new_value_ok) { if (value_int == *((int *)option->value)) - rc = 1; + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { *((int *)option->value) = value_int; - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } } } } break; case CONFIG_OPTION_TYPE_STRING: - rc = 1; + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; if ((!option->value && value) || (option->value && !value) || (strcmp ((char *)option->value, value) != 0)) - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; if (option->value) free (option->value); if (value) { option->value = strdup (value); if (!option->value) - rc = 0; + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; } else option->value = NULL; @@ -1049,11 +1057,11 @@ config_file_option_set (struct t_config_option *option, char *value, if (value_int >= 0) { if (value_int == *((int *)option->value)) - rc = 1; + rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; else { *((int *)option->value) = value_int; - rc = 2; + rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } } break; @@ -1061,12 +1069,13 @@ config_file_option_set (struct t_config_option *option, char *value, break; } - if ((rc == 2) && run_callback && option->callback_change) + if ((rc == WEECHAT_CONFIG_OPTION_SET_OK_CHANGED) + && run_callback && option->callback_change) { (void)(option->callback_change)(option->callback_change_data, option); } - if (rc > 0) + if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) { if (option->config_file && option->section) { @@ -1091,10 +1100,11 @@ config_file_option_set (struct t_config_option *option, char *value, /* * config_file_option_unset: unset/reset option - * return: -1 if failed - * 0 if reset not needed - * 1 if option reset - * 2 if option removed + * return one of these values: + * WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET + * WEECHAT_CONFIG_OPTION_UNSET_OK_RESET + * WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED + * WEECHAT_CONFIG_OPTION_UNSET_ERROR */ int @@ -1102,7 +1112,7 @@ config_file_option_unset (struct t_config_option *option) { int rc; - rc = 0; + rc = WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET; if (option->section && option->section->user_can_delete_options) { @@ -1114,21 +1124,21 @@ config_file_option_unset (struct t_config_option *option) option); } config_file_option_free (option); - rc = 2; + rc = WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; } else { /* reset value */ switch (config_file_option_reset (option, 1)) { - case 0: - rc = -1; + case WEECHAT_CONFIG_OPTION_SET_ERROR: + rc = WEECHAT_CONFIG_OPTION_UNSET_ERROR; break; - case 1: - rc = 0; + case WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE: + rc = WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET; break; - case 2: - rc = 1; + case WEECHAT_CONFIG_OPTION_SET_OK_CHANGED: + rc = WEECHAT_CONFIG_OPTION_UNSET_OK_RESET; break; } } @@ -1207,10 +1217,11 @@ config_file_option_get_pointer (struct t_config_option *option, char *property) /* * config_file_option_set_with_string: set value for an option (with a string * for name of option) - * return: 2 if ok (value changed) - * 1 if ok (value is the same) - * 0 if failed to set option - * -1 if option is not found + * return one of these values: + * WEECHAT_CONFIG_OPTION_SET_OK_CHANGED + * WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE + * WEECHAT_CONFIG_OPTION_SET_ERROR + * WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND */ int @@ -1222,7 +1233,7 @@ config_file_option_set_with_string (char *option_name, char *value) struct t_config_option *ptr_option; char *pos_option; - rc = 0; + rc = WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND; config_file_search_with_string (option_name, &ptr_config, &ptr_section, &ptr_option, &pos_option); @@ -1242,8 +1253,11 @@ config_file_option_set_with_string (char *option_name, char *value) ptr_section, pos_option, value); - if (rc > 0) + if ((rc == WEECHAT_CONFIG_OPTION_SET_OK_CHANGED) + || (rc == WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE)) + { hook_config_exec (option_name, value); + } } } } @@ -1253,10 +1267,11 @@ config_file_option_set_with_string (char *option_name, char *value) /* * config_file_option_unset_with_string: unset/reset option - * return: -1 if failed - * 0 if reset not needed - * 1 if option reset - * 2 if option removed + * return one of these values: + * WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET + * WEECHAT_CONFIG_OPTION_UNSET_OK_RESET + * WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED + * WEECHAT_CONFIG_OPTION_UNSET_ERROR */ int @@ -1265,7 +1280,7 @@ config_file_option_unset_with_string (char *option_name) struct t_config_option *ptr_option; int rc; - rc = -1; + rc = WEECHAT_CONFIG_OPTION_UNSET_ERROR; config_file_search_with_string (option_name, NULL, NULL, &ptr_option, NULL); @@ -1448,9 +1463,10 @@ config_file_write_line (struct t_config_file *config_file, /* * config_file_write_internal: write a configuration file * (should not be called directly) - * return: 0 if ok - * -1 if error writing file - * -2 if not enough memory + * return one of these values: + * WEECHAT_CONFIG_WRITE_OK + * WEECHAT_CONFIG_WRITE_ERROR + * WEECHAT_CONFIG_WRITE_MEMORY_ERROR */ int @@ -1464,14 +1480,14 @@ config_file_write_internal (struct t_config_file *config_file, struct t_config_option *ptr_option; if (!config_file) - return -1; + return WEECHAT_CONFIG_WRITE_ERROR; /* build filename */ filename_length = strlen (weechat_home) + strlen (config_file->filename) + 2; filename = malloc (filename_length); if (!filename) - return -2; + return WEECHAT_CONFIG_WRITE_MEMORY_ERROR; snprintf (filename, filename_length, "%s%s%s", weechat_home, DIR_SEPARATOR, config_file->filename); @@ -1481,7 +1497,7 @@ config_file_write_internal (struct t_config_file *config_file, if (!filename2) { free (filename); - return -2; + return WEECHAT_CONFIG_WRITE_MEMORY_ERROR; } snprintf (filename2, filename_length + 32, "%s.weechattmp", filename); @@ -1495,7 +1511,7 @@ config_file_write_internal (struct t_config_file *config_file, filename2); free (filename); free (filename2); - return -1; + return WEECHAT_CONFIG_WRITE_ERROR; } log_printf (_("Writing configuration file %s %s"), @@ -1556,16 +1572,19 @@ config_file_write_internal (struct t_config_file *config_file, free (filename); free (filename2); + if (rc != 0) - return -1; - return 0; + return WEECHAT_CONFIG_WRITE_ERROR; + + return WEECHAT_CONFIG_WRITE_OK; } /* * config_file_write: write a configuration file - * return: 0 if ok - * -1 if error writing file - * -2 if not enough memory + * return one of these values: + * WEECHAT_CONFIG_WRITE_OK + * WEECHAT_CONFIG_WRITE_ERROR + * WEECHAT_CONFIG_WRITE_MEMORY_ERROR */ int @@ -1577,9 +1596,10 @@ config_file_write (struct t_config_file *config_file) /* * config_file_read_internal: read a configuration file * (should not be called directly) - * return: 0 = successful - * -1 = config file file not found - * -2 = error in config file + * return one of these values: + * WEECHAT_CONFIG_READ_OK + * WEECHAT_CONFIG_READ_MEMORY_ERROR + * WEECHAT_CONFIG_READ_FILE_NOT_FOUND */ int @@ -1592,13 +1612,13 @@ config_file_read_internal (struct t_config_file *config_file, int reload) char line[1024], *ptr_line, *ptr_line2, *pos, *pos2; if (!config_file) - return -1; + return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; /* build filename */ filename_length = strlen (weechat_home) + strlen (config_file->filename) + 2; filename = malloc (filename_length); if (!filename) - return -2; + return WEECHAT_CONFIG_READ_MEMORY_ERROR; snprintf (filename, filename_length, "%s%s%s", weechat_home, DIR_SEPARATOR, config_file->filename); config_file->file = fopen (filename, "r"); @@ -1613,7 +1633,7 @@ config_file_read_internal (struct t_config_file *config_file, int reload) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], filename); free (filename); - return -1; + return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; } } @@ -1744,7 +1764,7 @@ config_file_read_internal (struct t_config_file *config_file, int reload) } else { - rc = -1; + rc = WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND; ptr_option = config_file_search_option (config_file, ptr_section, line); @@ -1770,7 +1790,7 @@ config_file_read_internal (struct t_config_file *config_file, int reload) switch (rc) { - case -1: + case WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND: if (ptr_section) gui_chat_printf (NULL, _("%sWarning: %s, line %d: " @@ -1789,7 +1809,7 @@ config_file_read_internal (struct t_config_file *config_file, int reload) filename, line_number, line); break; - case 0: + case WEECHAT_CONFIG_OPTION_SET_ERROR: gui_chat_printf (NULL, _("%sWarning: %s, line %d: " "invalid value for option " @@ -1808,14 +1828,15 @@ config_file_read_internal (struct t_config_file *config_file, int reload) config_file->file = NULL; free (filename); - return 0; + return WEECHAT_CONFIG_READ_OK; } /* * config_file_read: read a configuration file - * return: 0 = successful - * -1 = config file file not found - * -2 = error in config file + * return one of these values: + * WEECHAT_CONFIG_READ_OK + * WEECHAT_CONFIG_READ_MEMORY_ERROR + * WEECHAT_CONFIG_READ_FILE_NOT_FOUND */ int @@ -1826,9 +1847,10 @@ 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 + * return one of these values: + * WEECHAT_CONFIG_READ_OK + * WEECHAT_CONFIG_READ_MEMORY_ERROR + * WEECHAT_CONFIG_READ_FILE_NOT_FOUND */ int @@ -1839,7 +1861,7 @@ config_file_reload (struct t_config_file *config_file) int rc; if (!config_file) - return -1; + return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; log_printf (_("Reloading configuration file %s"), config_file->filename); diff --git a/src/core/wee-config.c b/src/core/wee-config.c index cad9b4703..198561248 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -486,9 +486,10 @@ config_change_day_change (void *data, struct t_config_option *option) /* * config_weechat_reload: reload WeeChat configuration file - * return: 0 = successful - * -1 = config file file not found - * -2 = error in config file + * return one of these values: + * WEECHAT_CONFIG_READ_OK + * WEECHAT_CONFIG_READ_MEMORY_ERROR + * WEECHAT_CONFIG_READ_FILE_NOT_FOUND */ int @@ -511,7 +512,7 @@ config_weechat_reload (void *data, struct t_config_file *config_file) rc = config_file_reload (weechat_config_file); - if (rc == 0) + if (rc == WEECHAT_CONFIG_READ_OK) { gui_bar_use_temp_bars (); } @@ -630,8 +631,6 @@ config_weechat_filter_read (void *data, /* * config_weechat_filter_write: write filter section in configuration file - * Return: 0 = successful - * -1 = write error */ void @@ -691,8 +690,6 @@ config_weechat_key_read (void *data, struct t_config_file *config_file, /* * config_weechat_key_write: write key section in configuration file - * Return: 0 = successful - * -1 = write error */ void @@ -1614,9 +1611,10 @@ config_weechat_init () /* * config_weechat_read: read WeeChat configuration file - * return: 0 = successful - * -1 = configuration file file not found - * -2 = error in configuration file + * return one of these values: + * WEECHAT_CONFIG_READ_OK + * WEECHAT_CONFIG_READ_MEMORY_ERROR + * WEECHAT_CONFIG_READ_FILE_NOT_FOUND */ int @@ -1625,7 +1623,7 @@ config_weechat_read () int rc; rc = config_file_read (weechat_config_file); - if (rc == 0) + if (rc == WEECHAT_CONFIG_READ_OK) { config_change_infobar_seconds (NULL, NULL); config_change_day_change (NULL, NULL); @@ -1637,8 +1635,10 @@ config_weechat_read () /* * config_weechat_write: write WeeChat configuration file - * return: 0 if ok - * < 0 if error + * return one of these values: + * WEECHAT_CONFIG_WRITE_OK + * WEECHAT_CONFIG_WRITE_ERROR + * WEECHAT_CONFIG_WRITE_MEMORY_ERROR */ int |