diff: don't output carriage returns that were stripped on input
--strip-trailing-cr worked as intended for comparison between files, but the characters were still present in final output.
This commit is contained in:
parent
ddce862ad8
commit
af2f016431
@ -1273,7 +1273,16 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags)
|
||||
}
|
||||
col = 0;
|
||||
for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) {
|
||||
if ((c = getc(lb)) == EOF) {
|
||||
c = getc(lb);
|
||||
if (flags & D_STRIPCR && c == '\r') {
|
||||
if ((c = getc(lb)) == '\n')
|
||||
j++;
|
||||
else {
|
||||
ungetc(c, lb);
|
||||
c = '\r';
|
||||
}
|
||||
}
|
||||
if (c == EOF) {
|
||||
if (diff_format == D_EDIT ||
|
||||
diff_format == D_REVERSE ||
|
||||
diff_format == D_NREVERSE)
|
||||
|
@ -26,7 +26,8 @@ ${PACKAGE}FILES+= \
|
||||
header.out \
|
||||
header_ns.out \
|
||||
ifdef.out \
|
||||
group-format.out
|
||||
group-format.out \
|
||||
strip_o.out
|
||||
|
||||
NETBSD_ATF_TESTS_SH+= netbsd_diff_test
|
||||
|
||||
|
@ -9,6 +9,7 @@ atf_test_case group_format
|
||||
atf_test_case side_by_side
|
||||
atf_test_case brief_format
|
||||
atf_test_case b230049
|
||||
atf_test_case stripcr_o
|
||||
atf_test_case b252515
|
||||
atf_test_case Bflag
|
||||
atf_test_case Nflag
|
||||
@ -68,6 +69,14 @@ b230049_body()
|
||||
b230049_a.in b230049_b.in
|
||||
}
|
||||
|
||||
stripcr_o_body()
|
||||
{
|
||||
printf 'a\nX\nc\n' > stripcr_o_X.in
|
||||
printf 'a\r\nY\r\nc\r\n' > stripcr_o_Y.in
|
||||
atf_check -o "file:$(atf_get_srcdir)/strip_o.out" -s eq:1 \
|
||||
diff -L1 -L2 -u --strip-trailing-cr stripcr_o_X.in stripcr_o_Y.in
|
||||
}
|
||||
|
||||
b252515_body()
|
||||
{
|
||||
printf 'a b\n' > b252515_a.in
|
||||
@ -267,6 +276,7 @@ atf_init_test_cases()
|
||||
atf_add_test_case side_by_side
|
||||
atf_add_test_case brief_format
|
||||
atf_add_test_case b230049
|
||||
atf_add_test_case stripcr_o
|
||||
atf_add_test_case b252515
|
||||
atf_add_test_case Bflag
|
||||
atf_add_test_case Nflag
|
||||
|
7
usr.bin/diff/tests/strip_o.out
Normal file
7
usr.bin/diff/tests/strip_o.out
Normal file
@ -0,0 +1,7 @@
|
||||
--- 1
|
||||
+++ 2
|
||||
@@ -1,3 +1,3 @@
|
||||
a
|
||||
-X
|
||||
+Y
|
||||
c
|
Loading…
Reference in New Issue
Block a user