summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-04-21 23:34:43 +0200
committerBram Moolenaar <Bram@vim.org>2018-04-21 23:34:43 +0200
commitebe74b73677b06db7d483987a863b41cee051cc0 (patch)
tree845132a5cdf2177e0d45e500e08443f57b3a3bf4
parenta69b39511d769bc88f0854bd026556fdb9bd2817 (diff)
downloadvim-git-ebe74b73677b06db7d483987a863b41cee051cc0.tar.gz
patch 8.0.1747: MS-Windows: term_start() does not set job_info() cmdv8.0.1747
Problem: MS-Windows: term_start() does not set job_info() cmd. Solution: Share the code from job_start() to set jv_argv.
-rw-r--r--src/channel.c36
-rw-r--r--src/misc2.c62
-rw-r--r--src/proto/misc2.pro2
-rw-r--r--src/terminal.c12
-rw-r--r--src/testdir/test_terminal.vim6
-rw-r--r--src/version.c2
6 files changed, 88 insertions, 32 deletions
diff --git a/src/channel.c b/src/channel.c
index fbf1cbeb9..359052208 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -5563,8 +5563,6 @@ 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)
@@ -5572,18 +5570,9 @@ job_start(typval_T *argvars, char **argv_arg, jobopt_T *opt_arg)
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;
diff --git a/src/misc2.c b/src/misc2.c
index cf957059c..e5b678158 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -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
diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro
index 06e33f50c..770bd33c4 100644
--- a/src/proto/misc2.pro
+++ b/src/proto/misc2.pro
@@ -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 : */
diff --git a/src/terminal.c b/src/terminal.c
index ff76ca1c6..7afc49dc1 100644
--- a/src/terminal.c
+++ b/src/terminal.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]);
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 158bb980c..1b87895ac 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -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")
diff --git a/src/version.c b/src/version.c
index af43697c1..a18394a82 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1747,
+/**/
1746,
/**/
1745,