073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.247
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.247
073263
Problem:    When passing input to system() there is no way to keep NUL and
073263
	    NL characters separate.
073263
Solution:   Optionally use a list for the system() input. (ZyX)
073263
Files:	    runtime/doc/eval.txt, src/eval.c
073263
073263
073263
*** ../vim-7.4.246/runtime/doc/eval.txt	2014-04-02 22:16:59.995482236 +0200
073263
--- runtime/doc/eval.txt	2014-04-05 18:47:12.907153201 +0200
073263
***************
073263
*** 5951,5960 ****
073263
  
073263
  system({expr} [, {input}])				*system()* *E677*
073263
  		Get the output of the shell command {expr}.
073263
! 		When {input} is given, this string is written to a file and
073263
! 		passed as stdin to the command.  The string is written as-is,
073263
! 		you need to take care of using the correct line separators
073263
! 		yourself.  Pipes are not used.
073263
  		Note: Use |shellescape()| or |::S| with |expand()| or 
073263
  		|fnamemodify()| to escape special characters in a command 
073263
  		argument.  Newlines in {expr} may cause the command to fail.  
073263
--- 5964,5980 ----
073263
  
073263
  system({expr} [, {input}])				*system()* *E677*
073263
  		Get the output of the shell command {expr}.
073263
! 
073263
! 		When {input} is given and is a string this string is written 
073263
! 		to a file and passed as stdin to the command.  The string is 
073263
! 		written as-is, you need to take care of using the correct line 
073263
! 		separators yourself.
073263
! 		If {input} is given and is a |List| it is written to the file
073263
! 		in a way |writefile()| does with {binary} set to "b" (i.e.
073263
! 		with a newline between each list item with newlines inside
073263
! 		list items converted to NULs).  
073263
! 		Pipes are not used.
073263
! 
073263
  		Note: Use |shellescape()| or |::S| with |expand()| or 
073263
  		|fnamemodify()| to escape special characters in a command 
073263
  		argument.  Newlines in {expr} may cause the command to fail.  
073263
*** ../vim-7.4.246/src/eval.c	2014-04-02 22:17:00.003482236 +0200
073263
--- src/eval.c	2014-04-05 18:47:50.971153284 +0200
073263
***************
073263
*** 836,841 ****
073263
--- 836,842 ----
073263
  static int searchpair_cmn __ARGS((typval_T *argvars, pos_T *match_pos));
073263
  static int search_cmn __ARGS((typval_T *argvars, pos_T *match_pos, int *flagsp));
073263
  static void setwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off));
073263
+ static int write_list __ARGS((FILE *fd, list_T *list, int binary));
073263
  
073263
  
073263
  #ifdef EBCDIC
073263
***************
073263
*** 18267,18280 ****
073263
  	    EMSG2(_(e_notopen), infile);
073263
  	    goto done;
073263
  	}
073263
! 	p = get_tv_string_buf_chk(&argvars[1], buf);
073263
! 	if (p == NULL)
073263
  	{
073263
! 	    fclose(fd);
073263
! 	    goto done;		/* type error; errmsg already given */
073263
  	}
073263
- 	if (fwrite(p, STRLEN(p), 1, fd) != 1)
073263
- 	    err = TRUE;
073263
  	if (fclose(fd) != 0)
073263
  	    err = TRUE;
073263
  	if (err)
073263
--- 18268,18289 ----
073263
  	    EMSG2(_(e_notopen), infile);
073263
  	    goto done;
073263
  	}
073263
! 	if (argvars[1].v_type == VAR_LIST)
073263
  	{
073263
! 	    if (write_list(fd, argvars[1].vval.v_list, TRUE) == FAIL)
073263
! 		err = TRUE;
073263
! 	}
073263
! 	else
073263
! 	{
073263
! 	    p = get_tv_string_buf_chk(&argvars[1], buf);
073263
! 	    if (p == NULL)
073263
! 	    {
073263
! 		fclose(fd);
073263
! 		goto done;		/* type error; errmsg already given */
073263
! 	    }
073263
! 	    if (fwrite(p, STRLEN(p), 1, fd) != 1)
073263
! 		err = TRUE;
073263
  	}
073263
  	if (fclose(fd) != 0)
073263
  	    err = TRUE;
073263
  	if (err)
073263
***************
073263
*** 19173,19178 ****
073263
--- 19182,19230 ----
073263
  }
073263
  
073263
  /*
073263
+  * Write list of strings to file
073263
+  */
073263
+     static int
073263
+ write_list(fd, list, binary)
073263
+     FILE	*fd;
073263
+     list_T	*list;
073263
+     int		binary;
073263
+ {
073263
+     listitem_T	*li;
073263
+     int		c;
073263
+     int		ret = OK;
073263
+     char_u	*s;
073263
+ 
073263
+     for (li = list->lv_first; li != NULL; li = li->li_next)
073263
+     {
073263
+ 	for (s = get_tv_string(&li->li_tv); *s != NUL; ++s)
073263
+ 	{
073263
+ 	    if (*s == '\n')
073263
+ 		c = putc(NUL, fd);
073263
+ 	    else
073263
+ 		c = putc(*s, fd);
073263
+ 	    if (c == EOF)
073263
+ 	    {
073263
+ 		ret = FAIL;
073263
+ 		break;
073263
+ 	    }
073263
+ 	}
073263
+ 	if (!binary || li->li_next != NULL)
073263
+ 	    if (putc('\n', fd) == EOF)
073263
+ 	    {
073263
+ 		ret = FAIL;
073263
+ 		break;
073263
+ 	    }
073263
+ 	if (ret == FAIL)
073263
+ 	{
073263
+ 	    EMSG(_(e_write));
073263
+ 	    break;
073263
+ 	}
073263
+     }
073263
+     return ret;
073263
+ }
073263
+ 
073263
+ /*
073263
   * "writefile()" function
073263
   */
073263
      static void
073263
***************
073263
*** 19183,19192 ****
073263
      int		binary = FALSE;
073263
      char_u	*fname;
073263
      FILE	*fd;
073263
-     listitem_T	*li;
073263
-     char_u	*s;
073263
      int		ret = 0;
073263
-     int		c;
073263
  
073263
      if (check_restricted() || check_secure())
073263
  	return;
073263
--- 19235,19241 ----
073263
***************
073263
*** 19213,19245 ****
073263
      }
073263
      else
073263
      {
073263
! 	for (li = argvars[0].vval.v_list->lv_first; li != NULL;
073263
! 							     li = li->li_next)
073263
! 	{
073263
! 	    for (s = get_tv_string(&li->li_tv); *s != NUL; ++s)
073263
! 	    {
073263
! 		if (*s == '\n')
073263
! 		    c = putc(NUL, fd);
073263
! 		else
073263
! 		    c = putc(*s, fd);
073263
! 		if (c == EOF)
073263
! 		{
073263
! 		    ret = -1;
073263
! 		    break;
073263
! 		}
073263
! 	    }
073263
! 	    if (!binary || li->li_next != NULL)
073263
! 		if (putc('\n', fd) == EOF)
073263
! 		{
073263
! 		    ret = -1;
073263
! 		    break;
073263
! 		}
073263
! 	    if (ret < 0)
073263
! 	    {
073263
! 		EMSG(_(e_write));
073263
! 		break;
073263
! 	    }
073263
! 	}
073263
  	fclose(fd);
073263
      }
073263
  
073263
--- 19262,19269 ----
073263
      }
073263
      else
073263
      {
073263
! 	if (write_list(fd, argvars[0].vval.v_list, binary) == FAIL)
073263
! 	    ret = -1;
073263
  	fclose(fd);
073263
      }
073263
  
073263
*** ../vim-7.4.246/src/version.c	2014-04-05 12:02:20.751100138 +0200
073263
--- src/version.c	2014-04-05 18:49:24.411153488 +0200
073263
***************
073263
*** 736,737 ****
073263
--- 736,739 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     247,
073263
  /**/
073263
073263
-- 
073263
Time is an illusion.  Lunchtime doubly so.
073263
		-- Ford Prefect, in Douglas Adams'
073263
		   "The Hitchhiker's Guide to the Galaxy"
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///