diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2007-12-17 17:07:08 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2007-12-17 17:07:08 +0100 |
commit | dba084f3d6a65ff8299c79b3867e28b57e50f1be (patch) | |
tree | 4b930f11254cc22148d7bd1b75eab83edcb1f063 /src/core | |
parent | e62ec5204c7061a83860fa6c6c8204414a2dd057 (diff) | |
download | weechat-dba084f3d6a65ff8299c79b3867e28b57e50f1be.zip |
New backlog option in logger plugin, added variable names in .h files, replaced "void *" pointers by structures
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-command.c | 62 | ||||
-rw-r--r-- | src/core/wee-config-file.c | 535 | ||||
-rw-r--r-- | src/core/wee-config-file.h | 90 | ||||
-rw-r--r-- | src/core/wee-config.c | 9 | ||||
-rw-r--r-- | src/core/wee-config.h | 12 | ||||
-rw-r--r-- | src/core/wee-hook.c | 107 | ||||
-rw-r--r-- | src/core/wee-hook.h | 103 | ||||
-rw-r--r-- | src/core/wee-input.c | 1 | ||||
-rw-r--r-- | src/core/wee-input.h | 5 | ||||
-rw-r--r-- | src/core/wee-list.c | 68 | ||||
-rw-r--r-- | src/core/wee-list.h | 31 | ||||
-rw-r--r-- | src/core/wee-log.c | 4 | ||||
-rw-r--r-- | src/core/wee-log.h | 2 | ||||
-rw-r--r-- | src/core/wee-string.c | 36 | ||||
-rw-r--r-- | src/core/wee-string.h | 36 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 2 | ||||
-rw-r--r-- | src/core/wee-utf8.c | 8 | ||||
-rw-r--r-- | src/core/wee-utf8.h | 28 | ||||
-rw-r--r-- | src/core/wee-util.c | 8 | ||||
-rw-r--r-- | src/core/wee-util.h | 15 | ||||
-rw-r--r-- | src/core/weechat.c | 4 | ||||
-rw-r--r-- | src/core/weechat.h | 4 |
22 files changed, 698 insertions, 472 deletions
diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 77c70e3a8..66e9727ca 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -38,6 +38,7 @@ #include "wee-string.h" #include "wee-utf8.h" #include "wee-list.h" +#include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" #include "../gui/gui-color.h" #include "../gui/gui-history.h" @@ -54,7 +55,7 @@ */ int -command_buffer (void *data, void *buffer, +command_buffer (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_gui_buffer *ptr_buffer; @@ -84,7 +85,7 @@ command_buffer (void *data, void *buffer, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS), GUI_COLOR(GUI_COLOR_CHAT), (ptr_buffer->plugin) ? - ((struct t_weechat_plugin *)ptr_buffer->plugin)->name : + ptr_buffer->plugin->name : "weechat", ptr_buffer->category, ptr_buffer->name); @@ -114,10 +115,10 @@ command_buffer (void *data, void *buffer, { if (argv[2][0] == '+') gui_buffer_move_to_number (buffer, - ((struct t_gui_buffer *)buffer)->number + ((int) number)); + buffer->number + ((int) number)); else if (argv[2][0] == '-') gui_buffer_move_to_number (buffer, - ((struct t_gui_buffer *)buffer)->number - ((int) number)); + buffer->number - ((int) number)); else gui_buffer_move_to_number (buffer, (int) number); } @@ -132,7 +133,7 @@ command_buffer (void *data, void *buffer, } else if (string_strcasecmp (argv[1], "close") == 0) { - if (!((struct t_gui_buffer *)buffer)->plugin) + if (!buffer->plugin) { gui_chat_printf (NULL, _("%sError: WeeChat main buffer can't be " @@ -140,7 +141,7 @@ command_buffer (void *data, void *buffer, gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_ERROR; } - gui_buffer_free (buffer, 1); + gui_buffer_close (buffer, 1); gui_status_draw (gui_current_window->buffer, 1); gui_input_draw (gui_current_window->buffer, 1); } @@ -186,7 +187,7 @@ command_buffer (void *data, void *buffer, "%d %s"), gui_chat_prefix[GUI_CHAT_PREFIX_INFO], GUI_COLOR(GUI_COLOR_CHAT_BUFFER), - ((struct t_gui_buffer *)buffer)->name, + buffer->name, GUI_COLOR(GUI_COLOR_CHAT), number, GUI_COLOR(GUI_COLOR_CHAT)); @@ -258,7 +259,7 @@ command_buffer (void *data, void *buffer, number = strtol (argv[1] + 1, &error, 10); if (error && (error[0] == '\0')) { - target_buffer = ((struct t_gui_buffer *)buffer)->number - (int) number; + target_buffer = buffer->number - (int) number; if (target_buffer < 1) target_buffer = (last_gui_buffer) ? last_gui_buffer->number + target_buffer : 1; @@ -273,7 +274,7 @@ command_buffer (void *data, void *buffer, number = strtol (argv[1] + 1, &error, 10); if (error && (error[0] == '\0')) { - target_buffer = ((struct t_gui_buffer *)buffer)->number + (int) number; + target_buffer = buffer->number + (int) number; if (last_gui_buffer && target_buffer > last_gui_buffer->number) target_buffer -= last_gui_buffer->number; gui_buffer_switch_by_number (gui_current_window, @@ -321,7 +322,7 @@ command_buffer (void *data, void *buffer, */ int -command_builtin (void *data, void *buffer, +command_builtin (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *command; @@ -354,7 +355,7 @@ command_builtin (void *data, void *buffer, */ int -command_clear (void *data, void *buffer, +command_clear (void *data, struct t_gui_buffer *buffer, int argc, char**argv, char **argv_eol) { struct t_gui_buffer *ptr_buffer; @@ -435,7 +436,7 @@ command_debug_display_windows (struct t_gui_window_tree *tree, int indent) */ int -command_debug (void *data, void *buffer, +command_debug (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { /* make C compiler happy */ @@ -479,7 +480,7 @@ command_debug (void *data, void *buffer, */ int -command_help (void *data, void *buffer, +command_help (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_hook *ptr_hook; @@ -605,7 +606,7 @@ command_help (void *data, void *buffer, */ int -command_history (void *data, void *buffer, +command_history (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_gui_history *ptr_history; @@ -628,10 +629,10 @@ command_history (void *data, void *buffer, n_user = atoi (argv[1]); } - if (((struct t_gui_buffer *)buffer)->history) + if (buffer->history) { n_total = 1; - for (ptr_history = ((struct t_gui_buffer *)buffer)->history; + for (ptr_history = buffer->history; ptr_history->next_history; ptr_history = ptr_history->next_history) { @@ -696,7 +697,7 @@ command_key_display (t_gui_key *key, int new_key) */ int -command_key (void *data, void *buffer, +command_key (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *args, *internal_code; @@ -1059,7 +1060,7 @@ command_plugin_list (char *name, int full) */ int -command_plugin (void *data, void *buffer, +command_plugin (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { /* make C compiler happy */ @@ -1123,7 +1124,7 @@ command_plugin (void *data, void *buffer, */ int -command_quit (void *data, void *buffer, +command_quit (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { /* make C compiler happy */ @@ -1132,7 +1133,7 @@ command_quit (void *data, void *buffer, (void) argc; (void) argv; - hook_signal_exec ("quit", + hook_signal_send ("quit", (argc > 1) ? argv_eol[1] : CONFIG_STRING(config_look_default_msg_quit)); @@ -1146,7 +1147,7 @@ command_quit (void *data, void *buffer, */ int -command_reload (void *data, void *buffer, +command_reload (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { /* make C compiler happy */ @@ -1177,7 +1178,7 @@ command_reload (void *data, void *buffer, gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); /* tell to plugins to reload their configuration */ - hook_signal_exec ("config_reload", NULL); + hook_signal_send ("config_reload", NULL); return WEECHAT_RC_OK; } @@ -1187,7 +1188,7 @@ command_reload (void *data, void *buffer, */ int -command_save (void *data, void *buffer, +command_save (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { /* make C compiler happy */ @@ -1339,7 +1340,7 @@ command_set_display_option_list (struct t_config_file *config_file, */ int -command_set (void *data, void *buffer, +command_set (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *value; @@ -1407,7 +1408,8 @@ command_set (void *data, void *buffer, } value = string_remove_quotes (argv_eol[3], "'\""); rc = config_file_option_set (ptr_option, - (value) ? value : argv_eol[3]); + (value) ? value : argv_eol[3], + 0); if (value) free (value); if (rc > 0) @@ -1437,7 +1439,7 @@ command_set (void *data, void *buffer, */ int -command_setp (void *data, void *buffer, +command_setp (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { char *pos, *ptr_name, *value; @@ -1557,7 +1559,7 @@ command_setp (void *data, void *buffer, */ int -command_upgrade (void *data, void *buffer, +command_upgrade (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { /*int filename_length; @@ -1602,7 +1604,7 @@ command_upgrade (void *data, void *buffer, } filename_length = strlen (weechat_home) + strlen (WEECHAT_SESSION_NAME) + 2; - filename = (char *) malloc (filename_length * sizeof (char)); + filename = (char *)malloc (filename_length * sizeof (char)); if (!filename) return -2; snprintf (filename, filename_length, "%s%s" WEECHAT_SESSION_NAME, @@ -1655,7 +1657,7 @@ command_upgrade (void *data, void *buffer, */ int -command_uptime (void *data, void *buffer, +command_uptime (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { time_t running_time; @@ -1716,7 +1718,7 @@ command_uptime (void *data, void *buffer, */ int -command_window (void *data, void *buffer, +command_window (void *data, struct t_gui_buffer *buffer, int argc, char **argv, char **argv_eol) { struct t_gui_window *ptr_win; diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 55dfddefb..ea4f0cde6 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -40,6 +40,9 @@ struct t_config_file *config_files = NULL; struct t_config_file *last_config_file = NULL; +char *config_boolean_true[] = { "on", "yes", "y", "true", "t", "1", NULL }; +char *config_boolean_false[] = { "off", "no", "n", "false", "f", "0", NULL }; + /* * config_file_search: search a configuration file @@ -66,7 +69,7 @@ config_file_search (char *filename) */ struct t_config_file * -config_file_new (void *plugin, char *filename) +config_file_new (struct t_weechat_plugin *plugin, char *filename) { struct t_config_file *new_config_file; @@ -105,7 +108,8 @@ config_file_new (void *plugin, char *filename) */ int -config_file_valid_for_plugin (void *plugin, struct t_config_file *config_file) +config_file_valid_for_plugin (struct t_weechat_plugin *plugin, + struct t_config_file *config_file) { struct t_config_file *ptr_config; @@ -113,7 +117,7 @@ config_file_valid_for_plugin (void *plugin, struct t_config_file *config_file) ptr_config = ptr_config->next_config) { if ((ptr_config == config_file) - && (ptr_config->plugin == (struct t_weechat_plugin *)plugin)) + && (ptr_config->plugin == plugin)) return 1; } @@ -127,9 +131,12 @@ config_file_valid_for_plugin (void *plugin, struct t_config_file *config_file) struct t_config_section * config_file_new_section (struct t_config_file *config_file, char *name, - void (*callback_read)(void *, char *, char *), - void (*callback_write)(void *, char *), - void (*callback_write_default)(void *, char *)) + void (*callback_read)(struct t_config_file *config_file, + char *option_name, char *value), + void (*callback_write)(struct t_config_file *config_file, + char *section_name), + void (*callback_write_default)(struct t_config_file *, + char *section_name)) { struct t_config_section *new_section; @@ -186,7 +193,7 @@ config_file_search_section (struct t_config_file *config_file, */ int -config_file_section_valid_for_plugin (void *plugin, +config_file_section_valid_for_plugin (struct t_weechat_plugin *plugin, struct t_config_section *section) { struct t_config_file *ptr_config; @@ -195,7 +202,7 @@ config_file_section_valid_for_plugin (void *plugin, for (ptr_config = config_files; ptr_config; ptr_config = ptr_config->next_config) { - if (ptr_config->plugin == (struct t_weechat_plugin *)plugin) + if (ptr_config->plugin == plugin) { for (ptr_section = ptr_config->sections; ptr_section; ptr_section = ptr_section->next_section) @@ -259,8 +266,7 @@ config_file_new_option (struct t_config_section *section, char *name, new_option->string_values = NULL; new_option->min = CONFIG_BOOLEAN_FALSE; new_option->max = CONFIG_BOOLEAN_TRUE; - int_value = (config_file_string_to_boolean (default_value) == CONFIG_BOOLEAN_TRUE) ? - CONFIG_BOOLEAN_TRUE : CONFIG_BOOLEAN_FALSE; + int_value = config_file_string_to_boolean (default_value); new_option->default_value = malloc (sizeof (int)); *((int *)new_option->default_value) = int_value; new_option->value = malloc (sizeof (int)); @@ -386,7 +392,7 @@ config_file_search_option (struct t_config_file *config_file, */ int -config_file_option_valid_for_plugin (void *plugin, +config_file_option_valid_for_plugin (struct t_weechat_plugin *plugin, struct t_config_option *option) { struct t_config_file *ptr_config; @@ -396,7 +402,7 @@ config_file_option_valid_for_plugin (void *plugin, for (ptr_config = config_files; ptr_config; ptr_config = ptr_config->next_config) { - if (ptr_config->plugin == (struct t_weechat_plugin *)plugin) + if (ptr_config->plugin == plugin) { for (ptr_section = ptr_config->sections; ptr_section; ptr_section = ptr_section->next_section) @@ -416,31 +422,47 @@ config_file_option_valid_for_plugin (void *plugin, } /* + * config_file_string_boolean_is_valid: return 1 if boolean is valid, otherwise 0 + */ + +int +config_file_string_boolean_is_valid (char *text) +{ + int i; + + for (i = 0; config_boolean_true[i]; i++) + { + if (string_strcasecmp (text, config_boolean_true[i]) == 0) + return 1; + } + + for (i = 0; config_boolean_false[i]; i++) + { + if (string_strcasecmp (text, config_boolean_false[i]) == 0) + return 1; + } + + /* text is not a boolean */ + return 0; +} + +/* * config_file_string_to_boolean: return boolean value of string - * return -1 if error + * (1 for true, 0 for false) */ int config_file_string_to_boolean (char *text) { - if ((string_strcasecmp (text, "on") == 0) - || (string_strcasecmp (text, "yes") == 0) - || (string_strcasecmp (text, "y") == 0) - || (string_strcasecmp (text, "true") == 0) - || (string_strcasecmp (text, "t") == 0) - || (string_strcasecmp (text, "1") == 0)) - return CONFIG_BOOLEAN_TRUE; - - if ((string_strcasecmp (text, "off") == 0) - || (string_strcasecmp (text, "no") == 0) - || (string_strcasecmp (text, "n") == 0) - || (string_strcasecmp (text, "false") == 0) - || (string_strcasecmp (text, "f") == 0) - || (string_strcasecmp (text, "0") == 0)) - return CONFIG_BOOLEAN_FALSE; - - /* invalid text */ - return -1; + int i; + + for (i = 0; config_boolean_true[i]; i++) + { + if (string_strcasecmp (text, config_boolean_true[i]) == 0) + return CONFIG_BOOLEAN_TRUE; + } + + return CONFIG_BOOLEAN_FALSE; } /* @@ -451,7 +473,8 @@ config_file_string_to_boolean (char *text) */ int -config_file_option_set (struct t_config_option *option, char *new_value) +config_file_option_set (struct t_config_option *option, char *new_value, + int run_callback) { int new_value_int, i, rc; long number; @@ -465,12 +488,14 @@ config_file_option_set (struct t_config_option *option, char *new_value) case CONFIG_OPTION_BOOLEAN: if (!new_value) return 0; - new_value_int = config_file_string_to_boolean (new_value); - if (new_value_int < 0) + if (!config_file_string_boolean_is_valid (new_value)) return 0; + new_value_int = config_file_string_to_boolean (new_value); if (new_value_int == *((int *)option->value)) return 1; *((int *)option->value) = new_value_int; + if (run_callback && option->callback_change) + (void) (option->callback_change) (); return 2; case CONFIG_OPTION_INTEGER: if (!new_value) @@ -492,6 +517,8 @@ config_file_option_set (struct t_config_option *option, char *new_value) if (new_value_int == *((int *)option->value)) return 1; *((int *)option->value) = new_value_int; + if (run_callback && option->callback_change) + (void) (option->callback_change) (); return 2; } else @@ -503,6 +530,8 @@ config_file_option_set (struct t_config_option *option, char *new_value) if (number == *((int *)option->value)) return 1; *((int *)option->value) = number; + if (run_callback && option->callback_change) + (void) (option->callback_change) (); return 2; } } @@ -523,6 +552,8 @@ config_file_option_set (struct t_config_option *option, char *new_value) } else option->value = NULL; + if (run_callback && (rc == 2) && option->callback_change) + (void) (option->callback_change) (); return rc; case CONFIG_OPTION_COLOR: if (!gui_color_assign (&new_value_int, new_value)) @@ -530,6 +561,8 @@ config_file_option_set (struct t_config_option *option, char *new_value) if (new_value_int == *((int *)option->value)) return 1; *((int *)option->value) = new_value_int; + if (run_callback && option->callback_change) + (void) (option->callback_change) (); return 2; } @@ -592,6 +625,259 @@ config_file_option_reset (struct t_config_option *option) } /* + * config_file_option_boolean: return boolean value of an option + */ + +int +config_file_option_boolean (struct t_config_option *option) +{ + if (option->type == CONFIG_OPTION_BOOLEAN) + return CONFIG_BOOLEAN(option); + else + return 0; +} + +/* + * config_file_option_integer: return integer value of an option + */ + +int +config_file_option_integer (struct t_config_option *option) +{ + switch (option->type) + { + case CONFIG_OPTION_BOOLEAN: + if (CONFIG_BOOLEAN(option) == CONFIG_BOOLEAN_TRUE) + return 1; + else + return 0; + case CONFIG_OPTION_INTEGER: + case CONFIG_OPTION_COLOR: + return CONFIG_INTEGER(option); + case CONFIG_OPTION_STRING: + return 0; + } + return 0; +} + +/* + * config_file_option_string: return string value of an option + */ + +char * +config_file_option_string (struct t_config_option *option) +{ + switch (option->type) + { + case CONFIG_OPTION_STRING: + return CONFIG_STRING(option); + case CONFIG_OPTION_INTEGER: + if (option->string_values) + return option->string_values[CONFIG_INTEGER(option)]; + return NULL; + default: + return NULL; + } + return NULL; +} + +/* + * config_file_option_color: return color value of an option + */ + +int +config_file_option_color (struct t_config_option *option) +{ + if (option->type == CONFIG_OPTION_COLOR) + return CONFIG_COLOR(option); + else + return 0; +} + +/* + * config_file_write_option: write an option in a config file + */ + +void +config_file_write_option (struct t_config_file *config_file, + struct t_config_option *option, + int default_value) +{ + void *value; + + if (!config_file || !config_file->file || !option) + return; + + value = (default_value) ? option->default_value : option->value; + + switch (option->type) + { + case CONFIG_OPTION_BOOLEAN: + string_iconv_fprintf (config_file->file, "%s = %s\n", + option->name, + (*((int *)value)) == CONFIG_BOOLEAN_TRUE ? + "on" : "off"); + break; + case CONFIG_OPTION_INTEGER: + if (option->string_values) + string_iconv_fprintf (config_file->file, "%s = %s\n", + option->name, + option->string_values[*((int *)value)]); + else + string_iconv_fprintf (config_file->file, "%s = %d\n", + option->name, + *((int *)value)); + break; + case CONFIG_OPTION_STRING: + string_iconv_fprintf (config_file->file, "%s = \"%s\"\n", + option->name, + (char *)value); + break; + case CONFIG_OPTION_COLOR: + string_iconv_fprintf (config_file->file, "%s = %s\n", + option->name, + gui_color_get_name (*((int *)value))); + break; + } +} + +/* + * config_file_write_line: write a line in a config file + * if value is NULL, then write a section with [ ] around + */ + +void +config_file_write_line (struct t_config_file *config_file, + char *option_name, char *value, ...) +{ + char buf[4096]; + va_list argptr; + + va_start (argptr, value); + vsnprintf (buf, sizeof (buf) - 1, value, argptr); + va_end (argptr); + + if (!buf[0]) + string_iconv_fprintf (config_file->file, "\n[%s]\n", + option_name); + else + { + string_iconv_fprintf (config_file->file, "%s = %s\n", + option_name, buf); + } +} + +/* + * 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 + */ + +int +config_file_write_internal (struct t_config_file *config_file, int default_options) +{ + int filename_length, rc; + char *filename, *filename2; + time_t current_time; + struct t_config_section *ptr_section; + struct t_config_option *ptr_option; + + if (!config_file) + return -1; + + filename_length = strlen (weechat_home) + + strlen (config_file->filename) + 2; + filename = + (char *)malloc (filename_length * sizeof (char)); + if (!filename) + return -2; + snprintf (filename, filename_length, "%s%s%s", + weechat_home, DIR_SEPARATOR, config_file->filename); + + filename2 = (char *)malloc ((filename_length + 32) * sizeof (char)); + if (!filename2) + { + free (filename); + return -2; + } + snprintf (filename2, filename_length + 32, "%s.weechattmp", filename); + + if ((config_file->file = fopen (filename2, "w")) == NULL) + { + gui_chat_printf (NULL, + _("Error: cannot create file \"%s\"\n"), + filename2); + free (filename); + free (filename2); + return -1; + } + + current_time = time (NULL); + string_iconv_fprintf (config_file->file, + _("#\n# %s configuration file, created by " + "%s v%s on %s"), + PACKAGE_NAME, PACKAGE_NAME, PACKAGE_VERSION, + ctime (¤t_time)); + string_iconv_fprintf (config_file->file, + _("# WARNING! Be careful when editing this file, " + "WeeChat may write it at any time.\n#\n")); + + for (ptr_section = config_file->sections; ptr_section; + ptr_section = ptr_section->next_section) + { + /* call write callback if defined for section */ + if (default_options && ptr_section->callback_write_default) + { + (void) (ptr_section->callback_write_default) (config_file, + ptr_section->name); + } + else if (!default_options && ptr_section->callback_write) + { + (void) (ptr_section->callback_write) (config_file, + ptr_section->name); + } + else + { + /* write all options for section */ + string_iconv_fprintf (config_file->file, + "\n[%s]\n", ptr_section->name); + for (ptr_option = ptr_section->options; ptr_option; + ptr_option = ptr_option->next_option) + { + config_file_write_option (config_file, ptr_option, + default_options); + } + } + } + + fclose (config_file->file); + config_file->file = NULL; + chmod (filename2, 0600); + unlink (filename); + rc = rename (filename2, filename); + free (filename); + free (filename2); + if (rc != 0) + return -1; + return 0; +} + +/* + * config_file_write: write a configuration file + * return: 0 if ok + * -1 if error writing file + * -2 if not enough memory + */ + +int +config_file_write (struct t_config_file *config_file) +{ + return config_file_write_internal (config_file, 0); +} + +/* * config_file_read: read a configuration file * return: 0 = successful * -1 = config file file not found @@ -611,14 +897,14 @@ config_file_read (struct t_config_file *config_file) return -1; filename_length = strlen (weechat_home) + strlen (config_file->filename) + 2; - filename = (char *) malloc (filename_length * sizeof (char)); + filename = (char *)malloc (filename_length * sizeof (char)); if (!filename) return -2; snprintf (filename, filename_length, "%s%s%s", weechat_home, DIR_SEPARATOR, config_file->filename); if ((config_file->file = fopen (filename, "r")) == NULL) { - config_file_write (config_file, 1); + config_file_write_internal (config_file, 1); if ((config_file->file = fopen (filename, "r")) == NULL) { gui_chat_printf (NULL, @@ -760,7 +1046,7 @@ config_file_read (struct t_config_file *config_file) line); if (ptr_option) { - rc = config_file_option_set (ptr_option, pos); + rc = config_file_option_set (ptr_option, pos, 1); ptr_option->loaded = 1; } } @@ -791,10 +1077,6 @@ config_file_read (struct t_config_file *config_file) "\"%s\"\n"), filename, line_number, line); break; - case 2: - if (ptr_option && ptr_option->callback_change) - (void) (ptr_option->callback_change) (); - break; } } } @@ -865,175 +1147,6 @@ config_file_reload (struct t_config_file *config_file) } /* - * config_file_write_option: write an option in a config file - */ - -void -config_file_write_option (struct t_config_file *config_file, - struct t_config_option *option, - int default_value) -{ - void *value; - - if (!config_file || !config_file->file || !option) - return; - - value = (default_value) ? option->default_value : option->value; - - switch (option->type) - { - case CONFIG_OPTION_BOOLEAN: - string_iconv_fprintf (config_file->file, "%s = %s\n", - option->name, - (*((int *)value)) == CONFIG_BOOLEAN_TRUE ? - "on" : "off"); - break; - case CONFIG_OPTION_INTEGER: - if (option->string_values) - string_iconv_fprintf (config_file->file, "%s = %s\n", - option->name, - option->string_values[*((int *)value)]); - else - string_iconv_fprintf (config_file->file, "%s = %d\n", - option->name, - *((int *)value)); - break; - case CONFIG_OPTION_STRING: - string_iconv_fprintf (config_file->file, "%s = \"%s\"\n", - option->name, - (char *)value); - break; - case CONFIG_OPTION_COLOR: - string_iconv_fprintf (config_file->file, "%s = %s\n", - option->name, - gui_color_get_name (*((int *)value))); - break; - } -} - -/* - * config_file_write_line: write a line in a config file - * if value is NULL, then write a section with [ ] around - */ - -void -config_file_write_line (struct t_config_file *config_file, - char *option_name, char *value, ...) -{ - char buf[4096]; - va_list argptr; - - va_start (argptr, value); - vsnprintf (buf, sizeof (buf) - 1, value, argptr); - va_end (argptr); - - if (!buf[0]) - string_iconv_fprintf (config_file->file, "\n[%s]\n", - option_name); - else - { - string_iconv_fprintf (config_file->file, "%s = %s\n", - option_name, buf); - } -} - -/* - * config_file_write: write a configuration file - * return: 0 if ok - * -1 if error writing file - * -2 if not enough memory - */ - -int -config_file_write (struct t_config_file *config_file, int default_options) -{ - int filename_length, rc; - char *filename, *filename2; - time_t current_time; - struct t_config_section *ptr_section; - struct t_config_option *ptr_option; - - if (!config_file) - return -1; - - filename_length = strlen (weechat_home) + - strlen (config_file->filename) + 2; - filename = - (char *) malloc (filename_length * sizeof (char)); - if (!filename) - return -2; - snprintf (filename, filename_length, "%s%s%s", - weechat_home, DIR_SEPARATOR, config_file->filename); - - filename2 = (char *) malloc ((filename_length + 32) * sizeof (char)); - if (!filename2) - { - free (filename); - return -2; - } - snprintf (filename2, filename_length + 32, "%s.weechattmp", filename); - - if ((config_file->file = fopen (filename2, "w")) == NULL) - { - gui_chat_printf (NULL, - _("Error: cannot create file \"%s\"\n"), - filename2); - free (filename); - free (filename2); - return -1; - } - - current_time = time (NULL); - string_iconv_fprintf (config_file->file, - _("#\n# %s configuration file, created by " - "%s v%s on %s"), - PACKAGE_NAME, PACKAGE_NAME, PACKAGE_VERSION, - ctime (¤t_time)); - string_iconv_fprintf (config_file->file, - _("# WARNING! Be careful when editing this file, " - "WeeChat may write it at any time.\n#\n")); - - for (ptr_section = config_file->sections; ptr_section; - ptr_section = ptr_section->next_section) - { - /* call write callback if defined for section */ - if (default_options && ptr_section->callback_write_default) - { - (void) (ptr_section->callback_write_default) (config_file, - ptr_section->name); - } - else if (!default_options && ptr_section->callback_write) - { - (void) (ptr_section->callback_write) (config_file, - ptr_section->name); - } - else - { - /* write all options for section */ - string_iconv_fprintf (config_file->file, - "\n[%s]\n", ptr_section->name); - for (ptr_option = ptr_section->options; ptr_option; - ptr_option = ptr_option->next_option) - { - config_file_write_option (config_file, ptr_option, - default_options); - } - } - } - - fclose (config_file->file); - config_file->file = NULL; - chmod (filename2, 0600); - unlink (filename); - rc = rename (filename2, filename); - free (filename); - free (filename2); - if (rc != 0) - return -1; - return 0; -} - -/* * config_file_option_free: free an option */ @@ -1159,7 +1272,7 @@ config_file_free_all () */ void -config_file_free_all_plugin (void *plugin) +config_file_free_all_plugin (struct t_weechat_plugin *plugin) { struct t_config_file *ptr_config, *next_config; diff --git a/src/core/wee-config-file.h b/src/core/wee-config-file.h index b27bf99da..7e347e497 100644 --- a/src/core/wee-config-file.h +++ b/src/core/wee-config-file.h @@ -50,11 +50,14 @@ struct t_config_section { char *name; /* section name */ void (*callback_read) /* called when unknown option */ - (void *, char *, char *); /* is read from config file */ + (struct t_config_file *config_file, /* is read from config file */ + char *option_name, char *value); void (*callback_write) /* called to write special */ - (void *, char *); /* options in config file */ + (struct t_config_file *config_file, /* options in config file */ + char *section_name); void (*callback_write_default) /* called to write default */ - (void *, char *); /* options in config file */ + (struct t_config_file *config_file, /* options in config file */ + char *section_name); struct t_config_option *options; /* options in section */ struct t_config_option *last_option; /* last option in section */ struct t_config_section *prev_section; /* link to previous section */ @@ -84,40 +87,57 @@ struct t_config_option struct t_config_option *next_option; /* link to next option */ }; -extern struct t_config_file *config_file_new (void *, char *); -extern int config_file_valid_for_plugin (void *, struct t_config_file *); -extern struct t_config_section *config_file_new_section (struct t_config_file *, - char *, - void (*)(void *, char *, char *), - void (*)(void *, char *), - void (*)(void *, char *)); -extern struct t_config_section *config_file_search_section (struct t_config_file *, - char *); -extern int config_file_section_valid_for_plugin (void *, struct t_config_section *); -extern struct t_config_option *config_file_new_option (struct t_config_section *, - char *, char *, char *, - char *, int, int, - char *, void (*)()); -extern struct t_config_option *config_file_search_option (struct t_config_file *, - struct t_config_section *, - char *); -extern int config_file_option_valid_for_plugin (void *, struct t_config_option *); -extern int config_file_string_to_boolean (char *); -extern int config_file_option_set (struct t_config_option *, char *); -extern int config_file_option_reset (struct t_config_option *); +extern struct t_config_file *config_file_new (struct t_weechat_plugin *plugin, + char *filename); +extern int config_file_valid_for_plugin (struct t_weechat_plugin *plugin, + struct t_config_file *config_file); +extern struct t_config_section *config_file_new_section (struct t_config_file *config_file, + char *name, + void (*callback_read)(struct t_config_file *config_file, + char *option_name, + char *value), + void (*callback_write)(struct t_config_file *config_file, + char *section_name), + void (*callback_write_default)(struct t_config_file *config_file, + char *section_name)); +extern struct t_config_section *config_file_search_section (struct t_config_file *config_file, + char *section_name); +extern int config_file_section_valid_for_plugin (struct t_weechat_plugin *plugin, + struct t_config_section *); +extern struct t_config_option *config_file_new_option (struct t_config_section *section, + char *name, char *type, + char *description, + char *string_values, + int min, int max, + char *default_value, + void (*callback_change)()); +extern struct t_config_option *config_file_search_option (struct t_config_file *config_file, + struct t_config_section *section, + char *option_name); +extern int config_file_option_valid_for_plugin (struct t_weechat_plugin *plugin, + struct t_config_option *option); +extern int config_file_string_to_boolean (char *text); +extern int config_file_option_set (struct t_config_option *option, + char *new_value, int run_callback); +extern int config_file_option_reset (struct t_config_option *option); +extern int config_file_option_boolean (struct t_config_option *option); +extern int config_file_option_integer (struct t_config_option *option); +extern char *config_file_option_string (struct t_config_option *option); +extern int config_file_option_color (struct t_config_option *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_option_free (struct t_config_section *, - struct t_config_option *); -extern void config_file_section_free (struct t_config_file *, - struct t_config_section *); -extern void config_file_free (struct t_config_file *); +extern void config_file_write_line (struct t_config_file *config_file, + char *option_name, char *value, ...); +extern int config_file_write (struct t_config_file *config_files); +extern int config_file_read (struct t_config_file *config_file); +extern int config_file_reload (struct t_config_file *config_file); +extern void config_file_option_free (struct t_config_section *section, + struct t_config_option *option); +extern void config_file_section_free (struct t_config_file *config_file, + struct t_config_section *section); +extern void config_file_free (struct t_config_file *config_file); extern void config_file_free_all (); -extern void config_file_free_all_plugin (void *); -extern void config_file_print_stdout (struct t_config_file *); +extern void config_file_free_all_plugin (struct t_weechat_plugin *plugin); +extern void config_file_print_stdout (struct t_config_file *config_file); extern void config_file_print_log (); #endif /* wee-config-file.h */ diff --git a/src/core/wee-config.c b/src/core/wee-config.c index cc89254ae..d11a9088e 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -41,11 +41,13 @@ #include "wee-util.h" #include "wee-list.h" #include "wee-string.h" +#include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" #include "../gui/gui-color.h" #include "../gui/gui-hotlist.h" #include "../gui/gui-infobar.h" #include "../gui/gui-keyboard.h" +#include "../gui/gui-nicklist.h" #include "../gui/gui-status.h" #include "../gui/gui-window.h" #include "../plugins/plugin.h" @@ -415,7 +417,7 @@ config_change_day_change () */ void -config_weechat_read_key (void *config_file, +config_weechat_read_key (struct t_config_file *config_file, char *option_name, char *value) { /* make C compiler happy */ @@ -443,7 +445,8 @@ config_weechat_read_key (void *config_file, */ void -config_weechat_write_keys (void *config_file, char *section_name) +config_weechat_write_keys (struct t_config_file *config_file, + char *section_name) { t_gui_key *ptr_key; char *expanded_name, *function_name; @@ -1177,5 +1180,5 @@ int config_weechat_write () { log_printf (_("Saving WeeChat configuration to disk")); - return config_file_write (weechat_config_file, 0); + return config_file_write (weechat_config_file); } diff --git a/src/core/wee-config.h b/src/core/wee-config.h index 040e74f81..15de988d6 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -164,18 +164,6 @@ extern struct t_config_option *config_plugins_path; extern struct t_config_option *config_plugins_autoload; extern struct t_config_option *config_plugins_extension; -extern void config_change_noop (); -extern void config_change_save_on_exit (); -extern void config_change_title (); -extern void config_change_buffers (); -extern void config_change_buffer_content (); -extern void config_change_buffer_time_format (); -extern void config_change_hotlist (); -extern void config_change_read_marker (); -extern void config_change_prefix (); -extern void config_change_color (); -extern void config_change_nicks_colors (); - extern int config_weechat_init (); extern int config_weechat_read (); extern int config_weechat_reload (); diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 31a782f18..e7ac17c45 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -188,7 +188,8 @@ hook_remove_deleted () */ void -hook_init_data (struct t_hook *hook, void *plugin, int type, void *callback_data) +hook_init_data (struct t_hook *hook, struct t_weechat_plugin *plugin, + int type, void *callback_data) { hook->plugin = plugin; hook->type = type; @@ -231,7 +232,7 @@ hook_valid (struct t_hook *hook) */ int -hook_valid_for_plugin (void *plugin, struct t_hook *hook) +hook_valid_for_plugin (struct t_weechat_plugin *plugin, struct t_hook *hook) { int type; struct t_hook *ptr_hook; @@ -242,7 +243,7 @@ hook_valid_for_plugin (void *plugin, struct t_hook *hook) ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && (ptr_hook == hook) - && (ptr_hook->plugin == (struct t_weechat_plugin *)plugin)) + && (ptr_hook->plugin == plugin)) return 1; } } @@ -277,10 +278,9 @@ hook_search_command (char *command) */ struct t_hook * -hook_command (void *plugin, char *command, char *description, +hook_command (struct t_weechat_plugin *plugin, char *command, char *description, char *args, char *args_description, char *completion, - t_hook_callback_command *callback, - void *callback_data) + t_hook_callback_command *callback, void *callback_data) { struct t_hook *ptr_hook,*new_hook; struct t_hook_command *new_hook_command; @@ -341,7 +341,7 @@ hook_command (void *plugin, char *command, char *description, */ int -hook_command_exec (void *buffer, char *string, int only_builtin) +hook_command_exec (struct t_gui_buffer *buffer, char *string, int only_builtin) { struct t_hook *ptr_hook, *next_hook; char **argv, **argv_eol; @@ -369,9 +369,9 @@ hook_command_exec (void *buffer, char *string, int only_builtin) && !ptr_hook->running && (HOOK_COMMAND(ptr_hook, level) == 0) && (!only_builtin || !ptr_hook->plugin) - && (!ptr_hook->plugin - || !((struct t_gui_buffer *)buffer)->plugin - || (((struct t_gui_buffer *)buffer)->plugin == ptr_hook->plugin)) + /*&& (!ptr_hook->plugin + || !buffer->plugin + || (buffer->plugin == ptr_hook->plugin))*/ && (string_strcasecmp (argv[0] + 1, HOOK_COMMAND(ptr_hook, command)) == 0)) { @@ -410,8 +410,9 @@ hook_command_exec (void *buffer, char *string, int only_builtin) */ struct t_hook * -hook_timer (void *plugin, long interval, int align_second, int max_calls, - t_hook_callback_timer *callback, void *callback_data) +hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second, + int max_calls, t_hook_callback_timer *callback, + void *callback_data) { struct t_hook *new_hook; struct t_hook_timer *new_hook_timer; @@ -462,7 +463,7 @@ hook_timer (void *plugin, long interval, int align_second, int max_calls, */ int -hook_timer_time_to_next (struct timeval *tv_time) +hook_timer_time_to_next (struct timeval *tv_timeout) { struct t_hook *ptr_hook; int found; @@ -470,19 +471,19 @@ hook_timer_time_to_next (struct timeval *tv_time) long diff_usec; found = 0; - tv_time->tv_sec = 0; - tv_time->tv_usec = 0; + tv_timeout->tv_sec = 0; + tv_timeout->tv_usec = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_TIMER]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && (!found - || (util_timeval_cmp (&HOOK_TIMER(ptr_hook, next_exec), tv_time) < 0))) + || (util_timeval_cmp (&HOOK_TIMER(ptr_hook, next_exec), tv_timeout) < 0))) { found = 1; - tv_time->tv_sec = HOOK_TIMER(ptr_hook, next_exec).tv_sec; - tv_time->tv_usec = HOOK_TIMER(ptr_hook, next_exec).tv_usec; + tv_timeout->tv_sec = HOOK_TIMER(ptr_hook, next_exec).tv_sec; + tv_timeout->tv_usec = HOOK_TIMER(ptr_hook, next_exec).tv_usec; } } @@ -493,21 +494,21 @@ hook_timer_time_to_next (struct timeval *tv_time) gettimeofday (&tv_now, NULL); /* next timeout is past date! */ - if (util_timeval_cmp (tv_time, &tv_now) < 0) + if (util_timeval_cmp (tv_timeout, &tv_now) < 0) { - tv_time->tv_sec = 0; - tv_time->tv_usec = 0; + tv_timeout->tv_sec = 0; + tv_timeout->tv_usec = 0; return 1; } - tv_time->tv_sec = tv_time->tv_sec - tv_now.tv_sec; - diff_usec = tv_time->tv_usec - tv_now.tv_usec; + tv_timeout->tv_sec = tv_timeout->tv_sec - tv_now.tv_sec; + diff_usec = tv_timeout->tv_usec - tv_now.tv_usec; if (diff_usec >= 0) - tv_time->tv_usec = diff_usec; + tv_timeout->tv_usec = diff_usec; else { - tv_time->tv_sec--; - tv_time->tv_usec = 1000000 + diff_usec; + tv_timeout->tv_sec--; + tv_timeout->tv_usec = 1000000 + diff_usec; } return 1; @@ -593,13 +594,14 @@ hook_search_fd (int fd) */ struct t_hook * -hook_fd (void *plugin, int fd, int flags, +hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read, + int flag_write, int flag_exception, t_hook_callback_fd *callback, void *callback_data) { struct t_hook *new_hook; struct t_hook_fd *new_hook_fd; - if (hook_search_fd (fd)) + if ((fd < 0) || hook_search_fd (fd)) return NULL; new_hook = (struct t_hook *)malloc (sizeof (struct t_hook)); @@ -617,7 +619,13 @@ hook_fd (void *plugin, int fd, int flags, new_hook->hook_data = new_hook_fd; new_hook_fd->callback = callback; new_hook_fd->fd = fd; - new_hook_fd->flags = flags; + new_hook_fd->flags = 0; + if (flag_read) + new_hook_fd->flags |= HOOK_FD_FLAG_READ; + if (flag_write) + new_hook_fd->flags |= HOOK_FD_FLAG_WRITE; + if (flag_exception) + new_hook_fd->flags |= HOOK_FD_FLAG_EXCEPTION; hook_add_to_list (new_hook); @@ -629,14 +637,10 @@ hook_fd (void *plugin, int fd, int flags, */ void -hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *except_fds) +hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) { struct t_hook *ptr_hook; - FD_ZERO (read_fds); - FD_ZERO (write_fds); - FD_ZERO (except_fds); - for (ptr_hook = weechat_hooks[HOOK_TYPE_FD]; ptr_hook; ptr_hook = ptr_hook->next_hook) { @@ -647,7 +651,7 @@ hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *except_fds) if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE) FD_SET (HOOK_FD(ptr_hook, fd), write_fds); if (HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION) - FD_SET (HOOK_FD(ptr_hook, fd), except_fds); + FD_SET (HOOK_FD(ptr_hook, fd), exception_fds); } } } @@ -657,7 +661,7 @@ hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *except_fds) */ void -hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *except_fds) +hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) { struct t_hook *ptr_hook, *next_hook; @@ -675,7 +679,7 @@ hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *except_fds) || ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_WRITE) && (FD_ISSET(HOOK_FD(ptr_hook, fd), write_fds))) || ((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_EXCEPTION) - && (FD_ISSET(HOOK_FD(ptr_hook, fd), except_fds))))) + && (FD_ISSET(HOOK_FD(ptr_hook, fd), exception_fds))))) { ptr_hook->running = 1; (HOOK_FD(ptr_hook, callback)) (ptr_hook->callback_data); @@ -697,8 +701,9 @@ hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *except_fds) */ struct t_hook * -hook_print (void *plugin, void *buffer, char *message, int strip_colors, - t_hook_callback_print *callback, void *callback_data) +hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, + char *message, int strip_colors, t_hook_callback_print *callback, + void *callback_data) { struct t_hook *new_hook; struct t_hook_print *new_hook_print; @@ -717,7 +722,7 @@ hook_print (void *plugin, void *buffer, char *message, int strip_colors, new_hook->hook_data = new_hook_print; new_hook_print->callback = callback; - new_hook_print->buffer = (struct t_gui_buffer *)buffer; + new_hook_print->buffer = buffer; new_hook_print->message = (message) ? strdup (message) : NULL; new_hook_print->strip_colors = strip_colors; @@ -731,7 +736,8 @@ hook_print (void *plugin, void *buffer, char *message, int strip_colors, */ void -hook_print_exec (void *buffer, time_t date, char *prefix, char *message) +hook_print_exec (struct t_gui_buffer *buffer, time_t date, char *prefix, + char *message) { struct t_hook *ptr_hook, *next_hook; char *prefix_no_color, *message_no_color; @@ -759,7 +765,7 @@ hook_print_exec (void *buffer, time_t date, char *prefix, char *message) if (!ptr_hook->deleted && !ptr_hook->running && (!HOOK_PRINT(ptr_hook, buffer) - || ((struct t_gui_buffer *)buffer == HOOK_PRINT(ptr_hook, buffer))) + || (buffer == HOOK_PRINT(ptr_hook, buffer))) && (!HOOK_PRINT(ptr_hook, message) || string_strcasestr (prefix_no_color, HOOK_PRINT(ptr_hook, message)) || string_strcasestr (message_no_color, HOOK_PRINT(ptr_hook, message)))) @@ -787,7 +793,7 @@ hook_print_exec (void *buffer, time_t date, char *prefix, char *message) */ struct t_hook * -hook_signal (void *plugin, char *signal, +hook_signal (struct t_weechat_plugin *plugin, char *signal, t_hook_callback_signal *callback, void *callback_data) { struct t_hook *new_hook; @@ -818,11 +824,11 @@ hook_signal (void *plugin, char *signal, } /* - * hook_signal_exec: execute signal hook + * hook_signal_send: send a signal */ void -hook_signal_exec (char *signal, void *pointer) +hook_signal_send (char *signal, void *signal_data) { struct t_hook *ptr_hook, *next_hook; @@ -840,7 +846,7 @@ hook_signal_exec (char *signal, void *pointer) { ptr_hook->running = 1; (void) (HOOK_SIGNAL(ptr_hook, callback)) - (ptr_hook->callback_data, signal, pointer); + (ptr_hook->callback_data, signal, signal_data); ptr_hook->running = 0; } @@ -859,7 +865,7 @@ hook_signal_exec (char *signal, void *pointer) */ struct t_hook * -hook_config (void *plugin, char *type, char *option, +hook_config (struct t_weechat_plugin *plugin, char *type, char *option, t_hook_callback_config *callback, void *callback_data) { struct t_hook *new_hook; @@ -933,7 +939,7 @@ hook_config_exec (char *type, char *option, char *value) */ struct t_hook * -hook_completion (void *plugin, char *completion, +hook_completion (struct t_weechat_plugin *plugin, char *completion, t_hook_callback_completion *callback, void *callback_data) { struct t_hook *new_hook; @@ -968,7 +974,8 @@ hook_completion (void *plugin, char *completion, */ void -hook_completion_exec (void *plugin, char *completion, void *buffer, void *list) +hook_completion_exec (struct t_weechat_plugin *plugin, char *completion, + struct t_gui_buffer *buffer, struct t_weelist *list) { struct t_hook *ptr_hook, *next_hook; @@ -1102,7 +1109,7 @@ unhook (struct t_hook *hook) */ void -unhook_all_plugin (void *plugin) +unhook_all_plugin (struct t_weechat_plugin *plugin) { int type; struct t_hook *ptr_hook, *next_hook; diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h index 09b5af483..c725d8661 100644 --- a/src/core/wee-hook.h +++ b/src/core/wee-hook.h @@ -20,6 +20,9 @@ #ifndef __WEECHAT_HOOK_H #define __WEECHAT_HOOK_H 1 +struct t_gui_buffer; +struct t_weelist; + /* hook types */ enum t_hook_type @@ -63,7 +66,8 @@ struct t_hook struct t_hook *next_hook; /* link to next hook */ }; -typedef int (t_hook_callback_command)(void *, void *, int, char **, char **); +typedef int (t_hook_callback_command)(void *data, struct t_gui_buffer *, + int argc, char **argv, char **argv_eol); struct t_hook_command { @@ -77,7 +81,7 @@ struct t_hook_command char *completion; /* template for completion */ }; -typedef int (t_hook_callback_timer)(void *); +typedef int (t_hook_callback_timer)(void *data); struct t_hook_timer { @@ -88,7 +92,7 @@ struct t_hook_timer struct timeval next_exec; /* next scheduled execution */ }; -typedef int (t_hook_callback_fd)(void *); +typedef int (t_hook_callback_fd)(void *data); struct t_hook_fd { @@ -97,7 +101,8 @@ struct t_hook_fd int flags; /* fd flags (read,write,..) */ }; -typedef int (t_hook_callback_print)(void *, void *, time_t, char *, char *); +typedef int (t_hook_callback_print)(void *data, struct t_gui_buffer *buffer, + time_t date, char *prefix, char *message); struct t_hook_print { @@ -107,7 +112,8 @@ struct t_hook_print int strip_colors; /* strip colors in msg for callback? */ }; -typedef int (t_hook_callback_signal)(void *, char *, void *); +typedef int (t_hook_callback_signal)(void *data, char *signal, + void *signal_data); struct t_hook_signal { @@ -115,7 +121,8 @@ struct t_hook_signal char *signal; /* signal selected ("*" = any signal)*/ }; -typedef int (t_hook_callback_config)(void *, char *, char *, char *); +typedef int (t_hook_callback_config)(void *data, char *type, char *option, + char *value); struct t_hook_config { @@ -125,7 +132,9 @@ struct t_hook_config /* (NULL = hook for all options) */ }; -typedef int (t_hook_callback_completion)(void *, char *, void *, void *); +typedef int (t_hook_callback_completion)(void *data, char *completion, + struct t_gui_buffer *buffer, + struct t_weelist *list); struct t_hook_completion { @@ -141,34 +150,60 @@ extern struct t_hook *last_weechat_hook[]; /* hook functions */ extern void hook_init (); -extern int hook_valid (struct t_hook *); -extern int hook_valid_for_plugin (void *, struct t_hook *); - -extern struct t_hook *hook_command (void *, char *, char *, char *, char *, - char *, t_hook_callback_command *, void *); -extern int hook_command_exec (void *, char *, int); -extern struct t_hook *hook_timer (void *, long, int, int, - t_hook_callback_timer *, void *); -extern int hook_timer_time_to_next (struct timeval *); +extern int hook_valid (struct t_hook *hook); +extern int hook_valid_for_plugin (struct t_weechat_plugin *plugin, + struct t_hook *hook); +extern struct t_hook *hook_command (struct t_weechat_plugin *plugin, + char *command, char *description, + char *args, char *args_description, + char *completion, + t_hook_callback_command *callback, + void *callback_data); +extern int hook_command_exec (struct t_gui_buffer *buffer, char *string, + int only_builtin); +extern struct t_hook *hook_timer (struct t_weechat_plugin *plugin, + long interval, int align_second, + int max_calls, + t_hook_callback_timer *callback, + void *callback_data); +extern int hook_timer_time_to_next (struct timeval *tv_timeout); extern void hook_timer_exec (); -extern struct t_hook *hook_fd (void *, int, int, t_hook_callback_fd *,void *); -extern void hook_fd_set (fd_set *, fd_set *, fd_set *); -extern void hook_fd_exec (fd_set *, fd_set *, fd_set *); -extern struct t_hook *hook_print (void *, void *, char *, int, - t_hook_callback_print *, void *); -extern void hook_print_exec (void *, time_t, char *, char *); -extern struct t_hook *hook_signal (void *, char *, - t_hook_callback_signal *, void *); -extern void hook_signal_exec (char *, void *); -extern struct t_hook *hook_config (void *, char *, char *, - t_hook_callback_config *, void *); -extern void hook_config_exec (char *, char *, char *); -extern struct t_hook *hook_completion (void *, char *, - t_hook_callback_completion *, void *); -extern void hook_completion_exec (void *, char *, void *, void *); - -extern void unhook (struct t_hook *); -extern void unhook_all_plugin (void *); +extern struct t_hook *hook_fd (struct t_weechat_plugin *plugin, int fd, + int flag_read, int flag_write, + int flag_exception, + t_hook_callback_fd * callback, + void *callback_data); +extern void hook_fd_set (fd_set *read_fds, fd_set *write_fds, + fd_set *exception_fds); +extern void hook_fd_exec (fd_set *read_fds, fd_set *write_fds, + fd_set *exception_fds); +extern struct t_hook *hook_print (struct t_weechat_plugin *plugin, + struct t_gui_buffer *buffer, + char *message, int strip_colors, + t_hook_callback_print *callback, + void *callback_data); +extern void hook_print_exec (struct t_gui_buffer *buffer, + time_t date, char *prefix, char *message); +extern struct t_hook *hook_signal (struct t_weechat_plugin *plugin, + char *signal, + t_hook_callback_signal *callback, + void *callback_data); +extern void hook_signal_send (char *signal, void *signal_date); +extern struct t_hook *hook_config (struct t_weechat_plugin *, char *type, + char *option, + t_hook_callback_config *callback, + void *callback_data); +extern void hook_config_exec (char *type, char *option, char *value); +extern struct t_hook *hook_completion (struct t_weechat_plugin *plugin, + char *completion, + t_hook_callback_completion *callback, + void *callback_data); +extern void hook_completion_exec (struct t_weechat_plugin *plugin, + char *completion, + struct t_gui_buffer *buffer, + struct t_weelist *list); +extern void unhook (struct t_hook *hook); +extern void unhook_all_plugin (struct t_weechat_plugin *plugin); extern void unhook_all (); extern void hook_print_log (); diff --git a/src/core/wee-input.c b/src/core/wee-input.c index ddd3b00c0..a89a2fc76 100644 --- a/src/core/wee-input.c +++ b/src/core/wee-input.c @@ -31,6 +31,7 @@ #include "wee-config.h" #include "wee-hook.h" #include "wee-string.h" +#include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" #include "../plugins/plugin.h" diff --git a/src/core/wee-input.h b/src/core/wee-input.h index b2bef04c9..77fd8e18c 100644 --- a/src/core/wee-input.h +++ b/src/core/wee-input.h @@ -20,8 +20,9 @@ #ifndef __WEECHAT_INPUT_H #define __WEECHAT_INPUT_H 1 -#include "../gui/gui-buffer.h" +struct t_gui_buffer; -extern void input_data (struct t_gui_buffer *, char *, int); +extern void input_data (struct t_gui_buffer *buffer, char *data, + int only_builtin); #endif /* wee-input.h */ diff --git a/src/core/wee-list.c b/src/core/wee-list.c index b162e0300..77e3c1533 100644 --- a/src/core/wee-list.c +++ b/src/core/wee-list.c @@ -78,7 +78,7 @@ weelist_find_pos (struct t_weelist *weelist, char *data) void weelist_insert (struct t_weelist *weelist, struct t_weelist_item *item, - int position) + char *where) { struct t_weelist_item *pos_item; @@ -97,18 +97,12 @@ weelist_insert (struct t_weelist *weelist, struct t_weelist_item *item, { /* search position for new element, according to pos asked */ pos_item = NULL; - switch (position) - { - case WEELIST_POS_SORT: - pos_item = weelist_find_pos (weelist, item->data); - break; - case WEELIST_POS_BEGINNING: - pos_item = weelist->items; - break; - case WEELIST_POS_END: - pos_item = NULL; - break; - } + if (string_strcasecmp (where, WEELIST_POS_BEGINNING) == 0) + pos_item = weelist->items; + else if (string_strcasecmp (where, WEELIST_POS_END) == 0) + pos_item = NULL; + else + pos_item = weelist_find_pos (weelist, item->data); if (pos_item) { @@ -144,17 +138,17 @@ weelist_insert (struct t_weelist *weelist, struct t_weelist_item *item, */ struct t_weelist_item * -weelist_add (struct t_weelist *weelist, char *data, int position) +weelist_add (struct t_weelist *weelist, char *data, char *where) { struct t_weelist_item *new_item; - if (!weelist || !data || (!data[0])) + if (!weelist || !data || !data[0] || !where || !where[0]) return NULL; - if ((new_item = ((struct t_weelist_item *) malloc (sizeof (struct t_weelist_item))))) + if ((new_item = ((struct t_weelist_item *)malloc (sizeof (struct t_weelist_item))))) { new_item->data = strdup (data); - weelist_insert (weelist, new_item, position); + weelist_insert (weelist, new_item, where); weelist->size++; } return new_item; @@ -231,6 +225,46 @@ weelist_get (struct t_weelist *weelist, int position) } /* + * weelist_next: get next item + */ + +struct t_weelist_item * +weelist_next (struct t_weelist_item *item) +{ + return item->next_item; +} + +/* + * weelist_prev: get previous item + */ + +struct t_weelist_item * +weelist_prev (struct t_weelist_item *item) +{ + return item->prev_item; +} + +/* + * weelist_string: get string pointer to item data + */ + +char * +weelist_string (struct t_weelist_item *item) +{ + return item->data; +} + +/* + * weelist_size: return size of weelist + */ + +int +weelist_size (struct t_weelist *weelist) +{ + return weelist->size; +} + +/* * weelist_remove: remove an item from a list */ diff --git a/src/core/wee-list.h b/src/core/wee-list.h index c5226d701..852026aba 100644 --- a/src/core/wee-list.h +++ b/src/core/wee-list.h @@ -20,9 +20,9 @@ #ifndef __WEECHAT_LIST_H #define __WEECHAT_LIST_H 1 -#define WEELIST_POS_SORT 0 -#define WEELIST_POS_BEGINNING 1 -#define WEELIST_POS_END 2 +#define WEELIST_POS_SORT "sort" +#define WEELIST_POS_BEGINNING "beginning" +#define WEELIST_POS_END "end" struct t_weelist_item { @@ -39,13 +39,22 @@ struct t_weelist }; extern struct t_weelist *weelist_new (); -extern struct t_weelist_item *weelist_add (struct t_weelist *, char *, int); -extern struct t_weelist_item *weelist_search (struct t_weelist *, char *); -extern struct t_weelist_item *weelist_casesearch (struct t_weelist *, char *); -extern struct t_weelist_item *weelist_get (struct t_weelist *, int); -extern void weelist_remove (struct t_weelist *, struct t_weelist_item *); -extern void weelist_remove_all (struct t_weelist *); -extern void weelist_free (struct t_weelist *); -extern void weelist_print_log (struct t_weelist *, char *); +extern struct t_weelist_item *weelist_add (struct t_weelist *weelist, + char *data, char *where); +extern struct t_weelist_item *weelist_search (struct t_weelist *weelist, + char *data); +extern struct t_weelist_item *weelist_casesearch (struct t_weelist *weelist, + char *data); +extern struct t_weelist_item *weelist_get (struct t_weelist *weelist, + int position); +extern struct t_weelist_item *weelist_next (struct t_weelist_item *item); +extern struct t_weelist_item *weelist_prev (struct t_weelist_item *item); +extern char *weelist_string (struct t_weelist_item *item); +extern int weelist_size (struct t_weelist *weelist); +extern void weelist_remove (struct t_weelist *weelist, + struct t_weelist_item *item); +extern void weelist_remove_all (struct t_weelist *weelist); +extern void weelist_free (struct t_weelist *weelist); +extern void weelist_print_log (struct t_weelist *weelist, char *name); #endif /* wee-list.h */ diff --git a/src/core/wee-log.c b/src/core/wee-log.c index 8c43fb501..051f9b45c 100644 --- a/src/core/wee-log.c +++ b/src/core/wee-log.c @@ -64,7 +64,7 @@ log_open (char *filename, char *mode) { filename_length = strlen (weechat_home) + 64; weechat_log_filename = - (char *) malloc (filename_length * sizeof (char)); + (char *)malloc (filename_length * sizeof (char)); snprintf (weechat_log_filename, filename_length, "%s/%s", weechat_home, WEECHAT_LOG_NAME); } @@ -204,7 +204,7 @@ log_crash_rename () log_close (); length = strlen (weechat_home) + 128; - new_name = (char *) malloc (length); + new_name = (char *)malloc (length); if (new_name) { time_now = time (NULL); diff --git a/src/core/wee-log.h b/src/core/wee-log.h index e41e673ff..80dabbee4 100644 --- a/src/core/wee-log.h +++ b/src/core/wee-log.h @@ -25,7 +25,7 @@ extern FILE *weechat_log_file; extern void log_init (); extern void log_close (); -extern void log_printf (char *, ...); +extern void log_printf (char *message, ...); extern int log_crash_rename (); #endif /* wee-log.h */ diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 2b3aa7380..902d57764 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -377,7 +377,7 @@ string_explode (char *string, char *separators, int keep_eol, if (num_items != NULL) *num_items = 0; - if (!string || !string[0]) + if (!string || !string[0] || !separators || !separators[0]) return NULL; /* calculate number of items */ @@ -395,7 +395,7 @@ string_explode (char *string, char *separators, int keep_eol, n_items = num_items_max; array = - (char **) malloc ((n_items + 1) * sizeof (char *)); + (char **)malloc ((n_items + 1) * sizeof (char *)); ptr1 = string; ptr2 = string; @@ -422,7 +422,7 @@ string_explode (char *string, char *separators, int keep_eol, else { array[i] = - (char *) malloc ((ptr2 - ptr1 + 1) * sizeof (char)); + (char *)malloc ((ptr2 - ptr1 + 1) * sizeof (char)); array[i] = strncpy (array[i], ptr1, ptr2 - ptr1); array[i][ptr2 - ptr1] = '\0'; } @@ -468,28 +468,28 @@ string_free_exploded (char **exploded_string) */ char ** -string_split_command (char *command, char sep) +string_split_command (char *command, char separator) { int nb_substr, arr_idx, str_idx, type; char **array; char *buffer, *ptr, *p; - if (command == NULL) + if (!command || !command[0]) return NULL; nb_substr = 1; ptr = command; - while ( (p = strchr(ptr, sep)) != NULL) + while ( (p = strchr(ptr, separator)) != NULL) { nb_substr++; ptr = ++p; } - array = (char **) malloc ((nb_substr + 1) * sizeof(char *)); + array = (char **)malloc ((nb_substr + 1) * sizeof(char *)); if (!array) return NULL; - buffer = (char *) malloc ( (strlen(command) + 1) * sizeof (char)); + buffer = (char *)malloc ( (strlen(command) + 1) * sizeof (char)); if (!buffer) { free (array); @@ -539,7 +539,7 @@ string_split_command (char *command, char sep) free (buffer); - array = (char **) realloc (array, (arr_idx + 1) * sizeof(char *)); + array = (char **)realloc (array, (arr_idx + 1) * sizeof(char *)); return array; } @@ -550,15 +550,15 @@ string_split_command (char *command, char sep) */ void -string_free_splitted_command (char **commands) +string_free_splitted_command (char **splitted_command) { int i; - if (commands) + if (splitted_command) { - for (i = 0; commands[i]; i++) - free (commands[i]); - free (commands); + for (i = 0; splitted_command[i]; i++) + free (splitted_command[i]); + free (splitted_command); } } @@ -590,7 +590,7 @@ string_iconv (int from_utf8, char *from_code, char *to_code, char *string) ptr_inbuf = inbuf; inbytesleft = strlen (inbuf); outbytesleft = inbytesleft * 4; - outbuf = (char *) malloc (outbytesleft + 2); + outbuf = (char *)malloc (outbytesleft + 2); ptr_outbuf = outbuf; ptr_inbuf_shift = NULL; done = 0; @@ -676,6 +676,9 @@ string_iconv_to_internal (char *charset, char *string) { char *input, *output; + if (!string) + return NULL; + input = strdup (string); /* optimize for UTF-8: if charset is NULL => we use term charset => @@ -710,6 +713,9 @@ string_iconv_from_internal (char *charset, char *string) { char *input, *output; + if (!string) + return NULL; + input = strdup (string); /* optimize for UTF-8: if charset is NULL => we use term charset => diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 67922b5d0..04cb109dc 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -21,23 +21,25 @@ #define __WEECHAT_STRING_H 1 #ifndef HAVE_STRNDUP -extern char *strndup (char *, int); +extern char *strndup (char *string, int length); #endif -extern void string_tolower (char *); -extern void string_toupper (char *); -extern int string_strcasecmp (char *, char *); -extern int string_strncasecmp (char *, char *, int); -extern char *string_strcasestr (char *, char *); -extern char *string_replace (char *, char *, char *); -extern char *string_remove_quotes (char *, char *); -extern char *string_convert_hex_chars (char *); -extern char **string_explode (char *, char *, int, int, int *); -extern void string_free_exploded (char **); -extern char **string_split_command (char *, char); -extern void string_free_splitted_command (char **); -extern char *string_iconv (int, char *, char *, char *); -extern char *string_iconv_to_internal (char *, char *); -extern char *string_iconv_from_internal (char *, char *); -extern void string_iconv_fprintf (FILE *, char *, ...); +extern void string_tolower (char *string); +extern void string_toupper (char *string); +extern int string_strcasecmp (char *string1, char *string2); +extern int string_strncasecmp (char *string1, char *string2, int max); +extern char *string_strcasestr (char *string, char *search); +extern char *string_replace (char *string, char *search, char *replace); +extern char *string_remove_quotes (char *string, char *quotes); +extern char *string_convert_hex_chars (char *string); +extern char **string_explode (char *string, char *separators, int keep_eol, + int num_items_max, int *num_items); +extern void string_free_exploded (char **exploded_string); +extern char **string_split_command (char *command, char separator); +extern void string_free_splitted_command (char **splitted_command); +extern char *string_iconv (int from_utf8, char *from_code, char *to_code, + char *string); +extern char *string_iconv_to_internal (char *charset, char *string); +extern char *string_iconv_from_internal (char *charset, char *string); +extern void string_iconv_fprintf (FILE *file, char *data, ...); #endif /* wee-string.h */ diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index 0890e14cb..c0edecad0 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -600,7 +600,7 @@ session_read_str (FILE *file, char **string) if (string) { - (*string) = (char *) malloc (length + 1); + (*string) = (char *)malloc (length + 1); if (!(*string)) return 0; diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index 9e52dd6b3..51f67a956 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -300,7 +300,7 @@ utf8_strlen_screen (char *string) return utf8_strlen (string); num_char = mbstowcs (NULL, string, 0) + 1; - wstring = (wchar_t *) malloc ((num_char + 1) * sizeof (wchar_t)); + wstring = (wchar_t *)malloc ((num_char + 1) * sizeof (wchar_t)); if (!wstring) return utf8_strlen (string); @@ -351,13 +351,13 @@ utf8_charcasecmp (char *string1, char *string2) return diff; i++; } - // string1 == string2 ? + /* string1 == string2 ? */ if ((i == length1) && (i == length2)) return 0; - // string1 < string2 ? + /* string1 < string2 ? */ if (i == length1) return 1; - // string1 > string2 + /* string1 > string2 */ return -1; } diff --git a/src/core/wee-utf8.h b/src/core/wee-utf8.h index f16733535..7ad3477ed 100644 --- a/src/core/wee-utf8.h +++ b/src/core/wee-utf8.h @@ -33,19 +33,19 @@ extern int local_utf8; extern void utf8_init (); -extern int utf8_has_8bits (char *); -extern int utf8_is_valid (char *, char **); -extern void utf8_normalize (char *, char); -extern char *utf8_prev_char (char *, char *); -extern char *utf8_next_char (char *); -extern int utf8_char_size (char *); -extern int utf8_strlen (char *); -extern int utf8_strnlen (char *, int); -extern int utf8_strlen_screen (char *); -extern int utf8_charcasecmp (char *, char *); -extern int utf8_char_size_screen (char *); -extern char *utf8_add_offset (char *, int); -extern int utf8_real_pos (char *, int); -extern int utf8_pos (char *, int); +extern int utf8_has_8bits (char *string); +extern int utf8_is_valid (char *string, char **error); +extern void utf8_normalize (char *string, char replacement); +extern char *utf8_prev_char (char *string_start, char *string); +extern char *utf8_next_char (char *string); +extern int utf8_char_size (char *string); +extern int utf8_strlen (char *string); +extern int utf8_strnlen (char *string, int bytes); +extern int utf8_strlen_screen (char *string); +extern int utf8_charcasecmp (char *string1, char *string2); +extern int utf8_char_size_screen (char *string); +extern char *utf8_add_offset (char *string, int offset); +extern int utf8_real_pos (char *string, int pos); +extern int utf8_pos (char *string, int real_pos); #endif /* wee-utf8.h */ diff --git a/src/core/wee-util.c b/src/core/wee-util.c index e737c7592..86f5f6b93 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -152,13 +152,17 @@ util_create_dir (char *directory, int permissions) */ void -util_exec_on_files (char *directory, int (*callback)(char *)) +util_exec_on_files (char *directory, void *data, + int (*callback)(void *data, char *filename)) { char complete_filename[1024]; DIR *dir; struct dirent *entry; struct stat statbuf; + if (!directory || !callback) + return; + dir = opendir (directory); if (dir) { @@ -169,7 +173,7 @@ util_exec_on_files (char *directory, int (*callback)(char *)) lstat (complete_filename, &statbuf); if (!S_ISDIR(statbuf.st_mode)) { - (int) (*callback) (complete_filename); + (int) (*callback) (data, complete_filename); } } closedir (dir); diff --git a/src/core/wee-util.h b/src/core/wee-util.h index 504c0377f..66d4bce0f 100644 --- a/src/core/wee-util.h +++ b/src/core/wee-util.h @@ -20,12 +20,13 @@ #ifndef __WEECHAT_UTIL_H #define __WEECHAT_UTIL_H 1 -extern int util_timeval_cmp (struct timeval *, struct timeval *); -extern long util_timeval_diff (struct timeval *, struct timeval *); -extern void util_timeval_add (struct timeval *, long); -extern int util_get_time_length (char *); -extern int util_create_dir (char *, int); -extern void util_exec_on_files (char *, int (*)(char *)); -extern char *util_search_full_lib_name (char *, char *); +extern int util_timeval_cmp (struct timeval *tv1, struct timeval *tv2); +extern long util_timeval_diff (struct timeval *tv1, struct timeval *tv2); +extern void util_timeval_add (struct timeval *tv, long interval); +extern int util_get_time_length (char *time_format); +extern int util_create_dir (char *directory, int permissions); +extern void util_exec_on_files (char *directory, void *data, + int (*callback)(void *data, char *filename)); +extern char *util_search_full_lib_name (char *filename, char *sys_directory); #endif /* wee-util.h */ diff --git a/src/core/weechat.c b/src/core/weechat.c index 8d6a74d9e..abe39e365 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -362,7 +362,7 @@ weechat_create_home_dirs () } dir_length = strlen (ptr_home) + 10; weechat_home = - (char *) malloc (dir_length * sizeof (char)); + (char *)malloc (dir_length * sizeof (char)); if (!weechat_home) { string_iconv_fprintf (stderr, @@ -521,7 +521,7 @@ weechat_dump (int crash) plugin_print_log (); - hook_signal_exec ("dump_data", NULL); + hook_signal_send ("dump_data", NULL); log_printf (""); log_printf ("****** End of WeeChat dump ******"); diff --git a/src/core/weechat.h b/src/core/weechat.h index cdc53d47a..2f98d7db1 100644 --- a/src/core/weechat.h +++ b/src/core/weechat.h @@ -108,7 +108,7 @@ extern int quit_weechat; extern char *weechat_home; extern char *local_charset; -extern void weechat_dump (int); -extern void weechat_shutdown (int, int); +extern void weechat_dump (int crash); +extern void weechat_shutdown (int return_code, int crash); #endif /* weechat.h */ |