summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2006-10-03 12:44:42 +0000
committerBram Moolenaar <Bram@vim.org>2006-10-03 12:44:42 +0000
commit60a495f02e7dec1db1776d8344cdd4da6a52a41f (patch)
tree11780489e9a53453161dd96e55dc36ed1db2614a
parent89f3727bd9d8097336f763d9cdbe8d6055cab7c1 (diff)
downloadvim-60a495f02e7dec1db1776d8344cdd4da6a52a41f.zip
updated for version 7.0-111
-rw-r--r--runtime/autoload/gzip.vim22
-rw-r--r--runtime/doc/eval.txt19
-rw-r--r--src/eval.c14
-rw-r--r--src/misc2.c88
-rw-r--r--src/proto/misc2.pro1
-rw-r--r--src/version.c2
6 files changed, 138 insertions, 8 deletions
diff --git a/runtime/autoload/gzip.vim b/runtime/autoload/gzip.vim
index 1e119a455..933d83d09 100644
--- a/runtime/autoload/gzip.vim
+++ b/runtime/autoload/gzip.vim
@@ -1,6 +1,6 @@
" Vim autoload file for editing compressed files.
" Maintainer: Bram Moolenaar <Bram@vim.org>
-" Last Change: 2006 Jul 19
+" Last Change: 2006 Oct 03
" These functions are used by the gzip plugin.
@@ -68,9 +68,9 @@ fun gzip#read(cmd)
let tmp = tempname()
let tmpe = tmp . "." . expand("<afile>:e")
" write the just read lines to a temp file "'[,']w tmp.gz"
- execute "silent '[,']w " . tmpe
+ execute "silent '[,']w " . escape(tmpe, ' ')
" uncompress the temp file: call system("gzip -dn tmp.gz")
- call system(a:cmd . " " . tmpe)
+ call system(a:cmd . " " . s:escape(tmpe))
if !filereadable(tmp)
" uncompress didn't work! Keep the compressed file then.
echoerr "Error: Could not read uncompressed file"
@@ -127,9 +127,9 @@ fun gzip#write(cmd)
let nmt = s:tempname(nm)
if rename(nm, nmt) == 0
if exists("b:gzip_comp_arg")
- call system(a:cmd . " " . b:gzip_comp_arg . " '" . nmt . "'")
+ call system(a:cmd . " " . b:gzip_comp_arg . " " . s:escape(nmt))
else
- call system(a:cmd . " '" . nmt . "'")
+ call system(a:cmd . " " . s:escape(nmt))
endif
call rename(nmt . "." . expand("<afile>:e"), nm)
endif
@@ -154,10 +154,10 @@ fun gzip#appre(cmd)
if rename(nm, nmte) == 0
if &patchmode != "" && getfsize(nm . &patchmode) == -1
" Create patchmode file by creating the decompressed file new
- call system(a:cmd . " -c " . nmte . " > " . nmt)
+ call system(a:cmd . " -c " . s:escape(nmte) . " > " . s:escape(nmt))
call rename(nmte, nm . &patchmode)
else
- call system(a:cmd . " " . nmte)
+ call system(a:cmd . " " . s:escape(nmte))
endif
call rename(nmt, nm)
endif
@@ -175,4 +175,12 @@ fun s:tempname(name)
return fnamemodify(a:name, ":p:h") . "/X~=@l9q5"
endfun
+fun s:escape(name)
+ " shellescape() was added by patch 7.0.111
+ if v:version > 700 || (v:version == 700 && has('patch111'))
+ return shellescape(a:name)
+ endif
+ return "'" . a:name . "'"
+endfun
+
" vim: set sw=2 :
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 939e7849b..caafd75ac 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1,4 +1,4 @@
-*eval.txt* For Vim version 7.0. Last change: 2006 May 06
+*eval.txt* For Vim version 7.0. Last change: 2006 Sep 22
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1709,6 +1709,8 @@ setreg( {n}, {v}[, {opt}]) Number set register to value and type
settabwinvar( {tabnr}, {winnr}, {varname}, {val}) set {varname} in window
{winnr} in tab page {tabnr} to {val}
setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val}
+shellescape( {string}) String escape {string} for use as shell
+ command argument
simplify( {filename}) String simplify filename as much as possible
sort( {list} [, {func}]) List sort {list}, using {func} to compare
soundfold( {word}) String sound-fold {word}
@@ -4434,6 +4436,21 @@ setwinvar({nr}, {varname}, {val}) *setwinvar()*
:call setwinvar(1, "&list", 0)
:call setwinvar(2, "myvar", "foobar")
+shellescape({string}) *shellescape()*
+ Escape {string} for use as shell command argument.
+ On MS-Windows and MS-DOS, when 'shellslash' is not set, it
+ will enclose {string} double quotes and double all double
+ quotes within {string}.
+ For other systems, it will enclose {string} in single quotes
+ and replace all "'" with "'\''".
+ Example: >
+ :echo shellescape('c:\program files\vim')
+< results in:
+ "c:\program files\vim" ~
+ Example usage: >
+ :call system("chmod +x -- " . shellescape(expand("%")))
+
+
simplify({filename}) *simplify()*
Simplify the file name as much as possible without changing
the meaning. Shortcuts (on MS-Windows) or symbolic links (on
diff --git a/src/eval.c b/src/eval.c
index f2abba7b2..d32efaa7b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -622,6 +622,7 @@ static void f_setqflist __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv));
static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
+static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
static void f_sort __ARGS((typval_T *argvars, typval_T *rettv));
static void f_soundfold __ARGS((typval_T *argvars, typval_T *rettv));
@@ -7146,6 +7147,7 @@ static struct fst
{"setreg", 2, 3, f_setreg},
{"settabwinvar", 4, 4, f_settabwinvar},
{"setwinvar", 3, 3, f_setwinvar},
+ {"shellescape", 1, 1, f_shellescape},
{"simplify", 1, 1, f_simplify},
{"sort", 1, 2, f_sort},
{"soundfold", 1, 1, f_soundfold},
@@ -14605,6 +14607,18 @@ setwinvar(argvars, rettv, off)
}
/*
+ * "shellescape({string})" function
+ */
+ static void
+f_shellescape(argvars, rettv)
+ typval_T *argvars;
+ typval_T *rettv;
+{
+ rettv->vval.v_string = vim_strsave_shellescape(get_tv_string(&argvars[0]));
+ rettv->v_type = VAR_STRING;
+}
+
+/*
* "simplify()" function
*/
static void
diff --git a/src/misc2.c b/src/misc2.c
index 5d8042706..04f34e97c 100644
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -1229,6 +1229,94 @@ vim_strsave_escaped_ext(string, esc_chars, cc, bsl)
return escaped_string;
}
+#if defined(FEAT_EVAL) || defined(PROTO)
+/*
+ * Escape "string" for use as a shell argument with system().
+ * This uses single quotes, except when we know we need to use double qoutes
+ * (MS-DOS and MS-Windows without 'shellslash' set).
+ * Returns the result in allocated memory, NULL if we have run out.
+ */
+ char_u *
+vim_strsave_shellescape(string)
+ char_u *string;
+{
+ unsigned length;
+ char_u *p;
+ char_u *d;
+ char_u *escaped_string;
+
+ /* First count the number of extra bytes required. */
+ length = STRLEN(string) + 3; /* two quotes and the trailing NUL */
+ for (p = string; *p != NUL; mb_ptr_adv(p))
+ {
+# if defined(WIN32) || defined(WIN16) || defined(DOS)
+ if (!p_ssl)
+ {
+ if (*p == '"')
+ ++length; /* " -> "" */
+ }
+ else
+# endif
+ if (*p == '\'')
+ length += 3; /* ' => '\'' */
+ }
+
+ /* Allocate memory for the result and fill it. */
+ escaped_string = alloc(length);
+ if (escaped_string != NULL)
+ {
+ d = escaped_string;
+
+ /* add opening quote */
+# if defined(WIN32) || defined(WIN16) || defined(DOS)
+ if (!p_ssl)
+ *d++ = '"';
+ else
+# endif
+ *d++ = '\'';
+
+ for (p = string; *p != NUL; )
+ {
+# if defined(WIN32) || defined(WIN16) || defined(DOS)
+ if (!p_ssl)
+ {
+ if (*p == '"')
+ {
+ *d++ = '"';
+ *d++ = '"';
+ ++p;
+ continue;
+ }
+ }
+ else
+# endif
+ if (*p == '\'')
+ {
+ *d++='\'';
+ *d++='\\';
+ *d++='\'';
+ *d++='\'';
+ ++p;
+ continue;
+ }
+
+ MB_COPY_CHAR(p, d);
+ }
+
+ /* add terminating quote and finish with a NUL */
+# if defined(WIN32) || defined(WIN16) || defined(DOS)
+ if (!p_ssl)
+ *d++ = '"';
+ else
+# endif
+ *d++ = '\'';
+ *d = NUL;
+ }
+
+ return escaped_string;
+}
+#endif
+
/*
* Like vim_strsave(), but make all characters uppercase.
* This uses ASCII lower-to-upper case translation, language independent.
diff --git a/src/proto/misc2.pro b/src/proto/misc2.pro
index adee78737..64637db13 100644
--- a/src/proto/misc2.pro
+++ b/src/proto/misc2.pro
@@ -29,6 +29,7 @@ extern char_u *vim_strsave __ARGS((char_u *string));
extern char_u *vim_strnsave __ARGS((char_u *string, int len));
extern char_u *vim_strsave_escaped __ARGS((char_u *string, char_u *esc_chars));
extern char_u *vim_strsave_escaped_ext __ARGS((char_u *string, char_u *esc_chars, int cc, int bsl));
+extern char_u *vim_strsave_shellescape __ARGS((char_u *string));
extern char_u *vim_strsave_up __ARGS((char_u *string));
extern char_u *vim_strnsave_up __ARGS((char_u *string, int len));
extern void vim_strup __ARGS((char_u *p));
diff --git a/src/version.c b/src/version.c
index d5ba9054c..f508b37c3 100644
--- a/src/version.c
+++ b/src/version.c
@@ -667,6 +667,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 111,
+/**/
110,
/**/
109,