]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR preprocessor/6489 (tradcpp0 fails on line ending with '\r\n')
authorJakub Jelinek <jakub@redhat.com>
Fri, 3 May 2002 17:51:03 +0000 (19:51 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 3 May 2002 17:51:03 +0000 (19:51 +0200)
PR preprocessor/6489
* tradcpp.c (fixup_newlines): New.
(main, finclude): Use it.

From-SVN: r53102

gcc/ChangeLog
gcc/tradcpp.c

index 03c6f394915bebd9d1b57dff892bac3618c34b24..dd1c8f15d7bc116277ac9b7a5d87b80e5de5e9a3 100644 (file)
@@ -1,3 +1,9 @@
+2002-05-03  Jakub Jelinek  <jakub@redhat.com>
+
+       PR preprocessor/6489
+       * tradcpp.c (fixup_newlines): New.
+       (main, finclude): Use it.
+
 2002-05-03  Rainer Orth  <ro@TechFak.Uni-Bielefeld.DE>
 
        * doc/install.texi (Installing): Mention GCC 3.1 buildstats.
index 3cff998e40639f3b4b88c1360af14e1d6fda7c34..f6bc24aeaa05b42f72247973aff7c25455c39c32 100644 (file)
@@ -430,6 +430,7 @@ static void grow_outbuf     PARAMS ((FILE_BUF *, int));
 static int handle_directive    PARAMS ((FILE_BUF *, FILE_BUF *));
 static void process_include    PARAMS ((struct file_name_list *,
                                         const U_CHAR *, int, int, FILE_BUF *));
+static void fixup_newlines     PARAMS ((FILE_BUF *));
 static void finclude           PARAMS ((int, const char *,
                                         struct file_name_list *, FILE_BUF *));
 static void init_dependency_output PARAMS ((void));
@@ -948,6 +949,7 @@ main (argc, argv)
   }
   fp->bufp = fp->buf;
   fp->if_stack = if_stack;
+  fixup_newlines (fp);
 
   /* Make sure data ends with a newline.  And put a null after it.  */
 
@@ -2590,6 +2592,42 @@ process_include (stackp, fbeg, flen, system_header_p, op)
   }
 }
 
+/* Replace all CR NL, NL CR and CR sequences with NL.  */
+
+static void
+fixup_newlines (FILE_BUF *fp)
+{
+  U_CHAR *p, *q, *end;
+
+  if (fp->length <= 0)
+    return;
+
+  end = fp->buf + fp->length;
+  *end = '\r';
+  p = (U_CHAR *) strchr ((const char *) fp->buf, '\r');
+  *end = '\0';
+  if (p == end)
+    return;
+
+  if (p > fp->buf && p[-1] == '\n')
+    p--;
+  q = p;
+  while (p < end)
+    switch (*p)
+      {
+      default:
+       *q++ = *p++;
+       break;
+      case '\n':
+      case '\r':
+       p += 1 + (p[0] + p[1] == '\n' + '\r');
+       *q++ = '\n';
+       break;
+      }
+
+  fp->length = q - fp->buf;
+}
+
 /* Process the contents of include file FNAME, already open on descriptor F,
    with output to OP.  */
 
@@ -2664,6 +2702,7 @@ finclude (f, fname, nhd, op)
     fp->length = st_size;
   }
   close (f);
+  fixup_newlines (fp);
 
   /* Make sure data ends with a newline.  And put a null after it.  */