summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2000-06-11 22:58:17 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2000-06-11 22:58:17 +0000
commit919abb2c6f8339e160a59b8ddcacfd403772379d (patch)
treee2ef2d913426d31fe0851577c0128350bddd0f24 /src
parentb8e1bb044459590531b98daf50682e33914636c3 (diff)
downloadirssi-919abb2c6f8339e160a59b8ddcacfd403772379d.zip
/EVAL will now expand \n and \t to newline and tab.
If you /SET expand_escapes ON and type \n or \t to text line, they will be expanded. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@326 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r--src/core/special-vars.c11
-rw-r--r--src/fe-common/core/printtext.c16
-rw-r--r--src/fe-common/irc/completion.c46
3 files changed, 70 insertions, 3 deletions
diff --git a/src/core/special-vars.c b/src/core/special-vars.c
index 91f8897e..e0215aa5 100644
--- a/src/core/special-vars.c
+++ b/src/core/special-vars.c
@@ -414,7 +414,16 @@ char *parse_special_string(const char *cmd, void *server, void *item, const char
str = g_string_new(NULL);
while (*cmd != '\0') {
if (code == '\\'){
- g_string_append_c(str, *cmd);
+ switch (*cmd) {
+ case 't':
+ g_string_append_c(str, '\t');
+ break;
+ case 'n':
+ g_string_append_c(str, '\n');
+ break;
+ default:
+ g_string_append_c(str, *cmd);
+ }
code = 0;
} else if (code == '$') {
char *ret;
diff --git a/src/fe-common/core/printtext.c b/src/fe-common/core/printtext.c
index 7e525202..7784b45d 100644
--- a/src/fe-common/core/printtext.c
+++ b/src/fe-common/core/printtext.c
@@ -506,6 +506,20 @@ static void print_string(TEXT_DEST_REC *dest, const char *text)
if (str != text) g_free(str);
}
+/* append string to `out', expand newlines. */
+static void printtext_append_str(TEXT_DEST_REC *dest, GString *out, const char *str)
+{
+ while (*str != '\0') {
+ if (*str != '\n')
+ g_string_append_c(out, *str);
+ else {
+ print_string(dest, out->str);
+ g_string_truncate(out, 0);
+ }
+ str++;
+ }
+}
+
static char *printtext_get_args(TEXT_DEST_REC *dest, const char *str, va_list va)
{
GString *out;
@@ -525,7 +539,7 @@ static char *printtext_get_args(TEXT_DEST_REC *dest, const char *str, va_list va
switch (*str) {
case 's': {
char *s = (char *) va_arg(va, char *);
- if (s && *s) g_string_append(out, s);
+ if (s && *s) printtext_append_str(dest, out, s);
break;
}
case 'd': {
diff --git a/src/fe-common/irc/completion.c b/src/fe-common/irc/completion.c
index 0e98c729..b53f40f5 100644
--- a/src/fe-common/irc/completion.c
+++ b/src/fe-common/irc/completion.c
@@ -269,6 +269,48 @@ static GList *completion_getmsglist(IRC_SERVER_REC *server, gchar *nick)
return list;
}
+/* expand \n, \t and \\ */
+static char *expand_escapes(const char *line, IRC_SERVER_REC *server, WI_IRC_REC *item)
+{
+ char *ptr, *ret;
+
+ ret = ptr = g_malloc(strlen(line)+1);
+ while (*line != '\0') {
+ if (*line != '\\')
+ *ptr++ = *line;
+ else {
+ line++;
+ if (*line == '\0') {
+ *ptr++ = '\\';
+ break;
+ }
+
+ switch (*line) {
+ case 'n':
+ /* newline .. we need to send another "send text" event to handle it (or actually the text before the newline..) */
+ *ptr = '\0';
+ signal_emit("send text", 3, line, server, item);
+ ptr = ret;
+ break;
+ case 't':
+ *ptr++ = '\t';
+ break;
+ case '\\':
+ *ptr++ = '\\';
+ break;
+ default:
+ *ptr++ = '\\';
+ *ptr++ = *line;
+ break;
+ }
+ }
+ line++;
+ }
+
+ *ptr = '\0';
+ return ret;
+}
+
static void event_text(gchar *line, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
CHANNEL_REC *channel;
@@ -280,7 +322,8 @@ static void event_text(gchar *line, IRC_SERVER_REC *server, WI_IRC_REC *item)
if (!irc_item_check(item))
return;
- line = g_strdup(line);
+ line = settings_get_bool("expand_escapes") ?
+ expand_escapes(line, server, item) : g_strdup(line);
/* check for nick completion */
if (settings_get_bool("completion_disable_auto") || *settings_get_str("completion_char") == '\0')
@@ -574,6 +617,7 @@ void completion_init(void)
settings_add_int("completion", "completion_keep_publics", 180);
settings_add_int("completion", "completion_keep_ownpublics", 360);
settings_add_int("completion", "completion_keep_privates", 10);
+ settings_add_bool("completion", "expand_escapes", FALSE);
signal_add("event privmsg", (SIGNAL_FUNC) event_privmsg);
signal_add("send text", (SIGNAL_FUNC) event_text);