Karsten Hopp 573b23
To: vim-dev@vim.org
Karsten Hopp 573b23
Subject: Patch 7.0.111
Karsten Hopp 573b23
Fcc: outbox
Karsten Hopp 573b23
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 573b23
Mime-Version: 1.0
Karsten Hopp 573b23
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 573b23
Content-Transfer-Encoding: 8bit
Karsten Hopp 573b23
------------
Karsten Hopp 573b23
Karsten Hopp 573b23
Patch 7.0.111
Karsten Hopp 573b23
Problem:    The gzip plugin can't handle filenames with single quotes.
Karsten Hopp 573b23
Solution:   Add and use the shellescape() function. (partly by Alexey Froloff)
Karsten Hopp 573b23
Files:      runtime/autoload/gzip.vim, runtime/doc/eval.txt, src/eval.c,
Karsten Hopp 573b23
            src/mbyte.c, src/misc2.c, src/proto/misc2.pro
Karsten Hopp 573b23
Karsten Hopp 573b23
Karsten Hopp 573b23
*** ../vim-7.0.110/runtime/autoload/gzip.vim	Tue Aug  8 19:55:06 2006
Karsten Hopp 573b23
--- runtime/autoload/gzip.vim	Tue Oct  3 14:39:29 2006
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 1,6 ****
Karsten Hopp 573b23
  " Vim autoload file for editing compressed files.
Karsten Hopp 573b23
  " Maintainer: Bram Moolenaar <Bram@vim.org>
Karsten Hopp 573b23
! " Last Change: 2006 Jul 19
Karsten Hopp 573b23
  
Karsten Hopp 573b23
  " These functions are used by the gzip plugin.
Karsten Hopp 573b23
  
Karsten Hopp 573b23
--- 1,6 ----
Karsten Hopp 573b23
  " Vim autoload file for editing compressed files.
Karsten Hopp 573b23
  " Maintainer: Bram Moolenaar <Bram@vim.org>
Karsten Hopp 573b23
! " Last Change: 2006 Oct 03
Karsten Hopp 573b23
  
Karsten Hopp 573b23
  " These functions are used by the gzip plugin.
Karsten Hopp 573b23
  
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 68,76 ****
Karsten Hopp 573b23
    let tmp = tempname()
Karsten Hopp 573b23
    let tmpe = tmp . "." . expand("<afile>:e")
Karsten Hopp 573b23
    " write the just read lines to a temp file "'[,']w tmp.gz"
Karsten Hopp 573b23
!   execute "silent '[,']w " . tmpe
Karsten Hopp 573b23
    " uncompress the temp file: call system("gzip -dn tmp.gz")
Karsten Hopp 573b23
!   call system(a:cmd . " " . tmpe)
Karsten Hopp 573b23
    if !filereadable(tmp)
Karsten Hopp 573b23
      " uncompress didn't work!  Keep the compressed file then.
Karsten Hopp 573b23
      echoerr "Error: Could not read uncompressed file"
Karsten Hopp 573b23
--- 68,76 ----
Karsten Hopp 573b23
    let tmp = tempname()
Karsten Hopp 573b23
    let tmpe = tmp . "." . expand("<afile>:e")
Karsten Hopp 573b23
    " write the just read lines to a temp file "'[,']w tmp.gz"
Karsten Hopp 573b23
!   execute "silent '[,']w " . escape(tmpe, ' ')
Karsten Hopp 573b23
    " uncompress the temp file: call system("gzip -dn tmp.gz")
Karsten Hopp 573b23
!   call system(a:cmd . " " . s:escape(tmpe))
Karsten Hopp 573b23
    if !filereadable(tmp)
Karsten Hopp 573b23
      " uncompress didn't work!  Keep the compressed file then.
Karsten Hopp 573b23
      echoerr "Error: Could not read uncompressed file"
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 127,135 ****
Karsten Hopp 573b23
      let nmt = s:tempname(nm)
Karsten Hopp 573b23
      if rename(nm, nmt) == 0
Karsten Hopp 573b23
        if exists("b:gzip_comp_arg")
Karsten Hopp 573b23
! 	call system(a:cmd . " " . b:gzip_comp_arg . " '" . nmt . "'")
Karsten Hopp 573b23
        else
Karsten Hopp 573b23
! 	call system(a:cmd . " '" . nmt . "'")
Karsten Hopp 573b23
        endif
Karsten Hopp 573b23
        call rename(nmt . "." . expand("<afile>:e"), nm)
Karsten Hopp 573b23
      endif
Karsten Hopp 573b23
--- 127,135 ----
Karsten Hopp 573b23
      let nmt = s:tempname(nm)
Karsten Hopp 573b23
      if rename(nm, nmt) == 0
Karsten Hopp 573b23
        if exists("b:gzip_comp_arg")
Karsten Hopp 573b23
! 	call system(a:cmd . " " . b:gzip_comp_arg . " " . s:escape(nmt))
Karsten Hopp 573b23
        else
Karsten Hopp 573b23
! 	call system(a:cmd . " " . s:escape(nmt))
Karsten Hopp 573b23
        endif
Karsten Hopp 573b23
        call rename(nmt . "." . expand("<afile>:e"), nm)
Karsten Hopp 573b23
      endif
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 154,163 ****
Karsten Hopp 573b23
      if rename(nm, nmte) == 0
Karsten Hopp 573b23
        if &patchmode != "" && getfsize(nm . &patchmode) == -1
Karsten Hopp 573b23
  	" Create patchmode file by creating the decompressed file new
Karsten Hopp 573b23
! 	call system(a:cmd . " -c " . nmte . " > " . nmt)
Karsten Hopp 573b23
  	call rename(nmte, nm . &patchmode)
Karsten Hopp 573b23
        else
Karsten Hopp 573b23
! 	call system(a:cmd . " " . nmte)
Karsten Hopp 573b23
        endif
Karsten Hopp 573b23
        call rename(nmt, nm)
Karsten Hopp 573b23
      endif
Karsten Hopp 573b23
--- 154,163 ----
Karsten Hopp 573b23
      if rename(nm, nmte) == 0
Karsten Hopp 573b23
        if &patchmode != "" && getfsize(nm . &patchmode) == -1
Karsten Hopp 573b23
  	" Create patchmode file by creating the decompressed file new
Karsten Hopp 573b23
! 	call system(a:cmd . " -c " . s:escape(nmte) . " > " . s:escape(nmt))
Karsten Hopp 573b23
  	call rename(nmte, nm . &patchmode)
Karsten Hopp 573b23
        else
Karsten Hopp 573b23
! 	call system(a:cmd . " " . s:escape(nmte))
Karsten Hopp 573b23
        endif
Karsten Hopp 573b23
        call rename(nmt, nm)
Karsten Hopp 573b23
      endif
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 173,178 ****
Karsten Hopp 573b23
--- 173,186 ----
Karsten Hopp 573b23
      return fn
Karsten Hopp 573b23
    endif
Karsten Hopp 573b23
    return fnamemodify(a:name, ":p:h") . "/X~=@l9q5"
Karsten Hopp 573b23
+ endfun
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+ fun s:escape(name)
Karsten Hopp 573b23
+   " shellescape() was added by patch 7.0.111
Karsten Hopp 573b23
+   if v:version > 700 || (v:version == 700 && has('patch111'))
Karsten Hopp 573b23
+     return shellescape(a:name)
Karsten Hopp 573b23
+   endif
Karsten Hopp 573b23
+   return "'" . a:name . "'"
Karsten Hopp 573b23
  endfun
Karsten Hopp 573b23
  
Karsten Hopp 573b23
  " vim: set sw=2 :
Karsten Hopp 573b23
*** ../vim-7.0.110/runtime/doc/eval.txt	Sun May  7 17:08:32 2006
Karsten Hopp 573b23
--- runtime/doc/eval.txt	Fri Sep 22 19:43:18 2006
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 1,4 ****
Karsten Hopp 573b23
! *eval.txt*      For Vim version 7.0.  Last change: 2006 Sep 09
Karsten Hopp 573b23
  
Karsten Hopp 573b23
  
Karsten Hopp 573b23
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
Karsten Hopp 573b23
--- 1,4 ----
Karsten Hopp 573b23
! *eval.txt*      For Vim version 7.0.  Last change: 2006 Sep 22
Karsten Hopp 573b23
  
Karsten Hopp 573b23
  
Karsten Hopp 573b23
  		  VIM REFERENCE MANUAL    by Bram Moolenaar
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 1709,1714 ****
Karsten Hopp 573b23
--- 1715,1722 ----
Karsten Hopp 573b23
  settabwinvar( {tabnr}, {winnr}, {varname}, {val})    set {varname} in window
Karsten Hopp 573b23
  					{winnr} in tab page {tabnr} to {val}
Karsten Hopp 573b23
  setwinvar( {nr}, {varname}, {val})	set {varname} in window {nr} to {val}
Karsten Hopp 573b23
+ shellescape( {string})		String	escape {string} for use as shell
Karsten Hopp 573b23
+ 					command argument
Karsten Hopp 573b23
  simplify( {filename})		String	simplify filename as much as possible
Karsten Hopp 573b23
  sort( {list} [, {func}])	List	sort {list}, using {func} to compare
Karsten Hopp 573b23
  soundfold( {word})		String	sound-fold {word}
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 4434,4439 ****
Karsten Hopp 573b23
--- 4457,4477 ----
Karsten Hopp 573b23
  			:call setwinvar(1, "&list", 0)
Karsten Hopp 573b23
  			:call setwinvar(2, "myvar", "foobar")
Karsten Hopp 573b23
  
Karsten Hopp 573b23
+ shellescape({string})					*shellescape()*
Karsten Hopp 573b23
+ 		Escape {string} for use as shell command argument.
Karsten Hopp 573b23
+ 		On MS-Windows and MS-DOS, when 'shellslash' is not set, it
Karsten Hopp 573b23
+ 		will enclose {string} double quotes and double all double
Karsten Hopp 573b23
+ 		quotes within {string}.
Karsten Hopp 573b23
+ 		For other systems, it will enclose {string} in single quotes
Karsten Hopp 573b23
+ 		and replace all "'" with "'\''".
Karsten Hopp 573b23
+ 		Example: >
Karsten Hopp 573b23
+ 			:echo shellescape('c:\program files\vim')
Karsten Hopp 573b23
+ <		results in:
Karsten Hopp 573b23
+ 			"c:\program files\vim" ~
Karsten Hopp 573b23
+ 		Example usage: >
Karsten Hopp 573b23
+ 			:call system("chmod +x -- " . shellescape(expand("%")))
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
  simplify({filename})					*simplify()*
Karsten Hopp 573b23
  		Simplify the file name as much as possible without changing
Karsten Hopp 573b23
  		the meaning.  Shortcuts (on MS-Windows) or symbolic links (on
Karsten Hopp 573b23
*** ../vim-7.0.110/src/eval.c	Sat Sep  9 12:05:39 2006
Karsten Hopp 573b23
--- src/eval.c	Thu Sep 14 17:44:41 2006
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 622,627 ****
Karsten Hopp 573b23
--- 622,628 ----
Karsten Hopp 573b23
  static void f_setreg __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 573b23
  static void f_settabwinvar __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 573b23
  static void f_setwinvar __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 573b23
+ static void f_shellescape __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 573b23
  static void f_simplify __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 573b23
  static void f_sort __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 573b23
  static void f_soundfold __ARGS((typval_T *argvars, typval_T *rettv));
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 7146,7151 ****
Karsten Hopp 573b23
--- 7147,7153 ----
Karsten Hopp 573b23
      {"setreg",		2, 3, f_setreg},
Karsten Hopp 573b23
      {"settabwinvar",	4, 4, f_settabwinvar},
Karsten Hopp 573b23
      {"setwinvar",	3, 3, f_setwinvar},
Karsten Hopp 573b23
+     {"shellescape",	1, 1, f_shellescape},
Karsten Hopp 573b23
      {"simplify",	1, 1, f_simplify},
Karsten Hopp 573b23
      {"sort",		1, 2, f_sort},
Karsten Hopp 573b23
      {"soundfold",	1, 1, f_soundfold},
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 14602,14607 ****
Karsten Hopp 573b23
--- 14604,14621 ----
Karsten Hopp 573b23
  	}
Karsten Hopp 573b23
  #endif
Karsten Hopp 573b23
      }
Karsten Hopp 573b23
+ }
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+ /*
Karsten Hopp 573b23
+  * "shellescape({string})" function
Karsten Hopp 573b23
+  */
Karsten Hopp 573b23
+     static void
Karsten Hopp 573b23
+ f_shellescape(argvars, rettv)
Karsten Hopp 573b23
+     typval_T	*argvars;
Karsten Hopp 573b23
+     typval_T	*rettv;
Karsten Hopp 573b23
+ {
Karsten Hopp 573b23
+     rettv->vval.v_string = vim_strsave_shellescape(get_tv_string(&argvars[0]));
Karsten Hopp 573b23
+     rettv->v_type = VAR_STRING;
Karsten Hopp 573b23
  }
Karsten Hopp 573b23
  
Karsten Hopp 573b23
  /*
Karsten Hopp 573b23
*** ../vim-7.0.110/src/misc2.c	Thu May  4 23:50:56 2006
Karsten Hopp 573b23
--- src/misc2.c	Tue Sep 26 23:13:57 2006
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 1229,1234 ****
Karsten Hopp 573b23
--- 1229,1322 ----
Karsten Hopp 573b23
      return escaped_string;
Karsten Hopp 573b23
  }
Karsten Hopp 573b23
  
Karsten Hopp 573b23
+ #if defined(FEAT_EVAL) || defined(PROTO)
Karsten Hopp 573b23
+ /*
Karsten Hopp 573b23
+  * Escape "string" for use as a shell argument with system().
Karsten Hopp 573b23
+  * This uses single quotes, except when we know we need to use double qoutes
Karsten Hopp 573b23
+  * (MS-DOS and MS-Windows without 'shellslash' set).
Karsten Hopp 573b23
+  * Returns the result in allocated memory, NULL if we have run out.
Karsten Hopp 573b23
+  */
Karsten Hopp 573b23
+     char_u *
Karsten Hopp 573b23
+ vim_strsave_shellescape(string)
Karsten Hopp 573b23
+     char_u	*string;
Karsten Hopp 573b23
+ {
Karsten Hopp 573b23
+     unsigned	length;
Karsten Hopp 573b23
+     char_u	*p;
Karsten Hopp 573b23
+     char_u	*d;
Karsten Hopp 573b23
+     char_u	*escaped_string;
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+     /* First count the number of extra bytes required. */
Karsten Hopp 573b23
+     length = STRLEN(string) + 3;	/* two quotes and the trailing NUL */
Karsten Hopp 573b23
+     for (p = string; *p != NUL; mb_ptr_adv(p))
Karsten Hopp 573b23
+     {
Karsten Hopp 573b23
+ # if defined(WIN32) || defined(WIN16) || defined(DOS)
Karsten Hopp 573b23
+ 	if (!p_ssl)
Karsten Hopp 573b23
+ 	{
Karsten Hopp 573b23
+ 	    if (*p == '"')
Karsten Hopp 573b23
+ 		++length;		/* " -> "" */
Karsten Hopp 573b23
+ 	}
Karsten Hopp 573b23
+ 	else
Karsten Hopp 573b23
+ # endif
Karsten Hopp 573b23
+ 	if (*p == '\'')
Karsten Hopp 573b23
+ 	    length += 3;		/* ' => '\'' */
Karsten Hopp 573b23
+     }
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+     /* Allocate memory for the result and fill it. */
Karsten Hopp 573b23
+     escaped_string = alloc(length);
Karsten Hopp 573b23
+     if (escaped_string != NULL)
Karsten Hopp 573b23
+     {
Karsten Hopp 573b23
+ 	d = escaped_string;
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+ 	/* add opening quote */
Karsten Hopp 573b23
+ # if defined(WIN32) || defined(WIN16) || defined(DOS)
Karsten Hopp 573b23
+ 	if (!p_ssl)
Karsten Hopp 573b23
+ 	    *d++ = '"';
Karsten Hopp 573b23
+ 	else
Karsten Hopp 573b23
+ # endif
Karsten Hopp 573b23
+ 	    *d++ = '\'';
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+ 	for (p = string; *p != NUL; )
Karsten Hopp 573b23
+ 	{
Karsten Hopp 573b23
+ # if defined(WIN32) || defined(WIN16) || defined(DOS)
Karsten Hopp 573b23
+ 	    if (!p_ssl)
Karsten Hopp 573b23
+ 	    {
Karsten Hopp 573b23
+ 		if (*p == '"')
Karsten Hopp 573b23
+ 		{
Karsten Hopp 573b23
+ 		    *d++ = '"';
Karsten Hopp 573b23
+ 		    *d++ = '"';
Karsten Hopp 573b23
+ 		    ++p;
Karsten Hopp 573b23
+ 		    continue;
Karsten Hopp 573b23
+ 		}
Karsten Hopp 573b23
+ 	    }
Karsten Hopp 573b23
+ 	    else
Karsten Hopp 573b23
+ # endif
Karsten Hopp 573b23
+ 	    if (*p == '\'')
Karsten Hopp 573b23
+ 	    {
Karsten Hopp 573b23
+ 		*d++='\'';
Karsten Hopp 573b23
+ 		*d++='\\';
Karsten Hopp 573b23
+ 		*d++='\'';
Karsten Hopp 573b23
+ 		*d++='\'';
Karsten Hopp 573b23
+ 		++p;
Karsten Hopp 573b23
+ 		continue;
Karsten Hopp 573b23
+ 	    }
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+ 	    MB_COPY_CHAR(p, d);
Karsten Hopp 573b23
+ 	}
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+ 	/* add terminating quote and finish with a NUL */
Karsten Hopp 573b23
+ # if defined(WIN32) || defined(WIN16) || defined(DOS)
Karsten Hopp 573b23
+ 	if (!p_ssl)
Karsten Hopp 573b23
+ 	    *d++ = '"';
Karsten Hopp 573b23
+ 	else
Karsten Hopp 573b23
+ # endif
Karsten Hopp 573b23
+ 	    *d++ = '\'';
Karsten Hopp 573b23
+ 	*d = NUL;
Karsten Hopp 573b23
+     }
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
+     return escaped_string;
Karsten Hopp 573b23
+ }
Karsten Hopp 573b23
+ #endif
Karsten Hopp 573b23
+ 
Karsten Hopp 573b23
  /*
Karsten Hopp 573b23
   * Like vim_strsave(), but make all characters uppercase.
Karsten Hopp 573b23
   * This uses ASCII lower-to-upper case translation, language independent.
Karsten Hopp 573b23
*** ../vim-7.0.110/src/proto/misc2.pro	Fri Mar 24 23:42:55 2006
Karsten Hopp 573b23
--- src/proto/misc2.pro	Thu Sep 14 18:28:43 2006
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 29,34 ****
Karsten Hopp 573b23
--- 29,35 ----
Karsten Hopp 573b23
  extern char_u *vim_strnsave __ARGS((char_u *string, int len));
Karsten Hopp 573b23
  extern char_u *vim_strsave_escaped __ARGS((char_u *string, char_u *esc_chars));
Karsten Hopp 573b23
  extern char_u *vim_strsave_escaped_ext __ARGS((char_u *string, char_u *esc_chars, int cc, int bsl));
Karsten Hopp 573b23
+ extern char_u *vim_strsave_shellescape __ARGS((char_u *string));
Karsten Hopp 573b23
  extern char_u *vim_strsave_up __ARGS((char_u *string));
Karsten Hopp 573b23
  extern char_u *vim_strnsave_up __ARGS((char_u *string, int len));
Karsten Hopp 573b23
  extern void vim_strup __ARGS((char_u *p));
Karsten Hopp 573b23
*** ../vim-7.0.110/src/version.c	Tue Sep 26 13:49:41 2006
Karsten Hopp 573b23
--- src/version.c	Tue Oct  3 14:36:40 2006
Karsten Hopp 573b23
***************
Karsten Hopp 573b23
*** 668,669 ****
Karsten Hopp 573b23
--- 668,671 ----
Karsten Hopp 573b23
  {   /* Add new patch number below this line */
Karsten Hopp 573b23
+ /**/
Karsten Hopp 573b23
+     111,
Karsten Hopp 573b23
  /**/
Karsten Hopp 573b23
Karsten Hopp 573b23
-- 
Karsten Hopp 573b23
The only way the average employee can speak to an executive is by taking a
Karsten Hopp 573b23
second job as a golf caddie.
Karsten Hopp 573b23
				(Scott Adams - The Dilbert principle)
Karsten Hopp 573b23
Karsten Hopp 573b23
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 573b23
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 573b23
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 573b23
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///