/[bison]/bison/src/lex.c
ViewVC logotype

Diff of /bison/src/lex.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.47 by marc, Wed Nov 28 22:28:01 2001 UTC revision 1.48 by akim, Fri Dec 14 15:39:05 2001 UTC
# Line 140  xgetc (FILE *f) Line 140  xgetc (FILE *f)
140  }  }
141    
142    
143  /*------------------------------------------------------------------.  /*-----------------------------------------------------------------.
144  | Read one literal character from finput.  Process \ escapes.       |  | Read one literal character from FINPUT.  Process \-escapes.      |
145  | Append the normalized string version of the char to OUT.  Assign  |  | Append the char to OUT and assign it *PCODE. Return 1 unless the |
146  | the character code to *PCODE. Return 1 unless the character is an |  | character is an unescaped `term' or \n report error for \n.      |
147  | unescaped `term' or \n report error for \n.                       |  `-----------------------------------------------------------------*/
 `------------------------------------------------------------------*/  
   
 /* FIXME: We could directly work in the obstack, but that would make  
    it more difficult to move to quotearg some day.  So for the time  
    being, I prefer have literalchar behave like quotearg, and change  
    my mind later if I was wrong.  */  
148    
149  int  int
150  literalchar (struct obstack *out, int *pcode, char term)  literalchar (struct obstack *out, int *pcode, char term)
151  {  {
152    int c;    int c;
   char buf[4096];  
   char *cp;  
153    int code;    int code;
154    int wasquote = 0;    int wasquote = 0;
155    
# Line 249  literalchar (struct obstack *out, int *p Line 241  literalchar (struct obstack *out, int *p
241          }          }
242      }                           /* has \ */      }                           /* has \ */
243    
   /* now fill BUF with the canonical name for this character as a  
      literal token.  Do not use what the user typed, so that `\012'  
      and `\n' can be interchangeable.  */  
   
   cp = buf;  
   if (code == term && wasquote)  
     *cp++ = code;  
   else if (code == '\\')  
     {  
       *cp++ = '\\';  
       *cp++ = '\\';  
     }  
   else if (code == '\'')  
     {  
       *cp++ = '\\';  
       *cp++ = '\'';  
     }  
   else if (code == '\"')  
     {  
       *cp++ = '\\';  
       *cp++ = '\"';  
     }  
   else if (code >= 040 && code < 0177)  
     *cp++ = code;  
   else if (code == '\t')  
     {  
       *cp++ = '\\';  
       *cp++ = 't';  
     }  
   else if (code == '\n')  
     {  
       *cp++ = '\\';  
       *cp++ = 'n';  
     }  
   else if (code == '\r')  
     {  
       *cp++ = '\\';  
       *cp++ = 'r';  
     }  
   else if (code == '\v')  
     {  
       *cp++ = '\\';  
       *cp++ = 'v';  
     }  
   else if (code == '\b')  
     {  
       *cp++ = '\\';  
       *cp++ = 'b';  
     }  
   else if (code == '\f')  
     {  
       *cp++ = '\\';  
       *cp++ = 'f';  
     }  
   else  
     {  
       *cp++ = '\\';  
       *cp++ = code / 0100 + '0';  
       *cp++ = ((code / 010) & 07) + '0';  
       *cp++ = (code & 07) + '0';  
     }  
   *cp = '\0';  
   
244    if (out)    if (out)
245      obstack_sgrow (out, buf);      obstack_1grow (out, code);
246    *pcode = code;    *pcode = code;
247    return !wasquote;    return !wasquote;
248  }  }

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.48

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26