Karsten Hopp 2022ac
To: vim-dev@vim.org
Karsten Hopp 2022ac
Subject: Patch 7.1.223
Karsten Hopp 2022ac
Fcc: outbox
Karsten Hopp 2022ac
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 2022ac
Mime-Version: 1.0
Karsten Hopp 2022ac
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 2022ac
Content-Transfer-Encoding: 8bit
Karsten Hopp 2022ac
------------
Karsten Hopp 2022ac
Karsten Hopp 2022ac
Patch 7.1.223
Karsten Hopp 2022ac
Problem:    glob() doesn't work properly when 'shell' is "sh" or "bash" and
Karsten Hopp 2022ac
	    the expanded name contains spaces, '~', single quotes and other
Karsten Hopp 2022ac
	    special characters.  (Adri Verhoef, Charles Campbell)
Karsten Hopp 2022ac
Solution:   For Posix shells define a vimglob() function to list the matches
Karsten Hopp 2022ac
	    instead of using "echo" directly.
Karsten Hopp 2022ac
Files:	    src/os_unix.c
Karsten Hopp 2022ac
Karsten Hopp 2022ac
Karsten Hopp 2022ac
*** ../vim-7.1.222/src/os_unix.c	Thu Jan  3 18:55:21 2008
Karsten Hopp 2022ac
--- src/os_unix.c	Sun Jan 13 13:52:53 2008
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 4946,4951 ****
Karsten Hopp 2022ac
--- 4946,4954 ----
Karsten Hopp 2022ac
      char_u	*p;
Karsten Hopp 2022ac
      int		dir;
Karsten Hopp 2022ac
  #ifdef __EMX__
Karsten Hopp 2022ac
+     /*
Karsten Hopp 2022ac
+      * This is the OS/2 implementation.
Karsten Hopp 2022ac
+      */
Karsten Hopp 2022ac
  # define EXPL_ALLOC_INC	16
Karsten Hopp 2022ac
      char_u	**expl_files;
Karsten Hopp 2022ac
      size_t	files_alloced, files_free;
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 5056,5075 ****
Karsten Hopp 2022ac
      return OK;
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
  #else /* __EMX__ */
Karsten Hopp 2022ac
! 
Karsten Hopp 2022ac
      int		j;
Karsten Hopp 2022ac
      char_u	*tempname;
Karsten Hopp 2022ac
      char_u	*command;
Karsten Hopp 2022ac
      FILE	*fd;
Karsten Hopp 2022ac
      char_u	*buffer;
Karsten Hopp 2022ac
! #define STYLE_ECHO  0	    /* use "echo" to expand */
Karsten Hopp 2022ac
! #define STYLE_GLOB  1	    /* use "glob" to expand, for csh */
Karsten Hopp 2022ac
! #define STYLE_PRINT 2	    /* use "print -N" to expand, for zsh */
Karsten Hopp 2022ac
! #define STYLE_BT    3	    /* `cmd` expansion, execute the pattern directly */
Karsten Hopp 2022ac
      int		shell_style = STYLE_ECHO;
Karsten Hopp 2022ac
      int		check_spaces;
Karsten Hopp 2022ac
      static int	did_find_nul = FALSE;
Karsten Hopp 2022ac
      int		ampersent = FALSE;
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
      *num_file = 0;	/* default: no files found */
Karsten Hopp 2022ac
      *file = NULL;
Karsten Hopp 2022ac
--- 5059,5084 ----
Karsten Hopp 2022ac
      return OK;
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
  #else /* __EMX__ */
Karsten Hopp 2022ac
!     /*
Karsten Hopp 2022ac
!      * This is the non-OS/2 implementation (really Unix).
Karsten Hopp 2022ac
!      */
Karsten Hopp 2022ac
      int		j;
Karsten Hopp 2022ac
      char_u	*tempname;
Karsten Hopp 2022ac
      char_u	*command;
Karsten Hopp 2022ac
      FILE	*fd;
Karsten Hopp 2022ac
      char_u	*buffer;
Karsten Hopp 2022ac
! #define STYLE_ECHO	0	/* use "echo", the default */
Karsten Hopp 2022ac
! #define STYLE_GLOB	1	/* use "glob", for csh */
Karsten Hopp 2022ac
! #define STYLE_VIMGLOB	2	/* use "vimglob", for Posix sh */
Karsten Hopp 2022ac
! #define STYLE_PRINT	3	/* use "print -N", for zsh */
Karsten Hopp 2022ac
! #define STYLE_BT	4	/* `cmd` expansion, execute the pattern
Karsten Hopp 2022ac
! 				 * directly */
Karsten Hopp 2022ac
      int		shell_style = STYLE_ECHO;
Karsten Hopp 2022ac
      int		check_spaces;
Karsten Hopp 2022ac
      static int	did_find_nul = FALSE;
Karsten Hopp 2022ac
      int		ampersent = FALSE;
Karsten Hopp 2022ac
+ 		/* vimglob() function to define for Posix shell */
Karsten Hopp 2022ac
+     static char *sh_vimglob_func = "vimglob() { while [ $# -ge 1 ]; do echo -n \"$1\"; echo; shift; done }; vimglob >";
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
      *num_file = 0;	/* default: no files found */
Karsten Hopp 2022ac
      *file = NULL;
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 5107,5115 ****
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
      /*
Karsten Hopp 2022ac
       * Let the shell expand the patterns and write the result into the temp
Karsten Hopp 2022ac
!      * file.  if expanding `cmd` execute it directly.
Karsten Hopp 2022ac
!      * If we use csh, glob will work better than echo.
Karsten Hopp 2022ac
!      * If we use zsh, print -N will work better than glob.
Karsten Hopp 2022ac
       */
Karsten Hopp 2022ac
      if (num_pat == 1 && *pat[0] == '`'
Karsten Hopp 2022ac
  	    && (len = STRLEN(pat[0])) > 2
Karsten Hopp 2022ac
--- 5116,5132 ----
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
      /*
Karsten Hopp 2022ac
       * Let the shell expand the patterns and write the result into the temp
Karsten Hopp 2022ac
!      * file.
Karsten Hopp 2022ac
!      * STYLE_BT:	NL separated
Karsten Hopp 2022ac
!      *	    If expanding `cmd` execute it directly.
Karsten Hopp 2022ac
!      * STYLE_GLOB:	NUL separated
Karsten Hopp 2022ac
!      *	    If we use *csh, "glob" will work better than "echo".
Karsten Hopp 2022ac
!      * STYLE_PRINT:	NL or NUL separated
Karsten Hopp 2022ac
!      *	    If we use *zsh, "print -N" will work better than "glob".
Karsten Hopp 2022ac
!      * STYLE_VIMGLOB:	NL separated
Karsten Hopp 2022ac
!      *	    If we use *sh*, we define "vimglob()".
Karsten Hopp 2022ac
!      * STYLE_ECHO:	space separated.
Karsten Hopp 2022ac
!      *	    A shell we don't know, stay safe and use "echo".
Karsten Hopp 2022ac
       */
Karsten Hopp 2022ac
      if (num_pat == 1 && *pat[0] == '`'
Karsten Hopp 2022ac
  	    && (len = STRLEN(pat[0])) > 2
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 5122,5130 ****
Karsten Hopp 2022ac
  	else if (STRCMP(p_sh + len - 3, "zsh") == 0)
Karsten Hopp 2022ac
  	    shell_style = STYLE_PRINT;
Karsten Hopp 2022ac
      }
Karsten Hopp 2022ac
! 
Karsten Hopp 2022ac
!     /* "unset nonomatch; print -N >" plus two is 29 */
Karsten Hopp 2022ac
      len = STRLEN(tempname) + 29;
Karsten Hopp 2022ac
      for (i = 0; i < num_pat; ++i)
Karsten Hopp 2022ac
      {
Karsten Hopp 2022ac
  	/* Count the length of the patterns in the same way as they are put in
Karsten Hopp 2022ac
--- 5139,5155 ----
Karsten Hopp 2022ac
  	else if (STRCMP(p_sh + len - 3, "zsh") == 0)
Karsten Hopp 2022ac
  	    shell_style = STYLE_PRINT;
Karsten Hopp 2022ac
      }
Karsten Hopp 2022ac
!     if (shell_style == STYLE_ECHO && strstr((char *)gettail(p_sh),
Karsten Hopp 2022ac
! 								"sh") != NULL)
Karsten Hopp 2022ac
! 	shell_style = STYLE_VIMGLOB;
Karsten Hopp 2022ac
! 
Karsten Hopp 2022ac
!     /* Compute the length of the command.  We need 2 extra bytes: for the
Karsten Hopp 2022ac
!      * optional '&' and for the NUL.
Karsten Hopp 2022ac
!      * Worst case: "unset nonomatch; print -N >" plus two is 29 */
Karsten Hopp 2022ac
      len = STRLEN(tempname) + 29;
Karsten Hopp 2022ac
+     if (shell_style == STYLE_VIMGLOB)
Karsten Hopp 2022ac
+ 	len += STRLEN(sh_vimglob_func);
Karsten Hopp 2022ac
+ 
Karsten Hopp 2022ac
      for (i = 0; i < num_pat; ++i)
Karsten Hopp 2022ac
      {
Karsten Hopp 2022ac
  	/* Count the length of the patterns in the same way as they are put in
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 5183,5192 ****
Karsten Hopp 2022ac
--- 5208,5221 ----
Karsten Hopp 2022ac
  	    STRCAT(command, "glob >");
Karsten Hopp 2022ac
  	else if (shell_style == STYLE_PRINT)
Karsten Hopp 2022ac
  	    STRCAT(command, "print -N >");
Karsten Hopp 2022ac
+ 	else if (shell_style == STYLE_VIMGLOB)
Karsten Hopp 2022ac
+ 	    STRCAT(command, sh_vimglob_func);
Karsten Hopp 2022ac
  	else
Karsten Hopp 2022ac
  	    STRCAT(command, "echo >");
Karsten Hopp 2022ac
      }
Karsten Hopp 2022ac
+ 
Karsten Hopp 2022ac
      STRCAT(command, tempname);
Karsten Hopp 2022ac
+ 
Karsten Hopp 2022ac
      if (shell_style != STYLE_BT)
Karsten Hopp 2022ac
  	for (i = 0; i < num_pat; ++i)
Karsten Hopp 2022ac
  	{
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 5232,5239 ****
Karsten Hopp 2022ac
      if (flags & EW_SILENT)
Karsten Hopp 2022ac
  	show_shell_mess = FALSE;
Karsten Hopp 2022ac
      if (ampersent)
Karsten Hopp 2022ac
! 	STRCAT(command, "&";;		/* put the '&' back after the
Karsten Hopp 2022ac
! 					   redirection */
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
      /*
Karsten Hopp 2022ac
       * Using zsh -G: If a pattern has no matches, it is just deleted from
Karsten Hopp 2022ac
--- 5261,5267 ----
Karsten Hopp 2022ac
      if (flags & EW_SILENT)
Karsten Hopp 2022ac
  	show_shell_mess = FALSE;
Karsten Hopp 2022ac
      if (ampersent)
Karsten Hopp 2022ac
! 	STRCAT(command, "&";;		/* put the '&' after the redirection */
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
      /*
Karsten Hopp 2022ac
       * Using zsh -G: If a pattern has no matches, it is just deleted from
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 5265,5271 ****
Karsten Hopp 2022ac
      show_shell_mess = TRUE;
Karsten Hopp 2022ac
      vim_free(command);
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
!     if (i)				/* mch_call_shell() failed */
Karsten Hopp 2022ac
      {
Karsten Hopp 2022ac
  	mch_remove(tempname);
Karsten Hopp 2022ac
  	vim_free(tempname);
Karsten Hopp 2022ac
--- 5293,5299 ----
Karsten Hopp 2022ac
      show_shell_mess = TRUE;
Karsten Hopp 2022ac
      vim_free(command);
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
!     if (i != 0)				/* mch_call_shell() failed */
Karsten Hopp 2022ac
      {
Karsten Hopp 2022ac
  	mch_remove(tempname);
Karsten Hopp 2022ac
  	vim_free(tempname);
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 5336,5342 ****
Karsten Hopp 2022ac
      }
Karsten Hopp 2022ac
      vim_free(tempname);
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
! #if defined(__CYGWIN__) || defined(__CYGWIN32__)
Karsten Hopp 2022ac
      /* Translate <CR><NL> into <NL>.  Caution, buffer may contain NUL. */
Karsten Hopp 2022ac
      p = buffer;
Karsten Hopp 2022ac
      for (i = 0; i < len; ++i)
Karsten Hopp 2022ac
--- 5364,5370 ----
Karsten Hopp 2022ac
      }
Karsten Hopp 2022ac
      vim_free(tempname);
Karsten Hopp 2022ac
  
Karsten Hopp 2022ac
! # if defined(__CYGWIN__) || defined(__CYGWIN32__)
Karsten Hopp 2022ac
      /* Translate <CR><NL> into <NL>.  Caution, buffer may contain NUL. */
Karsten Hopp 2022ac
      p = buffer;
Karsten Hopp 2022ac
      for (i = 0; i < len; ++i)
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 5359,5365 ****
Karsten Hopp 2022ac
  	}
Karsten Hopp 2022ac
      }
Karsten Hopp 2022ac
      /* file names are separated with NL */
Karsten Hopp 2022ac
!     else if (shell_style == STYLE_BT)
Karsten Hopp 2022ac
      {
Karsten Hopp 2022ac
  	buffer[len] = NUL;		/* make sure the buffer ends in NUL */
Karsten Hopp 2022ac
  	p = buffer;
Karsten Hopp 2022ac
--- 5387,5393 ----
Karsten Hopp 2022ac
  	}
Karsten Hopp 2022ac
      }
Karsten Hopp 2022ac
      /* file names are separated with NL */
Karsten Hopp 2022ac
!     else if (shell_style == STYLE_BT || shell_style == STYLE_VIMGLOB)
Karsten Hopp 2022ac
      {
Karsten Hopp 2022ac
  	buffer[len] = NUL;		/* make sure the buffer ends in NUL */
Karsten Hopp 2022ac
  	p = buffer;
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 5438,5444 ****
Karsten Hopp 2022ac
      {
Karsten Hopp 2022ac
  	(*file)[i] = p;
Karsten Hopp 2022ac
  	/* Space or NL separates */
Karsten Hopp 2022ac
! 	if (shell_style == STYLE_ECHO || shell_style == STYLE_BT)
Karsten Hopp 2022ac
  	{
Karsten Hopp 2022ac
  	    while (!(shell_style == STYLE_ECHO && *p == ' ')
Karsten Hopp 2022ac
  						   && *p != '\n' && *p != NUL)
Karsten Hopp 2022ac
--- 5466,5473 ----
Karsten Hopp 2022ac
      {
Karsten Hopp 2022ac
  	(*file)[i] = p;
Karsten Hopp 2022ac
  	/* Space or NL separates */
Karsten Hopp 2022ac
! 	if (shell_style == STYLE_ECHO || shell_style == STYLE_BT
Karsten Hopp 2022ac
! 					      || shell_style == STYLE_VIMGLOB)
Karsten Hopp 2022ac
  	{
Karsten Hopp 2022ac
  	    while (!(shell_style == STYLE_ECHO && *p == ' ')
Karsten Hopp 2022ac
  						   && *p != '\n' && *p != NUL)
Karsten Hopp 2022ac
*** ../vim-7.1.222/src/version.c	Sun Jan 13 13:30:34 2008
Karsten Hopp 2022ac
--- src/version.c	Sun Jan 13 13:45:04 2008
Karsten Hopp 2022ac
***************
Karsten Hopp 2022ac
*** 668,669 ****
Karsten Hopp 2022ac
--- 668,671 ----
Karsten Hopp 2022ac
  {   /* Add new patch number below this line */
Karsten Hopp 2022ac
+ /**/
Karsten Hopp 2022ac
+     223,
Karsten Hopp 2022ac
  /**/
Karsten Hopp 2022ac
Karsten Hopp 2022ac
-- 
Karsten Hopp 2022ac
User:       I'm having problems with my text editor.
Karsten Hopp 2022ac
Help desk:  Which editor are you using?
Karsten Hopp 2022ac
User:       I don't know, but it's version VI (pronounced: 6).
Karsten Hopp 2022ac
Help desk:  Oh, then you should upgrade to version VIM (pronounced: 994).
Karsten Hopp 2022ac
Karsten Hopp 2022ac
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 2022ac
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 2022ac
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 2022ac
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///