forked from aniani/vim
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.
This commit is contained in:
78
src/eval.c
78
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;
|
||||
@@ -9824,6 +9832,32 @@ get_callback(typval_T *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* "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
|
||||
*/
|
||||
@@ -9913,6 +9947,27 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
|
||||
rettv->vval.v_number = ch_idx;
|
||||
}
|
||||
|
||||
/*
|
||||
* "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.
|
||||
@@ -14299,6 +14354,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
|
||||
*/
|
||||
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user