diff3: implement --strip-trailing-cr
Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D31626
This commit is contained in:
parent
e8ff95356c
commit
54a3415cb6
@ -40,6 +40,7 @@
|
||||
.Nm diff3
|
||||
.Op Fl 3aEeiXx
|
||||
.Op Fl Fl diff-program Ar program
|
||||
.Op Fl Fl strip-trailing-cr
|
||||
.Op Fl L | Fl Fl label Ar label1
|
||||
.Op Fl L | Fl Fl label Ar label2
|
||||
.Op Fl L | Fl Fl label Ar label3
|
||||
@ -125,6 +126,8 @@ Use
|
||||
instead of the default
|
||||
.Xr diff 1
|
||||
to compare files.
|
||||
.It Fl Fl strip-trailing-cr
|
||||
Strip trailing carriage return on input files.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
|
@ -264,6 +264,12 @@ get_line(FILE *b, size_t *n)
|
||||
if ((len = getline(&buf, &bufsize, b)) < 0)
|
||||
return (NULL);
|
||||
|
||||
if (strip_cr && len >= 2 && strcmp("\r\n", &(buf[len - 2])) == 0) {
|
||||
buf[len - 2] = '\n';
|
||||
buf[len - 1] = '\0';
|
||||
len--;
|
||||
}
|
||||
|
||||
if (n != NULL)
|
||||
*n = len;
|
||||
|
||||
@ -599,7 +605,7 @@ main(int argc, char **argv)
|
||||
char *labels[] = { NULL, NULL, NULL };
|
||||
const char *diffprog = DIFF_PATH;
|
||||
char *file1, *file2, *file3;
|
||||
char *diffargv[6];
|
||||
char *diffargv[7];
|
||||
int diffargc = 0;
|
||||
int fd13[2], fd23[2];
|
||||
int pd13, pd23;
|
||||
@ -657,6 +663,7 @@ main(int argc, char **argv)
|
||||
break;
|
||||
case STRIPCR_OPT:
|
||||
strip_cr = 1;
|
||||
diffargv[diffargc++] = __DECONST(char *, "--strip-trailing-cr");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
6
usr.bin/diff3/tests/1cr.txt
Normal file
6
usr.bin/diff3/tests/1cr.txt
Normal file
@ -0,0 +1,6 @@
|
||||
This is a more complete test
|
||||
which multiple lines
|
||||
and a few typ0s to fix
|
||||
also I plan to add few lines
|
||||
and to remove
|
||||
other lines
|
@ -6,6 +6,7 @@ ATF_TESTS_SH= diff3_test
|
||||
|
||||
${PACKAGE}FILES+= \
|
||||
1.txt \
|
||||
1cr.txt \
|
||||
2.txt \
|
||||
3.txt \
|
||||
1.out \
|
||||
|
@ -8,6 +8,9 @@ diff3_body()
|
||||
atf_check -o file:$(atf_get_srcdir)/1.out \
|
||||
diff3 $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
|
||||
|
||||
atf_check -o file:$(atf_get_srcdir)/1.out \
|
||||
diff3 --strip-trailing-cr $(atf_get_srcdir)/1cr.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
|
||||
|
||||
atf_check -o file:$(atf_get_srcdir)/2.out \
|
||||
diff3 -e $(atf_get_srcdir)/1.txt $(atf_get_srcdir)/2.txt $(atf_get_srcdir)/3.txt
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user