Annotation of src/usr.bin/rcs/rlog.c, Revision 1.1
1.1 ! joris 1: /* $OpenBSD: rcsclean.c,v 1.3 2005/10/06 11:46:03 joris Exp $ */
! 2: /*
! 3: * Copyright (c) 2005 Joris Vink <joris@openbsd.org>
! 4: * All rights reserved.
! 5: *
! 6: * Redistribution and use in source and binary forms, with or without
! 7: * modification, are permitted provided that the following conditions
! 8: * are met:
! 9: *
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. The name of the author may not be used to endorse or promote products
! 13: * derived from this software without specific prior written permission.
! 14: *
! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
! 16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
! 17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
! 18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
! 19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! 20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
! 21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
! 22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
! 23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 25: */
! 26:
! 27: #include <sys/param.h>
! 28: #include <sys/stat.h>
! 29:
! 30: #include <dirent.h>
! 31: #include <stdio.h>
! 32: #include <stdlib.h>
! 33: #include <string.h>
! 34: #include <unistd.h>
! 35:
! 36: #include "diff.h"
! 37: #include "log.h"
! 38: #include "rcs.h"
! 39: #include "rcsprog.h"
! 40:
! 41: extern char *__progname;
! 42: static int rlog_file(const char *, const char *, RCSFILE *);
! 43:
! 44: #define REVSEP "----------------------------"
! 45: #define REVEND \
! 46: "============================================================================"
! 47:
! 48: static int hflag;
! 49: static int tflag;
! 50: static int Nflag;
! 51:
! 52: int
! 53: rlog_main(int argc, char **argv)
! 54: {
! 55: int Rflag;
! 56: int i, ch;
! 57: char fpath[MAXPATHLEN];
! 58: RCSFILE *file;
! 59:
! 60: hflag = Rflag = 0;
! 61: while ((ch = getopt(argc, argv, "hNqRtV")) != -1) {
! 62: switch (ch) {
! 63: case 'h':
! 64: hflag = 1;
! 65: break;
! 66: case 'N':
! 67: Nflag = 1;
! 68: break;
! 69: case 'q':
! 70: verbose = 0;
! 71: break;
! 72: case 'R':
! 73: Rflag = 1;
! 74: break;
! 75: case 't':
! 76: tflag = 1;
! 77: break;
! 78: case 'V':
! 79: printf("%s\n", rcs_version);
! 80: exit(0);
! 81: default:
! 82: break;
! 83: }
! 84: }
! 85:
! 86: argc -= optind;
! 87: argv += optind;
! 88:
! 89: if (argc == 0) {
! 90: cvs_log(LP_ERR, "no input file");
! 91: (usage)();
! 92: exit(1);
! 93: }
! 94:
! 95: for (i = 0; i < argc; i++) {
! 96: if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
! 97: continue;
! 98:
! 99: if ((file = rcs_open(fpath, RCS_READ)) == NULL)
! 100: continue;
! 101:
! 102: if (Rflag == 0)
! 103: rlog_file(argv[i], fpath, file);
! 104: rcs_close(file);
! 105: }
! 106:
! 107: return (0);
! 108: }
! 109:
! 110: void
! 111: rlog_usage(void)
! 112: {
! 113: fprintf(stderr, "usage %s [-qV] file ...\n", __progname);
! 114: }
! 115:
! 116: static int
! 117: rlog_file(const char *fname, const char *fpath, RCSFILE *file)
! 118: {
! 119: char numb[64];
! 120: struct rcs_sym *sym;
! 121: struct rcs_delta *rdp;
! 122: struct rcs_access *acp;
! 123:
! 124: printf("Working file: %s", fname);
! 125: printf("\nhead:");
! 126: if (file->rf_head != NULL)
! 127: printf(" %s", rcsnum_tostr(file->rf_head, numb, sizeof(numb)));
! 128:
! 129: printf("\nbranch:");
! 130: if (rcs_branch_get(file) != NULL) {
! 131: printf(" %s", rcsnum_tostr(rcs_branch_get(file),
! 132: numb, sizeof(numb)));
! 133: }
! 134:
! 135: printf("\nlocks: %s", (file->rf_flags & RCS_SLOCK) ? "strict" : "");
! 136: printf("\naccess list:\n");
! 137: TAILQ_FOREACH(acp, &(file->rf_access), ra_list)
! 138: printf("\t%s\n", acp->ra_name);
! 139:
! 140: if (Nflag == 0) {
! 141: printf("symbolic names:\n");
! 142: TAILQ_FOREACH(sym, &(file->rf_symbols), rs_list) {
! 143: printf("\t%s: %s\n", sym->rs_name,
! 144: rcsnum_tostr(sym->rs_num, numb, sizeof(numb)));
! 145: }
! 146: }
! 147:
! 148: printf("keyword substitution: %s\n",
! 149: file->rf_expand == NULL ? "kv" : file->rf_expand);
! 150:
! 151: printf("total revisions: %u\n", file->rf_ndelta);
! 152:
! 153: if ((hflag == 0) || (tflag == 1))
! 154: printf("description: %s\n", file->rf_desc);
! 155:
! 156: if ((hflag == 0) && (tflag == 0)) {
! 157: TAILQ_FOREACH(rdp, &(file->rf_delta), rd_list) {
! 158: rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
! 159: printf("%s\nrevision %s\n", REVSEP, numb);
! 160: printf("date: %d/%02d/%02d %02d:%02d:%02d;"
! 161: " author: %s; state: %s;\n",
! 162: rdp->rd_date.tm_year + 1900,
! 163: rdp->rd_date.tm_mon + 1,
! 164: rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
! 165: rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
! 166: rdp->rd_author, rdp->rd_state);
! 167: printf("%s", rdp->rd_log);
! 168: }
! 169: }
! 170:
! 171: printf("%s\n", REVEND);
! 172: return (0);
! 173: }