Mirror of the Vim source from https://github.com/vim/vim
Revisión | 656853d9c014add434086291b7af40ad828f126a (tree) |
---|---|
Tiempo | 2006-10-03 21:44:42 |
Autor | vimboss |
Commiter | vimboss |
updated for version 7.0-111
@@ -1,6 +1,6 @@ | ||
1 | 1 | " Vim autoload file for editing compressed files. |
2 | 2 | " Maintainer: Bram Moolenaar <Bram@vim.org> |
3 | -" Last Change: 2006 Jul 19 | |
3 | +" Last Change: 2006 Oct 03 | |
4 | 4 | |
5 | 5 | " These functions are used by the gzip plugin. |
6 | 6 |
@@ -68,9 +68,9 @@ | ||
68 | 68 | let tmp = tempname() |
69 | 69 | let tmpe = tmp . "." . expand("<afile>:e") |
70 | 70 | " write the just read lines to a temp file "'[,']w tmp.gz" |
71 | - execute "silent '[,']w " . tmpe | |
71 | + execute "silent '[,']w " . escape(tmpe, ' ') | |
72 | 72 | " uncompress the temp file: call system("gzip -dn tmp.gz") |
73 | - call system(a:cmd . " " . tmpe) | |
73 | + call system(a:cmd . " " . s:escape(tmpe)) | |
74 | 74 | if !filereadable(tmp) |
75 | 75 | " uncompress didn't work! Keep the compressed file then. |
76 | 76 | echoerr "Error: Could not read uncompressed file" |
@@ -127,9 +127,9 @@ | ||
127 | 127 | let nmt = s:tempname(nm) |
128 | 128 | if rename(nm, nmt) == 0 |
129 | 129 | if exists("b:gzip_comp_arg") |
130 | - call system(a:cmd . " " . b:gzip_comp_arg . " '" . nmt . "'") | |
130 | + call system(a:cmd . " " . b:gzip_comp_arg . " " . s:escape(nmt)) | |
131 | 131 | else |
132 | - call system(a:cmd . " '" . nmt . "'") | |
132 | + call system(a:cmd . " " . s:escape(nmt)) | |
133 | 133 | endif |
134 | 134 | call rename(nmt . "." . expand("<afile>:e"), nm) |
135 | 135 | endif |
@@ -154,10 +154,10 @@ | ||
154 | 154 | if rename(nm, nmte) == 0 |
155 | 155 | if &patchmode != "" && getfsize(nm . &patchmode) == -1 |
156 | 156 | " Create patchmode file by creating the decompressed file new |
157 | - call system(a:cmd . " -c " . nmte . " > " . nmt) | |
157 | + call system(a:cmd . " -c " . s:escape(nmte) . " > " . s:escape(nmt)) | |
158 | 158 | call rename(nmte, nm . &patchmode) |
159 | 159 | else |
160 | - call system(a:cmd . " " . nmte) | |
160 | + call system(a:cmd . " " . s:escape(nmte)) | |
161 | 161 | endif |
162 | 162 | call rename(nmt, nm) |
163 | 163 | endif |
@@ -175,4 +175,12 @@ | ||
175 | 175 | return fnamemodify(a:name, ":p:h") . "/X~=@l9q5" |
176 | 176 | endfun |
177 | 177 | |
178 | +fun s:escape(name) | |
179 | + " shellescape() was added by patch 7.0.111 | |
180 | + if v:version > 700 || (v:version == 700 && has('patch111')) | |
181 | + return shellescape(a:name) | |
182 | + endif | |
183 | + return "'" . a:name . "'" | |
184 | +endfun | |
185 | + | |
178 | 186 | " vim: set sw=2 : |
@@ -1,4 +1,4 @@ | ||
1 | -*eval.txt* For Vim version 7.0. Last change: 2006 May 06 | |
1 | +*eval.txt* For Vim version 7.0. Last change: 2006 Sep 22 | |
2 | 2 | |
3 | 3 | |
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -1709,6 +1709,8 @@ | ||
1709 | 1709 | settabwinvar( {tabnr}, {winnr}, {varname}, {val}) set {varname} in window |
1710 | 1710 | {winnr} in tab page {tabnr} to {val} |
1711 | 1711 | setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val} |
1712 | +shellescape( {string}) String escape {string} for use as shell | |
1713 | + command argument | |
1712 | 1714 | simplify( {filename}) String simplify filename as much as possible |
1713 | 1715 | sort( {list} [, {func}]) List sort {list}, using {func} to compare |
1714 | 1716 | soundfold( {word}) String sound-fold {word} |
@@ -4434,6 +4436,21 @@ | ||
4434 | 4436 | :call setwinvar(1, "&list", 0) |
4435 | 4437 | :call setwinvar(2, "myvar", "foobar") |
4436 | 4438 | |
4439 | +shellescape({string}) *shellescape()* | |
4440 | + Escape {string} for use as shell command argument. | |
4441 | + On MS-Windows and MS-DOS, when 'shellslash' is not set, it | |
4442 | + will enclose {string} double quotes and double all double | |
4443 | + quotes within {string}. | |
4444 | + For other systems, it will enclose {string} in single quotes | |
4445 | + and replace all "'" with "'\''". | |
4446 | + Example: > | |
4447 | + :echo shellescape('c:\program files\vim') | |
4448 | +< results in: | |
4449 | + "c:\program files\vim" ~ | |
4450 | + Example usage: > | |
4451 | + :call system("chmod +x -- " . shellescape(expand("%"))) | |
4452 | + | |
4453 | + | |
4437 | 4454 | simplify({filename}) *simplify()* |
4438 | 4455 | Simplify the file name as much as possible without changing |
4439 | 4456 | the meaning. Shortcuts (on MS-Windows) or symbolic links (on |
@@ -622,6 +622,7 @@ | ||
622 | 622 | static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv)); |
623 | 623 | static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv)); |
624 | 624 | static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv)); |
625 | +static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv)); | |
625 | 626 | static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv)); |
626 | 627 | static void f_sort __ARGS((typval_T *argvars, typval_T *rettv)); |
627 | 628 | static void f_soundfold __ARGS((typval_T *argvars, typval_T *rettv)); |
@@ -7146,6 +7147,7 @@ | ||
7146 | 7147 | {"setreg", 2, 3, f_setreg}, |
7147 | 7148 | {"settabwinvar", 4, 4, f_settabwinvar}, |
7148 | 7149 | {"setwinvar", 3, 3, f_setwinvar}, |
7150 | + {"shellescape", 1, 1, f_shellescape}, | |
7149 | 7151 | {"simplify", 1, 1, f_simplify}, |
7150 | 7152 | {"sort", 1, 2, f_sort}, |
7151 | 7153 | {"soundfold", 1, 1, f_soundfold}, |
@@ -14605,6 +14607,18 @@ | ||
14605 | 14607 | } |
14606 | 14608 | |
14607 | 14609 | /* |
14610 | + * "shellescape({string})" function | |
14611 | + */ | |
14612 | + static void | |
14613 | +f_shellescape(argvars, rettv) | |
14614 | + typval_T *argvars; | |
14615 | + typval_T *rettv; | |
14616 | +{ | |
14617 | + rettv->vval.v_string = vim_strsave_shellescape(get_tv_string(&argvars[0])); | |
14618 | + rettv->v_type = VAR_STRING; | |
14619 | +} | |
14620 | + | |
14621 | +/* | |
14608 | 14622 | * "simplify()" function |
14609 | 14623 | */ |
14610 | 14624 | static void |
@@ -1229,6 +1229,94 @@ | ||
1229 | 1229 | return escaped_string; |
1230 | 1230 | } |
1231 | 1231 | |
1232 | +#if defined(FEAT_EVAL) || defined(PROTO) | |
1233 | +/* | |
1234 | + * Escape "string" for use as a shell argument with system(). | |
1235 | + * This uses single quotes, except when we know we need to use double qoutes | |
1236 | + * (MS-DOS and MS-Windows without 'shellslash' set). | |
1237 | + * Returns the result in allocated memory, NULL if we have run out. | |
1238 | + */ | |
1239 | + char_u * | |
1240 | +vim_strsave_shellescape(string) | |
1241 | + char_u *string; | |
1242 | +{ | |
1243 | + unsigned length; | |
1244 | + char_u *p; | |
1245 | + char_u *d; | |
1246 | + char_u *escaped_string; | |
1247 | + | |
1248 | + /* First count the number of extra bytes required. */ | |
1249 | + length = STRLEN(string) + 3; /* two quotes and the trailing NUL */ | |
1250 | + for (p = string; *p != NUL; mb_ptr_adv(p)) | |
1251 | + { | |
1252 | +# if defined(WIN32) || defined(WIN16) || defined(DOS) | |
1253 | + if (!p_ssl) | |
1254 | + { | |
1255 | + if (*p == '"') | |
1256 | + ++length; /* " -> "" */ | |
1257 | + } | |
1258 | + else | |
1259 | +# endif | |
1260 | + if (*p == '\'') | |
1261 | + length += 3; /* ' => '\'' */ | |
1262 | + } | |
1263 | + | |
1264 | + /* Allocate memory for the result and fill it. */ | |
1265 | + escaped_string = alloc(length); | |
1266 | + if (escaped_string != NULL) | |
1267 | + { | |
1268 | + d = escaped_string; | |
1269 | + | |
1270 | + /* add opening quote */ | |
1271 | +# if defined(WIN32) || defined(WIN16) || defined(DOS) | |
1272 | + if (!p_ssl) | |
1273 | + *d++ = '"'; | |
1274 | + else | |
1275 | +# endif | |
1276 | + *d++ = '\''; | |
1277 | + | |
1278 | + for (p = string; *p != NUL; ) | |
1279 | + { | |
1280 | +# if defined(WIN32) || defined(WIN16) || defined(DOS) | |
1281 | + if (!p_ssl) | |
1282 | + { | |
1283 | + if (*p == '"') | |
1284 | + { | |
1285 | + *d++ = '"'; | |
1286 | + *d++ = '"'; | |
1287 | + ++p; | |
1288 | + continue; | |
1289 | + } | |
1290 | + } | |
1291 | + else | |
1292 | +# endif | |
1293 | + if (*p == '\'') | |
1294 | + { | |
1295 | + *d++='\''; | |
1296 | + *d++='\\'; | |
1297 | + *d++='\''; | |
1298 | + *d++='\''; | |
1299 | + ++p; | |
1300 | + continue; | |
1301 | + } | |
1302 | + | |
1303 | + MB_COPY_CHAR(p, d); | |
1304 | + } | |
1305 | + | |
1306 | + /* add terminating quote and finish with a NUL */ | |
1307 | +# if defined(WIN32) || defined(WIN16) || defined(DOS) | |
1308 | + if (!p_ssl) | |
1309 | + *d++ = '"'; | |
1310 | + else | |
1311 | +# endif | |
1312 | + *d++ = '\''; | |
1313 | + *d = NUL; | |
1314 | + } | |
1315 | + | |
1316 | + return escaped_string; | |
1317 | +} | |
1318 | +#endif | |
1319 | + | |
1232 | 1320 | /* |
1233 | 1321 | * Like vim_strsave(), but make all characters uppercase. |
1234 | 1322 | * This uses ASCII lower-to-upper case translation, language independent. |
@@ -29,6 +29,7 @@ | ||
29 | 29 | extern char_u *vim_strnsave __ARGS((char_u *string, int len)); |
30 | 30 | extern char_u *vim_strsave_escaped __ARGS((char_u *string, char_u *esc_chars)); |
31 | 31 | extern char_u *vim_strsave_escaped_ext __ARGS((char_u *string, char_u *esc_chars, int cc, int bsl)); |
32 | +extern char_u *vim_strsave_shellescape __ARGS((char_u *string)); | |
32 | 33 | extern char_u *vim_strsave_up __ARGS((char_u *string)); |
33 | 34 | extern char_u *vim_strnsave_up __ARGS((char_u *string, int len)); |
34 | 35 | extern void vim_strup __ARGS((char_u *p)); |
@@ -667,6 +667,8 @@ | ||
667 | 667 | static int included_patches[] = |
668 | 668 | { /* Add new patch number below this line */ |
669 | 669 | /**/ |
670 | + 111, | |
671 | +/**/ | |
670 | 672 | 110, |
671 | 673 | /**/ |
672 | 674 | 109, |