diff options
author | Sebastian Thorarensen <sebth@naju.se> | 2014-06-16 19:59:12 +0200 |
---|---|---|
committer | Sebastian Thorarensen <sebth@naju.se> | 2014-07-06 23:24:09 +0200 |
commit | 5c05c854dc298a914de8515a2795fa8dd2adca04 (patch) | |
tree | a345f329183957134f1ec5a4e6860d29d34b1cb7 | |
parent | e6147fb8f2764392dd685fd8b28f1d69527609cd (diff) | |
download | irssi-5c05c854dc298a914de8515a2795fa8dd2adca04.zip |
Add configurable split line prefixes and suffixes
Add settings `split_line_start' and `split_line_end' analogous to
`splitlong_line_start' and `splitlong_line_end' in `splitlong.pl'. The
prefixes and suffixes are concatenated with a wrapper function to keep
`recode_split' and `strsplit_len' simple.
-rw-r--r-- | src/irc/core/irc-servers.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index a52fa816..8af8364d 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -74,6 +74,46 @@ static int ischannel_func(SERVER_REC *server, const char *data) return ischannel(*data); } +static char **split_line(const SERVER_REC *server, const char *line, + const char *target, int len) +{ + const char *start = settings_get_str("split_line_start"); + 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; + int i; + + /* + * Having the same length limit on all lines will make the first line + * shorter than necessary if `split_line_start' is set, but it makes + * 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. */ + + lines = recode_split(server, line, target, len); + for (i = 0; lines[i] != NULL; i++) { + if (i != 0 && *start != '\0') { + /* Not the first line. */ + char *tmp = lines[i]; + lines[i] = g_strconcat(start, tmp, NULL); + g_free(tmp); + } + if (lines[i + 1] != NULL && *end != '\0') { + /* Not the last line. */ + char *tmp = lines[i]; + lines[i] = g_strconcat(tmp, end, NULL); + g_free(tmp); + } + } + + return lines; +} + static void send_message(SERVER_REC *server, const char *target, const char *msg, int target_type) { @@ -120,10 +160,10 @@ static char **split_message(SERVER_REC *server, const char *target, userhostlen = strlen(ircserver->userhost); /* length calculation shamelessly stolen from splitlong.pl */ - return recode_split(SERVER(server), msg, target, - 510 - strlen(":! PRIVMSG :") - - strlen(ircserver->nick) - userhostlen - - strlen(target)); + return split_line(SERVER(server), msg, target, + 510 - strlen(":! PRIVMSG :") - + strlen(ircserver->nick) - userhostlen - + strlen(target)); } static void server_init(IRC_SERVER_REC *server) @@ -893,6 +933,8 @@ void irc_servers_init(void) settings_add_str("misc", "usermode", DEFAULT_USER_MODE); settings_add_time("flood", "cmd_queue_speed", DEFAULT_CMD_QUEUE_SPEED); settings_add_int("flood", "cmds_max_at_once", DEFAULT_CMDS_MAX_AT_ONCE); + settings_add_str("misc", "split_line_start", ""); + settings_add_str("misc", "split_line_end", ""); cmd_tag = -1; |