diff options
-rw-r--r-- | src/channel.c | 36 | ||||
-rw-r--r-- | src/misc2.c | 62 | ||||
-rw-r--r-- | src/proto/misc2.pro | 2 | ||||
-rw-r--r-- | src/terminal.c | 12 | ||||
-rw-r--r-- | src/testdir/test_terminal.vim | 6 | ||||
-rw-r--r-- | src/version.c | 2 |
6 files changed, 88 insertions, 32 deletions
diff --git a/src/channel.c b/src/channel.c index fbf1cbeb9f..359052208f 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 cf957059c2..e5b6781583 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 06e33f50c2..770bd33c41 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 ff76ca1c6c..7afc49dc16 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 158bb980c4..1b87895acb 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 af43697c11..a18394a823 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, |