aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-06-26 15:29:38 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-07-17 11:30:01 -0300
commitf17668234a5bcd1905775436da9cf0e136bb8150 (patch)
tree0758a448eb414ba9fd6953010b5f6e6f768e7326 /src/nvim/api/vim.c
parent0e20afe37e7ad99036ab98356a3f72281e1a8017 (diff)
downloadrneovim-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.c31
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];
}
}