changeset 8443:6c421014a0b3 v7.4.1512

commit https://github.com/vim/vim/commit/94d0191dbcce829ad9b92d902b6e2717041db3b8 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 8 13:48:51 2016 +0100 patch 7.4.1512 Problem: Channel input from file not supported on MS-Windows. Solution: Implement it. (Yasuhiro Matsumoto)
author Christian Brabandt <cb@256bit.org>
date Tue, 08 Mar 2016 14:00:05 +0100
parents d2dd8de62539
children 865b2c46e625
files src/os_win32.c src/testdir/test_channel.vim src/version.c
diffstat 3 files changed, 36 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -5039,10 +5039,31 @@ mch_start_job(char *cmd, job_T *job, job
     if (use_file_for_in)
     {
 	char_u *fname = options->jo_io_name[PART_IN];
-
-	// TODO
-	EMSG2(_(e_notopen), fname);
-	goto failed;
+#ifdef FEAT_MBYTE
+	WCHAR *wn = NULL;
+	if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
+	{
+	    wn = enc_to_utf16(fname, NULL);
+	    if (wn != NULL)
+	    {
+		ifd[0] = CreateFileW(wn, GENERIC_WRITE, FILE_SHARE_READ,
+			 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+		vim_free(wn);
+		if (ifd[0] == INVALID_HANDLE_VALUE
+			      && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
+		    wn = NULL;
+	    }
+	}
+	if (wn == NULL)
+#endif
+
+	    ifd[0] = CreateFile((LPCSTR)fname, GENERIC_READ, FILE_SHARE_READ,
+			 &saAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+	if (ifd[0] == INVALID_HANDLE_VALUE)
+	{
+	    EMSG2(_(e_notopen), fname);
+	    goto failed;
+	}
     }
     else if (!CreatePipe(&ifd[0], &ifd[1], &saAttr, 0)
 	    || !pSetHandleInformation(ifd[1], HANDLE_FLAG_INHERIT, 0))
@@ -5088,18 +5109,21 @@ mch_start_job(char *cmd, job_T *job, job
     job->jv_status = JOB_STARTED;
 
 # ifdef FEAT_CHANNEL
-    CloseHandle(ifd[0]);
+    if (!use_file_for_in)
+	CloseHandle(ifd[0]);
     CloseHandle(ofd[1]);
     if (!use_out_for_err)
 	CloseHandle(efd[1]);
 
     job->jv_channel = channel;
-    channel_set_pipes(channel, (sock_T)ifd[1], (sock_T)ofd[0],
-			       use_out_for_err ? INVALID_FD : (sock_T)efd[0]);
+    channel_set_pipes(channel,
+		    use_file_for_in ? INVALID_FD : (sock_T)ifd[1],
+		    (sock_T)ofd[0],
+		    use_out_for_err ? INVALID_FD : (sock_T)efd[0]);
     channel_set_job(channel, job, options);
-#   ifdef FEAT_GUI
-     channel_gui_register(channel);
-#   endif
+#  ifdef FEAT_GUI
+    channel_gui_register(channel);
+#  endif
 # endif
     return;
 
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -538,10 +538,6 @@ func Test_nl_read_file()
   if !has('job')
     return
   endif
-  " TODO: make this work for MS-Windows.
-  if !has('unix')
-    return
-  endif
   call ch_log('Test_nl_read_file()')
   call writefile(['echo something', 'echoerr wrong', 'double this'], 'Xinput')
   let job = job_start(s:python . " test_channel_pipe.py",
--- a/src/version.c
+++ b/src/version.c
@@ -744,6 +744,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1512,
+/**/
     1511,
 /**/
     1510,