[BACK]Return to rlog.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / rcs

Annotation of src/usr.bin/rcs/rlog.c, Revision 1.33

1.33    ! ray         1: /*     $OpenBSD: rlog.c,v 1.32 2006/03/23 13:28:23 xsa 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:
                    198:        if ((hflag == 0) && (tflag == 0))
                    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.23      xsa       220:        char **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.23      xsa       239:                        for (i = 0; largv[i] != NULL; i++) {
                    240:                                if (strcmp(rdp->rd_locker, largv[i]) == 0) {
                    241:                                        found++;
                    242:                                        break;
                    243:                                }
                    244:                                found = 0;
                    245:                        }
1.31      xsa       246:                        xfree(largv);
1.23      xsa       247:                }
                    248:        }
1.20      xsa       249:        /* -sstates */
                    250:        if (slist != NULL) {
1.30      xsa       251:                sargv = cvs_strsplit(slist, ",");
1.20      xsa       252:                for (i = 0; sargv[i] != NULL; i++) {
                    253:                        if (strcmp(rdp->rd_state, sargv[i]) == 0) {
                    254:                                found++;
                    255:                                break;
                    256:                        }
                    257:                        found = 0;
                    258:                }
1.31      xsa       259:                xfree(sargv);
1.20      xsa       260:        }
                    261:        /* -w[logins] */
                    262:        if (wflag == 1) {
                    263:                if (wlist != NULL) {
1.30      xsa       264:                        wargv = cvs_strsplit(wlist, ",");
1.20      xsa       265:                        for (i = 0; wargv[i] != NULL; i++) {
                    266:                                if (strcmp(rdp->rd_author, wargv[i]) == 0) {
                    267:                                        found++;
                    268:                                        break;
                    269:                                }
                    270:                                found = 0;
                    271:                        }
1.31      xsa       272:                        xfree(wargv);
1.20      xsa       273:                } else {
                    274:                        if ((author = getlogin()) == NULL)
                    275:                                fatal("getlogin failed");
1.16      xsa       276:
1.20      xsa       277:                        if (strcmp(rdp->rd_author, author) == 0)
                    278:                                found++;
                    279:                }
                    280:        }
1.16      xsa       281:
1.20      xsa       282:        /* XXX dirty... */
1.23      xsa       283:        if (((((slist != NULL) && (wflag == 1)) ||
                    284:            ((slist != NULL) && (lflag == 1)) ||
                    285:            ((lflag == 1) && (wflag == 1))) && (found < 2)) ||
                    286:            ((((slist != NULL) && (lflag == 1) && (wflag == 1)) ||
                    287:            ((slist != NULL) || (lflag == 1) || (wflag == 1))) && (found == 0)))
1.20      xsa       288:                return;
                    289:
                    290:        printf("%s\n", REVSEP);
                    291:
                    292:        rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
                    293:
1.22      xsa       294:        printf("revision %s", numb);
                    295:        if (rdp->rd_locker != NULL)
                    296:                printf("\tlocked by: %s;", rdp->rd_locker);
                    297:        printf("\ndate: %d/%02d/%02d %02d:%02d:%02d;"
1.20      xsa       298:            "  author: %s;  state: %s;\n",
                    299:            rdp->rd_date.tm_year + 1900,
                    300:            rdp->rd_date.tm_mon + 1,
                    301:            rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
                    302:            rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
                    303:            rdp->rd_author, rdp->rd_state);
                    304:        printf("%s", rdp->rd_log);
1.1       joris     305: }