mirror of
https://git.savannah.gnu.org/git/gperf.git
synced 2025-12-02 13:09:22 +00:00
Support input files with CR/LF line terminators.
This commit is contained in:
26
src/input.cc
26
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. */
|
||||
|
||||
Reference in New Issue
Block a user