]> granicus.if.org Git - vim/commitdiff
patch 7.4.1512 v7.4.1512
authorBram Moolenaar <Bram@vim.org>
Tue, 8 Mar 2016 12:48:51 +0000 (13:48 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 8 Mar 2016 12:48:51 +0000 (13:48 +0100)
Problem:    Channel input from file not supported on MS-Windows.
Solution:   Implement it. (Yasuhiro Matsumoto)

src/os_win32.c
src/testdir/test_channel.vim
src/version.c

index 9201b349727f57e6d57febe8575a5d5ae89e7e24..12b156aaeec5866c40dd3c8e2e988b02f1bc200f 100644 (file)
@@ -5039,10 +5039,31 @@ mch_start_job(char *cmd, job_T *job, jobopt_T *options)
     if (use_file_for_in)
     {
        char_u *fname = options->jo_io_name[PART_IN];
+#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
 
-       // TODO
-       EMSG2(_(e_notopen), fname);
-       goto failed;
+           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, jobopt_T *options)
     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;
 
index 3f6511ad07f112041bfd5c4fbfedfeae6a1957bc..dd7ef4ec40549f92772618a82cda0bf28a020c76 100644 (file)
@@ -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",
index 6141a2e4eb8badbb908b12b12fa4289aaec60b7b..eb9c48667f0d89d62e7cdf691ca1d3cc6b033382 100644 (file)
@@ -743,6 +743,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1512,
 /**/
     1511,
 /**/