[PATCH] Fix PR preprocessor/6489 (take 2)
Jakub Jelinek
jakub@redhat.com
Tue Apr 30 15:18:00 GMT 2002
On Tue, Apr 30, 2002 at 10:58:53AM -0700, Zack Weinberg wrote:
> On Tue, Apr 30, 2002 at 04:25:10PM +0200, Jakub Jelinek wrote:
> > Hi!
> >
> > The following patch fixes PR preprocessor/6489 (a regression from 2.95.x).
> > #include <filename>
> > would result in
> > #include expects "fname" or <fname>
> > error. I don't think it is necessary to add much more for '\r', on all stuff
> > I've tried but this one egcs 1.1.2 and gcc 2.95.4 handled '\r' characters
> > equally bad as tradcpp.
> > Ok to commit?
>
> For mainline, I would prefer patches to make tradcpp universally
> accept \r\n, \r, \n\r as line endings; it's silly that it doesn't
> match the behavior of normal cpp.
Agreed, though the code is really dirty and uses hardcoded '\n' in lots of
places.
> For the branch, your patch should at least cope with bare \r as line
> ending, as well as \r\n and \n.
The following copes with \r, \n, \r\n and \n\r for directives, is that
enough? It will not handle cases like
id\
\
\
\
\
entifier
etc., the patch would be way bigger for that (and it is not regression).
2002-05-01 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/6489
* tradcpp.c (handle_directive): Handle CR LF, CR and LF CR
as newline too.
(do_include): Skip any whitespace at end, not just non-vertical.
--- gcc/tradcpp.c.jj Mon Feb 4 11:41:44 2002
+++ gcc/tradcpp.c Wed May 1 00:16:12 2002
@@ -2038,12 +2038,17 @@ handle_directive (ip, op)
break;
case '\n':
- --bp; /* Point to the newline */
+ case '\r':
+ cp = bp - 1;
+ if (bp == limit || bp[-1] + *bp != '\n' + '\r')
+ --bp; /* Point to the newline */
+ *bp = '\n';
ip->bufp = bp;
goto endloop1;
}
}
ip->bufp = bp;
+ cp = bp;
endloop1:
resume_p = ip->bufp;
@@ -2067,6 +2072,7 @@ handle_directive (ip, op)
*cp++ = c;
switch (c) {
+ case '\r':
case '\n':
break;
@@ -2129,8 +2135,6 @@ handle_directive (ip, op)
*cp = 0;
}
- else
- cp = bp;
ip->bufp = resume_p;
@@ -2325,7 +2329,7 @@ get_filename:
SKIP_WHITE_SPACE (fbeg);
/* Discard trailing whitespace so we can easily see
if we have parsed all the significant chars we were given. */
- while (limit != fbeg && is_nvspace (limit[-1])) limit--;
+ while (limit != fbeg && is_space (limit[-1])) limit--;
switch (*fbeg++) {
case '\"':
Jakub
More information about the Gcc-patches
mailing list