diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2014-06-26 15:29:38 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-07-17 11:30:01 -0300 |
commit | f17668234a5bcd1905775436da9cf0e136bb8150 (patch) | |
tree | 0758a448eb414ba9fd6953010b5f6e6f768e7326 /src/nvim/api/vim.c | |
parent | 0e20afe37e7ad99036ab98356a3f72281e1a8017 (diff) | |
download | rneovim-f17668234a5bcd1905775436da9cf0e136bb8150.tar.gz rneovim-f17668234a5bcd1905775436da9cf0e136bb8150.tar.bz2 rneovim-f17668234a5bcd1905775436da9cf0e136bb8150.zip |
api: Refactor write_msg to use separate out/err buffers
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 03b9257d79..9834633813 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -512,23 +512,24 @@ void vim_unsubscribe(uint64_t channel_id, String event) /// `emsg` instead of `msg` to print each line) static void write_msg(String message, bool to_err) { - static int pos = 0; - static char line_buf[LINE_BUFFER_SIZE]; + static int out_pos = 0, err_pos = 0; + static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE]; + +#define PUSH_CHAR(i, pos, line_buf, msg) \ + if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \ + line_buf[pos] = NUL; \ + msg((uint8_t *)line_buf); \ + pos = 0; \ + continue; \ + } \ + \ + line_buf[pos++] = message.data[i]; for (uint32_t i = 0; i < message.size; i++) { - if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { - // Flush line - line_buf[pos] = NUL; - if (to_err) { - emsg((uint8_t *)line_buf); - } else { - msg((uint8_t *)line_buf); - } - - pos = 0; - continue; + if (to_err) { + PUSH_CHAR(i, err_pos, err_line_buf, emsg); + } else { + PUSH_CHAR(i, out_pos, out_line_buf, msg); } - - line_buf[pos++] = message.data[i]; } } |