Mercurial > emacs
changeset 101678:589af07b7af1
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
stray ^M characters.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Fri, 30 Jan 2009 15:45:34 +0000 |
parents | 581bdd1e6b5f |
children | cedfaae09d98 |
files | src/coding.c |
diffstat | 1 files changed, 30 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/coding.c Fri Jan 30 14:37:32 2009 +0000 +++ b/src/coding.c Fri Jan 30 15:45:34 2009 +0000 @@ -5819,16 +5819,26 @@ || src[lsb + 2] != '\n') this_eol = EOL_SEEN_CR; else - this_eol = EOL_SEEN_CRLF; + { + this_eol = EOL_SEEN_CRLF; + src += 2; + } if (eol_seen == EOL_SEEN_NONE) /* This is the first end-of-line. */ eol_seen = this_eol; else if (eol_seen != this_eol) { - /* The found type is different from what found before. */ - eol_seen = EOL_SEEN_LF; - break; + /* The found type is different from what found before. + Allow for stray ^M characters in DOS EOL files. */ + if (eol_seen == EOL_SEEN_CR && this_eol == EOL_SEEN_CRLF + || eol_seen == EOL_SEEN_CRLF && this_eol == EOL_SEEN_CR) + eol_seen = EOL_SEEN_CRLF; + else + { + eol_seen = EOL_SEEN_LF; + break; + } } if (++total == MAX_EOL_CHECK_COUNT) break; @@ -5857,9 +5867,16 @@ eol_seen = this_eol; else if (eol_seen != this_eol) { - /* The found type is different from what found before. */ - eol_seen = EOL_SEEN_LF; - break; + /* The found type is different from what found before. + Allow for stray ^M characters in DOS EOL files. */ + if (eol_seen == EOL_SEEN_CR && this_eol == EOL_SEEN_CRLF + || eol_seen == EOL_SEEN_CRLF && this_eol == EOL_SEEN_CR) + eol_seen = EOL_SEEN_CRLF; + else + { + eol_seen = EOL_SEEN_LF; + break; + } } if (++total == MAX_EOL_CHECK_COUNT) break; @@ -6114,7 +6131,12 @@ eol_seen |= EOL_SEEN_CR; } } - if (eol_seen != EOL_SEEN_NONE + /* Handle DOS-style EOLs in a file with stray ^M characters. */ + if ((eol_seen & EOL_SEEN_CRLF) != 0 + && (eol_seen & EOL_SEEN_CR) != 0 + && (eol_seen & EOL_SEEN_LF) == 0) + eol_seen = EOL_SEEN_CRLF; + else if (eol_seen != EOL_SEEN_NONE && eol_seen != EOL_SEEN_LF && eol_seen != EOL_SEEN_CRLF && eol_seen != EOL_SEEN_CR)