aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorEli Zaretskii2009-01-30 15:46:03 +0000
committerEli Zaretskii2009-01-30 15:46:03 +0000
commit75f4f1ac04a17d1deda0e3a8c82428df784e7f5a (patch)
tree12e7dae1068baefe46bdcdeb3d58ef5ba679b72a /src/coding.c
parent3951477883d9ebfed7d302b4e8aaa5b1005f7351 (diff)
downloademacs-75f4f1ac04a17d1deda0e3a8c82428df784e7f5a.tar.gz
emacs-75f4f1ac04a17d1deda0e3a8c82428df784e7f5a.zip
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
stray ^M characters.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/coding.c b/src/coding.c
index 8c7ddf34db2..38cb3605464 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -5819,16 +5819,26 @@ detect_eol (source, src_bytes, category)
5819 || src[lsb + 2] != '\n') 5819 || src[lsb + 2] != '\n')
5820 this_eol = EOL_SEEN_CR; 5820 this_eol = EOL_SEEN_CR;
5821 else 5821 else
5822 this_eol = EOL_SEEN_CRLF; 5822 {
5823 this_eol = EOL_SEEN_CRLF;
5824 src += 2;
5825 }
5823 5826
5824 if (eol_seen == EOL_SEEN_NONE) 5827 if (eol_seen == EOL_SEEN_NONE)
5825 /* This is the first end-of-line. */ 5828 /* This is the first end-of-line. */
5826 eol_seen = this_eol; 5829 eol_seen = this_eol;
5827 else if (eol_seen != this_eol) 5830 else if (eol_seen != this_eol)
5828 { 5831 {
5829 /* The found type is different from what found before. */ 5832 /* The found type is different from what found before.
5830 eol_seen = EOL_SEEN_LF; 5833 Allow for stray ^M characters in DOS EOL files. */
5831 break; 5834 if (eol_seen == EOL_SEEN_CR && this_eol == EOL_SEEN_CRLF
5835 || eol_seen == EOL_SEEN_CRLF && this_eol == EOL_SEEN_CR)
5836 eol_seen = EOL_SEEN_CRLF;
5837 else
5838 {
5839 eol_seen = EOL_SEEN_LF;
5840 break;
5841 }
5832 } 5842 }
5833 if (++total == MAX_EOL_CHECK_COUNT) 5843 if (++total == MAX_EOL_CHECK_COUNT)
5834 break; 5844 break;
@@ -5857,9 +5867,16 @@ detect_eol (source, src_bytes, category)
5857 eol_seen = this_eol; 5867 eol_seen = this_eol;
5858 else if (eol_seen != this_eol) 5868 else if (eol_seen != this_eol)
5859 { 5869 {
5860 /* The found type is different from what found before. */ 5870 /* The found type is different from what found before.
5861 eol_seen = EOL_SEEN_LF; 5871 Allow for stray ^M characters in DOS EOL files. */
5862 break; 5872 if (eol_seen == EOL_SEEN_CR && this_eol == EOL_SEEN_CRLF
5873 || eol_seen == EOL_SEEN_CRLF && this_eol == EOL_SEEN_CR)
5874 eol_seen = EOL_SEEN_CRLF;
5875 else
5876 {
5877 eol_seen = EOL_SEEN_LF;
5878 break;
5879 }
5863 } 5880 }
5864 if (++total == MAX_EOL_CHECK_COUNT) 5881 if (++total == MAX_EOL_CHECK_COUNT)
5865 break; 5882 break;
@@ -6114,7 +6131,12 @@ decode_eol (coding)
6114 eol_seen |= EOL_SEEN_CR; 6131 eol_seen |= EOL_SEEN_CR;
6115 } 6132 }
6116 } 6133 }
6117 if (eol_seen != EOL_SEEN_NONE 6134 /* Handle DOS-style EOLs in a file with stray ^M characters. */
6135 if ((eol_seen & EOL_SEEN_CRLF) != 0
6136 && (eol_seen & EOL_SEEN_CR) != 0
6137 && (eol_seen & EOL_SEEN_LF) == 0)
6138 eol_seen = EOL_SEEN_CRLF;
6139 else if (eol_seen != EOL_SEEN_NONE
6118 && eol_seen != EOL_SEEN_LF 6140 && eol_seen != EOL_SEEN_LF
6119 && eol_seen != EOL_SEEN_CRLF 6141 && eol_seen != EOL_SEEN_CRLF
6120 && eol_seen != EOL_SEEN_CR) 6142 && eol_seen != EOL_SEEN_CR)