Date: Fri, 27 Jul 2018 05:21:20 +0000 (UTC) From: Xin LI <delphij@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336754 - in head/usr.bin/diff: . tests Message-ID: <201807270521.w6R5LKQW010565@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: delphij Date: Fri Jul 27 05:21:20 2018 New Revision: 336754 URL: https://svnweb.freebsd.org/changeset/base/336754 Log: 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 Modified: head/usr.bin/diff/diffreg.c head/usr.bin/diff/tests/diff_test.sh Modified: head/usr.bin/diff/diffreg.c ============================================================================== --- head/usr.bin/diff/diffreg.c Fri Jul 27 01:20:34 2018 (r336753) +++ head/usr.bin/diff/diffreg.c Fri Jul 27 05:21:20 2018 (r336754) @@ -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)) { Modified: head/usr.bin/diff/tests/diff_test.sh ============================================================================== --- head/usr.bin/diff/tests/diff_test.sh Fri Jul 27 01:20:34 2018 (r336753) +++ head/usr.bin/diff/tests/diff_test.sh Fri Jul 27 05:21:20 2018 (r336754) @@ -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 }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807270521.w6R5LKQW010565>