diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2005-10-06 02:00:06 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2005-10-06 02:00:06 +0000 |
commit | d0dfff088dcf2a23e83f1e94a6f1e9068b8c6409 (patch) | |
tree | a0de02bcf8befbdafecee2f76dccd60a608a4ed7 /usr.bin | |
parent | be4263efc565971051f57fa3fdcd828dbff74ec1 (diff) |
rcsclean now works;
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rcs/Makefile | 5 | ||||
-rw-r--r-- | usr.bin/rcs/rcsclean.c | 156 | ||||
-rw-r--r-- | usr.bin/rcs/rcsprog.c | 9 | ||||
-rw-r--r-- | usr.bin/rcs/rcsprog.h | 4 |
4 files changed, 167 insertions, 7 deletions
diff --git a/usr.bin/rcs/Makefile b/usr.bin/rcs/Makefile index fad192e257c..b1852d3a845 100644 --- a/usr.bin/rcs/Makefile +++ b/usr.bin/rcs/Makefile @@ -1,11 +1,12 @@ -# $OpenBSD: Makefile,v 1.9 2005/10/06 01:24:25 joris Exp $ +# $OpenBSD: Makefile,v 1.10 2005/10/06 02:00:04 joris Exp $ .PATH: ${.CURDIR}/../cvs PROG= rcs MAN= rcs.1 -SRCS= ci.c co.c rcsdiff.c rcsprog.c buf.c diff.c log.c rcs.c rcsnum.c strtab.c +SRCS= ci.c co.c rcsclean.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/rcsclean.c b/usr.bin/rcs/rcsclean.c new file mode 100644 index 00000000000..b31e90f04e1 --- /dev/null +++ b/usr.bin/rcs/rcsclean.c @@ -0,0 +1,156 @@ +/* $OpenBSD: rcsclean.c,v 1.1 2005/10/06 02:00:05 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 <dirent.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 rcsclean_file(char *, RCSNUM *); + +int +rcsclean_main(int argc, char **argv) +{ + int i, ch; + RCSNUM *rev; + DIR *dirp; + struct dirent *dp; + + 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) { + if ((dirp = opendir(".")) == NULL) { + cvs_log(LP_ERRNO, "failed to open directory '.'"); + (usage)(); + exit(1); + } + + while ((dp = readdir(dirp)) != NULL) { + if (dp->d_type == DT_DIR) + continue; + rcsclean_file(dp->d_name, rev); + } + + closedir(dirp); + } else { + for (i = 0; i < argc; i++) + rcsclean_file(argv[i], rev); + } + + return (0); +} + +void +rcsclean_usage(void) +{ + fprintf(stderr, "usage %s [file] ...\n", __progname); +} + +static int +rcsclean_file(char *fname, RCSNUM *rev) +{ + int match; + RCSFILE *file; + char fpath[MAXPATHLEN]; + RCSNUM *frev; + BUF *b1, *b2; + char *s1, *s2, *c1, *c2; + + match = 1; + if (rcs_statfile(fname, fpath, sizeof(fpath)) < 0) + return (-1); + + if ((file = rcs_open(fpath, RCS_RDWR)) == NULL) + return (-1); + + if (rev == RCS_HEAD_REV) + frev = file->rf_head; + else + frev = rev; + + if ((b1 = rcs_getrev(file, frev)) == NULL) { + cvs_log(LP_ERR, "failed to get needed revision"); + rcs_close(file); + return (-1); + } + + if ((b2 = cvs_buf_load(fname, BUF_AUTOEXT)) == NULL) { + cvs_log(LP_ERRNO, "failed to load '%s'", fname); + rcs_close(file); + return (-1); + } + + cvs_buf_putc(b1, '\0'); + cvs_buf_putc(b2, '\0'); + + c1 = cvs_buf_release(b1); + c2 = cvs_buf_release(b2); + + for (s1 = c1, s2 = c2; *s1 && *s2; *s1++, *s2++) { + if (*s1 != *s2) { + match = 0; + break; + } + } + + free(c1); + free(c2); + + if (match) { + if (verbose) + printf("rm -f %s\n", fname); + (void)unlink(fname); + } + + rcs_close(file); + return (0); +} diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c index ade7b00e616..ddd7bdcaca7 100644 --- a/usr.bin/rcs/rcsprog.c +++ b/usr.bin/rcs/rcsprog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.c,v 1.19 2005/10/06 01:26:12 joris Exp $ */ +/* $OpenBSD: rcsprog.c,v 1.20 2005/10/06 02:00:05 joris Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -54,7 +54,7 @@ struct rcs_prog { { "rcs", rcs_main, rcs_usage }, { "ci", checkin_main, checkin_usage }, { "co", checkout_main, checkout_usage }, - { "rcsclean", NULL, NULL }, + { "rcsclean", rcsclean_main, rcsclean_usage }, { "rcsdiff", rcsdiff_main, rcsdiff_usage }, { "ident", NULL, NULL }, }; @@ -80,12 +80,13 @@ rcs_statfile(char *fname, char *out, size_t len) } if (stat(fpath, &st) == -1) { - cvs_log(LP_ERRNO, "%s", fpath); + if (strcmp(__progname, "rcsclean")) + cvs_log(LP_ERRNO, "%s", fpath); return (-1); } strlcpy(out, fpath, len); - if (verbose == 1) { + if (verbose == 1 && strcmp(__progname, "rcsclean")) { if (!strcmp(__progname, "co")) { printf("%s --> ", fpath); if ((s = strrchr(filev, ',')) != NULL) { diff --git a/usr.bin/rcs/rcsprog.h b/usr.bin/rcs/rcsprog.h index c0adab5d629..9d07837686a 100644 --- a/usr.bin/rcs/rcsprog.h +++ b/usr.bin/rcs/rcsprog.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.h,v 1.5 2005/10/06 01:24:25 joris Exp $ */ +/* $OpenBSD: rcsprog.h,v 1.6 2005/10/06 02:00:05 joris Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -35,6 +35,7 @@ void rcs_usage(void); void checkout_usage(void); void checkin_usage(void); void rcsdiff_usage(void); +void rcsclean_usage(void); void (*usage)(void); int rcs_statfile(char *, char *, size_t); @@ -42,5 +43,6 @@ int checkout_main(int, char **); int checkin_main(int, char **); int rcs_main(int, char **); int rcsdiff_main(int, char **); +int rcsclean_main(int, char **); #endif /* RCSPROG_H */ |