diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-02-13 17:04:46 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-02-13 17:04:46 +0100 |
commit | 6463ca229cb9412581419497924c85fcbfc854ab (patch) | |
tree | 6c55cc23cf038e6f80ea954e670c691e72dc515a /src/eval.c | |
parent | 00af60bbb6cc7e8ccafddb30a1964f891b800bce (diff) | |
download | vim-git-6463ca229cb9412581419497924c85fcbfc854ab.tar.gz |
patch 7.4.1310v7.4.1310
Problem: Jobs don't open a channel.
Solution: Create pipes and add them to the channel. Add ch_logfile().
Only Unix for now.
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/src/eval.c b/src/eval.c index ece87def4..4a939a751 100644 --- a/src/eval.c +++ b/src/eval.c @@ -503,8 +503,10 @@ static void f_call(typval_T *argvars, typval_T *rettv); static void f_ceil(typval_T *argvars, typval_T *rettv); #endif #ifdef FEAT_CHANNEL -static void f_ch_open(typval_T *argvars, typval_T *rettv); static void f_ch_close(typval_T *argvars, typval_T *rettv); +static void f_ch_logfile(typval_T *argvars, typval_T *rettv); +static void f_ch_open(typval_T *argvars, typval_T *rettv); +static void f_ch_readraw(typval_T *argvars, typval_T *rettv); static void f_ch_sendexpr(typval_T *argvars, typval_T *rettv); static void f_ch_sendraw(typval_T *argvars, typval_T *rettv); #endif @@ -624,6 +626,7 @@ static void f_isdirectory(typval_T *argvars, typval_T *rettv); static void f_islocked(typval_T *argvars, typval_T *rettv); static void f_items(typval_T *argvars, typval_T *rettv); #ifdef FEAT_JOB +static void f_job_getchannel(typval_T *argvars, typval_T *rettv); static void f_job_start(typval_T *argvars, typval_T *rettv); static void f_job_stop(typval_T *argvars, typval_T *rettv); static void f_job_status(typval_T *argvars, typval_T *rettv); @@ -7720,6 +7723,8 @@ failret: static void job_free(job_T *job) { + if (job->jv_channel >= 0) + channel_close(job->jv_channel); mch_clear_job(job); vim_free(job); } @@ -8083,7 +8088,9 @@ static struct fst #endif #ifdef FEAT_CHANNEL {"ch_close", 1, 1, f_ch_close}, + {"ch_logfile", 1, 2, f_ch_logfile}, {"ch_open", 1, 2, f_ch_open}, + {"ch_readraw", 1, 2, f_ch_readraw}, {"ch_sendexpr", 2, 3, f_ch_sendexpr}, {"ch_sendraw", 2, 3, f_ch_sendraw}, #endif @@ -8207,6 +8214,7 @@ static struct fst {"islocked", 1, 1, f_islocked}, {"items", 1, 1, f_items}, #ifdef FEAT_JOB + {"job_getchannel", 1, 1, f_job_getchannel}, {"job_start", 1, 2, f_job_start}, {"job_status", 1, 1, f_job_status}, {"job_stop", 1, 2, f_job_stop}, @@ -9788,7 +9796,7 @@ get_channel_arg(typval_T *tv) } ch_idx = tv->vval.v_number; - if (!channel_is_open(ch_idx)) + if (!channel_can_write_to(ch_idx)) { EMSGN(_("E906: not an open channel"), ch_idx); return -1; @@ -9825,6 +9833,32 @@ get_callback(typval_T *arg) } /* + * "ch_logfile()" function + */ + static void +f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED) +{ + char_u *fname; + char_u *opt = (char_u *)""; + char_u buf[NUMBUFLEN]; + FILE *file = NULL; + + fname = get_tv_string(&argvars[0]); + if (argvars[1].v_type == VAR_STRING) + opt = get_tv_string_buf(&argvars[1], buf); + if (*fname != NUL) + { + file = fopen((char *)fname, *opt == 'w' ? "w" : "a"); + if (file == NULL) + { + EMSG2(_(e_notopen), fname); + return; + } + } + ch_logfile(file); +} + +/* * "ch_open()" function */ static void @@ -9914,6 +9948,27 @@ f_ch_open(typval_T *argvars, typval_T *rettv) } /* + * "ch_readraw()" function + */ + static void +f_ch_readraw(typval_T *argvars, typval_T *rettv) +{ + int ch_idx; + + /* return an empty string by default */ + rettv->v_type = VAR_STRING; + rettv->vval.v_string = NULL; + + ch_idx = get_channel_arg(&argvars[0]); + if (ch_idx < 0) + { + EMSG(_(e_invarg)); + return; + } + rettv->vval.v_string = channel_read_block(ch_idx); +} + +/* * common for "sendexpr()" and "sendraw()" * Returns the channel index if the caller should read the response. * Otherwise returns -1. @@ -14300,6 +14355,23 @@ f_items(typval_T *argvars, typval_T *rettv) #ifdef FEAT_JOB /* + * "job_getchannel()" function + */ + static void +f_job_getchannel(typval_T *argvars, typval_T *rettv) +{ + if (argvars[0].v_type != VAR_JOB) + EMSG(_(e_invarg)); + else + { + job_T *job = argvars[0].vval.v_job; + + rettv->v_type = VAR_NUMBER; + rettv->vval.v_number = job->jv_channel; + } +} + +/* * "job_start()" function */ static void @@ -14401,7 +14473,7 @@ theend: * "job_status()" function */ static void -f_job_status(typval_T *argvars UNUSED, typval_T *rettv UNUSED) +f_job_status(typval_T *argvars, typval_T *rettv) { char *result; |