Module Name: othersrc Committed By: agc Date: Tue Jan 15 01:49:23 UTC 2013
Modified Files: othersrc/external/bsd/netdiff/bin: Makefile Added Files: othersrc/external/bsd/netdiff/bin/cmp: Makefile f1 f2 othersrc/external/bsd/netdiff/dist: cmp.c Log Message: Add rudimentary support for cmp(1) in the shape of netcmp(1). More to come on this one, too. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 othersrc/external/bsd/netdiff/bin/Makefile cvs rdiff -u -r0 -r1.1 othersrc/external/bsd/netdiff/bin/cmp/Makefile \ othersrc/external/bsd/netdiff/bin/cmp/f1 \ othersrc/external/bsd/netdiff/bin/cmp/f2 cvs rdiff -u -r0 -r1.1 othersrc/external/bsd/netdiff/dist/cmp.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/Makefile diff -u othersrc/external/bsd/netdiff/bin/Makefile:1.4 othersrc/external/bsd/netdiff/bin/Makefile:1.5 --- othersrc/external/bsd/netdiff/bin/Makefile:1.4 Tue Jan 15 01:46:03 2013 +++ othersrc/external/bsd/netdiff/bin/Makefile Tue Jan 15 01:49:23 2013 @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.4 2013/01/15 01:46:03 agc Exp $ +# $NetBSD: Makefile,v 1.5 2013/01/15 01:49:23 agc Exp $ SUBDIR= netdiff SUBDIR+= wdiff -SUBDIR+= cmp .if !make(install) +SUBDIR+= cmp SUBDIR+= memdiff SUBDIR+= qdiff .endif Added files: Index: othersrc/external/bsd/netdiff/bin/cmp/Makefile diff -u /dev/null othersrc/external/bsd/netdiff/bin/cmp/Makefile:1.1 --- /dev/null Tue Jan 15 01:49:23 2013 +++ othersrc/external/bsd/netdiff/bin/cmp/Makefile Tue Jan 15 01:49:23 2013 @@ -0,0 +1,36 @@ +# $NetBSD: Makefile,v 1.1 2013/01/15 01:49:23 agc Exp $ + +.include <bsd.own.mk> + +PROG=netcmp +SRCS=cmp.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 +MKMAN=no + +DIST=${.CURDIR}/../../dist +.PATH: ${DIST} + +BINDIR=/usr/bin + +.include <bsd.prog.mk> + +t: ${PROG} + -env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} f1 f2 > netcmp.out + -cmp f1 f2 > cmp.out + -netdiff cmp.out netcmp.out + rm -f cmp.out netcmp.out + -env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} -l f1 f2 > netcmp.out + -cmp -l f1 f2 > cmp.out + -netdiff cmp.out netcmp.out + rm -f cmp.out netcmp.out + -env LD_LIBRARY_PATH=${LIB_NETDIFF_DIR} ./${PROG} -i f1 f2 > netcmp.out + -cmp f1 f2 > cmp.out + -netdiff cmp.out netcmp.out + rm -f cmp.out netcmp.out Index: othersrc/external/bsd/netdiff/bin/cmp/f1 diff -u /dev/null othersrc/external/bsd/netdiff/bin/cmp/f1:1.1 --- /dev/null Tue Jan 15 01:49:23 2013 +++ othersrc/external/bsd/netdiff/bin/cmp/f1 Tue Jan 15 01:49:23 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/cmp/f2 diff -u /dev/null othersrc/external/bsd/netdiff/bin/cmp/f2:1.1 --- /dev/null Tue Jan 15 01:49:23 2013 +++ othersrc/external/bsd/netdiff/bin/cmp/f2 Tue Jan 15 01:49:23 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/dist/cmp.c diff -u /dev/null othersrc/external/bsd/netdiff/dist/cmp.c:1.1 --- /dev/null Tue Jan 15 01:49:23 2013 +++ othersrc/external/bsd/netdiff/dist/cmp.c Tue Jan 15 01:49:23 2013 @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2013 Alistair Crooks <a...@netbsd.org> + * 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; + size_t cc; + char *s; + int i; + + memset(&diff, 0x0, sizeof(diff)); + diff_set_var(&diff, "format", "normal"); + diff_set_var(&diff, "output", "[dynamic]"); + while ((i = getopt(argc, argv, "il")) != -1) { + switch(i) { + case 'i': + case 'l': + diff_set_flag(&diff, i); + break; + default: + break; + } + } + cmp_file(&diff, argv[optind], argv[optind + 1], 0); + if (diff_get_diffs(&diff, &s, &cc)) { + printf("%.*s", (int)cc, s); + } + exit(diff.status); +}