patch 7.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.
diff --git a/src/eval.c b/src/eval.c
index ece87de..4a939a7 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -503,8 +503,10 @@
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_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 @@
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 @@
#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 @@
{"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 @@
}
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 @@
}
/*
+ * "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 @@
}
/*
+ * "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 @@
#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 @@
* "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;