jkunstle / rpms / vim

Forked from rpms/vim 3 years ago
Clone

Blame SOURCES/7.4.247

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