summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2009-01-30 15:46:03 +0000
committerEli Zaretskii <eliz@gnu.org>2009-01-30 15:46:03 +0000
commit75f4f1ac04a17d1deda0e3a8c82428df784e7f5a (patch)
tree12e7dae1068baefe46bdcdeb3d58ef5ba679b72a /src
parent3951477883d9ebfed7d302b4e8aaa5b1005f7351 (diff)
downloademacs-75f4f1ac04a17d1deda0e3a8c82428df784e7f5a.tar.gz
(detect_eol, decode_eol): Handle text with DOS-style EOLs that also has
stray ^M characters.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog5
-rw-r--r--src/coding.c38
2 files changed, 35 insertions, 8 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 91d39e7b580..f86e3c5afd4 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2009-01-30 Eli Zaretskii <eliz@gnu.org>
+
+ * coding.c (detect_eol, decode_eol): Handle text with DOS-style
+ EOLs that also has stray ^M characters.
+
2009-01-30 Juanma Barranquero <lekktu@gmail.com>
* atimer.c (run_timers, alarm_signal_handler):
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)
|| 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 @@ detect_eol (source, src_bytes, category)
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 @@ decode_eol (coding)
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)