diff options
author | Bram Moolenaar <Bram@vim.org> | 2004-09-13 20:26:32 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2004-09-13 20:26:32 +0000 |
commit | c0197e2815208269fa9ba2fba95230138ec39ceb (patch) | |
tree | 21db1c3acd16fb095a8e34ce2e15ed87275cbd79 /src/eval.c | |
parent | 15d0a8c77dad867b69822e2fd8f9f6bbcf765c48 (diff) |
updated for version 7.0016v7.0016
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/src/eval.c b/src/eval.c index 756c5fe75a..df83da5a8a 100644 --- a/src/eval.c +++ b/src/eval.c @@ -2933,7 +2933,7 @@ static struct fst {"synID", 3, 3, f_synID}, {"synIDattr", 2, 3, f_synIDattr}, {"synIDtrans", 1, 1, f_synIDtrans}, - {"system", 1, 1, f_system}, + {"system", 1, 2, f_system}, {"tempname", 0, 0, f_tempname}, {"tolower", 1, 1, f_tolower}, {"toupper", 1, 1, f_toupper}, @@ -7570,16 +7570,52 @@ f_system(argvars, retvar) VAR argvars; VAR retvar; { + char_u *res = NULL; char_u *p; + char_u *infile = NULL; + char_u buf[NUMBUFLEN]; + int err = FALSE; + FILE *fd; + + if (argvars[1].var_type != VAR_UNKNOWN) + { + /* + * Write the string to a temp file, to be used for input of the shell + * command. + */ + if ((infile = vim_tempname('i')) == NULL) + { + EMSG(_(e_notmp)); + return; + } + + fd = mch_fopen((char *)infile, WRITEBIN); + if (fd == NULL) + { + EMSG2(_(e_notopen), infile); + goto done; + } + p = get_var_string_buf(&argvars[1], buf); + if (fwrite(p, STRLEN(p), 1, fd) != 1) + err = TRUE; + if (fclose(fd) != 0) + err = TRUE; + if (err) + { + EMSG(_("E677: Error writing temp file")); + goto done; + } + } + + res = get_cmd_output(get_var_string(&argvars[0]), infile, SHELL_SILENT); - p = get_cmd_output(get_var_string(&argvars[0]), SHELL_SILENT); #ifdef USE_CR /* translate <CR> into <NL> */ - if (p != NULL) + if (res != NULL) { char_u *s; - for (s = p; *s; ++s) + for (s = res; *s; ++s) { if (*s == CAR) *s = NL; @@ -7588,12 +7624,12 @@ f_system(argvars, retvar) #else # ifdef USE_CRNL /* translate <CR><NL> into <NL> */ - if (p != NULL) + if (res != NULL) { char_u *s, *d; - d = p; - for (s = p; *s; ++s) + d = res; + for (s = res; *s; ++s) { if (s[0] == CAR && s[1] == NL) ++s; @@ -7603,8 +7639,15 @@ f_system(argvars, retvar) } # endif #endif + +done: + if (infile != NULL) + { + mch_remove(infile); + vim_free(infile); + } retvar->var_type = VAR_STRING; - retvar->var_val.var_string = p; + retvar->var_val.var_string = res; } /* |