summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastian Thorarensen <sebth@naju.se>2014-06-16 21:59:48 +0200
committerSebastian Thorarensen <sebth@naju.se>2014-07-06 23:24:09 +0200
commit281c6d437dbc30ffc30c615b8dc773dc937abefa (patch)
treee9b3e49e883baabb621120378057c54a623529b4 /src
parent5c05c854dc298a914de8515a2795fa8dd2adca04 (diff)
downloadirssi-281c6d437dbc30ffc30c615b8dc773dc937abefa.zip
Avoid unnecessary splitting of lines
`split_line_end' could force lines to be unnecessarily split. This commit fixes the problem by making sure that the last line isn't shorter than `split_line_end'.
Diffstat (limited to 'src')
-rw-r--r--src/irc/core/irc-servers.c31
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;
}