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

Annotation of src/usr.bin/cvs/rcsprog.c, Revision 1.3

1.3     ! joris       1: /*     $OpenBSD: rcsprog.c,v 1.2 2005/03/05 23:22:10 jmc Exp $ */
1.1       jfb         2: /*
                      3:  * Copyright (c) 2005 Jean-Francois Brousseau <jfb@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/types.h>
                     28: #include <sys/wait.h>
                     29:
                     30: #include <err.h>
                     31: #include <pwd.h>
                     32: #include <errno.h>
                     33: #include <stdio.h>
                     34: #include <ctype.h>
                     35: #include <stdlib.h>
                     36: #include <unistd.h>
                     37: #include <signal.h>
                     38: #include <string.h>
                     39: #include <sysexits.h>
                     40:
                     41: #include "log.h"
                     42: #include "rcs.h"
1.3     ! joris      43: #include "strtab.h"
1.1       jfb        44:
                     45: extern char *__progname;
                     46:
                     47:
                     48: const char rcs_version[] = "OpenCVS RCS version 3.6";
                     49:
                     50: void  rcs_usage (void);
                     51: int   rcs_main  (int, char **);
                     52:
                     53:
                     54:
                     55: struct rcs_prog {
                     56:        char  *prog_name;
                     57:        int  (*prog_hdlr)(int, char **);
                     58: } programs[] = {
                     59:        { "rcs",        rcs_main  },
                     60:        { "ci",         NULL      },
                     61:        { "co",         NULL      },
                     62:        { "rcsclean",   NULL      },
                     63:        { "rcsdiff",    NULL      },
                     64: };
                     65:
                     66:
                     67: int
                     68: main(int argc, char **argv)
                     69: {
                     70:        u_int i;
1.3     ! joris      71:        int ret;
        !            72:
        !            73:        ret = -1;
        !            74:        cvs_strtab_init();
1.1       jfb        75:
                     76:        for (i = 0; i < (sizeof(programs)/sizeof(programs[0])); i++)
                     77:                if (strcmp(__progname, programs[i].prog_name) == 0)
1.3     ! joris      78:                        ret = programs[i].prog_hdlr(argc, argv);
1.1       jfb        79:
1.3     ! joris      80:        cvs_strtab_cleanup();
1.1       jfb        81:
1.3     ! joris      82:        return (ret);
1.1       jfb        83: }
                     84:
                     85:
                     86: void
                     87: rcs_usage(void)
                     88: {
                     89:        fprintf(stderr,
1.2       jmc        90:            "Usage: %s [-hiLMUV] [-a users] [-b [rev]] [-c string] "
1.1       jfb        91:            "[-e users] [-k opt] file ...\n"
                     92:            "\t-a users\tAdd the login names in the comma-separated <users>\n"
                     93:            "\t-b rev\t\tSet the head revision to <rev>\n"
                     94:            "\t-c string\tSet the comment leader to <string>\n"
                     95:            "\t-e users\tRemove the login names in the comma-separated <users>\n"
                     96:            "\t-h\t\tPrint the program's usage and exit\n"
                     97:            "\t-i\t\tCreate a new empty RCS file\n"
                     98:            "\t-k opt\t\tSet the keyword expansion mode to <opt>\n"
                     99:            "\t-L\t\tEnable strict locking on the specified files\n"
                    100:            "\t-M\t\tDisable mail warning about lock breaks\n"
                    101:            "\t-U\t\tDisable strict locking on the specified files\n"
                    102:            "\t-V\t\tPrint the program's version string and exit\n",
                    103:            __progname);
                    104: }
                    105:
                    106:
                    107: /*
                    108:  * rcs_main()
                    109:  *
                    110:  * Handler for the `rcs' program.
                    111:  * Returns 0 on success, or >0 on error.
                    112:  */
                    113: int
                    114: rcs_main(int argc, char **argv)
                    115: {
                    116:        int i, ch, flags, kflag, lkmode;
                    117:        char *oldfile, *alist, *comment, *elist, *unp, *sp;
                    118:        mode_t fmode;
                    119:        RCSFILE *file;
                    120:
                    121:        kflag = lkmode = -1;
                    122:        fmode = 0;
                    123:        flags = RCS_READ;
                    124:        oldfile = alist = comment = elist = NULL;
                    125:
                    126:        cvs_log_init(LD_STD, 0);
                    127:
                    128:        while ((ch = getopt(argc, argv, "A:a:b::c:e::hik:LMUV")) != -1) {
                    129:                switch (ch) {
                    130:                case 'A':
                    131:                        oldfile = optarg;
                    132:                        break;
                    133:                case 'a':
                    134:                        alist = optarg;
                    135:                        break;
                    136:                case 'c':
                    137:                        comment = optarg;
                    138:                        break;
                    139:                case 'e':
                    140:                        elist = optarg;
                    141:                        break;
                    142:                case 'h':
                    143:                        rcs_usage();
                    144:                        exit(0);
                    145:                case 'i':
                    146:                        flags |= (RCS_WRITE | RCS_CREATE);
                    147:                        break;
                    148:                case 'k':
                    149:                        kflag = rcs_kflag_get(optarg);
                    150:                        if (RCS_KWEXP_INVAL(kflag)) {
                    151:                                cvs_log(LP_ERR,
                    152:                                    "invalid keyword substitution mode `%s'",
                    153:                                    optarg);
                    154:                                exit(1);
                    155:                        }
                    156:                        break;
                    157:                case 'L':
                    158:                        if (lkmode == RCS_LOCK_LOOSE)
                    159:                                cvs_log(LP_WARN, "-U overriden by -L");
                    160:                        lkmode = RCS_LOCK_STRICT;
                    161:                        break;
                    162:                case 'M':
                    163:                        /* ignore for the moment */
                    164:                        break;
                    165:                case 'U':
                    166:                        if (lkmode == RCS_LOCK_STRICT)
                    167:                                cvs_log(LP_WARN, "-L overriden by -U");
                    168:                        lkmode = RCS_LOCK_LOOSE;
                    169:                        break;
                    170:                case 'V':
                    171:                        printf("%s\n", rcs_version);
                    172:                        exit(0);
                    173:                default:
                    174:                        rcs_usage();
                    175:                        exit(1);
                    176:                }
                    177:        }
                    178:
                    179:        argc -= optind;
                    180:        argv += optind;
                    181:        if (argc == 0) {
                    182:                cvs_log(LP_ERR, "no input file");
                    183:                exit(1);
                    184:        }
                    185:
                    186:        for (i = 0; i < argc; i++) {
                    187:                printf("RCS file: %s\n", argv[0]);
                    188:                file = rcs_open(argv[0], flags, fmode);
                    189:                if (file == NULL) {
                    190:                        return (1);
                    191:                }
                    192:
                    193:                /* entries to add to the access list */
                    194:                if (alist != NULL) {
                    195:                        unp = alist;
                    196:                        do {
                    197:                                sp = strchr(unp, ',');
                    198:                                if (sp != NULL)
                    199:                                        *(sp++) = '\0';
                    200:
                    201:                                rcs_access_add(file, unp);
                    202:
                    203:                                unp = sp;
                    204:                        } while (sp != NULL);
                    205:                }
                    206:
                    207:                if (comment != NULL)
                    208:                        rcs_comment_set(file, comment);
                    209:
                    210:                if (kflag != -1)
                    211:                        rcs_kwexp_set(file, kflag);
                    212:
                    213:                if (lkmode != -1)
                    214:                        rcs_lock_setmode(file, lkmode);
                    215:
                    216:                rcs_close(file);
                    217:                printf("done\n");
                    218:        }
                    219:
                    220:        return (0);
                    221: }