lkundrak / rpms / vim

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