summaryrefslogtreecommitdiff
path: root/binutils/rclex.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2007-06-18 15:30:33 +0000
committerNick Clifton <nickc@redhat.com>2007-06-18 15:30:33 +0000
commit0ae923e8d923621c9553c33ef3d46902782871f2 (patch)
treef29caac8479b48eb063ba50c89cad101969ab451 /binutils/rclex.c
parentd2b6890afbb6c7edb0680aeb61c3db221c19bac2 (diff)
downloadbinutils-redhat-0ae923e8d923621c9553c33ef3d46902782871f2.tar.gz
* rclex.c: (cpp_line): Add code_page pragma support.
* windres.c: (usage, long_options, main): Add new option --codepage or -c. * winduni.c: (wind_default_codepage, wind_current_codepage): New. (unicode_from_ascii, ascii_from_unicode): Use wind_current_codepage as codepage parameter. (unicode_print): Print 4 characters for hexadecimal values in unicode strings. * winduni.h: (wind_default_codepage, wind_current_codepage): Export. * doc/binutils.texi: Document new option. * NEWS: Mention new feature.
Diffstat (limited to 'binutils/rclex.c')
-rw-r--r--binutils/rclex.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/binutils/rclex.c b/binutils/rclex.c
index edcf2cece6..ef0961b61c 100644
--- a/binutils/rclex.c
+++ b/binutils/rclex.c
@@ -142,11 +142,64 @@ 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 | <nr>). */
+ 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)
+ /* FIXME: We ought to issue a warning message about an unrecognised pragma. */
+ return;
+ s += mlen;
+ while (ISSPACE (*s))
+ ++s;
+ if (*s != '(')
+ /* FIXME: We ought to issue an error message about a malformed pragma. */
+ return;
+ ++s;
+ while (ISSPACE (*s))
+ ++s;
+ if (*s == 0 || (end = strchr (s, ')')) == NULL)
+ /* FIXME: We ought to issue an error message about a malformed pragma. */
+ return;
+ len = (size_t) (end - s);
+ fn = 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, NULL, 16);
+ else
+ ncp = (rc_uint_type) strtol (fn, NULL, 10);
+ if (ncp == CP_UTF16 || ! unicode_is_valid_codepage (ncp))
+ fatal (_("invalid value specified for pragma code_page.\n"));
+ wind_current_codepage = ncp;
+ }
+ free (fn);
+ return;
+ }
+
line = strtol (s, &send, 0);
if (*send != '\0' && ! ISSPACE (*send))
return;