Improve --strip-trailing-cr handling:
- Advance ctold for f1 and ctnew for f2 - ungetc() if the character is unexpected - Don't break early when we hit the combination on one side PR: 230049 Reported by: maskray <emacsray gmail com> Reviewed by: bapt, maskray MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D16451
This commit is contained in:
parent
324976739f
commit
9977c7b512
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336754
@ -720,19 +720,22 @@ check(FILE *f1, FILE *f2, int flags)
|
||||
}
|
||||
ctold++;
|
||||
ctnew++;
|
||||
if (flags & D_STRIPCR) {
|
||||
if (flags & D_STRIPCR && (c == '\r' || d == '\r')) {
|
||||
if (c == '\r') {
|
||||
if ((c = getc(f1)) == '\n') {
|
||||
ctnew++;
|
||||
break;
|
||||
ctold++;
|
||||
} else {
|
||||
ungetc(c, f1);
|
||||
}
|
||||
}
|
||||
if (d == '\r') {
|
||||
if ((d = getc(f2)) == '\n') {
|
||||
ctold++;
|
||||
break;
|
||||
ctnew++;
|
||||
} else {
|
||||
ungetc(d, f2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((flags & D_FOLDBLANKS) && isspace(c) &&
|
||||
isspace(d)) {
|
||||
|
@ -8,6 +8,7 @@ atf_test_case ifdef
|
||||
atf_test_case group_format
|
||||
atf_test_case side_by_side
|
||||
atf_test_case brief_format
|
||||
atf_test_case b230049
|
||||
|
||||
simple_body()
|
||||
{
|
||||
@ -52,6 +53,15 @@ unified_body()
|
||||
diff -u9999 -L input_c1.in -L input_c2.in "$(atf_get_srcdir)/input_c1.in" "$(atf_get_srcdir)/input_c2.in"
|
||||
}
|
||||
|
||||
b230049_body()
|
||||
{
|
||||
printf 'a\nb\r\nc\n' > b230049_a.in
|
||||
printf 'a\r\nb\r\nc\r\n' > b230049_b.in
|
||||
atf_check -o empty -s eq:0 \
|
||||
diff -up --strip-trailing-cr -L b230049_a.in -L b230049_b.in \
|
||||
b230049_a.in b230049_b.in
|
||||
}
|
||||
|
||||
header_body()
|
||||
{
|
||||
export TZ=UTC
|
||||
@ -150,4 +160,5 @@ atf_init_test_cases()
|
||||
atf_add_test_case group_format
|
||||
atf_add_test_case side_by_side
|
||||
atf_add_test_case brief_format
|
||||
atf_add_test_case b230049
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user