Refactor getting children name, value and type access
[deliverable/binutils-gdb.git] / binutils / rclex.l
index 47b479b20b6f941c0118840648808e4feaa8bfb2..92b1ec738526786bed9088739bed5e69bd682f10 100644 (file)
@@ -1,5 +1,6 @@
 %{ /* rclex.l -- lexer for Windows rc files parser  */
-/* Copyright 1997, 1998 Free Software Foundation, Inc.
+/* Copyright 1997, 1998, 1999, 2001, 2002, 2003, 2005
+   Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
    This file is part of GNU Binutils.
@@ -16,8 +17,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 
 /* This is a lex input file which generates a lexer used by the
    Windows rc file parser.  It basically just recognized a bunch of
 #include "bfd.h"
 #include "bucomm.h"
 #include "libiberty.h"
+#include "safe-ctype.h"
 #include "windres.h"
 #include "rcparse.h"
 
-#include <ctype.h>
 #include <assert.h>
 
+#define YY_NO_UNPUT
+
 /* Whether we are in rcdata mode, in which we returns the lengths of
    strings.  */
 
@@ -66,9 +69,9 @@ static struct alloc_string *strings;
 
 /* Local functions.  */
 
-static void cpp_line PARAMS ((const char *));
-static char *handle_quotes PARAMS ((const char *, unsigned long *));
-static char *get_string PARAMS ((int));
+static void cpp_line (const char *);
+static char *handle_quotes (const char *, unsigned long *);
+static char *get_string (int);
 
 %}
 
@@ -196,7 +199,7 @@ static char *get_string PARAMS ((int));
                          MAYBE_RETURN (NUMBER);
                        }
 
-("\""[^\"\n]*"\""[ \t]*)+ {
+("\""[^\"\n]*"\""[ \t\n]*)+ {
                          char *s;
                          unsigned long length;
 
@@ -236,7 +239,7 @@ static char *get_string PARAMS ((int));
 %%
 #ifndef yywrap
 /* This is needed for some versions of lex.  */
-int yywrap ()
+int yywrap (void)
 {
   return 1;
 }
@@ -245,25 +248,24 @@ int yywrap ()
 /* Handle a C preprocessor line.  */
 
 static void
-cpp_line (s)
-     const char *s;
+cpp_line (const char *s)
 {
   int line;
   char *send, *fn;
 
   ++s;
-  while (isspace ((unsigned char) *s))
+  while (ISSPACE (*s))
     ++s;
   
   line = strtol (s, &send, 0);
-  if (*send != '\0' && ! isspace ((unsigned char) *send))
+  if (*send != '\0' && ! ISSPACE (*send))
     return;
 
   /* Subtract 1 because we are about to count the newline.  */
   rc_lineno = line - 1;
 
   s = send;
-  while (isspace ((unsigned char) *s))
+  while (ISSPACE (*s))
     ++s;
 
   if (*s != '"')
@@ -284,11 +286,11 @@ cpp_line (s)
   if (!initial_fn)
     {
       initial_fn = xmalloc (strlen (fn) + 1);
-      strcpy(initial_fn, fn);
+      strcpy (initial_fn, fn);
     }
 
   /* Allow the initial file, regardless of name.  Suppress all other
-     files if they end in ".h" (this allows included "*.rc") */
+     files if they end in ".h" (this allows included "*.rc") */
   if (strcmp (initial_fn, fn) == 0
       || strcmp (fn + strlen (fn) - 2, ".h") != 0)
     suppress_cpp_data = 0;
@@ -301,13 +303,12 @@ cpp_line (s)
    merged separated by whitespace are merged, as in C.  */
 
 static char *
-handle_quotes (input, len)
-     const char *input;
-     unsigned long *len;
+handle_quotes (const char *input, unsigned long *len)
 {
   char *ret, *s;
   const char *t;
   int ch;
+  int num_xdigits;
 
   ret = get_string (strlen (input) + 1);
 
@@ -331,7 +332,7 @@ handle_quotes (input, len)
              break;
 
            case 'a':
-             *s++ = ESCAPE_A;
+             *s++ = ESCAPE_B; /* Strange, but true...  */
              ++t;
              break;
 
@@ -389,14 +390,18 @@ handle_quotes (input, len)
            case 'x':
              ++t;
              ch = 0;
-             while (1)
+             /* We only handle single byte chars here.  Make sure
+                we finish an escape sequence like "/xB0ABC" after
+                the first two digits.  */
+              num_xdigits = 2;
+             while (num_xdigits--)
                {
                  if (*t >= '0' && *t <= '9')
                    ch = (ch << 4) | (*t - '0');
                  else if (*t >= 'a' && *t <= 'f')
-                   ch = (ch << 4) | (*t - 'a');
+                   ch = (ch << 4) | (*t - 'a' + 10);
                  else if (*t >= 'A' && *t <= 'F')
-                   ch = (ch << 4) | (*t - 'A');
+                   ch = (ch << 4) | (*t - 'A' + 10);
                  else
                    break;
                  ++t;
@@ -423,9 +428,13 @@ handle_quotes (input, len)
       else
        {
          ++t;
-         assert (isspace ((unsigned char) *t));
-         while (isspace ((unsigned char) *t))
-           ++t;
+         assert (ISSPACE (*t));
+         while (ISSPACE (*t))
+           {
+             if ((*t) == '\n')
+               ++rc_lineno;
+             ++t;
+           }
          if (*t == '\0')
            break;
          assert (*t == '"');
@@ -443,8 +452,7 @@ handle_quotes (input, len)
 /* Allocate a string of a given length.  */
 
 static char *
-get_string (len)
-     int len;
+get_string (int len)
 {
   struct alloc_string *as;
 
@@ -452,7 +460,7 @@ get_string (len)
   as->s = xmalloc (len);
 
   as->next = strings;
-  strings = as->next;
+  strings = as;
 
   return as->s;
 }
@@ -461,7 +469,7 @@ get_string (len)
    when it no longer needs them.  */
 
 void
-rcparse_discard_strings ()
+rcparse_discard_strings (void)
 {
   struct alloc_string *as;
 
@@ -482,7 +490,7 @@ rcparse_discard_strings ()
 /* Enter rcdata mode.  */
 
 void
-rcparse_rcdata ()
+rcparse_rcdata (void)
 {
   rcdata_mode = 1;
 }
@@ -490,7 +498,7 @@ rcparse_rcdata ()
 /* Go back to normal mode from rcdata mode.  */
 
 void
-rcparse_normal ()
+rcparse_normal (void)
 {
   rcdata_mode = 0;
 }
This page took 0.030993 seconds and 4 git commands to generate.