This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Look for matching closing quote in gas/app.c


Hello,

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."
The function stringer() in read.c only recognises double quotes (") as 
string delimiter
The patch below causes do_scrub_chars() to only recognise a matching 
closing quote.

Arnold Metselaar

*** src/gas/app.c       2005-05-05 11:12:43.000000000 +0200
--- src/gas/app.c.new   2005-09-14 18:26:01.726641408 +0200
***************
*** 345,350 ****
--- 345,354 ----
    char *fromend;
    int fromlen;
    register int ch, ch2 = 0;
+   /* Character that started the string we're working on, this does
+      not get saved, so we can not process different strings at the
+      same time, I don't think we need to -- Arnold */
+   static char quotechar;

    /*State 0: beginning of normal line
          1: After first whitespace on line (flush more white)
***************
*** 536,546 ****
            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 == '\n')
                  break;
              }
--- 540,548 ----
            for (s = from; s < fromend; s++)
              {
                ch = *s;
                if (ch == '\\'
!                   /* only accept a matching closing quote */
!                   || ch == quotechar
                    || ch == '\n')
                  break;
              }
***************
*** 558,569 ****
          ch = GET ();
          if (ch == EOF)
            {
!             as_warn (_("end of file in string; inserted '\"'"));
              state = old_state;
              UNGET ('\n');
!             PUT ('"');
            }
!         else if (lex[ch] == LEX_IS_STRINGQUOTE)
            {
              state = old_state;
              PUT (ch);
--- 560,571 ----
          ch = GET ();
          if (ch == EOF)
            {
!             as_warn (_("end of file in string; inserted '%c'"), quotechar);
              state = old_state;
              UNGET ('\n');
!             PUT (quotechar);
            }
!         else if (ch == quotechar)
            {
              state = old_state;
              PUT (ch);
***************
*** 975,980 ****
--- 977,983 ----
          break;

        case LEX_IS_STRINGQUOTE:
+         quotechar=ch;
          if (state == 10)
            {
              /* Preserve the whitespace in foo "bar".  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]