1
0
forked from aniani/vim

patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmd

Problem:    MS-Windows: term_start() does not set job_info() cmd.
Solution:   Share the code from job_start() to set jv_argv.
This commit is contained in:
Bram Moolenaar
2018-04-21 23:34:43 +02:00
parent a69b39511d
commit ebe74b7367
6 changed files with 88 additions and 32 deletions

View File

@@ -5563,8 +5563,6 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
#endif #endif
if (argvars[0].v_type == VAR_STRING) if (argvars[0].v_type == VAR_STRING)
{ {
char_u *cmd_copy;
/* Command is a string. */ /* Command is a string. */
cmd = argvars[0].vval.v_string; cmd = argvars[0].vval.v_string;
if (cmd == NULL || *cmd == NUL) if (cmd == NULL || *cmd == NUL)
@@ -5572,18 +5570,9 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
EMSG(_(e_invarg)); EMSG(_(e_invarg));
goto theend; goto theend;
} }
/* Make a copy, parsing will modify "cmd". */
cmd_copy = vim_strsave(cmd); if (build_argv_from_string(cmd, &argv, &argc) == FAIL)
if (cmd_copy == NULL
|| mch_parse_cmd(cmd_copy, FALSE, &argv, &argc) == FAIL)
{
vim_free(cmd_copy);
goto theend; goto theend;
}
for (i = 0; i < argc; i++)
argv[i] = (char *)vim_strsave((char_u *)argv[i]);
argv[argc] = NULL;
vim_free(cmd_copy);
} }
else if (argvars[0].v_type != VAR_LIST else if (argvars[0].v_type != VAR_LIST
|| argvars[0].vval.v_list == NULL || argvars[0].vval.v_list == NULL
@@ -5594,27 +5583,10 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
} }
else else
{ {
list_T *l = argvars[0].vval.v_list; list_T *l = argvars[0].vval.v_list;
listitem_T *li;
char_u *s;
/* Pass argv[] to mch_call_shell(). */ if (build_argv_from_list(l, &argv, &argc) == FAIL)
argv = (char **)alloc(sizeof(char *) * (l->lv_len + 1));
if (argv == NULL)
goto theend; goto theend;
for (li = l->lv_first; li != NULL; li = li->li_next)
{
s = get_tv_string_chk(&li->li_tv);
if (s == NULL)
{
for (i = 0; i < argc; ++i)
vim_free(argv[i]);
goto theend;
}
argv[argc++] = (char *)vim_strsave(s);
}
argv[argc] = NULL;
#ifndef USE_ARGV #ifndef USE_ARGV
if (win32_build_cmd(l, &ga) == FAIL) if (win32_build_cmd(l, &ga) == FAIL)
goto theend; goto theend;

View File

@@ -6513,4 +6513,66 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
} }
return OK; return OK;
} }
# if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
/*
* Build "argv[argc]" from the string "cmd".
* "argv[argc]" is set to NULL;
* Return FAIL when out of memory.
*/
int
build_argv_from_string(char_u *cmd, char ***argv, int *argc)
{
char_u *cmd_copy;
int i;
/* Make a copy, parsing will modify "cmd". */
cmd_copy = vim_strsave(cmd);
if (cmd_copy == NULL
|| mch_parse_cmd(cmd_copy, FALSE, argv, argc) == FAIL)
{
vim_free(cmd_copy);
return FAIL;
}
for (i = 0; i < *argc; i++)
(*argv)[i] = (char *)vim_strsave((char_u *)(*argv)[i]);
(*argv)[*argc] = NULL;
vim_free(cmd_copy);
return OK;
}
/*
* Build "argv[argc]" from the list "l".
* "argv[argc]" is set to NULL;
* Return FAIL when out of memory.
*/
int
build_argv_from_list(list_T *l, char ***argv, int *argc)
{
listitem_T *li;
char_u *s;
/* Pass argv[] to mch_call_shell(). */
*argv = (char **)alloc(sizeof(char *) * (l->lv_len + 1));
if (*argv == NULL)
return FAIL;
*argc = 0;
for (li = l->lv_first; li != NULL; li = li->li_next)
{
s = get_tv_string_chk(&li->li_tv);
if (s == NULL)
{
int i;
for (i = 0; i < *argc; ++i)
vim_free((*argv)[i]);
return FAIL;
}
(*argv)[*argc] = (char *)vim_strsave(s);
*argc += 1;
}
(*argv)[*argc] = NULL;
return OK;
}
# endif
#endif #endif

View File

@@ -111,4 +111,6 @@ void time_to_bytes(time_T the_time, char_u *buf);
int has_non_ascii(char_u *s); int has_non_ascii(char_u *s);
void parse_queued_messages(void); void parse_queued_messages(void);
int mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc); int mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc);
int build_argv_from_string(char_u *cmd, char ***argv, int *argc);
int build_argv_from_list(list_T *l, char ***argv, int *argc);
/* vim: set ft=c : */ /* vim: set ft=c : */

View File

@@ -5342,6 +5342,18 @@ term_and_job_init(
job = job_alloc(); job = job_alloc();
if (job == NULL) if (job == NULL)
goto failed; goto failed;
if (argvar->v_type == VAR_STRING)
{
int argc;
build_argv_from_string(cmd, &job->jv_argv, &argc);
}
else
{
int argc;
build_argv_from_list(argvar->vval.v_list, &job->jv_argv, &argc);
}
if (opt->jo_set & JO_IN_BUF) if (opt->jo_set & JO_IN_BUF)
job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]); job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]);

View File

@@ -786,6 +786,12 @@ func Test_terminal_composing_unicode()
let g:job = term_getjob(buf) let g:job = term_getjob(buf)
call term_wait(buf, 50) call term_wait(buf, 50)
if has('win32')
call assert_equal('cmd', job_info(g:job).cmd[0])
else
call assert_equal(&shell, job_info(g:job).cmd[0])
endif
" ascii + composing " ascii + composing
let txt = "a\u0308bc" let txt = "a\u0308bc"
call term_sendkeys(buf, "echo " . txt . "\r") call term_sendkeys(buf, "echo " . txt . "\r")

View File

@@ -761,6 +761,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1747,
/**/ /**/
1746, 1746,
/**/ /**/