rcfile: allow alternate line endings in nanorc files

When copy-pasting has resulted in a nanorc file with DOS line endings
(CR+LF), then silently ignore the carriage return, to avoid printing
an error message that partly overwrites itself.

This fulfills https://savannah.gnu.org/bugs/?57756.
Requested-by: Matthias Aßhauer <mha1993@live.de>
This commit is contained in:
Benno Schulenberg 2020-02-09 11:41:56 +01:00
parent f8d2f552bd
commit 98f038ad96
1 changed files with 4 additions and 2 deletions

View File

@ -1317,9 +1317,11 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only)
if (just_syntax && !intros_only && lineno <= live_syntax->lineno)
continue;
#endif
/* Strip the terminating newline, if any. */
/* Strip the terminating newline and possibly a carriage return. */
if (buffer[len - 1] == '\n')
buffer[len - 1] = '\0';
buffer[--len] = '\0';
if (buffer[len - 1] == '\r')
buffer[--len] = '\0';
ptr = buffer;
while (isblank((unsigned char)*ptr))