=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rcs/rcsprog.c,v retrieving revision 1.8 retrieving revision 1.9 diff -c -r1.8 -r1.9 *** src/usr.bin/rcs/rcsprog.c 2005/09/29 00:20:22 1.8 --- src/usr.bin/rcs/rcsprog.c 2005/09/29 15:13:19 1.9 *************** *** 1,4 **** ! /* $OpenBSD: rcsprog.c,v 1.8 2005/09/29 00:20:22 joris Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau * All rights reserved. --- 1,4 ---- ! /* $OpenBSD: rcsprog.c,v 1.9 2005/09/29 15:13:19 joris Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau * All rights reserved. *************** *** 40,56 **** #include "log.h" #include "rcs.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 **); --- 40,50 ---- #include "log.h" #include "rcs.h" + #include "rcsprog.h" #include "strtab.h" const char rcs_version[] = "OpenCVS RCS version 3.6"; struct rcs_prog { char *prog_name; int (*prog_hdlr)(int, char **); *************** *** 64,70 **** --- 58,102 ---- { "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,78 **** --- 105,111 ---- 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,123 **** 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': --- 149,154 ---- *************** *** 178,203 **** } 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); continue; - } - printf("RCS file: %s\n", fpath); file = rcs_open(fpath, flags, fmode); if (file == NULL) continue; --- 209,217 ---- } for (i = 0; i < argc; i++) { ! if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0) continue; file = rcs_open(fpath, flags, fmode); if (file == NULL) continue; *************** *** 226,231 **** --- 240,246 ---- rcs_lock_setmode(file, lkmode); rcs_close(file); + printf("done\n"); }