[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.16

1.16    ! xsa         1: /*     $OpenBSD: rlog.c,v 1.15 2005/11/28 14:43:59 xsa Exp $   */
1.1       joris       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 "log.h"
                     37: #include "rcs.h"
1.3       niallo     38: #include "diff.h"
1.1       joris      39: #include "rcsprog.h"
                     40:
1.16    ! xsa        41: static int     rlog_file(const char *, const char *, RCSFILE *);
        !            42: static void    rlog_rev_print(RCSFILE *);
1.1       joris      43:
                     44: #define REVSEP         "----------------------------"
                     45: #define REVEND \
1.6       xsa        46:  "============================================================================="
1.1       joris      47:
                     48: static int hflag;
1.11      xsa        49: static int Lflag;
1.1       joris      50: static int tflag;
                     51: static int Nflag;
                     52:
                     53: int
                     54: rlog_main(int argc, char **argv)
                     55: {
                     56:        int Rflag;
                     57:        int i, ch;
                     58:        char fpath[MAXPATHLEN];
                     59:        RCSFILE *file;
                     60:
                     61:        hflag = Rflag = 0;
1.14      xsa        62:        while ((ch = rcs_getopt(argc, argv, "hLNqRTtVx:")) != -1) {
1.1       joris      63:                switch (ch) {
                     64:                case 'h':
                     65:                        hflag = 1;
                     66:                        break;
1.11      xsa        67:                case 'L':
                     68:                        Lflag = 1;
                     69:                        break;
1.1       joris      70:                case 'N':
                     71:                        Nflag = 1;
                     72:                        break;
                     73:                case 'q':
                     74:                        verbose = 0;
                     75:                        break;
                     76:                case 'R':
                     77:                        Rflag = 1;
                     78:                        break;
1.8       xsa        79:                case 'T':
                     80:                        /*
                     81:                         * kept for compatibility
                     82:                         */
                     83:                        break;
1.1       joris      84:                case 't':
                     85:                        tflag = 1;
                     86:                        break;
                     87:                case 'V':
                     88:                        printf("%s\n", rcs_version);
                     89:                        exit(0);
1.14      xsa        90:                case 'x':
                     91:                        rcs_suffixes = rcs_optarg;
                     92:                        break;
1.1       joris      93:                default:
                     94:                        break;
                     95:                }
                     96:        }
                     97:
1.5       joris      98:        argc -= rcs_optind;
                     99:        argv += rcs_optind;
1.1       joris     100:
                    101:        if (argc == 0) {
                    102:                cvs_log(LP_ERR, "no input file");
                    103:                (usage)();
                    104:                exit(1);
                    105:        }
                    106:
1.7       xsa       107:        if ((hflag == 1) && (tflag == 1)) {
1.6       xsa       108:                cvs_log(LP_WARN, "warning: -t overrides -h.");
1.7       xsa       109:                hflag = 0;
                    110:        }
1.6       xsa       111:
1.1       joris     112:        for (i = 0; i < argc; i++) {
                    113:                if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
                    114:                        continue;
                    115:
1.11      xsa       116:                if ((file = rcs_open(fpath, RCS_READ)) == NULL)
                    117:                        continue;
                    118:
                    119:                if ((Lflag == 1) && (TAILQ_EMPTY(&(file->rf_locks)))) {
                    120:                        rcs_close(file);
                    121:                        continue;
                    122:                }
                    123:
1.9       xsa       124:                if (Rflag == 1) {
                    125:                        printf("%s\n", fpath);
1.11      xsa       126:                        rcs_close(file);
1.9       xsa       127:                        continue;
                    128:                }
                    129:
                    130:                rlog_file(argv[i], fpath, file);
                    131:
1.1       joris     132:                rcs_close(file);
                    133:        }
                    134:
                    135:        return (0);
                    136: }
                    137:
                    138: void
                    139: rlog_usage(void)
                    140: {
1.4       deraadt   141:        fprintf(stderr,
1.15      xsa       142:            "usage: rlog [-hLNqRTtV] [-xsuffixes] file ...\n");
1.1       joris     143: }
                    144:
                    145: static int
                    146: rlog_file(const char *fname, const char *fpath, RCSFILE *file)
                    147: {
                    148:        char numb[64];
                    149:        struct rcs_sym *sym;
                    150:        struct rcs_access *acp;
1.10      xsa       151:        struct rcs_lock *lkp;
1.1       joris     152:
1.12      xsa       153:        printf("\nRCS file: %s", fpath);
1.6       xsa       154:        printf("\nWorking file: %s", fname);
1.1       joris     155:        printf("\nhead:");
                    156:        if (file->rf_head != NULL)
                    157:                printf(" %s", rcsnum_tostr(file->rf_head, numb, sizeof(numb)));
                    158:
                    159:        printf("\nbranch:");
                    160:        if (rcs_branch_get(file) != NULL) {
                    161:                printf(" %s", rcsnum_tostr(rcs_branch_get(file),
                    162:                    numb, sizeof(numb)));
                    163:        }
                    164:
                    165:        printf("\nlocks: %s", (file->rf_flags & RCS_SLOCK) ? "strict" : "");
1.10      xsa       166:        TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list)
                    167:                printf("\n\t%s: %s", lkp->rl_name,
                    168:                    rcsnum_tostr(lkp->rl_num, numb, sizeof(numb)));
1.1       joris     169:        printf("\naccess list:\n");
                    170:        TAILQ_FOREACH(acp, &(file->rf_access), ra_list)
                    171:                printf("\t%s\n", acp->ra_name);
                    172:
                    173:        if (Nflag == 0) {
                    174:                printf("symbolic names:\n");
                    175:                TAILQ_FOREACH(sym, &(file->rf_symbols), rs_list) {
                    176:                        printf("\t%s: %s\n", sym->rs_name,
                    177:                            rcsnum_tostr(sym->rs_num, numb, sizeof(numb)));
                    178:                }
                    179:        }
                    180:
                    181:        printf("keyword substitution: %s\n",
                    182:            file->rf_expand == NULL ? "kv" : file->rf_expand);
                    183:
                    184:        printf("total revisions: %u\n", file->rf_ndelta);
                    185:
                    186:        if ((hflag == 0) || (tflag == 1))
1.13      xsa       187:                printf("description:\n%s", file->rf_desc);
1.1       joris     188:
1.16    ! xsa       189:        if ((hflag == 0) && (tflag == 0))
        !           190:                rlog_rev_print(file);
1.1       joris     191:
                    192:        printf("%s\n", REVEND);
                    193:        return (0);
1.16    ! xsa       194: }
        !           195:
        !           196: static void
        !           197: rlog_rev_print(RCSFILE *file)
        !           198: {
        !           199:        char numb[64];
        !           200:        struct rcs_delta *rdp;
        !           201:
        !           202:        TAILQ_FOREACH(rdp, &(file->rf_delta), rd_list) {
        !           203:                printf("%s\n", REVSEP);
        !           204:
        !           205:                rcsnum_tostr(rdp->rd_num, numb, sizeof(numb));
        !           206:
        !           207:                printf("revision %s\n", numb);
        !           208:                printf("date: %d/%02d/%02d %02d:%02d:%02d;"
        !           209:                    "  author: %s;  state: %s;\n",
        !           210:                    rdp->rd_date.tm_year + 1900,
        !           211:                    rdp->rd_date.tm_mon + 1,
        !           212:                    rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
        !           213:                    rdp->rd_date.tm_min, rdp->rd_date.tm_sec,
        !           214:                    rdp->rd_author, rdp->rd_state);
        !           215:                printf("%s", rdp->rd_log);
        !           216:        }
1.1       joris     217: }