]>
Commit | Line | Data |
---|---|---|
d57b4abe ER |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.1.223 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.1.223 | |
11 | Problem: glob() doesn't work properly when 'shell' is "sh" or "bash" and | |
12 | the expanded name contains spaces, '~', single quotes and other | |
13 | special characters. (Adri Verhoef, Charles Campbell) | |
14 | Solution: For Posix shells define a vimglob() function to list the matches | |
15 | instead of using "echo" directly. | |
16 | Files: src/os_unix.c | |
17 | ||
18 | ||
19 | *** ../vim-7.1.222/src/os_unix.c Thu Jan 3 18:55:21 2008 | |
20 | --- src/os_unix.c Sun Jan 13 13:52:53 2008 | |
21 | *************** | |
22 | *** 4946,4951 **** | |
23 | --- 4946,4954 ---- | |
24 | char_u *p; | |
25 | int dir; | |
26 | #ifdef __EMX__ | |
27 | + /* | |
28 | + * This is the OS/2 implementation. | |
29 | + */ | |
30 | # define EXPL_ALLOC_INC 16 | |
31 | char_u **expl_files; | |
32 | size_t files_alloced, files_free; | |
33 | *************** | |
34 | *** 5056,5075 **** | |
35 | return OK; | |
36 | ||
37 | #else /* __EMX__ */ | |
38 | ! | |
39 | int j; | |
40 | char_u *tempname; | |
41 | char_u *command; | |
42 | FILE *fd; | |
43 | char_u *buffer; | |
44 | ! #define STYLE_ECHO 0 /* use "echo" to expand */ | |
45 | ! #define STYLE_GLOB 1 /* use "glob" to expand, for csh */ | |
46 | ! #define STYLE_PRINT 2 /* use "print -N" to expand, for zsh */ | |
47 | ! #define STYLE_BT 3 /* `cmd` expansion, execute the pattern directly */ | |
48 | int shell_style = STYLE_ECHO; | |
49 | int check_spaces; | |
50 | static int did_find_nul = FALSE; | |
51 | int ampersent = FALSE; | |
52 | ||
53 | *num_file = 0; /* default: no files found */ | |
54 | *file = NULL; | |
55 | --- 5059,5084 ---- | |
56 | return OK; | |
57 | ||
58 | #else /* __EMX__ */ | |
59 | ! /* | |
60 | ! * This is the non-OS/2 implementation (really Unix). | |
61 | ! */ | |
62 | int j; | |
63 | char_u *tempname; | |
64 | char_u *command; | |
65 | FILE *fd; | |
66 | char_u *buffer; | |
67 | ! #define STYLE_ECHO 0 /* use "echo", the default */ | |
68 | ! #define STYLE_GLOB 1 /* use "glob", for csh */ | |
69 | ! #define STYLE_VIMGLOB 2 /* use "vimglob", for Posix sh */ | |
70 | ! #define STYLE_PRINT 3 /* use "print -N", for zsh */ | |
71 | ! #define STYLE_BT 4 /* `cmd` expansion, execute the pattern | |
72 | ! * directly */ | |
73 | int shell_style = STYLE_ECHO; | |
74 | int check_spaces; | |
75 | static int did_find_nul = FALSE; | |
76 | int ampersent = FALSE; | |
77 | + /* vimglob() function to define for Posix shell */ | |
78 | + static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo -n \"$1\"; echo; shift; done }; vimglob >"; | |
79 | ||
80 | *num_file = 0; /* default: no files found */ | |
81 | *file = NULL; | |
82 | *************** | |
83 | *** 5107,5115 **** | |
84 | ||
85 | /* | |
86 | * Let the shell expand the patterns and write the result into the temp | |
87 | ! * file. if expanding `cmd` execute it directly. | |
88 | ! * If we use csh, glob will work better than echo. | |
89 | ! * If we use zsh, print -N will work better than glob. | |
90 | */ | |
91 | if (num_pat == 1 && *pat[0] == '`' | |
92 | && (len = STRLEN(pat[0])) > 2 | |
93 | --- 5116,5132 ---- | |
94 | ||
95 | /* | |
96 | * Let the shell expand the patterns and write the result into the temp | |
97 | ! * file. | |
98 | ! * STYLE_BT: NL separated | |
99 | ! * If expanding `cmd` execute it directly. | |
100 | ! * STYLE_GLOB: NUL separated | |
101 | ! * If we use *csh, "glob" will work better than "echo". | |
102 | ! * STYLE_PRINT: NL or NUL separated | |
103 | ! * If we use *zsh, "print -N" will work better than "glob". | |
104 | ! * STYLE_VIMGLOB: NL separated | |
105 | ! * If we use *sh*, we define "vimglob()". | |
106 | ! * STYLE_ECHO: space separated. | |
107 | ! * A shell we don't know, stay safe and use "echo". | |
108 | */ | |
109 | if (num_pat == 1 && *pat[0] == '`' | |
110 | && (len = STRLEN(pat[0])) > 2 | |
111 | *************** | |
112 | *** 5122,5130 **** | |
113 | else if (STRCMP(p_sh + len - 3, "zsh") == 0) | |
114 | shell_style = STYLE_PRINT; | |
115 | } | |
116 | ! | |
117 | ! /* "unset nonomatch; print -N >" plus two is 29 */ | |
118 | len = STRLEN(tempname) + 29; | |
119 | for (i = 0; i < num_pat; ++i) | |
120 | { | |
121 | /* Count the length of the patterns in the same way as they are put in | |
122 | --- 5139,5155 ---- | |
123 | else if (STRCMP(p_sh + len - 3, "zsh") == 0) | |
124 | shell_style = STYLE_PRINT; | |
125 | } | |
126 | ! if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh), | |
127 | ! "sh") != NULL) | |
128 | ! shell_style = STYLE_VIMGLOB; | |
129 | ! | |
130 | ! /* Compute the length of the command. We need 2 extra bytes: for the | |
131 | ! * optional '&' and for the NUL. | |
132 | ! * Worst case: "unset nonomatch; print -N >" plus two is 29 */ | |
133 | len = STRLEN(tempname) + 29; | |
134 | + if (shell_style == STYLE_VIMGLOB) | |
135 | + len += STRLEN(sh_vimglob_func); | |
136 | + | |
137 | for (i = 0; i < num_pat; ++i) | |
138 | { | |
139 | /* Count the length of the patterns in the same way as they are put in | |
140 | *************** | |
141 | *** 5183,5192 **** | |
142 | --- 5208,5221 ---- | |
143 | STRCAT(command, "glob >"); | |
144 | else if (shell_style == STYLE_PRINT) | |
145 | STRCAT(command, "print -N >"); | |
146 | + else if (shell_style == STYLE_VIMGLOB) | |
147 | + STRCAT(command, sh_vimglob_func); | |
148 | else | |
149 | STRCAT(command, "echo >"); | |
150 | } | |
151 | + | |
152 | STRCAT(command, tempname); | |
153 | + | |
154 | if (shell_style != STYLE_BT) | |
155 | for (i = 0; i < num_pat; ++i) | |
156 | { | |
157 | *************** | |
158 | *** 5232,5239 **** | |
159 | if (flags & EW_SILENT) | |
160 | show_shell_mess = FALSE; | |
161 | if (ampersent) | |
162 | ! STRCAT(command, "&"); /* put the '&' back after the | |
163 | ! redirection */ | |
164 | ||
165 | /* | |
166 | * Using zsh -G: If a pattern has no matches, it is just deleted from | |
167 | --- 5261,5267 ---- | |
168 | if (flags & EW_SILENT) | |
169 | show_shell_mess = FALSE; | |
170 | if (ampersent) | |
171 | ! STRCAT(command, "&"); /* put the '&' after the redirection */ | |
172 | ||
173 | /* | |
174 | * Using zsh -G: If a pattern has no matches, it is just deleted from | |
175 | *************** | |
176 | *** 5265,5271 **** | |
177 | show_shell_mess = TRUE; | |
178 | vim_free(command); | |
179 | ||
180 | ! if (i) /* mch_call_shell() failed */ | |
181 | { | |
182 | mch_remove(tempname); | |
183 | vim_free(tempname); | |
184 | --- 5293,5299 ---- | |
185 | show_shell_mess = TRUE; | |
186 | vim_free(command); | |
187 | ||
188 | ! if (i != 0) /* mch_call_shell() failed */ | |
189 | { | |
190 | mch_remove(tempname); | |
191 | vim_free(tempname); | |
192 | *************** | |
193 | *** 5336,5342 **** | |
194 | } | |
195 | vim_free(tempname); | |
196 | ||
197 | ! #if defined(__CYGWIN__) || defined(__CYGWIN32__) | |
198 | /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ | |
199 | p = buffer; | |
200 | for (i = 0; i < len; ++i) | |
201 | --- 5364,5370 ---- | |
202 | } | |
203 | vim_free(tempname); | |
204 | ||
205 | ! # if defined(__CYGWIN__) || defined(__CYGWIN32__) | |
206 | /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */ | |
207 | p = buffer; | |
208 | for (i = 0; i < len; ++i) | |
209 | *************** | |
210 | *** 5359,5365 **** | |
211 | } | |
212 | } | |
213 | /* file names are separated with NL */ | |
214 | ! else if (shell_style == STYLE_BT) | |
215 | { | |
216 | buffer[len] = NUL; /* make sure the buffer ends in NUL */ | |
217 | p = buffer; | |
218 | --- 5387,5393 ---- | |
219 | } | |
220 | } | |
221 | /* file names are separated with NL */ | |
222 | ! else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB) | |
223 | { | |
224 | buffer[len] = NUL; /* make sure the buffer ends in NUL */ | |
225 | p = buffer; | |
226 | *************** | |
227 | *** 5438,5444 **** | |
228 | { | |
229 | (*file)[i] = p; | |
230 | /* Space or NL separates */ | |
231 | ! if (shell_style == STYLE_ECHO || shell_style == STYLE_BT) | |
232 | { | |
233 | while (!(shell_style == STYLE_ECHO && *p == ' ') | |
234 | && *p != '\n' && *p != NUL) | |
235 | --- 5466,5473 ---- | |
236 | { | |
237 | (*file)[i] = p; | |
238 | /* Space or NL separates */ | |
239 | ! if (shell_style == STYLE_ECHO || shell_style == STYLE_BT | |
240 | ! || shell_style == STYLE_VIMGLOB) | |
241 | { | |
242 | while (!(shell_style == STYLE_ECHO && *p == ' ') | |
243 | && *p != '\n' && *p != NUL) | |
244 | *** ../vim-7.1.222/src/version.c Sun Jan 13 13:30:34 2008 | |
245 | --- src/version.c Sun Jan 13 13:45:04 2008 | |
246 | *************** | |
247 | *** 668,669 **** | |
248 | --- 668,671 ---- | |
249 | { /* Add new patch number below this line */ | |
250 | + /**/ | |
251 | + 223, | |
252 | /**/ | |
253 | ||
254 | -- | |
255 | User: I'm having problems with my text editor. | |
256 | Help desk: Which editor are you using? | |
257 | User: I don't know, but it's version VI (pronounced: 6). | |
258 | Help desk: Oh, then you should upgrade to version VIM (pronounced: 994). | |
259 | ||
260 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
261 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
262 | \\\ download, build and distribute -- http://www.A-A-P.org /// | |
263 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |