From 8157303b1e8961a18aa8779a99aea6a7d8dc7116 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 3 May 2002 19:55:26 +0200 Subject: [PATCH] re PR preprocessor/6489 (tradcpp0 fails on line ending with '\r\n') PR preprocessor/6489 * tradcpp.c (fixup_newlines): New. (main, finclude): Use it. From-SVN: r53103 --- gcc/ChangeLog | 6 ++++++ gcc/tradcpp.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 71e4466b0a6..cac408130e5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2002-05-03 Jakub Jelinek + + PR preprocessor/6489 + * tradcpp.c (fixup_newlines): New. + (main, finclude): Use it. + 2002-05-03 Richard Sandiford * config/mips/elf64.h (UNIQUE_SECTION): Use mips_unique_section. diff --git a/gcc/tradcpp.c b/gcc/tradcpp.c index 4ed6332ac7f..6381c2dc4e4 100644 --- a/gcc/tradcpp.c +++ b/gcc/tradcpp.c @@ -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)); @@ -952,6 +953,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. */ @@ -2594,6 +2596,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. */ @@ -2668,6 +2706,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. */ -- 2.30.2