[前][次][番号順一覧][スレッド一覧]

ruby-changes:6309

From: naruse <ko1@a...>
Date: Thu, 3 Jul 2008 01:27:32 +0900 (JST)
Subject: [ruby-changes:6309] Ruby:r17825 (win32-unicode-test): * win32/win32.c (rb_w32_write_console): this function converts output characters

naruse	2008-07-03 01:27:15 +0900 (Thu, 03 Jul 2008)

  New Revision: 17825

  Modified files:
    branches/win32-unicode-test/ChangeLog
    branches/win32-unicode-test/include/ruby/encoding.h
    branches/win32-unicode-test/include/ruby/win32.h
    branches/win32-unicode-test/io.c
    branches/win32-unicode-test/transcode.c
    branches/win32-unicode-test/win32/win32.c

  Log:
    * win32/win32.c (rb_w32_write_console): this function converts output characters
      to Unicode character and write it to Windows Connsole.
    
    * include/ruby/win32.h (rb_w32_write_console): ditto.
    
    * io.c (io_fwrite): use rb_w32_write_console when output is console and
      the system is win32.
    
    * transcode.c (rb_transcode_convertible): defined.
    
    * include/ruby/encoding.h (rb_transcode_convertible): ditto.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17825

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/win32-unicode-test/win32/win32.c?r1=17825&r2=17824&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/win32-unicode-test/io.c?r1=17825&r2=17824&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/win32-unicode-test/include/ruby/encoding.h?r1=17825&r2=17824&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/win32-unicode-test/ChangeLog?r1=17825&r2=17824&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/win32-unicode-test/include/ruby/win32.h?r1=17825&r2=17824&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/win32-unicode-test/transcode.c?r1=17825&r2=17824&diff_format=u

Index: win32-unicode-test/include/ruby/win32.h
===================================================================
--- win32-unicode-test/include/ruby/win32.h	(revision 17824)
+++ win32-unicode-test/include/ruby/win32.h	(revision 17825)
@@ -548,6 +548,7 @@
 size_t rb_w32_read(int, void *, size_t);
 size_t rb_w32_write(int, const void *, size_t);
 int  rb_w32_utime(const char *, const struct utimbuf *);
+long rb_w32_write_console(unsigned long, int);
 int  WINAPI rb_w32_Sleep(unsigned long msec);
 int  rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
 
Index: win32-unicode-test/include/ruby/encoding.h
===================================================================
--- win32-unicode-test/include/ruby/encoding.h	(revision 17824)
+++ win32-unicode-test/include/ruby/encoding.h	(revision 17825)
@@ -192,6 +192,7 @@
     return ENC_DUMMY_P(ENC_FROM_ENCODING(enc));
 }
 
+int rb_transcode_convertible(const char* from_encoding, const char* to_encoding);
 VALUE rb_str_transcode(VALUE str, VALUE to);
 
 #endif /* RUBY_ENCODING_H */
Index: win32-unicode-test/ChangeLog
===================================================================
--- win32-unicode-test/ChangeLog	(revision 17824)
+++ win32-unicode-test/ChangeLog	(revision 17825)
@@ -1,3 +1,17 @@
+Thu Jul  3 01:19:00 2008  NARUSE, Yui  <naruse@r...>
+
+	* win32/win32.c (rb_w32_write_console): this function converts output characters
+	  to Unicode character and write it to Windows Connsole.
+
+	* include/ruby/win32.h (rb_w32_write_console): ditto.
+	
+	* io.c (io_fwrite): use rb_w32_write_console when output is console and
+	  the system is win32.
+
+	* transcode.c (rb_transcode_convertible): defined.
+
+	* include/ruby/encoding.h (rb_transcode_convertible): ditto.
+
 Thu Jul  3 00:18:00 2008  Masaki Suketa  <masaki.suketa@n...>
 
 	* ext/win32ole/win32ole.c: avoid creating Ruby object during
Index: win32-unicode-test/io.c
===================================================================
--- win32-unicode-test/io.c	(revision 17824)
+++ win32-unicode-test/io.c	(revision 17825)
@@ -14,6 +14,7 @@
 #include "ruby/ruby.h"
 #include "ruby/io.h"
 #include "ruby/signal.h"
+#include "ruby/win32.h"
 #include "vm_core.h"
 #include <ctype.h>
 #include <errno.h>
@@ -689,6 +690,11 @@
 {
     long len, n, r, l, offset = 0;
 
+#ifdef _WIN32
+    len = rb_w32_write_console(str, fptr->fd);
+    if (len >= 0) return len;
+#endif
+
     /*
      * If an external encoding was specified and it differs from
      * the strings encoding then we must transcode before writing.
Index: win32-unicode-test/win32/win32.c
===================================================================
--- win32-unicode-test/win32/win32.c	(revision 17824)
+++ win32-unicode-test/win32/win32.c	(revision 17825)
@@ -12,6 +12,7 @@
 
 #include "ruby/ruby.h"
 #include "ruby/signal.h"
+#include "ruby/encoding.h"
 #include "dln.h"
 #include <fcntl.h>
 #include <process.h>
@@ -3933,6 +3934,28 @@
 	return rb_w32_send(fd, buf, size, 0);
 }
 
+long
+rb_w32_write_console(VALUE str, int fd)
+{
+    static int disable;
+    HANDLE handle;
+    DWORD dwMode, reslen;
+
+    if (disable) return -1L;
+    handle = (HANDLE)_osfhnd(fd);
+    if (!GetConsoleMode(handle, &dwMode) ||
+	!rb_transcode_convertible(rb_enc_name(rb_enc_get(str)), "UTF-16LE"))
+	return -1L;
+
+    str = rb_str_transcode(str, rb_str_new2("UTF-16LE"));
+    if (!WriteConsoleW(handle, (LPWSTR)RSTRING_PTR(str), RSTRING_LEN(str)/2, &reslen, NULL)) {
+	if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
+	    disable = TRUE;
+	return -1L;
+    }
+    return (long)reslen;
+}
+
 static int
 unixtime_to_filetime(time_t time, FILETIME *ft)
 {
Index: win32-unicode-test/transcode.c
===================================================================
--- win32-unicode-test/transcode.c	(revision 17824)
+++ win32-unicode-test/transcode.c	(revision 17825)
@@ -119,6 +119,14 @@
     return (rb_transcoder *)val;
 }
 
+/*
+ * experimental.
+ */
+int
+rb_transcode_convertible(const char* from_encoding, const char* to_encoding)
+{
+    return transcode_dispatch(from_encoding, to_encoding) ? TRUE : FALSE;
+}
 
 /*
  *  Transcoding engine logic

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]