Mirror of the Vim source from https://github.com/vim/vim
Revision | c89903e16772bebee28ec935f7459c8c83bdf05e (tree) |
---|---|
Time | 2008-01-13 21:54:11 |
Author | vimboss |
Commiter | vimboss |
updated for version 7.1-223
@@ -4946,6 +4946,9 @@ | ||
4946 | 4946 | char_u *p; |
4947 | 4947 | int dir; |
4948 | 4948 | #ifdef __EMX__ |
4949 | + /* | |
4950 | + * This is the OS/2 implementation. | |
4951 | + */ | |
4949 | 4952 | # define EXPL_ALLOC_INC 16 |
4950 | 4953 | char_u **expl_files; |
4951 | 4954 | size_t files_alloced, files_free; |
@@ -5056,20 +5059,26 @@ | ||
5056 | 5059 | return OK; |
5057 | 5060 | |
5058 | 5061 | #else /* __EMX__ */ |
5059 | - | |
5062 | + /* | |
5063 | + * This is the non-OS/2 implementation (really Unix). | |
5064 | + */ | |
5060 | 5065 | int j; |
5061 | 5066 | char_u *tempname; |
5062 | 5067 | char_u *command; |
5063 | 5068 | FILE *fd; |
5064 | 5069 | char_u *buffer; |
5065 | -#define STYLE_ECHO 0 /* use "echo" to expand */ | |
5066 | -#define STYLE_GLOB 1 /* use "glob" to expand, for csh */ | |
5067 | -#define STYLE_PRINT 2 /* use "print -N" to expand, for zsh */ | |
5068 | -#define STYLE_BT 3 /* `cmd` expansion, execute the pattern directly */ | |
5070 | +#define STYLE_ECHO 0 /* use "echo", the default */ | |
5071 | +#define STYLE_GLOB 1 /* use "glob", for csh */ | |
5072 | +#define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ | |
5073 | +#define STYLE_PRINT 3 /* use "print -N", for zsh */ | |
5074 | +#define STYLE_BT 4 /* `cmd` expansion, execute the pattern | |
5075 | + * directly */ | |
5069 | 5076 | int shell_style = STYLE_ECHO; |
5070 | 5077 | int check_spaces; |
5071 | 5078 | static int did_find_nul = FALSE; |
5072 | 5079 | int ampersent = FALSE; |
5080 | + /* vimglob() function to define for Posix shell */ | |
5081 | + static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo -n \"$1\"; echo; shift; done }; vimglob >"; | |
5073 | 5082 | |
5074 | 5083 | *num_file = 0; /* default: no files found */ |
5075 | 5084 | *file = NULL; |
@@ -5107,9 +5116,17 @@ | ||
5107 | 5116 | |
5108 | 5117 | /* |
5109 | 5118 | * Let the shell expand the patterns and write the result into the temp |
5110 | - * file. if expanding `cmd` execute it directly. | |
5111 | - * If we use csh, glob will work better than echo. | |
5112 | - * If we use zsh, print -N will work better than glob. | |
5119 | + * file. | |
5120 | + * STYLE_BT: NL separated | |
5121 | + * If expanding `cmd` execute it directly. | |
5122 | + * STYLE_GLOB: NUL separated | |
5123 | + * If we use *csh, "glob" will work better than "echo". | |
5124 | + * STYLE_PRINT: NL or NUL separated | |
5125 | + * If we use *zsh, "print -N" will work better than "glob". | |
5126 | + * STYLE_VIMGLOB: NL separated | |
5127 | + * If we use *sh*, we define "vimglob()". | |
5128 | + * STYLE_ECHO: space separated. | |
5129 | + * A shell we don't know, stay safe and use "echo". | |
5113 | 5130 | */ |
5114 | 5131 | if (num_pat == 1 && *pat[0] == '`' |
5115 | 5132 | && (len = STRLEN(pat[0])) > 2 |
@@ -5122,9 +5139,17 @@ | ||
5122 | 5139 | else if (STRCMP(p_sh + len - 3, "zsh") == 0) |
5123 | 5140 | shell_style = STYLE_PRINT; |
5124 | 5141 | } |
5125 | - | |
5126 | - /* "unset nonomatch; print -N >" plus two is 29 */ | |
5142 | + if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh), | |
5143 | + "sh") != NULL) | |
5144 | + shell_style = STYLE_VIMGLOB; | |
5145 | + | |
5146 | + /* Compute the length of the command. We need 2 extra bytes: for the | |
5147 | + * optional '&' and for the NUL. | |
5148 | + * Worst case: "unset nonomatch; print -N >" plus two is 29 */ | |
5127 | 5149 | len = STRLEN(tempname) + 29; |
5150 | + if (shell_style == STYLE_VIMGLOB) | |
5151 | + len += STRLEN(sh_vimglob_func); | |
5152 | + | |
5128 | 5153 | for (i = 0; i < num_pat; ++i) |
5129 | 5154 | { |
5130 | 5155 | /* Count the length of the patterns in the same way as they are put in |
@@ -5183,10 +5208,14 @@ | ||
5183 | 5208 | STRCAT(command, "glob >"); |
5184 | 5209 | else if (shell_style == STYLE_PRINT) |
5185 | 5210 | STRCAT(command, "print -N >"); |
5211 | + else if (shell_style == STYLE_VIMGLOB) | |
5212 | + STRCAT(command, sh_vimglob_func); | |
5186 | 5213 | else |
5187 | 5214 | STRCAT(command, "echo >"); |
5188 | 5215 | } |
5216 | + | |
5189 | 5217 | STRCAT(command, tempname); |
5218 | + | |
5190 | 5219 | if (shell_style != STYLE_BT) |
5191 | 5220 | for (i = 0; i < num_pat; ++i) |
5192 | 5221 | { |
@@ -5232,8 +5261,7 @@ | ||
5232 | 5261 | if (flags & EW_SILENT) |
5233 | 5262 | show_shell_mess = FALSE; |
5234 | 5263 | if (ampersent) |
5235 | - STRCAT(command, "&"); /* put the '&' back after the | |
5236 | - redirection */ | |
5264 | + STRCAT(command, "&"); /* put the '&' after the redirection */ | |
5237 | 5265 | |
5238 | 5266 | /* |
5239 | 5267 | * Using zsh -G: If a pattern has no matches, it is just deleted from |
@@ -5265,7 +5293,7 @@ | ||
5265 | 5293 | show_shell_mess = TRUE; |
5266 | 5294 | vim_free(command); |
5267 | 5295 | |
5268 | - if (i) /* mch_call_shell() failed */ | |
5296 | + if (i != 0) /* mch_call_shell() failed */ | |
5269 | 5297 | { |
5270 | 5298 | mch_remove(tempname); |
5271 | 5299 | vim_free(tempname); |
@@ -5336,7 +5364,7 @@ | ||
5336 | 5364 | } |
5337 | 5365 | vim_free(tempname); |
5338 | 5366 | |
5339 | -#if defined(__CYGWIN__) || defined(__CYGWIN32__) | |
5367 | +# if defined(__CYGWIN__) || defined(__CYGWIN32__) | |
5340 | 5368 | /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ |
5341 | 5369 | p = buffer; |
5342 | 5370 | for (i = 0; i < len; ++i) |
@@ -5359,7 +5387,7 @@ | ||
5359 | 5387 | } |
5360 | 5388 | } |
5361 | 5389 | /* file names are separated with NL */ |
5362 | - else if (shell_style == STYLE_BT) | |
5390 | + else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) | |
5363 | 5391 | { |
5364 | 5392 | buffer[len] = NUL; /* make sure the buffer ends in NUL */ |
5365 | 5393 | p = buffer; |
@@ -5438,7 +5466,8 @@ | ||
5438 | 5466 | { |
5439 | 5467 | (*file)[i] = p; |
5440 | 5468 | /* Space or NL separates */ |
5441 | - if (shell_style == STYLE_ECHO || shell_style == STYLE_BT) | |
5469 | + if (shell_style == STYLE_ECHO || shell_style == STYLE_BT | |
5470 | + || shell_style == STYLE_VIMGLOB) | |
5442 | 5471 | { |
5443 | 5472 | while (!(shell_style == STYLE_ECHO && *p == ' ') |
5444 | 5473 | && *p != '\n' && *p != NUL) |
@@ -667,6 +667,8 @@ | ||
667 | 667 | static int included_patches[] = |
668 | 668 | { /* Add new patch number below this line */ |
669 | 669 | /**/ |
670 | + 223, | |
671 | +/**/ | |
670 | 672 | 222, |
671 | 673 | /**/ |
672 | 674 | 221, |