Index: src/src/binutils/rclex.c =================================================================== --- src.orig/src/binutils/rclex.c +++ src/src/binutils/rclex.c @@ -142,10 +142,58 @@ cpp_line (void) const char *s = rclex_tok; int line; char *send, *fn; + size_t len, mlen; ++s; while (ISSPACE (*s)) ++s; + /* Check for #pragma code_page ( DEFAULT | ). */ + len = strlen (s); + mlen = strlen ("pragma"); + if (len > mlen && memcmp (s, "pragma", mlen) == 0 && ISSPACE (s[mlen])) + { + const char *end; + + s += mlen + 1; + while (ISSPACE (*s)) + ++s; + len = strlen (s); + mlen = strlen ("code_page"); + if (len <= mlen || memcmp (s, "code_page", mlen) != 0) + return; + s += mlen; + while (ISSPACE (*s)) + ++s; + if (*s != '(') + return; + ++s; + while (ISSPACE (*s)) + ++s; + if (*s == 0 || (end = strchr (s, ')')) == NULL) + return; + len = (size_t) (end - s); + fn = (char *) xmalloc (len + 1); + if (len) + memcpy (fn, s, len); + fn[len] = 0; + while (len > 0 && (fn[len - 1] > 0 && fn[len - 1] <= 0x20)) + fn[--len] = 0; + if (!len || (len == strlen ("DEFAULT") && strcasecmp (fn, "DEFAULT") == 0)) + wind_current_codepage = wind_default_codepage; + else if (len > 0) + { + rc_uint_type ncp; + if (fn[0] == '0' && (fn[1] == 'x' || fn[1] == 'X')) + ncp = (rc_uint_type) strtol (fn + 2, (char **) NULL, 16); + else + ncp = (rc_uint_type) strtol (fn, (char **) NULL, 10); + if (ncp == CP_UTF16 || ! unicode_is_valid_codepage (ncp)) + fatal (_("invalid value by pragma code_page specified.\n")); + wind_current_codepage = ncp; + } + free (fn); + return; + } line = strtol (s, &send, 0); if (*send != '\0' && ! ISSPACE (*send)) Index: src/src/binutils/windres.c =================================================================== --- src.orig/src/binutils/windres.c +++ src/src/binutils/windres.c @@ -663,6 +663,7 @@ usage (FILE *stream, int status) fprintf (stream, _("Usage: %s [option(s)] [input-file] [output-file]\n"), program_name); fprintf (stream, _(" The options are:\n\ + -c --codepage= Specify default codepage\n\ -i --input= Name input file\n\ -o --output= Name output file\n\ -J --input-format= Specify input format\n\ @@ -739,6 +740,7 @@ quot (const char *string) static const struct option long_options[] = { + {"codepage", required_argument, 0, 'c'}, {"input", required_argument, 0, 'i'}, {"output", required_argument, 0, 'o'}, {"input-format", required_argument, 0, 'J'}, @@ -809,11 +811,23 @@ main (int argc, char **argv) language = 0x409; /* LANG_ENGLISH, SUBLANG_ENGLISH_US. */ use_temp_file = 0; - while ((c = getopt_long (argc, argv, "f:i:l:o:I:J:O:F:D:U:rhHvV", long_options, + while ((c = getopt_long (argc, argv, "c:f:i:l:o:I:J:O:F:D:U:rhHvV", long_options, (int *) 0)) != EOF) { switch (c) { + case 'c': + { + rc_uint_type ncp; + if (optarg[0] == '0' && (optarg[1] == 'x' || optarg[1] == 'X')) + ncp = (rc_uint_type) strtol (optarg + 2, (char **) NULL, 16); + else + ncp = (rc_uint_type) strtol (optarg, (char **) NULL, 10); + if (ncp == CP_UTF16 || ! unicode_is_valid_codepage (ncp)) + fatal (_("invalid codepage specified.\n")); + wind_default_codepage = wind_current_codepage = ncp; + } + break; case 'i': input_filename = optarg; break; Index: src/src/binutils/winduni.c =================================================================== --- src.orig/src/binutils/winduni.c +++ src/src/binutils/winduni.c @@ -175,13 +175,21 @@ static const wind_language_t languages[] #endif +/* Specifies the default codepage to be used for unicode + transformations. By default this is CP_ACP. */ +rc_uint_type wind_default_codepage = CP_ACP; + +/* Specifies the currently used codepage for unicode + transformations. By default this is CP_ACP. */ +rc_uint_type wind_current_codepage = CP_ACP; + /* Convert an ASCII string to a unicode string. We just copy it, expanding chars to shorts, rather than doing something intelligent. */ void unicode_from_ascii (rc_uint_type *length, unichar **unicode, const char *ascii) { - unicode_from_codepage (length, unicode, ascii, 0 /*CP_ACP*/); + unicode_from_codepage (length, unicode, ascii, wind_current_codepage); } /* Convert an unicode string to an ASCII string. We just copy it, @@ -191,7 +199,7 @@ unicode_from_ascii (rc_uint_type *length void ascii_from_unicode (rc_uint_type *length, const unichar *unicode, char **ascii) { - codepage_from_unicode (length, unicode, ascii, 0/*CP_ACP*/); + codepage_from_unicode (length, unicode, ascii, wind_current_codepage); } /* Print the unicode string UNICODE to the file E. LENGTH is the @@ -267,7 +275,7 @@ unicode_print (FILE *e, const unichar *u else if ((ch & 0xff) == ch) fprintf (e, "\\%03o", (unsigned int) ch); else - fprintf (e, "\\x%x", (unsigned int) ch); + fprintf (e, "\\x%04x", (unsigned int) ch); } } Index: src/src/binutils/winduni.h =================================================================== --- src.orig/src/binutils/winduni.h +++ src/src/binutils/winduni.h @@ -96,6 +96,14 @@ extern void unicode_print_quoted (FILE * #define CP_OEM 1 /* Default OEM code page. */ #endif +/* Specifies the default codepage to be used for unicode + transformations. By default this is CP_ACP. */ +extern rc_uint_type wind_default_codepage; + +/* Specifies the currently used codepage for unicode + transformations. By default this is CP_ACP. */ +extern rc_uint_type wind_current_codepage; + typedef struct wind_language_t { unsigned id; Index: src/src/binutils/doc/binutils.texi =================================================================== --- src.orig/src/binutils/doc/binutils.texi +++ src/src/binutils/doc/binutils.texi @@ -3017,6 +3017,13 @@ Specify the default language to use when @var{val} should be a hexadecimal language code. The low eight bits are the language, and the high eight bits are the sublanguage. +@item -c @var{val} +@item --codepage @var{val} +Specify the default codepage to use when reading an @code{rc} file. +@var{val} should be a hexadecimal prefixed by @samp{0x} or decimal +codepage code. The valid range is from zero up to 0xffff, but the +validity of the codepage is host and configuration dependent. + @item --use-temp-file Use a temporary file to instead of using popen to read the output of the preprocessor. Use this option if the popen implementation is buggy =