4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
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.
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
28 + * This is the OS/2 implementation.
30 # define EXPL_ALLOC_INC 16
32 size_t files_alloced, files_free;
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;
50 static int did_find_nul = FALSE;
51 int ampersent = FALSE;
53 *num_file = 0; /* default: no files found */
60 ! * This is the non-OS/2 implementation (really Unix).
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
73 int shell_style = STYLE_ECHO;
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 >";
80 *num_file = 0; /* default: no files found */
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.
91 if (num_pat == 1 && *pat[0] == '`'
92 && (len = STRLEN(pat[0])) > 2
96 * Let the shell expand the patterns and write the result into the temp
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".
109 if (num_pat == 1 && *pat[0] == '`'
110 && (len = STRLEN(pat[0])) > 2
113 else if (STRCMP(p_sh + len - 3, "zsh") == 0)
114 shell_style = STYLE_PRINT;
117 ! /* "unset nonomatch; print -N >" plus two is 29 */
118 len = STRLEN(tempname) + 29;
119 for (i = 0; i < num_pat; ++i)
121 /* Count the length of the patterns in the same way as they are put in
123 else if (STRCMP(p_sh + len - 3, "zsh") == 0)
124 shell_style = STYLE_PRINT;
126 ! if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh),
128 ! shell_style = STYLE_VIMGLOB;
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);
137 for (i = 0; i < num_pat; ++i)
139 /* Count the length of the patterns in the same way as they are put in
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);
149 STRCAT(command, "echo >");
152 STRCAT(command, tempname);
154 if (shell_style != STYLE_BT)
155 for (i = 0; i < num_pat; ++i)
159 if (flags & EW_SILENT)
160 show_shell_mess = FALSE;
162 ! STRCAT(command, "&"); /* put the '&' back after the
166 * Using zsh -G: If a pattern has no matches, it is just deleted from
168 if (flags & EW_SILENT)
169 show_shell_mess = FALSE;
171 ! STRCAT(command, "&"); /* put the '&' after the redirection */
174 * Using zsh -G: If a pattern has no matches, it is just deleted from
177 show_shell_mess = TRUE;
180 ! if (i) /* mch_call_shell() failed */
182 mch_remove(tempname);
185 show_shell_mess = TRUE;
188 ! if (i != 0) /* mch_call_shell() failed */
190 mch_remove(tempname);
197 ! #if defined(__CYGWIN__) || defined(__CYGWIN32__)
198 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */
200 for (i = 0; i < len; ++i)
205 ! # if defined(__CYGWIN__) || defined(__CYGWIN32__)
206 /* Translate <CR><NL> into <NL>. Caution, buffer may contain NUL. */
208 for (i = 0; i < len; ++i)
213 /* file names are separated with NL */
214 ! else if (shell_style == STYLE_BT)
216 buffer[len] = NUL; /* make sure the buffer ends in NUL */
221 /* file names are separated with NL */
222 ! else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB)
224 buffer[len] = NUL; /* make sure the buffer ends in NUL */
230 /* Space or NL separates */
231 ! if (shell_style == STYLE_ECHO || shell_style == STYLE_BT)
233 while (!(shell_style == STYLE_ECHO && *p == ' ')
234 && *p != '\n' && *p != NUL)
238 /* Space or NL separates */
239 ! if (shell_style == STYLE_ECHO || shell_style == STYLE_BT
240 ! || shell_style == STYLE_VIMGLOB)
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
249 { /* Add new patch number below this line */
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).
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 ///