1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Support input files with CR/LF line terminators.

This commit is contained in:
Bruno Haible
2018-04-24 09:25:10 +02:00
parent 1edd38e96d
commit 13c9383b10
3 changed files with 37 additions and 1 deletions

View File

@@ -1,3 +1,9 @@
2018-04-24 Bruno Haible <bruno@clisp.org>
Support input files with CR/LF line terminators.
Reported at <https://savannah.gnu.org/bugs/?53732>.
* src/input.cc (Input::read_input): Convert CR/LF sequences to LF.
2018-01-27 Bruno Haible <bruno@clisp.org>
Rename some files.

6
NEWS
View File

@@ -1,3 +1,9 @@
New in 3.2:
* The input file may now use Windows line terminators (CR/LF) instead of
Unix line terminators (LF).
Note: This is an incompatible change. If you want to use a keyword that
ends in a CR byte, such as xyz<CR>, write it as "xyz\r".
New in 3.1:
* The generated C code is now in ANSI-C by default. If you want to support
pre-ANSI-C compilers, you need to provide the option --language=C on the

View File

@@ -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. */