mirror of
https://github.com/irssi/irssi.git
synced 2025-01-03 14:56:47 -05:00
/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
This commit is contained in:
parent
b8e1bb0444
commit
919abb2c6f
@ -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;
|
||||
|
@ -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': {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user