diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-06-03 15:20:05 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-06-03 21:31:38 +0200 |
commit | 43dee8ce548856f4d65caad66c1b7dba4d8b603e (patch) | |
tree | 81a7ba9e1b5695266131725e735d8123b04efcbc | |
parent | 682fc40708ca5ff0b86ff2f4d4652c477fdb22c5 (diff) | |
download | weechat-43dee8ce548856f4d65caad66c1b7dba4d8b603e.zip |
fifo: allow using escape characters
This allows you to use escape characters if you start the fifo command
with \ instead of *, in the same way as the escape_commands option in
the relay protocol. This allows you to send commands consisting of
multiple lines by using \n if the buffer has input_multiline set.
-rw-r--r-- | src/plugins/fifo/fifo.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c index d7620d584..904ecd5f5 100644 --- a/src/plugins/fifo/fifo.c +++ b/src/plugins/fifo/fifo.c @@ -197,7 +197,8 @@ fifo_remove () void fifo_exec (const char *text) { - char *text2, *pos_msg; + char *text2, *pos_msg, *command_unescaped; + int escaped; struct t_gui_buffer *ptr_buffer; text2 = strdup (text); @@ -205,14 +206,17 @@ fifo_exec (const char *text) return; pos_msg = NULL; + command_unescaped = NULL; + escaped = 0; ptr_buffer = NULL; /* * look for plugin + buffer name at beginning of text * text may be: "plugin.buffer *text" or "*text" */ - if (text2[0] == '*') + if (text2[0] == '*' || text2[0] == '\\') { + escaped = text2[0] == '\\'; pos_msg = text2 + 1; ptr_buffer = weechat_current_buffer (); } @@ -220,6 +224,9 @@ fifo_exec (const char *text) { pos_msg = strstr (text2, " *"); if (!pos_msg) + pos_msg = strstr (text2, " \\"); + + if (!pos_msg) { weechat_printf (NULL, _("%s%s: invalid text received in pipe"), @@ -227,6 +234,8 @@ fifo_exec (const char *text) free (text2); return; } + + escaped = pos_msg[1] == '\\'; pos_msg[0] = '\0'; pos_msg += 2; ptr_buffer = weechat_buffer_search ("==", text2); @@ -241,9 +250,18 @@ fifo_exec (const char *text) } } + if (escaped) + { + command_unescaped = weechat_string_convert_escaped_chars (pos_msg); + if (command_unescaped) + pos_msg = command_unescaped; + } + weechat_command (ptr_buffer, pos_msg); free (text2); + if (command_unescaped) + free(command_unescaped); } /* |