Mercurial > vim
comparison src/channel.c @ 9434:8f904a323b3f v7.4.1998
commit https://github.com/vim/vim/commit/bf2cc5f36d5ffd5de445e6970602000c7869b65a
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jul 7 20:45:06 2016 +0200
patch 7.4.1998
Problem: When writing buffer lines to a job there is no NL to NUL
conversion.
Solution: Make it work symmetrical with writing lines from a job into a
buffer.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 07 Jul 2016 21:00:06 +0200 |
parents | 2465b6cda394 |
children | 69ed2c9d34a6 |
comparison
equal
deleted
inserted
replaced
9433:42a5ae2e19e8 | 9434:8f904a323b3f |
---|---|
1311 write_buf_line(buf_T *buf, linenr_T lnum, channel_T *channel) | 1311 write_buf_line(buf_T *buf, linenr_T lnum, channel_T *channel) |
1312 { | 1312 { |
1313 char_u *line = ml_get_buf(buf, lnum, FALSE); | 1313 char_u *line = ml_get_buf(buf, lnum, FALSE); |
1314 int len = (int)STRLEN(line); | 1314 int len = (int)STRLEN(line); |
1315 char_u *p; | 1315 char_u *p; |
1316 int i; | |
1316 | 1317 |
1317 /* Need to make a copy to be able to append a NL. */ | 1318 /* Need to make a copy to be able to append a NL. */ |
1318 if ((p = alloc(len + 2)) == NULL) | 1319 if ((p = alloc(len + 2)) == NULL) |
1319 return; | 1320 return; |
1320 memcpy((char *)p, (char *)line, len); | 1321 memcpy((char *)p, (char *)line, len); |
1322 | |
1323 for (i = 0; i < len; ++i) | |
1324 if (p[i] == NL) | |
1325 p[i] = NUL; | |
1326 | |
1321 p[len] = NL; | 1327 p[len] = NL; |
1322 p[len + 1] = NUL; | 1328 p[len + 1] = NUL; |
1323 channel_send(channel, PART_IN, p, "write_buf_line()"); | 1329 channel_send(channel, PART_IN, p, len + 1, "write_buf_line()"); |
1324 vim_free(p); | 1330 vim_free(p); |
1325 } | 1331 } |
1326 | 1332 |
1327 /* | 1333 /* |
1328 * Return TRUE if "channel" can be written to. | 1334 * Return TRUE if "channel" can be written to. |
2183 } | 2189 } |
2184 if (json != NULL) | 2190 if (json != NULL) |
2185 { | 2191 { |
2186 channel_send(channel, | 2192 channel_send(channel, |
2187 part == PART_SOCK ? PART_SOCK : PART_IN, | 2193 part == PART_SOCK ? PART_SOCK : PART_IN, |
2188 json, (char *)cmd); | 2194 json, (int)STRLEN(json), (char *)cmd); |
2189 vim_free(json); | 2195 vim_free(json); |
2190 } | 2196 } |
2191 } | 2197 } |
2192 --emsg_skip; | 2198 --emsg_skip; |
2193 if (tv == &res_tv) | 2199 if (tv == &res_tv) |
3378 * Write "buf" (NUL terminated string) to "channel"/"part". | 3384 * Write "buf" (NUL terminated string) to "channel"/"part". |
3379 * When "fun" is not NULL an error message might be given. | 3385 * When "fun" is not NULL an error message might be given. |
3380 * Return FAIL or OK. | 3386 * Return FAIL or OK. |
3381 */ | 3387 */ |
3382 int | 3388 int |
3383 channel_send(channel_T *channel, int part, char_u *buf, char *fun) | 3389 channel_send(channel_T *channel, int part, char_u *buf, int len, char *fun) |
3384 { | 3390 { |
3385 int len = (int)STRLEN(buf); | |
3386 int res; | 3391 int res; |
3387 sock_T fd; | 3392 sock_T fd; |
3388 | 3393 |
3389 fd = channel->ch_part[part].ch_fd; | 3394 fd = channel->ch_part[part].ch_fd; |
3390 if (fd == INVALID_FD) | 3395 if (fd == INVALID_FD) |
3468 } | 3473 } |
3469 channel_set_req_callback(channel, part_send, | 3474 channel_set_req_callback(channel, part_send, |
3470 opt->jo_callback, opt->jo_partial, id); | 3475 opt->jo_callback, opt->jo_partial, id); |
3471 } | 3476 } |
3472 | 3477 |
3473 if (channel_send(channel, part_send, text, fun) == OK | 3478 if (channel_send(channel, part_send, text, (int)STRLEN(text), fun) == OK |
3474 && opt->jo_callback == NULL) | 3479 && opt->jo_callback == NULL) |
3475 return channel; | 3480 return channel; |
3476 return NULL; | 3481 return NULL; |
3477 } | 3482 } |
3478 | 3483 |