diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-10-26 20:37:03 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-10-26 20:37:03 +0200 |
commit | dfdf42e27b033730178bf8884e2f4a1e6c960791 (patch) | |
tree | 6f7a25f6df49089832aabc6448bd6e527de2ea0e /src/core | |
parent | 2a83aae85e68a8c7431f372f39131b09fea7bca1 (diff) | |
download | weechat-dfdf42e27b033730178bf8884e2f4a1e6c960791.zip |
core: remove unneeded whitespace
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-backtrace.c | 8 | ||||
-rw-r--r-- | src/core/wee-command.c | 626 | ||||
-rw-r--r-- | src/core/wee-completion.c | 188 | ||||
-rw-r--r-- | src/core/wee-config-file.c | 328 | ||||
-rw-r--r-- | src/core/wee-config.c | 290 | ||||
-rw-r--r-- | src/core/wee-debug.c | 74 | ||||
-rw-r--r-- | src/core/wee-hashtable.c | 144 | ||||
-rw-r--r-- | src/core/wee-hashtable.h | 6 | ||||
-rw-r--r-- | src/core/wee-hdata.c | 78 | ||||
-rw-r--r-- | src/core/wee-hook.c | 662 | ||||
-rw-r--r-- | src/core/wee-hook.h | 8 | ||||
-rw-r--r-- | src/core/wee-infolist.c | 130 | ||||
-rw-r--r-- | src/core/wee-input.c | 22 | ||||
-rw-r--r-- | src/core/wee-list.c | 48 | ||||
-rw-r--r-- | src/core/wee-log.c | 18 | ||||
-rw-r--r-- | src/core/wee-network.c | 154 | ||||
-rw-r--r-- | src/core/wee-proxy.c | 88 | ||||
-rw-r--r-- | src/core/wee-proxy.h | 2 | ||||
-rw-r--r-- | src/core/wee-string.c | 306 | ||||
-rw-r--r-- | src/core/wee-upgrade-file.c | 108 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 96 | ||||
-rw-r--r-- | src/core/wee-utf8.c | 76 | ||||
-rw-r--r-- | src/core/wee-util.c | 64 | ||||
-rw-r--r-- | src/core/weechat.c | 20 | ||||
-rw-r--r-- | src/core/weechat.h | 2 |
25 files changed, 1773 insertions, 1773 deletions
diff --git a/src/core/wee-backtrace.c b/src/core/wee-backtrace.c index fd121f084..1bc49df3f 100644 --- a/src/core/wee-backtrace.c +++ b/src/core/wee-backtrace.c @@ -80,14 +80,14 @@ weechat_backtrace_addr2line (int number, void *address, const char *symbol) char cmd_line[1024]; char line[1024], *ptr_line, *pos; char function_name[1024]; - + rc = dladdr (address, &info); if ((rc == 0) || !info.dli_fname || !info.dli_fname[0]) { weechat_backtrace_printf ("%03d %s", number, symbol); return; } - + addr = address; if (info.dli_fbase >= (const void *) 0x40000000) addr = (void *)((unsigned long)((const char *) addr) - @@ -166,7 +166,7 @@ weechat_backtrace () #ifdef HAVE_BACKTRACE trace_size = backtrace (trace, BACKTRACE_MAX); symbols = backtrace_symbols (trace, trace_size); - + for (i = 0; i < trace_size; i++) { weechat_backtrace_addr2line (i + 1, trace[i], symbols[i]); @@ -175,6 +175,6 @@ weechat_backtrace () weechat_backtrace_printf (" No backtrace info (no debug info available " "or no backtrace possible on your system)."); #endif - + weechat_backtrace_printf ("======= End of backtrace ======="); } diff --git a/src/core/wee-command.c b/src/core/wee-command.c index b52d12b99..8225baa05 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -84,7 +84,7 @@ command_bar_list (int full) { struct t_gui_bar *ptr_bar; char str_size[16]; - + if (gui_bars) { gui_chat_printf (NULL, ""); @@ -161,11 +161,11 @@ COMMAND_CALLBACK(bar) struct t_gui_bar *ptr_bar; struct t_gui_bar_item *ptr_item; struct t_gui_window *ptr_window; - + /* make C compiler happy */ (void) data; (void) buffer; - + /* list of bars */ if ((argc == 1) || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) @@ -173,14 +173,14 @@ COMMAND_CALLBACK(bar) command_bar_list (0); return WEECHAT_RC_OK; } - + /* full list of bars */ if ((argc == 2) && (string_strcasecmp (argv[1], "listfull") == 0)) { command_bar_list (1); return WEECHAT_RC_OK; } - + /* list of bar items */ if ((argc == 1) || ((argc == 2) && (string_strcasecmp (argv[1], "listitems") == 0))) @@ -200,10 +200,10 @@ COMMAND_CALLBACK(bar) } else gui_chat_printf (NULL, _("No bar item defined")); - + return WEECHAT_RC_OK; } - + /* add a new bar */ if (string_strcasecmp (argv[1], "add") == 0) { @@ -292,7 +292,7 @@ COMMAND_CALLBACK(bar) return WEECHAT_RC_OK; } - + /* create default bars */ if (string_strcasecmp (argv[1], "default") == 0) { @@ -314,7 +314,7 @@ COMMAND_CALLBACK(bar) gui_bar_create_default (); return WEECHAT_RC_OK; } - + /* delete a bar */ if (string_strcasecmp (argv[1], "del") == 0) { @@ -340,10 +340,10 @@ COMMAND_CALLBACK(bar) gui_chat_printf (NULL, _("Bar deleted")); gui_bar_create_default_input (); } - + return WEECHAT_RC_OK; } - + /* set a bar property */ if (string_strcasecmp (argv[1], "set") == 0) { @@ -366,10 +366,10 @@ COMMAND_CALLBACK(bar) argv[3], argv[2]); return WEECHAT_RC_OK; } - + return WEECHAT_RC_OK; } - + /* hide a bar */ if (string_strcasecmp (argv[1], "hide") == 0) { @@ -385,7 +385,7 @@ COMMAND_CALLBACK(bar) } if (!CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN])) gui_bar_set (ptr_bar, "hidden", "1"); - + return WEECHAT_RC_OK; } @@ -404,10 +404,10 @@ COMMAND_CALLBACK(bar) } if (CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN])) gui_bar_set (ptr_bar, "hidden", "0"); - + return WEECHAT_RC_OK; } - + /* toggle a bar visible/hidden */ if (string_strcasecmp (argv[1], "toggle") == 0) { @@ -423,10 +423,10 @@ COMMAND_CALLBACK(bar) } gui_bar_set (ptr_bar, "hidden", CONFIG_BOOLEAN(ptr_bar->options[GUI_BAR_OPTION_HIDDEN]) ? "0" : "1"); - + return WEECHAT_RC_OK; } - + /* scroll in a bar */ if (string_strcasecmp (argv[1], "scroll") == 0) { @@ -462,7 +462,7 @@ COMMAND_CALLBACK(bar) } return WEECHAT_RC_OK; } - + gui_chat_printf (NULL, _("%sError: unknown option for \"%s\" " "command"), @@ -483,7 +483,7 @@ command_buffer_display_localvar (void *data, /* make C compiler happy */ (void) data; (void) hashtable; - + if (key) { if (value) @@ -512,17 +512,17 @@ COMMAND_CALLBACK(buffer) long number, number1, number2; char *error, *value, *pos, *str_number1, *pos_number2; int i, target_buffer; - + /* make C compiler happy */ (void) data; - + if ((argc == 1) || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) { /* list buffers */ gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Buffers list:")); - + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { @@ -539,10 +539,10 @@ COMMAND_CALLBACK(buffer) GUI_COLOR(GUI_COLOR_CHAT), gui_buffer_notify_string[ptr_buffer->notify]); } - + return WEECHAT_RC_OK; } - + /* clear content of buffer */ if (string_strcasecmp (argv[1], "clear") == 0) { @@ -594,10 +594,10 @@ COMMAND_CALLBACK(buffer) if (buffer->type == GUI_BUFFER_TYPE_FORMATTED) gui_buffer_clear (buffer); } - + return WEECHAT_RC_OK; } - + /* move buffer to another number in the list */ if (string_strcasecmp (argv[1], "move") == 0) { @@ -625,10 +625,10 @@ COMMAND_CALLBACK(buffer) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_OK; } - + return WEECHAT_RC_OK; } - + /* merge buffer with another number in the list */ if (string_strcasecmp (argv[1], "merge") == 0) { @@ -649,10 +649,10 @@ COMMAND_CALLBACK(buffer) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_OK; } - + return WEECHAT_RC_OK; } - + /* unmerge buffer */ if (string_strcasecmp (argv[1], "unmerge") == 0) { @@ -679,10 +679,10 @@ COMMAND_CALLBACK(buffer) } } gui_buffer_unmerge (buffer, (int) number); - + return WEECHAT_RC_OK; } - + /* close buffer */ if (string_strcasecmp (argv[1], "close") == 0) { @@ -774,10 +774,10 @@ COMMAND_CALLBACK(buffer) gui_buffer_close (ptr_buffer); } } - + return WEECHAT_RC_OK; } - + /* set notify level */ if (string_strcasecmp (argv[1], "notify") == 0) { @@ -785,7 +785,7 @@ COMMAND_CALLBACK(buffer) config_weechat_notify_set (buffer, argv_eol[2]); return WEECHAT_RC_OK; } - + /* display local variables on buffer */ if (string_strcasecmp (argv[1], "localvar") == 0) { @@ -805,7 +805,7 @@ COMMAND_CALLBACK(buffer) } return WEECHAT_RC_OK; } - + /* set a property on buffer */ if (string_strcasecmp (argv[1], "set") == 0) { @@ -814,7 +814,7 @@ COMMAND_CALLBACK(buffer) gui_buffer_set (buffer, argv[2], (value) ? value : argv_eol[3]); if (value) free (value); - + return WEECHAT_RC_OK; } @@ -857,7 +857,7 @@ COMMAND_CALLBACK(buffer) } return WEECHAT_RC_OK; } - + /* relative jump '-' */ if (argv[1][0] == '-') { @@ -872,10 +872,10 @@ COMMAND_CALLBACK(buffer) gui_buffer_switch_by_number (gui_current_window, target_buffer); } - + return WEECHAT_RC_OK; } - + /* relative jump '+' */ if (argv[1][0] == '+') { @@ -889,10 +889,10 @@ COMMAND_CALLBACK(buffer) gui_buffer_switch_by_number (gui_current_window, target_buffer); } - + return WEECHAT_RC_OK; } - + /* smart jump (jump to previous buffer for current number) */ if (argv[1][0] == '*') { @@ -916,10 +916,10 @@ COMMAND_CALLBACK(buffer) } } } - + return WEECHAT_RC_OK; } - + /* jump to buffer by number or name */ error = NULL; number = strtol (argv[1], &error, 10); @@ -936,7 +936,7 @@ COMMAND_CALLBACK(buffer) if (ptr_buffer) gui_window_switch_to_buffer (gui_current_window, ptr_buffer, 1); } - + return WEECHAT_RC_OK; } @@ -951,22 +951,22 @@ COMMAND_CALLBACK(color) long number; int i; struct t_gui_color_palette *color_palette; - + /* make C compiler happy */ (void) data; (void) argv_eol; - + if (argc == 1) { gui_color_buffer_open (); return WEECHAT_RC_OK; } - + /* add a color alias */ if (string_strcasecmp (argv[1], "alias") == 0) { COMMAND_MIN_ARGS(4, "color alias"); - + /* check color number */ error = NULL; number = strtol (argv[2], &error, 10); @@ -988,7 +988,7 @@ COMMAND_CALLBACK(color) argv[2], 0, gui_color_get_term_colors ()); return WEECHAT_RC_OK; } - + /* check other arguments */ str_alias = NULL; str_rgb = NULL; @@ -1011,7 +1011,7 @@ COMMAND_CALLBACK(color) strcat (str_color, ";"); strcat (str_color, str_rgb); } - + /* add color alias */ snprintf (str_command, sizeof (str_command), "/set weechat.palette.%d \"%s\"", @@ -1020,12 +1020,12 @@ COMMAND_CALLBACK(color) input_exec_command (buffer, 1, NULL, str_command); return WEECHAT_RC_OK; } - + /* delete a color alias */ if (string_strcasecmp (argv[1], "unalias") == 0) { COMMAND_MIN_ARGS(3, "color unalias"); - + /* check color number */ error = NULL; number = strtol (argv[2], &error, 10); @@ -1047,7 +1047,7 @@ COMMAND_CALLBACK(color) argv[2], 0, gui_color_get_term_colors ()); return WEECHAT_RC_OK; } - + /* search color */ color_palette = gui_color_palette_get ((int)number); if (!color_palette) @@ -1058,7 +1058,7 @@ COMMAND_CALLBACK(color) argv[2]); return WEECHAT_RC_OK; } - + /* delete color alias */ snprintf (str_command, sizeof (str_command), "/unset weechat.palette.%d", @@ -1066,21 +1066,21 @@ COMMAND_CALLBACK(color) input_exec_command (buffer, 1, NULL, str_command); return WEECHAT_RC_OK; } - + /* reset color pairs */ if (string_strcasecmp (argv[1], "reset") == 0) { gui_color_reset_pairs (); return WEECHAT_RC_OK; } - + /* switch WeeChat/terminal colors */ if (string_strcasecmp (argv[1], "switch") == 0) { gui_color_switch_colors (); return WEECHAT_RC_OK; } - + return WEECHAT_RC_OK; } @@ -1093,10 +1093,10 @@ COMMAND_CALLBACK(command) int length; char *command; struct t_weechat_plugin *ptr_plugin; - + /* make C compiler happy */ (void) data; - + if (argc > 2) { ptr_plugin = NULL; @@ -1127,7 +1127,7 @@ COMMAND_CALLBACK(command) } } } - + return WEECHAT_RC_OK; } @@ -1139,18 +1139,18 @@ COMMAND_CALLBACK(cursor) { char *pos, *str_x, *error; int x, y; - + /* make C compiler happy */ (void) data; (void) buffer; (void) argv_eol; - + if (argc == 1) { gui_cursor_mode_toggle (); return WEECHAT_RC_OK; } - + if (string_strcasecmp (argv[1], "go") == 0) { if (argc > 2) @@ -1181,7 +1181,7 @@ COMMAND_CALLBACK(cursor) } return WEECHAT_RC_OK; } - + if (string_strcasecmp (argv[1], "move") == 0) { if (argc > 2) @@ -1205,7 +1205,7 @@ COMMAND_CALLBACK(cursor) } return WEECHAT_RC_OK; } - + if (string_strcasecmp (argv[1], "stop") == 0) { gui_cursor_mode_toggle (); @@ -1224,17 +1224,17 @@ COMMAND_CALLBACK(debug) struct t_config_option *ptr_option; struct t_weechat_plugin *ptr_plugin; int debug; - + /* make C compiler happy */ (void) data; (void) argv_eol; - + if ((argc == 1) || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) { gui_chat_printf (NULL, ""); gui_chat_printf (NULL, "Debug:"); - + ptr_option = config_weechat_debug_get (PLUGIN_CORE); gui_chat_printf (NULL, " %s: %d", PLUGIN_CORE, @@ -1248,7 +1248,7 @@ COMMAND_CALLBACK(debug) } return WEECHAT_RC_OK; } - + if (string_strcasecmp (argv[1], "dump") == 0) { if (argc > 2) @@ -1351,7 +1351,7 @@ COMMAND_CALLBACK(debug) } } } - + return WEECHAT_RC_OK; } @@ -1386,11 +1386,11 @@ command_filter_display (struct t_gui_filter *filter) COMMAND_CALLBACK(filter) { struct t_gui_filter *ptr_filter; - + /* make C compiler happy */ (void) data; (void) buffer; - + if ((argc == 1) || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) { @@ -1401,7 +1401,7 @@ COMMAND_CALLBACK(filter) (gui_filters_enabled) ? _("Message filtering enabled") : _("Message filtering disabled")); - + if (gui_filters) { gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER, @@ -1417,10 +1417,10 @@ COMMAND_CALLBACK(filter) gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER, _("No message filter defined")); } - + return WEECHAT_RC_OK; } - + /* enable global filtering or a filter */ if (string_strcasecmp (argv[1], "enable") == 0) { @@ -1498,7 +1498,7 @@ COMMAND_CALLBACK(filter) } return WEECHAT_RC_OK; } - + /* toggle global filtering or a filter on/off */ if (string_strcasecmp (argv[1], "toggle") == 0) { @@ -1531,7 +1531,7 @@ COMMAND_CALLBACK(filter) } return WEECHAT_RC_OK; } - + /* add filter */ if (string_strcasecmp (argv[1], "add") == 0) { @@ -1559,9 +1559,9 @@ COMMAND_CALLBACK(filter) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_OK; } - + ptr_filter = gui_filter_new (1, argv[2], argv[3], argv[4], argv_eol[5]); - + if (ptr_filter) { gui_chat_printf (NULL, ""); @@ -1576,7 +1576,7 @@ COMMAND_CALLBACK(filter) _("%sError adding filter"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); } - + return WEECHAT_RC_OK; } @@ -1611,10 +1611,10 @@ COMMAND_CALLBACK(filter) argv[2]); return WEECHAT_RC_OK; } - + return WEECHAT_RC_OK; } - + /* delete filter */ if (string_strcasecmp (argv[1], "del") == 0) { @@ -1654,7 +1654,7 @@ COMMAND_CALLBACK(filter) } return WEECHAT_RC_OK; } - + gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER, _("%sError: unknown option for \"%s\" " "command"), @@ -1679,7 +1679,7 @@ command_help_list_plugin_commands (struct t_weechat_plugin *plugin, int command_found, length, max_length, list_size; int cols, lines, col, line, index; char str_format[64], str_command[256], str_line[2048]; - + if (verbose) { command_found = 0; @@ -1718,7 +1718,7 @@ command_help_list_plugin_commands (struct t_weechat_plugin *plugin, { max_length = -1; list = weelist_new (); - + /* * build list of commands for plugin and save max length of command * names @@ -1737,7 +1737,7 @@ command_help_list_plugin_commands (struct t_weechat_plugin *plugin, WEECHAT_LIST_POS_SORT, NULL); } } - + /* use list to display commands, sorted by columns */ list_size = weelist_size (list); if ((max_length > 0) && (list_size > 0)) @@ -1749,10 +1749,10 @@ command_help_list_plugin_commands (struct t_weechat_plugin *plugin, GUI_COLOR(GUI_COLOR_CHAT_BUFFER), plugin_get_name (plugin), GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); - + snprintf (str_format, sizeof (str_format), " %%-%ds", max_length); - + /* auto compute number of colums, max size is 90% of chat width */ cols = ((gui_current_window->win_chat_width * 90) / 100) / (max_length + 1); if (cols == 0) @@ -1781,7 +1781,7 @@ command_help_list_plugin_commands (struct t_weechat_plugin *plugin, gui_chat_printf (NULL, " %s", str_line); } } - + weelist_free (list); } } @@ -1794,10 +1794,10 @@ void command_help_list_commands (int verbose) { struct t_weechat_plugin *ptr_plugin; - + /* WeeChat commands */ command_help_list_plugin_commands (NULL, verbose); - + /* plugins commands */ for (ptr_plugin = weechat_plugins; ptr_plugin; ptr_plugin = ptr_plugin->next_plugin) @@ -1818,12 +1818,12 @@ COMMAND_CALLBACK(help) int i, length, command_found, first_line_displayed, verbose; char *string, *ptr_string, *pos_double_pipe, *pos_end; char empty_string[1] = { '\0' }, str_format[64]; - + /* make C compiler happy */ (void) data; (void) buffer; (void) argv_eol; - + /* display help for all commands */ if ((argc == 1) || ((argc > 1) && (string_strncasecmp (argv[1], "-list", 5) == 0))) @@ -1847,7 +1847,7 @@ COMMAND_CALLBACK(help) command_help_list_commands (verbose); return WEECHAT_RC_OK; } - + /* look for command */ command_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; @@ -1904,7 +1904,7 @@ COMMAND_CALLBACK(help) } if (string) free (string); - + if (pos_double_pipe) { ptr_string = pos_double_pipe + 2; @@ -1934,7 +1934,7 @@ COMMAND_CALLBACK(help) } if (command_found) return WEECHAT_RC_OK; - + /* look for option */ config_file_search_with_string (argv[1], NULL, NULL, &ptr_option, NULL); if (ptr_option) @@ -2177,13 +2177,13 @@ COMMAND_CALLBACK(help) } return WEECHAT_RC_OK; } - + gui_chat_printf (NULL, _("%sNo help available, \"%s\" is not a command or an " "option"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], argv[1]); - + return WEECHAT_RC_OK; } @@ -2195,13 +2195,13 @@ COMMAND_CALLBACK(history) { struct t_gui_history *ptr_history; int n, n_total, n_user, displayed; - + /* make C compiler happy */ (void) data; (void) argv_eol; - + n_user = CONFIG_INTEGER(config_history_display_default); - + if (argc == 2) { if (string_strcasecmp (argv[1], "clear") == 0) @@ -2212,7 +2212,7 @@ COMMAND_CALLBACK(history) else n_user = atoi (argv[1]); } - + if (buffer->history) { n_total = 1; @@ -2238,7 +2238,7 @@ COMMAND_CALLBACK(history) displayed = 1; } } - + return WEECHAT_RC_OK; } @@ -2250,7 +2250,7 @@ COMMAND_CALLBACK(input) { /* make C compiler happy */ (void) data; - + if (argc > 1) { if (string_strcasecmp (argv[1], "clipboard_paste") == 0) @@ -2345,7 +2345,7 @@ COMMAND_CALLBACK(input) else if (string_strcasecmp (argv[1], "redo") == 0) gui_input_redo (buffer); } - + return WEECHAT_RC_OK; } @@ -2357,9 +2357,9 @@ void command_key_display (struct t_gui_key *key, struct t_gui_key *default_key) { char *expanded_name; - + expanded_name = gui_key_get_expanded_name (key->key); - + if (default_key) { gui_chat_printf (NULL, " %s%s => %s%s %s(%s%s %s%s)", @@ -2381,7 +2381,7 @@ command_key_display (struct t_gui_key *key, struct t_gui_key *default_key) GUI_COLOR(GUI_COLOR_CHAT), key->command); } - + if (expanded_name) free (expanded_name); } @@ -2398,7 +2398,7 @@ command_key_display_list (const char *message_no_key, int keys_count) { struct t_gui_key *ptr_key; - + if (keys_count == 0) gui_chat_printf (NULL, message_no_key, gui_key_context_string[context]); @@ -2424,7 +2424,7 @@ command_key_display_listdiff (int context) { struct t_gui_key *ptr_key, *ptr_default_key; int count_added, count_deleted; - + /* list keys added or redefined */ count_added = 0; for (ptr_key = gui_keys[context]; ptr_key; ptr_key = ptr_key->next_key) @@ -2457,7 +2457,7 @@ command_key_display_listdiff (int context) } } } - + /* list keys deleted */ count_deleted = 0; for (ptr_default_key = gui_default_keys[context]; ptr_default_key; @@ -2485,7 +2485,7 @@ command_key_display_listdiff (int context) } } } - + /* display a message if all key bindings are default bindings */ if ((count_added == 0) && (count_deleted == 0)) { @@ -2507,17 +2507,17 @@ command_key_reset (int context, const char *key) char *internal_code; struct t_gui_key *ptr_key, *ptr_default_key, *ptr_new_key; int rc; - + internal_code = gui_key_get_internal_code (key); if (!internal_code) return WEECHAT_RC_ERROR; - + ptr_key = gui_key_search (gui_keys[context], internal_code); ptr_default_key = gui_key_search (gui_default_keys[context], internal_code); free (internal_code); - + if (ptr_key || ptr_default_key) { if (ptr_key && ptr_default_key) @@ -2595,11 +2595,11 @@ COMMAND_CALLBACK(key) char *internal_code; struct t_gui_key *ptr_new_key; int old_keys_count, keys_added, i, context, rc; - + /* make C compiler happy */ (void) data; (void) buffer; - + /* display all key bindings (current keys) */ if ((argc == 1) || (string_strcasecmp (argv[1], "list") == 0)) { @@ -2618,7 +2618,7 @@ COMMAND_CALLBACK(key) } return WEECHAT_RC_OK; } - + /* display redefined or key bindings added */ if (string_strcasecmp (argv[1], "listdiff") == 0) { @@ -2632,7 +2632,7 @@ COMMAND_CALLBACK(key) } return WEECHAT_RC_OK; } - + /* display default key bindings */ if (string_strcasecmp (argv[1], "listdefault") == 0) { @@ -2653,12 +2653,12 @@ COMMAND_CALLBACK(key) } return WEECHAT_RC_OK; } - + /* bind a key (or display binding) */ if (string_strcasecmp (argv[1], "bind") == 0) { COMMAND_MIN_ARGS(3, "key bind"); - + /* display a key binding */ if (argc == 3) { @@ -2682,7 +2682,7 @@ COMMAND_CALLBACK(key) free (internal_code); return WEECHAT_RC_OK; } - + /* bind new key */ gui_key_verbose = 1; ptr_new_key = gui_key_bind (NULL, GUI_KEY_CONTEXT_DEFAULT, @@ -2698,12 +2698,12 @@ COMMAND_CALLBACK(key) } return WEECHAT_RC_OK; } - + /* bind a key for given context (or display binding) */ if (string_strcasecmp (argv[1], "bindctxt") == 0) { COMMAND_MIN_ARGS(4, "key bindctxt"); - + /* search context */ context = gui_key_search_context (argv[2]); if (context < 0) @@ -2738,7 +2738,7 @@ COMMAND_CALLBACK(key) free (internal_code); return WEECHAT_RC_OK; } - + /* bind new key */ gui_key_verbose = 1; ptr_new_key = gui_key_bind (NULL, context, @@ -2754,7 +2754,7 @@ COMMAND_CALLBACK(key) } return WEECHAT_RC_OK; } - + /* unbind a key */ if (string_strcasecmp (argv[1], "unbind") == 0) { @@ -2803,20 +2803,20 @@ COMMAND_CALLBACK(key) } return WEECHAT_RC_OK; } - + /* reset a key to default binding */ if (string_strcasecmp (argv[1], "reset") == 0) { COMMAND_MIN_ARGS(3, "key reset"); - + return command_key_reset (GUI_KEY_CONTEXT_DEFAULT, argv[2]); } - + /* reset a key to default binding for a given context */ if (string_strcasecmp (argv[1], "resetctxt") == 0) { COMMAND_MIN_ARGS(4, "key reset"); - + /* search context */ context = gui_key_search_context (argv[2]); if (context < 0) @@ -2827,10 +2827,10 @@ COMMAND_CALLBACK(key) argv[2]); return WEECHAT_RC_OK; } - + return command_key_reset (context, argv[3]); } - + /* reset ALL keys (only with "-yes", for security reason) */ if (string_strcasecmp (argv[1], "resetall") == 0) { @@ -2861,7 +2861,7 @@ COMMAND_CALLBACK(key) } return WEECHAT_RC_OK; } - + /* add missing keys */ if (string_strcasecmp (argv[1], "missing") == 0) { @@ -2885,13 +2885,13 @@ COMMAND_CALLBACK(key) } return WEECHAT_RC_OK; } - + gui_chat_printf (NULL, _("%sError: unknown option for \"%s\" " "command"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], "key"); - + return WEECHAT_RC_OK; } @@ -2904,7 +2904,7 @@ command_layout_display_tree (struct t_gui_layout_window *layout_window, int indent) { char format[128]; - + if (layout_window) { if (layout_window->plugin_name) @@ -2944,10 +2944,10 @@ command_layout_display_tree (struct t_gui_layout_window *layout_window, (layout_window->split_horiz) ? _("horizontal split") : _("vertical split")); } - + if (layout_window->child1) command_layout_display_tree (layout_window->child1, indent + 1); - + if (layout_window->child2) command_layout_display_tree (layout_window->child2, indent + 1); } @@ -2961,12 +2961,12 @@ COMMAND_CALLBACK(layout) { struct t_gui_layout_buffer *ptr_layout_buffer; int flag_buffers, flag_windows; - + /* make C compiler happy */ (void) data; (void) buffer; (void) argv_eol; - + /* display all key bindings */ if (argc == 1) { @@ -2995,13 +2995,13 @@ COMMAND_CALLBACK(layout) } else gui_chat_printf (NULL, _("No layout saved")); - + return WEECHAT_RC_OK; } - + flag_buffers = 1; flag_windows = 1; - + if (argc > 2) { if (string_strcasecmp (argv[2], "buffers") == 0) @@ -3009,7 +3009,7 @@ COMMAND_CALLBACK(layout) else if (string_strcasecmp (argv[2], "windows") == 0) flag_buffers = 0; } - + /* save layout */ if (string_strcasecmp (argv[1], "save") == 0) { @@ -3026,10 +3026,10 @@ COMMAND_CALLBACK(layout) _("Layout saved for windows (buffer displayed by " "each window)")); } - + return WEECHAT_RC_OK; } - + /* apply layout */ if (string_strcasecmp (argv[1], "apply") == 0) { @@ -3037,7 +3037,7 @@ COMMAND_CALLBACK(layout) gui_layout_buffer_apply (gui_layout_buffers); if (flag_windows) gui_layout_window_apply (gui_layout_windows, -1); - + return WEECHAT_RC_OK; } @@ -3056,10 +3056,10 @@ COMMAND_CALLBACK(layout) gui_chat_printf (NULL, _("Layout reset for windows")); } - + return WEECHAT_RC_OK; } - + return WEECHAT_RC_OK; } @@ -3078,11 +3078,11 @@ command_mouse_timer_cb (void *data, int remaining_calls) gui_mouse_disable (); else gui_mouse_enable (); - + return WEECHAT_RC_OK; } -/* +/* * command_mouse_timer: timer for toggling mouse */ @@ -3091,7 +3091,7 @@ command_mouse_timer (const char *delay) { long seconds; char *error; - + error = NULL; seconds = strtol (delay, &error, 10); if (error && !error[0] && (seconds > 0)) @@ -3110,13 +3110,13 @@ COMMAND_CALLBACK(mouse) (void) data; (void) buffer; (void) argv_eol; - + if (argc == 1) { gui_mouse_display_state (); return WEECHAT_RC_OK; } - + /* enable mouse */ if (string_strcasecmp (argv[1], "enable") == 0) { @@ -3125,7 +3125,7 @@ COMMAND_CALLBACK(mouse) command_mouse_timer (argv[2]); return WEECHAT_RC_OK; } - + /* disable mouse */ if (string_strcasecmp (argv[1], "disable") == 0) { @@ -3134,7 +3134,7 @@ COMMAND_CALLBACK(mouse) command_mouse_timer (argv[2]); return WEECHAT_RC_OK; } - + /* toggle mouse */ if (string_strcasecmp (argv[1], "toggle") == 0) { @@ -3146,7 +3146,7 @@ COMMAND_CALLBACK(mouse) command_mouse_timer (argv[2]); return WEECHAT_RC_OK; } - + return WEECHAT_RC_OK; } @@ -3159,16 +3159,16 @@ COMMAND_CALLBACK(mute) int length, mute_mode; char *command, *ptr_command; struct t_gui_buffer *mute_buffer, *ptr_buffer; - + /* make C compiler happy */ (void) data; - + if (argc >= 2) { mute_mode = GUI_CHAT_MUTE_BUFFER; mute_buffer = gui_buffer_search_main (); ptr_command = argv_eol[1]; - + if (string_strcasecmp (argv[1], "-current") == 0) { mute_buffer = buffer; @@ -3189,12 +3189,12 @@ COMMAND_CALLBACK(mute) mute_buffer = NULL; ptr_command = argv_eol[2]; } - + if (ptr_command && ptr_command[0]) { gui_chat_mute = mute_mode; gui_chat_mute_buffer = mute_buffer; - + if (string_is_command_char (ptr_command)) { input_exec_command (buffer, 1, NULL, ptr_command); @@ -3210,12 +3210,12 @@ COMMAND_CALLBACK(mute) free (command); } } - + gui_chat_mute = GUI_CHAT_MUTE_DISABLED; gui_chat_mute_buffer = NULL; } } - + return WEECHAT_RC_OK; } @@ -3229,26 +3229,26 @@ command_plugin_list (const char *name, int full) struct t_weechat_plugin *ptr_plugin; struct t_hook *ptr_hook; int plugins_found, hook_found, interval; - + gui_chat_printf (NULL, ""); if (!name) { gui_chat_printf (NULL, _("Plugins loaded:")); } - + plugins_found = 0; - + for (ptr_plugin = weechat_plugins; ptr_plugin; ptr_plugin = ptr_plugin->next_plugin) { if (!name || (string_strcasestr (ptr_plugin->name, name))) { plugins_found++; - + if (full) { gui_chat_printf (NULL, ""); - + /* plugin info */ gui_chat_printf (NULL, " %s%s %s[%sv%s%s]%s: %s (%s)", @@ -3261,13 +3261,13 @@ command_plugin_list (const char *name, int full) GUI_COLOR(GUI_COLOR_CHAT), ptr_plugin->description, ptr_plugin->filename); - + /* second line of plugin info */ gui_chat_printf (NULL, _(" written by \"%s\", license: %s"), ptr_plugin->author, ptr_plugin->license); - + /* commands hooked */ hook_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; @@ -3287,7 +3287,7 @@ command_plugin_list (const char *name, int full) HOOK_COMMAND(ptr_hook, description) ? ")" : ""); } } - + /* command_run hooked */ hook_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND_RUN]; ptr_hook; @@ -3302,7 +3302,7 @@ command_plugin_list (const char *name, int full) HOOK_COMMAND_RUN(ptr_hook, command)); } } - + /* timers hooked */ hook_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_TIMER]; ptr_hook; @@ -3335,7 +3335,7 @@ command_plugin_list (const char *name, int full) (NG_("millisecond", "milliseconds", interval))); } } - + /* fd hooked */ hook_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_FD]; ptr_hook; @@ -3359,7 +3359,7 @@ command_plugin_list (const char *name, int full) _(" exception") : ""); } } - + /* process hooked */ hook_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_PROCESS]; ptr_hook; @@ -3378,7 +3378,7 @@ command_plugin_list (const char *name, int full) HOOK_PROCESS(ptr_hook, child_pid)); } } - + /* connect hooked */ hook_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_CONNECT]; ptr_hook; @@ -3399,7 +3399,7 @@ command_plugin_list (const char *name, int full) HOOK_CONNECT(ptr_hook, child_pid)); } } - + /* prints hooked */ hook_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_PRINT]; ptr_hook; @@ -3423,7 +3423,7 @@ command_plugin_list (const char *name, int full) HOOK_PRINT(ptr_hook, message) : _("(none)")); } } - + /* signals hooked */ hook_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_SIGNAL]; ptr_hook; @@ -3440,7 +3440,7 @@ command_plugin_list (const char *name, int full) HOOK_SIGNAL(ptr_hook, signal) : _("(all)")); } } - + /* config options hooked */ hook_found = 0; for (ptr_hook = weechat_hooks[HOOK_TYPE_CONFIG]; ptr_hook; @@ -3525,7 +3525,7 @@ COMMAND_CALLBACK(plugin) (void) data; (void) buffer; (void) argv_eol; - + switch (argc) { case 1: @@ -3574,7 +3574,7 @@ COMMAND_CALLBACK(plugin) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], "plugin"); } - + return WEECHAT_RC_OK; } @@ -3586,7 +3586,7 @@ void command_proxy_list () { struct t_proxy *ptr_proxy; - + if (weechat_proxies) { gui_chat_printf (NULL, ""); @@ -3626,11 +3626,11 @@ COMMAND_CALLBACK(proxy) long value; char *error; struct t_proxy *ptr_proxy; - + /* make C compiler happy */ (void) data; (void) buffer; - + /* list of bars */ if ((argc == 1) || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) @@ -3638,7 +3638,7 @@ COMMAND_CALLBACK(proxy) command_proxy_list (); return WEECHAT_RC_OK; } - + /* add a new proxy */ if (string_strcasecmp (argv[1], "add") == 0) { @@ -3690,10 +3690,10 @@ COMMAND_CALLBACK(proxy) argv[5], argv[2]); return WEECHAT_RC_OK; } - + return WEECHAT_RC_OK; } - + /* delete a proxy */ if (string_strcasecmp (argv[1], "del") == 0) { @@ -3717,10 +3717,10 @@ COMMAND_CALLBACK(proxy) proxy_free (ptr_proxy); gui_chat_printf (NULL, _("Proxy deleted")); } - + return WEECHAT_RC_OK; } - + /* set a proxy property */ if (string_strcasecmp (argv[1], "set") == 0) { @@ -3743,10 +3743,10 @@ COMMAND_CALLBACK(proxy) argv[3], argv[2]); return WEECHAT_RC_OK; } - + return WEECHAT_RC_OK; } - + gui_chat_printf (NULL, _("%sError: unknown option for \"%s\" " "command"), @@ -3763,11 +3763,11 @@ COMMAND_CALLBACK(quit) { int confirm_ok; char *pos_args; - + /* make C compiler happy */ (void) data; (void) buffer; - + confirm_ok = 0; pos_args = NULL; if (argc > 1) @@ -3781,7 +3781,7 @@ COMMAND_CALLBACK(quit) else pos_args = argv_eol[1]; } - + /* if confirmation is required, check that "-yes" is given */ if (CONFIG_BOOLEAN(config_look_confirm_quit) && !confirm_ok) { @@ -3791,16 +3791,16 @@ COMMAND_CALLBACK(quit) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_OK; } - + /* * send quit signal: some plugins like irc use this signal to disconnect * from servers */ hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, pos_args); - + /* force end of WeeChat main loop */ weechat_quit = 1; - + return WEECHAT_RC_OK; } @@ -3812,13 +3812,13 @@ void command_reload_file (struct t_config_file *config_file) { int rc; - + if (config_file->callback_reload) rc = (int) (config_file->callback_reload) (config_file->callback_reload_data, config_file); else rc = config_file_reload (config_file); - + if (rc == WEECHAT_RC_OK) { gui_chat_printf (NULL, @@ -3842,12 +3842,12 @@ COMMAND_CALLBACK(reload) { struct t_config_file *ptr_config_file; int i; - + /* make C compiler happy */ (void) data; (void) buffer; (void) argv_eol; - + if (argc > 1) { for (i = 1; i < argc; i++) @@ -3873,7 +3873,7 @@ COMMAND_CALLBACK(reload) command_reload_file (ptr_config_file); } } - + return WEECHAT_RC_OK; } @@ -3887,24 +3887,24 @@ command_repeat_timer_cb (void *data, int remaining_calls) char **repeat_args; int i; struct t_gui_buffer *ptr_buffer; - + repeat_args = (char **)data; - + if (!repeat_args) return WEECHAT_RC_ERROR; - + if (repeat_args[0] && repeat_args[1] && repeat_args[2]) { /* search buffer, fallback to core buffer if not found */ ptr_buffer = gui_buffer_search_by_name (repeat_args[0], repeat_args[1]); if (!ptr_buffer) ptr_buffer = gui_buffer_search_main (); - + /* execute command */ if (ptr_buffer) input_exec_command (ptr_buffer, 1, NULL, repeat_args[2]); } - + if (remaining_calls == 0) { for (i = 0; i < 3; i++) @@ -3914,7 +3914,7 @@ command_repeat_timer_cb (void *data, int remaining_calls) } free (repeat_args); } - + return WEECHAT_RC_OK; } @@ -3926,16 +3926,16 @@ COMMAND_CALLBACK(repeat) { int arg_count, count, interval, length, i; char *error, *command, **repeat_args; - + /* make C compiler happy */ (void) data; - + if (argc < 3) return WEECHAT_RC_OK; - + arg_count = 1; interval = 0; - + if ((argc >= 5) && (string_strcasecmp (argv[1], "-interval") == 0)) { error = NULL; @@ -3944,7 +3944,7 @@ COMMAND_CALLBACK(repeat) interval = 0; arg_count = 3; } - + error = NULL; count = (int)strtol (argv[arg_count], &error, 10); if (!error || error[0] || (count < 1)) @@ -3955,7 +3955,7 @@ COMMAND_CALLBACK(repeat) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_OK; } - + if (string_is_command_char (argv_eol[arg_count + 1])) command = strdup (argv_eol[arg_count + 1]); else @@ -3965,7 +3965,7 @@ COMMAND_CALLBACK(repeat) if (command) snprintf (command, length, "/%s", argv_eol[arg_count + 1]); } - + if (command) { input_exec_command (buffer, 1, NULL, command); @@ -4001,7 +4001,7 @@ COMMAND_CALLBACK(repeat) free (command); } } - + return WEECHAT_RC_OK; } @@ -4035,7 +4035,7 @@ COMMAND_CALLBACK(save) { struct t_config_file *ptr_config_file; int i; - + /* make C compiler happy */ (void) data; (void) buffer; @@ -4068,7 +4068,7 @@ COMMAND_CALLBACK(save) command_save_file (ptr_config_file); } } - + return WEECHAT_RC_OK; } @@ -4089,7 +4089,7 @@ command_set_display_section (struct t_config_file *config_file, GUI_COLOR(GUI_COLOR_CHAT), config_file->filename); } - + /* * command_set_display_option: display configuration option */ @@ -4195,9 +4195,9 @@ command_set_display_option_list (const char *message, const char *search) struct t_config_section *ptr_section; struct t_config_option *ptr_option; char *option_full_name; - + number_found = 0; - + for (ptr_config = config_files; ptr_config; ptr_config = ptr_config->next_config) { @@ -4205,7 +4205,7 @@ command_set_display_option_list (const char *message, const char *search) ptr_section = ptr_section->next_section) { section_displayed = 0; - + for (ptr_option = ptr_section->options; ptr_option; ptr_option = ptr_option->next_option) { @@ -4236,10 +4236,10 @@ command_set_display_option_list (const char *message, const char *search) } } } - + return number_found; } - + /* * command_set: set config options */ @@ -4249,20 +4249,20 @@ COMMAND_CALLBACK(set) char *value; int number_found, rc; struct t_config_option *ptr_option, *ptr_option_before; - + /* make C compiler happy */ (void) data; (void) buffer; - + /* display list of options */ if (argc < 3) { number_found = 0; - + number_found += command_set_display_option_list (NULL, (argc == 2) ? argv[1] : NULL); - + if (number_found == 0) { if (argc == 2) @@ -4309,7 +4309,7 @@ COMMAND_CALLBACK(set) } return WEECHAT_RC_OK; } - + /* set option value */ config_file_search_with_string (argv[1], NULL, NULL, &ptr_option_before, NULL); @@ -4347,7 +4347,7 @@ COMMAND_CALLBACK(set) gui_chat_printf (NULL, _("Option changed")); break; } - + return WEECHAT_RC_OK; } @@ -4362,15 +4362,15 @@ COMMAND_CALLBACK(unset) struct t_config_option *ptr_option, *next_option; char *option_full_name; int length, number_reset, number_removed; - + /* make C compiler happy */ (void) data; (void) buffer; (void) argv; - + number_reset = 0; number_removed = 0; - + if (argc >= 2) { for (ptr_config = config_files; ptr_config; @@ -4383,7 +4383,7 @@ COMMAND_CALLBACK(unset) while (ptr_option) { next_option = ptr_option->next_option; - + length = strlen (ptr_config->name) + 1 + strlen (ptr_section->name) + 1 + strlen (ptr_option->name) + 1; @@ -4421,7 +4421,7 @@ COMMAND_CALLBACK(unset) } free (option_full_name); } - + ptr_option = next_option; } } @@ -4431,7 +4431,7 @@ COMMAND_CALLBACK(unset) number_reset, number_removed); } - + return WEECHAT_RC_OK; } @@ -4445,12 +4445,12 @@ COMMAND_CALLBACK(upgrade) char *exec_args[7] = { NULL, "-a", "--dir", NULL, "--upgrade", NULL }; struct stat stat_buf; int rc; - + /* make C compiler happy */ (void) data; (void) buffer; (void) argv; - + /* * it is forbidden to upgrade while there are some background process * (hook type "process" or "connect") @@ -4463,7 +4463,7 @@ COMMAND_CALLBACK(upgrade) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_OK; } - + if (argc > 1) { ptr_binary = string_expand_home (argv_eol[1]); @@ -4496,7 +4496,7 @@ COMMAND_CALLBACK(upgrade) } else ptr_binary = strdup (weechat_argv0); - + if (!ptr_binary) { gui_chat_printf (NULL, @@ -4504,14 +4504,14 @@ COMMAND_CALLBACK(upgrade) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_OK; } - + gui_chat_printf (NULL, _("Upgrading WeeChat with binary file: \"%s\"..."), ptr_binary); - + /* send "upgrade" signal to plugins */ hook_signal_send ("upgrade", WEECHAT_HOOK_SIGNAL_STRING, NULL); - + if (!upgrade_weechat_save ()) { gui_chat_printf (NULL, @@ -4520,13 +4520,13 @@ COMMAND_CALLBACK(upgrade) free (ptr_binary); return WEECHAT_RC_OK; } - + exec_args[0] = ptr_binary; exec_args[3] = strdup (weechat_home); - + weechat_quit = 1; weechat_upgrading = 1; - + /* save layout, unload plugins, save config, then upgrade */ gui_layout_save_on_exit (); plugin_end (); @@ -4534,21 +4534,21 @@ COMMAND_CALLBACK(upgrade) (void) config_weechat_write (); gui_main_end (1); log_close (); - + execvp (exec_args[0], exec_args); - + /* this code should not be reached if execvp is ok */ string_iconv_fprintf (stderr, "\n\n*****\n"); string_iconv_fprintf (stderr, _("***** Error: exec failed (program: \"%s\"), exiting WeeChat"), exec_args[0]); string_iconv_fprintf (stderr, "\n*****\n\n"); - + free (exec_args[0]); free (exec_args[3]); - + exit (EXIT_FAILURE); - + /* never executed */ return WEECHAT_RC_ERROR; } @@ -4562,17 +4562,17 @@ COMMAND_CALLBACK(uptime) time_t running_time; int day, hour, min, sec; char string[512]; - + /* make C compiler happy */ (void) data; (void) argv_eol; - + running_time = time (NULL) - weechat_first_start_time; day = running_time / (60 * 60 * 24); hour = (running_time % (60 * 60 * 24)) / (60 * 60); min = ((running_time % (60 * 60 * 24)) % (60 * 60)) / 60; sec = ((running_time % (60 * 60 * 24)) % (60 * 60)) % 60; - + if ((argc >= 2) && (string_strcasecmp (argv[1], "-o") == 0)) { snprintf (string, sizeof (string), @@ -4622,7 +4622,7 @@ COMMAND_CALLBACK(uptime) GUI_COLOR(GUI_COLOR_CHAT_BUFFER), util_get_time_string (&weechat_first_start_time)); } - + return WEECHAT_RC_OK; } @@ -4636,7 +4636,7 @@ command_version_display (struct t_gui_buffer *buffer, int translated_string) { char string[512]; - + if (send_to_buffer_as_input) { if (translated_string) @@ -4710,7 +4710,7 @@ command_version_display (struct t_gui_buffer *buffer, COMMAND_CALLBACK(version) { int send_to_buffer_as_input, translated_string; - + /* make C compiler happy */ (void) data; (void) argv_eol; @@ -4728,10 +4728,10 @@ COMMAND_CALLBACK(version) translated_string = 1; } } - + command_version_display (buffer, send_to_buffer_as_input, translated_string); - + return WEECHAT_RC_OK; } @@ -4745,34 +4745,34 @@ command_wait_timer_cb (void *data, int remaining_calls) char **timer_args; int i; struct t_gui_buffer *ptr_buffer; - + /* make C compiler happy */ (void) remaining_calls; - + timer_args = (char **)data; - + if (!timer_args) return WEECHAT_RC_ERROR; - + if (timer_args[0] && timer_args[1] && timer_args[2]) { /* search buffer, fallback to core buffer if not found */ ptr_buffer = gui_buffer_search_by_name (timer_args[0], timer_args[1]); if (!ptr_buffer) ptr_buffer = gui_buffer_search_main (); - + /* execute command */ if (ptr_buffer) input_data (ptr_buffer, timer_args[2]); } - + for (i = 0; i < 3; i++) { if (timer_args[i]) free (timer_args[i]); } free (timer_args); - + return WEECHAT_RC_OK; } @@ -4785,10 +4785,10 @@ COMMAND_CALLBACK(wait) char *pos, *str_number, *error; long number, factor, delay; char **timer_args; - + /* make C compiler happy */ (void) data; - + if (argc > 2) { pos = argv[1]; @@ -4796,10 +4796,10 @@ COMMAND_CALLBACK(wait) { pos++; } - + /* default is seconds (1000 milliseconds) */ factor = 1000; - + if ((pos != argv[1]) && pos[0]) { str_number = string_strndup (argv[1], pos - argv[1]); @@ -4816,7 +4816,7 @@ COMMAND_CALLBACK(wait) } else str_number = strdup (argv[1]); - + if (str_number) { error = NULL; @@ -4825,7 +4825,7 @@ COMMAND_CALLBACK(wait) { free (str_number); delay = number * factor; - + /* build arguments for timer callback */ timer_args = malloc (3 * sizeof (*timer_args)); if (!timer_args) @@ -4838,18 +4838,18 @@ COMMAND_CALLBACK(wait) timer_args[0] = strdup (gui_buffer_get_plugin_name (buffer)); timer_args[1] = strdup (buffer->name); timer_args[2] = strdup (argv_eol[2]); - + /* schedule command, execute it after "delay" milliseconds */ hook_timer (NULL, delay, 0, 1, &command_wait_timer_cb, timer_args); - + return WEECHAT_RC_OK; } free (str_number); return WEECHAT_RC_ERROR; } } - + return WEECHAT_RC_OK; } @@ -4863,19 +4863,19 @@ COMMAND_CALLBACK(window) char *error; long number; int win_args; - + /* make C compiler happy */ (void) data; (void) buffer; (void) argv_eol; - + if ((argc == 1) || ((argc == 2) && (string_strcasecmp (argv[1], "list") == 0))) { /* list all windows */ gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Windows list:")); - + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { gui_chat_printf (NULL, "%s[%s%d%s] (%s%d:%d%s;%s%dx%d%s) ", @@ -4892,17 +4892,17 @@ COMMAND_CALLBACK(window) ptr_win->win_height, GUI_COLOR(GUI_COLOR_CHAT_DELIMITERS)); } - + return WEECHAT_RC_OK; } - + /* refresh screen */ if (string_strcasecmp (argv[1], "refresh") == 0) { gui_window_ask_refresh (2); return WEECHAT_RC_OK; } - + /* balance windows */ if (string_strcasecmp (argv[1], "balance") == 0) { @@ -4910,7 +4910,7 @@ COMMAND_CALLBACK(window) gui_window_ask_refresh (1); return WEECHAT_RC_OK; } - + /* * search window, for actions related to a given window * (default is current window if no number is given) @@ -4935,21 +4935,21 @@ COMMAND_CALLBACK(window) gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); return WEECHAT_RC_OK; } - + /* page up */ if (string_strcasecmp (argv[1], "page_up") == 0) { gui_window_page_up (ptr_win); return WEECHAT_RC_OK; } - + /* page down */ if (string_strcasecmp (argv[1], "page_down") == 0) { gui_window_page_down (ptr_win); return WEECHAT_RC_OK; } - + /* vertical scroll */ if (string_strcasecmp (argv[1], "scroll") == 0) { @@ -4957,7 +4957,7 @@ COMMAND_CALLBACK(window) gui_window_scroll (ptr_win, argv[win_args]); return WEECHAT_RC_OK; } - + /* horizontal scroll in window (for buffers with free content) */ if (string_strcasecmp (argv[1], "scroll_horiz") == 0) { @@ -4968,49 +4968,49 @@ COMMAND_CALLBACK(window) } return WEECHAT_RC_OK; } - + /* scroll up */ if (string_strcasecmp (argv[1], "scroll_up") == 0) { gui_window_scroll_up (ptr_win); return WEECHAT_RC_OK; } - + /* scroll down */ if (string_strcasecmp (argv[1], "scroll_down") == 0) { gui_window_scroll_down (ptr_win); return WEECHAT_RC_OK; } - + /* scroll to top of window */ if (string_strcasecmp (argv[1], "scroll_top") == 0) { gui_window_scroll_top (ptr_win); return WEECHAT_RC_OK; } - + /* scroll to bottom of window */ if (string_strcasecmp (argv[1], "scroll_bottom") == 0) { gui_window_scroll_bottom (ptr_win); return WEECHAT_RC_OK; } - + /* scroll to previous highlight */ if (string_strcasecmp (argv[1], "scroll_previous_highlight") == 0) { gui_window_scroll_previous_highlight (ptr_win); return WEECHAT_RC_OK; } - + /* scroll to next highlight */ if (string_strcasecmp (argv[1], "scroll_next_highlight") == 0) { gui_window_scroll_next_highlight (ptr_win); return WEECHAT_RC_OK; } - + /* split window horizontally */ if (string_strcasecmp (argv[1], "splith") == 0) { @@ -5026,10 +5026,10 @@ COMMAND_CALLBACK(window) } else gui_window_split_horizontal (ptr_win, 50); - + return WEECHAT_RC_OK; } - + /* split window vertically */ if (string_strcasecmp (argv[1], "splitv") == 0) { @@ -5045,10 +5045,10 @@ COMMAND_CALLBACK(window) } else gui_window_split_vertical (ptr_win, 50); - + return WEECHAT_RC_OK; } - + /* resize window */ if (string_strcasecmp (argv[1], "resize") == 0) { @@ -5078,7 +5078,7 @@ COMMAND_CALLBACK(window) } return WEECHAT_RC_OK; } - + /* merge windows */ if (string_strcasecmp (argv[1], "merge") == 0) { @@ -5110,49 +5110,49 @@ COMMAND_CALLBACK(window) } return WEECHAT_RC_OK; } - + /* switch to previous window */ if (string_strcasecmp (argv[1], "-1") == 0) { gui_window_switch_previous (ptr_win); return WEECHAT_RC_OK; } - + /* switch to next window */ if (string_strcasecmp (argv[1], "+1") == 0) { gui_window_switch_next (ptr_win); return WEECHAT_RC_OK; } - + /* switch to window above */ if (string_strcasecmp (argv[1], "up") == 0) { gui_window_switch_up (ptr_win); return WEECHAT_RC_OK; } - + /* switch to window below */ if (string_strcasecmp (argv[1], "down") == 0) { gui_window_switch_down (ptr_win); return WEECHAT_RC_OK; } - + /* switch to window on the left */ if (string_strcasecmp (argv[1], "left") == 0) { gui_window_switch_left (ptr_win); return WEECHAT_RC_OK; } - + /* switch to window on the right */ if (string_strcasecmp (argv[1], "right") == 0) { gui_window_switch_right (ptr_win); return WEECHAT_RC_OK; } - + /* swap windows */ if (string_strcasecmp (argv[1], "swap") == 0) { @@ -5182,14 +5182,14 @@ COMMAND_CALLBACK(window) } return WEECHAT_RC_OK; } - + /* zoom window */ if (string_strcasecmp (argv[1], "zoom") == 0) { gui_window_zoom (ptr_win); return WEECHAT_RC_OK; } - + /* jump to window by buffer number */ if (string_strncasecmp (argv[1], "b", 1) == 0) { @@ -5201,7 +5201,7 @@ COMMAND_CALLBACK(window) return WEECHAT_RC_OK; } } - + /* jump to window by number */ error = NULL; number = strtol (argv[1], &error, 10); @@ -5210,7 +5210,7 @@ COMMAND_CALLBACK(window) gui_window_switch_by_number (number); return WEECHAT_RC_OK; } - + gui_chat_printf (NULL, _("%sError: unknown option for \"%s\" " "command"), @@ -6083,12 +6083,12 @@ command_startup (int plugins_loaded) { char *command, **commands, **ptr_cmd; struct t_gui_buffer *weechat_buffer; - + if (plugins_loaded) command = CONFIG_STRING(config_startup_command_after_plugins); else command = CONFIG_STRING(config_startup_command_before_plugins); - + if (command && command[0]) { commands = string_split_command (command, ';'); diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c index 6f4bc06e2..631054968 100644 --- a/src/core/wee-completion.c +++ b/src/core/wee-completion.c @@ -65,18 +65,18 @@ completion_list_add_bars_names_cb (void *data, struct t_gui_completion *completion) { struct t_gui_bar *ptr_bar; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_bar = gui_bars; ptr_bar; ptr_bar = ptr_bar->next_bar) { gui_completion_list_add (completion, ptr_bar->name, 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -91,18 +91,18 @@ completion_list_add_bars_options_cb (void *data, struct t_gui_completion *completion) { int i; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (i = 0; i < GUI_BAR_NUM_OPTIONS; i++) { gui_completion_list_add (completion, gui_bar_option_string[i], 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -117,19 +117,19 @@ completion_list_add_buffers_names_cb (void *data, struct t_gui_completion *completion) { struct t_gui_buffer *ptr_buffer; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { gui_completion_list_add (completion, ptr_buffer->name, 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -145,12 +145,12 @@ completion_list_add_buffers_numbers_cb (void *data, { struct t_gui_buffer *ptr_buffer; char str_number[32]; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { @@ -158,7 +158,7 @@ completion_list_add_buffers_numbers_cb (void *data, gui_completion_list_add (completion, str_number, 0, WEECHAT_LIST_POS_END); } - + return WEECHAT_RC_OK; } @@ -175,12 +175,12 @@ completion_list_add_buffers_plugins_names_cb (void *data, { struct t_gui_buffer *ptr_buffer; char name[512]; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { @@ -190,7 +190,7 @@ completion_list_add_buffers_plugins_names_cb (void *data, gui_completion_list_add (completion, name, 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -206,19 +206,19 @@ completion_list_add_buffer_properties_set_cb (void *data, struct t_gui_completion *completion) { int i; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (i = 0; gui_buffer_properties_set[i]; i++) { gui_completion_list_add (completion, gui_buffer_properties_set[i], 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -234,12 +234,12 @@ completion_list_add_buffer_properties_get_cb (void *data, struct t_gui_completion *completion) { int i; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (i = 0; gui_buffer_properties_get_integer[i]; i++) { gui_completion_list_add (completion, @@ -258,7 +258,7 @@ completion_list_add_buffer_properties_get_cb (void *data, gui_buffer_properties_get_pointer[i], 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -274,19 +274,19 @@ completion_list_add_windows_numbers_cb (void *data, { struct t_gui_window *ptr_win; char str_number[32]; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_win = gui_windows; ptr_win; ptr_win = ptr_win->next_window) { snprintf (str_number, sizeof (str_number), "%d", ptr_win->number); gui_completion_list_add (completion, str_number, 0, WEECHAT_LIST_POS_END); } - + return WEECHAT_RC_OK; } @@ -302,7 +302,7 @@ completion_list_map_add_palette_color_cb (void *data, /* make C compiler happy */ (void) hashtable; (void) value; - + gui_completion_list_add ((struct t_gui_completion *)data, (char *)key, 0, WEECHAT_LIST_POS_SORT); @@ -322,11 +322,11 @@ completion_list_add_palette_colors_cb (void *data, (void) data; (void) completion_item; (void) buffer; - + hashtable_map (gui_color_hash_palette_color, &completion_list_map_add_palette_color_cb, completion); - + return WEECHAT_RC_OK; } @@ -341,19 +341,19 @@ completion_list_add_config_files_cb (void *data, struct t_gui_completion *completion) { struct t_config_file *ptr_config_file; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_config_file = config_files; ptr_config_file; ptr_config_file = ptr_config_file->next_config) { gui_completion_list_add (completion, ptr_config_file->name, 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -375,19 +375,19 @@ completion_list_add_filename_cb (void *data, struct dirent *entry; struct stat statbuf; char home[3] = { '~', DIR_SEPARATOR_CHAR, '\0' }; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + buf_len = PATH_MAX; buf = malloc (buf_len); if (!buf) return WEECHAT_RC_OK; - + completion->add_space = 0; - + if ((strncmp (completion->base_word, home, 2) == 0) && getenv("HOME")) { real_prefix = strdup (getenv("HOME")); @@ -407,7 +407,7 @@ completion_list_add_filename_cb (void *data, prefix = strdup (DIR_SEPARATOR); } } - + snprintf (buf, buf_len, "%s", completion->base_word + strlen (prefix)); p = strrchr (buf, DIR_SEPARATOR_CHAR); if (p) @@ -422,7 +422,7 @@ completion_list_add_filename_cb (void *data, path_d = strdup (""); path_b = strdup (buf); } - + sprintf (buf, "%s%s%s", real_prefix, DIR_SEPARATOR, path_d); d_name = strdup (buf); dp = opendir (d_name); @@ -434,12 +434,12 @@ completion_list_add_filename_cb (void *data, { if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0) continue; - + snprintf (buf, buf_len, "%s%s%s", d_name, DIR_SEPARATOR, entry->d_name); if (stat (buf, &statbuf) == -1) continue; - + snprintf (buf, buf_len, "%s%s%s%s%s%s", prefix, ((strcmp(prefix, "") == 0) @@ -448,21 +448,21 @@ completion_list_add_filename_cb (void *data, strcmp(path_d, "") == 0 ? "" : DIR_SEPARATOR, entry->d_name, S_ISDIR(statbuf.st_mode) ? DIR_SEPARATOR : ""); - + gui_completion_list_add (completion, buf, 0, WEECHAT_LIST_POS_SORT); } } closedir (dp); } - + free (d_name); free (prefix); free (real_prefix); free (path_d); free (path_b); free (buf); - + return WEECHAT_RC_OK; } @@ -477,19 +477,19 @@ completion_list_add_filters_cb (void *data, struct t_gui_completion *completion) { struct t_gui_filter *ptr_filter; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_filter = gui_filters; ptr_filter; ptr_filter = ptr_filter->next_filter) { gui_completion_list_add (completion, ptr_filter->name, 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -504,12 +504,12 @@ completion_list_add_commands_cb (void *data, struct t_gui_completion *completion) { struct t_hook *ptr_hook; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; ptr_hook = ptr_hook->next_hook) { @@ -520,7 +520,7 @@ completion_list_add_commands_cb (void *data, HOOK_COMMAND(ptr_hook, command), 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -535,12 +535,12 @@ completion_list_add_infos_cb (void *data, struct t_gui_completion *completion) { struct t_hook *ptr_hook; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_hook = weechat_hooks[HOOK_TYPE_INFO]; ptr_hook; ptr_hook = ptr_hook->next_hook) { @@ -551,7 +551,7 @@ completion_list_add_infos_cb (void *data, HOOK_INFO(ptr_hook, info_name), 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -566,12 +566,12 @@ completion_list_add_infolists_cb (void *data, struct t_gui_completion *completion) { struct t_hook *ptr_hook; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_hook = weechat_hooks[HOOK_TYPE_INFOLIST]; ptr_hook; ptr_hook = ptr_hook->next_hook) { @@ -582,7 +582,7 @@ completion_list_add_infolists_cb (void *data, HOOK_INFOLIST(ptr_hook, infolist_name), 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -599,12 +599,12 @@ completion_list_add_nicks_cb (void *data, struct t_gui_nick_group *ptr_group; struct t_gui_nick *ptr_nick; int count_before; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + count_before = weelist_size (completion->completion_list); hook_completion_exec (completion->buffer->plugin, "nick", @@ -630,7 +630,7 @@ completion_list_add_nicks_cb (void *data, &ptr_group, &ptr_nick); } } - + return WEECHAT_RC_OK; } @@ -650,12 +650,12 @@ completion_list_add_config_options_cb (void *data, struct t_config_option *ptr_option; int length; char *option_full_name; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_config = config_files; ptr_config; ptr_config = ptr_config->next_config) { @@ -682,7 +682,7 @@ completion_list_add_config_options_cb (void *data, } } } - + return WEECHAT_RC_OK; } @@ -697,19 +697,19 @@ completion_list_add_plugins_cb (void *data, struct t_gui_completion *completion) { struct t_weechat_plugin *ptr_plugin; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_plugin = weechat_plugins; ptr_plugin; ptr_plugin = ptr_plugin->next_plugin) { gui_completion_list_add (completion, ptr_plugin->name, 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -728,12 +728,12 @@ completion_list_add_plugins_commands_cb (void *data, char *pos_space, *plugin_name; struct t_weechat_plugin *ptr_plugin; struct t_hook *ptr_hook; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + if (completion->args) { pos_space = strchr (completion->args, ' '); @@ -742,7 +742,7 @@ completion_list_add_plugins_commands_cb (void *data, pos_space - completion->args); else plugin_name = strdup (completion->args); - + if (plugin_name) { ptr_plugin = NULL; @@ -772,7 +772,7 @@ completion_list_add_plugins_commands_cb (void *data, free (plugin_name); } } - + return WEECHAT_RC_OK; } @@ -788,7 +788,7 @@ completion_list_map_add_color_alias_cb (void *data, /* make C compiler happy */ (void) hashtable; (void) value; - + gui_completion_list_add ((struct t_gui_completion *)data, (char *)key, 0, WEECHAT_LIST_POS_SORT); @@ -813,12 +813,12 @@ completion_list_add_config_option_values_cb (void *data, struct t_config_section *ptr_section, *section_found; struct t_config_option *option_found; struct t_gui_color_palette *color_palette; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + if (completion->args) { pos_space = strchr (completion->args, ' '); @@ -827,16 +827,16 @@ completion_list_add_config_option_values_cb (void *data, pos_space - completion->args); else option_full_name = strdup (completion->args); - + if (option_full_name) { file = NULL; section = NULL; pos_option = NULL; - + pos_section = strchr (option_full_name, '.'); pos_option = (pos_section) ? strchr (pos_section + 1, '.') : NULL; - + if (pos_section && pos_option) { file = string_strndup (option_full_name, @@ -1043,7 +1043,7 @@ completion_list_add_config_option_values_cb (void *data, free (section); } } - + return WEECHAT_RC_OK; } @@ -1059,12 +1059,12 @@ completion_list_add_weechat_commands_cb (void *data, struct t_gui_completion *completion) { struct t_hook *ptr_hook; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; ptr_hook = ptr_hook->next_hook) { @@ -1078,7 +1078,7 @@ completion_list_add_weechat_commands_cb (void *data, 0, WEECHAT_LIST_POS_SORT); } } - + return WEECHAT_RC_OK; } @@ -1093,19 +1093,19 @@ completion_list_add_proxies_names_cb (void *data, struct t_gui_completion *completion) { struct t_proxy *ptr_proxy; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (ptr_proxy = weechat_proxies; ptr_proxy; ptr_proxy = ptr_proxy->next_proxy) { gui_completion_list_add (completion, ptr_proxy->name, 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -1120,18 +1120,18 @@ completion_list_add_proxies_options_cb (void *data, struct t_gui_completion *completion) { int i; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (i = 0; i < PROXY_NUM_OPTIONS; i++) { gui_completion_list_add (completion, proxy_option_string[i], 0, WEECHAT_LIST_POS_SORT); } - + return WEECHAT_RC_OK; } @@ -1146,18 +1146,18 @@ completion_list_add_keys_contexts_cb (void *data, struct t_gui_completion *completion) { int i; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++) { gui_completion_list_add (completion, gui_key_context_string[i], 0, WEECHAT_LIST_POS_END); } - + return WEECHAT_RC_OK; } @@ -1174,7 +1174,7 @@ completion_list_add_keys_codes_cb (void *data, int i; struct t_gui_key *ptr_key; char *expanded_name; - + /* make C compiler happy */ (void) data; (void) completion_item; @@ -1192,7 +1192,7 @@ completion_list_add_keys_codes_cb (void *data, free (expanded_name); } } - + return WEECHAT_RC_OK; } @@ -1211,7 +1211,7 @@ completion_list_add_keys_codes_for_reset_cb (void *data, int i; struct t_gui_key *ptr_key, *ptr_default_key; char *expanded_name; - + /* make C compiler happy */ (void) data; (void) completion_item; @@ -1234,7 +1234,7 @@ completion_list_add_keys_codes_for_reset_cb (void *data, free (expanded_name); } } - + /* keys deleted */ for (ptr_default_key = gui_default_keys[i]; ptr_default_key; ptr_default_key = ptr_default_key->next_key) @@ -1251,7 +1251,7 @@ completion_list_add_keys_codes_for_reset_cb (void *data, } } } - + return WEECHAT_RC_OK; } @@ -1268,15 +1268,15 @@ completion_list_add_cursor_areas_cb (void *data, { struct t_gui_bar_window *ptr_bar_win; struct t_gui_bar *ptr_bar; - + /* make C compiler happy */ (void) data; (void) completion_item; (void) buffer; - + /* add "chat" for chat area */ gui_completion_list_add (completion, "chat", 0, WEECHAT_LIST_POS_SORT); - + /* add bar windows (of current window) */ for (ptr_bar_win = gui_current_window->bar_windows; ptr_bar_win; ptr_bar_win = ptr_bar_win->next_bar_window) @@ -1292,7 +1292,7 @@ completion_list_add_cursor_areas_cb (void *data, 0, WEECHAT_LIST_POS_SORT); } } - + return WEECHAT_RC_OK; } diff --git a/src/core/wee-config-file.c b/src/core/wee-config-file.c index 12f3ac612..4cdcb4123 100644 --- a/src/core/wee-config-file.c +++ b/src/core/wee-config-file.c @@ -65,17 +65,17 @@ struct t_config_file * config_file_search (const char *name) { struct t_config_file *ptr_config; - + if (!name) return NULL; - + for (ptr_config = config_files; ptr_config; ptr_config = ptr_config->next_config) { if (string_strcasecmp (ptr_config->name, name) == 0) return ptr_config; } - + /* configuration file not found */ return NULL; } @@ -93,14 +93,14 @@ config_file_new (struct t_weechat_plugin *plugin, const char *name, struct t_config_file *new_config_file; char *filename; int length; - + if (!name) return NULL; - + /* it's NOT authorized to create two configuration files with same filename */ if (config_file_search (name)) return NULL; - + new_config_file = malloc (sizeof (*new_config_file)); if (new_config_file) { @@ -132,7 +132,7 @@ config_file_new (struct t_weechat_plugin *plugin, const char *name, new_config_file->callback_reload_data = callback_reload_data; new_config_file->sections = NULL; new_config_file->last_section = NULL; - + new_config_file->prev_config = last_config_file; new_config_file->next_config = NULL; if (config_files) @@ -141,7 +141,7 @@ config_file_new (struct t_weechat_plugin *plugin, const char *name, config_files = new_config_file; last_config_file = new_config_file; } - + return new_config_file; } @@ -179,13 +179,13 @@ config_file_new_section (struct t_config_file *config_file, const char *name, void *callback_delete_option_data) { struct t_config_section *new_section; - + if (!config_file || !name) return NULL; - + if (config_file_search_section (config_file, name)) return NULL; - + new_section = malloc (sizeof (*new_section)); if (new_section) { @@ -210,7 +210,7 @@ config_file_new_section (struct t_config_file *config_file, const char *name, new_section->callback_delete_option_data = callback_delete_option_data; new_section->options = NULL; new_section->last_option = NULL; - + new_section->prev_section = config_file->last_section; new_section->next_section = NULL; if (config_file->sections) @@ -219,7 +219,7 @@ config_file_new_section (struct t_config_file *config_file, const char *name, config_file->sections = new_section; config_file->last_section = new_section; } - + return new_section; } @@ -235,14 +235,14 @@ config_file_search_section (struct t_config_file *config_file, if (!config_file || !section_name) return NULL; - + for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) { if (string_strcasecmp (ptr_section->name, section_name) == 0) return ptr_section; } - + /* section not found */ return NULL; } @@ -256,10 +256,10 @@ config_file_option_full_name (struct t_config_option *option) { int length_option; char *option_full_name; - + if (!option) return NULL; - + length_option = strlen (option->config_file->name) + 1 + strlen (option->section->name) + 1 + strlen (option->name) + 1; option_full_name = malloc (length_option); @@ -271,7 +271,7 @@ config_file_option_full_name (struct t_config_option *option) option->section->name, option->name); } - + return option_full_name; } @@ -283,7 +283,7 @@ void config_file_hook_config_exec (struct t_config_option *option) { char *option_full_name, str_value[256]; - + if (option) { option_full_name = config_file_option_full_name (option); @@ -322,7 +322,7 @@ config_file_hook_config_exec (struct t_config_option *option) } else hook_config_exec (option_full_name, NULL); - + free (option_full_name); } } @@ -347,7 +347,7 @@ config_file_option_find_pos (struct t_config_section *section, const char *name) return ptr_option; } } - + /* position not found (we will add to the end of list) */ return NULL; } @@ -361,10 +361,10 @@ void config_file_option_insert_in_section (struct t_config_option *option) { struct t_config_option *pos_option; - + if (!option || !option->section) return; - + if (option->section->options) { pos_option = config_file_option_find_pos (option->section, @@ -407,7 +407,7 @@ struct t_config_option * config_file_option_malloc () { struct t_config_option *new_option; - + new_option = malloc (sizeof (*new_option)); if (new_option) { @@ -432,7 +432,7 @@ config_file_option_malloc () new_option->prev_option = NULL; new_option->next_option = NULL; } - + return new_option; } @@ -463,14 +463,14 @@ config_file_new_option (struct t_config_file *config_file, int var_type, int_value, argc, i, index_value; long number; char *error; - + if (!name) return NULL; - + if (config_file && section && config_file_search_option (config_file, section, name)) return NULL; - + var_type = -1; for (i = 0; i < CONFIG_NUM_OPTION_TYPES; i++) { @@ -487,7 +487,7 @@ config_file_new_option (struct t_config_file *config_file, type); return NULL; } - + if (!null_value_allowed) { if (default_value && !value) @@ -497,7 +497,7 @@ config_file_new_option (struct t_config_file *config_file, if (!default_value || !value) return NULL; } - + new_option = config_file_option_malloc (); if (new_option) { @@ -677,14 +677,14 @@ config_file_new_option (struct t_config_file *config_file, new_option->prev_option = NULL; new_option->next_option = NULL; } - + /* run config hook(s) */ if (new_option->config_file && new_option->section) { config_file_hook_config_exec (new_option); } } - + return new_option; error: @@ -730,7 +730,7 @@ config_file_search_option (struct t_config_file *config_file, } } } - + /* option not found */ return NULL; } @@ -749,10 +749,10 @@ config_file_search_section_option (struct t_config_file *config_file, { struct t_config_section *ptr_section; struct t_config_option *ptr_option; - + *section_found = NULL; *option_found = NULL; - + if (section) { for (ptr_option = section->options; ptr_option; @@ -810,15 +810,15 @@ config_file_search_with_string (const char *option_name, *option = NULL; if (pos_option_name) *pos_option_name = NULL; - + ptr_config = NULL; ptr_section = NULL; ptr_option = NULL; - + file_name = NULL; section_name = NULL; pos_option = NULL; - + pos_section = strchr (option_name, '.'); pos_option = (pos_section) ? strchr (pos_section + 1, '.') : NULL; if (pos_section && pos_option) @@ -845,12 +845,12 @@ config_file_search_with_string (const char *option_name, } } } - + if (file_name) free (file_name); if (section_name) free (section_name); - + if (config_file) *config_file = ptr_config; if (section) @@ -867,10 +867,10 @@ int config_file_string_boolean_is_valid (const char *text) { int i; - + if (!text) return 0; - + for (i = 0; config_boolean_true[i]; i++) { if (string_strcasecmp (text, config_boolean_true[i]) == 0) @@ -882,7 +882,7 @@ config_file_string_boolean_is_valid (const char *text) if (string_strcasecmp (text, config_boolean_false[i]) == 0) return 1; } - + /* text is not a boolean */ return 0; } @@ -896,16 +896,16 @@ int config_file_string_to_boolean (const char *text) { int i; - + if (!text) return CONFIG_BOOLEAN_FALSE; - + 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; } @@ -921,12 +921,12 @@ int config_file_option_reset (struct t_config_option *option, int run_callback) { int rc, old_value_was_null; - + if (!option) return WEECHAT_CONFIG_OPTION_SET_ERROR; - + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; - + if (option->default_value) { old_value_was_null = (option->value == NULL); @@ -1018,20 +1018,20 @@ config_file_option_reset (struct t_config_option *option, int run_callback) rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } - + if ((rc == WEECHAT_CONFIG_OPTION_SET_OK_CHANGED) && run_callback && option->callback_change) { (void)(option->callback_change)(option->callback_change_data, option); } - + /* run config hook(s) */ if ((rc != WEECHAT_CONFIG_OPTION_SET_ERROR) && option->config_file && option->section) { config_file_hook_config_exec (option); } - + return rc; } @@ -1050,12 +1050,12 @@ config_file_option_set (struct t_config_option *option, const char *value, int value_int, i, rc, new_value_ok, old_value_was_null, old_value; long number; char *error; - + if (!option) return WEECHAT_CONFIG_OPTION_SET_ERROR; - + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; - + if (option->callback_check_value) { if (!(int)(option->callback_check_value) @@ -1064,7 +1064,7 @@ config_file_option_set (struct t_config_option *option, const char *value, value)) return WEECHAT_CONFIG_OPTION_SET_ERROR; } - + if (value) { old_value_was_null = (option->value == NULL); @@ -1329,21 +1329,21 @@ config_file_option_set (struct t_config_option *option, const char *value, else rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } - + /* run callback if asked and value was changed */ if ((rc == WEECHAT_CONFIG_OPTION_SET_OK_CHANGED) && run_callback && option->callback_change) { (void)(option->callback_change)(option->callback_change_data, option); } - + /* run config hook(s) */ if ((rc != WEECHAT_CONFIG_OPTION_SET_ERROR) && option->config_file && option->section) { config_file_hook_config_exec (option); } - + return rc; } @@ -1359,12 +1359,12 @@ int config_file_option_set_null (struct t_config_option *option, int run_callback) { int rc; - + if (!option) return WEECHAT_CONFIG_OPTION_SET_ERROR; - + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; - + /* null value is authorized only if it's allowed in option */ if (option->null_value_allowed) { @@ -1379,21 +1379,21 @@ config_file_option_set_null (struct t_config_option *option, int run_callback) rc = WEECHAT_CONFIG_OPTION_SET_OK_CHANGED; } } - + /* run callback if asked and value was changed */ if ((rc == WEECHAT_CONFIG_OPTION_SET_OK_CHANGED) && run_callback && option->callback_change) { (void)(option->callback_change)(option->callback_change_data, option); } - + /* run config hook(s) */ if ((rc != WEECHAT_CONFIG_OPTION_SET_ERROR) && option->config_file && option->section) { config_file_hook_config_exec (option); } - + return rc; } @@ -1411,12 +1411,12 @@ config_file_option_unset (struct t_config_option *option) { int rc; char *option_full_name; - + if (!option) return WEECHAT_CONFIG_OPTION_UNSET_ERROR; - + rc = WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET; - + if (option->section && option->section->user_can_delete_options) { /* delete option */ @@ -1426,7 +1426,7 @@ config_file_option_unset (struct t_config_option *option) (option->callback_delete_data, option); } - + option_full_name = config_file_option_full_name (option); if (option->section->callback_delete_option) @@ -1442,7 +1442,7 @@ config_file_option_unset (struct t_config_option *option) config_file_option_free (option); rc = WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; } - + if (option_full_name) { hook_config_exec (option_full_name, NULL); @@ -1465,7 +1465,7 @@ config_file_option_unset (struct t_config_option *option) break; } } - + return rc; } @@ -1478,7 +1478,7 @@ config_file_option_rename (struct t_config_option *option, const char *new_name) { char *str_new_name; - + if (!option || !new_name || !new_name[0] || config_file_search_option (option->config_file, option->section, new_name)) return; @@ -1498,12 +1498,12 @@ config_file_option_rename (struct t_config_option *option, if (option->section->last_option == option) (option->section)->last_option = option->prev_option; } - + /* rename option */ if (option->name) free (option->name); option->name = str_new_name; - + /* re-insert option in section */ if (option->section) config_file_option_insert_in_section (option); @@ -1520,7 +1520,7 @@ config_file_option_get_pointer (struct t_config_option *option, { if (!option || !property) return NULL; - + if (string_strcasecmp (property, "config_file") == 0) return option->config_file; else if (string_strcasecmp (property, "section") == 0) @@ -1545,7 +1545,7 @@ config_file_option_get_pointer (struct t_config_option *option, return option->prev_option; else if (string_strcasecmp (property, "next_option") == 0) return option->next_option; - + return NULL; } @@ -1559,7 +1559,7 @@ config_file_option_is_null (struct t_config_option *option) { if (!option) return 1; - + return (option->value) ? 0 : 1; } @@ -1573,7 +1573,7 @@ config_file_option_default_is_null (struct t_config_option *option) { if (!option) return 1; - + return (option->default_value) ? 0 : 1; } @@ -1595,12 +1595,12 @@ config_file_option_set_with_string (const char *option_name, const char *value) struct t_config_section *ptr_section; struct t_config_option *ptr_option; char *pos_option; - + rc = WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND; - + config_file_search_with_string (option_name, &ptr_config, &ptr_section, &ptr_option, &pos_option); - + if (ptr_config && ptr_section) { if (ptr_option) @@ -1623,7 +1623,7 @@ config_file_option_set_with_string (const char *option_name, const char *value) } } } - + return rc; } @@ -1636,7 +1636,7 @@ config_file_option_boolean (struct t_config_option *option) { if (!option) return 0; - + if (option->type == CONFIG_OPTION_TYPE_BOOLEAN) return CONFIG_BOOLEAN(option); else @@ -1652,7 +1652,7 @@ config_file_option_boolean_default (struct t_config_option *option) { if (!option) return 0; - + if (option->type == CONFIG_OPTION_TYPE_BOOLEAN) return CONFIG_BOOLEAN_DEFAULT(option); else @@ -1668,7 +1668,7 @@ config_file_option_integer (struct t_config_option *option) { if (!option) return 0; - + switch (option->type) { case CONFIG_OPTION_TYPE_BOOLEAN: @@ -1696,7 +1696,7 @@ config_file_option_integer_default (struct t_config_option *option) { if (!option) return 0; - + switch (option->type) { case CONFIG_OPTION_TYPE_BOOLEAN: @@ -1724,7 +1724,7 @@ config_file_option_string (struct t_config_option *option) { if (!option) return NULL; - + switch (option->type) { case CONFIG_OPTION_TYPE_BOOLEAN: @@ -1755,7 +1755,7 @@ config_file_option_string_default (struct t_config_option *option) { if (!option) return NULL; - + switch (option->type) { case CONFIG_OPTION_TYPE_BOOLEAN: @@ -1813,12 +1813,12 @@ config_file_write_option (struct t_config_file *config_file, struct t_config_option *option) { int rc; - + if (!config_file || !config_file->file || !option) return 0; - + rc = 1; - + if (option->value) { switch (option->type) @@ -1858,7 +1858,7 @@ config_file_write_option (struct t_config_file *config_file, rc = string_iconv_fprintf (config_file->file, "%s\n", option->name); } - + return rc; } @@ -1873,10 +1873,10 @@ config_file_write_line (struct t_config_file *config_file, const char *option_name, const char *value, ...) { int rc; - + if (!config_file || !option_name) return 0; - + if (value && value[0]) { weechat_va_format (value); @@ -1892,7 +1892,7 @@ config_file_write_line (struct t_config_file *config_file, free (vbuffer); } } - + return (string_iconv_fprintf (config_file->file, "\n[%s]\n", option_name)); } @@ -1914,7 +1914,7 @@ config_file_write_internal (struct t_config_file *config_file, char *filename, *filename2; struct t_config_section *ptr_section; struct t_config_option *ptr_option; - + if (!config_file) return WEECHAT_CONFIG_WRITE_ERROR; @@ -1926,7 +1926,7 @@ config_file_write_internal (struct t_config_file *config_file, return WEECHAT_CONFIG_WRITE_MEMORY_ERROR; snprintf (filename, filename_length, "%s%s%s", weechat_home, DIR_SEPARATOR, config_file->filename); - + /* * build temporary filename, this temp file will be renamed to filename * after write @@ -1938,11 +1938,11 @@ config_file_write_internal (struct t_config_file *config_file, return WEECHAT_CONFIG_WRITE_MEMORY_ERROR; } snprintf (filename2, filename_length + 32, "%s.weechattmp", filename); - + log_printf (_("Writing configuration file %s %s"), config_file->filename, (default_options) ? _("(default options)") : ""); - + /* open temp file in write mode */ config_file->file = fopen (filename2, "wb"); if (!config_file->file) @@ -1953,7 +1953,7 @@ config_file_write_internal (struct t_config_file *config_file, filename2); goto error; } - + /* write header with name of config file and WeeChat version */ if (!string_iconv_fprintf (config_file->file, "#\n")) goto error; @@ -1961,7 +1961,7 @@ config_file_write_internal (struct t_config_file *config_file, "# %s -- %s v%s\n#\n", config_file->filename, PACKAGE_NAME, PACKAGE_VERSION)) goto error; - + /* write all sections */ for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) @@ -1995,31 +1995,31 @@ config_file_write_internal (struct t_config_file *config_file, } } } - + if (fflush (config_file->file) != 0) goto error; - + /* close temp file */ fclose (config_file->file); config_file->file = NULL; - + /* update file mode */ chmod (filename2, 0600); - + /* remove target file */ unlink (filename); - + /* rename temp file to target file */ rc = rename (filename2, filename); - + free (filename); free (filename2); - + if (rc != 0) return WEECHAT_CONFIG_WRITE_ERROR; - + return WEECHAT_CONFIG_WRITE_OK; - + error: gui_chat_printf (NULL, _("%sError writing configuration file \"%s\""), @@ -2069,10 +2069,10 @@ config_file_read_internal (struct t_config_file *config_file, int reload) struct t_config_section *ptr_section; struct t_config_option *ptr_option; char line[1024], *ptr_line, *ptr_line2, *pos, *pos2; - + if (!config_file) return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; - + /* build filename */ filename_length = strlen (weechat_home) + strlen (config_file->filename) + 2; filename = malloc (filename_length); @@ -2095,10 +2095,10 @@ config_file_read_internal (struct t_config_file *config_file, int reload) return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; } } - + if (!reload) log_printf (_("Reading configuration file %s"), config_file->filename); - + /* read all lines */ ptr_section = NULL; line_number = 0; @@ -2115,7 +2115,7 @@ config_file_read_internal (struct t_config_file *config_file, int reload) snprintf (line, sizeof (line) - 1, "%s", ptr_line2); free (ptr_line2); } - + /* skip spaces */ while (ptr_line[0] == ' ') ptr_line++; @@ -2155,7 +2155,7 @@ config_file_read_internal (struct t_config_file *config_file, int reload) else { undefined_value = 1; - + /* remove CR/LF */ pos = strchr (line, '\r'); if (pos != NULL) @@ -2163,13 +2163,13 @@ config_file_read_internal (struct t_config_file *config_file, int reload) pos = strchr (line, '\n'); if (pos != NULL) pos[0] = '\0'; - + pos = strstr (line, " ="); if (pos) { pos[0] = '\0'; pos += 2; - + /* remove spaces before '=' */ pos2 = pos - 3; while ((pos2 > line) && (pos2[0] == ' ')) @@ -2177,13 +2177,13 @@ config_file_read_internal (struct t_config_file *config_file, int reload) pos2[0] = '\0'; pos2--; } - + /* skip spaces after '=' */ while (pos[0] && (pos[0] == ' ')) { pos++; } - + if (pos[0] && string_strcasecmp (pos, WEECHAT_CONFIG_OPTION_NULL) != 0) { @@ -2209,7 +2209,7 @@ config_file_read_internal (struct t_config_file *config_file, int reload) } } } - + if (ptr_section && ptr_section->callback_read) { ptr_option = NULL; @@ -2248,7 +2248,7 @@ config_file_read_internal (struct t_config_file *config_file, int reload) } } } - + switch (rc) { case WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND: @@ -2283,11 +2283,11 @@ config_file_read_internal (struct t_config_file *config_file, int reload) } } } - + fclose (config_file->file); config_file->file = NULL; free (filename); - + return WEECHAT_CONFIG_READ_OK; } @@ -2319,12 +2319,12 @@ config_file_reload (struct t_config_file *config_file) struct t_config_section *ptr_section; struct t_config_option *ptr_option; int rc; - + if (!config_file) return WEECHAT_CONFIG_READ_FILE_NOT_FOUND; - + log_printf (_("Reloading configuration file %s"), config_file->filename); - + /* init "loaded" flag for all options */ for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) @@ -2338,10 +2338,10 @@ config_file_reload (struct t_config_file *config_file) } } } - + /* read configuration file */ rc = config_file_read_internal (config_file, 1); - + /* reset options not found in configuration file */ for (ptr_section = config_file->sections; ptr_section; ptr_section = ptr_section->next_section) @@ -2356,7 +2356,7 @@ config_file_reload (struct t_config_file *config_file) } } } - + return rc; } @@ -2388,12 +2388,12 @@ config_file_option_free (struct t_config_option *option) { struct t_config_section *ptr_section; struct t_config_option *new_options; - + if (!option) return; - + ptr_section = option->section; - + /* remove option from section */ if (ptr_section) { @@ -2410,10 +2410,10 @@ config_file_option_free (struct t_config_option *option) (option->next_option)->prev_option = option->prev_option; ptr_section->options = new_options; } - + /* free data */ config_file_option_free_data (option); - + free (option); } @@ -2426,7 +2426,7 @@ config_file_section_free_options (struct t_config_section *section) { if (!section) return; - + while (section->options) { config_file_option_free (section->options); @@ -2442,12 +2442,12 @@ config_file_section_free (struct t_config_section *section) { struct t_config_file *ptr_config; struct t_config_section *new_sections; - + if (!section) return; - + ptr_config = section->config_file; - + /* remove section */ if (ptr_config->last_section == section) ptr_config->last_section = section->prev_section; @@ -2458,17 +2458,17 @@ config_file_section_free (struct t_config_section *section) } else new_sections = section->next_section; - + if (section->next_section) (section->next_section)->prev_section = section->prev_section; - + /* free data */ config_file_section_free_options (section); if (section->name) free (section->name); - + free (section); - + ptr_config->sections = new_sections; } @@ -2480,10 +2480,10 @@ void config_file_free (struct t_config_file *config_file) { struct t_config_file *new_config_files; - + if (!config_file) return; - + /* remove configuration file */ if (last_config_file == config_file) last_config_file = config_file->prev_config; @@ -2494,10 +2494,10 @@ config_file_free (struct t_config_file *config_file) } else new_config_files = config_file->next_config; - + if (config_file->next_config) (config_file->next_config)->prev_config = config_file->prev_config; - + /* free data */ while (config_file->sections) { @@ -2507,9 +2507,9 @@ config_file_free (struct t_config_file *config_file) free (config_file->name); if (config_file->filename) free (config_file->filename); - + free (config_file); - + config_files = new_config_files; } @@ -2534,15 +2534,15 @@ void config_file_free_all_plugin (struct t_weechat_plugin *plugin) { struct t_config_file *ptr_config, *next_config; - + ptr_config = config_files; while (ptr_config) { next_config = ptr_config->next_config; - + if (ptr_config->plugin == plugin) config_file_free (ptr_config); - + ptr_config = next_config; } } @@ -2555,10 +2555,10 @@ struct t_hdata * config_file_hdata_config_file_cb (void *data, const char *hdata_name) { struct t_hdata *hdata; - + /* make C compiler happy */ (void) data; - + hdata = hdata_new (NULL, hdata_name, "prev_config", "next_config"); if (hdata) { @@ -2586,10 +2586,10 @@ struct t_hdata * config_file_hdata_config_section_cb (void *data, const char *hdata_name) { struct t_hdata *hdata; - + /* make C compiler happy */ (void) data; - + hdata = hdata_new (NULL, hdata_name, "prev_section", "next_section"); if (hdata) { @@ -2623,10 +2623,10 @@ struct t_hdata * config_file_hdata_config_option_cb (void *data, const char *hdata_name) { struct t_hdata *hdata; - + /* make C compiler happy */ (void) data; - + hdata = hdata_new (NULL, hdata_name, "prev_option", "next_option"); if (hdata) { @@ -2669,10 +2669,10 @@ config_file_add_to_infolist (struct t_infolist *infolist, struct t_infolist_item *ptr_item; int length; char *option_full_name, value[128], *string_values; - + if (!infolist) return 0; - + for (ptr_config = config_files; ptr_config; ptr_config = ptr_config->next_config) { @@ -2960,7 +2960,7 @@ config_file_add_to_infolist (struct t_infolist *infolist, } } } - + return 1; } @@ -2974,7 +2974,7 @@ config_file_print_log () struct t_config_file *ptr_config_file; struct t_config_section *ptr_section; struct t_config_option *ptr_option; - + for (ptr_config_file = config_files; ptr_config_file; ptr_config_file = ptr_config_file->next_config) { @@ -2992,7 +2992,7 @@ config_file_print_log () log_printf (" last_section . . . . . : 0x%lx", ptr_config_file->last_section); log_printf (" prev_config. . . . . . : 0x%lx", ptr_config_file->prev_config); log_printf (" next_config. . . . . . : 0x%lx", ptr_config_file->next_config); - + for (ptr_section = ptr_config_file->sections; ptr_section; ptr_section = ptr_section->next_section) { @@ -3014,7 +3014,7 @@ config_file_print_log () log_printf (" last_option. . . . . . . . : 0x%lx", ptr_section->last_option); log_printf (" prev_section . . . . . . . : 0x%lx", ptr_section->prev_section); log_printf (" next_section . . . . . . . : 0x%lx", ptr_section->next_section); - + for (ptr_option = ptr_section->options; ptr_option; ptr_option = ptr_option->next_option) { diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 42a65a044..147ee728d 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -252,7 +252,7 @@ config_change_save_config_on_exit (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + if (!CONFIG_BOOLEAN(config_look_save_config_on_exit)) { gui_chat_printf (NULL, @@ -272,7 +272,7 @@ config_change_title (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + if (CONFIG_BOOLEAN(config_look_set_title)) gui_window_set_title (PACKAGE_NAME " " PACKAGE_VERSION); } @@ -287,7 +287,7 @@ config_change_buffers (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + gui_window_ask_refresh (1); } @@ -301,7 +301,7 @@ config_change_buffer_content (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + if (gui_ok) gui_current_window->refresh_needed = 1; } @@ -316,7 +316,7 @@ config_change_buffer_notify_default (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + gui_buffer_notify_set_all (); } @@ -330,7 +330,7 @@ config_change_buffer_time_format (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + gui_chat_time_length = gui_chat_get_time_length (); gui_chat_change_time_format (); if (gui_ok) @@ -347,7 +347,7 @@ config_change_eat_newline_glitch (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + if (gui_ok) { if (CONFIG_BOOLEAN(config_look_eat_newline_glitch)) @@ -367,14 +367,14 @@ config_change_highlight_regex (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + if (config_highlight_regex) { regfree (config_highlight_regex); free (config_highlight_regex); config_highlight_regex = NULL; } - + if (CONFIG_STRING(config_look_highlight_regex) && CONFIG_STRING(config_look_highlight_regex)[0]) { @@ -402,14 +402,14 @@ config_change_highlight_tags (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + if (config_highlight_tags) { string_free_split (config_highlight_tags); config_highlight_tags = NULL; } config_num_highlight_tags = 0; - + if (CONFIG_STRING(config_look_highlight_tags) && CONFIG_STRING(config_look_highlight_tags)[0]) { @@ -428,7 +428,7 @@ config_change_hotlist (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + gui_hotlist_resort (); } @@ -442,7 +442,7 @@ config_change_read_marker (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + gui_window_ask_refresh (1); } @@ -456,7 +456,7 @@ config_change_prefix (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + gui_chat_prefix_build (); } @@ -468,11 +468,11 @@ void config_change_prefix_align_min (void *data, struct t_config_option *option) { struct t_gui_buffer *ptr_buffer; - + /* make C compiler happy */ (void) data; (void) option; - + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { @@ -494,7 +494,7 @@ config_change_color (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + if (gui_ok) { gui_color_init_weechat (); @@ -512,7 +512,7 @@ config_change_nick_colors (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + gui_color_buffer_display (); } @@ -527,7 +527,7 @@ config_change_network_gnutls_ca_file (void *data, /* make C compiler happy */ (void) data; (void) option; - + if (network_init_ok) network_set_gnutls_ca_file (); } @@ -546,15 +546,15 @@ config_day_change_timer_cb (void *data, int remaining_calls) int new_mday; char text_time[256], *text_time2; struct t_gui_buffer *ptr_buffer; - + /* make C compiler happy */ (void) data; (void) remaining_calls; - + gettimeofday (&tv_time, NULL); local_time = localtime (&tv_time.tv_sec); new_mday = local_time->tm_mday; - + if ((config_day_change_old_day >= 0) && (new_mday != config_day_change_old_day)) { @@ -580,14 +580,14 @@ config_day_change_timer_cb (void *data, int remaining_calls) free (text_time2); gui_add_hotlist = 1; } - + /* send signal "day_changed" */ strftime (text_time, sizeof (text_time), "%Y-%m-%d", local_time); hook_signal_send ("day_changed", WEECHAT_HOOK_SIGNAL_STRING, text_time); } - + config_day_change_old_day = new_mday; - + return WEECHAT_RC_OK; } @@ -600,11 +600,11 @@ void config_weechat_init_after_read () { int i; - + gui_buffer_notify_set_all (); - + proxy_use_temp_proxies (); - + gui_bar_use_temp_bars (); if (gui_bars) { @@ -619,7 +619,7 @@ config_weechat_init_after_read () /* no bar defined => create default bars */ gui_bar_create_default (); } - + /* if no key was found config file, then we use default bindings */ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++) { @@ -640,38 +640,38 @@ int config_weechat_reload_cb (void *data, struct t_config_file *config_file) { int i, rc; - + /* make C compiler happy */ (void) data; - + /* remove all keys */ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++) { gui_key_free_all (&gui_keys[i], &last_gui_key[i], &gui_keys_count[i]); } - + /* remove all proxies */ proxy_free_all (); - + /* remove all bars */ gui_bar_free_all (); - + /* remove layout */ gui_layout_buffer_reset (&gui_layout_buffers, &last_gui_layout_buffer); gui_layout_window_reset (&gui_layout_windows); - + /* remove all notify levels */ config_file_section_free_options (weechat_config_section_notify); - + /* remove all filters */ gui_filter_free_all (); - + rc = config_file_reload (config_file); - + if (rc == WEECHAT_CONFIG_READ_OK) config_weechat_init_after_read (); - + return rc; } @@ -697,11 +697,11 @@ config_weechat_debug_set_all () { struct t_config_option *ptr_option; struct t_weechat_plugin *ptr_plugin; - + /* set debug for core */ ptr_option = config_weechat_debug_get (PLUGIN_CORE); weechat_debug_core = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0; - + /* set debug for plugins */ for (ptr_plugin = weechat_plugins; ptr_plugin; ptr_plugin = ptr_plugin->next_plugin) @@ -722,7 +722,7 @@ config_weechat_debug_change_cb (void *data, /* make C compiler happy */ (void) data; (void) option; - + config_weechat_debug_set_all (); } @@ -739,12 +739,12 @@ config_weechat_debug_create_option_cb (void *data, { struct t_config_option *ptr_option; int rc; - + /* make C compiler happy */ (void) data; - + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; - + if (option_name) { ptr_option = config_file_search_option (config_file, section, @@ -777,10 +777,10 @@ config_weechat_debug_create_option_cb (void *data, rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } - + /* set debug level for "core" and all plugins */ config_weechat_debug_set_all (); - + return rc; } @@ -798,11 +798,11 @@ config_weechat_debug_delete_option_cb (void *data, (void) data; (void) config_file; (void) section; - + config_file_option_free (option); - + config_weechat_debug_set_all (); - + return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; } @@ -830,11 +830,11 @@ config_weechat_palette_change_cb (void *data, { char *error; int number; - + /* make C compiler happy */ (void) data; (void) option; - + error = NULL; number = (int)strtol (option->name, &error, 10); if (error && !error[0]) @@ -857,10 +857,10 @@ config_weechat_palette_create_option_cb (void *data, struct t_config_option *ptr_option; char *error; int rc, number; - + /* make C compiler happy */ (void) data; - + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; error = NULL; @@ -908,7 +908,7 @@ config_weechat_palette_create_option_cb (void *data, _("%sError: palette option must be numeric"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); } - + return rc; } @@ -924,19 +924,19 @@ config_weechat_palette_delete_option_cb (void *data, { char *error; int number; - + /* make C compiler happy */ (void) data; (void) config_file; (void) section; - + error = NULL; number = (int)strtol (option->name, &error, 10); if (error && !error[0]) gui_color_palette_remove (number); - + config_file_option_free (option); - + return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; } @@ -952,12 +952,12 @@ config_weechat_proxy_read_cb (void *data, struct t_config_file *config_file, char *pos_option, *proxy_name; struct t_proxy *ptr_temp_proxy; int index_option; - + /* make C compiler happy */ (void) data; (void) config_file; (void) section; - + if (option_name) { pos_option = strchr (option_name, '.'); @@ -982,7 +982,7 @@ config_weechat_proxy_read_cb (void *data, struct t_config_file *config_file, /* add new temp proxy at end of queue */ ptr_temp_proxy->prev_proxy = last_weechat_temp_proxy; ptr_temp_proxy->next_proxy = NULL; - + if (!weechat_temp_proxies) weechat_temp_proxies = ptr_temp_proxy; else @@ -990,7 +990,7 @@ config_weechat_proxy_read_cb (void *data, struct t_config_file *config_file, last_weechat_temp_proxy = ptr_temp_proxy; } } - + if (ptr_temp_proxy) { index_option = proxy_search_option (pos_option); @@ -1000,12 +1000,12 @@ config_weechat_proxy_read_cb (void *data, struct t_config_file *config_file, value); } } - + free (proxy_name); } } } - + return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } @@ -1021,12 +1021,12 @@ config_weechat_bar_read_cb (void *data, struct t_config_file *config_file, char *pos_option, *bar_name; struct t_gui_bar *ptr_temp_bar; int index_option; - + /* make C compiler happy */ (void) data; (void) config_file; (void) section; - + if (option_name) { pos_option = strchr (option_name, '.'); @@ -1051,7 +1051,7 @@ config_weechat_bar_read_cb (void *data, struct t_config_file *config_file, /* add new temp bar at end of queue */ ptr_temp_bar->prev_bar = last_gui_temp_bar; ptr_temp_bar->next_bar = NULL; - + if (!gui_temp_bars) gui_temp_bars = ptr_temp_bar; else @@ -1059,7 +1059,7 @@ config_weechat_bar_read_cb (void *data, struct t_config_file *config_file, last_gui_temp_bar = ptr_temp_bar; } } - + if (ptr_temp_bar) { index_option = gui_bar_search_option (pos_option); @@ -1069,12 +1069,12 @@ config_weechat_bar_read_cb (void *data, struct t_config_file *config_file, value); } } - + free (bar_name); } } } - + return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } @@ -1091,12 +1091,12 @@ config_weechat_layout_read_cb (void *data, struct t_config_file *config_file, char **argv, *error1, *error2, *error3, *error4; long number1, number2, number3, number4; struct t_gui_layout_window *parent; - + /* make C compiler happy */ (void) data; (void) config_file; (void) section; - + if (option_name && value && value[0]) { if (string_strcasecmp (option_name, "buffer") == 0) @@ -1153,7 +1153,7 @@ config_weechat_layout_read_cb (void *data, struct t_config_file *config_file, } } } - + return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } @@ -1176,21 +1176,21 @@ config_weechat_layout_write_tree (struct t_config_file *config_file, (layout_window->buffer_name) ? layout_window->buffer_name : "-")) return WEECHAT_CONFIG_WRITE_ERROR; - + if (layout_window->child1) { if (config_weechat_layout_write_tree (config_file, layout_window->child1) != WEECHAT_CONFIG_WRITE_OK) return WEECHAT_CONFIG_WRITE_ERROR; } - + if (layout_window->child2) { if (config_weechat_layout_write_tree (config_file, layout_window->child2) != WEECHAT_CONFIG_WRITE_OK) return WEECHAT_CONFIG_WRITE_ERROR; } - + return WEECHAT_CONFIG_WRITE_OK; } @@ -1203,13 +1203,13 @@ config_weechat_layout_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_gui_layout_buffer *ptr_layout_buffer; - + /* make C compiler happy */ (void) data; - + if (!config_file_write_line (config_file, section_name, NULL)) return WEECHAT_CONFIG_WRITE_ERROR; - + for (ptr_layout_buffer = gui_layout_buffers; ptr_layout_buffer; ptr_layout_buffer = ptr_layout_buffer->next_layout) { @@ -1219,14 +1219,14 @@ config_weechat_layout_write_cb (void *data, struct t_config_file *config_file, ptr_layout_buffer->number)) return WEECHAT_CONFIG_WRITE_ERROR; } - + if (gui_layout_windows) { if (config_weechat_layout_write_tree (config_file, gui_layout_windows) != WEECHAT_CONFIG_WRITE_OK) return WEECHAT_CONFIG_WRITE_ERROR; } - + return WEECHAT_CONFIG_WRITE_OK; } @@ -1240,7 +1240,7 @@ config_weechat_notify_change_cb (void *data, struct t_config_option *option) /* make C compiler happy */ (void) data; (void) option; - + gui_buffer_notify_set_all (); } @@ -1258,12 +1258,12 @@ config_weechat_notify_create_option_cb (void *data, { struct t_config_option *ptr_option; int rc; - + /* make C compiler happy */ (void) data; - + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; - + if (option_name) { ptr_option = config_file_search_option (config_file, section, @@ -1296,10 +1296,10 @@ config_weechat_notify_create_option_cb (void *data, rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } } - + if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) gui_buffer_notify_set_all (); - + return rc; } @@ -1318,11 +1318,11 @@ config_weechat_notify_delete_option_cb (void *data, (void) data; (void) config_file; (void) section; - + config_file_option_free (option); - + gui_buffer_notify_set_all (); - + return WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED; } @@ -1339,10 +1339,10 @@ config_weechat_notify_set (struct t_gui_buffer *buffer, const char *notify) const char *plugin_name; char *option_name; int i, value, length; - + if (!buffer || !notify) return 0; - + value = -1; for (i = 0; i < GUI_BUFFER_NUM_NOTIFY; i++) { @@ -1354,14 +1354,14 @@ config_weechat_notify_set (struct t_gui_buffer *buffer, const char *notify) } if ((value < 0) && (strcmp (notify, "reset") != 0)) return 0; - + plugin_name = gui_buffer_get_plugin_name (buffer); length = strlen (plugin_name) + 1 + strlen (buffer->name) + 1; option_name = malloc (length); if (option_name) { snprintf (option_name, length, "%s.%s", plugin_name, buffer->name); - + /* create/update option */ config_weechat_notify_create_option_cb (NULL, weechat_config_file, @@ -1371,7 +1371,7 @@ config_weechat_notify_set (struct t_gui_buffer *buffer, const char *notify) NULL : gui_buffer_notify_string[value]); return 1; } - + return 0; } @@ -1387,12 +1387,12 @@ config_weechat_filter_read_cb (void *data, { char **argv, **argv_eol; int argc; - + /* make C compiler happy */ (void) data; (void) config_file; (void) section; - + if (option_name && value && value[0]) { argv = string_split (value, ";", 0, 0, &argc); @@ -1407,7 +1407,7 @@ config_weechat_filter_read_cb (void *data, if (argv_eol) string_free_split (argv_eol); } - + return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } @@ -1420,13 +1420,13 @@ config_weechat_filter_write_cb (void *data, struct t_config_file *config_file, const char *section_name) { struct t_gui_filter *ptr_filter; - + /* make C compiler happy */ (void) data; - + if (!config_file_write_line (config_file, section_name, NULL)) return WEECHAT_CONFIG_WRITE_ERROR; - + for (ptr_filter = gui_filters; ptr_filter; ptr_filter = ptr_filter->next_filter) { @@ -1439,7 +1439,7 @@ config_weechat_filter_write_cb (void *data, struct t_config_file *config_file, ptr_filter->regex)) return WEECHAT_CONFIG_WRITE_ERROR; } - + return WEECHAT_CONFIG_WRITE_OK; } @@ -1454,11 +1454,11 @@ config_weechat_key_read_cb (void *data, struct t_config_file *config_file, { int context; char *pos; - + /* make C compiler happy */ (void) data; (void) config_file; - + if (option_name) { context = GUI_KEY_CONTEXT_DEFAULT; @@ -1469,7 +1469,7 @@ config_weechat_key_read_cb (void *data, struct t_config_file *config_file, if (context < 0) context = GUI_KEY_CONTEXT_DEFAULT; } - + if (value && value[0]) { /* bind key (overwrite any binding with same key) */ @@ -1481,7 +1481,7 @@ config_weechat_key_read_cb (void *data, struct t_config_file *config_file, gui_key_unbind (NULL, context, option_name); } } - + return WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; } @@ -1496,10 +1496,10 @@ config_weechat_key_write_cb (void *data, struct t_config_file *config_file, struct t_gui_key *ptr_key; char *pos, *expanded_name; int rc, context; - + /* make C compiler happy */ (void) data; - + if (!config_file_write_line (config_file, section_name, NULL)) return WEECHAT_CONFIG_WRITE_ERROR; @@ -1526,7 +1526,7 @@ config_weechat_key_write_cb (void *data, struct t_config_file *config_file, return WEECHAT_CONFIG_WRITE_ERROR; } } - + return WEECHAT_CONFIG_WRITE_OK; } @@ -1541,12 +1541,12 @@ config_weechat_init_options () struct t_config_section *ptr_section; int i; char section_name[128]; - + weechat_config_file = config_file_new (NULL, WEECHAT_CONFIG_NAME, &config_weechat_reload_cb, NULL); if (!weechat_config_file) return 0; - + /* debug */ ptr_section = config_file_new_section (weechat_config_file, "debug", 1, 1, @@ -1559,9 +1559,9 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + weechat_config_section_debug = ptr_section; - + /* startup */ ptr_section = config_file_new_section (weechat_config_file, "startup", 0, 0, @@ -1572,7 +1572,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + config_startup_command_after_plugins = config_file_new_option ( weechat_config_file, ptr_section, "command_after_plugins", "string", @@ -1593,7 +1593,7 @@ config_weechat_init_options () "display_version", "boolean", N_("display WeeChat version at startup"), NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); - + /* look */ ptr_section = config_file_new_section (weechat_config_file, "look", 0, 0, @@ -1604,7 +1604,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + config_look_align_end_of_lines = config_file_new_option ( weechat_config_file, ptr_section, "align_end_of_lines", "integer", @@ -2051,7 +2051,7 @@ config_weechat_init_options () N_("time format for dates converted to strings and displayed in " "messages"), NULL, 0, 0, "%a, %d %b %Y %T", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); - + /* palette */ ptr_section = config_file_new_section (weechat_config_file, "palette", 1, 1, @@ -2064,7 +2064,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + /* colors */ ptr_section = config_file_new_section (weechat_config_file, "color", 0, 0, @@ -2075,9 +2075,9 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + weechat_config_section_color = ptr_section; - + /* general color settings */ config_color_separator = config_file_new_option ( weechat_config_file, ptr_section, @@ -2414,7 +2414,7 @@ config_weechat_init_options () N_("text color for offline nicknames"), NULL, -1, 0, "blue", NULL, 0, NULL, NULL, &config_change_color, NULL, NULL, NULL); - + /* completion */ ptr_section = config_file_new_section (weechat_config_file, "completion", 0, 0, @@ -2425,7 +2425,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + config_completion_default_template = config_file_new_option ( weechat_config_file, ptr_section, "default_template", "string", @@ -2482,7 +2482,7 @@ config_weechat_init_options () "partial_completion_count", "boolean", N_("display count for each partial completion in bar item"), NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); - + /* history */ ptr_section = config_file_new_section (weechat_config_file, "history", 0, 0, @@ -2493,7 +2493,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + config_history_max_lines = config_file_new_option ( weechat_config_file, ptr_section, "max_lines", "integer", @@ -2517,7 +2517,7 @@ config_weechat_init_options () N_("maximum number of commands to display by default in " "history listing (0 = unlimited)"), NULL, 0, INT_MAX, "5", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); - + /* proxies */ ptr_section = config_file_new_section (weechat_config_file, "proxy", 0, 0, @@ -2529,7 +2529,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + weechat_config_section_proxy = ptr_section; /* network */ @@ -2542,7 +2542,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + config_network_gnutls_ca_file = config_file_new_option ( weechat_config_file, ptr_section, "gnutls_ca_file", "string", @@ -2555,7 +2555,7 @@ config_weechat_init_options () "gnutls_handshake_timeout", "integer", N_("timeout (in seconds) for gnutls handshake"), NULL, 1, INT_MAX, "30", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); - + /* plugin */ ptr_section = config_file_new_section (weechat_config_file, "plugin", 0, 0, @@ -2566,7 +2566,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + config_plugin_autoload = config_file_new_option ( weechat_config_file, ptr_section, "autoload", "string", @@ -2605,7 +2605,7 @@ config_weechat_init_options () "save_config_on_unload", "boolean", N_("save configuration files when unloading plugins"), NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); - + /* bars */ ptr_section = config_file_new_section (weechat_config_file, "bar", 0, 0, @@ -2617,9 +2617,9 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + weechat_config_section_bar = ptr_section; - + /* layout */ ptr_section = config_file_new_section (weechat_config_file, "layout", 0, 0, @@ -2631,7 +2631,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + /* notify */ ptr_section = config_file_new_section (weechat_config_file, "notify", 1, 1, @@ -2645,9 +2645,9 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + weechat_config_section_notify = ptr_section; - + /* filters */ ptr_section = config_file_new_section (weechat_config_file, "filter", 0, 0, @@ -2660,7 +2660,7 @@ config_weechat_init_options () config_file_free (weechat_config_file); return 0; } - + /* keys */ for (i = 0; i < GUI_KEY_NUM_CONTEXTS; i++) { @@ -2680,7 +2680,7 @@ config_weechat_init_options () return 0; } } - + return 1; } @@ -2695,15 +2695,15 @@ config_weechat_init () int rc; struct timeval tv_time; struct tm *local_time; - + rc = config_weechat_init_options (); - + if (!rc) { gui_chat_printf (NULL, _("FATAL: error initializing configuration options")); } - + if (!config_day_change_timer) { /* create timer to check if day has changed */ @@ -2721,7 +2721,7 @@ config_weechat_init () config_change_highlight_regex (NULL, NULL); if (!config_highlight_tags) config_change_highlight_tags (NULL, NULL); - + return rc; } @@ -2737,18 +2737,18 @@ int config_weechat_read () { int rc; - + rc = config_file_read (weechat_config_file); if (rc == WEECHAT_CONFIG_READ_OK) config_weechat_init_after_read (); - + if (rc != WEECHAT_CONFIG_READ_OK) { gui_chat_printf (NULL, _("%sError reading configuration"), gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]); } - + return rc; } diff --git a/src/core/wee-debug.c b/src/core/wee-debug.c index 14eabec89..6cdacb0f6 100644 --- a/src/core/wee-debug.c +++ b/src/core/wee-debug.c @@ -69,14 +69,14 @@ debug_dump (int crash) /* prevent reentrance */ if (debug_dump_active) exit (EXIT_FAILURE); - + if (crash) { debug_dump_active = 1; log_printf ("Very bad, WeeChat is crashing (SIGSEGV received)..."); weechat_log_use_time = 0; } - + log_printf (""); if (crash) { @@ -97,19 +97,19 @@ debug_dump (int crash) gui_bar_print_log (); gui_bar_item_print_log (); gui_hotlist_print_log (); - + hdata_print_log (); - + infolist_print_log (); - + hook_print_log (); - + config_file_print_log (); - + proxy_print_log (); - + plugin_print_log (); - + log_printf (""); log_printf ("****** End of WeeChat dump ******"); log_printf (""); @@ -127,10 +127,10 @@ debug_dump_cb (void *data, const char *signal, const char *type_data, (void) data; (void) signal; (void) type_data; - + if (!signal_data || (string_strcasecmp ((char *)signal_data, "core") == 0)) debug_dump (0); - + return WEECHAT_RC_OK; } @@ -145,7 +145,7 @@ debug_sigsegv () debug_dump (1); unhook_all (); gui_main_end (0); - + string_iconv_fprintf (stderr, "\n"); string_iconv_fprintf (stderr, "*** Very bad! WeeChat is crashing (SIGSEGV received)\n"); if (!log_crash_rename ()) @@ -160,9 +160,9 @@ debug_sigsegv () string_iconv_fprintf (stderr, "*** 2. Otherwise send backtrace (below) and weechat.log\n"); string_iconv_fprintf (stderr, "*** (be careful, private info may be in this file since\n"); string_iconv_fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n"); - + weechat_backtrace (); - + /* shutdown with error code */ weechat_shutdown (EXIT_FAILURE, 1); } @@ -179,9 +179,9 @@ debug_buffer_cb (void *data, const char *signal, const char *type_data, (void) data; (void) signal; (void) type_data; - + gui_buffer_dump_hexa ((struct t_gui_buffer *)signal_data); - + return WEECHAT_RC_OK; } @@ -193,7 +193,7 @@ void debug_windows_tree_display (struct t_gui_window_tree *tree, int indent) { char format[128]; - + if (tree) { if (tree->window) @@ -229,7 +229,7 @@ debug_windows_tree_display (struct t_gui_window_tree *tree, int indent) tree->split_horizontal, tree->child1, tree->child2); } - + if (tree->child1) debug_windows_tree_display (tree->child1, indent + 1); if (tree->child2) @@ -262,9 +262,9 @@ debug_windows_cb (void *data, const char *signal, const char *type_data, (void) signal; (void) type_data; (void) signal_data; - + debug_windows_tree (); - + return WEECHAT_RC_OK; } @@ -277,9 +277,9 @@ debug_memory () { #ifdef HAVE_MALLINFO struct mallinfo info; - + info = mallinfo (); - + gui_chat_printf (NULL, ""); gui_chat_printf (NULL, _("Memory usage (see \"man mallinfo\" for help):")); gui_chat_printf (NULL, " arena :%10d", info.arena); @@ -310,12 +310,12 @@ debug_hdata_hash_var_map_cb (void *data, { struct t_weelist *list; char str_offset[16]; - + /* make C compiler happy */ (void) hashtable; - + list = (struct t_weelist *)data; - + snprintf (str_offset, sizeof (str_offset), "%12d", (*((int *)value)) & 0xFFFF); weelist_add (list, str_offset, WEECHAT_LIST_POS_SORT, (void *)key); @@ -333,7 +333,7 @@ debug_hdata_hash_list_map_cb (void *data, /* make C compiler happy */ (void) data; (void) hashtable; - + gui_chat_printf (NULL, " list: %s -> 0x%lx", (char *)key, @@ -352,13 +352,13 @@ debug_hdata_map_cb (void *data, struct t_hashtable *hashtable, struct t_weelist *list; struct t_weelist_item *ptr_item; void *ptr_value; - + /* make C compiler happy */ (void) data; (void) hashtable; - + ptr_hdata = (struct t_hdata *)value; - + gui_chat_printf (NULL, " hdata 0x%lx: \"%s\", %d vars, %d lists:", ptr_hdata, (const char *)key, @@ -366,11 +366,11 @@ debug_hdata_map_cb (void *data, struct t_hashtable *hashtable, "items_count"), hashtable_get_integer (ptr_hdata->hash_list, "items_count")); - + /* display lists */ hashtable_map (ptr_hdata->hash_list, &debug_hdata_hash_list_map_cb, NULL); - + /* display vars */ list = weelist_new (); hashtable_map (ptr_hdata->hash_var, @@ -399,12 +399,12 @@ void debug_hdata () { int count; - + count = hashtable_get_integer (weechat_hdata, "items_count"); - + gui_chat_printf (NULL, ""); gui_chat_printf (NULL, "%d hdata in memory", count); - + if (count > 0) hashtable_map (weechat_hdata, &debug_hdata_map_cb, NULL); } @@ -421,21 +421,21 @@ debug_infolists () struct t_infolist_var *ptr_var; int i, count, count_items, count_vars, size_structs, size_data; int total_items, total_vars, total_size; - + count = 0; for (ptr_infolist = weechat_infolists; ptr_infolist; ptr_infolist = ptr_infolist->next_infolist) { count++; } - + gui_chat_printf (NULL, ""); gui_chat_printf (NULL, "%d infolists in memory (%s)", count, (count == 0) ? "this is ok!" : "WARNING: this is probably a memory leak in WeeChat or " "plugins/scripts!"); - + if (count > 0) { i = 0; diff --git a/src/core/wee-hashtable.c b/src/core/wee-hashtable.c index 41349a1bd..90eaa8a43 100644 --- a/src/core/wee-hashtable.c +++ b/src/core/wee-hashtable.c @@ -52,16 +52,16 @@ int hashtable_get_type (const char *type) { int i; - + if (!type) return -1; - + for (i = 0; i < HASHTABLE_NUM_TYPES; i++) { if (string_strcasecmp (hashtable_type_string[i], type) == 0) return i; } - + /* type not found */ return -1; } @@ -75,7 +75,7 @@ hashtable_hash_key_string_cb (struct t_hashtable *hashtable, const void *key) { const char *ptr_key; unsigned long hash; - + /* variant of djb2 hash */ hash = 5381; for (ptr_key = (const char *)key; ptr_key[0]; ptr_key++) @@ -95,7 +95,7 @@ hashtable_keycmp_string_cb (struct t_hashtable *hashtable, { /* make C compiler happy */ (void) hashtable; - + return strcmp ((const char *)key1, (const char *)key2); } @@ -111,17 +111,17 @@ hashtable_new (int size, { struct t_hashtable *new_hashtable; int i, type_keys_int, type_values_int; - + type_keys_int = hashtable_get_type (type_keys); if (type_keys_int < 0) return NULL; type_values_int = hashtable_get_type (type_values); if (type_values_int < 0) return NULL; - + if ((type_keys_int != HASHTABLE_STRING) && (!callback_hash_key || !callback_keycmp)) return NULL; - + new_hashtable = malloc (sizeof (*new_hashtable)); if (new_hashtable) { @@ -140,17 +140,17 @@ hashtable_new (int size, new_hashtable->htable[i] = NULL; } new_hashtable->items_count = 0; - + if ((type_keys_int == HASHTABLE_STRING) && !callback_hash_key) new_hashtable->callback_hash_key = &hashtable_hash_key_string_cb; else new_hashtable->callback_hash_key = callback_hash_key; - + if ((type_keys_int == HASHTABLE_STRING) && !callback_keycmp) new_hashtable->callback_keycmp = &hashtable_keycmp_string_cb; else new_hashtable->callback_keycmp = callback_keycmp; - + new_hashtable->callback_free_value = NULL; } return new_hashtable; @@ -281,14 +281,14 @@ hashtable_set_with_size (struct t_hashtable *hashtable, { unsigned int hash; struct t_hashtable_item *ptr_item, *pos_item, *new_item; - + if (!hashtable || !key || ((hashtable->type_keys == HASHTABLE_BUFFER) && (key_size <= 0)) || ((hashtable->type_values == HASHTABLE_BUFFER) && (value_size <= 0))) { return 0; } - + /* search position for item in hash table */ hash = hashtable->callback_hash_key (hashtable, key); pos_item = NULL; @@ -299,7 +299,7 @@ hashtable_set_with_size (struct t_hashtable *hashtable, { pos_item = ptr_item; } - + /* replace value if item is already in hash table */ if (ptr_item && (hashtable->callback_keycmp (hashtable, key, ptr_item->key) == 0)) { @@ -309,12 +309,12 @@ hashtable_set_with_size (struct t_hashtable *hashtable, &ptr_item->value, &ptr_item->value_size); return 1; } - + /* create new item */ new_item = malloc (sizeof (*new_item)); if (!new_item) return 0; - + /* set key and value */ hashtable_alloc_type (hashtable->type_keys, key, key_size, @@ -322,7 +322,7 @@ hashtable_set_with_size (struct t_hashtable *hashtable, hashtable_alloc_type (hashtable->type_values, value, value_size, &new_item->value, &new_item->value_size); - + /* add item */ if (pos_item) { @@ -342,9 +342,9 @@ hashtable_set_with_size (struct t_hashtable *hashtable, (hashtable->htable[hash])->prev_item = new_item; hashtable->htable[hash] = new_item; } - + hashtable->items_count++; - + return 1; } @@ -374,10 +374,10 @@ hashtable_get_item (struct t_hashtable *hashtable, const void *key, { unsigned int key_hash; struct t_hashtable_item *ptr_item; - + if (!hashtable) return NULL; - + key_hash = hashtable->callback_hash_key (hashtable, key); if (hash) *hash = key_hash; @@ -386,13 +386,13 @@ hashtable_get_item (struct t_hashtable *hashtable, const void *key, ptr_item = ptr_item->next_item) { } - + if (ptr_item && (hashtable->callback_keycmp (hashtable, key, ptr_item->key) == 0)) { return ptr_item; } - + return NULL; } @@ -406,9 +406,9 @@ void * hashtable_get (struct t_hashtable *hashtable, const void *key) { struct t_hashtable_item *ptr_item; - + ptr_item = hashtable_get_item (hashtable, key, NULL); - + return (ptr_item) ? ptr_item->value : NULL; } @@ -433,22 +433,22 @@ hashtable_map (struct t_hashtable *hashtable, { int i; struct t_hashtable_item *ptr_item, *ptr_next_item; - + if (!hashtable) return; - + for (i = 0; i < hashtable->size; i++) { ptr_item = hashtable->htable[i]; while (ptr_item) { ptr_next_item = ptr_item->next_item; - + (void) (callback_map) (callback_map_data, hashtable, ptr_item->key, ptr_item->value); - + ptr_item = ptr_next_item; } } @@ -465,10 +465,10 @@ hashtable_duplicate_map_cb (void *data, const void *key, const void *value) { struct t_hashtable *hashtable2; - + /* make C compiler happy */ (void) hashtable; - + hashtable2 = (struct t_hashtable *)data; if (hashtable2) hashtable_set (hashtable2, key, value); @@ -482,7 +482,7 @@ struct t_hashtable * hashtable_dup (struct t_hashtable *hashtable) { struct t_hashtable *new_hashtable; - + new_hashtable = hashtable_new (hashtable->size, hashtable_type_string[hashtable->type_keys], hashtable_type_string[hashtable->type_values], @@ -495,7 +495,7 @@ hashtable_dup (struct t_hashtable *hashtable) &hashtable_duplicate_map_cb, new_hashtable); } - + return new_hashtable; } @@ -511,13 +511,13 @@ hashtable_get_list_keys_map_cb (void *data, { struct t_weelist *list; char str_key[128]; - + /* make C compiler happy */ (void) hashtable; (void) value; - + list = (struct t_weelist *)data; - + switch (hashtable->type_keys) { case HASHTABLE_INTEGER: @@ -550,7 +550,7 @@ struct t_weelist * hashtable_get_list_keys (struct t_hashtable *hashtable) { struct t_weelist *weelist; - + weelist = weelist_new (); if (weelist) hashtable_map (hashtable, &hashtable_get_list_keys_map_cb, weelist); @@ -571,7 +571,7 @@ hashtable_get_integer (struct t_hashtable *hashtable, const char *property) else if (string_strcasecmp (property, "items_count") == 0) return hashtable->items_count; } - + return 0; } @@ -586,12 +586,12 @@ hashtable_compute_length_keys_cb (void *data, { char str_value[128]; int *length; - + /* make C compiler happy */ (void) value; - + length = (int *)data; - + switch (hashtable->type_keys) { case HASHTABLE_INTEGER: @@ -626,10 +626,10 @@ hashtable_compute_length_values_cb (void *data, { char str_value[128]; int *length; - + /* make C compiler happy */ (void) key; - + length = (int *)data; if (value) @@ -686,15 +686,15 @@ hashtable_build_string_keys_cb (void *data, { char str_value[128]; char *str; - + /* make C compiler happy */ (void) value; - + str = (char *)data; - + if (str[0]) strcat (str, ","); - + switch (hashtable->type_keys) { case HASHTABLE_INTEGER: @@ -729,12 +729,12 @@ hashtable_build_string_values_cb (void *data, { char str_value[128]; char *str; - + /* make C compiler happy */ (void) key; - + str = (char *)data; - + if (str[0]) strcat (str, ","); @@ -779,12 +779,12 @@ hashtable_build_string_keys_values_cb (void *data, { char str_value[128]; char *str; - + str = (char *)data; - + if (str[0]) strcat (str, ","); - + switch (hashtable->type_keys) { case HASHTABLE_INTEGER: @@ -806,7 +806,7 @@ hashtable_build_string_keys_values_cb (void *data, case HASHTABLE_NUM_TYPES: break; } - + strcat (str, ":"); if (value) @@ -854,13 +854,13 @@ hashtable_get_keys_values (struct t_hashtable *hashtable, int length; struct t_weelist *list_keys; struct t_weelist_item *ptr_item; - + if (hashtable->keys_values) { free (hashtable->keys_values); hashtable->keys_values = NULL; } - + /* first compute length of string */ length = 0; hashtable_map (hashtable, @@ -870,7 +870,7 @@ hashtable_get_keys_values (struct t_hashtable *hashtable, &length); if (length == 0) return hashtable->keys_values; - + /* build string */ hashtable->keys_values = malloc (length + 1); if (!hashtable->keys_values) @@ -911,7 +911,7 @@ hashtable_get_keys_values (struct t_hashtable *hashtable, &hashtable_build_string_values_cb), hashtable->keys_values); } - + return hashtable->keys_values; } @@ -939,7 +939,7 @@ hashtable_get_string (struct t_hashtable *hashtable, const char *property) else if (string_strcasecmp (property, "keys_values_sorted") == 0) return hashtable_get_keys_values (hashtable, 1, 1, 1); } - + return NULL; } @@ -971,11 +971,11 @@ hashtable_add_to_infolist (struct t_hashtable *hashtable, int i, item_number; struct t_hashtable_item *ptr_item; char option_name[128]; - + if (!hashtable || (hashtable->type_keys != HASHTABLE_STRING) || !infolist_item || !prefix) return 0; - + item_number = 0; for (i = 0; i < hashtable->size; i++) { @@ -1037,11 +1037,11 @@ hashtable_remove_item (struct t_hashtable *hashtable, { if (!hashtable || !item) return; - + /* free key and value */ hashtable_free_value (hashtable, item); hashtable_free_key (hashtable, item); - + /* remove item from list */ if (item->prev_item) (item->prev_item)->next_item = item->next_item; @@ -1049,9 +1049,9 @@ hashtable_remove_item (struct t_hashtable *hashtable, (item->next_item)->prev_item = item->prev_item; if (hashtable->htable[hash] == item) hashtable->htable[hash] = item->next_item; - + free (item); - + hashtable->items_count--; } @@ -1064,10 +1064,10 @@ hashtable_remove (struct t_hashtable *hashtable, const void *key) { struct t_hashtable_item *ptr_item; unsigned int hash; - + if (!hashtable || !key) return; - + ptr_item = hashtable_get_item (hashtable, key, &hash); if (ptr_item) hashtable_remove_item (hashtable, ptr_item, hash); @@ -1081,10 +1081,10 @@ void hashtable_remove_all (struct t_hashtable *hashtable) { int i; - + if (!hashtable) return; - + for (i = 0; i < hashtable->size; i++) { while (hashtable->htable[i]) @@ -1103,7 +1103,7 @@ hashtable_free (struct t_hashtable *hashtable) { if (!hashtable) return; - + hashtable_remove_all (hashtable); free (hashtable->htable); if (hashtable->keys_values) @@ -1120,7 +1120,7 @@ hashtable_print_log (struct t_hashtable *hashtable, const char *name) { struct t_hashtable_item *ptr_item; int i; - + log_printf (""); log_printf ("[hashtable %s (addr:0x%lx)]", name, hashtable); log_printf (" size . . . . . . . . . : %d", hashtable->size); @@ -1134,7 +1134,7 @@ hashtable_print_log (struct t_hashtable *hashtable, const char *name) hashtable_type_string[hashtable->type_values]); log_printf (" callback_hash_key. . . : 0x%lx", hashtable->callback_hash_key); log_printf (" callback_keycmp. . . . : 0x%lx", hashtable->callback_keycmp); - + for (i = 0; i < hashtable->size; i++) { log_printf (" htable[%06d] . . . . : 0x%lx", i, hashtable->htable[i]); diff --git a/src/core/wee-hashtable.h b/src/core/wee-hashtable.h index c4ac29a8b..4c8eecf2f 100644 --- a/src/core/wee-hashtable.h +++ b/src/core/wee-hashtable.h @@ -91,16 +91,16 @@ struct t_hashtable struct t_hashtable_item **htable; /* table to map hashes with linked */ /* lists */ int items_count; /* number of items in hashtable */ - + /* type for keys and values */ enum t_hashtable_type type_keys; /* type for keys: int/str/pointer */ enum t_hashtable_type type_values; /* type for values: int/str/pointer */ - + /* callbacks */ t_hashtable_hash_key *callback_hash_key; /* hash key to int value */ t_hashtable_keycmp *callback_keycmp; /* compare two keys */ t_hashtable_free_value *callback_free_value; /* callback to free value */ - + /* keys/values as string */ char *keys_values; /* keys/values as string (NULL if */ /* never asked) */ diff --git a/src/core/wee-hdata.c b/src/core/wee-hdata.c index 510c21ce6..b36d6f6b6 100644 --- a/src/core/wee-hdata.c +++ b/src/core/wee-hdata.c @@ -51,10 +51,10 @@ hdata_new (struct t_weechat_plugin *plugin, const char *hdata_name, const char *var_prev, const char *var_next) { struct t_hdata *new_hdata; - + if (!hdata_name || !hdata_name[0]) return NULL; - + new_hdata = malloc (sizeof (*new_hdata)); if (new_hdata) { @@ -78,7 +78,7 @@ hdata_new (struct t_weechat_plugin *plugin, const char *hdata_name, NULL); hashtable_set (weechat_hdata, hdata_name, new_hdata); } - + return new_hdata; } @@ -91,7 +91,7 @@ hdata_new_var (struct t_hdata *hdata, const char *name, int offset, int type, const char *hdata_name) { int value; - + if (hdata && name) { value = (type << 16) | (offset & 0xFFFF); @@ -120,14 +120,14 @@ int hdata_get_var_offset (struct t_hdata *hdata, const char *name) { int *ptr_value; - + if (hdata && name) { ptr_value = hashtable_get (hdata->hash_var, name); if (ptr_value) return (*ptr_value) & 0xFFFF; } - + return -1; } @@ -139,14 +139,14 @@ int hdata_get_var_type (struct t_hdata *hdata, const char *name) { int *ptr_value; - + if (hdata && name) { ptr_value = hashtable_get (hdata->hash_var, name); if (ptr_value) return (*ptr_value) >> 16; } - + return -1; } @@ -158,14 +158,14 @@ const char * hdata_get_var_type_string (struct t_hdata *hdata, const char *name) { int *ptr_value; - + if (hdata && name) { ptr_value = hashtable_get (hdata->hash_var, name); if (ptr_value) return hdata_type_string[(*ptr_value) >> 16]; } - + return NULL; } @@ -179,7 +179,7 @@ hdata_get_var_hdata (struct t_hdata *hdata, const char *name) { if (hdata && name) return (const char *)hashtable_get (hdata->hash_var_hdata, name); - + return NULL; } @@ -191,14 +191,14 @@ void * hdata_get_var (struct t_hdata *hdata, void *pointer, const char *name) { int offset; - + if (hdata && pointer) { offset = hdata_get_var_offset (hdata, name); if (offset >= 0) return pointer + offset; } - + return NULL; } @@ -212,7 +212,7 @@ hdata_get_var_at_offset (struct t_hdata *hdata, void *pointer, int offset) { if (hdata && pointer) return pointer + offset; - + return NULL; } @@ -224,14 +224,14 @@ void * hdata_get_list (struct t_hdata *hdata, const char *name) { void *ptr_value; - + if (hdata && name) { ptr_value = hashtable_get (hdata->hash_list, name); if (ptr_value) return *((void **)ptr_value); } - + return NULL; } @@ -244,12 +244,12 @@ hdata_move (struct t_hdata *hdata, void *pointer, int count) { char *ptr_var; int i, abs_count; - + if (hdata && pointer && (count != 0)) { ptr_var = (count < 0) ? hdata->var_prev : hdata->var_next; abs_count = abs(count); - + for (i = 0; i < abs_count; i++) { pointer = hdata_pointer (hdata, pointer, ptr_var); @@ -257,7 +257,7 @@ hdata_move (struct t_hdata *hdata, void *pointer, int count) return pointer; } } - + return NULL; } @@ -269,14 +269,14 @@ int hdata_integer (struct t_hdata *hdata, void *pointer, const char *name) { int offset; - + if (hdata && pointer) { offset = hdata_get_var_offset (hdata, name); if (offset >= 0) return *((int *)(pointer + offset)); } - + return 0; } @@ -288,14 +288,14 @@ long hdata_long (struct t_hdata *hdata, void *pointer, const char *name) { int offset; - + if (hdata && pointer) { offset = hdata_get_var_offset (hdata, name); if (offset >= 0) return *((long *)(pointer + offset)); } - + return 0; } @@ -307,14 +307,14 @@ const char * hdata_string (struct t_hdata *hdata, void *pointer, const char *name) { int offset; - + if (hdata && pointer) { offset = hdata_get_var_offset (hdata, name); if (offset >= 0) return *((char **)(pointer + offset)); } - + return NULL; } @@ -326,14 +326,14 @@ void * hdata_pointer (struct t_hdata *hdata, void *pointer, const char *name) { int offset; - + if (hdata && pointer) { offset = hdata_get_var_offset (hdata, name); if (offset >= 0) return *((void **)(pointer + offset)); } - + return NULL; } @@ -345,14 +345,14 @@ time_t hdata_time (struct t_hdata *hdata, void *pointer, const char *name) { int offset; - + if (hdata && pointer) { offset = hdata_get_var_offset (hdata, name); if (offset >= 0) return *((time_t *)(pointer + offset)); } - + return 0; } @@ -388,7 +388,7 @@ hdata_get_string (struct t_hdata *hdata, const char *property) else if (string_strcasecmp (property, "list_keys_values") == 0) return hashtable_get_string (hdata->hash_list, "keys_values"); } - + return NULL; } @@ -409,7 +409,7 @@ hdata_free (struct t_hdata *hdata) hashtable_free (hdata->hash_var_hdata); if (hdata->hash_list) hashtable_free (hdata->hash_list); - + free (hdata); } @@ -422,9 +422,9 @@ hdata_free_all_plugin_map_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { struct t_hdata *ptr_hdata; - + ptr_hdata = (struct t_hdata *)value; - + if (ptr_hdata->plugin == (struct t_weechat_plugin *)data) { hdata_free (ptr_hdata); @@ -451,12 +451,12 @@ hdata_free_all_map_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { struct t_hdata *ptr_hdata; - + /* make C compiler happy */ (void) data; - + ptr_hdata = (struct t_hdata *)value; - + hdata_free (ptr_hdata); hashtable_remove (hashtable, key); } @@ -480,13 +480,13 @@ hdata_print_log_map_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { struct t_hdata *ptr_hdata; - + /* make C compiler happy */ (void) data; (void) hashtable; - + ptr_hdata = (struct t_hdata *)value; - + log_printf (""); log_printf ("[hdata (addr:0x%lx, name:'%s')]", ptr_hdata, (const char *)key); log_printf (" plugin . . . . . . . . : 0x%lx", ptr_hdata->plugin); diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index a2e579d5e..36773f4af 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -82,7 +82,7 @@ void hook_init () { int type; - + for (type = 0; type < HOOK_NUM_TYPES; type++) { weechat_hooks[type] = NULL; @@ -99,16 +99,16 @@ int hook_search_type (const char *type) { int i; - + if (!type) return -1; - + for (i = 0; i < HOOK_NUM_TYPES; i++) { if (strcmp (hook_type_string[i], type) == 0) return i; } - + /* type not found */ return -1; } @@ -124,7 +124,7 @@ hook_find_pos (struct t_hook *hook) { struct t_hook *ptr_hook; int rc_cmp; - + if (hook->type == HOOK_TYPE_COMMAND) { /* for command hook, sort on command name */ @@ -152,7 +152,7 @@ hook_find_pos (struct t_hook *hook) return ptr_hook; } } - + /* position not found, add at the end */ return NULL; } @@ -207,9 +207,9 @@ hook_remove_from_list (struct t_hook *hook) { struct t_hook *new_hooks; int type; - + type = hook->type; - + if (last_weechat_hook[hook->type] == hook) last_weechat_hook[hook->type] = hook->prev_hook; if (hook->prev_hook) @@ -219,12 +219,12 @@ hook_remove_from_list (struct t_hook *hook) } else new_hooks = hook->next_hook; - + if (hook->next_hook) (hook->next_hook)->prev_hook = hook->prev_hook; - + free (hook); - + weechat_hooks[type] = new_hooks; } @@ -246,10 +246,10 @@ hook_remove_deleted () while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (ptr_hook->deleted) hook_remove_from_list (ptr_hook); - + ptr_hook = next_hook; } } @@ -273,12 +273,12 @@ hook_get_priority_and_name (const char *name, { char *pos, *str_priority, *error; long number; - + if (priority) *priority = HOOK_PRIORITY_DEFAULT; if (ptr_name) *ptr_name = name; - + pos = strchr (name, '|'); if (pos) { @@ -314,7 +314,7 @@ hook_init_data (struct t_hook *hook, struct t_weechat_plugin *plugin, hook->priority = priority; hook->callback_data = callback_data; hook->hook_data = NULL; - + if (weechat_debug_core >= 2) { gui_chat_printf (NULL, @@ -347,7 +347,7 @@ hook_valid (struct t_hook *hook) return 1; } } - + /* hook not found */ return 0; } @@ -371,7 +371,7 @@ hook_exec_end () { if (hook_exec_recursion > 0) hook_exec_recursion--; - + if (hook_exec_recursion == 0) hook_remove_deleted (); } @@ -384,7 +384,7 @@ struct t_hook * hook_search_command (struct t_weechat_plugin *plugin, const char *command) { struct t_hook *ptr_hook; - + for (ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND]; ptr_hook; ptr_hook = ptr_hook->next_hook) { @@ -393,7 +393,7 @@ hook_search_command (struct t_weechat_plugin *plugin, const char *command) && (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), command) == 0)) return ptr_hook; } - + /* command hook not found for plugin */ return NULL; } @@ -410,7 +410,7 @@ hook_command_build_completion (struct t_hook_command *hook_command) struct t_weelist *list; char *pos_completion, *pos_double_pipe, *pos_start, *pos_end; char **items, *last_space, *ptr_template; - + /* split templates using "||" as separator */ hook_command->cplt_num_templates = 1; pos_completion = hook_command->completion; @@ -458,7 +458,7 @@ hook_command_build_completion (struct t_hook_command *hook_command) else pos_completion = pos_double_pipe + 2; } - + /* for each template, split/count args */ hook_command->cplt_templates_static = malloc (hook_command->cplt_num_templates * sizeof (*hook_command->cplt_templates_static)); @@ -504,7 +504,7 @@ hook_command_build_completion (struct t_hook_command *hook_command) last_space - hook_command->cplt_templates[i]); else hook_command->cplt_templates_static[i] = strdup (hook_command->cplt_templates[i]); - + /* build arguments for each template */ hook_command->cplt_template_args[i] = string_split (hook_command->cplt_templates[i], " ", 0, 0, @@ -512,7 +512,7 @@ hook_command_build_completion (struct t_hook_command *hook_command) if (hook_command->cplt_template_num_args[i] > hook_command->cplt_template_num_args_concat) hook_command->cplt_template_num_args_concat = hook_command->cplt_template_num_args[i]; } - + /* * build strings with concatentaion of items from different templates * for each argument: these strings will be used when completing argument @@ -583,10 +583,10 @@ hook_command (struct t_weechat_plugin *plugin, const char *command, struct t_hook_command *new_hook_command; int priority; const char *ptr_command; - + if (!callback) return NULL; - + if (hook_search_command (plugin, command)) { gui_chat_printf (NULL, @@ -597,7 +597,7 @@ hook_command (struct t_weechat_plugin *plugin, const char *command, plugin_get_name (plugin)); return NULL; } - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -607,11 +607,11 @@ hook_command (struct t_weechat_plugin *plugin, const char *command, free (new_hook); return NULL; } - + hook_get_priority_and_name (command, &priority, &ptr_command); hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND, priority, callback_data); - + new_hook->hook_data = new_hook_command; new_hook_command->callback = callback; new_hook_command->command = strdup ((ptr_command) ? ptr_command : @@ -621,7 +621,7 @@ hook_command (struct t_weechat_plugin *plugin, const char *command, new_hook_command->args_description = strdup ((args_description) ? args_description : ""); new_hook_command->completion = strdup ((completion) ? completion : ""); - + /* build completion variables for command */ new_hook_command->cplt_num_templates = 0; new_hook_command->cplt_templates = NULL; @@ -631,9 +631,9 @@ hook_command (struct t_weechat_plugin *plugin, const char *command, new_hook_command->cplt_template_num_args_concat = 0; new_hook_command->cplt_template_args_concat = NULL; hook_command_build_completion (new_hook_command); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -656,16 +656,16 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin, struct t_hook *hook_for_plugin, *hook_for_other_plugin; char **argv, **argv_eol, *ptr_command_name; int argc, rc, number_for_other_plugin; - + if (!buffer || !string || !string[0]) return -1; - + rc = hook_command_run_exec (buffer, string); if (rc == WEECHAT_RC_OK_EAT) return 1; - + rc = -1; - + argv = string_split (string, " ", 0, 0, &argc); if (argc == 0) { @@ -673,11 +673,11 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin, return -1; } argv_eol = string_split (string, " ", 1, 0, NULL); - + ptr_command_name = utf8_next_char (argv[0]); - + hook_exec_start (); - + hook_for_plugin = NULL; hook_for_other_plugin = NULL; number_for_other_plugin = 0; @@ -685,7 +685,7 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin, while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && (string_strcasecmp (ptr_command_name, HOOK_COMMAND(ptr_hook, command)) == 0)) @@ -705,10 +705,10 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin, } } } - + ptr_hook = next_hook; } - + if (!hook_for_plugin && !hook_for_other_plugin) { /* command not found */ @@ -729,7 +729,7 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin, { ptr_hook = (hook_for_plugin) ? hook_for_plugin : hook_for_other_plugin; - + if (ptr_hook->running >= HOOK_COMMAND_MAX_CALLS) rc = -3; else @@ -745,12 +745,12 @@ hook_command_exec (struct t_gui_buffer *buffer, int any_plugin, } } } - + string_free_split (argv); string_free_split (argv_eol); - + hook_exec_end (); - + return rc; } @@ -766,10 +766,10 @@ hook_command_run (struct t_weechat_plugin *plugin, const char *command, struct t_hook_command_run *new_hook_command_run; int priority; const char *ptr_command; - + if (!callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -779,18 +779,18 @@ hook_command_run (struct t_weechat_plugin *plugin, const char *command, free (new_hook); return NULL; } - + hook_get_priority_and_name (command, &priority, &ptr_command); hook_init_data (new_hook, plugin, HOOK_TYPE_COMMAND_RUN, priority, callback_data); - + new_hook->hook_data = new_hook_command_run; new_hook_command_run->callback = callback; new_hook_command_run->command = strdup ((ptr_command) ? ptr_command : ((command) ? command : "")); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -805,10 +805,10 @@ hook_command_run_exec (struct t_gui_buffer *buffer, const char *command) int rc, hook_matching, length; char *command2; const char *ptr_command; - + ptr_command = command; command2 = NULL; - + if (command[0] != '/') { length = strlen (command) + 1; @@ -819,12 +819,12 @@ hook_command_run_exec (struct t_gui_buffer *buffer, const char *command) ptr_command = command2; } } - + ptr_hook = weechat_hooks[HOOK_TYPE_COMMAND_RUN]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && HOOK_COMMAND_RUN(ptr_hook, command)) @@ -832,7 +832,7 @@ hook_command_run_exec (struct t_gui_buffer *buffer, const char *command) hook_matching = string_match (ptr_command, HOOK_COMMAND_RUN(ptr_hook, command), 0); - + if (!hook_matching && !strchr (HOOK_COMMAND_RUN(ptr_hook, command), ' ')) { @@ -840,7 +840,7 @@ hook_command_run_exec (struct t_gui_buffer *buffer, const char *command) HOOK_COMMAND_RUN(ptr_hook, command), utf8_strlen (HOOK_COMMAND_RUN(ptr_hook, command))) == 0); } - + if (hook_matching) { ptr_hook->running = 1; @@ -856,13 +856,13 @@ hook_command_run_exec (struct t_gui_buffer *buffer, const char *command) } } } - + ptr_hook = next_hook; } - + if (command2) free (command2); - + return WEECHAT_RC_OK; } @@ -876,7 +876,7 @@ hook_timer_init (struct t_hook *hook) time_t time_now; struct tm *local_time, *gm_time; int local_hour, gm_hour, diff_hour; - + gettimeofday (&HOOK_TIMER(hook, last_exec), NULL); time_now = time (NULL); local_time = localtime(&time_now); @@ -897,7 +897,7 @@ hook_timer_init (struct t_hook *hook) } else diff_hour = local_hour - gm_hour; - + if ((HOOK_TIMER(hook, interval) >= 1000) && (HOOK_TIMER(hook, align_second) > 0)) { @@ -912,11 +912,11 @@ hook_timer_init (struct t_hook *hook) ((HOOK_TIMER(hook, last_exec).tv_sec + (diff_hour * 3600)) % HOOK_TIMER(hook, align_second)); } - + /* init next call with date of last call */ HOOK_TIMER(hook, next_exec).tv_sec = HOOK_TIMER(hook, last_exec).tv_sec; HOOK_TIMER(hook, next_exec).tv_usec = HOOK_TIMER(hook, last_exec).tv_usec; - + /* add interval to next call date */ util_timeval_add (&HOOK_TIMER(hook, next_exec), HOOK_TIMER(hook, interval)); } @@ -932,10 +932,10 @@ hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second, { struct t_hook *new_hook; struct t_hook_timer *new_hook_timer; - + if ((interval <= 0) || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -945,20 +945,20 @@ hook_timer (struct t_weechat_plugin *plugin, long interval, int align_second, free (new_hook); return NULL; } - + hook_init_data (new_hook, plugin, HOOK_TYPE_TIMER, HOOK_PRIORITY_DEFAULT, callback_data); - + new_hook->hook_data = new_hook_timer; new_hook_timer->callback = callback; new_hook_timer->interval = interval; new_hook_timer->align_second = align_second; new_hook_timer->remaining_calls = max_calls; - + hook_timer_init (new_hook); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -975,9 +975,9 @@ hook_timer_check_system_clock () time_t now; long diff_time; struct t_hook *ptr_hook; - + now = time (NULL); - + /* * check if difference with previous time is more than 10 seconds: * if it is, then consider it's clock skew and reinitialize all timers @@ -992,7 +992,7 @@ hook_timer_check_system_clock () "reinitializing all timers"), diff_time); } - + /* reinitialize all timers */ for (ptr_hook = weechat_hooks[HOOK_TYPE_TIMER]; ptr_hook; ptr_hook = ptr_hook->next_hook) @@ -1001,7 +1001,7 @@ hook_timer_check_system_clock () hook_timer_init (ptr_hook); } } - + hook_last_system_time = now; } @@ -1018,13 +1018,13 @@ hook_timer_time_to_next (struct timeval *tv_timeout) int found; struct timeval tv_now; long diff_usec; - + hook_timer_check_system_clock (); - + found = 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) { @@ -1037,7 +1037,7 @@ hook_timer_time_to_next (struct timeval *tv_timeout) tv_timeout->tv_usec = HOOK_TIMER(ptr_hook, next_exec).tv_usec; } } - + /* no timeout found, return 2 seconds by default */ if (!found) { @@ -1045,9 +1045,9 @@ hook_timer_time_to_next (struct timeval *tv_timeout) tv_timeout->tv_usec = 0; return; } - + gettimeofday (&tv_now, NULL); - + /* next timeout is past date! */ if (util_timeval_cmp (tv_timeout, &tv_now) < 0) { @@ -1055,7 +1055,7 @@ hook_timer_time_to_next (struct timeval *tv_timeout) tv_timeout->tv_usec = 0; return; } - + 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) @@ -1065,7 +1065,7 @@ hook_timer_time_to_next (struct timeval *tv_timeout) tv_timeout->tv_sec--; tv_timeout->tv_usec = 1000000 + diff_usec; } - + /* * to detect clock skew, we ensure there's a call to timers every * 2 seconds max @@ -1086,18 +1086,18 @@ hook_timer_exec () { struct timeval tv_time; struct t_hook *ptr_hook, *next_hook; - + hook_timer_check_system_clock (); - + gettimeofday (&tv_time, NULL); - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_TIMER]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (util_timeval_cmp (&HOOK_TIMER(ptr_hook, next_exec), @@ -1113,10 +1113,10 @@ hook_timer_exec () { HOOK_TIMER(ptr_hook, last_exec).tv_sec = tv_time.tv_sec; HOOK_TIMER(ptr_hook, last_exec).tv_usec = tv_time.tv_usec; - + util_timeval_add (&HOOK_TIMER(ptr_hook, next_exec), HOOK_TIMER(ptr_hook, interval)); - + if (HOOK_TIMER(ptr_hook, remaining_calls) > 0) { HOOK_TIMER(ptr_hook, remaining_calls)--; @@ -1125,10 +1125,10 @@ hook_timer_exec () } } } - + ptr_hook = next_hook; } - + hook_exec_end (); } @@ -1140,14 +1140,14 @@ struct t_hook * hook_search_fd (int fd) { struct t_hook *ptr_hook; - + for (ptr_hook = weechat_hooks[HOOK_TYPE_FD]; ptr_hook; ptr_hook = ptr_hook->next_hook) { if (!ptr_hook->deleted && (HOOK_FD(ptr_hook, fd) == fd)) return ptr_hook; } - + /* fd hook not found */ return NULL; } @@ -1163,10 +1163,10 @@ hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read, { struct t_hook *new_hook; struct t_hook_fd *new_hook_fd; - + if ((fd < 0) || hook_search_fd (fd) || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -1176,10 +1176,10 @@ hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read, free (new_hook); return NULL; } - + hook_init_data (new_hook, plugin, HOOK_TYPE_FD, HOOK_PRIORITY_DEFAULT, callback_data); - + new_hook->hook_data = new_hook_fd; new_hook_fd->callback = callback; new_hook_fd->fd = fd; @@ -1191,9 +1191,9 @@ hook_fd (struct t_weechat_plugin *plugin, int fd, int flag_read, 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); - + return new_hook; } @@ -1251,7 +1251,7 @@ hook_fd_set (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) } } } - + return max_fd; } @@ -1263,14 +1263,14 @@ void hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) { struct t_hook *ptr_hook, *next_hook; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_FD]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (((HOOK_FD(ptr_hook, flags) & HOOK_FD_FLAG_READ) @@ -1285,10 +1285,10 @@ hook_fd_exec (fd_set *read_fds, fd_set *write_fds, fd_set *exception_fds) HOOK_FD(ptr_hook, fd)); ptr_hook->running = 0; } - + ptr_hook = next_hook; } - + hook_exec_end (); } @@ -1304,21 +1304,21 @@ hook_process (struct t_weechat_plugin *plugin, struct t_hook *new_hook; struct t_hook_process *new_hook_process; char *stdout_buffer, *stderr_buffer; - + if (!command || !command[0] || !callback) return NULL; - + stdout_buffer = malloc (HOOK_PROCESS_BUFFER_SIZE + 1); if (!stdout_buffer) return NULL; - + stderr_buffer = malloc (HOOK_PROCESS_BUFFER_SIZE + 1); if (!stderr_buffer) { free (stdout_buffer); return NULL; } - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) { @@ -1334,10 +1334,10 @@ hook_process (struct t_weechat_plugin *plugin, free (new_hook); return NULL; } - + hook_init_data (new_hook, plugin, HOOK_TYPE_PROCESS, HOOK_PRIORITY_DEFAULT, callback_data); - + new_hook->hook_data = new_hook_process; new_hook_process->callback = callback; new_hook_process->command = strdup (command); @@ -1354,11 +1354,11 @@ hook_process (struct t_weechat_plugin *plugin, new_hook_process->buffer[HOOK_PROCESS_STDERR] = stderr_buffer; new_hook_process->buffer_size[HOOK_PROCESS_STDOUT] = 0; new_hook_process->buffer_size[HOOK_PROCESS_STDERR] = 0; - + hook_add_to_list (new_hook); - + hook_process_run (new_hook); - + return new_hook; } @@ -1371,13 +1371,13 @@ void hook_process_child (struct t_hook *hook_process) { char *exec_args[4] = { "sh", "-c", NULL, NULL }; - + /* * close stdin, so that process will fail to read stdin (process reading * stdin should not be run inside WeeChat!) */ close (STDIN_FILENO); - + /* redirect stdout/stderr to pipe (so that father process can read them) */ close (HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT])); close (HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR])); @@ -1391,11 +1391,11 @@ hook_process_child (struct t_hook *hook_process) { _exit (EXIT_FAILURE); } - + /* launch command */ exec_args[2] = HOOK_PROCESS(hook_process, command); execvp (exec_args[0], exec_args); - + /* should not be executed if execvp was ok */ fprintf (stderr, "Error with command '%s'\n", HOOK_PROCESS(hook_process, command)); @@ -1410,7 +1410,7 @@ void hook_process_send_buffers (struct t_hook *hook_process, int callback_rc) { int i, size; - + /* add '\0' at end of stdout and stderr */ for (i = 0; i < 2; i++) { @@ -1418,7 +1418,7 @@ hook_process_send_buffers (struct t_hook *hook_process, int callback_rc) if (size > 0) HOOK_PROCESS(hook_process, buffer[i])[size] = '\0'; } - + /* send buffers to callback */ (void) (HOOK_PROCESS(hook_process, callback)) (hook_process->callback_data, @@ -1428,7 +1428,7 @@ hook_process_send_buffers (struct t_hook *hook_process, int callback_rc) HOOK_PROCESS(hook_process, buffer[HOOK_PROCESS_STDOUT]) : NULL, (HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDERR]) > 0) ? HOOK_PROCESS(hook_process, buffer[HOOK_PROCESS_STDERR]) : NULL); - + /* reset size for stdout and stderr */ HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDOUT]) = 0; HOOK_PROCESS(hook_process, buffer_size[HOOK_PROCESS_STDERR]) = 0; @@ -1444,7 +1444,7 @@ hook_process_add_to_buffer (struct t_hook *hook_process, int index_buffer, { if (HOOK_PROCESS(hook_process, buffer_size[index_buffer]) + size > HOOK_PROCESS_BUFFER_SIZE) hook_process_send_buffers (hook_process, WEECHAT_HOOK_PROCESS_RUNNING); - + memcpy (HOOK_PROCESS(hook_process, buffer[index_buffer]) + HOOK_PROCESS(hook_process, buffer_size[index_buffer]), buffer, size); @@ -1462,10 +1462,10 @@ hook_process_child_read (struct t_hook *hook_process, int fd, { char buffer[4096]; int num_read; - + if (hook_process->deleted) return; - + num_read = read (fd, buffer, sizeof (buffer) - 1); if (num_read > 0) { @@ -1488,7 +1488,7 @@ int hook_process_child_read_stdout_cb (void *arg_hook_process, int fd) { struct t_hook *hook_process; - + hook_process = (struct t_hook *)arg_hook_process; hook_process_child_read (hook_process, fd, HOOK_PROCESS_STDOUT, &(HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDOUT]))); @@ -1504,7 +1504,7 @@ int hook_process_child_read_stderr_cb (void *arg_hook_process, int fd) { struct t_hook *hook_process; - + hook_process = (struct t_hook *)arg_hook_process; hook_process_child_read (hook_process, fd, HOOK_PROCESS_STDERR, &(HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDERR]))); @@ -1520,15 +1520,15 @@ hook_process_timer_cb (void *arg_hook_process, int remaining_calls) { struct t_hook *hook_process; int status, rc; - + /* make C compiler happy */ (void) remaining_calls; - + hook_process = (struct t_hook *)arg_hook_process; - + if (hook_process->deleted) return WEECHAT_RC_OK; - + if (remaining_calls == 0) { hook_process_send_buffers (hook_process, WEECHAT_HOOK_PROCESS_ERROR); @@ -1556,7 +1556,7 @@ hook_process_timer_cb (void *arg_hook_process, int remaining_calls) } } } - + return WEECHAT_RC_OK; } @@ -1571,7 +1571,7 @@ hook_process_run (struct t_hook *hook_process) int pipe_stdout[2], pipe_stderr[2], timeout, max_calls; long interval; pid_t pid; - + /* create pipe for child process (stdout) */ if (pipe (pipe_stdout) < 0) { @@ -1595,13 +1595,13 @@ hook_process_run (struct t_hook *hook_process) unhook (hook_process); return; } - + HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT]) = pipe_stdout[0]; HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT]) = pipe_stdout[1]; - + HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR]) = pipe_stderr[0]; HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR]) = pipe_stderr[1]; - + switch (pid = fork ()) { /* fork failed */ @@ -1627,21 +1627,21 @@ hook_process_run (struct t_hook *hook_process) HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDOUT]) = -1; close (HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR])); HOOK_PROCESS(hook_process, child_write[HOOK_PROCESS_STDERR]) = -1; - + HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDOUT]) = hook_fd (hook_process->plugin, HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDOUT]), 1, 0, 0, &hook_process_child_read_stdout_cb, hook_process); - + HOOK_PROCESS(hook_process, hook_fd[HOOK_PROCESS_STDERR]) = hook_fd (hook_process->plugin, HOOK_PROCESS(hook_process, child_read[HOOK_PROCESS_STDERR]), 1, 0, 0, &hook_process_child_read_stderr_cb, hook_process); - + timeout = HOOK_PROCESS(hook_process, timeout); interval = 100; max_calls = 0; @@ -1679,7 +1679,7 @@ hook_connect (struct t_weechat_plugin *plugin, const char *proxy, { struct t_hook *new_hook; struct t_hook_connect *new_hook_connect; - + #ifndef HAVE_GNUTLS /* make C compiler happy */ (void) gnutls_sess; @@ -1687,10 +1687,10 @@ hook_connect (struct t_weechat_plugin *plugin, const char *proxy, (void) gnutls_dhkey_size; (void) gnutls_priorities; #endif - + if ((sock < 0) || !address || (port <= 0) || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -1700,10 +1700,10 @@ hook_connect (struct t_weechat_plugin *plugin, const char *proxy, free (new_hook); return NULL; } - + hook_init_data (new_hook, plugin, HOOK_TYPE_CONNECT, HOOK_PRIORITY_DEFAULT, callback_data); - + new_hook->hook_data = new_hook_connect; new_hook_connect->callback = callback; new_hook_connect->proxy = (proxy) ? strdup (proxy) : NULL; @@ -1728,11 +1728,11 @@ hook_connect (struct t_weechat_plugin *plugin, const char *proxy, new_hook_connect->handshake_hook_timer = NULL; new_hook_connect->handshake_fd_flags = 0; new_hook_connect->handshake_ip_address = NULL; - + hook_add_to_list (new_hook); - + network_connect_with_fork (new_hook); - + return new_hook; } @@ -1746,7 +1746,7 @@ hook_connect_gnutls_verify_certificates (gnutls_session_t tls_session) { struct t_hook *ptr_hook; int rc; - + rc = -1; ptr_hook = weechat_hooks[HOOK_TYPE_CONNECT]; while (ptr_hook) @@ -1764,7 +1764,7 @@ hook_connect_gnutls_verify_certificates (gnutls_session_t tls_session) } ptr_hook = ptr_hook->next_hook; } - + return rc; } #endif @@ -1787,7 +1787,7 @@ hook_connect_gnutls_set_certificates (gnutls_session_t tls_session, { struct t_hook *ptr_hook; int rc; - + rc = -1; ptr_hook = weechat_hooks[HOOK_TYPE_CONNECT]; while (ptr_hook) @@ -1805,7 +1805,7 @@ hook_connect_gnutls_set_certificates (gnutls_session_t tls_session, } ptr_hook = ptr_hook->next_hook; } - + return rc; } #endif @@ -1821,10 +1821,10 @@ hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, { struct t_hook *new_hook; struct t_hook_print *new_hook_print; - + if (!callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -1834,10 +1834,10 @@ hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, free (new_hook); return NULL; } - + hook_init_data (new_hook, plugin, HOOK_TYPE_PRINT, HOOK_PRIORITY_DEFAULT, callback_data); - + new_hook->hook_data = new_hook_print; new_hook_print->callback = callback; new_hook_print->buffer = buffer; @@ -1853,9 +1853,9 @@ hook_print (struct t_weechat_plugin *plugin, struct t_gui_buffer *buffer, } new_hook_print->message = (message) ? strdup (message) : NULL; new_hook_print->strip_colors = strip_colors; - + hook_add_to_list (new_hook); - + return new_hook; } @@ -1869,13 +1869,13 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line) struct t_hook *ptr_hook, *next_hook; char *prefix_no_color, *message_no_color; int tags_match, tag_found, i, j; - + if (!line->data->message || !line->data->message[0]) return; - + prefix_no_color = (line->data->prefix) ? gui_color_decode (line->data->prefix, NULL) : NULL; - + message_no_color = gui_color_decode (line->data->message, NULL); if (!message_no_color) { @@ -1883,14 +1883,14 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line) free (prefix_no_color); return; } - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_PRINT]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (!HOOK_PRINT(ptr_hook, buffer) @@ -1933,7 +1933,7 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line) } else tags_match = 1; - + /* run callback */ if (tags_match) { @@ -1948,15 +1948,15 @@ hook_print_exec (struct t_gui_buffer *buffer, struct t_gui_line *line) ptr_hook->running = 0; } } - + ptr_hook = next_hook; } - + if (prefix_no_color) free (prefix_no_color); if (message_no_color) free (message_no_color); - + hook_exec_end (); } @@ -1972,10 +1972,10 @@ hook_signal (struct t_weechat_plugin *plugin, const char *signal, struct t_hook_signal *new_hook_signal; int priority; const char *ptr_signal; - + if (!signal || !signal[0] || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -1985,17 +1985,17 @@ hook_signal (struct t_weechat_plugin *plugin, const char *signal, free (new_hook); return NULL; } - + hook_get_priority_and_name (signal, &priority, &ptr_signal); hook_init_data (new_hook, plugin, HOOK_TYPE_SIGNAL, priority, callback_data); - + new_hook->hook_data = new_hook_signal; new_hook_signal->callback = callback; new_hook_signal->signal = strdup ((ptr_signal) ? ptr_signal : signal); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2007,14 +2007,14 @@ void hook_signal_send (const char *signal, const char *type_data, void *signal_data) { struct t_hook *ptr_hook, *next_hook; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_SIGNAL]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (string_match (signal, HOOK_SIGNAL(ptr_hook, signal), 0))) @@ -2024,10 +2024,10 @@ hook_signal_send (const char *signal, const char *type_data, void *signal_data) (ptr_hook->callback_data, signal, type_data, signal_data); ptr_hook->running = 0; } - + ptr_hook = next_hook; } - + hook_exec_end (); } @@ -2043,10 +2043,10 @@ hook_hsignal (struct t_weechat_plugin *plugin, const char *signal, struct t_hook_hsignal *new_hook_hsignal; int priority; const char *ptr_signal; - + if (!signal || !signal[0] || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -2056,17 +2056,17 @@ hook_hsignal (struct t_weechat_plugin *plugin, const char *signal, free (new_hook); return NULL; } - + hook_get_priority_and_name (signal, &priority, &ptr_signal); hook_init_data (new_hook, plugin, HOOK_TYPE_HSIGNAL, priority, callback_data); - + new_hook->hook_data = new_hook_hsignal; new_hook_hsignal->callback = callback; new_hook_hsignal->signal = strdup ((ptr_signal) ? ptr_signal : signal); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2078,14 +2078,14 @@ void hook_hsignal_send (const char *signal, struct t_hashtable *hashtable) { struct t_hook *ptr_hook, *next_hook; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_HSIGNAL]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (string_match (signal, HOOK_HSIGNAL(ptr_hook, signal), 0))) @@ -2095,10 +2095,10 @@ hook_hsignal_send (const char *signal, struct t_hashtable *hashtable) (ptr_hook->callback_data, signal, hashtable); ptr_hook->running = 0; } - + ptr_hook = next_hook; } - + hook_exec_end (); } @@ -2114,10 +2114,10 @@ hook_config (struct t_weechat_plugin *plugin, const char *option, struct t_hook_config *new_hook_config; int priority; const char *ptr_option; - + if (!callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -2127,18 +2127,18 @@ hook_config (struct t_weechat_plugin *plugin, const char *option, free (new_hook); return NULL; } - + hook_get_priority_and_name (option, &priority, &ptr_option); hook_init_data (new_hook, plugin, HOOK_TYPE_CONFIG, priority, callback_data); - + new_hook->hook_data = new_hook_config; new_hook_config->callback = callback; new_hook_config->option = strdup ((ptr_option) ? ptr_option : ((option) ? option : "")); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2150,14 +2150,14 @@ void hook_config_exec (const char *option, const char *value) { struct t_hook *ptr_hook, *next_hook; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_CONFIG]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (!HOOK_CONFIG(ptr_hook, option) @@ -2168,10 +2168,10 @@ hook_config_exec (const char *option, const char *value) (ptr_hook->callback_data, option, value); ptr_hook->running = 0; } - + ptr_hook = next_hook; } - + hook_exec_end (); } @@ -2188,11 +2188,11 @@ hook_completion (struct t_weechat_plugin *plugin, const char *completion_item, struct t_hook_completion *new_hook_completion; int priority; const char *ptr_completion_item; - + if (!completion_item || !completion_item[0] || strchr (completion_item, ' ') || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -2202,20 +2202,20 @@ hook_completion (struct t_weechat_plugin *plugin, const char *completion_item, free (new_hook); return NULL; } - + hook_get_priority_and_name (completion_item, &priority, &ptr_completion_item); hook_init_data (new_hook, plugin, HOOK_TYPE_COMPLETION, priority, callback_data); - + new_hook->hook_data = new_hook_completion; new_hook_completion->callback = callback; new_hook_completion->completion_item = strdup ((ptr_completion_item) ? ptr_completion_item : completion_item); new_hook_completion->description = strdup ((description) ? description : ""); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2253,17 +2253,17 @@ hook_completion_exec (struct t_weechat_plugin *plugin, struct t_gui_completion *completion) { struct t_hook *ptr_hook, *next_hook; - + /* make C compiler happy */ (void) plugin; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_COMPLETION]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_COMPLETION(ptr_hook, completion_item), @@ -2274,10 +2274,10 @@ hook_completion_exec (struct t_weechat_plugin *plugin, (ptr_hook->callback_data, completion_item, buffer, completion); ptr_hook->running = 0; } - + ptr_hook = next_hook; } - + hook_exec_end (); } @@ -2293,10 +2293,10 @@ hook_modifier (struct t_weechat_plugin *plugin, const char *modifier, struct t_hook_modifier *new_hook_modifier; int priority; const char *ptr_modifier; - + if (!modifier || !modifier[0] || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -2306,17 +2306,17 @@ hook_modifier (struct t_weechat_plugin *plugin, const char *modifier, free (new_hook); return NULL; } - + hook_get_priority_and_name (modifier, &priority, &ptr_modifier); hook_init_data (new_hook, plugin, HOOK_TYPE_MODIFIER, priority, callback_data); - + new_hook->hook_data = new_hook_modifier; new_hook_modifier->callback = callback; new_hook_modifier->modifier = strdup ((ptr_modifier) ? ptr_modifier : modifier); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2330,25 +2330,25 @@ hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier, { struct t_hook *ptr_hook, *next_hook; char *new_msg, *message_modified; - + /* make C compiler happy */ (void) plugin; - + if (!modifier || !modifier[0]) return NULL; - + new_msg = NULL; message_modified = strdup (string); if (!message_modified) return NULL; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_MODIFIER]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_MODIFIER(ptr_hook, modifier), @@ -2359,7 +2359,7 @@ hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier, (ptr_hook->callback_data, modifier, modifier_data, message_modified); ptr_hook->running = 0; - + /* empty string returned => message dropped */ if (new_msg && !new_msg[0]) { @@ -2367,7 +2367,7 @@ hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier, hook_exec_end (); return new_msg; } - + /* new message => keep it as base for next modifier */ if (new_msg) { @@ -2375,12 +2375,12 @@ hook_modifier_exec (struct t_weechat_plugin *plugin, const char *modifier, message_modified = new_msg; } } - + ptr_hook = next_hook; } - + hook_exec_end (); - + return message_modified; } @@ -2397,10 +2397,10 @@ hook_info (struct t_weechat_plugin *plugin, const char *info_name, struct t_hook_info *new_hook_info; int priority; const char *ptr_info_name; - + if (!info_name || !info_name[0] || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -2410,10 +2410,10 @@ hook_info (struct t_weechat_plugin *plugin, const char *info_name, free (new_hook); return NULL; } - + hook_get_priority_and_name (info_name, &priority, &ptr_info_name); hook_init_data (new_hook, plugin, HOOK_TYPE_INFO, priority, callback_data); - + new_hook->hook_data = new_hook_info; new_hook_info->callback = callback; new_hook_info->info_name = strdup ((ptr_info_name) ? @@ -2421,9 +2421,9 @@ hook_info (struct t_weechat_plugin *plugin, const char *info_name, new_hook_info->description = strdup ((description) ? description : ""); new_hook_info->args_description = strdup ((args_description) ? args_description : ""); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2437,20 +2437,20 @@ hook_info_get (struct t_weechat_plugin *plugin, const char *info_name, { struct t_hook *ptr_hook, *next_hook; const char *value; - + /* make C compiler happy */ (void) plugin; - + if (!info_name || !info_name[0]) return NULL; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_INFO]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_INFO(ptr_hook, info_name), @@ -2460,16 +2460,16 @@ hook_info_get (struct t_weechat_plugin *plugin, const char *info_name, value = (HOOK_INFO(ptr_hook, callback)) (ptr_hook->callback_data, info_name, arguments); ptr_hook->running = 0; - + hook_exec_end (); return value; } - + ptr_hook = next_hook; } - + hook_exec_end (); - + /* info not found */ return NULL; } @@ -2489,10 +2489,10 @@ hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name, struct t_hook_info_hashtable *new_hook_info_hashtable; int priority; const char *ptr_info_name; - + if (!info_name || !info_name[0] || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -2502,11 +2502,11 @@ hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name, free (new_hook); return NULL; } - + hook_get_priority_and_name (info_name, &priority, &ptr_info_name); hook_init_data (new_hook, plugin, HOOK_TYPE_INFO_HASHTABLE, priority, callback_data); - + new_hook->hook_data = new_hook_info_hashtable; new_hook_info_hashtable->callback = callback; new_hook_info_hashtable->info_name = strdup ((ptr_info_name) ? @@ -2516,9 +2516,9 @@ hook_info_hashtable (struct t_weechat_plugin *plugin, const char *info_name, args_description : ""); new_hook_info_hashtable->output_description = strdup ((output_description) ? output_description : ""); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2532,20 +2532,20 @@ hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name, { struct t_hook *ptr_hook, *next_hook; struct t_hashtable *value; - + /* make C compiler happy */ (void) plugin; - + if (!info_name || !info_name[0]) return NULL; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_INFO_HASHTABLE]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_INFO_HASHTABLE(ptr_hook, info_name), @@ -2555,16 +2555,16 @@ hook_info_get_hashtable (struct t_weechat_plugin *plugin, const char *info_name, value = (HOOK_INFO_HASHTABLE(ptr_hook, callback)) (ptr_hook->callback_data, info_name, hashtable); ptr_hook->running = 0; - + hook_exec_end (); return value; } - + ptr_hook = next_hook; } - + hook_exec_end (); - + /* info not found */ return NULL; } @@ -2583,10 +2583,10 @@ hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name, struct t_hook_infolist *new_hook_infolist; int priority; const char *ptr_infolist_name; - + if (!infolist_name || !infolist_name[0] || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -2596,11 +2596,11 @@ hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name, free (new_hook); return NULL; } - + hook_get_priority_and_name (infolist_name, &priority, &ptr_infolist_name); hook_init_data (new_hook, plugin, HOOK_TYPE_INFOLIST, priority, callback_data); - + new_hook->hook_data = new_hook_infolist; new_hook_infolist->callback = callback; new_hook_infolist->infolist_name = strdup ((ptr_infolist_name) ? @@ -2610,9 +2610,9 @@ hook_infolist (struct t_weechat_plugin *plugin, const char *infolist_name, pointer_description : ""); new_hook_infolist->args_description = strdup ((args_description) ? args_description : ""); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2626,20 +2626,20 @@ hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name, { struct t_hook *ptr_hook, *next_hook; struct t_infolist *value; - + /* make C compiler happy */ (void) plugin; - + if (!infolist_name || !infolist_name[0]) return NULL; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_INFOLIST]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (string_strcasecmp (HOOK_INFOLIST(ptr_hook, infolist_name), @@ -2649,16 +2649,16 @@ hook_infolist_get (struct t_weechat_plugin *plugin, const char *infolist_name, value = (HOOK_INFOLIST(ptr_hook, callback)) (ptr_hook->callback_data, infolist_name, pointer, arguments); ptr_hook->running = 0; - + hook_exec_end (); return value; } - + ptr_hook = next_hook; } - + hook_exec_end (); - + /* infolist not found */ return NULL; } @@ -2676,10 +2676,10 @@ hook_hdata (struct t_weechat_plugin *plugin, const char *hdata_name, struct t_hook_hdata *new_hook_hdata; int priority; const char *ptr_hdata_name; - + if (!hdata_name || !hdata_name[0] || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -2689,19 +2689,19 @@ hook_hdata (struct t_weechat_plugin *plugin, const char *hdata_name, free (new_hook); return NULL; } - + hook_get_priority_and_name (hdata_name, &priority, &ptr_hdata_name); hook_init_data (new_hook, plugin, HOOK_TYPE_HDATA, priority, callback_data); - + new_hook->hook_data = new_hook_hdata; new_hook_hdata->callback = callback; new_hook_hdata->hdata_name = strdup ((ptr_hdata_name) ? ptr_hdata_name : hdata_name); new_hook_hdata->description = strdup ((description) ? description : ""); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2714,27 +2714,27 @@ hook_hdata_get (struct t_weechat_plugin *plugin, const char *hdata_name) { struct t_hook *ptr_hook, *next_hook; struct t_hdata *value; - + /* make C compiler happy */ (void) plugin; - + if (!hdata_name || !hdata_name[0]) return NULL; - + if (weechat_hdata) { value = hashtable_get (weechat_hdata, hdata_name); if (value) return value; } - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_HDATA]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && (strcmp (HOOK_HDATA(ptr_hook, hdata_name), hdata_name) == 0)) @@ -2744,16 +2744,16 @@ hook_hdata_get (struct t_weechat_plugin *plugin, const char *hdata_name) (ptr_hook->callback_data, HOOK_HDATA(ptr_hook, hdata_name)); ptr_hook->running = 0; - + hook_exec_end (); return value; } - + ptr_hook = next_hook; } - + hook_exec_end (); - + /* hdata not found */ return NULL; } @@ -2770,10 +2770,10 @@ hook_focus (struct t_weechat_plugin *plugin, const char *area, struct t_hook_focus *new_hook_focus; int priority; const char *ptr_area; - + if (!area || !area[0] || !callback) return NULL; - + new_hook = malloc (sizeof (*new_hook)); if (!new_hook) return NULL; @@ -2783,17 +2783,17 @@ hook_focus (struct t_weechat_plugin *plugin, const char *area, free (new_hook); return NULL; } - + hook_get_priority_and_name (area, &priority, &ptr_area); hook_init_data (new_hook, plugin, HOOK_TYPE_FOCUS, priority, callback_data); - + new_hook->hook_data = new_hook_focus; new_hook_focus->callback = callback; new_hook_focus->area = strdup ((ptr_area) ? ptr_area : area); - + hook_add_to_list (new_hook); - + return new_hook; } @@ -2806,10 +2806,10 @@ hook_focus_hashtable_map_cb (void *data, struct t_hashtable *hashtable, const void *key, const void *value) { struct t_hashtable *hashtable1; - + /* make C compiler happy */ (void) hashtable; - + hashtable1 = (struct t_hashtable *)data; if (hashtable1 && key && value) @@ -2828,10 +2828,10 @@ hook_focus_hashtable_map2_cb (void *data, struct t_hashtable *hashtable, struct t_hashtable *hashtable1; int length; char *key2; - + /* make C compiler happy */ (void) hashtable; - + hashtable1 = (struct t_hashtable *)data; length = strlen ((const char *)key) + 1 + 1; @@ -2860,26 +2860,26 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1, const char *focus1_chat, *focus1_bar_item_name, *keys; char **list_keys, *new_key; int num_keys, i, length, focus1_is_chat; - + if (!hashtable_focus1) return NULL; - + focus1_chat = hashtable_get (hashtable_focus1, "_chat"); focus1_is_chat = (focus1_chat && (strcmp (focus1_chat, "1") == 0)); focus1_bar_item_name = hashtable_get (hashtable_focus1, "_bar_item_name"); - + hashtable1 = hashtable_dup (hashtable_focus1); if (!hashtable1) return NULL; hashtable2 = (hashtable_focus2) ? hashtable_dup (hashtable_focus2) : NULL; - + hook_exec_start (); - + ptr_hook = weechat_hooks[HOOK_TYPE_FOCUS]; while (ptr_hook) { next_hook = ptr_hook->next_hook; - + if (!ptr_hook->deleted && !ptr_hook->running && ((focus1_is_chat @@ -2906,7 +2906,7 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1, hashtable_free (hashtable_ret); } } - + /* run callback for focus #2 */ if (hashtable2) { @@ -2930,10 +2930,10 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1, } } } - + ptr_hook = next_hook; } - + if (hashtable2) { hashtable_map (hashtable2, &hook_focus_hashtable_map2_cb, hashtable1); @@ -2964,9 +2964,9 @@ hook_focus_get_data (struct t_hashtable *hashtable_focus1, } } } - + hook_exec_end (); - + return hashtable1; } @@ -2978,15 +2978,15 @@ void unhook (struct t_hook *hook) { int i; - + /* invalid hook? */ if (!hook_valid (hook)) return; - + /* hook already deleted? */ if (hook->deleted) return; - + if (weechat_debug_core >= 2) { gui_chat_printf (NULL, @@ -2994,7 +2994,7 @@ unhook (struct t_hook *hook) hook->type, hook_type_string[hook->type], hook->plugin, plugin_get_name (hook->plugin)); } - + /* free data */ if (hook->hook_data) { @@ -3178,7 +3178,7 @@ unhook (struct t_hook *hook) free (hook->hook_data); hook->hook_data = NULL; } - + /* remove hook from list (if there's no hook exec pending) */ if (hook_exec_recursion == 0) { @@ -3201,7 +3201,7 @@ unhook_all_plugin (struct t_weechat_plugin *plugin) { int type; struct t_hook *ptr_hook, *next_hook; - + for (type = 0; type < HOOK_NUM_TYPES; type++) { ptr_hook = weechat_hooks[type]; @@ -3224,7 +3224,7 @@ unhook_all () { int type; struct t_hook *ptr_hook, *next_hook; - + for (type = 0; type < HOOK_NUM_TYPES; type++) { ptr_hook = weechat_hooks[type]; @@ -3266,14 +3266,14 @@ hook_add_to_infolist_type (struct t_infolist *infolist, int type, break; } } - + if (!match) continue; - + ptr_item = infolist_new_item (infolist); if (!ptr_item) return 0; - + if (!infolist_new_var_pointer (ptr_item, "pointer", ptr_hook)) return 0; if (!infolist_new_var_pointer (ptr_item, "plugin", ptr_hook->plugin)) @@ -3624,7 +3624,7 @@ hook_add_to_infolist_type (struct t_infolist *infolist, int type, break; } } - + return 1; } @@ -3641,13 +3641,13 @@ hook_add_to_infolist (struct t_infolist *infolist, const char *arguments) const char *pos_arguments; char *type; int i, type_int; - + if (!infolist) return 0; - + type = NULL; pos_arguments = NULL; - + if (arguments && arguments[0]) { pos_arguments = strchr (arguments, ','); @@ -3659,18 +3659,18 @@ hook_add_to_infolist (struct t_infolist *infolist, const char *arguments) else type = strdup (arguments); } - + type_int = (type) ? hook_search_type (type) : -1; - + for (i = 0; i < HOOK_NUM_TYPES; i++) { if ((type_int < 0) || (type_int == i)) hook_add_to_infolist_type (infolist, i, pos_arguments); } - + if (type) free (type); - + return 1; } @@ -3685,7 +3685,7 @@ hook_print_log () struct t_hook *ptr_hook; struct tm *local_time; char text_time[1024]; - + for (type = 0; type < HOOK_NUM_TYPES; type++) { for (ptr_hook = weechat_hooks[type]; ptr_hook; diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h index 37edded47..a3ca2f52d 100644 --- a/src/core/wee-hook.h +++ b/src/core/wee-hook.h @@ -108,7 +108,7 @@ struct t_hook int running; /* 1 if hook is currently running */ int priority; /* priority (to sort hooks) */ void *callback_data; /* data sent to callback */ - + /* hook data (depends on hook type) */ void *hook_data; /* hook specific data */ struct t_hook *prev_hook; /* link to previous hook */ @@ -128,17 +128,17 @@ struct t_hook_command char *args; /* (for /help) command arguments */ char *args_description; /* (for /help) args long description*/ char *completion; /* template for completion */ - + /* templates */ int cplt_num_templates; /* number of templates for compl. */ char **cplt_templates; /* completion templates */ char **cplt_templates_static; /* static part of template (at */ /* beginning */ - + /* arguments for each template */ int *cplt_template_num_args; /* number of arguments for template */ char ***cplt_template_args; /* arguments for each template */ - + /* concatenation of arg N for each template */ int cplt_template_num_args_concat; /* number of concatened arguments */ char **cplt_template_args_concat; /* concatened arguments */ diff --git a/src/core/wee-infolist.c b/src/core/wee-infolist.c index 31f484925..875f2e41d 100644 --- a/src/core/wee-infolist.c +++ b/src/core/wee-infolist.c @@ -54,7 +54,7 @@ infolist_new (struct t_weechat_plugin *plugin) new_infolist->items = NULL; new_infolist->last_item = NULL; new_infolist->ptr_item = NULL; - + new_infolist->prev_infolist = last_weechat_infolist; new_infolist->next_infolist = NULL; if (weechat_infolists) @@ -63,7 +63,7 @@ infolist_new (struct t_weechat_plugin *plugin) weechat_infolists = new_infolist; last_weechat_infolist = new_infolist; } - + return new_infolist; } @@ -82,7 +82,7 @@ infolist_new_item (struct t_infolist *infolist) new_item->vars = NULL; new_item->last_var = NULL; new_item->fields = NULL; - + new_item->prev_item = infolist->last_item; new_item->next_item = NULL; if (infolist->items) @@ -91,7 +91,7 @@ infolist_new_item (struct t_infolist *infolist) infolist->items = new_item; infolist->last_item = new_item; } - + return new_item; } @@ -104,10 +104,10 @@ infolist_new_var_integer (struct t_infolist_item *item, const char *name, int value) { struct t_infolist_var *new_var; - + if (!item || !name || !name[0]) return NULL; - + new_var = malloc (sizeof (*new_var)); if (new_var) { @@ -116,7 +116,7 @@ infolist_new_var_integer (struct t_infolist_item *item, new_var->value = malloc (sizeof (int)); if (new_var->value) *((int *)new_var->value) = value; - + new_var->prev_var = item->last_var; new_var->next_var = NULL; if (item->vars) @@ -125,7 +125,7 @@ infolist_new_var_integer (struct t_infolist_item *item, item->vars = new_var; item->last_var = new_var; } - + return new_var; } @@ -138,17 +138,17 @@ infolist_new_var_string (struct t_infolist_item *item, const char *name, const char *value) { struct t_infolist_var *new_var; - + if (!item || !name || !name[0]) return NULL; - + new_var = malloc (sizeof (*new_var)); if (new_var) { new_var->name = strdup (name); new_var->type = INFOLIST_STRING; new_var->value = (value) ? strdup (value) : NULL; - + new_var->prev_var = item->last_var; new_var->next_var = NULL; if (item->vars) @@ -157,7 +157,7 @@ infolist_new_var_string (struct t_infolist_item *item, item->vars = new_var; item->last_var = new_var; } - + return new_var; } @@ -170,17 +170,17 @@ infolist_new_var_pointer (struct t_infolist_item *item, const char *name, void *pointer) { struct t_infolist_var *new_var; - + if (!item || !name || !name[0]) return NULL; - + new_var = malloc (sizeof (*new_var)); if (new_var) { new_var->name = strdup (name); new_var->type = INFOLIST_POINTER; new_var->value = pointer; - + new_var->prev_var = item->last_var; new_var->next_var = NULL; if (item->vars) @@ -189,7 +189,7 @@ infolist_new_var_pointer (struct t_infolist_item *item, item->vars = new_var; item->last_var = new_var; } - + return new_var; } @@ -202,10 +202,10 @@ infolist_new_var_buffer (struct t_infolist_item *item, const char *name, void *pointer, int size) { struct t_infolist_var *new_var; - + if (!item || !name || !name[0] || (size <= 0)) return NULL; - + new_var = malloc (sizeof (*new_var)); if (new_var) { @@ -215,7 +215,7 @@ infolist_new_var_buffer (struct t_infolist_item *item, if (new_var->value) memcpy (new_var->value, pointer, size); new_var->size = size; - + new_var->prev_var = item->last_var; new_var->next_var = NULL; if (item->vars) @@ -224,7 +224,7 @@ infolist_new_var_buffer (struct t_infolist_item *item, item->vars = new_var; item->last_var = new_var; } - + return new_var; } @@ -237,10 +237,10 @@ infolist_new_var_time (struct t_infolist_item *item, const char *name, time_t time) { struct t_infolist_var *new_var; - + if (!item || !name || !name[0]) return NULL; - + new_var = malloc (sizeof (*new_var)); if (new_var) { @@ -249,7 +249,7 @@ infolist_new_var_time (struct t_infolist_item *item, new_var->value = malloc (sizeof (time_t)); if (new_var->value) *((time_t *)new_var->value) = time; - + new_var->prev_var = item->last_var; new_var->next_var = NULL; if (item->vars) @@ -258,7 +258,7 @@ infolist_new_var_time (struct t_infolist_item *item, item->vars = new_var; item->last_var = new_var; } - + return new_var; } @@ -272,14 +272,14 @@ int infolist_valid (struct t_infolist *infolist) { struct t_infolist *ptr_infolist; - + for (ptr_infolist = weechat_infolists; ptr_infolist; ptr_infolist = ptr_infolist->next_infolist) { if (ptr_infolist == infolist) return 1; } - + /* list not found */ return 0; } @@ -339,25 +339,25 @@ infolist_fields (struct t_infolist *infolist) { struct t_infolist_var *ptr_var; int length; - + if (!infolist || !infolist->ptr_item) return NULL; /* list of fields already asked ? if yes, just return string */ if (infolist->ptr_item->fields) return infolist->ptr_item->fields; - + length = 0; for (ptr_var = infolist->ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { length += strlen (ptr_var->name) + 3; } - + infolist->ptr_item->fields = malloc (length + 1); if (!infolist->ptr_item->fields) return NULL; - + infolist->ptr_item->fields[0] = '\0'; for (ptr_var = infolist->ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) @@ -384,7 +384,7 @@ infolist_fields (struct t_infolist *infolist) if (ptr_var->next_var) strcat (infolist->ptr_item->fields, ","); } - + return infolist->ptr_item->fields; } @@ -396,10 +396,10 @@ int infolist_integer (struct t_infolist *infolist, const char *var) { struct t_infolist_var *ptr_var; - + if (!infolist || !infolist->ptr_item || !var || !var[0]) return 0; - + for (ptr_var = infolist->ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { @@ -411,7 +411,7 @@ infolist_integer (struct t_infolist *infolist, const char *var) return 0; } } - + /* variable not found */ return 0; } @@ -424,10 +424,10 @@ const char * infolist_string (struct t_infolist *infolist, const char *var) { struct t_infolist_var *ptr_var; - + if (!infolist || !infolist->ptr_item || !var || !var[0]) return NULL; - + for (ptr_var = infolist->ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { @@ -439,7 +439,7 @@ infolist_string (struct t_infolist *infolist, const char *var) return NULL; } } - + /* variable not found */ return NULL; } @@ -452,10 +452,10 @@ void * infolist_pointer (struct t_infolist *infolist, const char *var) { struct t_infolist_var *ptr_var; - + if (!infolist || !infolist->ptr_item || !var || !var[0]) return NULL; - + for (ptr_var = infolist->ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { @@ -467,7 +467,7 @@ infolist_pointer (struct t_infolist *infolist, const char *var) return NULL; } } - + /* variable not found */ return NULL; } @@ -482,10 +482,10 @@ infolist_buffer (struct t_infolist *infolist, const char *var, int *size) { struct t_infolist_var *ptr_var; - + if (!infolist || !infolist->ptr_item || !var || !var[0]) return NULL; - + for (ptr_var = infolist->ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { @@ -500,7 +500,7 @@ infolist_buffer (struct t_infolist *infolist, const char *var, return NULL; } } - + /* variable not found */ return NULL; } @@ -513,10 +513,10 @@ time_t infolist_time (struct t_infolist *infolist, const char *var) { struct t_infolist_var *ptr_var; - + if (!infolist || !infolist->ptr_item || !var || !var[0]) return 0; - + for (ptr_var = infolist->ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { @@ -528,7 +528,7 @@ infolist_time (struct t_infolist *infolist, const char *var) return 0; } } - + /* variable not found */ return 0; } @@ -542,7 +542,7 @@ infolist_var_free (struct t_infolist_item *item, struct t_infolist_var *var) { struct t_infolist_var *new_vars; - + /* remove var */ if (item->last_var == var) item->last_var = var->prev_var; @@ -553,10 +553,10 @@ infolist_var_free (struct t_infolist_item *item, } else new_vars = var->next_var; - + if (var->next_var) (var->next_var)->prev_var = var->prev_var; - + /* free data */ if (var->name) free (var->name); @@ -568,9 +568,9 @@ infolist_var_free (struct t_infolist_item *item, { free (var->value); } - + free (var); - + item->vars = new_vars; } @@ -583,7 +583,7 @@ infolist_item_free (struct t_infolist *infolist, struct t_infolist_item *item) { struct t_infolist_item *new_items; - + /* remove var */ if (infolist->last_item == item) infolist->last_item = item->prev_item; @@ -594,10 +594,10 @@ infolist_item_free (struct t_infolist *infolist, } else new_items = item->next_item; - + if (item->next_item) (item->next_item)->prev_item = item->prev_item; - + /* free data */ while (item->vars) { @@ -605,9 +605,9 @@ infolist_item_free (struct t_infolist *infolist, } if (item->fields) free (item->fields); - + free (item); - + infolist->items = new_items; } @@ -619,7 +619,7 @@ void infolist_free (struct t_infolist *infolist) { struct t_infolist *new_weechat_infolists; - + /* remove list */ if (last_weechat_infolist == infolist) last_weechat_infolist = infolist->prev_infolist; @@ -630,18 +630,18 @@ infolist_free (struct t_infolist *infolist) } else new_weechat_infolists = infolist->next_infolist; - + if (infolist->next_infolist) (infolist->next_infolist)->prev_infolist = infolist->prev_infolist; - + /* free data */ while (infolist->items) { infolist_item_free (infolist, infolist->items); } - + free (infolist); - + weechat_infolists = new_weechat_infolists; } @@ -653,7 +653,7 @@ void infolist_free_all_plugin (struct t_weechat_plugin *plugin) { struct t_infolist *ptr_infolist, *next_infolist; - + ptr_infolist = weechat_infolists; while (ptr_infolist) { @@ -674,7 +674,7 @@ infolist_print_log () struct t_infolist *ptr_infolist; struct t_infolist_item *ptr_item; struct t_infolist_var *ptr_var; - + for (ptr_infolist = weechat_infolists; ptr_infolist; ptr_infolist = ptr_infolist->next_infolist) { @@ -686,7 +686,7 @@ infolist_print_log () log_printf (" ptr_item . . . . . . . : 0x%lx", ptr_infolist->ptr_item); log_printf (" prev_infolist. . . . . : 0x%lx", ptr_infolist->prev_infolist); log_printf (" next_infolist. . . . . : 0x%lx", ptr_infolist->next_infolist); - + for (ptr_item = ptr_infolist->items; ptr_item; ptr_item = ptr_item->next_item) { @@ -696,7 +696,7 @@ infolist_print_log () log_printf (" last_var . . . . . . . : 0x%lx", ptr_item->last_var); log_printf (" prev_item. . . . . . . : 0x%lx", ptr_item->prev_item); log_printf (" next_item. . . . . . . : 0x%lx", ptr_item->next_item); - + for (ptr_var = ptr_item->vars; ptr_var; ptr_var = ptr_var->next_var) { diff --git a/src/core/wee-input.c b/src/core/wee-input.c index d803002d4..bb9aecfdd 100644 --- a/src/core/wee-input.c +++ b/src/core/wee-input.c @@ -71,17 +71,17 @@ input_exec_command (struct t_gui_buffer *buffer, { int rc; char *command, *pos, *ptr_args; - + if ((!string) || (!string[0])) return; - + command = strdup (string); if (!command) return ; - + /* look for end of command */ ptr_args = NULL; - + pos = &command[strlen (command) - 1]; if (pos[0] == ' ') { @@ -89,9 +89,9 @@ input_exec_command (struct t_gui_buffer *buffer, pos--; pos[1] = '\0'; } - + rc = hook_command_exec (buffer, any_plugin, plugin, command); - + pos = strchr (command, ' '); if (pos) { @@ -103,7 +103,7 @@ input_exec_command (struct t_gui_buffer *buffer, if (!ptr_args[0]) ptr_args = NULL; } - + switch (rc) { case 0: /* command hooked, KO */ @@ -161,10 +161,10 @@ input_data (struct t_gui_buffer *buffer, const char *data) char *pos, *buf; const char *ptr_data, *ptr_data_for_buffer; int length, char_size; - + if (!buffer || !data || !data[0] || (data[0] == '\r') || (data[0] == '\n')) return; - + /* use new data (returned by plugin) */ ptr_data = data; while (ptr_data && ptr_data[0]) @@ -172,7 +172,7 @@ input_data (struct t_gui_buffer *buffer, const char *data) pos = strchr (ptr_data, '\n'); if (pos) pos[0] = '\0'; - + ptr_data_for_buffer = string_input_for_buffer (ptr_data); if (ptr_data_for_buffer) { @@ -202,7 +202,7 @@ input_data (struct t_gui_buffer *buffer, const char *data) /* input string is a command */ input_exec_command (buffer, 1, buffer->plugin, ptr_data); } - + if (pos) { pos[0] = '\n'; diff --git a/src/core/wee-list.c b/src/core/wee-list.c index 948b3acdd..889faeb7a 100644 --- a/src/core/wee-list.c +++ b/src/core/wee-list.c @@ -64,7 +64,7 @@ weelist_find_pos (struct t_weelist *weelist, const char *data) if (!weelist || !data) return NULL; - + for (ptr_item = weelist->items; ptr_item; ptr_item = ptr_item->next_item) { @@ -87,7 +87,7 @@ weelist_insert (struct t_weelist *weelist, struct t_weelist_item *item, if (!weelist || !item) return; - + if (weelist->items) { /* remove element if already in list */ @@ -106,7 +106,7 @@ weelist_insert (struct t_weelist *weelist, struct t_weelist_item *item, pos_item = NULL; else pos_item = weelist_find_pos (weelist, item->data); - + if (pos_item) { /* insert data into the list (before position found) */ @@ -145,10 +145,10 @@ weelist_add (struct t_weelist *weelist, const char *data, const char *where, void *user_data) { struct t_weelist_item *new_item; - + if (!weelist || !data || !data[0] || !where || !where[0]) return NULL; - + new_item = malloc (sizeof (*new_item)); if (new_item) { @@ -171,7 +171,7 @@ weelist_search (struct t_weelist *weelist, const char *data) if (!weelist || !data) return NULL; - + for (ptr_item = weelist->items; ptr_item; ptr_item = ptr_item->next_item) { @@ -192,7 +192,7 @@ weelist_search_pos (struct t_weelist *weelist, const char *data) { struct t_weelist_item *ptr_item; int i; - + if (!weelist || !data) return -1; @@ -219,7 +219,7 @@ weelist_casesearch (struct t_weelist *weelist, const char *data) if (!weelist || !data) return NULL; - + for (ptr_item = weelist->items; ptr_item; ptr_item = ptr_item->next_item) { @@ -240,10 +240,10 @@ weelist_casesearch_pos (struct t_weelist *weelist, const char *data) { struct t_weelist_item *ptr_item; int i; - + if (!weelist || !data) return -1; - + for (ptr_item = weelist->items; ptr_item; ptr_item = ptr_item->next_item) { @@ -267,7 +267,7 @@ weelist_get (struct t_weelist *weelist, int position) if (!weelist) return NULL; - + i = 0; ptr_item = weelist->items; while (ptr_item) @@ -305,7 +305,7 @@ weelist_next (struct t_weelist_item *item) { if (item) return item->next_item; - + return NULL; } @@ -318,7 +318,7 @@ weelist_prev (struct t_weelist_item *item) { if (item) return item->prev_item; - + return NULL; } @@ -331,7 +331,7 @@ weelist_string (struct t_weelist_item *item) { if (item) return item->data; - + return NULL; } @@ -344,7 +344,7 @@ weelist_size (struct t_weelist *weelist) { if (weelist) return weelist->size; - + return 0; } @@ -356,10 +356,10 @@ void weelist_remove (struct t_weelist *weelist, struct t_weelist_item *item) { struct t_weelist_item *new_items; - + if (!weelist || !item) return; - + /* remove item from list */ if (weelist->last_item == item) weelist->last_item = item->prev_item; @@ -370,16 +370,16 @@ weelist_remove (struct t_weelist *weelist, struct t_weelist_item *item) } else new_items = item->next_item; - + if (item->next_item) (item->next_item)->prev_item = item->prev_item; - + /* free data */ if (item->data) free (item->data); free (item); weelist->items = new_items; - + weelist->size--; } @@ -392,7 +392,7 @@ weelist_remove_all (struct t_weelist *weelist) { if (!weelist) return; - + while (weelist->items) { weelist_remove (weelist, weelist->items); @@ -408,7 +408,7 @@ weelist_free (struct t_weelist *weelist) { if (!weelist) return; - + weelist_remove_all (weelist); free (weelist); } @@ -421,9 +421,9 @@ void weelist_print_log (struct t_weelist *weelist, const char *name) { struct t_weelist_item *ptr_item; - + log_printf ("[weelist %s (addr:0x%lx)]", name, weelist); - + for (ptr_item = weelist->items; ptr_item; ptr_item = ptr_item->next_item) { diff --git a/src/core/wee-log.c b/src/core/wee-log.c index 97f5347bc..c6adceb15 100644 --- a/src/core/wee-log.c +++ b/src/core/wee-log.c @@ -74,7 +74,7 @@ log_open (const char *filename, const char *mode) snprintf (weechat_log_filename, filename_length, "%s/%s", weechat_home, WEECHAT_LOG_NAME); } - + weechat_log_file = fopen (weechat_log_filename, mode); if (!weechat_log_file) { @@ -129,10 +129,10 @@ log_printf (const char *message, ...) char *ptr_buffer; static time_t seconds; struct tm *date_tmp; - + if (!weechat_log_file) return; - + weechat_va_format (message); if (vbuffer) { @@ -146,7 +146,7 @@ log_printf (const char *message, ...) ptr_buffer[0] = '.'; ptr_buffer++; } - + if (!weechat_log_use_time) string_iconv_fprintf (weechat_log_file, "%s\n", vbuffer); else @@ -163,9 +163,9 @@ log_printf (const char *message, ...) else string_iconv_fprintf (weechat_log_file, "%s\n", vbuffer); } - + fflush (weechat_log_file); - + free (vbuffer); } } @@ -179,7 +179,7 @@ log_printf_hexa (const char *spaces, const char *string) { int msg_pos, hexa_pos, ascii_pos; char hexa[(16 * 3) + 1], ascii[(16 * 2) + 1]; - + msg_pos = 0; hexa_pos = 0; ascii_pos = 0; @@ -243,13 +243,13 @@ log_crash_rename () if (!weechat_log_filename) return 0; - + old_name = strdup (weechat_log_filename); if (!old_name) return 0; log_close (); - + length = strlen (weechat_home) + 128; new_name = malloc (length); if (new_name) diff --git a/src/core/wee-network.c b/src/core/wee-network.c index e226c57b6..c381d988c 100644 --- a/src/core/wee-network.c +++ b/src/core/wee-network.c @@ -71,7 +71,7 @@ network_set_gnutls_ca_file () { #ifdef HAVE_GNUTLS char *ca_path, *ca_path2; - + ca_path = string_expand_home (CONFIG_STRING(config_network_gnutls_ca_file)); if (ca_path) { @@ -97,7 +97,7 @@ network_init () #ifdef HAVE_GNUTLS gnutls_global_init (); gnutls_certificate_allocate_credentials (&gnutls_xcred); - + network_set_gnutls_ca_file (); #if LIBGNUTLS_VERSION_NUMBER >= 0x02090a /* for gnutls >= 2.9.10 */ @@ -152,7 +152,7 @@ network_pass_httpproxy (struct t_proxy *proxy, int sock, const char *address, { char buffer[256], authbuf[128], authbuf_base64[512]; int n, m; - + if (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]) && CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])[0]) { @@ -172,20 +172,20 @@ network_pass_httpproxy (struct t_proxy *proxy, int sock, const char *address, n = snprintf (buffer, sizeof (buffer), "CONNECT %s:%d HTTP/1.0\r\n\r\n", address, port); } - + m = send (sock, buffer, n, 0); if (n != m) return 0; - + n = recv (sock, buffer, sizeof (buffer), 0); - + /* success result must be like: "HTTP/1.0 200 OK" */ if (n < 12) return 0; - + if (memcmp (buffer, "HTTP/", 5) || memcmp (buffer + 9, "200", 3)) return 0; - + /* connection ok */ return 1; } @@ -202,34 +202,34 @@ network_resolve (const char *hostname, char *ip, int *version) { char ipbuffer[NI_MAXHOST]; struct addrinfo *res; - + if (version != NULL) *version = 0; - + res = NULL; - + if (getaddrinfo (hostname, NULL, NULL, &res) != 0) return 0; - + if (!res) return 0; - + if (getnameinfo (res->ai_addr, res->ai_addrlen, ipbuffer, sizeof(ipbuffer), NULL, 0, NI_NUMERICHOST) != 0) { freeaddrinfo (res); return 0; } - + if ((res->ai_family == AF_INET) && (version != NULL)) *version = 4; if ((res->ai_family == AF_INET6) && (version != NULL)) *version = 6; - + strcpy (ip, ipbuffer); - + freeaddrinfo (res); - + /* resolution ok */ return 1; } @@ -246,11 +246,11 @@ network_pass_socks4proxy (struct t_proxy *proxy, int sock, const char *address, int port) { /* socks4 protocol is explained here: http://en.wikipedia.org/wiki/SOCKS */ - + struct t_network_socks4 socks4; unsigned char buffer[24]; char ip_addr[NI_MAXHOST]; - + socks4.version = 4; socks4.method = 1; socks4.port = htons (port); @@ -258,14 +258,14 @@ network_pass_socks4proxy (struct t_proxy *proxy, int sock, const char *address, socks4.address = inet_addr (ip_addr); strncpy (socks4.user, CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]), sizeof (socks4.user) - 1); - + send (sock, (char *) &socks4, 8 + strlen (socks4.user) + 1, 0); recv (sock, buffer, sizeof (buffer), 0); - + /* connection ok */ if ((buffer[0] == 0) && (buffer[1] == 90)) return 1; - + /* connection failed */ return 0; } @@ -285,26 +285,26 @@ network_pass_socks5proxy (struct t_proxy *proxy, int sock, const char *address, * socks5 protocol is explained in RFC 1928 * socks5 authentication with username/pass is explained in RFC 1929 */ - + struct t_network_socks5 socks5; unsigned char buffer[288]; int username_len, password_len, addr_len, addr_buffer_len; unsigned char *addr_buffer; - + socks5.version = 5; socks5.nmethods = 1; - + if (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]) && CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])[0]) socks5.method = 2; /* with authentication */ else socks5.method = 0; /* without authentication */ - + send (sock, (char *) &socks5, sizeof(socks5), 0); /* server socks5 must respond with 2 bytes */ if (recv (sock, buffer, 2, 0) != 2) return 0; - + if (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME]) && CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])[0]) { @@ -314,14 +314,14 @@ network_pass_socks5proxy (struct t_proxy *proxy, int sock, const char *address, * - socks version (buffer[0]) = 5 => socks5 * - socks method (buffer[1]) = 2 => authentication */ - + if (buffer[0] != 5 || buffer[1] != 2) return 0; - + /* authentication as in RFC 1929 */ username_len = strlen (CONFIG_STRING(proxy->options[PROXY_OPTION_USERNAME])); password_len = strlen (CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD])); - + /* make username/password buffer */ buffer[0] = 1; buffer[1] = (unsigned char) username_len; @@ -329,13 +329,13 @@ network_pass_socks5proxy (struct t_proxy *proxy, int sock, const char *address, buffer[2 + username_len] = (unsigned char) password_len; memcpy (buffer + 3 + username_len, CONFIG_STRING(proxy->options[PROXY_OPTION_PASSWORD]), password_len); - + send (sock, buffer, 3 + username_len + password_len, 0); - + /* server socks5 must respond with 2 bytes */ if (recv (sock, buffer, 2, 0) != 2) return 0; - + /* buffer[1] = auth state, must be 0 for success */ if (buffer[1] != 0) return 0; @@ -351,7 +351,7 @@ network_pass_socks5proxy (struct t_proxy *proxy, int sock, const char *address, if (!((buffer[0] == 5) && (buffer[1] == 0))) return 0; } - + /* authentication successful then giving address/port to connect */ addr_len = strlen(address); addr_buffer_len = 4 + 1 + addr_len + 2; @@ -365,17 +365,17 @@ network_pass_socks5proxy (struct t_proxy *proxy, int sock, const char *address, addr_buffer[4] = (unsigned char) addr_len; memcpy (addr_buffer + 5, address, addr_len); /* server address */ *((unsigned short *) (addr_buffer + 5 + addr_len)) = htons (port); /* server port */ - + send (sock, addr_buffer, addr_buffer_len, 0); free (addr_buffer); - + /* dialog with proxy server */ if (recv (sock, buffer, 4, 0) != 4) return 0; - + if (!((buffer[0] == 5) && (buffer[1] == 0))) return 0; - + /* buffer[3] = address type */ switch (buffer[3]) { @@ -413,7 +413,7 @@ network_pass_socks5proxy (struct t_proxy *proxy, int sock, const char *address, default: return 0; } - + /* connection ok */ return 1; } @@ -429,9 +429,9 @@ network_pass_proxy (const char *proxy, int sock, const char *address, int port) { int rc; struct t_proxy *ptr_proxy; - + rc = 0; - + ptr_proxy = proxy_search (proxy); if (ptr_proxy) { @@ -466,7 +466,7 @@ network_connect_to (const char *proxy, int sock, struct hostent *hostent; char *ip4; int ret; - + ptr_proxy = NULL; if (proxy && proxy[0]) { @@ -474,13 +474,13 @@ network_connect_to (const char *proxy, int sock, if (!ptr_proxy) return 0; } - + if (ptr_proxy) { memset (&addr, 0, sizeof (addr)); addr.sin_addr.s_addr = htonl (address); ip4 = inet_ntoa(addr.sin_addr); - + memset (&addr, 0, sizeof (addr)); addr.sin_port = htons (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT])); addr.sin_family = AF_INET; @@ -520,12 +520,12 @@ network_connect_child (struct t_hook *hook_connect) char ipv4_address[INET_ADDRSTRLEN + 1], ipv6_address[INET6_ADDRSTRLEN + 1]; char status_ok_without_address[1 + 5 + 1]; int rc, length, num_written; - + res = NULL; res_local = NULL; - + status_str[1] = '\0'; - + ptr_proxy = NULL; if (HOOK_CONNECT(hook_connect, proxy) && HOOK_CONNECT(hook_connect, proxy)[0]) @@ -541,7 +541,7 @@ network_connect_child (struct t_hook *hook_connect) return; } } - + if (ptr_proxy) { /* get info about peer */ @@ -578,12 +578,12 @@ network_connect_child (struct t_hook *hook_connect) freeaddrinfo (res); return; } - + if (CONFIG_BOOLEAN(ptr_proxy->options[PROXY_OPTION_IPV6])) ((struct sockaddr_in6 *)(res->ai_addr))->sin6_port = htons (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT])); else ((struct sockaddr_in *)(res->ai_addr))->sin_port = htons (CONFIG_INTEGER(ptr_proxy->options[PROXY_OPTION_PORT])); - + /* connect to peer */ if (connect (HOOK_CONNECT(hook_connect, sock), res->ai_addr, res->ai_addrlen) != 0) @@ -596,7 +596,7 @@ network_connect_child (struct t_hook *hook_connect) freeaddrinfo (res); return; } - + if (!network_pass_proxy (HOOK_CONNECT(hook_connect, proxy), HOOK_CONNECT(hook_connect, sock), HOOK_CONNECT(hook_connect, address), @@ -652,7 +652,7 @@ network_connect_child (struct t_hook *hook_connect) return; } } - + /* get info about peer */ memset (&hints, 0, sizeof(hints)); hints.ai_family = (HOOK_CONNECT(hook_connect, ipv6)) ? AF_INET6 : AF_INET; @@ -672,9 +672,9 @@ network_connect_child (struct t_hook *hook_connect) freeaddrinfo (res_local); return; } - + status_str[0] = '0' + WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND; - + /* try all IP addresses found, stop when connection is ok */ for (ptr_res = res; ptr_res; ptr_res = ptr_res->ai_next) { @@ -682,7 +682,7 @@ network_connect_child (struct t_hook *hook_connect) if ((HOOK_CONNECT(hook_connect, ipv6) && (ptr_res->ai_family != AF_INET6)) || ((!HOOK_CONNECT(hook_connect, ipv6) && (ptr_res->ai_family != AF_INET)))) continue; - + /* connect to peer */ if (HOOK_CONNECT(hook_connect, ipv6)) ((struct sockaddr_in6 *)(ptr_res->ai_addr))->sin6_port = @@ -690,7 +690,7 @@ network_connect_child (struct t_hook *hook_connect) else ((struct sockaddr_in *)(ptr_res->ai_addr))->sin_port = htons (HOOK_CONNECT(hook_connect, port)); - + if (connect (HOOK_CONNECT(hook_connect, sock), ptr_res->ai_addr, ptr_res->ai_addrlen) == 0) { @@ -701,7 +701,7 @@ network_connect_child (struct t_hook *hook_connect) status_str[0] = '0' + WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED; } } - + if (status_str[0] == '0' + WEECHAT_HOOK_CONNECT_OK) { status_ok_with_address = NULL; @@ -736,7 +736,7 @@ network_connect_child (struct t_hook *hook_connect) status_str, (int)strlen (ptr_address), ptr_address); } } - + if (status_ok_with_address) { num_written = write (HOOK_CONNECT(hook_connect, child_write), @@ -759,7 +759,7 @@ network_connect_child (struct t_hook *hook_connect) status_str, 1); (void) num_written; } - + if (res) freeaddrinfo (res); if (res_local) @@ -778,14 +778,14 @@ network_connect_gnutls_handshake_fd_cb (void *arg_hook_connect, int fd) { struct t_hook *hook_connect; int rc, direction, flags; - + /* make C compiler happy */ (void) fd; - + hook_connect = (struct t_hook *)arg_hook_connect; - + rc = gnutls_handshake (*HOOK_CONNECT(hook_connect, gnutls_sess)); - + if ((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED)) { direction = gnutls_record_get_direction (*HOOK_CONNECT(hook_connect, gnutls_sess)); @@ -837,7 +837,7 @@ network_connect_gnutls_handshake_fd_cb (void *arg_hook_connect, int fd) HOOK_CONNECT(hook_connect, handshake_ip_address)); unhook (hook_connect); } - + return WEECHAT_RC_OK; } #endif @@ -852,14 +852,14 @@ network_connect_gnutls_handshake_timer_cb (void *arg_hook_connect, int remaining_calls) { struct t_hook *hook_connect; - + /* make C compiler happy */ (void) remaining_calls; - + hook_connect = (struct t_hook *)arg_hook_connect; - + HOOK_CONNECT(hook_connect, handshake_hook_timer) = NULL; - + (void) (HOOK_CONNECT(hook_connect, callback)) (hook_connect->callback_data, WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR, @@ -867,7 +867,7 @@ network_connect_gnutls_handshake_timer_cb (void *arg_hook_connect, gnutls_strerror (GNUTLS_E_EXPIRED), HOOK_CONNECT(hook_connect, handshake_ip_address)); unhook (hook_connect); - + return WEECHAT_RC_OK; } #endif @@ -889,11 +889,11 @@ network_connect_child_read_cb (void *arg_hook_connect, int fd) /* make C compiler happy */ (void) fd; - + hook_connect = (struct t_hook *)arg_hook_connect; - + ip_address = NULL; - + num_read = read (HOOK_CONNECT(hook_connect, child_read), buffer, sizeof (buffer)); if (num_read > 0) @@ -1011,10 +1011,10 @@ network_connect_child_read_cb (void *arg_hook_connect, int fd) (hook_connect->callback_data, buffer[0] - '0', 0, NULL, ip_address); unhook (hook_connect); } - + if (ip_address) free (ip_address); - + return WEECHAT_RC_OK; } @@ -1031,7 +1031,7 @@ network_connect_with_fork (struct t_hook *hook_connect) const char *pos_error; #endif pid_t pid; - + #ifdef HAVE_GNUTLS /* initialize GnuTLS if SSL asked */ if (HOOK_CONNECT(hook_connect, gnutls_sess)) @@ -1064,7 +1064,7 @@ network_connect_with_fork (struct t_hook *hook_connect) (gnutls_transport_ptr) ((unsigned long) HOOK_CONNECT(hook_connect, sock))); } #endif - + /* create pipe for child process */ if (pipe (child_pipe) < 0) { @@ -1077,7 +1077,7 @@ network_connect_with_fork (struct t_hook *hook_connect) } HOOK_CONNECT(hook_connect, child_read) = child_pipe[0]; HOOK_CONNECT(hook_connect, child_write) = child_pipe[1]; - + switch (pid = fork ()) { /* fork failed */ diff --git a/src/core/wee-proxy.c b/src/core/wee-proxy.c index 7e3406d17..26a263f67 100644 --- a/src/core/wee-proxy.c +++ b/src/core/wee-proxy.c @@ -59,16 +59,16 @@ int proxy_search_option (const char *option_name) { int i; - + if (!option_name) return -1; - + for (i = 0; i < PROXY_NUM_OPTIONS; i++) { if (string_strcasecmp (proxy_option_string[i], option_name) == 0) return i; } - + /* proxy option not found */ return -1; } @@ -82,16 +82,16 @@ int proxy_search_type (const char *type) { int i; - + if (!type) return -1; - + for (i = 0; i < PROXY_NUM_TYPES; i++) { if (string_strcasecmp (proxy_type_string[i], type) == 0) return i; } - + /* type not found */ return -1; } @@ -104,17 +104,17 @@ struct t_proxy * proxy_search (const char *name) { struct t_proxy *ptr_proxy; - + if (!name || !name[0]) return NULL; - + for (ptr_proxy = weechat_proxies; ptr_proxy; ptr_proxy = ptr_proxy->next_proxy) { if (strcmp (ptr_proxy->name, name) == 0) return ptr_proxy; } - + /* proxy not found */ return NULL; } @@ -129,9 +129,9 @@ proxy_search_with_option_name (const char *option_name) { char *proxy_name, *pos_option; struct t_proxy *ptr_proxy; - + ptr_proxy = NULL; - + pos_option = strchr (option_name, '.'); if (pos_option) { @@ -147,7 +147,7 @@ proxy_search_with_option_name (const char *option_name) free (proxy_name); } } - + return ptr_proxy; } @@ -160,10 +160,10 @@ proxy_set_name (struct t_proxy *proxy, const char *name) { int length; char *option_name; - + if (!name || !name[0]) return; - + length = strlen (name) + 64; option_name = malloc (length); if (option_name) @@ -180,11 +180,11 @@ proxy_set_name (struct t_proxy *proxy, const char *name) config_file_option_rename (proxy->options[PROXY_OPTION_USERNAME], option_name); snprintf (option_name, length, "%s.password", name); config_file_option_rename (proxy->options[PROXY_OPTION_PASSWORD], option_name); - + if (proxy->name) free (proxy->name); proxy->name = strdup (name); - + free (option_name); } } @@ -199,7 +199,7 @@ proxy_set (struct t_proxy *proxy, const char *property, const char *value) { if (!proxy || !property || !value) return 0; - + if (string_strcasecmp (property, "name") == 0) { proxy_set_name (proxy, value); @@ -235,7 +235,7 @@ proxy_set (struct t_proxy *proxy, const char *property, const char *value) config_file_option_set (proxy->options[PROXY_OPTION_PASSWORD], value, 1); return 1; } - + return 0; } @@ -250,9 +250,9 @@ proxy_create_option (const char *proxy_name, int index_option, struct t_config_option *ptr_option; int length; char *option_name; - + ptr_option = NULL; - + length = strlen (proxy_name) + 1 + strlen (proxy_option_string[index_option]) + 1; option_name = malloc (length); @@ -260,7 +260,7 @@ proxy_create_option (const char *proxy_name, int index_option, { snprintf (option_name, length, "%s.%s", proxy_name, proxy_option_string[index_option]); - + switch (index_option) { case PROXY_OPTION_TYPE: @@ -316,7 +316,7 @@ proxy_create_option (const char *proxy_name, int index_option, } free (option_name); } - + return ptr_option; } @@ -330,7 +330,7 @@ proxy_create_option_temp (struct t_proxy *temp_proxy, int index_option, const char *value) { struct t_config_option *new_option; - + new_option = proxy_create_option (temp_proxy->name, index_option, value); @@ -347,7 +347,7 @@ proxy_alloc (const char *name) { struct t_proxy *new_proxy; int i; - + new_proxy = malloc (sizeof (*new_proxy)); if (new_proxy) { @@ -359,7 +359,7 @@ proxy_alloc (const char *name) new_proxy->prev_proxy = NULL; new_proxy->next_proxy = NULL; } - + return new_proxy; } @@ -377,7 +377,7 @@ proxy_new_with_options (const char *name, struct t_config_option *password) { struct t_proxy *new_proxy; - + /* create proxy */ new_proxy = proxy_alloc (name); if (new_proxy) @@ -388,7 +388,7 @@ proxy_new_with_options (const char *name, new_proxy->options[PROXY_OPTION_PORT] = port; new_proxy->options[PROXY_OPTION_USERNAME] = username; new_proxy->options[PROXY_OPTION_PASSWORD] = password; - + /* add proxy to proxies list */ new_proxy->prev_proxy = last_weechat_proxy; if (weechat_proxies) @@ -398,7 +398,7 @@ proxy_new_with_options (const char *name, last_weechat_proxy = new_proxy; new_proxy->next_proxy = NULL; } - + return new_proxy; } @@ -414,18 +414,18 @@ proxy_new (const char *name, const char *type, const char *ipv6, struct t_config_option *option_type, *option_ipv6, *option_address; struct t_config_option *option_port, *option_username, *option_password; struct t_proxy *new_proxy; - + if (!name || !name[0]) return NULL; - + /* it's not possible to create 2 proxies with same name */ if (proxy_search (name)) return NULL; - + /* look for type */ if (proxy_search_type (type) < 0) return NULL; - + option_type = proxy_create_option (name, PROXY_OPTION_TYPE, type); option_ipv6 = proxy_create_option (name, PROXY_OPTION_IPV6, @@ -438,7 +438,7 @@ proxy_new (const char *name, const char *type, const char *ipv6, (username) ? username : ""); option_password = proxy_create_option (name, PROXY_OPTION_PASSWORD, (password) ? password : ""); - + new_proxy = proxy_new_with_options (name, option_type, option_ipv6, option_address, option_port, option_username, option_password); @@ -457,7 +457,7 @@ proxy_new (const char *name, const char *type, const char *ipv6, if (option_password) config_file_option_free (option_password); } - + return new_proxy; } @@ -470,7 +470,7 @@ proxy_use_temp_proxies () { struct t_proxy *ptr_temp_proxy, *next_temp_proxy; int i, num_options_ok; - + for (ptr_temp_proxy = weechat_temp_proxies; ptr_temp_proxy; ptr_temp_proxy = ptr_temp_proxy->next_proxy) { @@ -486,7 +486,7 @@ proxy_use_temp_proxies () if (ptr_temp_proxy->options[i]) num_options_ok++; } - + if (num_options_ok == PROXY_NUM_OPTIONS) { proxy_new_with_options (ptr_temp_proxy->name, @@ -509,16 +509,16 @@ proxy_use_temp_proxies () } } } - + /* free all temp proxies */ while (weechat_temp_proxies) { next_temp_proxy = weechat_temp_proxies->next_proxy; - + if (weechat_temp_proxies->name) free (weechat_temp_proxies->name); free (weechat_temp_proxies); - + weechat_temp_proxies = next_temp_proxy; } last_weechat_temp_proxy = NULL; @@ -532,10 +532,10 @@ void proxy_free (struct t_proxy *proxy) { int i; - + if (!proxy) return; - + /* remove proxy from proxies list */ if (proxy->prev_proxy) (proxy->prev_proxy)->next_proxy = proxy->next_proxy; @@ -545,7 +545,7 @@ proxy_free (struct t_proxy *proxy) weechat_proxies = proxy->next_proxy; if (last_weechat_proxy == proxy) last_weechat_proxy = proxy->prev_proxy; - + /* free data */ if (proxy->name) free (proxy->name); @@ -553,7 +553,7 @@ proxy_free (struct t_proxy *proxy) { config_file_option_free (proxy->options[i]); } - + free (proxy); } @@ -578,7 +578,7 @@ void proxy_print_log () { struct t_proxy *ptr_proxy; - + for (ptr_proxy = weechat_proxies; ptr_proxy; ptr_proxy = ptr_proxy->next_proxy) { diff --git a/src/core/wee-proxy.h b/src/core/wee-proxy.h index fd22463d7..b449377c6 100644 --- a/src/core/wee-proxy.h +++ b/src/core/wee-proxy.h @@ -45,7 +45,7 @@ struct t_proxy { char *name; /* proxy name */ struct t_config_option *options[PROXY_NUM_OPTIONS]; - + struct t_proxy *prev_proxy; /* link to previous bar */ struct t_proxy *next_proxy; /* link to next bar */ }; diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 2ffeb583e..ad534cbb6 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -69,17 +69,17 @@ char * string_strndup (const char *string, int length) { char *result; - + if ((int)strlen (string) < length) return strdup (string); - + result = malloc (length + 1); if (!result) return NULL; - + memcpy (result, string, length); result[length] = '\0'; - + return result; } @@ -121,10 +121,10 @@ int string_strcasecmp (const char *string1, const char *string2) { int diff; - + if (!string1 || !string2) return (string1) ? 1 : ((string2) ? -1 : 0); - + while (string1[0] && string2[0]) { diff = utf8_charcasecmp (string1, string2); @@ -134,7 +134,7 @@ string_strcasecmp (const char *string1, const char *string2) string1 = utf8_next_char (string1); string2 = utf8_next_char (string2); } - + return (string1[0]) ? 1 : ((string2[0]) ? -1 : 0); } @@ -147,22 +147,22 @@ int string_strncasecmp (const char *string1, const char *string2, int max) { int count, diff; - + if (!string1 || !string2) return (string1) ? 1 : ((string2) ? -1 : 0); - + count = 0; while ((count < max) && string1[0] && string2[0]) { diff = utf8_charcasecmp (string1, string2); if (diff != 0) return diff; - + string1 = utf8_next_char (string1); string2 = utf8_next_char (string2); count++; } - + if (count >= max) return 0; else @@ -178,14 +178,14 @@ string_strcmp_ignore_chars (const char *string1, const char *string2, const char *chars_ignored, int case_sensitive) { int diff; - + if (!string1 && !string2) return 0; if (!string1 && string2) return -1; if (string1 && !string2) return 1; - + while (string1 && string1[0] && string2 && string2[0]) { /* skip ignored chars */ @@ -205,16 +205,16 @@ string_strcmp_ignore_chars (const char *string1, const char *string2, return -1; if (string1 && string1[0] && (!string2 || !string2[0])) return 1; - + /* look at diff */ diff = (case_sensitive) ? (int)string1[0] - (int)string2[0] : utf8_charcasecmp (string1, string2); if (diff != 0) return diff; - + string1 = utf8_next_char (string1); string2 = utf8_next_char (string2); - + /* skip ignored chars */ while (string1 && string1[0] && strchr (chars_ignored, string1[0])) { @@ -240,20 +240,20 @@ char * string_strcasestr (const char *string, const char *search) { int length_search; - + length_search = utf8_strlen (search); - + if (!string || !search || (length_search == 0)) return NULL; - + while (string[0]) { if (string_strncasecmp (string, search, length_search) == 0) return (char *)string; - + string = utf8_next_char (string); } - + return NULL; } @@ -268,19 +268,19 @@ string_match (const char *string, const char *mask, int case_sensitive) { char last, *mask2; int len_string, len_mask, rc; - + if (!mask || !mask[0]) return 0; - + /* if mask is "*", then any string matches */ if (strcmp (mask, "*") == 0) return 1; - + len_string = strlen (string); len_mask = strlen (mask); - + last = mask[len_mask - 1]; - + /* mask begins with "*" */ if ((mask[0] == '*') && (last != '*')) { @@ -296,7 +296,7 @@ string_match (const char *string, const char *mask, int case_sensitive) /* no match */ return 0; } - + /* mask ends with "*" */ if ((mask[0] != '*') && (last == '*')) { @@ -312,7 +312,7 @@ string_match (const char *string, const char *mask, int case_sensitive) /* no match */ return 0; } - + /* mask begins and ends with "*" */ if ((mask[0] == '*') && (last == '*')) { @@ -331,12 +331,12 @@ string_match (const char *string, const char *mask, int case_sensitive) free (mask2); return rc; } - + /* no "*" at all, compare strings */ if ((case_sensitive && (strcmp (string, mask) == 0)) || (!case_sensitive && (string_strcasecmp (string, mask) == 0))) return 1; - + /* no match */ return 0; } @@ -352,13 +352,13 @@ string_replace (const char *string, const char *search, const char *replace) const char *pos; char *new_string; int length1, length2, length_new, count; - + if (!string || !search || !replace) return NULL; - + length1 = strlen (search); length2 = strlen (replace); - + /* count number of strings to replace */ count = 0; pos = string; @@ -367,19 +367,19 @@ string_replace (const char *string, const char *search, const char *replace) count++; pos += length1; } - + /* easy: no string to replace! */ if (count == 0) return strdup (string); - + /* compute needed memory for new string */ length_new = strlen (string) - (count * length1) + (count * length2) + 1; - + /* allocate new string */ new_string = malloc (length_new); if (!new_string) return strdup (string); - + /* replace all occurrences */ new_string[0] = '\0'; while (string && string[0]) @@ -409,22 +409,22 @@ string_expand_home (const char *path) { char *ptr_home, *str; int length; - + if (!path) return NULL; - + if (!path[0] || (path[0] != '~') || (path[1] != DIR_SEPARATOR_CHAR)) return strdup (path); - + ptr_home = getenv ("HOME"); - + length = strlen (ptr_home) + strlen (path + 1) + 1; str = malloc (length); if (!str) return strdup (path); - + snprintf (str, length, "%s%s", ptr_home, path + 1); - + return str; } @@ -440,7 +440,7 @@ string_remove_quotes (const char *string, const char *quotes) { int length; const char *pos_start, *pos_end; - + if (!string || !quotes) return NULL; @@ -460,14 +460,14 @@ string_remove_quotes (const char *string, const char *quotes) } if (!pos_start[0] || !pos_end[0] || (pos_end <= pos_start)) return strdup (string); - + if (strchr (quotes, pos_start[0]) && (pos_end[0] == pos_start[0])) { if (pos_end == (pos_start + 1)) return strdup (""); return string_strndup (pos_start + 1, pos_end - pos_start - 1); } - + return strdup (string); } @@ -480,16 +480,16 @@ char * string_strip (const char *string, int left, int right, const char *chars) { const char *ptr_start, *ptr_end; - + if (!string) return NULL; - + if (!string[0]) return strdup (string); - + ptr_start = string; ptr_end = string + strlen (string) - 1; - + if (left) { while (ptr_start[0] && strchr (chars, ptr_start[0])) @@ -499,7 +499,7 @@ string_strip (const char *string, int left, int right, const char *chars) if (!ptr_start[0]) return strdup (ptr_start); } - + if (right) { while ((ptr_end >= ptr_start) && strchr (chars, ptr_end[0])) @@ -509,7 +509,7 @@ string_strip (const char *string, int left, int right, const char *chars) if (ptr_end < ptr_start) return strdup (""); } - + return string_strndup (ptr_start, ptr_end - ptr_start + 1); } @@ -581,7 +581,7 @@ string_convert_hex_chars (const char *string) } output[pos_output] = '\0'; } - + return output; } @@ -593,13 +593,13 @@ int string_is_word_char (const char *string) { wint_t c = utf8_wide_char (string); - + if (c == WEOF) return 0; - + if (iswalnum (c)) return 1; - + switch (c) { case '-': @@ -607,7 +607,7 @@ string_is_word_char (const char *string) case '|': return 1; } - + /* not a 'word char' */ return 0; } @@ -623,10 +623,10 @@ string_has_highlight (const char *string, const char *highlight_words) { char *msg, *highlight, *match, *match_pre, *match_post, *msg_pos, *pos, *pos_end; int end, length, startswith, endswith, wildcard_start, wildcard_end; - + if (!string || !string[0] || !highlight_words || !highlight_words[0]) return 0; - + /* convert both strings to lower case */ msg = strdup (string); if (!msg) @@ -639,7 +639,7 @@ string_has_highlight (const char *string, const char *highlight_words) return 0; } string_tolower (highlight); - + pos = highlight; end = 0; while (!end) @@ -657,7 +657,7 @@ string_has_highlight (const char *string, const char *highlight_words) free (highlight); return 0; } - + length = pos_end - pos; pos_end[0] = '\0'; if (length > 0) @@ -673,7 +673,7 @@ string_has_highlight (const char *string, const char *highlight_words) length--; } } - + if (length > 0) { msg_pos = msg; @@ -699,14 +699,14 @@ string_has_highlight (const char *string, const char *highlight_words) msg_pos = match_post; } } - + if (!end) pos = pos_end + 1; } - + free (msg); free (highlight); - + /* no highlight found */ return 0; } @@ -724,16 +724,16 @@ string_has_highlight_regex_compiled (const char *string, regex_t *regex) int rc, startswith, endswith; regmatch_t regex_match; const char *match_pre; - + if (!string || !regex) return 0; - + while (string && string[0]) { rc = regexec (regex, string, 1, ®ex_match, 0); if ((rc != 0) || (regex_match.rm_so < 0) || (regex_match.rm_eo < 0)) break; - + startswith = (regex_match.rm_so == 0); if (!startswith) { @@ -748,10 +748,10 @@ string_has_highlight_regex_compiled (const char *string, regex_t *regex) } if (startswith && endswith) return 1; - + string += regex_match.rm_eo; } - + /* no highlight found */ return 0; } @@ -767,17 +767,17 @@ string_has_highlight_regex (const char *string, const char *regex) { regex_t reg; int rc; - + if (!string || !regex || !regex[0]) return 0; - + if (regcomp (®, regex, REG_EXTENDED) != 0) return 0; - + rc = string_has_highlight_regex_compiled (string, ®); - + regfree (®); - + return rc; } @@ -793,14 +793,14 @@ string_mask_to_regex (const char *mask) const char *ptr_mask; int index_result; char *regex_special_char = ".[]{}()?+"; - + if (!mask) return NULL; - + result = malloc ((strlen (mask) * 2) + 1); if (!result) return NULL; - + result[0] = '\0'; index_result = 0; ptr_mask = mask; @@ -821,13 +821,13 @@ string_mask_to_regex (const char *mask) /* standard char, just copy it */ else result[index_result++] = ptr_mask[0]; - + ptr_mask++; } - + /* add final '\0' */ result[index_result] = '\0'; - + return result; } @@ -853,17 +853,17 @@ string_split (const char *string, const char *separators, int keep_eol, int i, j, n_items; char *string2, **array; char *ptr, *ptr1, *ptr2; - + if (num_items != NULL) *num_items = 0; - + if (!string || !string[0] || !separators || !separators[0]) return NULL; - + string2 = string_strip (string, 1, (keep_eol == 2) ? 0 : 1, separators); if (!string2 || !string2[0]) return NULL; - + /* calculate number of items */ ptr = string2; i = 1; @@ -876,16 +876,16 @@ string_split (const char *string, const char *separators, int keep_eol, i++; } n_items = i; - + if ((num_items_max != 0) && (n_items > num_items_max)) n_items = num_items_max; - + array = malloc ((n_items + 1) * sizeof (array[0])); if (!array) return NULL; - + ptr1 = string2; - + for (i = 0; i < n_items; i++) { while (ptr1[0] && (strchr (separators, ptr1[0]) != NULL)) @@ -911,7 +911,7 @@ string_split (const char *string, const char *separators, int keep_eol, } } } - + if ((ptr1 == NULL) || (ptr2 == NULL)) { array[i] = NULL; @@ -960,13 +960,13 @@ string_split (const char *string, const char *separators, int keep_eol, } } } - + array[i] = NULL; if (num_items != NULL) *num_items = i; - + free (string2); - + return array; } @@ -978,7 +978,7 @@ void string_free_split (char **split_string) { int i; - + if (split_string) { for (i = 0; split_string[i]; i++) @@ -999,23 +999,23 @@ string_build_with_split_string (const char **split_string, { int i, length, length_separator; char *result; - + if (!split_string) return NULL; - + length = 0; length_separator = (separator) ? strlen (separator) : 0; - + for (i = 0; split_string[i]; i++) { length += strlen (split_string[i]) + length_separator; } - + result = malloc (length + 1); if (result) { result[0] = '\0'; - + for (i = 0; split_string[i]; i++) { strcat (result, split_string[i]); @@ -1023,7 +1023,7 @@ string_build_with_split_string (const char **split_string, strcat (result, separator); } } - + return result; } @@ -1045,7 +1045,7 @@ string_split_command (const char *command, char separator) if (!command || !command[0]) return NULL; - + nb_substr = 1; ptr = command; while ( (p = strchr(ptr, separator)) != NULL) @@ -1057,14 +1057,14 @@ string_split_command (const char *command, char separator) array = malloc ((nb_substr + 1) * sizeof (array[0])); if (!array) return NULL; - + buffer = malloc (strlen(command) + 1); if (!buffer) { free (array); return NULL; } - + ptr = command; str_idx = 0; arr_idx = 0; @@ -1097,17 +1097,17 @@ string_split_command (const char *command, char separator) str_idx++; ptr++; } - + buffer[str_idx] = '\0'; p = buffer; while (*p == ' ') p++; if (p && p[0]) array[arr_idx++] = strdup (p); - + array[arr_idx] = NULL; - + free (buffer); - + array2 = realloc (array, (arr_idx + 1) * sizeof(array[0])); if (!array2) { @@ -1115,7 +1115,7 @@ string_split_command (const char *command, char separator) free (array); return NULL; } - + return array2; } @@ -1147,14 +1147,14 @@ string_iconv (int from_utf8, const char *from_code, const char *to_code, const char *string) { char *outbuf; - + #ifdef HAVE_ICONV iconv_t cd; char *inbuf, *ptr_inbuf, *ptr_outbuf, *next_char; char *ptr_inbuf_shift; int done; size_t err, inbytesleft, outbytesleft; - + if (from_code && from_code[0] && to_code && to_code[0] && (string_strcasecmp(from_code, to_code) != 0)) { @@ -1243,7 +1243,7 @@ string_iconv (int from_utf8, const char *from_code, const char *to_code, (void) to_code; outbuf = strdup (string); #endif /* HAVE_ICONV */ - + return outbuf; } @@ -1257,24 +1257,24 @@ char * string_iconv_to_internal (const char *charset, const char *string) { char *input, *output; - + if (!string) return NULL; - + input = strdup (string); if (!input) return NULL; - + /* * optimized for UTF-8: if charset is NULL => we use term charset => if * this charset is already UTF-8, then no iconv is needed */ if (local_utf8 && (!charset || !charset[0])) return input; - + if (utf8_has_8bits (input) && utf8_is_valid (input, NULL)) return input; - + output = string_iconv (0, (charset && charset[0]) ? charset : weechat_local_charset, @@ -1297,21 +1297,21 @@ char * string_iconv_from_internal (const char *charset, const char *string) { char *input, *output; - + if (!string) return NULL; - + input = strdup (string); if (!input) return NULL; - + /* * optimized for UTF-8: if charset is NULL => we use term charset => if * this charset is already UTF-8, then no iconv needed */ if (local_utf8 && (!charset || !charset[0])) return input; - + utf8_normalize (input, '?'); output = string_iconv (1, WEECHAT_INTERNAL_CHARSET, @@ -1334,7 +1334,7 @@ string_iconv_fprintf (FILE *file, const char *data, ...) { char *buf2; int rc, num_written; - + rc = 0; weechat_va_format (data); if (vbuffer) @@ -1346,7 +1346,7 @@ string_iconv_fprintf (FILE *file, const char *data, ...) free (buf2); free (vbuffer); } - + return rc; } @@ -1363,9 +1363,9 @@ string_format_size (unsigned long long size) float unit_divide[] = { 1, 1024, 1024*1024, 1024*1024*1024 }; char format_size[128], str_size[128]; int num_unit; - + str_size[0] = '\0'; - + if (size < 1024*10) num_unit = 0; else if (size < 1024*1024) @@ -1374,7 +1374,7 @@ string_format_size (unsigned long long size) num_unit = 2; else num_unit = 3; - + snprintf (format_size, sizeof (format_size), "%s %%s", unit_format[num_unit]); @@ -1382,7 +1382,7 @@ string_format_size (unsigned long long size) format_size, ((float)size) / ((float)(unit_divide[num_unit])), (size <= 1) ? _("byte") : _(unit_name[num_unit])); - + return strdup (str_size); } @@ -1395,7 +1395,7 @@ string_convbase64_8x3_to_6x4 (const char *from, char *to) { unsigned char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz0123456789+/"; - + to[0] = base64_table [ (from[0] & 0xfc) >> 2 ]; to[1] = base64_table [ ((from[0] & 0x03) << 4) + ((from[1] & 0xf0) >> 4) ]; to[2] = base64_table [ ((from[1] & 0x0f) << 2) + ((from[2] & 0xc0) >> 6) ]; @@ -1413,10 +1413,10 @@ string_encode_base64 (const char *from, int length, char *to) { const char *ptr_from; char *ptr_to; - + ptr_from = from; ptr_to = to; - + while (length >= 3) { string_convbase64_8x3_to_6x4 (ptr_from, ptr_to); @@ -1424,7 +1424,7 @@ string_encode_base64 (const char *from, int length, char *to) ptr_to += 4 * sizeof (*ptr_to); length -= 3; } - + if (length > 0) { char rest[3] = { 0, 0, 0 }; @@ -1475,13 +1475,13 @@ string_decode_base64 (const char *from, char *to) unsigned char c, in[4], out[3]; unsigned char base64_table[]="|$$$}rstuvwxyz{$$$$$$$>?" "@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq"; - + ptr_from = from; ptr_to = to; - + ptr_to[0] = '\0'; to_length = 0; - + while (ptr_from && ptr_from[0]) { length = 0; @@ -1519,9 +1519,9 @@ string_decode_base64 (const char *from, char *to) } } } - + ptr_to[0] = '\0'; - + return to_length; } @@ -1534,24 +1534,24 @@ int string_is_command_char (const char *string) { const char *ptr_command_chars; - + if (!string) return 0; - + if (string[0] == '/') return 1; - + ptr_command_chars = CONFIG_STRING(config_look_command_chars); if (!ptr_command_chars || !ptr_command_chars[0]) return 0; - + while (ptr_command_chars && ptr_command_chars[0]) { if (utf8_charcmp (ptr_command_chars, string) == 0) return 1; ptr_command_chars = utf8_next_char (ptr_command_chars); } - + return 0; } @@ -1566,11 +1566,11 @@ const char * string_input_for_buffer (const char *string) { char *pos_slash, *pos_space, *next_char; - + /* special case for C comments pasted in input line */ if (strncmp (string, "/*", 2) == 0) return string; - + /* * special case if string starts with '/': to allow to paste a path line * "/path/to/file.txt", we check if next '/' is after a space or not @@ -1579,28 +1579,28 @@ string_input_for_buffer (const char *string) { pos_slash = strchr (string + 1, '/'); pos_space = strchr (string + 1, ' '); - + /* * if there's no other '/' of if '/' is after first space, * then it is a command, and return NULL */ if (!pos_slash || (pos_space && pos_slash > pos_space)) return NULL; - + return (string[1] == '/') ? string + 1 : string; } - + /* if string does not start with a command char, then it's not command */ if (!string_is_command_char (string)) return string; - + /* check if first char is doubled: if yes, then it's not a command */ next_char = utf8_next_char (string); if (!next_char || !next_char[0]) return string; if (utf8_charcmp (string, next_char) == 0) return next_char; - + /* string is a command */ return NULL; } @@ -1619,15 +1619,15 @@ string_replace_with_hashtable (const char *string, int length, length_value, index_string, index_result; char *result, *result2, *key; const char *pos_end_name, *ptr_value; - + *errors = 0; - + if (!string) return NULL; - + if (!hashtable) return strdup (string); - + length = strlen (string) + 1; result = malloc (length); if (result) @@ -1676,7 +1676,7 @@ string_replace_with_hashtable (const char *string, result[index_result++] = string[index_string++]; (*errors)++; } - + free (key); } else @@ -1690,6 +1690,6 @@ string_replace_with_hashtable (const char *string, } result[index_result] = '\0'; } - + return result; } diff --git a/src/core/wee-upgrade-file.c b/src/core/wee-upgrade-file.c index 9af4910c4..eba5e96bf 100644 --- a/src/core/wee-upgrade-file.c +++ b/src/core/wee-upgrade-file.c @@ -94,7 +94,7 @@ upgrade_file_write_integer (struct t_upgrade_file *upgrade_file, int value) { if (fwrite ((void *)(&value), sizeof (value), 1, upgrade_file->file) <= 0) return 0; - + return 1; } @@ -108,7 +108,7 @@ upgrade_file_write_time (struct t_upgrade_file *upgrade_file, time_t date) { if (fwrite ((void *)(&date), sizeof (date), 1, upgrade_file->file) <= 0) return 0; - + return 1; } @@ -122,7 +122,7 @@ upgrade_file_write_string (struct t_upgrade_file *upgrade_file, const char *string) { int length; - + if (string && string[0]) { length = strlen (string); @@ -136,7 +136,7 @@ upgrade_file_write_string (struct t_upgrade_file *upgrade_file, if (!upgrade_file_write_integer (upgrade_file, 0)) return 0; } - + return 1; } @@ -161,7 +161,7 @@ upgrade_file_write_buffer (struct t_upgrade_file *upgrade_file, void *pointer, if (!upgrade_file_write_integer (upgrade_file, 0)) return 0; } - + return 1; } @@ -176,10 +176,10 @@ upgrade_file_new (const char *filename, int write) { int length; struct t_upgrade_file *new_upgrade_file; - + if (!filename) return NULL; - + new_upgrade_file = malloc (sizeof (*new_upgrade_file)); if (new_upgrade_file) { @@ -193,33 +193,33 @@ upgrade_file_new (const char *filename, int write) } snprintf (new_upgrade_file->filename, length, "%s/%s.upgrade", weechat_home, filename); - + /* open file in read or write mode */ if (write) new_upgrade_file->file = fopen (new_upgrade_file->filename, "wb"); else new_upgrade_file->file = fopen (new_upgrade_file->filename, "rb"); - + if (!new_upgrade_file->file) { free (new_upgrade_file->filename); free (new_upgrade_file); return NULL; } - + /* change permissions if write mode */ if (write) { chmod (new_upgrade_file->filename, 0600); - + /* write signature */ upgrade_file_write_string (new_upgrade_file, UPGRADE_SIGNATURE); } - + /* init positions */ new_upgrade_file->last_read_pos = 0; new_upgrade_file->last_read_length = 0; - + /* add upgrade file to list of upgrade files */ new_upgrade_file->prev_upgrade = last_upgrade_file; new_upgrade_file->next_upgrade = NULL; @@ -245,7 +245,7 @@ upgrade_file_write_object (struct t_upgrade_file *upgrade_file, int object_id, char **argv; const char *fields; void *buf; - + /* write all infolist variables */ infolist_reset_item_cursor (infolist); while (infolist_next (infolist)) @@ -261,7 +261,7 @@ upgrade_file_write_object (struct t_upgrade_file *upgrade_file, int object_id, UPGRADE_ERROR(_("write - object id"), ""); return 0; } - + fields = infolist_fields (infolist); if (fields) { @@ -376,12 +376,12 @@ upgrade_file_write_object (struct t_upgrade_file *upgrade_file, int object_id, if (argv) string_free_split (argv); } - + /* write object end */ if (!upgrade_file_write_integer (upgrade_file, UPGRADE_TYPE_OBJECT_END)) return 0; } - + return 1; } @@ -416,28 +416,28 @@ int upgrade_file_read_string (struct t_upgrade_file *upgrade_file, char **string) { int length; - + if (string && *string) { free (*string); *string = NULL; } - + if (!upgrade_file_read_integer (upgrade_file, &length)) return 0; - + upgrade_file->last_read_pos = ftell (upgrade_file->file); upgrade_file->last_read_length = length; - + if (string) { if (length == 0) return 1; - + (*string) = malloc (length + 1); if (!(*string)) return 0; - + if (fread ((void *)(*string), length, 1, upgrade_file->file) <= 0) { free (*string); @@ -464,10 +464,10 @@ upgrade_file_read_string_utf8 (struct t_upgrade_file *upgrade_file, { if (!upgrade_file_read_string (upgrade_file, string)) return 0; - + if (string && *string) utf8_normalize (*string, '?'); - + return 1; } @@ -481,23 +481,23 @@ upgrade_file_read_buffer (struct t_upgrade_file *upgrade_file, { if (!buffer) return 0; - + if (*buffer) { free (*buffer); *buffer = NULL; } - + if (!upgrade_file_read_integer (upgrade_file, size)) return 0; - + if (*size > 0) { upgrade_file->last_read_pos = ftell (upgrade_file->file); upgrade_file->last_read_length = *size; - + *buffer = malloc (*size); - + if (*buffer) { if (fread (*buffer, *size, 1, upgrade_file->file) <= 0) @@ -509,7 +509,7 @@ upgrade_file_read_buffer (struct t_upgrade_file *upgrade_file, return 0; } } - + return 1; } @@ -522,7 +522,7 @@ upgrade_file_read_time (struct t_upgrade_file *upgrade_file, time_t *time) { upgrade_file->last_read_pos = ftell (upgrade_file->file); upgrade_file->last_read_length = sizeof (*time); - + if (time) { if (fread ((void *)time, sizeof (*time), 1, upgrade_file->file) <= 0) @@ -533,7 +533,7 @@ upgrade_file_read_time (struct t_upgrade_file *upgrade_file, time_t *time) if (fseek (upgrade_file->file, sizeof (*time), SEEK_CUR) < 0) return 0; } - + return 1; } @@ -551,14 +551,14 @@ upgrade_file_read_object (struct t_upgrade_file *upgrade_file) char *name, *value_str; void *buffer; time_t time; - + rc = 0; - + infolist = NULL; name = NULL; value_str = NULL; buffer = NULL; - + if (!upgrade_file_read_integer (upgrade_file, &type)) { if (feof (upgrade_file->file)) @@ -567,19 +567,19 @@ upgrade_file_read_object (struct t_upgrade_file *upgrade_file) UPGRADE_ERROR(_("read - object type"), ""); goto end; } - + if (type != UPGRADE_TYPE_OBJECT_START) { UPGRADE_ERROR(_("read - bad object type ('object start' expected)"), ""); goto end; } - + if (!upgrade_file_read_integer (upgrade_file, &object_id)) { UPGRADE_ERROR(_("read - object id"), ""); goto end; } - + infolist = infolist_new (); if (!infolist) { @@ -592,7 +592,7 @@ upgrade_file_read_object (struct t_upgrade_file *upgrade_file) UPGRADE_ERROR(_("read - infolist item creation"), ""); goto end; } - + while (1) { if (!upgrade_file_read_integer (upgrade_file, &type)) @@ -600,10 +600,10 @@ upgrade_file_read_object (struct t_upgrade_file *upgrade_file) UPGRADE_ERROR(_("read - object type"), ""); goto end; } - + if (type == UPGRADE_TYPE_OBJECT_END) break; - + if (type == UPGRADE_TYPE_OBJECT_VAR) { if (!upgrade_file_read_string (upgrade_file, &name)) @@ -621,7 +621,7 @@ upgrade_file_read_object (struct t_upgrade_file *upgrade_file) UPGRADE_ERROR(_("read - variable type"), ""); goto end; } - + switch (type_var) { case INFOLIST_INTEGER: @@ -661,9 +661,9 @@ upgrade_file_read_object (struct t_upgrade_file *upgrade_file) } } } - + rc = 1; - + if (upgrade_file->callback_read) { if ((int)(upgrade_file->callback_read) (upgrade_file->callback_read_data, @@ -672,7 +672,7 @@ upgrade_file_read_object (struct t_upgrade_file *upgrade_file) infolist) == WEECHAT_RC_ERROR) rc = 0; } - + end: if (infolist) infolist_free (infolist); @@ -682,7 +682,7 @@ end: free (value_str); if (buffer) free (buffer); - + return rc; } @@ -700,35 +700,35 @@ upgrade_file_read (struct t_upgrade_file *upgrade_file, void *callback_read_data) { char *signature; - + if (!upgrade_file) return 0; - + upgrade_file->callback_read = callback_read; upgrade_file->callback_read_data = callback_read_data; - + signature = NULL; if (!upgrade_file_read_string (upgrade_file, &signature)) { UPGRADE_ERROR(_("read - signature not found"), ""); return 0; } - + if (!signature || (strcmp (signature, UPGRADE_SIGNATURE) != 0)) { UPGRADE_ERROR(_("read - bad signature (upgrade file format may have " "changed since last version)"), ""); return 0; } - + free (signature); - + while (!feof (upgrade_file->file)) { if (!upgrade_file_read_object (upgrade_file)) return 0; } - + return 1; } diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index c6e33b636..f1ee1da43 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -71,14 +71,14 @@ upgrade_weechat_save_history (struct t_upgrade_file *upgrade_file, struct t_infolist_item *ptr_item; struct t_gui_history *ptr_history; int rc; - + if (!last_history) return 1; - + ptr_infolist = infolist_new (); if (!ptr_infolist) return 0; - + ptr_history = last_history; while (ptr_history) { @@ -88,23 +88,23 @@ upgrade_weechat_save_history (struct t_upgrade_file *upgrade_file, infolist_free (ptr_infolist); return 0; } - + if (!infolist_new_var_string (ptr_item, "text", ptr_history->text)) { infolist_free (ptr_infolist); return 0; } - + ptr_history = ptr_history->prev_history; } - + rc = upgrade_file_write_object (upgrade_file, UPGRADE_WEECHAT_TYPE_HISTORY, ptr_infolist); infolist_free (ptr_infolist); if (!rc) return 0; - + return 1; } @@ -119,7 +119,7 @@ upgrade_weechat_save_buffers (struct t_upgrade_file *upgrade_file) struct t_gui_buffer *ptr_buffer; struct t_gui_line *ptr_line; int rc; - + for (ptr_buffer = gui_buffers; ptr_buffer; ptr_buffer = ptr_buffer->next_buffer) { @@ -138,7 +138,7 @@ upgrade_weechat_save_buffers (struct t_upgrade_file *upgrade_file) infolist_free (ptr_infolist); if (!rc) return 0; - + /* save nicklist */ if (ptr_buffer->nicklist) { @@ -157,7 +157,7 @@ upgrade_weechat_save_buffers (struct t_upgrade_file *upgrade_file) if (!rc) return 0; } - + /* save buffer lines */ for (ptr_line = ptr_buffer->own_lines->first_line; ptr_line; ptr_line = ptr_line->next_line) @@ -179,7 +179,7 @@ upgrade_weechat_save_buffers (struct t_upgrade_file *upgrade_file) if (!rc) return 0; } - + /* save command/text history of buffer */ if (ptr_buffer->history) { @@ -189,7 +189,7 @@ upgrade_weechat_save_buffers (struct t_upgrade_file *upgrade_file) return 0; } } - + return 1; } @@ -203,11 +203,11 @@ upgrade_weechat_save_misc (struct t_upgrade_file *upgrade_file) struct t_infolist *ptr_infolist; struct t_infolist_item *ptr_item; int rc; - + ptr_infolist = infolist_new (); if (!ptr_infolist) return 0; - + ptr_item = infolist_new_item (ptr_infolist); if (!ptr_item) { @@ -229,12 +229,12 @@ upgrade_weechat_save_misc (struct t_upgrade_file *upgrade_file) infolist_free (ptr_infolist); return 0; } - + rc = upgrade_file_write_object (upgrade_file, UPGRADE_WEECHAT_TYPE_MISC, ptr_infolist); infolist_free (ptr_infolist); - + return rc; } @@ -248,7 +248,7 @@ upgrade_weechat_save_hotlist (struct t_upgrade_file *upgrade_file) struct t_infolist *ptr_infolist; struct t_gui_hotlist *ptr_hotlist; int rc; - + for (ptr_hotlist = gui_hotlist; ptr_hotlist; ptr_hotlist = ptr_hotlist->next_hotlist) { @@ -267,7 +267,7 @@ upgrade_weechat_save_hotlist (struct t_upgrade_file *upgrade_file) if (!rc) return 0; } - + return 1; } @@ -282,39 +282,39 @@ upgrade_weechat_save_layout_window_tree (struct t_upgrade_file *upgrade_file, { struct t_infolist *ptr_infolist; int rc; - + ptr_infolist = infolist_new (); if (!ptr_infolist) return 0; - + if (!gui_layout_window_add_to_infolist (ptr_infolist, layout_window)) { infolist_free (ptr_infolist); return 0; } - + rc = upgrade_file_write_object (upgrade_file, UPGRADE_WEECHAT_TYPE_LAYOUT_WINDOW, ptr_infolist); - + infolist_free (ptr_infolist); if (!rc) return 0; - + if (layout_window->child1) { if (!upgrade_weechat_save_layout_window_tree (upgrade_file, layout_window->child1)) return 0; } - + if (layout_window->child2) { if (!upgrade_weechat_save_layout_window_tree (upgrade_file, layout_window->child2)) return 0; } - + return 1; } @@ -327,16 +327,16 @@ upgrade_weechat_save_layout_window (struct t_upgrade_file *upgrade_file) { struct t_gui_layout_window *layout_windows; int rc; - + /* get current layout for windows */ layout_windows = NULL; gui_layout_window_save (&layout_windows); /* save tree with layout of windows */ rc = upgrade_weechat_save_layout_window_tree (upgrade_file, layout_windows); - + gui_layout_window_remove_all (&layout_windows); - + return rc; } @@ -350,7 +350,7 @@ upgrade_weechat_save () { int rc; struct t_upgrade_file *upgrade_file; - + upgrade_file = upgrade_file_new (WEECHAT_UPGRADE_FILENAME, 1); if (!upgrade_file) return 0; @@ -361,9 +361,9 @@ upgrade_weechat_save () rc &= upgrade_weechat_save_misc (upgrade_file); rc &= upgrade_weechat_save_hotlist (upgrade_file); rc &= upgrade_weechat_save_layout_window (upgrade_file); - + upgrade_file_close (upgrade_file); - + return rc; } @@ -387,11 +387,11 @@ upgrade_weechat_read_cb (void *data, struct timeval creation_time; void *buf; int i, size, index, length; - + /* make C compiler happy */ (void) data; (void) upgrade_file; - + infolist_reset_item_cursor (infolist); while (infolist_next (infolist)) { @@ -673,7 +673,7 @@ upgrade_weechat_read_cb (void *data, break; } } - + return WEECHAT_RC_OK; } @@ -687,40 +687,40 @@ upgrade_weechat_load () { int rc; struct t_upgrade_file *upgrade_file; - + upgrade_file = upgrade_file_new (WEECHAT_UPGRADE_FILENAME, 0); rc = upgrade_file_read (upgrade_file, &upgrade_weechat_read_cb, NULL); - + if (!hotlist_reset) gui_hotlist_clear (); - + gui_color_buffer_assign (); gui_color_buffer_display (); - + if (upgrade_layout_buffers) { gui_layout_buffer_apply (upgrade_layout_buffers); gui_layout_buffer_remove_all (&upgrade_layout_buffers, &last_upgrade_layout_buffer); } - + if (upgrade_layout_windows) { gui_layout_window_apply (upgrade_layout_windows, -1); gui_layout_window_remove_all (&upgrade_layout_windows); } - + if (upgrade_set_current_window > 0) gui_window_switch_by_number (upgrade_set_current_window); - + if (upgrade_set_current_buffer) { gui_window_switch_to_buffer (gui_current_window, upgrade_set_current_buffer, 0); } - + gui_layout_buffer_get_number_all (gui_layout_buffers); - + return rc; } @@ -733,7 +733,7 @@ upgrade_weechat_remove_file_cb (void *data, const char *filename) { /* make C compiler happy */ (void) data; - + if (string_match (filename, "*.upgrade", 1)) { if (weechat_debug_core >= 2) @@ -752,13 +752,13 @@ upgrade_weechat_end () { struct timeval tv_now; long time_diff; - + /* remove .upgrade files */ util_exec_on_files (weechat_home, 0, NULL, &upgrade_weechat_remove_file_cb); - + /* display message for end of /upgrade with duration */ gettimeofday (&tv_now, NULL); time_diff = util_timeval_diff (&weechat_current_start_timeval, &tv_now); @@ -767,10 +767,10 @@ upgrade_weechat_end () _("Upgrade done (%.02f %s)"), ((float)time_diff) / 1000, NG_("second", "seconds", time_diff / 1000)); - + /* upgrading ended */ weechat_upgrading = 0; - + /* send signal for end of /upgrade */ hook_signal_send ("upgrade_ended", WEECHAT_HOOK_SIGNAL_STRING, NULL); } diff --git a/src/core/wee-utf8.c b/src/core/wee-utf8.c index 1ef32542e..d61261f33 100644 --- a/src/core/wee-utf8.c +++ b/src/core/wee-utf8.c @@ -137,7 +137,7 @@ void utf8_normalize (char *string, char replacement) { char *error; - + while (string && string[0]) { if (utf8_is_valid (string, &error)) @@ -156,9 +156,9 @@ utf8_prev_char (const char *string_start, const char *string) { if (!string || (string <= string_start)) return NULL; - + string--; - + if (((unsigned char)(string[0]) & 0xC0) == 0x80) { /* UTF-8, at least 2 bytes */ @@ -197,7 +197,7 @@ utf8_next_char (const char *string) { if (!string) return NULL; - + /* UTF-8, 2 bytes: 110vvvvv 10vvvvvv */ if (((unsigned char)(string[0]) & 0xE0) == 0xC0) { @@ -237,12 +237,12 @@ int utf8_char_int (const char *string) { const unsigned char *ptr_string; - + if (!string) return 0; - + ptr_string = (unsigned char *)string; - + /* UTF-8, 2 bytes: 110vvvvv 10vvvvvv */ if ((ptr_string[0] & 0xE0) == 0xC0) { @@ -293,10 +293,10 @@ utf8_wide_char (const char *string) { int char_size; wint_t result; - + if (!string || !string[0]) return WEOF; - + char_size = utf8_char_size (string); switch (char_size) { @@ -333,7 +333,7 @@ utf8_char_size (const char *string) { if (!string) return 0; - + return utf8_next_char (string) - string; } @@ -345,10 +345,10 @@ int utf8_strlen (const char *string) { int length; - + if (!string) return 0; - + length = 0; while (string && string[0]) { @@ -367,10 +367,10 @@ utf8_strnlen (const char *string, int bytes) { char *start; int length; - + if (!string) return 0; - + start = (char *)string; length = 0; while (string && string[0] && (string - start < bytes)) @@ -391,24 +391,24 @@ utf8_strlen_screen (const char *string) { int length, num_char; wchar_t *wstring; - + if (!string) return 0; - + if (!local_utf8) return utf8_strlen (string); - + num_char = mbstowcs (NULL, string, 0) + 1; wstring = malloc ((num_char + 1) * sizeof (wstring[0])); if (!wstring) return utf8_strlen (string); - + if (mbstowcs (wstring, string, num_char) == (size_t)(-1)) { free (wstring); return utf8_strlen (string); } - + length = wcswidth (wstring, num_char); free (wstring); return length; @@ -422,13 +422,13 @@ int utf8_charcmp (const char *string1, const char *string2) { int length1, length2, i, diff; - + if (!string1 || !string2) return (string1) ? 1 : ((string2) ? -1 : 0); - + length1 = utf8_char_size (string1); length2 = utf8_char_size (string2); - + i = 0; while ((i < length1) && (i < length2)) { @@ -455,18 +455,18 @@ int utf8_charcasecmp (const char *string1, const char *string2) { wint_t wchar1, wchar2; - + if (!string1 || !string2) return (string1) ? 1 : ((string2) ? -1 : 0); - + wchar1 = utf8_wide_char (string1); if ((wchar1 >= 'A') && (wchar1 <= 'Z')) wchar1 += ('a' - 'A'); - + wchar2 = utf8_wide_char (string2); if ((wchar2 >= 'A') && (wchar2 <= 'Z')) wchar2 += ('a' - 'A'); - + return (wchar1 < wchar2) ? -1 : ((wchar1 == wchar2) ? 0 : 1); } @@ -480,17 +480,17 @@ utf8_char_size_screen (const char *string) { int char_size; char utf_char[16]; - + if (!string) return 0; - + char_size = utf8_char_size (string); if (char_size == 0) return 0; - + memcpy (utf_char, string, char_size); utf_char[char_size] = '\0'; - + return utf8_strlen_screen (utf_char); } @@ -503,7 +503,7 @@ utf8_add_offset (const char *string, int offset) { if (!string) return NULL; - + while (string && string[0] && (offset > 0)) { string = utf8_next_char (string); @@ -522,10 +522,10 @@ utf8_real_pos (const char *string, int pos) { int count, real_pos; char *next_char; - + if (!string) return pos; - + count = 0; real_pos = 0; while (string && string[0] && (count < pos)) @@ -548,10 +548,10 @@ utf8_pos (const char *string, int real_pos) { int count; char *limit; - + if (!string || !weechat_local_charset) return real_pos; - + count = 0; limit = (char *)string + real_pos; while (string && string[0] && (string < limit)) @@ -570,13 +570,13 @@ char * utf8_strndup (const char *string, int length) { const char *end; - + if (!string || (length < 0)) return NULL; - + if (length == 0) return strdup (""); - + end = utf8_add_offset (string, length); if (!end || (end == string)) return strdup (string); diff --git a/src/core/wee-util.c b/src/core/wee-util.c index da3906825..d5e517fd9 100644 --- a/src/core/wee-util.c +++ b/src/core/wee-util.c @@ -73,10 +73,10 @@ long util_timeval_diff (struct timeval *tv1, struct timeval *tv2) { long diff_sec, diff_usec; - + diff_sec = tv2->tv_sec - tv1->tv_sec; diff_usec = tv2->tv_usec - tv1->tv_usec; - + if (diff_usec < 0) { diff_usec += 1000000; @@ -93,7 +93,7 @@ void util_timeval_add (struct timeval *tv, long interval) { long usec; - + tv->tv_sec += (interval / 1000); usec = tv->tv_usec + ((interval % 1000) * 1000); if (usec > 1000000) @@ -115,11 +115,11 @@ util_get_time_string (const time_t *date) { struct tm *local_time; static char text_time[128]; - + local_time = localtime (date); strftime (text_time, sizeof (text_time), CONFIG_STRING(config_look_time_format), local_time); - + return text_time; } @@ -131,7 +131,7 @@ void util_catch_signal (int signum, void (*handler)(int)) { struct sigaction act; - + sigemptyset (&act.sa_mask); act.sa_flags = 0; act.sa_handler = handler; @@ -148,18 +148,18 @@ util_mkdir_home (const char *directory, int mode) { char *dir_name; int dir_length; - + if (!directory) return 0; - + /* build directory, adding WeeChat home */ dir_length = strlen (weechat_home) + strlen (directory) + 2; dir_name = malloc (dir_length); if (!dir_name) return 0; - + snprintf (dir_name, dir_length, "%s/%s", weechat_home, directory); - + if (mkdir (dir_name, mode) < 0) { if (errno != EEXIST) @@ -168,7 +168,7 @@ util_mkdir_home (const char *directory, int mode) return 0; } } - + free (dir_name); return 1; } @@ -183,13 +183,13 @@ util_mkdir (const char *directory, int mode) { if (!directory) return 0; - + if (mkdir (directory, mode) < 0) { if (errno != EEXIST) return 0; } - + return 1; } @@ -204,26 +204,26 @@ util_mkdir_parents (const char *directory, int mode) char *string, *ptr_string, *pos_sep; struct stat buf; int rc; - + if (!directory) return 0; - + string = strdup (directory); if (!string) return 0; - + ptr_string = string; while (ptr_string[0] == DIR_SEPARATOR_CHAR) { ptr_string++; } - + while (ptr_string && ptr_string[0]) { pos_sep = strchr (ptr_string, DIR_SEPARATOR_CHAR); if (pos_sep) pos_sep[0] = '\0'; - + rc = stat (string, &buf); if ((rc < 0) || !S_ISDIR(buf.st_mode)) { @@ -234,7 +234,7 @@ util_mkdir_parents (const char *directory, int mode) return 0; } } - + if (pos_sep) { pos_sep[0] = DIR_SEPARATOR_CHAR; @@ -243,9 +243,9 @@ util_mkdir_parents (const char *directory, int mode) else ptr_string = NULL; } - + free (string); - + return 1; } @@ -262,10 +262,10 @@ util_exec_on_files (const char *directory, int hidden_files, void *data, DIR *dir; struct dirent *entry; struct stat statbuf; - + if (!directory || !callback) return; - + dir = opendir (directory); if (dir) { @@ -302,11 +302,11 @@ util_search_full_lib_name (const char *filename, const char *sys_directory) char *name_with_ext, *final_name; int length; struct stat st; - + /* filename is already a full path */ if (strchr (filename, '/') || strchr (filename, '\\')) return strdup (filename); - + length = strlen (filename) + 16; if (CONFIG_STRING(config_plugin_extension) && CONFIG_STRING(config_plugin_extension)[0]) @@ -319,7 +319,7 @@ util_search_full_lib_name (const char *filename, const char *sys_directory) && CONFIG_STRING(config_plugin_extension) && CONFIG_STRING(config_plugin_extension)[0]) strcat (name_with_ext, CONFIG_STRING(config_plugin_extension)); - + /* try WeeChat user's dir */ length = strlen (weechat_home) + strlen (name_with_ext) + strlen (sys_directory) + 16; @@ -337,7 +337,7 @@ util_search_full_lib_name (const char *filename, const char *sys_directory) return final_name; } free (final_name); - + /* try WeeChat global lib dir */ length = strlen (WEECHAT_LIBDIR) + strlen (name_with_ext) + strlen (sys_directory) + 16; @@ -372,10 +372,10 @@ util_file_get_content (const char *filename) char *buffer, *buffer2; FILE *f; size_t count, fp; - + buffer = NULL; fp = 0; - + f = fopen (filename, "r"); if (f) { @@ -408,7 +408,7 @@ util_file_get_content (const char *filename) buffer[fp] = '\0'; fclose (f); } - + return buffer; } @@ -430,7 +430,7 @@ util_version_number (const char *version) char **items, buf[64], *ptr_item, *error; int num_items, i, version_int[4], index_buf; long number; - + items = string_split (version, ".", 0, 4, &num_items); for (i = 0; i < 4; i++) { @@ -468,7 +468,7 @@ util_version_number (const char *version) } if (items) string_free_split (items); - + return (version_int[0] << 24) | (version_int[1] << 16) | (version_int[2] << 8) | version_int[3]; } diff --git a/src/core/weechat.c b/src/core/weechat.c index 66bcb3d17..735fc15f7 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -197,14 +197,14 @@ void weechat_parse_args (int argc, char *argv[]) { int i; - + weechat_argv0 = strdup (argv[0]); weechat_upgrading = 0; weechat_home = NULL; weechat_server_cmd_line = 0; weechat_auto_load_plugins = 1; weechat_plugin_no_dlclose = 0; - + for (i = 1; i < argc; i++) { if ((strcmp (argv[i], "-c") == 0) @@ -323,7 +323,7 @@ weechat_create_home_dirs () weechat_shutdown (EXIT_FAILURE, 0); } } - + /* create home directory; error is fatal */ if (!util_mkdir (weechat_home, 0755)) { @@ -383,7 +383,7 @@ weechat_shutdown (int return_code, int crash) free (weechat_local_charset); network_end (); - + if (crash) abort(); else @@ -398,21 +398,21 @@ int main (int argc, char *argv[]) { weechat_init_vars (); /* initialize some variables */ - + setlocale (LC_ALL, ""); /* initialize gettext */ #ifdef ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif - + #ifdef HAVE_LANGINFO_CODESET weechat_local_charset = strdup (nl_langinfo (CODESET)); #else weechat_local_charset = strdup (""); #endif utf8_init (); - + util_catch_signal (SIGINT, SIG_IGN); /* ignore SIGINT signal */ util_catch_signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal */ util_catch_signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal */ @@ -449,9 +449,9 @@ main (int argc, char *argv[]) gui_layout_window_apply (gui_layout_windows, -1); /* apply win layout */ if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ - + gui_main_loop (); /* WeeChat main loop */ - + gui_layout_save_on_exit (); /* save layout */ plugin_end (); /* end plugin interface(s) */ if (CONFIG_BOOLEAN(config_look_save_config_on_exit)) @@ -463,6 +463,6 @@ main (int argc, char *argv[]) unhook_all (); /* remove all hooks */ hdata_end (); /* end hdata */ weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */ - + return EXIT_SUCCESS; /* make C compiler happy */ } diff --git a/src/core/weechat.h b/src/core/weechat.h index 2d0644b33..269a362e6 100644 --- a/src/core/weechat.h +++ b/src/core/weechat.h @@ -75,7 +75,7 @@ "\n" \ "You should have received a copy of the GNU General Public License\n" \ "along with WeeChat. If not, see <http://www.gnu.org/licenses/>.\n\n" - + /* directory separator, depending on OS */ #ifdef _WIN32 |