commit 98f038ad96183ed4cca947180928d03002f87201
parent f8d2f552bdd65f3855dfb505b739a19103c521d5
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 9 Feb 2020 11:41:56 +0100
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>
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/rcfile.c b/src/rcfile.c
@@ -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))