This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


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

cpp:s handling of \-CR-LF continuation lines


I have a set of source files that are shared between w*ndows and unix
environments. The files are mostly edited under w*ndows.

Some of the files contains macro definitions like

  #define FOO(x) \
  foo(x)

that are split over several lines, for readability. The problem is that
if the file was edited under W*ndows or DOS, the file typically
contains the character sequence \ CR LF. But gcc only recognizes the
\-construction if the backslash is followed *immediately* by a
linefeed character.

Symptoms are "stray \ in program" errors followed by other parse
errors.

I'm running gcc-2.95.2, on linux (redhat-6.0) machine.

I can think of several approaches that could help to solve the
problem.

1. Make sure that gcc treats the sequence \ CR LF as an backslash
   followed by end of line.

2. Treat any sequence \ (whitespace other than NL) LF as \ followed by
   end of line.

3. Provide some option to pass all input files through an arbitrary
   filter before (or instead of) reading them into cpp.


An attempt do (1) is the following patch:

--- cppfiles.c-original Mon Jan 10 19:05:09 2000
+++ cppfiles.c  Tue Jan 11 17:15:34 2000
@@ -934,8 +934,9 @@
                  *--ibase = '\\';
                  goto read_next;
                }
-             else if (*ip == '\n')
+             else if (ip[0] == '\n' || (ip[0] == '\r' && ip[1] ==
'\n') )
                {
+                 if (*ip == '\r') ip++;
                  ip++;
                  if (*ip == '\r') ip++;
                  if (*ip == '\n' || *ip == '\t' || *ip == ' ')

But when trying to test this, I discovered that appearantly this file
is part of the unused cpplib, and the real implementation is in
cccp.c. And unfortunately, the requirement that \ is followed
*immediately* by a newline is in a *lot* of places in that file.
(M-x occur RET = '\\\\' RET in emacs should find most of them).

Suggestions on make trickery to solve the problem is also appreciated.
Without support from gcc, I don't see how to write make rules to
filter files on the fly; the problem is how to get files filtered when
they are included.

Regards,
/Niels

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