4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: The gzip plugin can't handle filenames with single quotes.
12 Solution: Add and use the shellescape() function. (partly by Alexey Froloff)
13 Files: runtime/autoload/gzip.vim, runtime/doc/eval.txt, src/eval.c,
14 src/mbyte.c, src/misc2.c, src/proto/misc2.pro
17 *** ../vim-7.0.110/runtime/autoload/gzip.vim Tue Aug 8 19:55:06 2006
18 --- runtime/autoload/gzip.vim Tue Oct 3 14:39:29 2006
21 " Vim autoload file for editing compressed files.
22 " Maintainer: Bram Moolenaar <Bram@vim.org>
23 ! " Last Change: 2006 Jul 19
25 " These functions are used by the gzip plugin.
28 " Vim autoload file for editing compressed files.
29 " Maintainer: Bram Moolenaar <Bram@vim.org>
30 ! " Last Change: 2006 Oct 03
32 " These functions are used by the gzip plugin.
37 let tmpe = tmp . "." . expand("<afile>:e")
38 " write the just read lines to a temp file "'[,']w tmp.gz"
39 ! execute "silent '[,']w " . tmpe
40 " uncompress the temp file: call system("gzip -dn tmp.gz")
41 ! call system(a:cmd . " " . tmpe)
43 " uncompress didn't work! Keep the compressed file then.
44 echoerr "Error: Could not read uncompressed file"
47 let tmpe = tmp . "." . expand("<afile>:e")
48 " write the just read lines to a temp file "'[,']w tmp.gz"
49 ! execute "silent '[,']w " . escape(tmpe, ' ')
50 " uncompress the temp file: call system("gzip -dn tmp.gz")
51 ! call system(a:cmd . " " . s:escape(tmpe))
53 " uncompress didn't work! Keep the compressed file then.
54 echoerr "Error: Could not read uncompressed file"
57 let nmt = s:tempname(nm)
58 if rename(nm, nmt) == 0
59 if exists("b:gzip_comp_arg")
60 ! call system(a:cmd . " " . b:gzip_comp_arg . " '" . nmt . "'")
62 ! call system(a:cmd . " '" . nmt . "'")
64 call rename(nmt . "." . expand("<afile>:e"), nm)
67 let nmt = s:tempname(nm)
68 if rename(nm, nmt) == 0
69 if exists("b:gzip_comp_arg")
70 ! call system(a:cmd . " " . b:gzip_comp_arg . " " . s:escape(nmt))
72 ! call system(a:cmd . " " . s:escape(nmt))
74 call rename(nmt . "." . expand("<afile>:e"), nm)
78 if rename(nm, nmte) == 0
79 if &patchmode != "" && getfsize(nm . &patchmode) == -1
80 " Create patchmode file by creating the decompressed file new
81 ! call system(a:cmd . " -c " . nmte . " > " . nmt)
82 call rename(nmte, nm . &patchmode)
84 ! call system(a:cmd . " " . nmte)
89 if rename(nm, nmte) == 0
90 if &patchmode != "" && getfsize(nm . &patchmode) == -1
91 " Create patchmode file by creating the decompressed file new
92 ! call system(a:cmd . " -c " . s:escape(nmte) . " > " . s:escape(nmt))
93 call rename(nmte, nm . &patchmode)
95 ! call system(a:cmd . " " . s:escape(nmte))
104 return fnamemodify(a:name, ":p:h") . "/X~=@l9q5"
108 + " shellescape() was added by patch 7.0.111
109 + if v:version > 700 || (v:version == 700 && has('patch111'))
110 + return shellescape(a:name)
112 + return "'" . a:name . "'"
116 *** ../vim-7.0.110/runtime/doc/eval.txt Sun May 7 17:08:32 2006
117 --- runtime/doc/eval.txt Fri Sep 22 19:43:18 2006
120 ! *eval.txt* For Vim version 7.0. Last change: 2006 May 06
123 VIM REFERENCE MANUAL by Bram Moolenaar
125 ! *eval.txt* For Vim version 7.0. Last change: 2006 Sep 22
128 VIM REFERENCE MANUAL by Bram Moolenaar
132 settabwinvar( {tabnr}, {winnr}, {varname}, {val}) set {varname} in window
133 {winnr} in tab page {tabnr} to {val}
134 setwinvar( {nr}, {varname}, {val}) set {varname} in window {nr} to {val}
135 + shellescape( {string}) String escape {string} for use as shell
137 simplify( {filename}) String simplify filename as much as possible
138 sort( {list} [, {func}]) List sort {list}, using {func} to compare
139 soundfold( {word}) String sound-fold {word}
143 :call setwinvar(1, "&list", 0)
144 :call setwinvar(2, "myvar", "foobar")
146 + shellescape({string}) *shellescape()*
147 + Escape {string} for use as shell command argument.
148 + On MS-Windows and MS-DOS, when 'shellslash' is not set, it
149 + will enclose {string} double quotes and double all double
150 + quotes within {string}.
151 + For other systems, it will enclose {string} in single quotes
152 + and replace all "'" with "'\''".
154 + :echo shellescape('c:\program files\vim')
156 + "c:\program files\vim" ~
158 + :call system("chmod +x -- " . shellescape(expand("%")))
161 simplify({filename}) *simplify()*
162 Simplify the file name as much as possible without changing
163 the meaning. Shortcuts (on MS-Windows) or symbolic links (on
164 *** ../vim-7.0.110/src/eval.c Sat Sep 9 12:05:39 2006
165 --- src/eval.c Thu Sep 14 17:44:41 2006
169 static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv));
170 static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
171 static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
172 + static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
173 static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
174 static void f_sort __ARGS((typval_T *argvars, typval_T *rettv));
175 static void f_soundfold __ARGS((typval_T *argvars, typval_T *rettv));
179 {"setreg", 2, 3, f_setreg},
180 {"settabwinvar", 4, 4, f_settabwinvar},
181 {"setwinvar", 3, 3, f_setwinvar},
182 + {"shellescape", 1, 1, f_shellescape},
183 {"simplify", 1, 1, f_simplify},
184 {"sort", 1, 2, f_sort},
185 {"soundfold", 1, 1, f_soundfold},
195 + * "shellescape({string})" function
198 + f_shellescape(argvars, rettv)
202 + rettv->vval.v_string = vim_strsave_shellescape(get_tv_string(&argvars[0]));
203 + rettv->v_type = VAR_STRING;
207 *** ../vim-7.0.110/src/misc2.c Thu May 4 23:50:56 2006
208 --- src/misc2.c Tue Sep 26 23:13:57 2006
212 return escaped_string;
215 + #if defined(FEAT_EVAL) || defined(PROTO)
217 + * Escape "string" for use as a shell argument with system().
218 + * This uses single quotes, except when we know we need to use double qoutes
219 + * (MS-DOS and MS-Windows without 'shellslash' set).
220 + * Returns the result in allocated memory, NULL if we have run out.
223 + vim_strsave_shellescape(string)
229 + char_u *escaped_string;
231 + /* First count the number of extra bytes required. */
232 + length = STRLEN(string) + 3; /* two quotes and the trailing NUL */
233 + for (p = string; *p != NUL; mb_ptr_adv(p))
235 + # if defined(WIN32) || defined(WIN16) || defined(DOS)
239 + ++length; /* " -> "" */
244 + length += 3; /* ' => '\'' */
247 + /* Allocate memory for the result and fill it. */
248 + escaped_string = alloc(length);
249 + if (escaped_string != NULL)
251 + d = escaped_string;
253 + /* add opening quote */
254 + # if defined(WIN32) || defined(WIN16) || defined(DOS)
261 + for (p = string; *p != NUL; )
263 + # if defined(WIN32) || defined(WIN16) || defined(DOS)
286 + MB_COPY_CHAR(p, d);
289 + /* add terminating quote and finish with a NUL */
290 + # if defined(WIN32) || defined(WIN16) || defined(DOS)
299 + return escaped_string;
304 * Like vim_strsave(), but make all characters uppercase.
305 * This uses ASCII lower-to-upper case translation, language independent.
306 *** ../vim-7.0.110/src/proto/misc2.pro Fri Mar 24 23:42:55 2006
307 --- src/proto/misc2.pro Thu Sep 14 18:28:43 2006
311 extern char_u *vim_strnsave __ARGS((char_u *string, int len));
312 extern char_u *vim_strsave_escaped __ARGS((char_u *string, char_u *esc_chars));
313 extern char_u *vim_strsave_escaped_ext __ARGS((char_u *string, char_u *esc_chars, int cc, int bsl));
314 + extern char_u *vim_strsave_shellescape __ARGS((char_u *string));
315 extern char_u *vim_strsave_up __ARGS((char_u *string));
316 extern char_u *vim_strnsave_up __ARGS((char_u *string, int len));
317 extern void vim_strup __ARGS((char_u *p));
318 *** ../vim-7.0.110/src/version.c Tue Sep 26 13:49:41 2006
319 --- src/version.c Tue Oct 3 14:36:40 2006
323 { /* Add new patch number below this line */
329 The only way the average employee can speak to an executive is by taking a
330 second job as a golf caddie.
331 (Scott Adams - The Dilbert principle)
333 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
334 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
335 \\\ download, build and distribute -- http://www.A-A-P.org ///
336 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///