diff -uNr binutils-2.15.91-20040703/binutils/rclex.l binutils.patched/binutils/rclex.l --- binutils-2.15.91-20040703/binutils/rclex.l 2003-09-14 21:20:16.000000000 +0900 +++ binutils.patched/binutils/rclex.l 2004-07-03 22:49:33.427453080 +0900 @@ -31,6 +31,9 @@ #include "rcparse.h" #include + +/* mbchar fix */ +#include /* Whether we are in rcdata mode, in which we returns the lengths of strings. */ @@ -306,10 +309,52 @@ const char *t; int ch; - ret = get_string (strlen (input) + 1); +/* mbchar fix */ + char *code; + char *str, *outtmp; + const char *intmp; + size_t sstr, sinput; + + code = getenv ("CLANG"); + intmp = input; + sinput = strlen (input) + 1; + sstr = sinput * 2; + outtmp = str = (char *) alloca (sstr); + if (code == NULL || outtmp == NULL) + t = input; + else + if (! strcmp (code, "C-SJIS")) + { + iconv_t cd = iconv_open ("EUC-JP","SJIS"); + if (cd != (iconv_t) -1) + { + iconv (cd, &intmp, &sinput, &outtmp, &sstr); + iconv_close (cd); + t = (const char *) str; + } + else + t = input; + } + else + if (! strcmp (code, "C-JIS")) + { + iconv_t cd = iconv_open ("EUC-JP","ISO-2022-JP"); + if (cd != (iconv_t) -1) + { + iconv (cd, &intmp, &sinput, &outtmp, &sstr); + iconv_close (cd); + t = (const char *) str; + } + else + t = input; + } + else + t = input; + + ret = get_string ((strlen (input) + 1) * 2); s = ret; - t = input; + if (*t == '"') ++t; while (*t != '\0') diff -uNr binutils-2.15.91-20040703/binutils/winduni.c binutils.patched/binutils/winduni.c --- binutils-2.15.91-20040703/binutils/winduni.c 2003-09-14 21:20:17.000000000 +0900 +++ binutils.patched/binutils/winduni.c 2004-07-03 23:36:25.330978768 +0900 @@ -31,6 +31,9 @@ #include "bucomm.h" #include "winduni.h" #include "safe-ctype.h" + +/* mbchar fix */ +#include #ifdef _WIN32 #include @@ -42,16 +45,57 @@ void unicode_from_ascii (int *length, unichar **unicode, const char *ascii) { - int len; - const char *s; +/* mbchar fix */ + size_t len; + const unsigned char *s; unsigned short *w; - len = strlen (ascii); + char *code; - if (length != NULL) - *length = len; + len = strlen (ascii) + 1; + + code = getenv ("CLANG"); + if (code == NULL) + ; + else + if (! strcmp (code, "C-SJIS") || + ! strcmp (code, "C-JIS") || + ! strcmp (code, "C-EUCJP")) + { + iconv_t cd; + char *str, *tmp; + const char *src; + size_t ssrc, sstr, stmp; + + src = ascii; + ssrc = len; + sstr = stmp = len * sizeof (unichar); + str = tmp = alloca (stmp); + + cd = iconv_open ("UCS-2","EUC-JP"); + if (cd != (iconv_t) -1 && str != NULL) + { + int char_len; + + iconv (cd, &src, &ssrc, &tmp, &stmp); + iconv_close (cd); - *unicode = ((unichar *) res_alloc ((len + 1) * sizeof (unichar))); + char_len = (sstr - stmp) / sizeof (unichar) - 1; + *unicode = ((unichar *) res_alloc (sstr - stmp)); + + if (length != NULL) + *length = char_len; + + memcpy(*unicode, str, char_len*sizeof(unichar)); + *(*unicode + char_len) = 0; + return; + } + } + + *unicode = ((unichar *) res_alloc (len * sizeof (unichar))); + + if (length != NULL) + *length = len - 1; #ifdef _WIN32 /* FIXME: On Windows, we should be using MultiByteToWideChar to set