From 9479046aa189bf86375023f47054f47ee2f7c93d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20A=C3=9Fhauer?= Date: Sat, 18 Jan 2020 11:06:12 +0100 Subject: [PATCH] tweaks: allow alternate line endings in rc files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nano currently expects rc files to have LF line endings. With users interacting between different environments, transfering config files between devices and sharing config files or parts thereof with other users, these line endings can get mangled in the process. There seems to be no documentation that describes that these files need to have LF line endings and no technical reason that mandates it either. Let's grant users the convenience of not caring about the line endings of these config files. Signed-off-by: Matthias Aßhauer --- configure.ac | 26 ++++++++++++++++++++++++++ src/rcfile.c | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/configure.ac b/configure.ac index c9a5127b..78613b3c 100644 --- a/configure.ac +++ b/configure.ac @@ -130,6 +130,32 @@ if test "x$enable_color" != xno; then color_support=yes fi + +AC_ARG_ENABLE(permissive-rcfile-eol, +AS_HELP_STRING([--disable-permissive-rcfile-eol], [Disable support for DOS and Macintosh line endings])) +if test "x$enable_tiny" = xyes; then + if test "x$enable_permissive_rcfile_eol" = xyes; then + if test "x$enable_nanorc" != xyes; then + AC_MSG_ERROR([--enable-permissive-rcfile-eol needs --enable-nanorc to work]) + fi + else + enable_permissive_rcfile_eol=no + fi +fi +if test "x$enable_nanorc" = xno; then + if test "x$enable_permissive_rcfile_eol" = xyes; then + AC_MSG_ERROR([--enable-permissive-rcfile-eol cannot work with --disable-nanorc]) + else + # Disabling nanorc silently disables alternate line endings. + enable_permissive_rcfile_eol=no + fi +fi +if test "x$enable_permissive_rcfile_eol" != xno; then + AC_DEFINE(ENABLE_PERMISSIVE_RCFILE_EOL, 1, [Define this to allow DOS and/or Macintosh line endings in rc files.]) + permissive_rcfile_eol=yes +fi + + AC_ARG_ENABLE(comment, AS_HELP_STRING([--disable-comment], [Disable the comment/uncomment function])) if test "x$enable_tiny" = xyes; then diff --git a/src/rcfile.c b/src/rcfile.c index 7285027c..d07710e1 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -1328,6 +1328,10 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only) /* Strip the terminating newline, if any. */ if (buffer[len - 1] == '\n') buffer[len - 1] = '\0'; +#ifdef ENABLE_PERMISSIVE_RCFILE_EOL + if (buffer[len - 1] == '\r') + buffer[len - 1] = '\0'; +#endif ptr = buffer; while (isblank((unsigned char)*ptr)) -- 2.17.1