03d5e4f
To: vim-dev@vim.org
03d5e4f
Subject: Patch 7.2.010
03d5e4f
Fcc: outbox
03d5e4f
From: Bram Moolenaar <Bram@moolenaar.net>
03d5e4f
Mime-Version: 1.0
03d5e4f
Content-Type: text/plain; charset=ISO-8859-1
03d5e4f
Content-Transfer-Encoding: 8bit
03d5e4f
------------
03d5e4f
03d5e4f
Patch 7.2.010
03d5e4f
Problem:    When using "K" in Visual mode not all characters are properly
03d5e4f
	    escaped. (Ben Schmidt)
03d5e4f
Solution:   Use a function with the functionality of shellescape(). (Jan
03d5e4f
	    Minar)
03d5e4f
Files:	    src/mbyte.c, src/misc2.c, src/normal.c
03d5e4f
03d5e4f
03d5e4f
*** ../vim-7.2.009/src/mbyte.c	Wed Aug  6 18:45:36 2008
03d5e4f
--- src/mbyte.c	Wed Sep  3 22:34:48 2008
03d5e4f
***************
03d5e4f
*** 2540,2546 ****
03d5e4f
      return (int)(p - q);
03d5e4f
  }
03d5e4f
  
03d5e4f
- #if defined(FEAT_EVAL) || defined(PROTO)
03d5e4f
  /*
03d5e4f
   * Copy a character from "*fp" to "*tp" and advance the pointers.
03d5e4f
   */
03d5e4f
--- 2540,2545 ----
03d5e4f
***************
03d5e4f
*** 2555,2561 ****
03d5e4f
      *tp += l;
03d5e4f
      *fp += l;
03d5e4f
  }
03d5e4f
- #endif
03d5e4f
  
03d5e4f
  /*
03d5e4f
   * Return the offset from "p" to the first byte of a character.  When "p" is
03d5e4f
--- 2554,2559 ----
03d5e4f
*** ../vim-7.2.009/src/misc2.c	Thu Jul 24 20:28:58 2008
03d5e4f
--- src/misc2.c	Wed Sep  3 22:05:21 2008
03d5e4f
***************
03d5e4f
*** 1257,1263 ****
03d5e4f
      return escaped_string;
03d5e4f
  }
03d5e4f
  
03d5e4f
- #if !defined(BACKSLASH_IN_FILENAME) || defined(FEAT_EVAL) || defined(PROTO)
03d5e4f
  /*
03d5e4f
   * Return TRUE when 'shell' has "csh" in the tail.
03d5e4f
   */
03d5e4f
--- 1257,1262 ----
03d5e4f
***************
03d5e4f
*** 1266,1274 ****
03d5e4f
  {
03d5e4f
      return (strstr((char *)gettail(p_sh), "csh") != NULL);
03d5e4f
  }
03d5e4f
- #endif
03d5e4f
  
03d5e4f
- #if defined(FEAT_EVAL) || defined(PROTO)
03d5e4f
  /*
03d5e4f
   * Escape "string" for use as a shell argument with system().
03d5e4f
   * This uses single quotes, except when we know we need to use double qoutes
03d5e4f
--- 1265,1271 ----
03d5e4f
***************
03d5e4f
*** 1391,1397 ****
03d5e4f
  
03d5e4f
      return escaped_string;
03d5e4f
  }
03d5e4f
- #endif
03d5e4f
  
03d5e4f
  /*
03d5e4f
   * Like vim_strsave(), but make all characters uppercase.
03d5e4f
--- 1388,1393 ----
03d5e4f
*** ../vim-7.2.009/src/normal.c	Thu Jul 31 22:03:54 2008
03d5e4f
--- src/normal.c	Sat Sep  6 15:06:07 2008
03d5e4f
***************
03d5e4f
*** 5469,5474 ****
03d5e4f
--- 5469,5479 ----
03d5e4f
  		STRCPY(buf, "he! ");
03d5e4f
  	    else
03d5e4f
  	    {
03d5e4f
+ 		/* An external command will probably use an argument starting
03d5e4f
+ 		 * with "-" as an option.  To avoid trouble we skip the "-". */
03d5e4f
+ 		while (*ptr == '-')
03d5e4f
+ 		    ++ptr;
03d5e4f
+ 
03d5e4f
  		/* When a count is given, turn it into a range.  Is this
03d5e4f
  		 * really what we want? */
03d5e4f
  		isman = (STRCMP(kp, "man") == 0);
03d5e4f
***************
03d5e4f
*** 5511,5547 ****
03d5e4f
      /*
03d5e4f
       * Now grab the chars in the identifier
03d5e4f
       */
03d5e4f
!     if (cmdchar == '*')
03d5e4f
! 	aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\");
03d5e4f
!     else if (cmdchar == '#')
03d5e4f
! 	aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\");
03d5e4f
!     else if (cmdchar == 'K' && !kp_help)
03d5e4f
! 	aux_ptr = (char_u *)" \t\\\"|!";
03d5e4f
!     else
03d5e4f
! 	/* Don't escape spaces and Tabs in a tag with a backslash */
03d5e4f
! 	aux_ptr = (char_u *)"\\|\"";
03d5e4f
! 
03d5e4f
!     p = buf + STRLEN(buf);
03d5e4f
!     while (n-- > 0)
03d5e4f
!     {
03d5e4f
! 	/* put a backslash before \ and some others */
03d5e4f
! 	if (vim_strchr(aux_ptr, *ptr) != NULL)
03d5e4f
! 	    *p++ = '\\';
03d5e4f
! #ifdef FEAT_MBYTE
03d5e4f
! 	/* When current byte is a part of multibyte character, copy all bytes
03d5e4f
! 	 * of that character. */
03d5e4f
! 	if (has_mbyte)
03d5e4f
  	{
03d5e4f
! 	    int i;
03d5e4f
! 	    int len = (*mb_ptr2len)(ptr) - 1;
03d5e4f
! 
03d5e4f
! 	    for (i = 0; i < len && n >= 1; ++i, --n)
03d5e4f
! 		*p++ = *ptr++;
03d5e4f
  	}
03d5e4f
  #endif
03d5e4f
! 	*p++ = *ptr++;
03d5e4f
      }
03d5e4f
-     *p = NUL;
03d5e4f
  
03d5e4f
      /*
03d5e4f
       * Execute the command.
03d5e4f
--- 5516,5572 ----
03d5e4f
      /*
03d5e4f
       * Now grab the chars in the identifier
03d5e4f
       */
03d5e4f
!     if (cmdchar == 'K' && !kp_help)
03d5e4f
!     {
03d5e4f
! 	/* Escape the argument properly for a shell command */
03d5e4f
! 	p = vim_strsave_shellescape(ptr, TRUE);
03d5e4f
! 	if (p == NULL)
03d5e4f
  	{
03d5e4f
! 	    vim_free(buf);
03d5e4f
! 	    return;
03d5e4f
  	}
03d5e4f
+ 	buf = (char_u *)vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1);
03d5e4f
+ 	if (buf == NULL)
03d5e4f
+ 	{
03d5e4f
+ 	    vim_free(buf);
03d5e4f
+ 	    vim_free(p);
03d5e4f
+ 	    return;
03d5e4f
+ 	}
03d5e4f
+ 	STRCAT(buf, p);
03d5e4f
+ 	vim_free(p);
03d5e4f
+     }
03d5e4f
+     else
03d5e4f
+     {
03d5e4f
+ 	if (cmdchar == '*')
03d5e4f
+ 	    aux_ptr = (char_u *)(p_magic ? "/.*~[^$\\" : "/^$\\");
03d5e4f
+ 	else if (cmdchar == '#')
03d5e4f
+ 	    aux_ptr = (char_u *)(p_magic ? "/?.*~[^$\\" : "/?^$\\");
03d5e4f
+ 	else
03d5e4f
+ 	    /* Don't escape spaces and Tabs in a tag with a backslash */
03d5e4f
+ 	    aux_ptr = (char_u *)"\\|\"\n*?[";
03d5e4f
+ 
03d5e4f
+ 	p = buf + STRLEN(buf);
03d5e4f
+ 	while (n-- > 0)
03d5e4f
+ 	{
03d5e4f
+ 	    /* put a backslash before \ and some others */
03d5e4f
+ 	    if (vim_strchr(aux_ptr, *ptr) != NULL)
03d5e4f
+ 		*p++ = '\\';
03d5e4f
+ #ifdef FEAT_MBYTE
03d5e4f
+ 	    /* When current byte is a part of multibyte character, copy all
03d5e4f
+ 	     * bytes of that character. */
03d5e4f
+ 	    if (has_mbyte)
03d5e4f
+ 	    {
03d5e4f
+ 		int i;
03d5e4f
+ 		int len = (*mb_ptr2len)(ptr) - 1;
03d5e4f
+ 
03d5e4f
+ 		for (i = 0; i < len && n >= 1; ++i, --n)
03d5e4f
+ 		    *p++ = *ptr++;
03d5e4f
+ 	    }
03d5e4f
  #endif
03d5e4f
! 	    *p++ = *ptr++;
03d5e4f
! 	}
03d5e4f
! 	*p = NUL;
03d5e4f
      }
03d5e4f
  
03d5e4f
      /*
03d5e4f
       * Execute the command.
03d5e4f
*** ../vim-7.2.009/src/version.c	Mon Sep  1 17:56:05 2008
03d5e4f
--- src/version.c	Sat Sep  6 16:26:42 2008
03d5e4f
***************
03d5e4f
*** 678,679 ****
03d5e4f
--- 678,681 ----
03d5e4f
  {   /* Add new patch number below this line */
03d5e4f
+ /**/
03d5e4f
+     10,
03d5e4f
  /**/
03d5e4f
03d5e4f
-- 
03d5e4f
Q. What happens to programmers when they die?
03d5e4f
A: MS-Windows programmers are reinstalled.  C++ programmers become undefined,
03d5e4f
   anyone who refers to them will die as well.  Java programmers reincarnate
03d5e4f
   after being garbage collected.
03d5e4f
03d5e4f
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
03d5e4f
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
03d5e4f
\\\        download, build and distribute -- http://www.A-A-P.org        ///
03d5e4f
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///