Module Name:    othersrc
Committed By:   agc
Date:           Sun Jan 13 22:17:22 UTC 2013

Modified Files:
        othersrc/external/bsd/netdiff/bin: Makefile
        othersrc/external/bsd/netdiff/bin/netdiff: Makefile
        othersrc/external/bsd/netdiff/bin/qdiff: Makefile
        othersrc/external/bsd/netdiff/dist: diff.c diff_subr.c diffreg.c
            libnetdiff.3 netdiff.h
        othersrc/external/bsd/netdiff/lib: Makefile
Added Files:
        othersrc/external/bsd/netdiff/bin/wdiff: Makefile f1 f2
        othersrc/external/bsd/netdiff/dist: netwdiff.1 netwdiff.c

Log Message:
Add wdiff functionality, which performs a word-by-word comparison
between two areas of memory, or between two files.  This is
accomplished using two new functions, wdiff_mem() or wdiff_file(), and
results can either be retrieved by displaying them to stdout, to an
output file, or by using diff_get_diffs() to retrieve the results
in-memory.

Internally, the two files/areas of memory are split into separate
areas of memory with a word on each line, and the two areas of memory
are compared using diff_mem().

Comparisons can also be made in a case-insensitive manner.

In the comparison output, added text is displayed in {+ ...  +}
delimiters, and deleted text is shown with [- ... -] delimiters.
Changes are displayed as a deletion and an addition.

+ Deleted text can be inhibited from display by using the -1 argument
  to netwdiff(1).
+ Added text can be inhibited from display by using the -2 argument to
  netwdiff(1).
+ Common text can be inhibited from display by using the -3 argument
  to netwdiff(1).

(Don't blame me, these flags are the ones used by GNU wdiff.)

With thanks to Thomas Klausner for the nudge to create this.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/netdiff/bin/Makefile
cvs rdiff -u -r1.1.1.1 -r1.2 \
    othersrc/external/bsd/netdiff/bin/netdiff/Makefile
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/netdiff/bin/qdiff/Makefile
cvs rdiff -u -r0 -r1.1 othersrc/external/bsd/netdiff/bin/wdiff/Makefile \
    othersrc/external/bsd/netdiff/bin/wdiff/f1 \
    othersrc/external/bsd/netdiff/bin/wdiff/f2
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/netdiff/dist/diff.c \
    othersrc/external/bsd/netdiff/dist/diffreg.c \
    othersrc/external/bsd/netdiff/dist/libnetdiff.3
cvs rdiff -u -r1.4 -r1.5 othersrc/external/bsd/netdiff/dist/diff_subr.c
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/netdiff/dist/netdiff.h
cvs rdiff -u -r0 -r1.1 othersrc/external/bsd/netdiff/dist/netwdiff.1 \
    othersrc/external/bsd/netdiff/dist/netwdiff.c
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/bsd/netdiff/lib/Makefile

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/Makefile
diff -u othersrc/external/bsd/netdiff/bin/Makefile:1.2 othersrc/external/bsd/netdiff/bin/Makefile:1.3
--- othersrc/external/bsd/netdiff/bin/Makefile:1.2	Sat Jan 12 01:31:20 2013
+++ othersrc/external/bsd/netdiff/bin/Makefile	Sun Jan 13 22:17:21 2013
@@ -1,6 +1,7 @@
-# $NetBSD: Makefile,v 1.2 2013/01/12 01:31:20 agc Exp $
+# $NetBSD: Makefile,v 1.3 2013/01/13 22:17:21 agc Exp $
 
 SUBDIR=		netdiff
+SUBDIR=		wdiff
 .if !make(install)
 SUBDIR+=	memdiff
 SUBDIR+=	qdiff
@@ -12,3 +13,4 @@ t:
 	cd netdiff && ${MAKE} t
 	cd qdiff && ${MAKE} t
 	cd memdiff && ${MAKE} t
+	cd wdiff && ${MAKE} t

Index: othersrc/external/bsd/netdiff/bin/netdiff/Makefile
diff -u othersrc/external/bsd/netdiff/bin/netdiff/Makefile:1.1.1.1 othersrc/external/bsd/netdiff/bin/netdiff/Makefile:1.2
--- othersrc/external/bsd/netdiff/bin/netdiff/Makefile:1.1.1.1	Thu Jan 10 08:17:11 2013
+++ othersrc/external/bsd/netdiff/bin/netdiff/Makefile	Sun Jan 13 22:17:21 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1.1.1 2013/01/10 08:17:11 agc Exp $
+# $NetBSD: Makefile,v 1.2 2013/01/13 22:17:21 agc Exp $
 
 .include <bsd.own.mk>
 
@@ -30,9 +30,9 @@ t: ${PROG}
 	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} -u f1 f2 > 003.out
 	diff 003.expected 003.out
 	rm -f 003.out
-	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} /usr/src/sbin /d/thinfs-src/sbin > 004.out
-	diff 004.expected 004.out
-	rm -f 004.out
+	#-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} /usr/src/sbin /d/thinfs-src/sbin > 004.out
+	#diff 004.expected 004.out
+	#rm -f 004.out
 	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} Makefile Makefile > 005.out
 	diff 005.expected 005.out
 	rm -f 005.out

Index: othersrc/external/bsd/netdiff/bin/qdiff/Makefile
diff -u othersrc/external/bsd/netdiff/bin/qdiff/Makefile:1.1.1.1 othersrc/external/bsd/netdiff/bin/qdiff/Makefile:1.2
--- othersrc/external/bsd/netdiff/bin/qdiff/Makefile:1.1.1.1	Thu Jan 10 08:17:11 2013
+++ othersrc/external/bsd/netdiff/bin/qdiff/Makefile	Sun Jan 13 22:17:21 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1.1.1 2013/01/10 08:17:11 agc Exp $
+# $NetBSD: Makefile,v 1.2 2013/01/13 22:17:21 agc Exp $
 
 .include <bsd.own.mk>
 
@@ -30,9 +30,9 @@ t: ${PROG}
 	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} -u ${.CURDIR}/../netdiff/f1 ${.CURDIR}/../netdiff/f2 > 003.out
 	diff 003.expected 003.out
 	rm -f 003.out
-	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} /usr/src/sbin /d/thinfs-src/sbin > 004.out
-	diff 004.expected 004.out
-	rm -f 004.out
+	#-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} /usr/src/sbin /d/thinfs-src/sbin > 004.out
+	#diff 004.expected 004.out
+	#rm -f 004.out
 	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} ${.CURDIR}/../netdiff/Makefile ${.CURDIR}/../netdiff/Makefile > 005.out
 	diff 005.expected 005.out
 	rm -f 005.out

Index: othersrc/external/bsd/netdiff/dist/diff.c
diff -u othersrc/external/bsd/netdiff/dist/diff.c:1.3 othersrc/external/bsd/netdiff/dist/diff.c:1.4
--- othersrc/external/bsd/netdiff/dist/diff.c:1.3	Sat Jan 12 01:31:21 2013
+++ othersrc/external/bsd/netdiff/dist/diff.c	Sun Jan 13 22:17:22 2013
@@ -274,9 +274,9 @@ push_excludes(diff_t *diff, char *patter
 static int
 read_excludes_file(diff_t *diff, char *file)
 {
-	FILE	*fp;
-	char	*buf, *pattern;
 	size_t	 len;
+	FILE	*fp;
+	char	*buf;
 
 	if (strcmp(file, "-") == 0) {
 		fp = stdin;
@@ -288,7 +288,7 @@ read_excludes_file(diff_t *diff, char *f
 		if (buf[len - 1] == '\n') {
 			len--;
 		}
-		if (!push_excludes(diff, pattern, len)) {
+		if (!push_excludes(diff, buf, len)) {
 			return 0;
 		}
 	}
Index: othersrc/external/bsd/netdiff/dist/diffreg.c
diff -u othersrc/external/bsd/netdiff/dist/diffreg.c:1.3 othersrc/external/bsd/netdiff/dist/diffreg.c:1.4
--- othersrc/external/bsd/netdiff/dist/diffreg.c:1.3	Sat Jan 12 01:31:21 2013
+++ othersrc/external/bsd/netdiff/dist/diffreg.c	Sun Jan 13 22:17:22 2013
@@ -1995,6 +1995,207 @@ closem:
 	return rval;
 }
 
+/*********************** word diff/wdiff ************************/
+
+/* struct which describes a file to diff for word diffs */
+typedef struct wordfile_t {
+	FILE	*fp;		/* file pointer  */
+	char	*name;		/* file name */
+	char	*file;		/* contents of the file */
+	size_t	 filesize;	/* # of bytes in file */
+	int	 mapped;	/* memory was mmap'ed */
+	char	*splitwords;	/* file split into a single word per line */
+	size_t	 splitwordscc;	/* # of chars in splitwords */
+	size_t	 totwords;	/* total number of words */
+	char	*p;		/* runtime - pointer to offset in file */
+	size_t	 wordc;		/* runtime - word count */
+} wordfile_t;
+
+/* mmap the file */
+static int
+mapfile(wordfile_t *f, const char *name)
+{
+	struct stat	 st;
+
+	if ((f->fp = fopen(name, "r")) == NULL) {
+		warn("can't open '%s'", name);
+		return 0;
+	}
+	f->name = strdup(name);
+	fstat(fileno(f->fp), &st);
+	f->filesize = (size_t)st.st_size;
+	f->file = mmap(NULL, f->filesize, PROT_READ, MAP_SHARED, fileno(f->fp), 0);
+	if (f->file == MAP_FAILED) {
+		warn("can't mmap '%s'", name);
+		fclose(f->fp);
+		return 0;
+	}
+	f->mapped = 1;
+	return 1;
+}
+
+/* split file into words */
+static int
+splitfile(wordfile_t *f)
+{
+	char		*p;
+	int		 prevspace;
+	int		 inspace;
+
+	if ((f->splitwords = calloc(1, f->filesize)) == NULL) {
+		warn("can't allocate '%s'", f->name);
+		munmap(f->file, f->filesize);
+		fclose(f->fp);
+		return 0;
+	}
+	for (p = f->p = f->file, prevspace = 1 ; (size_t)(p - f->file) < f->filesize ; p++) {
+		if ((inspace = isspace((uint8_t)*p)) && !prevspace) {
+			f->splitwords[f->splitwordscc++] = '\n';
+			f->totwords += 1;
+		} else if (!inspace) {
+			f->splitwords[f->splitwordscc++] = *p;
+		}
+		prevspace = inspace;
+	}
+	return 1;
+}
+
+/* skip input from netdiff(1) */
+static char *
+inputskip(char *d, long *in, char type)
+{
+	long	n;
+	long	i;
+
+	n = in[1] - in[0] + in[3] - in[2] + 1 + 1;
+	if (type == 'c') {
+		n += 2;
+	}
+	for (i = 0 ; i < n ; ) {
+		if (*d++ == '\n') {
+			i += 1;
+		}
+	}
+	return d;
+}
+
+/* copy until finished */
+static int
+copy(FILE *fp, wordfile_t *f, int copyspace)
+{
+	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);
+		}
+	}
+	return 1;
+}
+
+/* print words */
+static int
+pwords(FILE *fp, wordfile_t *f, long words, const char *head, const char *tail)
+{
+	const int	copyspace = 1;
+	const int	copyword = 0;
+	long		i;
+
+	for (i = 0 ; i < words ; i++) {
+		copy(fp, f, copyspace);
+		if (i == 0 && head && fp) {
+			fprintf(fp, "%s", head);
+		}
+		copy(fp, f, copyword);
+		f->wordc += 1;
+	}
+	if (tail && fp) {
+		fprintf(fp, "%s", tail);
+	}
+	return 1;
+}
+
+#define WDIFF_COMMON_DELIM \
+	"======================================================================"
+
+/* get the diffs, and print them as part of the original */
+static int
+pdiffs(diff_t *diff, wordfile_t *f, char *diffs)
+{
+	regmatch_t	 match[10];
+	regex_t		 r;
+	long		 in[4];
+	char		*d;
+	char		 type;
+	FILE		*lhs;
+	FILE		*rhs;
+	FILE		*common;
+
+	lhs = (diff->inhibit == 1) ? NULL : stdout;
+	rhs = (diff->inhibit == 2) ? NULL : stdout;
+	common = (diff->inhibit == 3) ? NULL : stdout;
+	regcomp(&r, "^([0-9]+)(,([0-9]+))?([acd])([0-9]+)(,([0-9]+))?", REG_EXTENDED);
+	for (d = diffs; regexec(&r, d, 10, match, 0) == 0 ; ) {
+		/* parse the diff */
+		in[0] = strtol(&d[match[1].rm_so], NULL, 0);
+		in[1] = (match[3].rm_so >= 0) ? strtol(&d[match[3].rm_so], NULL, 0) : in[0];
+		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, 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, NULL);
+		switch(type) {
+		case 'a':
+			if (f->p != f->file) {
+				pwords(common, &f[0], 1, NULL, NULL);
+			}
+			pwords(rhs, &f[1], in[3] - in[2] + 1, "{+", "+}");
+			if (rhs && common && in[0] == 0) {
+				fprintf(rhs, "\n");
+			}
+			break;
+		case 'c':
+			pwords(lhs, &f[0], in[1] - in[0] + 1, "[-", "-]");
+			pwords(rhs, &f[1], in[3] - in[2] + 1, "{+", "+}");
+			break;
+		case 'd':
+			pwords(lhs, &f[0], in[1] - in[0] + 1, "[-", "-]");
+			break;
+		default:
+			break;
+		}
+		/* move d to correct place in diffs */
+		d = inputskip(d, in, type);
+	}
+	if (diff->inhibit == 3) {
+		fprintf(stdout, "\n%s", WDIFF_COMMON_DELIM);
+	}
+	pwords(common, &f[0], (long)(f[0].totwords - f[0].wordc), NULL, NULL);
+	/* copy trailing whitespace */
+	copy(stdout, &f[0], 1);
+	return 1;
+}
+
+/* free resources */
+static void
+cleanup(diff_t *diff, wordfile_t *f)
+{
+	int	i;
+
+	for (i = 0 ; i < 2 ; i++) {
+		if (f[i].mapped) {
+			munmap(f[i].file, f[i].filesize);
+		}
+		free(f[i].splitwords);
+		free(f[i].name);
+	}
+	diff_fini(diff);
+}
+
+/*******************************************************************/
+
 /* compare two regular files */
 int
 diff_file(diff_t *diff, const char *ofile1, const char *ofile2, int flags)
@@ -2082,3 +2283,73 @@ diff_mem(diff_t *diff, const char *m1, s
 	setupmem(&f[1], &diff->st[1], m2, size2);
 	return diffit(diff, f, &s, flags, 0);
 }
+
+/* word diff two files */
+int
+wdiff_file(diff_t *diff, const char *f1, const char *f2)
+{
+	wordfile_t	 wdf[2];
+	diff_t		 local;
+	size_t		 cc;
+	char		*diffs;
+
+	if (diff == NULL || f1 == NULL || f2 == NULL) {
+		return 0;
+	}
+	memset(&wdf, 0x0, sizeof(wdf));
+	memset(&local, 0x0, sizeof(local));
+	local.fp = stdout;
+	local.inhibit = diff->inhibit;
+	diff_set_var(&local, "format", "normal");
+	diff_set_var(&local, "output", "[dynamic]");
+	if (!mapfile(&wdf[0], f1)) {
+		return 0;
+	}
+	splitfile(&wdf[0]);
+	if (!mapfile(&wdf[1], f2)) {
+		return 0;
+	}
+	splitfile(&wdf[1]);
+	diff_mem(&local, wdf[0].splitwords, wdf[0].splitwordscc, wdf[1].splitwords, wdf[1].splitwordscc, 0);
+	if (!diff_get_diffs(&local, &diffs, &cc)) {
+		return 0;
+	}
+	pdiffs(diff, wdf, diffs);
+	cleanup(&local, wdf);
+	return 1;
+}
+
+/* word diff two areas of memory */
+int
+wdiff_mem(diff_t *diff, const char *m1, size_t size1, const char *m2, size_t size2)
+{
+	wordfile_t	 wdf[2];
+	diff_t		 local;
+	size_t		 cc;
+	char		*diffs;
+
+	if (diff == NULL || m1 == NULL || m2 == NULL) {
+		return 0;
+	}
+	memset(&wdf, 0x0, sizeof(wdf));
+	memset(&local, 0x0, sizeof(local));
+	local.fp = stdout;
+	local.inhibit = diff->inhibit;
+	diff_set_var(&local, "format", "normal");
+	diff_set_var(&local, "output", "[dynamic]");
+	wdf[0].name = strdup("lhs");
+	wdf[1].name = strdup("rhs");
+	wdf[0].file = __UNCONST(m1);
+	wdf[0].filesize = size1;
+	wdf[1].file = __UNCONST(m2);
+	wdf[1].filesize = size2;
+	splitfile(&wdf[0]);
+	splitfile(&wdf[1]);
+	diff_mem(&local, wdf[0].splitwords, wdf[0].splitwordscc, wdf[1].splitwords, wdf[1].splitwordscc, 0);
+	if (!diff_get_diffs(&local, &diffs, &cc)) {
+		return 0;
+	}
+	pdiffs(diff, wdf, diffs);
+	cleanup(&local, wdf);
+	return 1;
+}
Index: othersrc/external/bsd/netdiff/dist/libnetdiff.3
diff -u othersrc/external/bsd/netdiff/dist/libnetdiff.3:1.3 othersrc/external/bsd/netdiff/dist/libnetdiff.3:1.4
--- othersrc/external/bsd/netdiff/dist/libnetdiff.3:1.3	Sat Jan 12 01:31:21 2013
+++ othersrc/external/bsd/netdiff/dist/libnetdiff.3	Sun Jan 13 22:17:22 2013
@@ -1,4 +1,4 @@
-.\" $NetBSD: libnetdiff.3,v 1.3 2013/01/12 01:31:21 agc Exp $
+.\" $NetBSD: libnetdiff.3,v 1.4 2013/01/13 22:17:22 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 11, 2013
+.Dd January 7, 2013
 .Dt LIBNETDIFF 3
 .Os
 .Sh NAME
@@ -74,6 +74,17 @@
 .Fo difference
 .Fa "diff_t *diff" "char *file1" "char *file2"
 .Fc
+.Pp
+Word difference functions are also provided
+.Ft int
+.Fo wdiff_file
+.Fa "diff_t *diff" "const char *file1" "const char *file2"
+.Fc
+.Ft int
+.Fo wdiff_mem
+.Fa "diff_t *diff" "const char *mem1" "size_t size1" "const char *mem2"
+.Fa "size_t size2"
+.Fc
 .Sh DESCRIPTION
 The
 .Nm
@@ -126,26 +137,26 @@ If an output buffer has been allocated, 
 in that buffer, and they can be read using the
 .Fn diff_get_diffs
 function.
+If neither an output file or an output buffer have been specified,
+the output will be sent to
+.Dv stdout .
+.Pp
 To specify an output buffer, and thus enable
 .Fn diff_get_diffs
 to function properly, there must be a call to
 .Bd -literal -offset indent
-diff_t	diff;
+diff_t diff;
 
 diff_set_var(\*[Am]diff, "output", "[dynamic]");
 .Ed
 .Pp
 prior to calling any difference function.
-If neither an output file or an output buffer have been specified,
-the output will be sent to
-.Dv stdout .
 .Pp
 It is also possible, but not usual, to directly call the regular file
 comparison function
 .Fn diff_file
 and the directory comparison function
 .Fn diff_dir .
-.Pp
 One exception to this is the
 .Fn diff_mem
 function, which allows two areas of memory, denoted by the
@@ -162,6 +173,17 @@ For this function, the
 timestamps on any output will be the time of execution of the
 comparison.
 .Pp
+Word comparison functions are similar:
+.Fn wdiff_file
+is used to compare two files on a word-by-word basis, whilst
+.Fn wdiff_mem
+is used to compare two areas of memory.
+Results can be displayed on
+.Dv stdout
+or retrieved by using the
+.Fn diff_get_diffs
+in the usual way.
+.Pp
 Finally, resources can be freed using the
 .Fn diff_fini
 function.

Index: othersrc/external/bsd/netdiff/dist/diff_subr.c
diff -u othersrc/external/bsd/netdiff/dist/diff_subr.c:1.4 othersrc/external/bsd/netdiff/dist/diff_subr.c:1.5
--- othersrc/external/bsd/netdiff/dist/diff_subr.c:1.4	Sat Jan 12 01:31:21 2013
+++ othersrc/external/bsd/netdiff/dist/diff_subr.c	Sun Jan 13 22:17:22 2013
@@ -336,6 +336,20 @@ diff_set_var(diff_t *diff, const char *k
 			}
 		}
 	}
+	if (strcasecmp(key, "inhibit") == 0) {
+		if (strcasecmp(value, "lhs") == 0) {
+			diff->inhibit = 1;
+			return 1;
+		}
+		if (strcasecmp(value, "rhs") == 0) {
+			diff->inhibit = 2;
+			return 1;
+		}
+		if (strcasecmp(value, "common") == 0) {
+			diff->inhibit = 3;
+			return 1;
+		}
+	}
 	return 1;
 }
 

Index: othersrc/external/bsd/netdiff/dist/netdiff.h
diff -u othersrc/external/bsd/netdiff/dist/netdiff.h:1.2 othersrc/external/bsd/netdiff/dist/netdiff.h:1.3
--- othersrc/external/bsd/netdiff/dist/netdiff.h:1.2	Sat Jan 12 01:31:21 2013
+++ othersrc/external/bsd/netdiff/dist/netdiff.h	Sun Jan 13 22:17:22 2013
@@ -56,6 +56,7 @@ typedef struct diff_t {
 	int	 	  Fromflag;
 	int		  Toflag;
 	const char	 *optfile;
+	int		  inhibit;	/* for word diff */
 } diff_t;
 
 diff_t	*diff_init(void);
@@ -69,4 +70,7 @@ int	diff_fini(diff_t */*diff*/);
 int	diff_get_diffs(diff_t */*diff*/, char **/*ptr*/, size_t */*size*/);
 int	difference(diff_t */*diff*/, char */*file1*/, char */*file2*/);
 
+int	wdiff_file(diff_t */*diff*/, const char */*f1*/, const char */*f2*/);
+int	wdiff_mem(diff_t */*diff*/, const char */*m1*/, size_t /*size1*/, const char */*m2*/, size_t /*size2*/);
+
 #endif

Index: othersrc/external/bsd/netdiff/lib/Makefile
diff -u othersrc/external/bsd/netdiff/lib/Makefile:1.1.1.1 othersrc/external/bsd/netdiff/lib/Makefile:1.2
--- othersrc/external/bsd/netdiff/lib/Makefile:1.1.1.1	Thu Jan 10 08:17:11 2013
+++ othersrc/external/bsd/netdiff/lib/Makefile	Sun Jan 13 22:17:22 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1.1.1 2013/01/10 08:17:11 agc Exp $
+# $NetBSD: Makefile,v 1.2 2013/01/13 22:17:22 agc Exp $
 
 LIB=netdiff
 

Added files:

Index: othersrc/external/bsd/netdiff/bin/wdiff/Makefile
diff -u /dev/null othersrc/external/bsd/netdiff/bin/wdiff/Makefile:1.1
--- /dev/null	Sun Jan 13 22:17:22 2013
+++ othersrc/external/bsd/netdiff/bin/wdiff/Makefile	Sun Jan 13 22:17:22 2013
@@ -0,0 +1,39 @@
+# $NetBSD: Makefile,v 1.1 2013/01/13 22:17:22 agc Exp $
+
+.include <bsd.own.mk>
+
+PROG=netwdiff
+SRCS=netwdiff.c
+CPPFLAGS+=-I${DIST}
+
+LIB_NETDIFF_DIR!=	cd ${.CURDIR}/../../lib && ${PRINTOBJDIR}
+LDADD+=		-L${LIB_NETDIFF_DIR} -lnetdiff
+DPADD+=		${LIB_NETDIFF_DIR}/libnetdiff.a
+
+WARNS=5
+MAN=netwdiff.1
+
+DIST=${.CURDIR}/../../dist
+.PATH: ${DIST}
+
+BINDIR=/usr/bin
+
+.include <bsd.prog.mk>
+
+t: ${PROG}
+	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} f1 f2 > netwdiff.out
+	-wdiff f1 f2 > wdiff.out
+	-netdiff wdiff.out netwdiff.out
+	rm -f wdiff.out netwdiff.out
+	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} -1 f1 f2 > netwdiff.out
+	-wdiff -1 f1 f2 > wdiff.out
+	-netdiff wdiff.out netwdiff.out
+	rm -f wdiff.out netwdiff.out
+	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} -2 f1 f2 > netwdiff.out
+	-wdiff -2 f1 f2 > wdiff.out
+	-netdiff wdiff.out netwdiff.out
+	rm -f wdiff.out netwdiff.out
+	-env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} -3 f1 f2 > netwdiff.out
+	-wdiff -3 f1 f2 > wdiff.out
+	-netdiff wdiff.out netwdiff.out
+	rm -f wdiff.out netwdiff.out
Index: othersrc/external/bsd/netdiff/bin/wdiff/f1
diff -u /dev/null othersrc/external/bsd/netdiff/bin/wdiff/f1:1.1
--- /dev/null	Sun Jan 13 22:17:22 2013
+++ othersrc/external/bsd/netdiff/bin/wdiff/f1	Sun Jan 13 22:17:22 2013
@@ -0,0 +1,75 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include <err.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+// bufgap
+
+typedef struct f_t {
+	char	*name;
+	char	*mapped;
+	FILE	*fp;
+	size_t	 size;
+} f_t;
+
+static int
+finit(f_t *file, const char *name)
+{
+	struct stat	st;
+
+	memset(file, 0x0, sizeof(*file));
+	if ((file->fp = fopen(name, "r")) == NULL) {
+		return 0;
+	}
+	fstat(fileno(file->fp), &st);
+	file->size = st.st_size;
+	file->mapped = mmap(NULL, file->size, PROT_READ, MAP_SHARED, fileno(file->fp), 0);
+	// xxx
+	file->name = strdup(name);
+	return 1;
+}
+
+static void
+fend(f_t *f)
+{
+	free(f->name);
+	munmap(f->mapped, f->size);
+	fclose(f->fp);
+	memset(f, 0x0, sizeof(*f));
+}
+
+static int
+diff(const char *filename1, const char *filename2)
+{
+	FILE	*pp;
+	char	 buf[2048]; // XXX
+	char	 cmd[2048]; // XXX
+	f_t	 f[2];
+
+	finit(&f[0], filename1);
+	finit(&f[1], filename2);
+	snprintf(cmd, sizeof(cmd), "diff %s %s", filename1, filename2);
+	if ((pp = popen(cmd, "r")) == NULL) {
+		return 0;
+	}
+	while (fgets(buf, sizeof(buf), pp) != NULL) {
+		printf("%s", buf);
+	}
+	pclose(pp);
+	fend(&f[0]);
+	fend(&f[1]);
+	return 1;
+}
+
+int
+main(int argc, char **argv)
+{
+	diff(argv[optind], argv[optind + 1]);
+	exit(EXIT_SUCCESS);
+}
Index: othersrc/external/bsd/netdiff/bin/wdiff/f2
diff -u /dev/null othersrc/external/bsd/netdiff/bin/wdiff/f2:1.1
--- /dev/null	Sun Jan 13 22:17:22 2013
+++ othersrc/external/bsd/netdiff/bin/wdiff/f2	Sun Jan 13 22:17:22 2013
@@ -0,0 +1,114 @@
+/*-
+ * Copyright (c) 2013 Alistair Crooks <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include <err.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+typedef struct f_t {
+	char	*name;
+	char	*mapped;
+	FILE	*fp;
+	size_t	 size;
+} f_t;
+
+static int
+finit(f_t *file, const char *name)
+{
+	struct stat	st;
+
+	memset(file, 0x0, sizeof(*file));
+	if ((file->fp = fopen(name, "r")) == NULL) {
+		return 0;
+	}
+	fstat(fileno(file->fp), &st);
+	file->size = st.st_size;
+	file->mapped = mmap(NULL, file->size, PROT_READ, MAP_SHARED, fileno(file->fp), 0);
+	if (file->mapped == MAP_FAILED) {
+		return 0;
+	}
+	file->name = strdup(name);
+	return 1;
+}
+
+static void
+fend(f_t *f)
+{
+	free(f->name);
+	munmap(f->mapped, f->size);
+	fclose(f->fp);
+	memset(f, 0x0, sizeof(*f));
+}
+
+static int
+difffile(const char *filename1, const char *filename2)
+{
+	FILE	*pp;
+	char	 buf[2048]; // XXX
+	char	 cmd[2048]; // XXX
+	f_t	 f[2];
+
+	finit(&f[0], filename1);
+	finit(&f[1], filename2);
+	snprintf(cmd, sizeof(cmd), "diff %s %s", filename1, filename2);
+	if ((pp = popen(cmd, "r")) == NULL) {
+		return 0;
+	}
+	while (fgets(buf, sizeof(buf), pp) != NULL) {
+		printf("%s", buf);
+	}
+	pclose(pp);
+	fend(&f[0]);
+	fend(&f[1]);
+	return 1;
+}
+
+/*
+a long and interesting comment.
+
+multiple lines.
+
+very informative
+*/
+
+int
+main(int argc, char **argv)
+{
+	int	i;
+
+	while ((i = getopt(argc, argv, "")) != -1) {
+	}
+	if (argc - optind < 2) {
+		errx(EXIT_FAILURE, "Usage: agcdiff file1 file2");
+	}
+	difffile(argv[optind], argv[optind + 1]);
+	exit(EXIT_SUCCESS);
+}

Index: othersrc/external/bsd/netdiff/dist/netwdiff.1
diff -u /dev/null othersrc/external/bsd/netdiff/dist/netwdiff.1:1.1
--- /dev/null	Sun Jan 13 22:17:22 2013
+++ othersrc/external/bsd/netdiff/dist/netwdiff.1	Sun Jan 13 22:17:22 2013
@@ -0,0 +1,118 @@
+.\" $NetBSD: netwdiff.1,v 1.1 2013/01/13 22:17:22 agc Exp $
+.\"
+.\" Copyright (c) 2013 Alistair Crooks <[email protected]>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (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 13, 2013
+.Dt NETWDIFF 1
+.Os
+.Sh NAME
+.Nm netwdiff
+.Nd Word-based difference and comparison program
+.Sh SYNOPSIS
+.Nm
+.Op Fl 123i
+.Ar file1 file2
+.Sh DESCRIPTION
+The
+.Nm
+command performs a word-based difference and comparison on the
+two files given as input.
+For each difference, deleted text is prefixed with a
+.Da [-
+and ended with a
+.Dq -]
+pattern.
+Text which has been added is prefixed with a
+.Dq {+
+pattern, and ends with a
+.Dq +}
+pattern.
+Changes are interleaved, making it easier to see changes made
+within the line differences reported by
+.Xr netdiff 1 .
+.Pp
+The
+.Nm
+utility uses the
+.Xr libnetdiff 3
+library.
+.Pp
+The following options are available:
+.Bl -tag -width sector-size123
+.It Fl 1
+Inhibit the display of text which has been deleted.
+.It Fl 2
+Inhibit the display of text which has been added.
+.It Fl 3
+Inhibit the display of text common to both files, which
+means that only the changes will be displayed.
+.It Fl i
+Perform comparisons in a case-insensitive manner.
+.El
+.Sh RETURN VALUES
+The
+.Nm
+utility will return 0 for success,
+and 1 for failure.
+.Sh EXAMPLES
+.Bd -literal
+% netwdiff f1 f2
+
+static int
+[-diff(const-]
+{+difffile(const+} char *filename1, const char *filename2)
+{
+
+% netwdiff -1 f1 f2
+static int
+{+difffile(const+} char *filename1, const char *filename2)
+{
+
+% netwdiff -2 f1 f2
+
+static int
+[-diff(const-] char *filename1, const char *filename2)
+{
+
+% netwdiff -3 f1 f2
+
+======================================================================
+
+[-diff(const-]
+{+difffile(const+}
+======================================================================
+
+%
+.Ed
+.Sh SEE ALSO
+.Xr netdiff 1 ,
+.Xr libnetdiff 3
+.Sh HISTORY
+The
+.Nm
+command first appeared in
+.Nx 7.0 .
+.Sh AUTHORS
+.An -nosplit
+.An Alistair Crooks Aq [email protected]
Index: othersrc/external/bsd/netdiff/dist/netwdiff.c
diff -u /dev/null othersrc/external/bsd/netdiff/dist/netwdiff.c:1.1
--- /dev/null	Sun Jan 13 22:17:22 2013
+++ othersrc/external/bsd/netdiff/dist/netwdiff.c	Sun Jan 13 22:17:22 2013
@@ -0,0 +1,62 @@
+/*-
+ * Copyright (c) 2013 Alistair Crooks <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "netdiff.h"
+
+int
+main(int argc, char **argv)
+{
+	diff_t	diff;
+	int	i;
+
+	memset(&diff, 0x0, sizeof(diff));
+	diff_set_var(&diff, "format", "normal");
+	diff_set_var(&diff, "output", "[dynamic]");
+	while ((i = getopt(argc, argv, "123i")) != -1) {
+		switch(i) {
+		case '1':
+			diff_set_var(&diff, "inhibit", "lhs");
+			break;
+		case '2':
+			diff_set_var(&diff, "inhibit", "rhs");
+			break;
+		case '3':
+			diff_set_var(&diff, "inhibit", "common");
+			break;
+		case 'i':
+			diff_set_flag(&diff, i);
+			break;
+		default:
+			break;
+		}
+	}
+	wdiff_file(&diff, argv[optind], argv[optind + 1]);
+	exit(diff.status);
+}

Reply via email to