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

1.7     ! joris       1: /*     $OpenBSD: rcsprog.c,v 1.6 2005/09/20 05:01:31 joris 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:
1.6       joris      27: #include <sys/param.h>
1.1       deraadt    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.7     ! joris      63:        { "ident",      NULL,           NULL            },
1.1       deraadt    64: };
                     65:
                     66:
                     67: int
                     68: main(int argc, char **argv)
                     69: {
                     70:        u_int i;
                     71:        int ret;
                     72:
                     73:        ret = -1;
                     74:        cvs_strtab_init();
                     75:
                     76:        for (i = 0; i < (sizeof(programs)/sizeof(programs[0])); i++)
1.2       deraadt    77:                if (strcmp(__progname, programs[i].prog_name) == 0) {
                     78:                        usage = programs[i].prog_usage;
1.1       deraadt    79:                        ret = programs[i].prog_hdlr(argc, argv);
1.2       deraadt    80:                        break;
                     81:                }
1.1       deraadt    82:
                     83:        cvs_strtab_cleanup();
                     84:
                     85:        return (ret);
                     86: }
                     87:
                     88:
                     89: void
                     90: rcs_usage(void)
                     91: {
                     92:        fprintf(stderr,
1.2       deraadt    93:            "usage: %s [-hiLMUV] [-a users] [-b [rev]] [-c string] "
                     94:            "[-e users] [-k opt] file ...\n", __progname);
1.1       deraadt    95: }
                     96:
                     97:
                     98: /*
                     99:  * rcs_main()
                    100:  *
                    101:  * Handler for the `rcs' program.
                    102:  * Returns 0 on success, or >0 on error.
                    103:  */
                    104: int
                    105: rcs_main(int argc, char **argv)
                    106: {
                    107:        int i, ch, flags, kflag, lkmode;
1.6       joris     108:        char fpath[MAXPATHLEN];
1.1       deraadt   109:        char *oldfile, *alist, *comment, *elist, *unp, *sp;
                    110:        mode_t fmode;
                    111:        RCSFILE *file;
                    112:
                    113:        kflag = lkmode = -1;
                    114:        fmode = 0;
                    115:        flags = RCS_RDWR;
                    116:        oldfile = alist = comment = elist = NULL;
                    117:
                    118:        cvs_log_init(LD_STD, 0);
                    119:
                    120:        while ((ch = getopt(argc, argv, "A:a:b::c:e::hik:LMUV")) != -1) {
                    121:                switch (ch) {
                    122:                case 'A':
                    123:                        oldfile = optarg;
                    124:                        break;
                    125:                case 'a':
                    126:                        alist = optarg;
                    127:                        break;
                    128:                case 'c':
                    129:                        comment = optarg;
                    130:                        break;
                    131:                case 'e':
                    132:                        elist = optarg;
                    133:                        break;
                    134:                case 'h':
1.2       deraadt   135:                        (usage)();
1.1       deraadt   136:                        exit(0);
                    137:                case 'i':
                    138:                        flags |= RCS_CREATE;
                    139:                        break;
                    140:                case 'k':
                    141:                        kflag = rcs_kflag_get(optarg);
                    142:                        if (RCS_KWEXP_INVAL(kflag)) {
                    143:                                cvs_log(LP_ERR,
                    144:                                    "invalid keyword substitution mode `%s'",
                    145:                                    optarg);
                    146:                                exit(1);
                    147:                        }
                    148:                        break;
                    149:                case 'L':
                    150:                        if (lkmode == RCS_LOCK_LOOSE)
                    151:                                cvs_log(LP_WARN, "-U overriden by -L");
                    152:                        lkmode = RCS_LOCK_STRICT;
                    153:                        break;
                    154:                case 'M':
                    155:                        /* ignore for the moment */
                    156:                        break;
                    157:                case 'U':
                    158:                        if (lkmode == RCS_LOCK_STRICT)
                    159:                                cvs_log(LP_WARN, "-L overriden by -U");
                    160:                        lkmode = RCS_LOCK_LOOSE;
                    161:                        break;
                    162:                case 'V':
                    163:                        printf("%s\n", rcs_version);
                    164:                        exit(0);
                    165:                default:
1.2       deraadt   166:                        (usage)();
1.1       deraadt   167:                        exit(1);
                    168:                }
                    169:        }
                    170:
                    171:        argc -= optind;
                    172:        argv += optind;
                    173:        if (argc == 0) {
                    174:                cvs_log(LP_ERR, "no input file");
1.5       joris     175:                (usage)();
1.1       deraadt   176:                exit(1);
                    177:        }
                    178:
                    179:        for (i = 0; i < argc; i++) {
1.6       joris     180:                /*
                    181:                 * Our RCS API does not append the RCS_FILE_EXT extension
                    182:                 * automaticly in rcs_open(), so we add it here.
                    183:                 */
                    184:                snprintf(fpath, sizeof(fpath), "%s%s", argv[i], RCS_FILE_EXT);
                    185:
                    186:                printf("RCS file: %s\n", fpath);
                    187:                file = rcs_open(fpath, flags, fmode);
                    188:                if (file == NULL)
                    189:                        continue;
1.1       deraadt   190:
                    191:                /* entries to add to the access list */
                    192:                if (alist != NULL) {
                    193:                        unp = alist;
                    194:                        do {
                    195:                                sp = strchr(unp, ',');
                    196:                                if (sp != NULL)
                    197:                                        *(sp++) = '\0';
                    198:
                    199:                                rcs_access_add(file, unp);
                    200:
                    201:                                unp = sp;
                    202:                        } while (sp != NULL);
                    203:                }
                    204:
                    205:                if (comment != NULL)
                    206:                        rcs_comment_set(file, comment);
                    207:
                    208:                if (kflag != -1)
                    209:                        rcs_kwexp_set(file, kflag);
                    210:
                    211:                if (lkmode != -1)
                    212:                        rcs_lock_setmode(file, lkmode);
                    213:
                    214:                rcs_close(file);
                    215:                printf("done\n");
                    216:        }
                    217:
                    218:        return (0);
                    219: }