073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.503
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.503
073263
Problem:    Cannot append a list of lines to a file.
073263
Solution:   Add the append option to writefile(). (Yasuhiro Matsumoto)
073263
Files:	    runtime/doc/eval.txt, src/Makefile, src/eval.c,
073263
	    src/testdir/test_writefile.in, src/testdir/test_writefile.ok
073263
073263
073263
*** ../vim-7.4.502/runtime/doc/eval.txt	2014-09-09 16:13:05.040531695 +0200
073263
--- runtime/doc/eval.txt	2014-11-05 17:57:01.592454006 +0100
073263
***************
073263
*** 2040,2046 ****
073263
  winrestview( {dict})		none	restore view of current window
073263
  winsaveview()			Dict	save view of current window
073263
  winwidth( {nr})			Number	width of window {nr}
073263
! writefile( {list}, {fname} [, {binary}])
073263
  				Number	write list of lines to file {fname}
073263
  xor( {expr}, {expr})		Number  bitwise XOR
073263
  
073263
--- 2041,2047 ----
073263
  winrestview( {dict})		none	restore view of current window
073263
  winsaveview()			Dict	save view of current window
073263
  winwidth( {nr})			Number	width of window {nr}
073263
! writefile( {list}, {fname} [, {flags}])
073263
  				Number	write list of lines to file {fname}
073263
  xor( {expr}, {expr})		Number  bitwise XOR
073263
  
073263
***************
073263
*** 6532,6545 ****
073263
    :endif
073263
  <
073263
  							*writefile()*
073263
! writefile({list}, {fname} [, {binary}])
073263
  		Write |List| {list} to file {fname}.  Each list item is
073263
  		separated with a NL.  Each list item must be a String or
073263
  		Number.
073263
! 		When {binary} is equal to "b" binary mode is used: There will
073263
  		not be a NL after the last list item.  An empty item at the
073263
  		end does cause the last line in the file to end in a NL.
073263
! 		All NL characters are replaced with a NUL character.
073263
  		Inserting CR characters needs to be done before passing {list}
073263
  		to writefile().
073263
  		An existing file is overwritten, if possible.
073263
--- 6555,6574 ----
073263
    :endif
073263
  <
073263
  							*writefile()*
073263
! writefile({list}, {fname} [, {flags}])
073263
  		Write |List| {list} to file {fname}.  Each list item is
073263
  		separated with a NL.  Each list item must be a String or
073263
  		Number.
073263
! 		When {flags} contains "b" then binary mode is used: There will
073263
  		not be a NL after the last list item.  An empty item at the
073263
  		end does cause the last line in the file to end in a NL.
073263
! 
073263
! 		When {flags} contains "a" then append mode is used, lines are
073263
! 		append to the file: >
073263
! 			:call writefile(["foo"], "event.log", "a")
073263
! 			:call writefile(["bar"], "event.log", "a")
073263
! >
073263
! <		All NL characters are replaced with a NUL character.
073263
  		Inserting CR characters needs to be done before passing {list}
073263
  		to writefile().
073263
  		An existing file is overwritten, if possible.
073263
*** ../vim-7.4.502/src/Makefile	2014-11-05 14:26:30.760758363 +0100
073263
--- src/Makefile	2014-11-05 17:54:36.864457494 +0100
073263
***************
073263
*** 1899,1906 ****
073263
--- 1899,1910 ----
073263
  	test_insertcount \
073263
  	test_listlbr \
073263
  	test_listlbr_utf8 \
073263
+ 	test_mapping \
073263
  	test_options \
073263
  	test_qf_title \
073263
+ 	test_signs \
073263
+ 	test_utf8 \
073263
+ 	test_writefile \
073263
  	test10 test11 test12 test13 test14 test15 test16 test17 test18 test19 \
073263
  	test20 test21 test22 test23 test24 test25 test26 test27 test28 test29 \
073263
  	test30 test31 test32 test33 test34 test35 test36 test37 test38 test39 \
073263
*** ../vim-7.4.502/src/eval.c	2014-11-05 16:03:40.588617886 +0100
073263
--- src/eval.c	2014-11-05 17:59:15.388450782 +0100
073263
***************
073263
*** 19689,19694 ****
073263
--- 19689,19695 ----
073263
      typval_T	*rettv;
073263
  {
073263
      int		binary = FALSE;
073263
+     int		append = FALSE;
073263
      char_u	*fname;
073263
      FILE	*fd;
073263
      int		ret = 0;
073263
***************
073263
*** 19704,19717 ****
073263
      if (argvars[0].vval.v_list == NULL)
073263
  	return;
073263
  
073263
!     if (argvars[2].v_type != VAR_UNKNOWN
073263
! 			      && STRCMP(get_tv_string(&argvars[2]), "b") == 0)
073263
! 	binary = TRUE;
073263
  
073263
      /* Always open the file in binary mode, library functions have a mind of
073263
       * their own about CR-LF conversion. */
073263
      fname = get_tv_string(&argvars[1]);
073263
!     if (*fname == NUL || (fd = mch_fopen((char *)fname, WRITEBIN)) == NULL)
073263
      {
073263
  	EMSG2(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname);
073263
  	ret = -1;
073263
--- 19705,19723 ----
073263
      if (argvars[0].vval.v_list == NULL)
073263
  	return;
073263
  
073263
!     if (argvars[2].v_type != VAR_UNKNOWN)
073263
!     {
073263
! 	if (vim_strchr(get_tv_string(&argvars[2]), 'b') != NULL)
073263
! 	    binary = TRUE;
073263
! 	if (vim_strchr(get_tv_string(&argvars[2]), 'a') != NULL)
073263
! 	    append = TRUE;
073263
!     }
073263
  
073263
      /* Always open the file in binary mode, library functions have a mind of
073263
       * their own about CR-LF conversion. */
073263
      fname = get_tv_string(&argvars[1]);
073263
!     if (*fname == NUL || (fd = mch_fopen((char *)fname,
073263
! 				      append ? APPENDBIN : WRITEBIN)) == NULL)
073263
      {
073263
  	EMSG2(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname);
073263
  	ret = -1;
073263
*** ../vim-7.4.502/src/testdir/test_writefile.in	2014-11-05 18:04:54.912442601 +0100
073263
--- src/testdir/test_writefile.in	2014-11-05 18:01:07.408448083 +0100
073263
***************
073263
*** 0 ****
073263
--- 1,18 ----
073263
+ Tests for writefile()
073263
+ 
073263
+ STARTTEST
073263
+ :source small.vim
073263
+ :%delete _
073263
+ :let f = tempname()
073263
+ :call writefile(["over","written"], f, "b")
073263
+ :call writefile(["hello","world"], f, "b")
073263
+ :call writefile(["!", "good"], f, "a")
073263
+ :call writefile(["morning"], f, "ab")
073263
+ :call writefile(["", "vimmers"], f, "ab")
073263
+ :bwipeout!
073263
+ :$put =readfile(f)
073263
+ :1 delete _
073263
+ :w! test.out
073263
+ :qa!
073263
+ ENDTEST
073263
+ 
073263
*** ../vim-7.4.502/src/testdir/test_writefile.ok	2014-11-05 18:04:54.916442601 +0100
073263
--- src/testdir/test_writefile.ok	2014-11-05 17:53:19.776459351 +0100
073263
***************
073263
*** 0 ****
073263
--- 1,5 ----
073263
+ hello
073263
+ world!
073263
+ good
073263
+ morning
073263
+ vimmers
073263
*** ../vim-7.4.502/src/version.c	2014-11-05 17:44:47.676471691 +0100
073263
--- src/version.c	2014-11-05 17:55:08.508456731 +0100
073263
***************
073263
*** 743,744 ****
073263
--- 743,746 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     503,
073263
  /**/
073263
073263
-- 
073263
BLACK KNIGHT:  Come on you pansy!
073263
    [hah] [parry thrust]
073263
    [ARTHUR chops the BLACK KNIGHT's right arm off]
073263
ARTHUR:        Victory is mine!  [kneeling]
073263
               We thank thee Lord, that in thy merc-
073263
    [Black Knight kicks Arthur in the head while he is praying]
073263
                                  The Quest for the Holy Grail (Monty Python)
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    ///