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