From 0a990ad6f725dba816e067f6273d59c860c306ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sun, 10 May 2015 02:12:39 +0200 Subject: [PATCH] degesch: add a way to output mIRC formatting --- degesch.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/degesch.c b/degesch.c index 2477400..275f744 100644 --- a/degesch.c +++ b/degesch.c @@ -3967,6 +3967,39 @@ irc_process_message (const struct irc_message *msg, irc_process_numeric (s, msg, numeric); } +// --- mIRC formatting --------------------------------------------------------- + +// Out user interface doesn't give us much of a choice with entering it. + +static char * +add_mirc_formatting (const char *text) +{ + struct str output; + str_init (&output); + + for (; *text; text++) + { + char c = *text; + if (c != '\\') + { + str_append_c (&output, c); + continue; + } + + switch (text[1]) + { + case 'b': c = '\x02'; text++; break; + case 'c': c = '\x03'; text++; break; + case 'i': c = '\x1d'; text++; break; + case '_': c = '\x1f'; text++; break; + case 'v': c = '\x16'; text++; break; + case 'o': c = '\x0f'; text++; break; + } + str_append_c (&output, c); + } + return str_steal (&output); +} + // --- Message autosplitting magic --------------------------------------------- // This is the most basic acceptable algorithm; something like ICU with proper @@ -4102,10 +4135,13 @@ send_autosplit_message (struct server *s, struct send_autosplit_args a) int fixed_part = strlen (a.command) + 1 + strlen (a.target) + 1 + 1 + strlen (a.prefix) + strlen (a.suffix); + // XXX: this may screw up the formatting if we do split the message + char *formatted = add_mirc_formatting (a.message); + struct str_vector lines; str_vector_init (&lines); struct error *e = NULL; - if (!irc_autosplit_message (s, a.message, fixed_part, &lines, &e)) + if (!irc_autosplit_message (s, formatted, fixed_part, &lines, &e)) { buffer_send_error (s->ctx, buffer ? buffer : s->buffer, "%s", e->message); @@ -4120,6 +4156,7 @@ send_autosplit_message (struct server *s, struct send_autosplit_args a) a.logger (s, &a, buffer, lines.vector[i]); } end: + free (formatted); str_vector_free (&lines); }