]> gcc.gnu.org Git - gcc.git/commitdiff
lex.c (real_yylex): Replace unused bytes from bad multibyte char.
authorDave Brolley <brolley@cygnus.com>
Mon, 7 Jun 1999 11:10:29 +0000 (11:10 +0000)
committerDave Brolley <brolley@gcc.gnu.org>
Mon, 7 Jun 1999 11:10:29 +0000 (07:10 -0400)
1999-06-07  Dave Brolley  <brolley@cygnus.com>
* lex.c (real_yylex): Replace unused bytes from bad multibyte char.
* input.c (putback_buffer): New structure type.
(putback): Replaces putback_char member.
(putback): Replaces putback_char static variable.
(feed_input): Use putback.
(end_input): Use putback.
(sub_getch): Use putback.
(put_back): Use putback.

From-SVN: r27392

gcc/cp/ChangeLog
gcc/cp/input.c
gcc/cp/lex.c

index a066e3b98a2a495fdae7b269a0211359ef7227a7..e89dfdff1a237a92031b43a771ef179559294228 100644 (file)
@@ -1,3 +1,14 @@
+1999-06-07  Dave Brolley  <brolley@cygnus.com>
+
+       * lex.c (real_yylex): Replace unused bytes from bad multibyte char.
+       * input.c (putback_buffer): New structure type.
+       (putback): Replaces putback_char member.
+       (putback): Replaces putback_char static variable.
+       (feed_input): Use putback.
+       (end_input): Use putback.
+       (sub_getch): Use putback.
+       (put_back): Use putback.
+
 1999-06-05  Mark Mitchell  <mark@codesourcery.com>
 
        * decl.c (grokdeclarator): Fix typo in last change.
index 9148c86562335fd5c14e2a7018f4e99bbab22603..b7fb9e2db3724a2ba2547e0129d7a65db091c4fd 100644 (file)
@@ -33,6 +33,12 @@ Boston, MA 02111-1307, USA.  */
 
 extern FILE *finput;
 
+struct putback_buffer {
+  char *buffer;
+  int   buffer_size;
+  int   index;
+};
+
 struct input_source {
   /* saved string */
   char *str;
@@ -45,7 +51,7 @@ struct input_source {
   char *filename;
   int lineno;
   struct pending_input *input;
-  int putback_char;
+  struct putback_buffer putback;
 };
 
 static struct input_source *input, *free_inputs;
@@ -98,7 +104,7 @@ free_input (inp)
   free_inputs = inp;
 }
 
-static int putback_char = -1;
+static struct putback_buffer putback = {NULL, 0, -1};
 
 /* Some of these external functions are declared inline in case this file
    is included in lex.c.  */
@@ -122,8 +128,10 @@ feed_input (str, len)
   inp->filename = input_filename;
   inp->lineno = lineno;
   inp->input = save_pending_input ();
-  inp->putback_char = putback_char;
-  putback_char = -1;
+  inp->putback = putback;
+  putback.buffer = NULL;
+  putback.buffer_size = 0;
+  putback.index = -1;
   input = inp;
 }
 
@@ -141,7 +149,7 @@ end_input ()
   lineno = inp->lineno;
   /* Get interface/implementation back in sync.  */
   extract_interface_info ();
-  putback_char = inp->putback_char;
+  putback = inp->putback;
   restore_pending_input (inp->input);
   free_input (inp);
 }
@@ -149,17 +157,17 @@ end_input ()
 static inline int
 sub_getch ()
 {
-  if (putback_char != -1)
+  if (putback.index != -1)
     {
-      int ch = putback_char;
-      putback_char = -1;
+      int ch = putback.buffer[putback.index];
+      --putback.index;
       return ch;
     }
   if (input)
     {
       if (input->offset >= input->length)
        {
-         my_friendly_assert (putback_char == -1, 223);
+         my_friendly_assert (putback.index == -1, 223);
          ++(input->offset);
          if (input->offset - input->length < 64)
            return EOF;
@@ -180,8 +188,13 @@ put_back (ch)
 {
   if (ch != EOF)
     {
-      my_friendly_assert (putback_char == -1, 224);
-      putback_char = ch;
+      if (putback.index == putback.buffer_size - 1)
+       {
+         putback.buffer_size += 16;
+         putback.buffer = xrealloc (putback.buffer, putback.buffer_size);
+       }
+      my_friendly_assert (putback.buffer != NULL, 224);
+      putback.buffer[++putback.index] = ch;
     }
 }
 
index 80f855ede3bc17d4e798b12be724a2255c8511ee..1ab5df3a3041bd60175caf765d8d1466a0d159dc 100644 (file)
@@ -4074,12 +4074,17 @@ real_yylex ()
                else
                  {
                    if (char_len == -1)
-                     warning ("Ignoring invalid multibyte character");
-                   if (wide_flag)
-                     c = wc;
+                     {
+                       warning ("Ignoring invalid multibyte character");
+                       /* Replace all but the first byte.  */
+                       for (--i; i > 1; --i)
+                         put_back (token_buffer[i]);
+                       wc = token_buffer[1];
+                     }
 #ifdef MAP_CHARACTER
-                   else
-                     c = MAP_CHARACTER (c);
+                     c = MAP_CHARACTER (wc);
+#else
+                     c = wc;
 #endif
                  }
 #else /* ! MULTIBYTE_CHARS */
@@ -4203,20 +4208,24 @@ real_yylex ()
                    c = getch ();
                  }
                if (char_len == -1)
-                 warning ("Ignoring invalid multibyte character");
-               else
                  {
-                   /* mbtowc sometimes needs an extra char before accepting */
-                   if (char_len <= i)
-                     put_back (c);
-                   if (! wide_flag)
-                     {
-                       p += (i + 1);
-                       c = getch ();
-                       continue;
-                     }
-                   c = wc;
+                   warning ("Ignoring invalid multibyte character");
+                   /* Replace all except the first byte.  */
+                   put_back (c);
+                   for (--i; i > 0; --i)
+                     put_back (p[i]);
+                   char_len = 1;
+                 }
+               /* mbtowc sometimes needs an extra char before accepting */
+               if (char_len <= i)
+                 put_back (c);
+               if (! wide_flag)
+                 {
+                   p += (i + 1);
+                   c = getch ();
+                   continue;
                  }
+               c = wc;
 #endif /* MULTIBYTE_CHARS */
              }
 
This page took 0.086381 seconds and 5 git commands to generate.