summaryrefslogtreecommitdiff
path: root/src/input.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/input.cc')
-rw-r--r--src/input.cc26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/input.cc b/src/input.cc
index 67c93b5..fca04e0 100644
--- a/src/input.cc
+++ b/src/input.cc
@@ -1,5 +1,5 @@
/* Input routines.
- Copyright (C) 1989-1998, 2002-2004, 2011 Free Software Foundation, Inc.
+ Copyright (C) 1989-1998, 2002-2004, 2011, 2017-2018 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -263,6 +263,30 @@ Input::read_input ()
exit (1);
}
+ /* Convert CR/LF line terminators (Windows) to LF line terminators (Unix).
+ GCC 3.3 and newer support CR/LF line terminators in C sources on Unix,
+ so we do the same.
+ The so-called "text mode" in stdio on Windows translates CR/LF to \n
+ automatically, but here we also need this conversion on Unix. As a side
+ effect, on Windows we also parse CR/CR/LF into a single \n, but this
+ is not a problem. */
+ {
+ char *p = input;
+ char *p_end = input + input_length;
+ /* Converting the initial segment without CRs is a no-op. */
+ while (p < p_end && *p != '\r')
+ p++;
+ /* Then start the conversion for real. */
+ char *q = p;
+ while (p < p_end)
+ {
+ if (p[0] == '\r' && p + 1 < p_end && p[1] == '\n')
+ p++;
+ *q++ = *p++;
+ }
+ input_length = q - input;
+ }
+
/* We use input_end as a limit, in order to cope with NUL bytes in the
input. But note that one trailing NUL byte has been added after
input_end, for convenience. */