Skip to content

Commit ba093bc

Browse files
committed
patch 7.4.1337
Problem: Part of the change is missing. Solution: Add changes to eval.c
1 parent 9a6e33a commit ba093bc

2 files changed

Lines changed: 63 additions & 26 deletions

File tree

src/eval.c

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7535,7 +7535,7 @@ get_dict_string(dict_T *d, char_u *key, int save)
75357535

75367536
/*
75377537
* Get a number item from a dictionary.
7538-
* Returns 0 if the entry doesn't exist or out of memory.
7538+
* Returns 0 if the entry doesn't exist.
75397539
*/
75407540
long
75417541
get_dict_number(dict_T *d, char_u *key)
@@ -9929,21 +9929,50 @@ f_ch_logfile(typval_T *argvars, typval_T *rettv UNUSED)
99299929
ch_logfile(file);
99309930
}
99319931

9932+
/*
9933+
* Get the "mode" entry from "dict", if it exists, and parse the mode name.
9934+
* If the mode is invalide return FAIL.
9935+
*/
9936+
static int
9937+
get_mode_arg(dict_T *dict, jobopt_T *opt)
9938+
{
9939+
dictitem_T *item;
9940+
char_u *mode;
9941+
9942+
if ((item = dict_find(dict, (char_u *)"mode", -1)) != NULL)
9943+
{
9944+
mode = get_tv_string(&item->di_tv);
9945+
if (STRCMP(mode, "nl") == 0)
9946+
opt->jo_mode = MODE_NL;
9947+
else if (STRCMP(mode, "raw") == 0)
9948+
opt->jo_mode = MODE_RAW;
9949+
else if (STRCMP(mode, "js") == 0)
9950+
opt->jo_mode = MODE_JS;
9951+
else if (STRCMP(mode, "json") == 0)
9952+
opt->jo_mode = MODE_JSON;
9953+
else
9954+
{
9955+
EMSG2(_(e_invarg2), mode);
9956+
return FAIL;
9957+
}
9958+
}
9959+
return OK;
9960+
}
9961+
99329962
/*
99339963
* "ch_open()" function
99349964
*/
99359965
static void
99369966
f_ch_open(typval_T *argvars, typval_T *rettv)
99379967
{
99389968
char_u *address;
9939-
char_u *mode;
99409969
char_u *callback = NULL;
99419970
char_u *p;
99429971
char *rest;
99439972
int port;
99449973
int waittime = 0;
99459974
int timeout = 2000;
9946-
ch_mode_T ch_mode = MODE_JSON;
9975+
jobopt_T options;
99479976
channel_T *channel;
99489977

99499978
/* default: fail */
@@ -9974,27 +10003,15 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
997410003
return;
997510004
}
997610005

10006+
options.jo_mode = MODE_JSON;
997710007
if (argvars[1].v_type == VAR_DICT)
997810008
{
997910009
dict_T *dict = argvars[1].vval.v_dict;
998010010
dictitem_T *item;
998110011

998210012
/* parse argdict */
9983-
if ((item = dict_find(dict, (char_u *)"mode", -1)) != NULL)
9984-
{
9985-
mode = get_tv_string(&item->di_tv);
9986-
if (STRCMP(mode, "raw") == 0)
9987-
ch_mode = MODE_RAW;
9988-
else if (STRCMP(mode, "js") == 0)
9989-
ch_mode = MODE_JS;
9990-
else if (STRCMP(mode, "json") == 0)
9991-
ch_mode = MODE_JSON;
9992-
else
9993-
{
9994-
EMSG2(_(e_invarg2), mode);
9995-
return;
9996-
}
9997-
}
10013+
if (get_mode_arg(dict, &options) == FAIL)
10014+
return;
999810015
if ((item = dict_find(dict, (char_u *)"waittime", -1)) != NULL)
999910016
waittime = get_tv_number(&item->di_tv);
1000010017
if ((item = dict_find(dict, (char_u *)"timeout", -1)) != NULL)
@@ -10012,7 +10029,7 @@ f_ch_open(typval_T *argvars, typval_T *rettv)
1001210029
if (channel != NULL)
1001310030
{
1001410031
rettv->vval.v_channel = channel;
10015-
channel_set_json_mode(channel, ch_mode);
10032+
channel_set_mode(channel, options.jo_mode);
1001610033
channel_set_timeout(channel, timeout);
1001710034
if (callback != NULL && *callback != NUL)
1001810035
channel_set_callback(channel, callback);
@@ -14473,15 +14490,16 @@ f_job_getchannel(typval_T *argvars, typval_T *rettv)
1447314490
static void
1447414491
f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
1447514492
{
14476-
job_T *job;
14477-
char_u *cmd = NULL;
14493+
job_T *job;
14494+
char_u *cmd = NULL;
1447814495
#if defined(UNIX)
1447914496
# define USE_ARGV
14480-
char **argv = NULL;
14481-
int argc = 0;
14497+
char **argv = NULL;
14498+
int argc = 0;
1448214499
#else
14483-
garray_T ga;
14500+
garray_T ga;
1448414501
#endif
14502+
jobopt_T options;
1448514503

1448614504
rettv->v_type = VAR_JOB;
1448714505
job = job_alloc();
@@ -14490,6 +14508,23 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
1449014508
return;
1449114509

1449214510
rettv->vval.v_job->jv_status = JOB_FAILED;
14511+
14512+
/* Default mode is NL. */
14513+
options.jo_mode = MODE_NL;
14514+
if (argvars[1].v_type != VAR_UNKNOWN)
14515+
{
14516+
dict_T *dict;
14517+
14518+
if (argvars[1].v_type != VAR_DICT)
14519+
{
14520+
EMSG(_(e_invarg));
14521+
return;
14522+
}
14523+
dict = argvars[1].vval.v_dict;
14524+
if (get_mode_arg(dict, &options) == FAIL)
14525+
return;
14526+
}
14527+
1449314528
#ifndef USE_ARGV
1449414529
ga_init2(&ga, (int)sizeof(char*), 20);
1449514530
#endif
@@ -14552,9 +14587,9 @@ f_job_start(typval_T *argvars UNUSED, typval_T *rettv)
1455214587
#endif
1455314588
}
1455414589
#ifdef USE_ARGV
14555-
mch_start_job(argv, job);
14590+
mch_start_job(argv, job, &options);
1455614591
#else
14557-
mch_start_job((char *)cmd, job);
14592+
mch_start_job((char *)cmd, job, &options);
1455814593
#endif
1455914594

1456014595
theend:

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ static char *(features[]) =
747747

748748
static int included_patches[] =
749749
{ /* Add new patch number below this line */
750+
/**/
751+
1337,
750752
/**/
751753
1336,
752754
/**/

0 commit comments

Comments
 (0)