jkunstle / rpms / vim

Forked from rpms/vim 3 years ago
Clone
073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.248
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.248
073263
Problem:    Cannot distinguish between NL and NUL in output of system().
073263
Solution:   Add systemlist(). (ZyX)
073263
Files:	    runtime/doc/eval.txt, src/eval.c, src/ex_cmds2.c, src/misc1.c,
073263
	    src/proto/misc1.pro
073263
073263
073263
*** ../vim-7.4.247/runtime/doc/eval.txt	2014-04-05 18:55:40.471154309 +0200
073263
--- runtime/doc/eval.txt	2014-04-05 19:03:05.419155281 +0200
073263
***************
073263
*** 2001,2006 ****
073263
--- 2002,2008 ----
073263
  synconcealed( {lnum}, {col})	List    info about concealing
073263
  synstack( {lnum}, {col})	List	stack of syntax IDs at {lnum} and {col}
073263
  system( {expr} [, {input}])	String	output of shell command/filter {expr}
073263
+ systemlist( {expr} [, {input}])	List	output of shell command/filter {expr}
073263
  tabpagebuflist( [{arg}])	List	list of buffer numbers in tab page
073263
  tabpagenr( [{arg}])		Number	number of current or last tab page
073263
  tabpagewinnr( {tabarg}[, {arg}])
073263
***************
073263
*** 5950,5956 ****
073263
  		valid positions.
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
--- 5964,5971 ----
073263
  		valid positions.
073263
  
073263
  system({expr} [, {input}])				*system()* *E677*
073263
! 		Get the output of the shell command {expr} as a string.  See
073263
! 		|systemlist()| to get the output as a List.
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
***************
073263
*** 5998,6003 ****
073263
--- 6013,6028 ----
073263
  		Use |:checktime| to force a check.
073263
  
073263
  
073263
+ systemlist({expr} [, {input}])				*systemlist()*
073263
+ 		Same as |system()|, but returns a |List| with lines (parts of 
073263
+ 		output separated by NL) with NULs transformed into NLs. Output 
073263
+ 		is the same as |readfile()| will output with {binary} argument 
073263
+ 		set to "b".
073263
+ 
073263
+ 		Returns an empty string on error, so be careful not to run 
073263
+ 		into |E706|.
073263
+ 
073263
+ 
073263
  tabpagebuflist([{arg}])					*tabpagebuflist()*
073263
  		The result is a |List|, where each item is the number of the
073263
  		buffer associated with each window in the current tab page.
073263
*** ../vim-7.4.247/src/eval.c	2014-04-05 18:55:40.479154309 +0200
073263
--- src/eval.c	2014-04-05 19:42:37.675160463 +0200
073263
***************
073263
*** 726,731 ****
073263
--- 726,732 ----
073263
  static void f_synstack __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_synconcealed __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_system __ARGS((typval_T *argvars, typval_T *rettv));
073263
+ static void f_systemlist __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_tabpagebuflist __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_tabpagenr __ARGS((typval_T *argvars, typval_T *rettv));
073263
  static void f_tabpagewinnr __ARGS((typval_T *argvars, typval_T *rettv));
073263
***************
073263
*** 837,842 ****
073263
--- 838,844 ----
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
+ static void get_cmd_output_as_rettv __ARGS((typval_T *argvars, typval_T *rettv, int retlist));
073263
  
073263
  
073263
  #ifdef EBCDIC
073263
***************
073263
*** 8139,8144 ****
073263
--- 8141,8147 ----
073263
      {"synconcealed",	2, 2, f_synconcealed},
073263
      {"synstack",	2, 2, f_synstack},
073263
      {"system",		1, 2, f_system},
073263
+     {"systemlist",	1, 2, f_systemlist},
073263
      {"tabpagebuflist",	0, 1, f_tabpagebuflist},
073263
      {"tabpagenr",	0, 1, f_tabpagenr},
073263
      {"tabpagewinnr",	1, 2, f_tabpagewinnr},
073263
***************
073263
*** 18232,18244 ****
073263
  #endif
073263
  }
073263
  
073263
- /*
073263
-  * "system()" function
073263
-  */
073263
      static void
073263
! f_system(argvars, rettv)
073263
      typval_T	*argvars;
073263
      typval_T	*rettv;
073263
  {
073263
      char_u	*res = NULL;
073263
      char_u	*p;
073263
--- 18235,18245 ----
073263
  #endif
073263
  }
073263
  
073263
      static void
073263
! get_cmd_output_as_rettv(argvars, rettv, retlist)
073263
      typval_T	*argvars;
073263
      typval_T	*rettv;
073263
+     int		retlist;
073263
  {
073263
      char_u	*res = NULL;
073263
      char_u	*p;
073263
***************
073263
*** 18246,18254 ****
073263
      char_u	buf[NUMBUFLEN];
073263
      int		err = FALSE;
073263
      FILE	*fd;
073263
  
073263
      if (check_restricted() || check_secure())
073263
! 	goto done;
073263
  
073263
      if (argvars[1].v_type != VAR_UNKNOWN)
073263
      {
073263
--- 18247,18258 ----
073263
      char_u	buf[NUMBUFLEN];
073263
      int		err = FALSE;
073263
      FILE	*fd;
073263
+     list_T	*list = NULL;
073263
  
073263
+     rettv->v_type = VAR_STRING;
073263
+     rettv->vval.v_string = NULL;
073263
      if (check_restricted() || check_secure())
073263
! 	goto errret;
073263
  
073263
      if (argvars[1].v_type != VAR_UNKNOWN)
073263
      {
073263
***************
073263
*** 18259,18272 ****
073263
  	if ((infile = vim_tempname('i')) == NULL)
073263
  	{
073263
  	    EMSG(_(e_notmp));
073263
! 	    goto done;
073263
  	}
073263
  
073263
  	fd = mch_fopen((char *)infile, WRITEBIN);
073263
  	if (fd == NULL)
073263
  	{
073263
  	    EMSG2(_(e_notopen), infile);
073263
! 	    goto done;
073263
  	}
073263
  	if (argvars[1].v_type == VAR_LIST)
073263
  	{
073263
--- 18263,18276 ----
073263
  	if ((infile = vim_tempname('i')) == NULL)
073263
  	{
073263
  	    EMSG(_(e_notmp));
073263
! 	    goto errret;
073263
  	}
073263
  
073263
  	fd = mch_fopen((char *)infile, WRITEBIN);
073263
  	if (fd == NULL)
073263
  	{
073263
  	    EMSG2(_(e_notopen), infile);
073263
! 	    goto errret;
073263
  	}
073263
  	if (argvars[1].v_type == VAR_LIST)
073263
  	{
073263
***************
073263
*** 18279,18285 ****
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
--- 18283,18289 ----
073263
  	    if (p == NULL)
073263
  	    {
073263
  		fclose(fd);
073263
! 		goto errret;		/* type error; errmsg already given */
073263
  	    }
073263
  	    if (fwrite(p, STRLEN(p), 1, fd) != 1)
073263
  		err = TRUE;
073263
***************
073263
*** 18289,18340 ****
073263
  	if (err)
073263
  	{
073263
  	    EMSG(_("E677: Error writing temp file"));
073263
! 	    goto done;
073263
  	}
073263
      }
073263
  
073263
!     res = get_cmd_output(get_tv_string(&argvars[0]), infile,
073263
! 						 SHELL_SILENT | SHELL_COOKED);
073263
! 
073263
! #ifdef USE_CR
073263
!     /* translate <CR> into <NL> */
073263
!     if (res != NULL)
073263
      {
073263
! 	char_u	*s;
073263
  
073263
! 	for (s = res; *s; ++s)
073263
! 	{
073263
! 	    if (*s == CAR)
073263
! 		*s = NL;
073263
  	}
073263
      }
073263
! #else
073263
! # ifdef USE_CRNL
073263
!     /* translate <CR><NL> into <NL> */
073263
!     if (res != NULL)
073263
      {
073263
! 	char_u	*s, *d;
073263
  
073263
! 	d = res;
073263
! 	for (s = res; *s; ++s)
073263
  	{
073263
! 	    if (s[0] == CAR && s[1] == NL)
073263
! 		++s;
073263
! 	    *d++ = *s;
073263
  	}
073263
- 	*d = NUL;
073263
-     }
073263
  # endif
073263
  #endif
073263
  
073263
! done:
073263
      if (infile != NULL)
073263
      {
073263
  	mch_remove(infile);
073263
  	vim_free(infile);
073263
      }
073263
!     rettv->v_type = VAR_STRING;
073263
!     rettv->vval.v_string = res;
073263
  }
073263
  
073263
  /*
073263
--- 18293,18420 ----
073263
  	if (err)
073263
  	{
073263
  	    EMSG(_("E677: Error writing temp file"));
073263
! 	    goto errret;
073263
  	}
073263
      }
073263
  
073263
!     if (retlist)
073263
      {
073263
! 	int		len;
073263
! 	listitem_T	*li;
073263
! 	char_u		*s = NULL;
073263
! 	char_u		*start;
073263
! 	char_u		*end;
073263
! 	char_u		*p;
073263
! 	int		i;
073263
! 
073263
! 	res = get_cmd_output(get_tv_string(&argvars[0]), infile,
073263
! 					   SHELL_SILENT | SHELL_COOKED, &len;;
073263
! 	if (res == NULL)
073263
! 	    goto errret;
073263
! 
073263
! 	list = list_alloc();
073263
! 	if (list == NULL)
073263
! 	    goto errret;
073263
! 
073263
! 	for (i = 0; i < len; ++i)
073263
! 	{
073263
! 	    start = res + i;
073263
! 	    for (end = start; i < len && *end != NL; ++end)
073263
! 		++i;
073263
  
073263
! 	    s = vim_strnsave(start, (int)(end - start));
073263
! 	    if (s == NULL)
073263
! 		goto errret;
073263
! 
073263
! 	    for (p = s, end = s + (end - start); p < end; ++p)
073263
! 		if (*p == NUL)
073263
! 		    *p = NL;
073263
! 
073263
! 	    li = listitem_alloc();
073263
! 	    if (li == NULL)
073263
! 	    {
073263
! 		vim_free(s);
073263
! 		goto errret;
073263
! 	    }
073263
! 	    li->li_tv.v_type = VAR_STRING;
073263
! 	    li->li_tv.vval.v_string = s;
073263
! 	    list_append(list, li);
073263
  	}
073263
+ 
073263
+ 	rettv->v_type = VAR_LIST;
073263
+ 	rettv->vval.v_list = list;
073263
+ 	list = NULL;
073263
      }
073263
!     else
073263
      {
073263
! 	res = get_cmd_output(get_tv_string(&argvars[0]), infile,
073263
! 					   SHELL_SILENT | SHELL_COOKED, NULL);
073263
! #ifdef USE_CR
073263
! 	/* translate <CR> into <NL> */
073263
! 	if (res != NULL)
073263
! 	{
073263
! 	    char_u	*s;
073263
  
073263
! 	    for (s = res; *s; ++s)
073263
! 	    {
073263
! 		if (*s == CAR)
073263
! 		    *s = NL;
073263
! 	    }
073263
! 	}
073263
! #else
073263
! # ifdef USE_CRNL
073263
! 	/* translate <CR><NL> into <NL> */
073263
! 	if (res != NULL)
073263
  	{
073263
! 	    char_u	*s, *d;
073263
! 
073263
! 	    d = res;
073263
! 	    for (s = res; *s; ++s)
073263
! 	    {
073263
! 		if (s[0] == CAR && s[1] == NL)
073263
! 		    ++s;
073263
! 		*d++ = *s;
073263
! 	    }
073263
! 	    *d = NUL;
073263
  	}
073263
  # endif
073263
  #endif
073263
+ 	rettv->vval.v_string = res;
073263
+ 	res = NULL;
073263
+     }
073263
  
073263
! errret:
073263
      if (infile != NULL)
073263
      {
073263
  	mch_remove(infile);
073263
  	vim_free(infile);
073263
      }
073263
!     if (res != NULL)
073263
! 	vim_free(res);
073263
!     if (list != NULL)
073263
! 	list_free(list, TRUE);
073263
! }
073263
! 
073263
! /*
073263
!  * "system()" function
073263
!  */
073263
!     static void
073263
! f_system(argvars, rettv)
073263
!     typval_T	*argvars;
073263
!     typval_T	*rettv;
073263
! {
073263
!     get_cmd_output_as_rettv(argvars, rettv, FALSE);
073263
! }
073263
! 
073263
! /*
073263
!  * "systemlist()" function
073263
!  */
073263
!     static void
073263
! f_systemlist(argvars, rettv)
073263
!     typval_T	*argvars;
073263
!     typval_T	*rettv;
073263
! {
073263
!     get_cmd_output_as_rettv(argvars, rettv, TRUE);
073263
  }
073263
  
073263
  /*
073263
*** ../vim-7.4.247/src/ex_cmds2.c	2013-11-09 03:31:45.000000000 +0100
073263
--- src/ex_cmds2.c	2014-04-05 19:20:25.023157552 +0200
073263
***************
073263
*** 4341,4347 ****
073263
      /* Find all available locales by running command "locale -a".  If this
073263
       * doesn't work we won't have completion. */
073263
      char_u *locale_a = get_cmd_output((char_u *)"locale -a",
073263
! 							NULL, SHELL_SILENT);
073263
      if (locale_a == NULL)
073263
  	return NULL;
073263
      ga_init2(&locales_ga, sizeof(char_u *), 20);
073263
--- 4341,4347 ----
073263
      /* Find all available locales by running command "locale -a".  If this
073263
       * doesn't work we won't have completion. */
073263
      char_u *locale_a = get_cmd_output((char_u *)"locale -a",
073263
! 						    NULL, SHELL_SILENT, NULL);
073263
      if (locale_a == NULL)
073263
  	return NULL;
073263
      ga_init2(&locales_ga, sizeof(char_u *), 20);
073263
*** ../vim-7.4.247/src/misc1.c	2014-04-01 21:00:45.436733663 +0200
073263
--- src/misc1.c	2014-04-05 19:21:36.603157708 +0200
073263
***************
073263
*** 10665,10671 ****
073263
      else
073263
  #endif
073263
  	buffer = get_cmd_output(cmd, NULL,
073263
! 				      (flags & EW_SILENT) ? SHELL_SILENT : 0);
073263
      vim_free(cmd);
073263
      if (buffer == NULL)
073263
  	return 0;
073263
--- 10665,10671 ----
073263
      else
073263
  #endif
073263
  	buffer = get_cmd_output(cmd, NULL,
073263
! 				(flags & EW_SILENT) ? SHELL_SILENT : 0, NULL);
073263
      vim_free(cmd);
073263
      if (buffer == NULL)
073263
  	return 0;
073263
***************
073263
*** 10765,10777 ****
073263
  
073263
  /*
073263
   * Get the stdout of an external command.
073263
   * Returns an allocated string, or NULL for error.
073263
   */
073263
      char_u *
073263
! get_cmd_output(cmd, infile, flags)
073263
      char_u	*cmd;
073263
      char_u	*infile;	/* optional input file name */
073263
      int		flags;		/* can be SHELL_SILENT */
073263
  {
073263
      char_u	*tempname;
073263
      char_u	*command;
073263
--- 10765,10780 ----
073263
  
073263
  /*
073263
   * Get the stdout of an external command.
073263
+  * If "ret_len" is NULL replace NUL characters with NL.  When "ret_len" is not
073263
+  * NULL store the length there.
073263
   * Returns an allocated string, or NULL for error.
073263
   */
073263
      char_u *
073263
! get_cmd_output(cmd, infile, flags, ret_len)
073263
      char_u	*cmd;
073263
      char_u	*infile;	/* optional input file name */
073263
      int		flags;		/* can be SHELL_SILENT */
073263
+     int		*ret_len;
073263
  {
073263
      char_u	*tempname;
073263
      char_u	*command;
073263
***************
073263
*** 10841,10847 ****
073263
  	vim_free(buffer);
073263
  	buffer = NULL;
073263
      }
073263
!     else
073263
      {
073263
  	/* Change NUL into SOH, otherwise the string is truncated. */
073263
  	for (i = 0; i < len; ++i)
073263
--- 10844,10850 ----
073263
  	vim_free(buffer);
073263
  	buffer = NULL;
073263
      }
073263
!     else if (ret_len == NULL)
073263
      {
073263
  	/* Change NUL into SOH, otherwise the string is truncated. */
073263
  	for (i = 0; i < len; ++i)
073263
***************
073263
*** 10850,10855 ****
073263
--- 10853,10860 ----
073263
  
073263
  	buffer[len] = NUL;	/* make sure the buffer is terminated */
073263
      }
073263
+     else
073263
+ 	*ret_len = len;
073263
  
073263
  done:
073263
      vim_free(tempname);
073263
*** ../vim-7.4.247/src/proto/misc1.pro	2013-11-06 04:01:31.000000000 +0100
073263
--- src/proto/misc1.pro	2014-04-05 19:06:26.427155720 +0200
073263
***************
073263
*** 100,106 ****
073263
  void remove_duplicates __ARGS((garray_T *gap));
073263
  int gen_expand_wildcards __ARGS((int num_pat, char_u **pat, int *num_file, char_u ***file, int flags));
073263
  void addfile __ARGS((garray_T *gap, char_u *f, int flags));
073263
! char_u *get_cmd_output __ARGS((char_u *cmd, char_u *infile, int flags));
073263
  void FreeWild __ARGS((int count, char_u **files));
073263
  int goto_im __ARGS((void));
073263
  /* vim: set ft=c : */
073263
--- 100,106 ----
073263
  void remove_duplicates __ARGS((garray_T *gap));
073263
  int gen_expand_wildcards __ARGS((int num_pat, char_u **pat, int *num_file, char_u ***file, int flags));
073263
  void addfile __ARGS((garray_T *gap, char_u *f, int flags));
073263
! char_u *get_cmd_output __ARGS((char_u *cmd, char_u *infile, int flags, int *ret_len));
073263
  void FreeWild __ARGS((int count, char_u **files));
073263
  int goto_im __ARGS((void));
073263
  /* vim: set ft=c : */
073263
*** ../vim-7.4.247/src/version.c	2014-04-05 18:55:40.479154309 +0200
073263
--- src/version.c	2014-04-05 19:07:12.447155821 +0200
073263
***************
073263
*** 736,737 ****
073263
--- 736,739 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     248,
073263
  /**/
073263
073263
-- 
073263
Tips for aliens in New York: Land anywhere.  Central Park, anywhere.
073263
No one will care or indeed even notice.
073263
		-- Douglas Adams, "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    ///