summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-10 02:12:39 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-10 02:12:39 +0200
commit0a990ad6f725dba816e067f6273d59c860c306ba (patch)
tree2edfab74c40c962fa2ab45df506c69232cbcd0f4
parent00b91976b07f4ad7d5f2b78642ddc8975b96c1d8 (diff)
downloadxK-0a990ad6f725dba816e067f6273d59c860c306ba.tar.gz
xK-0a990ad6f725dba816e067f6273d59c860c306ba.tar.xz
xK-0a990ad6f725dba816e067f6273d59c860c306ba.zip
degesch: add a way to output mIRC formatting
-rw-r--r--degesch.c39
1 files changed, 38 insertions, 1 deletions
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);
}