public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Bruno Haible <haible@ilog.fr>
To: egcs@cygnus.com
Subject: Re: CRLF translations by CPP?
Date: Tue, 27 Jan 1998 04:02:00 -0000	[thread overview]
Message-ID: <199801271202.NAA07525@halles.ilog.fr> (raw)
In-Reply-To: <34CC20B9.2DF560E0@SLAC.Stanford.EDU>

> Is there a way to enable egcs to properly parse files with lines ending
> in CarriageReturn-LineFeed?

This issue was discussed between Paul Eggert, Richard Stallman and the gcc2
list in May 1997. The outcome of the discussion was:

1) The issue of CR LF and the issue of whitespace after backslash should
   be treated separately.
2) CR LF should be treated like LF (newline) on all platforms.
3) Inside macro definitions, whitespace between a backslash and a newline
   character deserves a warning, but this whitespace should not be ignored
   (because it is part of the source file).

Here is a patch which implements this. I think we can put this in.

                      Bruno


Tue Jan 27 02:43:01 1998  Bruno Haible  <bruno@linuix.mathematik.uni-karlsruhe.de>

        * cccp.c (crlf_pcp): New function.
          (main, finclude): Call it.
        * cccp.c (handle_directive): Emit warning for trailing whitespace
          after backslash.

*** egcs-980122/gcc/cccp.c.bak	Sat Jan 24 12:52:16 1998
--- egcs-980122/gcc/cccp.c	Tue Jan 27 02:38:32 1998
*************** static void path_include PROTO((char *))
*** 983,988 ****
--- 983,989 ----
  
  static U_CHAR *index0 PROTO((U_CHAR *, int, size_t));
  
+ static void crlf_pcp PROTO((FILE_BUF *));
  static void trigraph_pcp PROTO((FILE_BUF *));
  
  static void newline_fix PROTO((U_CHAR *));
*************** main (argc, argv)
*** 2129,2134 ****
--- 2130,2139 ----
    }
    fp->buf[fp->length] = '\0';
  
+   /* Convert DOS/VAX CR/LF sequences to NL, even on Unix.  */
+ 
+   crlf_pcp (fp);
+ 
    /* Unless inhibited, convert trigraphs in the input.  */
  
    if (!no_trigraphs)
*************** index0 (s, c, n)
*** 2269,2274 ****
--- 2274,2314 ----
    }
  }
  \f
+ /* Pre-C-Preprocessor to translate CR/LF sequences in BUF into NLs
+    before main CCCP processing.  */
+ 
+ static void
+ crlf_pcp (buf)
+      FILE_BUF *buf;
+ {
+   register /*const*/ U_CHAR *fptr, *sptr, *lptr;
+   register U_CHAR *bptr;
+   int len;
+ 
+   fptr = sptr = bptr = buf->buf;
+   lptr = fptr + buf->length;
+   while ((sptr = index0 (sptr, '\r', (size_t) (lptr - sptr))) != NULL) {
+     if (*++sptr != '\n')
+       continue;
+ 
+     len = sptr - fptr - 1;
+ 
+     /* BSD doc says bcopy () works right for overlapping strings.  In ANSI
+        C, this will be memmove ().  */
+     if (bptr != fptr && len > 0)
+       bcopy ((char *) fptr, (char *) bptr, len);
+ 
+     bptr += len;
+     *bptr++ = '\n';
+     fptr = ++sptr;
+   }
+   len = buf->length - (fptr - buf->buf);
+   if (bptr != fptr && len > 0)
+     bcopy ((char *) fptr, (char *) bptr, len);
+   buf->length -= fptr - bptr;
+   buf->buf[buf->length] = '\0';
+ }
+ \f
  /* Pre-C-Preprocessor to translate ANSI trigraph idiocy in BUF
     before main CCCP processing.  Name `pcp' is also in honor of the
     drugs the trigraph designers must have been on.
*************** handle_directive (ip, op)
*** 3661,3666 ****
--- 3701,3715 ----
  	switch (c) {
  	case '\\':
  	  if (bp < limit) {
+ 	    /* Backslash followed by whitespace and then newline deserves a
+ 	       warning.  */
+ 	    if (warn_comments)
+ 	      {
+ 		cp = bp;
+ 		while (cp < limit && is_hor_space[*cp]) cp++;
+ 		if (cp < limit && *cp == '\n' && bp != cp)
+ 		  warning ("trailing whitespace after backslash within macro definition");
+ 	      }
  	    if (*bp == '\n') {
  	      ip->lineno++;
  	      copy_directive = 1;
*************** finclude (f, inc, op, system_header_p, d
*** 5045,5050 ****
--- 5094,5101 ----
  
    indepth++;
    input_file_stack_tick++;
+ 
+   crlf_pcp (fp);
  
    if (!no_trigraphs)
      trigraph_pcp (fp);

      parent reply	other threads:[~1998-01-27  4:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-25 21:35 Matthew D. Langston
1998-01-25 23:26 ` Per Bothner
1998-01-27  4:02 ` Bruno Haible [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199801271202.NAA07525@halles.ilog.fr \
    --to=haible@ilog.fr \
    --cc=egcs@cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).