comparison src/channel.c @ 8386:3b9a306724ec v7.4.1485

commit https://github.com/vim/vim/commit/014069a7ac51557e531eb3c8b94e36f2193f6c21 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 3 22:51:40 2016 +0100 patch 7.4.1485 Problem: Job input from buffer is not implemented. Solution: Implement it. Add "in-top" and "in-bot" options.
author Christian Brabandt <cb@256bit.org>
date Thu, 03 Mar 2016 23:00:05 +0100
parents 3dbe93a240d8
children 8894d595b786
comparison
equal deleted inserted replaced
8385:4ee533cc650f 8386:3b9a306724ec
817 channel->CH_ERR_FD = err; 817 channel->CH_ERR_FD = err;
818 } 818 }
819 #endif 819 #endif
820 820
821 /* 821 /*
822 * Sets the job the channel is associated with. 822 * Sets the job the channel is associated with and associated options.
823 * This does not keep a refcount, when the job is freed ch_job is cleared. 823 * This does not keep a refcount, when the job is freed ch_job is cleared.
824 */ 824 */
825 void 825 void
826 channel_set_job(channel_T *channel, job_T *job) 826 channel_set_job(channel_T *channel, job_T *job, jobopt_T *options)
827 { 827 {
828 channel->ch_job = job; 828 channel->ch_job = job;
829
830 channel_set_options(channel, options);
831
832 if (job->jv_in_buf != NULL)
833 {
834 chanpart_T *in_part = &channel->ch_part[PART_IN];
835
836 in_part->ch_buffer = job->jv_in_buf;
837 ch_logs(channel, "reading from buffer '%s'",
838 (char *)in_part->ch_buffer->b_ffname);
839 if (options->jo_set & JO_IN_TOP)
840 in_part->ch_buf_top = options->jo_in_top;
841 else
842 in_part->ch_buf_top = 1;
843 if (options->jo_set & JO_IN_BOT)
844 in_part->ch_buf_bot = options->jo_in_bot;
845 else
846 in_part->ch_buf_bot = in_part->ch_buffer->b_ml.ml_line_count;
847 }
829 } 848 }
830 849
831 /* 850 /*
832 * Find a buffer matching "name" or create a new one. 851 * Find a buffer matching "name" or create a new one.
833 */ 852 */
959 if (item->cq_prev == NULL) 978 if (item->cq_prev == NULL)
960 head->cq_next = item; 979 head->cq_next = item;
961 else 980 else
962 item->cq_prev->cq_next = item; 981 item->cq_prev->cq_next = item;
963 } 982 }
983 }
984
985 /*
986 * Write any lines to the in channel.
987 */
988 void
989 channel_write_in(channel_T *channel)
990 {
991 chanpart_T *in_part = &channel->ch_part[PART_IN];
992 linenr_T lnum;
993 buf_T *buf = in_part->ch_buffer;
994
995 if (buf == NULL)
996 return;
997 if (!buf_valid(buf) || buf->b_ml.ml_mfp == NULL)
998 {
999 /* buffer was wiped out or unloaded */
1000 in_part->ch_buffer = NULL;
1001 return;
1002 }
1003 if (in_part->ch_fd == INVALID_FD)
1004 /* pipe was closed */
1005 return;
1006
1007 for (lnum = in_part->ch_buf_top; lnum <= in_part->ch_buf_bot
1008 && lnum <= buf->b_ml.ml_line_count; ++lnum)
1009 {
1010 char_u *line = ml_get_buf(buf, lnum, FALSE);
1011 int len = STRLEN(line);
1012 char_u *p;
1013
1014 /* TODO: check if channel can be written to */
1015 if ((p = alloc(len + 2)) == NULL)
1016 break;
1017 STRCPY(p, line);
1018 p[len] = NL;
1019 p[len + 1] = NUL;
1020 channel_send(channel, PART_IN, p, "channel_write_in()");
1021 vim_free(p);
1022 }
1023 in_part->ch_buf_top = lnum;
964 } 1024 }
965 1025
966 /* 1026 /*
967 * Invoke the "callback" on channel "channel". 1027 * Invoke the "callback" on channel "channel".
968 */ 1028 */