Annotation of src/usr.bin/rcs/rlog.c, Revision 1.35
1.35 ! xsa 1: /* $OpenBSD: rlog.c,v 1.34 2006/03/27 06:13:51 pat Exp $ */
1.1 joris 2: /*
3: * Copyright (c) 2005 Joris Vink <joris@openbsd.org>
1.20 xsa 4: * Copyright (c) 2005, 2006 Xavier Santolaria <xsa@openbsd.org>
1.1 joris 5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: *
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. The name of the author may not be used to endorse or promote products
14: * derived from this software without specific prior written permission.
15: *
16: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26: */
27:
1.18 xsa 28: #include "includes.h"
1.1 joris 29:
1.19 xsa 30: #include "rcsprog.h"
1.3 niallo 31: #include "diff.h"
1.1 joris 32:
1.32 xsa 33: static void rlog_file(const char *, const char *);
34: static void rlog_rev_print(struct rcs_delta *);
1.1 joris 35:
36: #define REVSEP "----------------------------"
37: #define REVEND \
1.6 xsa 38: "============================================================================="
1.1 joris 39:
1.23 xsa 40: static int hflag, Lflag, lflag, tflag, Nflag, wflag;
41: static char *llist = NULL;
1.20 xsa 42: static char *slist = NULL;
43: static char *wlist = NULL;
1.23 xsa 44: static RCSFILE *file;
1.1 joris 45:
1.21 xsa 46: void
47: rlog_usage(void)
48: {
49: fprintf(stderr,
1.25 jmc 50: "usage: rlog [-bhLNqRtV] [-ddates] [-l[lockers]] [-r[revs]]\n"
1.28 xsa 51: " [-sstates] [-w[logins]] [-xsuffixes]\n"
52: " [-ztz] file ...\n");
1.21 xsa 53: }
54:
1.1 joris 55: int
56: rlog_main(int argc, char **argv)
57: {
58: int Rflag;
59: int i, ch;
60: char fpath[MAXPATHLEN];
61:
62: hflag = Rflag = 0;
1.33 ray 63: while ((ch = rcs_getopt(argc, argv, "hLl::NqRs:TtVw::x::z:")) != -1) {
1.1 joris 64: switch (ch) {
65: case 'h':
66: hflag = 1;
67: break;
1.11 xsa 68: case 'L':
69: Lflag = 1;
70: break;
1.23 xsa 71: case 'l':
72: lflag = 1;
73: llist = rcs_optarg;
74: break;
1.1 joris 75: case 'N':
76: Nflag = 1;
77: break;
78: case 'q':
79: verbose = 0;
80: break;
81: case 'R':
82: Rflag = 1;
83: break;
1.20 xsa 84: case 's':
85: slist = rcs_optarg;
86: break;
1.8 xsa 87: case 'T':
88: /*
89: * kept for compatibility
90: */
91: break;
1.1 joris 92: case 't':
93: tflag = 1;
94: break;
95: case 'V':
96: printf("%s\n", rcs_version);
97: exit(0);
1.29 ray 98: /* NOTREACHED */
1.20 xsa 99: case 'w':
100: wflag = 1;
101: wlist = rcs_optarg;
102: break;
1.14 xsa 103: case 'x':
1.33 ray 104: /* Use blank extension if none given. */
105: rcs_suffixes = rcs_optarg ? rcs_optarg : "";
1.14 xsa 106: break;
1.26 joris 107: case 'z':
108: timezone_flag = rcs_optarg;
1.27 xsa 109: break;
1.1 joris 110: default:
1.21 xsa 111: (usage());
112: exit(1);
1.1 joris 113: }
114: }
115:
1.5 joris 116: argc -= rcs_optind;
117: argv += rcs_optind;
1.1 joris 118:
119: if (argc == 0) {
120: cvs_log(LP_ERR, "no input file");
121: (usage)();
122: exit(1);
123: }
124:
1.7 xsa 125: if ((hflag == 1) && (tflag == 1)) {
1.6 xsa 126: cvs_log(LP_WARN, "warning: -t overrides -h.");
1.7 xsa 127: hflag = 0;
128: }
1.6 xsa 129:
1.1 joris 130: for (i = 0; i < argc; i++) {
131: if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
132: continue;
133:
1.17 niallo 134: if ((file = rcs_open(fpath, RCS_READ|RCS_PARSE_FULLY)) == NULL)
1.11 xsa 135: continue;
136:
137: if ((Lflag == 1) && (TAILQ_EMPTY(&(file->rf_locks)))) {
138: rcs_close(file);
139: continue;
140: }
141:
1.9 xsa 142: if (Rflag == 1) {
143: printf("%s\n", fpath);
1.11 xsa 144: rcs_close(file);
1.9 xsa 145: continue;
146: }
147:
1.23 xsa 148: rlog_file(argv[i], fpath);
1.9 xsa 149:
1.1 joris 150: rcs_close(file);
151: }
152:
153: return (0);
154: }
155:
1.32 xsa 156: static void
1.23 xsa 157: rlog_file(const char *fname, const char *fpath)
1.1 joris 158: {
159: char numb[64];
160: struct rcs_sym *sym;
161: struct rcs_access *acp;
1.20 xsa 162: struct rcs_delta *rdp;
1.10 xsa 163: struct rcs_lock *lkp;
1.1 joris 164:
1.12 xsa 165: printf("\nRCS file: %s", fpath);
1.6 xsa 166: printf("\nWorking file: %s", fname);
1.1 joris 167: printf("\nhead:");
168: if (file->rf_head != NULL)
169: printf(" %s", rcsnum_tostr(file->rf_head, numb, sizeof(numb)));
170:
171: printf("\nbranch:");
172: if (rcs_branch_get(file) != NULL) {
173: printf(" %s", rcsnum_tostr(rcs_branch_get(file),
174: numb, sizeof(numb)));
175: }
176:
177: printf("\nlocks: %s", (file->rf_flags & RCS_SLOCK) ? "strict" : "");
1.10 xsa 178: TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list)
179: printf("\n\t%s: %s", lkp->rl_name,
180: rcsnum_tostr(lkp->rl_num, numb, sizeof(numb)));
1.1 joris 181: printf("\naccess list:\n");
182: TAILQ_FOREACH(acp, &(file->rf_access), ra_list)
183: printf("\t%s\n", acp->ra_name);
184:
185: if (Nflag == 0) {
186: printf("symbolic names:\n");
187: TAILQ_FOREACH(sym, &(file->rf_symbols), rs_list) {
188: printf("\t%s: %s\n", sym->rs_name,
189: rcsnum_tostr(sym->rs_num, numb, sizeof(numb)));
190: }
191: }
192:
193: printf("keyword substitution: %s\n",
194: file->rf_expand == NULL ? "kv" : file->rf_expand);
195:
1.20 xsa 196: printf("total revisions: %u", file->rf_ndelta);
197:
1.35 ! xsa 198: if ((file->rf_head != NULL) && (hflag == 0) && (tflag == 0))
1.20 xsa 199: printf(";\tselected revisions:"); /* XXX */
200:
201: printf("\n");
202:
1.1 joris 203:
204: if ((hflag == 0) || (tflag == 1))
1.13 xsa 205: printf("description:\n%s", file->rf_desc);
1.1 joris 206:
1.20 xsa 207: if ((hflag == 0) && (tflag == 0)) {
208: TAILQ_FOREACH(rdp, &(file->rf_delta), rd_list)
209: rlog_rev_print(rdp);
210: }
1.1 joris 211:
212: printf("%s\n", REVEND);
1.16 xsa 213: }
214:
215: static void
1.20 xsa 216: rlog_rev_print(struct rcs_delta *rdp)
1.16 xsa 217: {
1.20 xsa 218: int i, found;
219: char *author, numb[64];
1.34 pat 220: struct cvs_argvector *largv, *sargv, *wargv;
1.20 xsa 221:
222: i = found = 0;
223: author = NULL;
224:
1.23 xsa 225: /* -l[lockers] */
226: if (lflag == 1) {
227: /* if no locks at all, abort. */
228: if (TAILQ_EMPTY(&(file->rf_locks)))
229: return;
230: else
231: if (rdp->rd_locker != NULL)
232: found++;
233:
234: if (llist != NULL) {
235: /* if locker is empty, no need to go further. */
236: if (rdp->rd_locker == NULL)
237: return;
1.30 xsa 238: largv = cvs_strsplit(llist, ",");
1.34 pat 239: for (i = 0; largv->argv[i] != NULL; i++) {
240: if (strcmp(rdp->rd_locker, largv->argv[i])
241: == 0) {
1.23 xsa 242: found++;
243: break;
244: }
245: found = 0;
246: }
1.34 pat 247: cvs_argv_destroy(largv);
1.23 xsa 248: }
249: }
1.20 xsa 250: /* -sstates */
251: if (slist != NULL) {
1.30 xsa 252: sargv = cvs_strsplit(slist, ",");
1.34 pat 253: for (i = 0; sargv->argv[i] != NULL; i++) {
254: if (strcmp(rdp->rd_state, sargv->argv[i]) == 0) {
1.20 xsa 255: found++;
256: break;
257: }
258: found = 0;
259: }
1.34 pat 260: cvs_argv_destroy(sargv);
1.20 xsa 261: }
262: /* -w[logins] */
263: if (wflag == 1) {
264: if (wlist != NULL) {
1.30 xsa 265: wargv = cvs_strsplit(wlist, ",");
1.34 pat 266: for (i = 0; wargv->argv[i] != NULL; i++) {
267: if (strcmp(rdp->rd_author, wargv->argv[i])
268: == 0) {
1.20 xsa 269: found++;
270: break;
271: }
272: found = 0;
273: }
1.34 pat 274: cvs_argv_destroy(wargv);
1.20 xsa 275: } else {
276: if ((author = getlogin()) == NULL)
277: fatal("getlogin failed");
1.16 xsa 278:
1.20 xsa 279: if (strcmp(rdp->rd_author, author) == 0)
280: found++;
281: }
282: }
1.16 xsa 283:
1.20 xsa 284: /* XXX dirty... */
1.23 xsa 285: if (((((slist != NULL) && (wflag == 1)) ||
286: ((slist != NULL) && (lflag == 1)) ||
287: ((lflag == 1) && (wflag == 1))) && (found < 2)) ||
288: ((((slist != NULL) && (lflag == 1) && (wflag == 1)) ||
289: ((slist != NULL) || (lflag == 1) || (wflag == 1))) && (found == 0)))
1.20 xsa 290: return;
291:
292: printf("%s\n", REVSEP);
293:
294: rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
295:
1.22 xsa 296: printf("revision %s", numb);
297: if (rdp->rd_locker != NULL)
298: printf("\tlocked by: %s;", rdp->rd_locker);
299: printf("\ndate: %d/%02d/%02d %02d:%02d:%02d;"
1.20 xsa 300: " author: %s; state: %s;\n",
301: rdp->rd_date.tm_year + 1900,
302: rdp->rd_date.tm_mon + 1,
303: rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
304: rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
305: rdp->rd_author, rdp->rd_state);
306: printf("%s", rdp->rd_log);
1.1 joris 307: }