diff options
author | Joris Vink <joris@cvs.openbsd.org> | 2005-09-29 15:13:20 +0000 |
---|---|---|
committer | Joris Vink <joris@cvs.openbsd.org> | 2005-09-29 15:13:20 +0000 |
commit | b3572f321f3153cd3bca7d06466a41fbdb00f212 (patch) | |
tree | 05496521211301407d8c1b071c1bdf1eecddb0a7 /usr.bin/rcs/rcsprog.c | |
parent | b6f01bb3c8a7cccbce5e768a32c994a9f87bff84 (diff) |
- prototypes for the RCS commands go in rcsprog.h
- use rcs_statfile() to obtain the correct path to the RCS file
Diffstat (limited to 'usr.bin/rcs/rcsprog.c')
-rw-r--r-- | usr.bin/rcs/rcsprog.c | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/usr.bin/rcs/rcsprog.c b/usr.bin/rcs/rcsprog.c index c0e9261c105..064146bdf9c 100644 --- a/usr.bin/rcs/rcsprog.c +++ b/usr.bin/rcs/rcsprog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsprog.c,v 1.8 2005/09/29 00:20:22 joris Exp $ */ +/* $OpenBSD: rcsprog.c,v 1.9 2005/09/29 15:13:19 joris Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -40,17 +40,11 @@ #include "log.h" #include "rcs.h" +#include "rcsprog.h" #include "strtab.h" -extern char *__progname; - - const char rcs_version[] = "OpenCVS RCS version 3.6"; -void rcs_usage(void); -int rcs_main(int, char **); -void (*usage)(void); - struct rcs_prog { char *prog_name; int (*prog_hdlr)(int, char **); @@ -64,6 +58,44 @@ struct rcs_prog { { "ident", NULL, NULL }, }; +int +rcs_statfile(char *fname, char *out, size_t len) +{ + int l; + char *s; + char filev[MAXPATHLEN], fpath[MAXPATHLEN]; + struct stat st; + + l = snprintf(filev, sizeof(filev), "%s%s", fname, RCS_FILE_EXT); + if (l == -1 || l >= (int)sizeof(filev)) + return (-1); + + if (stat(RCSDIR, &st) != -1) { + l = snprintf(fpath, sizeof(fpath), "%s/%s", RCSDIR, filev); + if (l == -1 || l >= (int)sizeof(fpath)) + return (-1); + } else { + strlcpy(fpath, filev, sizeof(fpath)); + } + + if (stat(fpath, &st) == -1) { + cvs_log(LP_ERRNO, "%s", fpath); + return (-1); + } + + strlcpy(out, fpath, len); + if (!strcmp(__progname, "co")) { + printf("%s --> ", filev); + if ((s = strrchr(filev, ',')) != NULL) { + *s = '\0'; + printf("%s\n", fname); + } + } else { + printf("RCS file: %s\n", fpath); + } + + return (0); +} int main(int argc, char **argv) @@ -73,6 +105,7 @@ main(int argc, char **argv) ret = -1; cvs_strtab_init(); + cvs_log_init(LD_STD, 0); for (i = 0; i < (sizeof(programs)/sizeof(programs[0])); i++) if (strcmp(__progname, programs[i].prog_name) == 0) { @@ -116,8 +149,6 @@ rcs_main(int argc, char **argv) flags = RCS_RDWR; oldfile = alist = comment = elist = NULL; - cvs_log_init(LD_STD, 0); - while ((ch = getopt(argc, argv, "A:a:b::c:e::hik:LMUV")) != -1) { switch (ch) { case 'A': @@ -178,26 +209,9 @@ rcs_main(int argc, char **argv) } for (i = 0; i < argc; i++) { - /* - * Our RCS API does not append the RCS_FILE_EXT extension - * automaticly in rcs_open(), so we add it here. - */ - snprintf(filev, sizeof(filev), "%s%s", argv[i], RCS_FILE_EXT); - if (stat(RCSDIR, &st) != -1) { - strlcpy(fpath, RCSDIR, sizeof(fpath)); - strlcat(fpath, "/", sizeof(fpath)); - strlcat(fpath, filev, sizeof(fpath)); - } else { - strlcpy(fpath, filev, sizeof(filev)); - } - - if (stat(fpath, &st) != -1) { - errno = EEXIST; - cvs_log(LP_ERRNO, "%s", fpath); + if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0) continue; - } - printf("RCS file: %s\n", fpath); file = rcs_open(fpath, flags, fmode); if (file == NULL) continue; @@ -226,6 +240,7 @@ rcs_main(int argc, char **argv) rcs_lock_setmode(file, lkmode); rcs_close(file); + printf("done\n"); } |