diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-01-08 13:26:03 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-01-08 13:26:03 +0100 |
commit | 12c4492dd35e0cd83c8816be2ec849b836109882 (patch) | |
tree | 95f4c3fe9930a7d42630659e7571175f5f2c2a22 /src/evalfunc.c | |
parent | 7069bf18e1b1b7bc7640335e07d1022b5acc9048 (diff) | |
download | vim-12c4492dd35e0cd83c8816be2ec849b836109882.zip |
patch 8.0.0151: passing buffer content to system() is clumsy
Problem: To pass buffer content to system() and systemlist() one has to
first create a string or list.
Solution: Allow passing a buffer number. (LemonBoy, closes #1240)
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r-- | src/evalfunc.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index 10f6b182e..f66fa9a8e 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -11817,7 +11817,6 @@ get_cmd_output_as_rettv( char_u *res = NULL; char_u *p; char_u *infile = NULL; - char_u buf[NUMBUFLEN]; int err = FALSE; FILE *fd; list_T *list = NULL; @@ -11831,7 +11830,7 @@ get_cmd_output_as_rettv( if (argvars[1].v_type != VAR_UNKNOWN) { /* - * Write the string to a temp file, to be used for input of the shell + * Write the text to a temp file, to be used for input of the shell * command. */ if ((infile = vim_tempname('i', TRUE)) == NULL) @@ -11846,14 +11845,42 @@ get_cmd_output_as_rettv( EMSG2(_(e_notopen), infile); goto errret; } - if (argvars[1].v_type == VAR_LIST) + if (argvars[1].v_type == VAR_NUMBER) + { + linenr_T lnum; + buf_T *buf; + + buf = buflist_findnr(argvars[1].vval.v_number); + if (buf == NULL) + { + EMSGN(_(e_nobufnr), argvars[1].vval.v_number); + goto errret; + } + + for (lnum = 1; lnum <= buf->b_ml.ml_line_count; lnum++) + { + for (p = ml_get_buf(buf, lnum, FALSE); *p != NUL; ++p) + if (putc(*p == '\n' ? NUL : *p, fd) == EOF) + { + err = TRUE; + break; + } + if (putc(NL, fd) == EOF) + { + err = TRUE; + break; + } + } + } + else if (argvars[1].v_type == VAR_LIST) { if (write_list(fd, argvars[1].vval.v_list, TRUE) == FAIL) err = TRUE; } else { - size_t len; + size_t len; + char_u buf[NUMBUFLEN]; p = get_tv_string_buf_chk(&argvars[1], buf); if (p == NULL) |