Mirror of the Vim source from https://github.com/vim/vim
Revision | 553c97222cc0d0adb7beecd6f73be1c512f2f37c (tree) |
---|---|
Time | 2008-07-17 05:43:37 |
Author | vimboss |
Commiter | vimboss |
updated for version 7.2b-005
@@ -1262,7 +1262,9 @@ | ||
1262 | 1262 | * Escape "string" for use as a shell argument with system(). |
1263 | 1263 | * This uses single quotes, except when we know we need to use double qoutes |
1264 | 1264 | * (MS-DOS and MS-Windows without 'shellslash' set). |
1265 | - * Also replace "%", "#" and things like "<cfile>" when "do_special" is TRUE. | |
1265 | + * Escape a newline, depending on the 'shell' option. | |
1266 | + * When "do_special" is TRUE also replace "!", "%", "#" and things starting | |
1267 | + * with "<" like "<cfile>". | |
1266 | 1268 | * Returns the result in allocated memory, NULL if we have run out. |
1267 | 1269 | */ |
1268 | 1270 | char_u * |
@@ -1275,6 +1277,13 @@ | ||
1275 | 1277 | char_u *d; |
1276 | 1278 | char_u *escaped_string; |
1277 | 1279 | int l; |
1280 | + int csh_like; | |
1281 | + | |
1282 | + /* Only csh and similar shells expand '!' within single quotes. For sh and | |
1283 | + * the like we must not put a backslash before it, it will be taken | |
1284 | + * literally. If do_special is set the '!' will be escaped twice. | |
1285 | + * Csh also needs to have "\n" escaped twice when do_special is set. */ | |
1286 | + csh_like = (strstr((char *)gettail(p_sh), "csh") != NULL); | |
1278 | 1287 | |
1279 | 1288 | /* First count the number of extra bytes required. */ |
1280 | 1289 | length = (unsigned)STRLEN(string) + 3; /* two quotes and a trailing NUL */ |
@@ -1290,6 +1299,12 @@ | ||
1290 | 1299 | # endif |
1291 | 1300 | if (*p == '\'') |
1292 | 1301 | length += 3; /* ' => '\'' */ |
1302 | + if (*p == '\n' || (*p == '!' && (csh_like || do_special))) | |
1303 | + { | |
1304 | + ++length; /* insert backslash */ | |
1305 | + if (csh_like && do_special) | |
1306 | + ++length; /* insert backslash */ | |
1307 | + } | |
1293 | 1308 | if (do_special && find_cmdline_var(p, &l) >= 0) |
1294 | 1309 | { |
1295 | 1310 | ++length; /* insert backslash */ |
@@ -1335,6 +1350,14 @@ | ||
1335 | 1350 | ++p; |
1336 | 1351 | continue; |
1337 | 1352 | } |
1353 | + if (*p == '\n' || (*p == '!' && (csh_like || do_special))) | |
1354 | + { | |
1355 | + *d++ = '\\'; | |
1356 | + if (csh_like && do_special) | |
1357 | + *d++ = '\\'; | |
1358 | + *d++ = *p++; | |
1359 | + continue; | |
1360 | + } | |
1338 | 1361 | if (do_special && find_cmdline_var(p, &l) >= 0) |
1339 | 1362 | { |
1340 | 1363 | *d++ = '\\'; /* insert backslash */ |
@@ -677,6 +677,8 @@ | ||
677 | 677 | static int included_patches[] = |
678 | 678 | { /* Add new patch number below this line */ |
679 | 679 | /**/ |
680 | + 5, | |
681 | +/**/ | |
680 | 682 | 4, |
681 | 683 | /**/ |
682 | 684 | 3, |