diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2005-10-06 01:24:26 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2005-10-06 01:24:26 +0000 |
commit | 5f599e48497168db2034e53232abdfd5fbdf91fe (patch) | |
tree | 4dd17dc24cd135dba08346d4aba3bdd188a4a018 /usr.bin/rcs | |
parent | 6a3f41515a02ee244a1a378e9e1a5e026356689a (diff) |
thanks to niallo's diff changes, we now can support rcsdiff;
only basic stuff works, more coming;
Diffstat (limited to 'usr.bin/rcs')
-rw-r--r-- | usr.bin/rcs/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/rcs/rcsdiff.c | 152 | ||||
-rw-r--r-- | usr.bin/rcs/rcsprog.c | 4 | ||||
-rw-r--r-- | usr.bin/rcs/rcsprog.h | 4 |
4 files changed, 159 insertions, 5 deletions
diff --git a/usr.bin/rcs/Makefile b/usr.bin/rcs/Makefile index 5c5bd522186..fad192e257c 100644 --- a/usr.bin/rcs/Makefile +++ b/usr.bin/rcs/Makefile @@ -1,11 +1,11 @@ -# $OpenBSD: Makefile,v 1.8 2005/10/05 23:11:15 niallo Exp $ +# $OpenBSD: Makefile,v 1.9 2005/10/06 01:24:25 joris Exp $ .PATH: ${.CURDIR}/../cvs PROG= rcs MAN= rcs.1 -SRCS= ci.c co.c rcsprog.c buf.c diff.c log.c rcs.c rcsnum.c strtab.c +SRCS= ci.c co.c rcsdiff.c rcsprog.c buf.c diff.c log.c rcs.c rcsnum.c strtab.c CFLAGS+=-I${.CURDIR}/../cvs # Don't build the links until we actually support those commands diff --git a/usr.bin/rcs/rcsdiff.c b/usr.bin/rcs/rcsdiff.c new file mode 100644 index 00000000000..067cbb5be4f --- /dev/null +++ b/usr.bin/rcs/rcsdiff.c @@ -0,0 +1,152 @@ +/* $OpenBSD: rcsdiff.c,v 1.1 2005/10/06 01:24:25 joris Exp $ */ +/* + * Copyright (c) 2005 Joris Vink <joris@openbsd.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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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/param.h> +#include <sys/stat.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "diff.h" +#include "log.h" +#include "rcs.h" +#include "rcsprog.h" + +extern char *__progname; +static int rcsdiff_file(RCSFILE *, RCSNUM *, const char *); + +int +rcsdiff_main(int argc, char **argv) +{ + int i, ch; + RCSNUM *rev, *frev; + RCSFILE *file; + char fpath[MAXPATHLEN]; + + rev = RCS_HEAD_REV; + + while ((ch = getopt(argc, argv, "qV")) != -1) { + switch (ch) { + case 'q': + verbose = 0; + break; + case 'V': + printf("%s\n", rcs_version); + exit(0); + default: + break; + } + } + + argc -= optind; + argv += optind; + + if (argc == 0) { + cvs_log(LP_ERR, "no input file"); + (usage)(); + exit(1); + } + + for (i = 0; i < argc; i++) { + if (verbose) + cvs_printf("%s\n", RCS_DIFF_DIV); + + if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0) + continue; + + if ((file = rcs_open(fpath, RCS_READ)) == NULL) + continue; + + if (rev == RCS_HEAD_REV) + frev = file->rf_head; + else + frev = rev; + + if (rcsdiff_file(file, frev, argv[i]) < 0) { + cvs_log(LP_ERR, "failed to rcsdiff"); + rcs_close(file); + continue; + } + + rcs_close(file); + } + + return (0); +} + +void +rcsdiff_usage(void) +{ + fprintf(stderr, "usage %s [-qV] file ...\n", __progname); +} + +static int +rcsdiff_file(RCSFILE *rfp, RCSNUM *rev, const char *filename) +{ + char path1[MAXPATHLEN], path2[MAXPATHLEN]; + BUF *b1, *b2; + char rbuf[64]; + + rcsnum_tostr(rev, rbuf, sizeof(rbuf)); + if (verbose) + printf("retrieving revision %s\n", rbuf); + + if ((b1 = rcs_getrev(rfp, rev)) == NULL) { + cvs_log(LP_ERR, "failed to retrieve revision"); + return (-1); + } + + if ((b2 = cvs_buf_load(filename, BUF_AUTOEXT)) == NULL) { + cvs_log(LP_ERR, "failed to load file: '%s'", filename); + cvs_buf_free(b1); + return (-1); + } + + strlcpy(path1, "/tmp/diff1.XXXXXXXXXX", sizeof(path1)); + if (cvs_buf_write_stmp(b1, path1, 0600) == -1) { + cvs_log(LP_ERRNO, "could not write temporary file"); + cvs_buf_free(b1); + cvs_buf_free(b2); + return (-1); + } + cvs_buf_free(b1); + + strlcpy(path2, "/tmp/diff2.XXXXXXXXXX", sizeof(path2)); + if (cvs_buf_write_stmp(b2, path2, 0600) == -1) { + cvs_buf_free(b2); + (void)unlink(path1); + return (-1); + } + cvs_buf_free(b2); + + cvs_diffreg(path1, path2); + (void)unlink(path1); + (void)unlink(path2); + + return (0); +} diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c index 93c3b5caad5..27babbf7603 100644 --- a/usr.bin/rcs/rcsprog.c +++ b/usr.bin/rcs/rcsprog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.c,v 1.17 2005/09/30 17:34:58 joris Exp $ */ +/* $OpenBSD: rcsprog.c,v 1.18 2005/10/06 01:24:25 joris Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -55,7 +55,7 @@ struct rcs_prog { { "ci", checkin_main, checkin_usage }, { "co", checkout_main, checkout_usage }, { "rcsclean", NULL, NULL }, - { "rcsdiff", NULL, NULL }, + { "rcsdiff", rcsdiff_main, rcsdiff_usage }, { "ident", NULL, NULL }, }; diff --git a/usr.bin/rcs/rcsprog.h b/usr.bin/rcs/rcsprog.h index 989e9607978..c0adab5d629 100644 --- a/usr.bin/rcs/rcsprog.h +++ b/usr.bin/rcs/rcsprog.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.h,v 1.4 2005/10/02 09:39:01 xsa Exp $ */ +/* $OpenBSD: rcsprog.h,v 1.5 2005/10/06 01:24:25 joris Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -34,11 +34,13 @@ extern int verbose; void rcs_usage(void); void checkout_usage(void); void checkin_usage(void); +void rcsdiff_usage(void); void (*usage)(void); int rcs_statfile(char *, char *, size_t); int checkout_main(int, char **); int checkin_main(int, char **); int rcs_main(int, char **); +int rcsdiff_main(int, char **); #endif /* RCSPROG_H */ |