8000 * win32/win32.c (rb_w32_write_console): this function converts output… · documenting-ruby/ruby@058358b · GitHub
[go: up one dir, main page]

Skip to content

Commit 058358b

Browse files
committed
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/win32-unicode-test@17825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent ca7ac31 commit 058358b

File tree

6 files changed

+53
-0
lines changed

6 files changed

+53
-0
lines changed

ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
Thu Jul 3 01:19:00 2008 NARUSE, Yui <naruse@ruby-lang.org>
2+
3+
* win32/win32.c (rb_w32_write_console): this function converts output characters
4+
to Unicode character and write it to Windows Connsole.
5+
6+
* include/ruby/win32.h (rb_w32_write_console): ditto.
7+
8+
* io.c (io_fwrite): use rb_w32_write_console when output is console and
9+
the system is win32.
10+
11+
* transcode.c (rb_transcode_convertible): defined.
12+
13+
* include/ruby/encoding.h (rb_transcode_convertible): ditto.
14+
115
Thu Jul 3 00:18:00 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
216

317
* ext/win32ole/win32ole.c: avoid creating Ruby object during

include/ruby/encoding.h

< 10000 div class="d-flex mr-2 flex-justify-end flex-items-center flex-1">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ rb_enc_dummy_p(rb_encoding *enc)
192192
return ENC_DUMMY_P(ENC_FROM_ENCODING(enc));
193193
}
194194

195+
int rb_transcode_convertible(const char* from_encoding, const char* to_encoding);
195196
VALUE rb_str_transcode(VALUE str, VALUE to);
196197

197198
#endif /* RUBY_ENCODING_H */

include/ruby/win32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ int rb_w32_fclose(FILE*);
548548
size_t rb_w32_read(int, void *, size_t);
549549
size_t rb_w32_write(int, const void *, size_t);
550550
int rb_w32_utime(const char *, const struct utimbuf *);
551+
long rb_w32_write_console(unsigned long, int);
551552
int WINAPI rb_w32_Sleep(unsigned long msec);
552553
int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
553554

io.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ruby/ruby.h"
1515
#include "ruby/io.h"
1616
#include "ruby/signal.h"
17+
#include "ruby/win32.h"
1718
#include "vm_core.h"
1819
#include <ctype.h>
1920
#include <errno.h>
@@ -689,6 +690,11 @@ io_fwrite(VALUE str, rb_io_t *fptr)
689690
{
690691
long len, n, r, l, offset = 0;
691692

693+
#ifdef _WIN32
694+
len = rb_w32_write_console(str, fptr->fd);
695+
if (len >= 0) return len;
696+
#endif
697+
692698
/*
693699
* If an external encoding was specified and it differs from
694700
* the strings encoding then we must transcode before writing.

transcode.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ transcode_dispatch(const char* from_encoding, const char* to_encoding)
119119
return (rb_transcoder *)val;
120120
}
121121

122+
/*
123+
* experimental.
124+
*/
125+
int
126+
rb_transcode_convertible(const char* from_encoding, const char* to_encoding)
127+
{
128+
return transcode_dispatch(from_encoding, to_encoding) ? TRUE : FALSE;
129+
}
122130

123131
/*
124132
* Transcoding engine logic

win32/win32.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "ruby/ruby.h"
1414
#include "ruby/signal.h"
15+
#include "ruby/encoding.h"
1516
#include "dln.h"
1617
#include <fcntl.h>
1718
#include <process.h>
@@ -3933,6 +3934,28 @@ rb_w32_write(int fd, const void *buf, size_t size)
39333934
return rb_w32_send(fd, buf, size, 0);
39343935
}
39353936

3937+
long
3938+
rb_w32_write_console(VALUE str, int fd)
3939+
{
3940+
static int disable;
3941+
HANDLE handle;
3942+
DWORD dwMode, reslen;
3943+
3944+
if (disable) return -1L;
3945+
handle = (HANDLE)_osfhnd(fd);
3946+
if (!GetConsoleMode(handle, &dwMode) ||
3947+
!rb_transcode_convertible(rb_enc_name(rb_enc_get(str)), "UTF-16LE"))
3948+
return -1L;
3949+
3950+
str = rb_str_transcode(str, rb_str_new2("UTF-16LE"));
3951+
if (!WriteConsoleW(handle, (LPWSTR)RSTRING_PTR(str), RSTRING_LEN(str)/2, &reslen, NULL)) {
3952+
if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
3953+
disable = TRUE;
3954+
return -1L;
3955+
}
3956+
return (long)reslen;
3957+
}
3958+
39363959
static int
39373960
unixtime_to_filetime(time_t time, FILETIME *ft)
39383961
{

0 commit comments

Comments
 (0)
0