diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2007-05-22 16:37:11 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2007-05-22 16:37:11 +0000 |
commit | 5e4f45e2a2ee184f7191264d7a4c00f2c73cde90 (patch) | |
tree | 15003bf9009857a5bbb88ee43ffcba5c5d9b6a9c /src | |
parent | e339e9020d903e7d2025661e43382e63b4c819d6 (diff) | |
download | weechat-5e4f45e2a2ee184f7191264d7a4c00f2c73cde90.zip |
Improved IRC long message split: use word boundary (task #6685)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command.c | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/common/command.c b/src/common/command.c index 5b6606cc8..700ffcf73 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -757,30 +757,39 @@ void user_message (t_irc_server *server, t_gui_buffer *buffer, char *text) { int max_length; - char *pos, *pos_next, *pos_max, *next, saved_char; + char *pos, *pos_next, *pos_max, *next, saved_char, *last_space; if (!text || !text[0]) return; + + next = NULL; + last_space = NULL; + saved_char = '\0'; max_length = 512 - 16 - 65 - 10 - strlen (server->nick) - strlen (CHANNEL(buffer)->name); - next = NULL; - saved_char = '\0'; - if ((int)strlen (text) > max_length) + if (max_length > 0) { - pos = text; - pos_max = text + max_length; - while (pos && pos[0]) + if ((int)strlen (text) > max_length) { - pos_next = utf8_next_char (pos); - if (pos_next > pos_max) - break; - pos = pos_next; + pos = text; + pos_max = text + max_length; + while (pos && pos[0]) + { + if (pos[0] == ' ') + last_space = pos; + pos_next = utf8_next_char (pos); + if (pos_next > pos_max) + break; + pos = pos_next; + } + if (last_space && (last_space < pos)) + pos = last_space + 1; + saved_char = pos[0]; + pos[0] = '\0'; + next = pos; } - saved_char = pos[0]; - pos[0] = '\0'; - next = pos; } irc_server_sendf_queued (server, "PRIVMSG %s :%s", CHANNEL(buffer)->name, text); |