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

ruby-changes:6428

From: usa <ko1@a...>
Date: Tue, 8 Jul 2008 00:11:07 +0900 (JST)
Subject: [ruby-changes:6428] Ruby:r17944 (win32-unicode-test): * win32/win32.c, include/win32/win32.c (rb_w32_parse_cmndline): new

usa	2008-07-08 00:06:39 +0900 (Tue, 08 Jul 2008)

  New Revision: 17944

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

  Log:
    * win32/win32.c, include/win32/win32.c (rb_w32_parse_cmndline): new
      function to parse command line from GetCommandLineW().
      this is incomplete.
    
    * ruby.c (process_options): use rb_w32_parse_cmdline(). this is
      incomplete, too.
    
    * win32/win32.c (rb_w32_write_console): sorry, pullup mistake.
    


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

Index: win32-unicode-test/include/ruby/win32.h
===================================================================
--- win32-unicode-test/include/ruby/win32.h	(revision 17943)
+++ win32-unicode-test/include/ruby/win32.h	(revision 17944)
@@ -208,6 +208,7 @@
 #define isascii __isascii
 #endif
 #define NtInitialize ruby_sysinit
+extern int    rb_w32_parse_cmdline(char ***, const char *);
 extern int    rb_w32_cmdvector(const char *, char ***);
 extern rb_pid_t  rb_w32_pipe_exec(const char *, const char *, int, int *, int *);
 extern int    flock(int fd, int oper);
Index: win32-unicode-test/ChangeLog
===================================================================
--- win32-unicode-test/ChangeLog	(revision 17943)
+++ win32-unicode-test/ChangeLog	(revision 17944)
@@ -1,3 +1,14 @@
+Tue Jul  8 00:03:20 2008  NAKAMURA Usaku  <usa@r...>
+
+	* win32/win32.c, include/win32/win32.c (rb_w32_parse_cmndline): new
+	  function to parse command line from GetCommandLineW().
+	  this is incomplete.
+
+	* ruby.c (process_options): use rb_w32_parse_cmdline(). this is
+	  incomplete, too.
+
+	* win32/win32.c (rb_w32_write_console): sorry, pullup mistake.
+
 Mon Jul  7 20:39:28 2008  Masaki Suketa  <masaki.suketa@n...>
 
 	* ext/win32ole/win32ole.c(Init_win32ole): add
Index: win32-unicode-test/win32/win32.c
===================================================================
--- win32-unicode-test/win32/win32.c	(revision 17943)
+++ win32-unicode-test/win32/win32.c	(revision 17944)
@@ -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>
@@ -1144,7 +1145,31 @@
     return ptr;
 }
 
-int 
+int
+rb_w32_parse_cmdline(char ***vec, const char *enc)
+{
+    WCHAR *wcmd;
+    char *cmd;
+    VALUE str;
+
+    if (enc) {
+	if (!rb_transcode_convertible("UTF-16LE", enc))
+	    return 0;
+	wcmd = GetCommandLineW();
+	str = rb_str_transcode(rb_enc_str_new((char *)wcmd,
+					      lstrlenW(wcmd) * sizeof(WCHAR),
+					      rb_enc_find("UTF-16LE")),
+			       rb_str_new2(enc));
+	cmd = RSTRING_PTR(str);
+    }
+    else {
+	cmd = GetCommandLineA();
+    }
+
+    return rb_w32_cmdvector(cmd, vec);
+}
+
+int
 rb_w32_cmdvector(const char *cmd, char ***vec)
 {
     int globbing, len;
@@ -3933,6 +3958,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/ruby.c
===================================================================
--- win32-unicode-test/ruby.c	(revision 17943)
+++ win32-unicode-test/ruby.c	(revision 17944)
@@ -970,11 +970,12 @@
     rb_encoding *enc, *lenc;
     const char *s;
     char fbuf[MAXPATHLEN];
-    int i = proc_options(argc, argv, opt);
+    int opnum = proc_options(argc, argv, opt);
+    int i;
     int safe;
 
-    argc -= i;
-    argv += i;
+    argc -= opnum;
+    argv += opnum;
 
     if (!(opt->disable & DISABLE_BIT(rubyopt)) &&
 	rb_safe_level() == 0 && (s = getenv("RUBYOPT"))) {
@@ -1058,6 +1059,7 @@
 		if (!opt->script)
 		    opt->script = argv[0];
 	    }
+	    opnum++;
 	    argc--;
 	    argv++;
 	}
@@ -1096,6 +1098,15 @@
 	enc = lenc;
     }
     rb_enc_set_default_external(rb_enc_from_encoding(enc));
+#ifdef _WIN32
+    if ((argc = rb_w32_parse_cmdline(&argv, rb_enc_name(enc))) != 0) {
+	argc -= opnum;
+	argv += opnum;
+	ruby_set_argv(argc, argv);
+	for (i = 0; i < RARRAY_LEN(rb_argv); i++)
+	    rb_enc_associate(RARRAY_PTR(rb_argv)[i], enc);
+    }
+#endif
 
     rb_set_safe_level_force(safe);
     if (opt->e_script) {

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

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