public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* CRLF translations by CPP?
@ 1998-01-25 21:35 Matthew D. Langston
  1998-01-25 23:26 ` Per Bothner
  1998-01-27  4:02 ` Bruno Haible
  0 siblings, 2 replies; 3+ messages in thread
From: Matthew D. Langston @ 1998-01-25 21:35 UTC (permalink / raw)
  To: egcs

Quick Description
-----------------
Is there a mechanism to enable egcs to properly parse multi-line cpp
macros that end with Backslash-CarriageReturn-LineFeed instead of
Backslash-LineFeed?

Detailed Description
--------------------
I help develop a library written in C that is primarily developed under
WinNT, e.g. each line of the source code ends with a
CarriageReturn-LineFeed.  The author of this library develops under
WinNT.  I develop under Linux using egcs.

This library makes heavy use of multi-line cpp macros.  Since this
library is developed under WinNT, these multi-line macros end with
Backslash-CarriageReturn-LineFeed instead of Backslash-LineFeed.  This
prevents egcs from successfully compiling the source files in the
library which use multi-line cpp macros.

Is there a way to enable egcs to properly parse files with lines ending
in CarriageReturn-LineFeed?  I was hoping for a solution that didn't
require me to use the `dos2unix' program (or an equivalent program) on
all of the source files of the library every time I receive patches to
the library source code.

--
Matthew D. Langston
SLD, Stanford Linear Accelerator Center
langston@SLAC.Stanford.EDU

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: CRLF translations by CPP?
  1998-01-25 21:35 CRLF translations by CPP? Matthew D. Langston
@ 1998-01-25 23:26 ` Per Bothner
  1998-01-27  4:02 ` Bruno Haible
  1 sibling, 0 replies; 3+ messages in thread
From: Per Bothner @ 1998-01-25 23:26 UTC (permalink / raw)
  To: langston; +Cc: egcs

> Is there a mechanism to enable egcs to properly parse multi-line cpp
> macros that end with Backslash-CarriageReturn-LineFeed instead of
> Backslash-LineFeed?

Cpp (and cpplib and the various lexers) should be modified so that they
treat any of CR, LF, or CR-followed-by-LF as a newline - without
requiring any special flags, independent of host operating system.
This is the most useful and convenient apprach (for the user) for
any program that reads "text" input.

But actually doing the work is tedious.  Note that Cygnus is
working on making the cpplib the default, so long-term, fixing
cpplib will take care of C, C++, and cpp.  There is reason to
believe this will happen soon (by mid-year).

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: CRLF translations by CPP?
  1998-01-25 21:35 CRLF translations by CPP? Matthew D. Langston
  1998-01-25 23:26 ` Per Bothner
@ 1998-01-27  4:02 ` Bruno Haible
  1 sibling, 0 replies; 3+ messages in thread
From: Bruno Haible @ 1998-01-27  4:02 UTC (permalink / raw)
  To: egcs

> 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);

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-01-27  4:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-25 21:35 CRLF translations by CPP? Matthew D. Langston
1998-01-25 23:26 ` Per Bothner
1998-01-27  4:02 ` Bruno Haible

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).