From: David Lawrence Ramsey Date: Sat, 17 Nov 2007 20:34:38 +0000 (+0000) Subject: in read_file(), improve autodetection of DOS and Mac format files to not X-Git-Tag: v2.0.7~28 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=c7a23145b739f4132bc3293bb619cba21dcfac5a;p=nano.git in read_file(), improve autodetection of DOS and Mac format files to not trigger on carriage returns in the middle of files, as found by Kjell Braden git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_0_branch/nano@4179 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index b62005fb..3d2bfdc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -43,6 +43,10 @@ CVS code - - Simplify and rewrite to use the strncasecmp() equivalents. (DLR) - files.c: + read_file() + - Improve autodetection of DOS and Mac format files to not + trigger on carriage returns in the middle of files. (DLR, + found by Kjell Braden) do_insertfile() - Make sure the mark is always properly positioned after inserting a file with the mark on. (DLR) diff --git a/src/files.c b/src/files.c index da0ff9cd..a74054d2 100644 --- a/src/files.c +++ b/src/files.c @@ -382,12 +382,15 @@ void read_file(FILE *f, const char *filename) * conversion isn't disabled, handle it! */ if (input == '\n') { #ifndef NANO_TINY - /* If there's a '\r' before the '\n', set format to DOS if - * we currently think this is a *nix file, or to both if we - * currently think it's a Mac file. */ - if (!ISSET(NO_CONVERT) && i > 0 && buf[i - 1] == '\r' && - (format == 0 || format == 2)) - format++; + /* If it's a DOS file or a DOS/Mac file ('\r' before '\n' on + * the first line if we think it's a *nix file, or on any + * line otherwise), and file conversion isn't disabled, + * handle it! */ + if (!ISSET(NO_CONVERT) && (num_lines == 0 || format != 0) && + i > 0 && buf[i - 1] == '\r') { + if (format == 0 || format == 2) + format++; + } #endif /* Read in the line properly. */ @@ -401,9 +404,11 @@ void read_file(FILE *f, const char *filename) buf[0] = '\0'; i = 0; #ifndef NANO_TINY - /* If it's a Mac file ('\r' without '\n'), and file conversion - * isn't disabled, handle it! */ - } else if (!ISSET(NO_CONVERT) && i > 0 && buf[i - 1] == '\r') { + /* If it's a Mac file ('\r' without '\n' on the first line if we + * think it's a *nix file, or on any line otherwise), and file + * conversion isn't disabled, handle it! */ + } else if (!ISSET(NO_CONVERT) && (num_lines == 0 || + format != 0) && i > 0 && buf[i - 1] == '\r') { /* If we currently think the file is a *nix file, set format * to Mac. If we currently think the file is a DOS file, * set format to both DOS and Mac. */