Commit cd28936c by Dave Brolley Committed by Dave Brolley

lex.c (real_yylex): Replace unused bytes from bad multibyte char.

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
parent e7553be5
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> 1999-06-05 Mark Mitchell <mark@codesourcery.com>
* decl.c (grokdeclarator): Fix typo in last change. * decl.c (grokdeclarator): Fix typo in last change.
......
...@@ -33,6 +33,12 @@ Boston, MA 02111-1307, USA. */ ...@@ -33,6 +33,12 @@ Boston, MA 02111-1307, USA. */
extern FILE *finput; extern FILE *finput;
struct putback_buffer {
char *buffer;
int buffer_size;
int index;
};
struct input_source { struct input_source {
/* saved string */ /* saved string */
char *str; char *str;
...@@ -45,7 +51,7 @@ struct input_source { ...@@ -45,7 +51,7 @@ struct input_source {
char *filename; char *filename;
int lineno; int lineno;
struct pending_input *input; struct pending_input *input;
int putback_char; struct putback_buffer putback;
}; };
static struct input_source *input, *free_inputs; static struct input_source *input, *free_inputs;
...@@ -98,7 +104,7 @@ free_input (inp) ...@@ -98,7 +104,7 @@ free_input (inp)
free_inputs = 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 /* Some of these external functions are declared inline in case this file
is included in lex.c. */ is included in lex.c. */
...@@ -122,8 +128,10 @@ feed_input (str, len) ...@@ -122,8 +128,10 @@ feed_input (str, len)
inp->filename = input_filename; inp->filename = input_filename;
inp->lineno = lineno; inp->lineno = lineno;
inp->input = save_pending_input (); inp->input = save_pending_input ();
inp->putback_char = putback_char; inp->putback = putback;
putback_char = -1; putback.buffer = NULL;
putback.buffer_size = 0;
putback.index = -1;
input = inp; input = inp;
} }
...@@ -141,7 +149,7 @@ end_input () ...@@ -141,7 +149,7 @@ end_input ()
lineno = inp->lineno; lineno = inp->lineno;
/* Get interface/implementation back in sync. */ /* Get interface/implementation back in sync. */
extract_interface_info (); extract_interface_info ();
putback_char = inp->putback_char; putback = inp->putback;
restore_pending_input (inp->input); restore_pending_input (inp->input);
free_input (inp); free_input (inp);
} }
...@@ -149,17 +157,17 @@ end_input () ...@@ -149,17 +157,17 @@ end_input ()
static inline int static inline int
sub_getch () sub_getch ()
{ {
if (putback_char != -1) if (putback.index != -1)
{ {
int ch = putback_char; int ch = putback.buffer[putback.index];
putback_char = -1; --putback.index;
return ch; return ch;
} }
if (input) if (input)
{ {
if (input->offset >= input->length) if (input->offset >= input->length)
{ {
my_friendly_assert (putback_char == -1, 223); my_friendly_assert (putback.index == -1, 223);
++(input->offset); ++(input->offset);
if (input->offset - input->length < 64) if (input->offset - input->length < 64)
return EOF; return EOF;
...@@ -180,8 +188,13 @@ put_back (ch) ...@@ -180,8 +188,13 @@ put_back (ch)
{ {
if (ch != EOF) if (ch != EOF)
{ {
my_friendly_assert (putback_char == -1, 224); if (putback.index == putback.buffer_size - 1)
putback_char = ch; {
putback.buffer_size += 16;
putback.buffer = xrealloc (putback.buffer, putback.buffer_size);
}
my_friendly_assert (putback.buffer != NULL, 224);
putback.buffer[++putback.index] = ch;
} }
} }
......
...@@ -4074,12 +4074,17 @@ real_yylex () ...@@ -4074,12 +4074,17 @@ real_yylex ()
else else
{ {
if (char_len == -1) if (char_len == -1)
warning ("Ignoring invalid multibyte character"); {
if (wide_flag) warning ("Ignoring invalid multibyte character");
c = wc; /* Replace all but the first byte. */
for (--i; i > 1; --i)
put_back (token_buffer[i]);
wc = token_buffer[1];
}
#ifdef MAP_CHARACTER #ifdef MAP_CHARACTER
else c = MAP_CHARACTER (wc);
c = MAP_CHARACTER (c); #else
c = wc;
#endif #endif
} }
#else /* ! MULTIBYTE_CHARS */ #else /* ! MULTIBYTE_CHARS */
...@@ -4203,20 +4208,24 @@ real_yylex () ...@@ -4203,20 +4208,24 @@ real_yylex ()
c = getch (); c = getch ();
} }
if (char_len == -1) if (char_len == -1)
warning ("Ignoring invalid multibyte character");
else
{ {
/* mbtowc sometimes needs an extra char before accepting */ warning ("Ignoring invalid multibyte character");
if (char_len <= i) /* Replace all except the first byte. */
put_back (c); put_back (c);
if (! wide_flag) for (--i; i > 0; --i)
{ put_back (p[i]);
p += (i + 1); char_len = 1;
c = getch (); }
continue; /* mbtowc sometimes needs an extra char before accepting */
} if (char_len <= i)
c = wc; put_back (c);
if (! wide_flag)
{
p += (i + 1);
c = getch ();
continue;
} }
c = wc;
#endif /* MULTIBYTE_CHARS */ #endif /* MULTIBYTE_CHARS */
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment