[PATCH] Look for matching closing quote in gas/app.c
Alan Modra
amodra@bigpond.net.au
Wed Sep 28 14:16:00 GMT 2005
On Wed, Sep 14, 2005 at 10:53:13PM +0200, Arnold Metselaar wrote:
> While working on gas-Z80 I also noticed that do_scrub_chars() in gas/app.c
> does not distinguish between a closing quote and another quote. That is
> .string "this looks like a terminated string to do_scrub_chars().'
> .string "and it thinks that this one isn't."
I think you missed a place where quotechar needs to be set, and some
where it should be used. How does the following look to you?
* app.c (do_scrub_chars): Match open and close quote of strings.
Remove redundant EOF test in case 7.
Index: gas/app.c
===================================================================
RCS file: /cvs/src/src/gas/app.c,v
retrieving revision 1.31
diff -u -p -r1.31 app.c
--- gas/app.c 28 Sep 2005 12:31:44 -0000 1.31
+++ gas/app.c 28 Sep 2005 13:19:17 -0000
@@ -345,6 +345,8 @@ do_scrub_chars (int (*get) (char *, int)
char *fromend;
int fromlen;
register int ch, ch2 = 0;
+ /* Character that started the string we're working on. */
+ static char quotechar;
/*State 0: beginning of normal line
1: After first whitespace on line (flush more white)
@@ -536,11 +538,8 @@ do_scrub_chars (int (*get) (char *, int)
for (s = from; s < fromend; s++)
{
ch = *s;
- /* This condition must be changed if the type of any
- other character can be LEX_IS_STRINGQUOTE. */
if (ch == '\\'
- || ch == '"'
- || ch == '\''
+ || ch == quotechar
|| ch == '\n')
break;
}
@@ -558,12 +557,12 @@ do_scrub_chars (int (*get) (char *, int)
ch = GET ();
if (ch == EOF)
{
- as_warn (_("end of file in string; inserted '\"'"));
+ as_warn (_("end of file in string; '%c' inserted"), quotechar);
state = old_state;
UNGET ('\n');
- PUT ('"');
+ PUT (quotechar);
}
- else if (lex[ch] == LEX_IS_STRINGQUOTE)
+ else if (ch == quotechar)
{
state = old_state;
PUT (ch);
@@ -603,8 +602,8 @@ do_scrub_chars (int (*get) (char *, int)
continue;
case EOF:
- as_warn (_("end of file in string; '\"' inserted"));
- PUT ('"');
+ as_warn (_("end of file in string; '%c' inserted"), quotechar);
+ PUT (quotechar);
continue;
case '"':
@@ -638,10 +637,9 @@ do_scrub_chars (int (*get) (char *, int)
case 7:
ch = GET ();
+ quotechar = ch;
state = 5;
old_state = 8;
- if (ch == EOF)
- goto fromeof;
PUT (ch);
continue;
@@ -975,6 +973,7 @@ do_scrub_chars (int (*get) (char *, int)
break;
case LEX_IS_STRINGQUOTE:
+ quotechar = ch;
if (state == 10)
{
/* Preserve the whitespace in foo "bar". */
--
Alan Modra
IBM OzLabs - Linux Technology Centre
More information about the Binutils
mailing list