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

ruby-changes:46907

From: nobu <ko1@a...>
Date: Tue, 6 Jun 2017 12:45:08 +0900 (JST)
Subject: [ruby-changes:46907] nobu:r59022 (trunk): debug.c: parse locale and filesystem codepages

nobu	2017-06-06 12:45:02 +0900 (Tue, 06 Jun 2017)

  New Revision: 59022

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59022

  Log:
    debug.c: parse locale and filesystem codepages

  Modified files:
    trunk/debug.c
    trunk/localeinit.c
Index: debug.c
===================================================================
--- debug.c	(revision 59021)
+++ debug.c	(revision 59022)
@@ -117,7 +117,7 @@ extern int ruby_w32_rtc_error; https://github.com/ruby/ruby/blob/trunk/debug.c#L117
 #endif
 #if defined _WIN32 || defined __CYGWIN__
 #include <windows.h>
-UINT ruby_w32_codepage;
+UINT ruby_w32_codepage[2];
 #endif
 
 static void
@@ -131,7 +131,7 @@ set_debug_option(const char *str, int le https://github.com/ruby/ruby/blob/trunk/debug.c#L131
 	}				    \
     } while (0)
 #define NAME_MATCH_VALUE(name) \
-    ((size_t)len > sizeof(name) && \
+    ((size_t)len >= sizeof(name) && \
      strncmp(str, (name), sizeof(name)-1) == 0 && \
      str[sizeof(name)-1] == '=' && \
      (str += sizeof(name), len -= sizeof(name), 1))
@@ -144,14 +144,25 @@ set_debug_option(const char *str, int le https://github.com/ruby/ruby/blob/trunk/debug.c#L144
 # endif
 #endif
 #if defined _WIN32 || defined __CYGWIN__
-    {
+    if (NAME_MATCH_VALUE("codepage")) {
+	int i;
 	int ov;
 	size_t retlen;
 	unsigned long n;
-	if (NAME_MATCH_VALUE("codepage") &&
-	    (n = ruby_scan_digits(str, len, 10, &retlen, &ov),
-	     (size_t)len == retlen && !ov)) {
-	    ruby_w32_codepage = (UINT)n;
+	for (i = 0; i < numberof(ruby_w32_codepage); ++i) {
+	    n = ruby_scan_digits(str, len, 10, &retlen, &ov);
+	    if (!ov && retlen) {
+		ruby_w32_codepage[i] = (UINT)n;
+	    }
+	    if ((size_t)len <= retlen) break;
+	    str += retlen;
+	    len -= retlen;
+	    if (*str != ':') break;
+	    ++str;
+	    --len;
+	}
+	if (len > 0) {
+	    fprintf(stderr, "ignored codepage option: `%.*s'\n", len, str);
 	}
 	return;
     }
Index: localeinit.c
===================================================================
--- localeinit.c	(revision 59021)
+++ localeinit.c	(revision 59022)
@@ -22,7 +22,7 @@ https://github.com/ruby/ruby/blob/trunk/localeinit.c#L22
 #define SIZEOF_CP_NAME ((sizeof(UINT) * 8 / 3) + 4)
 #define CP_FORMAT(buf, codepage) snprintf(buf, sizeof(buf), "CP%u", (codepage))
 
-extern UINT ruby_w32_codepage;
+extern UINT ruby_w32_codepage[2];
 #endif
 
 #ifndef NO_LOCALE_CHARMAP
@@ -45,7 +45,7 @@ locale_charmap(VALUE (*conv)(const char https://github.com/ruby/ruby/blob/trunk/localeinit.c#L45
     codeset = nl_langinfo_codeset();
 # endif
     if (!codeset) {
-	UINT codepage = ruby_w32_codepage;
+	UINT codepage = ruby_w32_codepage[0];
 	if (!codepage) codepage = GetConsoleCP();
 	if (!codepage) codepage = GetACP();
 	CP_FORMAT(cp, codepage);
@@ -122,7 +122,7 @@ Init_enc_set_filesystem_encoding(void) https://github.com/ruby/ruby/blob/trunk/localeinit.c#L122
     idx = ENCINDEX_US_ASCII;
 #elif defined _WIN32
     char cp[SIZEOF_CP_NAME];
-    const UINT codepage = ruby_w32_codepage ? ruby_w32_codepage :
+    const UINT codepage = ruby_w32_codepage[1] ? ruby_w32_codepage[1] :
 	AreFileApisANSI() ? GetACP() : GetOEMCP();
     CP_FORMAT(cp, codepage);
     idx = rb_enc_find_index(cp);

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

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