daily update
[deliverable/binutils-gdb.git] / binutils / rclex.c
index edcf2cece6b30cbdca2348accc23293103b22fe5..5922106a0e453e859a30e0b35f3a597dc60eef6e 100644 (file)
@@ -9,7 +9,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -22,6 +22,7 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
    02110-1301, USA.  */
 
+
 /* This is a lexer used by the Windows rc file parser.  It basically
    just recognized a bunch of keywords.  */
 
@@ -142,11 +143,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;
This page took 0.024215 seconds and 4 git commands to generate.