1
0
forked from aniani/vim

updated for version 7.0-111

This commit is contained in:
Bram Moolenaar
2006-10-03 12:44:42 +00:00
parent 89f3727bd9
commit 60a495f02e
6 changed files with 138 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
" Vim autoload file for editing compressed files. " Vim autoload file for editing compressed files.
" Maintainer: Bram Moolenaar <Bram@vim.org> " Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2006 Jul 19 " Last Change: 2006 Oct 03
" These functions are used by the gzip plugin. " These functions are used by the gzip plugin.
@@ -68,9 +68,9 @@ fun gzip#read(cmd)
let tmp = tempname() let tmp = tempname()
let tmpe = tmp . "." . expand("<afile>:e") let tmpe = tmp . "." . expand("<afile>:e")
" write the just read lines to a temp file "'[,']w tmp.gz" " 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") " 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) if !filereadable(tmp)
" uncompress didn't work! Keep the compressed file then. " uncompress didn't work! Keep the compressed file then.
echoerr "Error: Could not read uncompressed file" echoerr "Error: Could not read uncompressed file"
@@ -127,9 +127,9 @@ fun gzip#write(cmd)
let nmt = s:tempname(nm) let nmt = s:tempname(nm)
if rename(nm, nmt) == 0 if rename(nm, nmt) == 0
if exists("b:gzip_comp_arg") 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 else
call system(a:cmd . " '" . nmt . "'") call system(a:cmd . " " . s:escape(nmt))
endif endif
call rename(nmt . "." . expand("<afile>:e"), nm) call rename(nmt . "." . expand("<afile>:e"), nm)
endif endif
@@ -154,10 +154,10 @@ fun gzip#appre(cmd)
if rename(nm, nmte) == 0 if rename(nm, nmte) == 0
if &patchmode != "" && getfsize(nm . &patchmode) == -1 if &patchmode != "" && getfsize(nm . &patchmode) == -1
" Create patchmode file by creating the decompressed file new " 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) call rename(nmte, nm . &patchmode)
else else
call system(a:cmd . " " . nmte) call system(a:cmd . " " . s:escape(nmte))
endif endif
call rename(nmt, nm) call rename(nmt, nm)
endif endif
@@ -175,4 +175,12 @@ fun s:tempname(name)
return fnamemodify(a:name, ":p:h") . "/X~=@l9q5" return fnamemodify(a:name, ":p:h") . "/X~=@l9q5"
endfun 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 : " vim: set sw=2 :

View File

@@ -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 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 settabwinvar( {tabnr}, {winnr}, {varname}, {val}) set {varname} in window
{winnr} in tab page {tabnr} to {val} {winnr} in tab page {tabnr} to {val}
setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} 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 simplify( {filename}) String simplify filename as much as possible
sort( {list} [, {func}]) List sort {list}, using {func} to compare sort( {list} [, {func}]) List sort {list}, using {func} to compare
soundfold( {word}) String sound-fold {word} soundfold( {word}) String sound-fold {word}
@@ -4434,6 +4436,21 @@ setwinvar({nr}, {varname}, {val}) *setwinvar()*
:call setwinvar(1, "&list", 0) :call setwinvar(1, "&list", 0)
:call setwinvar(2, "myvar", "foobar") :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({filename}) *simplify()*
Simplify the file name as much as possible without changing Simplify the file name as much as possible without changing
the meaning. Shortcuts (on MS-Windows) or symbolic links (on the meaning. Shortcuts (on MS-Windows) or symbolic links (on

View File

@@ -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_setreg __ARGS((typval_T *argvars, typval_T *rettv));
static void f_settabwinvar __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_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_simplify __ARGS((typval_T *argvars, typval_T *rettv));
static void f_sort __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)); static void f_soundfold __ARGS((typval_T *argvars, typval_T *rettv));
@@ -7146,6 +7147,7 @@ static struct fst
{"setreg", 2, 3, f_setreg}, {"setreg", 2, 3, f_setreg},
{"settabwinvar", 4, 4, f_settabwinvar}, {"settabwinvar", 4, 4, f_settabwinvar},
{"setwinvar", 3, 3, f_setwinvar}, {"setwinvar", 3, 3, f_setwinvar},
{"shellescape", 1, 1, f_shellescape},
{"simplify", 1, 1, f_simplify}, {"simplify", 1, 1, f_simplify},
{"sort", 1, 2, f_sort}, {"sort", 1, 2, f_sort},
{"soundfold", 1, 1, f_soundfold}, {"soundfold", 1, 1, f_soundfold},
@@ -14604,6 +14606,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 * "simplify()" function
*/ */

View File

@@ -1229,6 +1229,94 @@ vim_strsave_escaped_ext(string, esc_chars, cc, bsl)
return escaped_string; 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. * Like vim_strsave(), but make all characters uppercase.
* This uses ASCII lower-to-upper case translation, language independent. * This uses ASCII lower-to-upper case translation, language independent.

View File

@@ -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_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 __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_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_strsave_up __ARGS((char_u *string));
extern char_u *vim_strnsave_up __ARGS((char_u *string, int len)); extern char_u *vim_strnsave_up __ARGS((char_u *string, int len));
extern void vim_strup __ARGS((char_u *p)); extern void vim_strup __ARGS((char_u *p));

View File

@@ -666,6 +666,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
111,
/**/ /**/
110, 110,
/**/ /**/