Permalink
Browse files

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.
  • Loading branch information...
brammool committed Apr 21, 2018
1 parent a69b395 commit ebe74b73677b06db7d483987a863b41cee051cc0
Showing with 88 additions and 32 deletions.
  1. +4 −32 src/channel.c
  2. +62 −0 src/misc2.c
  3. +2 −0 src/proto/misc2.pro
  4. +12 −0 src/terminal.c
  5. +6 −0 src/testdir/test_terminal.vim
  6. +2 −0 src/version.c
@@ -5563,27 +5563,16 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
#endif
if (argvars[0].v_type == VAR_STRING)
{
char_u *cmd_copy;
/* Command is a string. */
cmd = argvars[0].vval.v_string;
if (cmd == NULL || *cmd == NUL)
{
EMSG(_(e_invarg));
goto theend;
}
/* 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);
if (build_argv_from_string(cmd, &argv, &argc) == FAIL)
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
|| argvars[0].vval.v_list == NULL
@@ -5594,27 +5583,10 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
}
else
{
list_T *l = argvars[0].vval.v_list;
listitem_T *li;
char_u *s;
list_T *l = argvars[0].vval.v_list;
/* Pass argv[] to mch_call_shell(). */
argv = (char **)alloc(sizeof(char *) * (l->lv_len + 1));
if (argv == NULL)
if (build_argv_from_list(l, &argv, &argc) == FAIL)
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
if (win32_build_cmd(l, &ga) == FAIL)
goto theend;
@@ -6513,4 +6513,66 @@ mch_parse_cmd(char_u *cmd, int use_shcf, char ***argv, int *argc)
}
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
@@ -111,4 +111,6 @@ void time_to_bytes(time_T the_time, char_u *buf);
int has_non_ascii(char_u *s);
void parse_queued_messages(void);
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 : */
@@ -5342,6 +5342,18 @@ term_and_job_init(
job = job_alloc();
if (job == NULL)
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)
job->jv_in_buf = buflist_findnr(opt->jo_io_buf[PART_IN]);
@@ -786,6 +786,12 @@ func Test_terminal_composing_unicode()
let g:job = term_getjob(buf)
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
let txt = "a\u0308bc"
call term_sendkeys(buf, "echo " . txt . "\r")
@@ -761,6 +761,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1747,
/**/
1746,
/**/

0 comments on commit ebe74b7

Please sign in to comment.