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

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

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