Module Name:    othersrc
Committed By:   agc
Date:           Tue Jan 15 08:26:16 UTC 2013

Modified Files:
        othersrc/external/bsd/netdiff/bin/wdiff: Makefile
        othersrc/external/bsd/netdiff/dist: diffreg.c netwdiff.1 netwdiff.c

Log Message:
Implement the -n (nowrap) argument to wdiff(1).  With the -n argument
specified, and when a change spans two lines, the end of region
character sequence is displayed before the new line character, and the
start of region character sequence after it.

Add a test which implements change bars on the left for any changed
text:

% netwdiff -1n f1 f2 | sed -e 's/^/  /;/{+/s/^ /|/;s/{+//g;s/+}//g'

  ...
  static int
| difffile(const char *filename1, const char *filename2)
  {
  ...


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 othersrc/external/bsd/netdiff/bin/wdiff/Makefile
cvs rdiff -u -r1.8 -r1.9 othersrc/external/bsd/netdiff/dist/diffreg.c
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/netdiff/dist/netwdiff.1
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/netdiff/dist/netwdiff.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/external/bsd/netdiff/bin/wdiff/Makefile
diff -u othersrc/external/bsd/netdiff/bin/wdiff/Makefile:1.1 othersrc/external/bsd/netdiff/bin/wdiff/Makefile:1.2
--- othersrc/external/bsd/netdiff/bin/wdiff/Makefile:1.1	Sun Jan 13 22:17:22 2013
+++ othersrc/external/bsd/netdiff/bin/wdiff/Makefile	Tue Jan 15 08:26:15 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2013/01/13 22:17:22 agc Exp $
+# $NetBSD: Makefile,v 1.2 2013/01/15 08:26:15 agc Exp $
 
 .include <bsd.own.mk>
 
@@ -37,3 +37,8 @@ t: ${PROG}
 	-wdiff -3 f1 f2 > wdiff.out
 	-netdiff wdiff.out netwdiff.out
 	rm -f wdiff.out netwdiff.out
+	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} -1n f1 f2 | \
+		sed -e 's/^/  /;/{+/s/^ /|/;s/{+//g;s/+}//g' > netwdiff.out
+	-wdiff -1n f1 f2 | sed -e 's/^/  /;/{+/s/^ /|/;s/{+//g;s/+}//g' > wdiff.out
+	-netdiff wdiff.out netwdiff.out
+	rm -f wdiff.out netwdiff.out

Index: othersrc/external/bsd/netdiff/dist/diffreg.c
diff -u othersrc/external/bsd/netdiff/dist/diffreg.c:1.8 othersrc/external/bsd/netdiff/dist/diffreg.c:1.9
--- othersrc/external/bsd/netdiff/dist/diffreg.c:1.8	Tue Jan 15 01:57:56 2013
+++ othersrc/external/bsd/netdiff/dist/diffreg.c	Tue Jan 15 08:26:16 2013
@@ -2042,12 +2042,16 @@ inputskip(char *d, long *in, char type)
 
 /* copy until finished */
 static int
-copy(FILE *fp, wordfile_t *f, int copyspace)
+copy(FILE *fp, wordfile_t *f, int copyspace, int nowrap, char **region)
 {
 	for ( ; (size_t)(f->p - f->file) < f->filesize &&
 		(copyspace != 0) == (isspace((uint8_t)*f->p) != 0) ; f->p++) {
 		if (fp) {
-			fprintf(fp, "%c", *f->p);
+			if (*f->p == '\n' && nowrap) {
+				fprintf(fp, "%s\n%s", region[1], region[0]);
+			} else {
+				fprintf(fp, "%c", *f->p);
+			}
 		}
 	}
 	return 1;
@@ -2055,18 +2059,18 @@ copy(FILE *fp, wordfile_t *f, int copysp
 
 /* print words */
 static int
-pwords(FILE *fp, wordfile_t *f, long words, char **region)
+pwords(FILE *fp, wordfile_t *f, long words, int nowrap, char **region)
 {
 	const int	copyspace = 1;
 	const int	copyword = 0;
 	long		i;
 
 	for (i = 0 ; i < words ; i++) {
-		copy(fp, f, copyspace);
+		copy(fp, f, copyspace, i > 0 && nowrap, region);
 		if (i == 0 && region && fp) {
 			fprintf(fp, "%s", region[0]);
 		}
-		copy(fp, f, copyword);
+		copy(fp, f, copyword, nowrap, region);
 		f->wordc += 1;
 	}
 	if (region && fp) {
@@ -2102,27 +2106,27 @@ pdiffs(diff_t *diff, wordfile_t *f, char
 		in[2] = strtol(&d[match[5].rm_so], NULL, 0);
 		in[3] = (match[7].rm_so >= 0) ? strtol(&d[match[7].rm_so], NULL, 0) : in[2];
 		type = d[match[4].rm_so];
-		pwords(common, &f[0], (long)(in[0] - f[0].wordc - 1), NULL);
+		pwords(common, &f[0], (long)(in[0] - f[0].wordc - 1), 0, NULL);
 		if (diff->inhibit == 3) {
 			fprintf(stdout, "\n%s\n", WDIFF_COMMON_DELIM);
 		}
-		pwords(NULL, &f[1], (long)(in[2] - f[1].wordc - 1), NULL);
+		pwords(NULL, &f[1], (long)(in[2] - f[1].wordc - 1), 0, NULL);
 		switch(type) {
 		case 'a':
 			if (f->p != f->file) {
-				pwords(common, &f[0], 1, NULL);
+				pwords(common, &f[0], 1, 0, NULL);
 			}
-			pwords(rhs, &f[1], in[3] - in[2] + 1, diff->insertregion);
+			pwords(rhs, &f[1], in[3] - in[2] + 1, DIFF_GET_FLAG(diff, 'n'), diff->insertregion);
 			if (rhs && common && in[0] == 0) {
 				fprintf(rhs, "\n");
 			}
 			break;
 		case 'c':
-			pwords(lhs, &f[0], in[1] - in[0] + 1, diff->deleteregion);
-			pwords(rhs, &f[1], in[3] - in[2] + 1, diff->insertregion);
+			pwords(lhs, &f[0], in[1] - in[0] + 1, DIFF_GET_FLAG(diff, 'n'), diff->deleteregion);
+			pwords(rhs, &f[1], in[3] - in[2] + 1, DIFF_GET_FLAG(diff, 'n'), diff->insertregion);
 			break;
 		case 'd':
-			pwords(lhs, &f[0], in[1] - in[0] + 1, diff->deleteregion);
+			pwords(lhs, &f[0], in[1] - in[0] + 1, DIFF_GET_FLAG(diff, 'n'), diff->deleteregion);
 			break;
 		default:
 			break;
@@ -2133,9 +2137,9 @@ pdiffs(diff_t *diff, wordfile_t *f, char
 	if (diff->inhibit == 3) {
 		fprintf(stdout, "\n%s", WDIFF_COMMON_DELIM);
 	}
-	pwords(common, &f[0], (long)(f[0].totwords - f[0].wordc), NULL);
+	pwords(common, &f[0], (long)(f[0].totwords - f[0].wordc), 0, NULL);
 	/* copy trailing whitespace */
-	copy(stdout, &f[0], 1);
+	copy(stdout, &f[0], 1, 0, NULL);
 	return 1;
 }
 

Index: othersrc/external/bsd/netdiff/dist/netwdiff.1
diff -u othersrc/external/bsd/netdiff/dist/netwdiff.1:1.3 othersrc/external/bsd/netdiff/dist/netwdiff.1:1.4
--- othersrc/external/bsd/netdiff/dist/netwdiff.1:1.3	Tue Jan 15 01:46:04 2013
+++ othersrc/external/bsd/netdiff/dist/netwdiff.1	Tue Jan 15 08:26:16 2013
@@ -1,4 +1,4 @@
-.\" $NetBSD: netwdiff.1,v 1.3 2013/01/15 01:46:04 agc Exp $
+.\" $NetBSD: netwdiff.1,v 1.4 2013/01/15 08:26:16 agc Exp $
 .\"
 .\" Copyright (c) 2013 Alistair Crooks <[email protected]>
 .\" All rights reserved.
@@ -23,7 +23,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 14, 2013
+.Dd January 15, 2013
 .Dt NETWDIFF 1
 .Os
 .Sh NAME
@@ -31,7 +31,7 @@
 .Nd Word-based difference and comparison program
 .Sh SYNOPSIS
 .Nm
-.Op Fl 123i
+.Op Fl 123in
 .Op Fl w Ar start-delete
 .Op Fl x Ar end-delete
 .Op Fl y Ar start-insert
@@ -63,6 +63,10 @@ Inhibit the display of text common to bo
 means that only the changes will be displayed.
 .It Fl i
 Perform comparisons in a case-insensitive manner.
+.It Fl n
+When a change flows over the end of a line, issue the end of region character
+sequence before the newline character, and a start of region character sequence
+after the newline character.
 .It Fl w Ar start-delete
 Specify the character sequence to be used at the start of a region of deleted text.
 The default is
@@ -155,6 +159,11 @@ Finally, the escape sequences can be use
 .Bd -literal
 % netwdiff -w $ansi_red -x $ansi_end -y $ansi_green -z $ansi_end f1 f2
 .Ed
+.Pp
+This example shows only the added text with change bars in the left margin
+.Bd -literal
+% netwdiff -1n f1 f2 | sed -e 's/^/  /;/{+/s/^ /|/;s/{+//g;s/+}//g'
+.Ed
 .Sh SEE ALSO
 .Xr ksh 1 ,
 .Xr netdiff 1 ,

Index: othersrc/external/bsd/netdiff/dist/netwdiff.c
diff -u othersrc/external/bsd/netdiff/dist/netwdiff.c:1.2 othersrc/external/bsd/netdiff/dist/netwdiff.c:1.3
--- othersrc/external/bsd/netdiff/dist/netwdiff.c:1.2	Tue Jan 15 01:46:04 2013
+++ othersrc/external/bsd/netdiff/dist/netwdiff.c	Tue Jan 15 08:26:16 2013
@@ -39,7 +39,7 @@ main(int argc, char **argv)
 	memset(&diff, 0x0, sizeof(diff));
 	diff_set_var(&diff, "format", "normal");
 	diff_set_var(&diff, "output", "[dynamic]");
-	while ((i = getopt(argc, argv, "123iw:x:y:z:")) != -1) {
+	while ((i = getopt(argc, argv, "123inw:x:y:z:")) != -1) {
 		switch(i) {
 		case '1':
 			diff_set_var(&diff, "inhibit", "lhs");
@@ -51,6 +51,7 @@ main(int argc, char **argv)
 			diff_set_var(&diff, "inhibit", "common");
 			break;
 		case 'i':
+		case 'n':
 			diff_set_flag(&diff, i);
 			break;
 		case 'w':

Reply via email to