diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/irc/core/irc-servers.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index 8af8364d..fa7feda6 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -81,7 +81,7 @@ static char **split_line(const SERVER_REC *server, const char *line, const char *end = settings_get_str("split_line_end"); char *recoded_start = recode_out(server, start, target); char *recoded_end = recode_out(server, end, target); - char **lines; + char **lines = NULL; int i; /* @@ -90,10 +90,8 @@ static char **split_line(const SERVER_REC *server, const char *line, * the code much simpler. It's worth it. */ len -= strlen(recoded_start) + strlen(recoded_end); - g_free(recoded_start); - g_free(recoded_end); if (len <= 0) - return NULL; /* There is no room for anything. */ + goto out; /* There is no room for anything. */ lines = recode_split(server, line, target, len); for (i = 0; lines[i] != NULL; i++) { @@ -106,11 +104,36 @@ static char **split_line(const SERVER_REC *server, const char *line, if (lines[i + 1] != NULL && *end != '\0') { /* Not the last line. */ char *tmp = lines[i]; + + if (lines[i + 2] == NULL) { + /* Next to last line. Check if we have room + * to append the last line to the current line, + * to avoid an unnecessary line break. + */ + char *recoded_l = recode_out(server, + lines[i+1], + target); + if (strlen(recoded_l) <= strlen(recoded_end)) { + lines[i] = g_strconcat(tmp, lines[i+1], + NULL); + g_free_and_null(lines[i+1]); + lines = g_renew(char *, lines, i + 2); + + g_free(recoded_l); + g_free(tmp); + break; + } + g_free(recoded_l); + } + lines[i] = g_strconcat(tmp, end, NULL); g_free(tmp); } } +out: + g_free(recoded_start); + g_free(recoded_end); return lines; } |