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

1.69    ! niallo      1: /*     $OpenBSD: rcsprog.c,v 1.68 2006/03/08 20:19:39 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.59      xsa        27: #include "includes.h"
1.1       deraadt    28:
1.9       joris      29: #include "rcsprog.h"
1.1       deraadt    30:
1.29      joris      31: #define RCS_CMD_MAXARG 128
1.42      xsa        32: #define RCS_DEFAULT_SUFFIX     ",v/"
1.56      joris      33: #define RCSPROG_OPTSTRING      "A:a:b::c:e::hik:Lm:Mn:N:qt::TUVx:z:"
                     34:
                     35: #define DESC_PROMPT    "enter description, terminated with single '.' "      \
                     36:                        "or end of file:\nNOTE: This is NOT the log message!" \
                     37:                        "\n>> "
1.29      joris      38:
1.1       deraadt    39: const char rcs_version[] = "OpenCVS RCS version 3.6";
1.12      joris      40: int verbose = 1;
1.34      joris      41: int pipeout = 0;
1.1       deraadt    42:
1.56      joris      43: #define RCS_NFLAG      1
                     44: #define RCS_TFLAG      2
                     45: static int rcsflags = 0;
                     46:
1.36      xsa        47: int     rcs_optind;
1.28      joris      48: char   *rcs_optarg;
1.42      xsa        49: char   *rcs_suffixes;
1.36      xsa        50: char   *rcs_tmpdir = RCS_TMPDIR_DEFAULT;
1.28      joris      51:
1.1       deraadt    52: struct rcs_prog {
1.26      deraadt    53:        char    *prog_name;
                     54:        int     (*prog_hdlr)(int, char **);
                     55:        void    (*prog_usage)(void);
1.1       deraadt    56: } programs[] = {
1.2       deraadt    57:        { "rcs",        rcs_main,       rcs_usage       },
1.17      joris      58:        { "ci",         checkin_main,   checkin_usage   },
1.11      joris      59:        { "co",         checkout_main,  checkout_usage  },
1.20      joris      60:        { "rcsclean",   rcsclean_main,  rcsclean_usage  },
1.18      joris      61:        { "rcsdiff",    rcsdiff_main,   rcsdiff_usage   },
1.33      xsa        62:        { "rcsmerge",   rcsmerge_main,  rcsmerge_usage  },
1.21      joris      63:        { "rlog",       rlog_main,      rlog_usage      },
1.22      joris      64:        { "ident",      ident_main,     ident_usage     },
1.1       deraadt    65: };
1.31      joris      66:
1.68      joris      67: struct cvs_wklhead rcs_temp_files;
                     68:
                     69: void sighdlr(int);
1.56      joris      70: static void rcs_set_description(RCSFILE *, const char *);
                     71: static void rcs_attach_symbol(RCSFILE *, const char *);
                     72:
1.31      joris      73: void
1.68      joris      74: sighdlr(int sig)
                     75: {
                     76:        cvs_worklist_clean(&rcs_temp_files, cvs_worklist_unlink);
                     77:        _exit(1);
                     78: }
                     79:
                     80: void
1.31      joris      81: rcs_set_rev(const char *str, RCSNUM **rev)
                     82: {
1.32      joris      83:        if (str == NULL)
                     84:                return;
                     85:
1.52      joris      86:        if ((*rev != NULL) && (*rev != RCS_HEAD_REV))
1.31      joris      87:                cvs_log(LP_WARN, "redefinition of revision number");
                     88:
1.55      xsa        89:        if ((*rev = rcsnum_parse(str)) == NULL)
                     90:                fatal("bad revision number '%s'", str);
1.47      xsa        91: }
                     92:
                     93: /*
                     94:  * rcs_get_mtime()
                     95:  *
                     96:  * Get <filename> last modified time.
                     97:  * Returns last modified time on success, or -1 on failure.
                     98:  */
                     99: time_t
                    100: rcs_get_mtime(const char *filename)
                    101: {
                    102:        struct stat st;
                    103:        time_t mtime;
                    104:
                    105:        if (stat(filename, &st) == -1) {
                    106:                cvs_log(LP_ERRNO, "failed to stat `%s'", filename);
                    107:                return (-1);
                    108:        }
                    109:        mtime = (time_t)st.st_mtimespec.tv_sec;
                    110:
                    111:        return (mtime);
                    112: }
                    113:
                    114: /*
                    115:  * rcs_set_mtime()
                    116:  *
                    117:  * Set <filename> last modified time to <mtime> if it's not set to -1.
                    118:  * Returns 0 on success, or -1 on failure.
                    119:  */
                    120: int
                    121: rcs_set_mtime(const char *filename, time_t mtime)
                    122: {
                    123:        static struct timeval tv[2];
                    124:
                    125:        if (mtime == -1)
                    126:                return (0);
                    127:
                    128:        tv[0].tv_sec = mtime;
                    129:        tv[1].tv_sec = tv[0].tv_sec;
                    130:
                    131:        if (utimes(filename, tv) == -1) {
                    132:                cvs_log(LP_ERRNO, "error setting utimes");
                    133:                return (-1);
                    134:        }
                    135:
                    136:        return (0);
1.31      joris     137: }
1.1       deraadt   138:
1.9       joris     139: int
1.29      joris     140: rcs_init(char *envstr, char **argv, int argvlen)
                    141: {
                    142:        u_int i;
                    143:        int argc, error;
                    144:        char linebuf[256],  *lp, *cp;
                    145:
                    146:        strlcpy(linebuf, envstr, sizeof(linebuf));
                    147:        memset(argv, 0, argvlen * sizeof(char *));
                    148:
                    149:        error = argc = 0;
                    150:        for (lp = linebuf; lp != NULL;) {
1.61      xsa       151:                cp = strsep(&lp, " \t\b\f\n\r\t\v");
1.29      joris     152:                if (cp == NULL)
                    153:                        break;
                    154:                else if (*cp == '\0')
                    155:                        continue;
                    156:
                    157:                if (argc == argvlen) {
                    158:                        error++;
                    159:                        break;
                    160:                }
                    161:
1.53      joris     162:                argv[argc] = xstrdup(cp);
1.29      joris     163:                argc++;
                    164:        }
                    165:
                    166:        if (error != 0) {
                    167:                for (i = 0; i < (u_int)argc; i++)
1.53      joris     168:                        xfree(argv[i]);
1.29      joris     169:                argc = -1;
                    170:        }
                    171:
                    172:        return (argc);
                    173: }
                    174:
                    175: int
1.28      joris     176: rcs_getopt(int argc, char **argv, const char *optstr)
                    177: {
                    178:        char *a;
                    179:        const char *c;
                    180:        static int i = 1;
                    181:        int opt, hasargument, ret;
                    182:
                    183:        hasargument = 0;
                    184:        rcs_optarg = NULL;
                    185:
                    186:        if (i >= argc)
                    187:                return (-1);
                    188:
                    189:        a = argv[i++];
                    190:        if (*a++ != '-')
                    191:                return (-1);
                    192:
                    193:        ret = 0;
                    194:        opt = *a;
                    195:        for (c = optstr; *c != '\0'; c++) {
                    196:                if (*c == opt) {
                    197:                        a++;
                    198:                        ret = opt;
                    199:
                    200:                        if (*(c + 1) == ':') {
                    201:                                if (*(c + 2) == ':') {
                    202:                                        if (*a != '\0')
                    203:                                                hasargument = 1;
                    204:                                } else {
                    205:                                        if (*a != '\0') {
                    206:                                                hasargument = 1;
                    207:                                        } else {
                    208:                                                ret = 1;
                    209:                                                break;
                    210:                                        }
                    211:                                }
                    212:                        }
                    213:
                    214:                        if (hasargument == 1)
                    215:                                rcs_optarg = a;
                    216:
                    217:                        if (ret == opt)
                    218:                                rcs_optind++;
                    219:                        break;
                    220:                }
                    221:        }
                    222:
                    223:        if (ret == 0)
                    224:                cvs_log(LP_ERR, "unknown option -%c", opt);
                    225:        else if (ret == 1)
                    226:                cvs_log(LP_ERR, "missing argument for option -%c", opt);
                    227:
                    228:        return (ret);
                    229: }
                    230:
                    231: int
1.9       joris     232: rcs_statfile(char *fname, char *out, size_t len)
                    233: {
1.62      xsa       234:        int found, strdir;
1.42      xsa       235:        char defaultsuffix[] = RCS_DEFAULT_SUFFIX;
1.9       joris     236:        char filev[MAXPATHLEN], fpath[MAXPATHLEN];
1.42      xsa       237:        char *ext, *slash;
1.9       joris     238:        struct stat st;
                    239:
1.42      xsa       240:        strdir = found = 0;
                    241:
                    242:        /* we might have gotten a RCS file as argument */
                    243:        if ((ext = strchr(fname, ',')) != NULL)
                    244:                *ext = '\0';
                    245:
                    246:        /* we might have gotten the RCS/ dir in the argument string */
                    247:        if (strstr(fname, RCSDIR) != NULL)
                    248:                strdir = 1;
                    249:
                    250:        if (rcs_suffixes != NULL)
                    251:                ext = rcs_suffixes;
                    252:        else
                    253:                ext = defaultsuffix;
1.43      xsa       254:
1.42      xsa       255:        for (;;) {
                    256:                /*
                    257:                 * GNU documentation says -x,v/ specifies two suffixes,
                    258:                 * namely the ,v one and an empty one (which matches
                    259:                 * everything).
                    260:                 * The problem is that they don't follow this rule at
                    261:                 * all, and their documentation seems flawed.
                    262:                 * We try to be compatible, so let's do so.
                    263:                 */
                    264:                if (*ext == '\0')
                    265:                        break;
                    266:
                    267:                if ((slash = strchr(ext, '/')) != NULL)
                    268:                        *slash = '\0';
1.9       joris     269:
1.62      xsa       270:                if (strlcpy(filev, fname, sizeof(filev)) >= sizeof(filev) ||
                    271:                    strlcat(filev, ext, sizeof(filev)) >= sizeof(filev))
1.55      xsa       272:                        fatal("rcs_statfile: path truncation");
1.42      xsa       273:
                    274:                if ((strdir == 0) &&
                    275:                    (stat(RCSDIR, &st) != -1) && (st.st_mode & S_IFDIR)) {
1.62      xsa       276:                        if (strlcpy(fpath, RCSDIR,
                    277:                            sizeof(fpath)) >= sizeof(fpath) ||
                    278:                            strlcat(fpath, "/",
                    279:                            sizeof(fpath)) >= sizeof(fpath) ||
                    280:                            strlcat(fpath, filev,
                    281:                            sizeof(fpath)) >= sizeof(fpath))
1.55      xsa       282:                                fatal("rcs_statfile: path truncation");
1.42      xsa       283:                } else {
1.62      xsa       284:                        if (strlcpy(fpath, filev,
                    285:                            sizeof(fpath)) >= sizeof(fpath))
1.57      xsa       286:                                fatal("rcs_statfile: path truncation");
1.42      xsa       287:                }
                    288:
1.56      joris     289:                if ((stat(fpath, &st) != -1) || (rcsflags & RCS_CREATE)) {
1.42      xsa       290:                        found++;
                    291:                        break;
                    292:                }
                    293:
                    294:                if (slash == NULL)
                    295:                        break;
                    296:
                    297:                *slash++ = '/';
                    298:                ext = slash;
1.9       joris     299:        }
                    300:
1.42      xsa       301:        if (found != 1) {
1.44      niallo    302:                if ((strcmp(__progname, "rcsclean") != 0)
                    303:                    && (strcmp(__progname, "ci") != 0))
1.20      joris     304:                        cvs_log(LP_ERRNO, "%s", fpath);
1.9       joris     305:                return (-1);
                    306:        }
                    307:
1.62      xsa       308:        if (strlcpy(out, fpath, len) >= len)
1.57      xsa       309:                fatal("rcs_statfile: path truncation");
1.9       joris     310:
                    311:        return (0);
                    312: }
1.1       deraadt   313:
                    314: int
                    315: main(int argc, char **argv)
                    316: {
                    317:        u_int i;
1.29      joris     318:        char *rcsinit, *cmd_argv[RCS_CMD_MAXARG];
                    319:        int ret, cmd_argc;
1.1       deraadt   320:
                    321:        ret = -1;
1.28      joris     322:        rcs_optind = 1;
1.9       joris     323:        cvs_log_init(LD_STD, 0);
1.68      joris     324:        SLIST_INIT(&rcs_temp_files);
1.1       deraadt   325:
1.29      joris     326:        cmd_argc = 0;
1.30      joris     327:        cmd_argv[cmd_argc++] = argv[0];
1.29      joris     328:        if ((rcsinit = getenv("RCSINIT")) != NULL) {
                    329:                ret = rcs_init(rcsinit, cmd_argv + 1,
                    330:                    RCS_CMD_MAXARG - 1);
                    331:                if (ret < 0) {
                    332:                        cvs_log(LP_ERRNO, "failed to prepend RCSINIT options");
                    333:                        exit (1);
                    334:                }
                    335:
                    336:                cmd_argc += ret;
                    337:        }
1.36      xsa       338:
                    339:        if ((rcs_tmpdir = getenv("TMPDIR")) == NULL)
                    340:                rcs_tmpdir = RCS_TMPDIR_DEFAULT;
1.29      joris     341:
                    342:        for (ret = 1; ret < argc; ret++)
                    343:                cmd_argv[cmd_argc++] = argv[ret];
1.68      joris     344:
                    345:        signal(SIGHUP, sighdlr);
                    346:        signal(SIGINT, sighdlr);
                    347:        signal(SIGQUIT, sighdlr);
                    348:        signal(SIGABRT, sighdlr);
                    349:        signal(SIGALRM, sighdlr);
                    350:        signal(SIGTERM, sighdlr);
1.29      joris     351:
1.1       deraadt   352:        for (i = 0; i < (sizeof(programs)/sizeof(programs[0])); i++)
1.2       deraadt   353:                if (strcmp(__progname, programs[i].prog_name) == 0) {
                    354:                        usage = programs[i].prog_usage;
1.29      joris     355:                        ret = programs[i].prog_hdlr(cmd_argc, cmd_argv);
1.2       deraadt   356:                        break;
                    357:                }
1.1       deraadt   358:
1.23      niallo    359:        exit(ret);
1.1       deraadt   360: }
                    361:
                    362:
                    363: void
                    364: rcs_usage(void)
                    365: {
                    366:        fprintf(stderr,
1.66      jmc       367:            "usage: rcs [-ehIiLMqTUV] [-Aoldfile] [-ausers] [-b[rev]]\n"
1.67      xsa       368:            "           [-cstring] [-e[users]] [-kmode] [-mrev:msg]\n"
1.66      jmc       369:            "           [-orev] [-sstate[:rev]] [-tfile|str]\n"
1.67      xsa       370:            "           [-xsuffixes] file ...\n");
1.1       deraadt   371: }
                    372:
                    373: /*
                    374:  * rcs_main()
                    375:  *
                    376:  * Handler for the `rcs' program.
                    377:  * Returns 0 on success, or >0 on error.
                    378:  */
                    379: int
                    380: rcs_main(int argc, char **argv)
                    381: {
                    382:        int i, ch, flags, kflag, lkmode;
1.39      xsa       383:        char fpath[MAXPATHLEN], ofpath[MAXPATHLEN];
1.56      joris     384:        char *logstr, *logmsg, *nflag, *descfile;
1.39      xsa       385:        char *alist, *comment, *elist, *unp, *sp;
1.1       deraadt   386:        mode_t fmode;
1.39      xsa       387:        RCSFILE *file, *oldfile;
1.24      joris     388:        RCSNUM *logrev;
1.39      xsa       389:        struct rcs_access *acp;
1.48      xsa       390:        time_t rcs_mtime = -1;
1.1       deraadt   391:
                    392:        kflag = lkmode = -1;
                    393:        fmode = 0;
1.58      niallo    394:        flags = RCS_RDWR|RCS_PARSE_FULLY;
1.56      joris     395:        descfile = nflag = NULL;
1.39      xsa       396:        logstr = alist = comment = elist = NULL;
1.1       deraadt   397:
1.51      xsa       398:        while ((ch = rcs_getopt(argc, argv, RCSPROG_OPTSTRING)) != -1) {
1.1       deraadt   399:                switch (ch) {
                    400:                case 'A':
1.39      xsa       401:                        if (rcs_statfile(rcs_optarg, ofpath, sizeof(ofpath)) < 0)
                    402:                                exit(1);
1.56      joris     403:                        rcsflags |= CO_ACLAPPEND;
1.1       deraadt   404:                        break;
                    405:                case 'a':
1.28      joris     406:                        alist = rcs_optarg;
1.1       deraadt   407:                        break;
                    408:                case 'c':
1.28      joris     409:                        comment = rcs_optarg;
1.1       deraadt   410:                        break;
                    411:                case 'e':
1.28      joris     412:                        elist = rcs_optarg;
1.1       deraadt   413:                        break;
                    414:                case 'h':
1.2       deraadt   415:                        (usage)();
1.1       deraadt   416:                        exit(0);
                    417:                case 'i':
                    418:                        flags |= RCS_CREATE;
1.56      joris     419:                        rcsflags |= RCS_CREATE;
1.1       deraadt   420:                        break;
                    421:                case 'k':
1.28      joris     422:                        kflag = rcs_kflag_get(rcs_optarg);
1.1       deraadt   423:                        if (RCS_KWEXP_INVAL(kflag)) {
                    424:                                cvs_log(LP_ERR,
                    425:                                    "invalid keyword substitution mode `%s'",
1.28      joris     426:                                    rcs_optarg);
1.1       deraadt   427:                                exit(1);
                    428:                        }
                    429:                        break;
                    430:                case 'L':
                    431:                        if (lkmode == RCS_LOCK_LOOSE)
                    432:                                cvs_log(LP_WARN, "-U overriden by -L");
                    433:                        lkmode = RCS_LOCK_STRICT;
                    434:                        break;
1.24      joris     435:                case 'm':
1.53      joris     436:                        logstr = xstrdup(rcs_optarg);
1.24      joris     437:                        break;
1.1       deraadt   438:                case 'M':
                    439:                        /* ignore for the moment */
                    440:                        break;
1.56      joris     441:                case 'n':
                    442:                        nflag = xstrdup(rcs_optarg);
                    443:                        break;
                    444:                case 'N':
                    445:                        nflag = xstrdup(rcs_optarg);
                    446:                        rcsflags |= RCS_NFLAG;
                    447:                        break;
1.12      joris     448:                case 'q':
                    449:                        verbose = 0;
1.46      xsa       450:                        break;
1.56      joris     451:                case 't':
                    452:                        descfile = rcs_optarg;
                    453:                        rcsflags |= RCS_TFLAG;
                    454:                        break;
1.46      xsa       455:                case 'T':
1.56      joris     456:                        rcsflags |= PRESERVETIME;
1.12      joris     457:                        break;
1.1       deraadt   458:                case 'U':
                    459:                        if (lkmode == RCS_LOCK_STRICT)
                    460:                                cvs_log(LP_WARN, "-L overriden by -U");
                    461:                        lkmode = RCS_LOCK_LOOSE;
                    462:                        break;
                    463:                case 'V':
                    464:                        printf("%s\n", rcs_version);
                    465:                        exit(0);
1.45      xsa       466:                case 'x':
                    467:                        rcs_suffixes = rcs_optarg;
1.51      xsa       468:                        break;
                    469:                case 'z':
                    470:                        /*
                    471:                         * kept for compatibility
                    472:                         */
1.45      xsa       473:                        break;
1.1       deraadt   474:                default:
1.2       deraadt   475:                        (usage)();
1.1       deraadt   476:                        exit(1);
                    477:                }
                    478:        }
                    479:
1.28      joris     480:        argc -= rcs_optind;
                    481:        argv += rcs_optind;
1.30      joris     482:
1.1       deraadt   483:        if (argc == 0) {
                    484:                cvs_log(LP_ERR, "no input file");
1.5       joris     485:                (usage)();
1.1       deraadt   486:                exit(1);
                    487:        }
                    488:
                    489:        for (i = 0; i < argc; i++) {
1.9       joris     490:                if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
1.8       joris     491:                        continue;
1.6       joris     492:
1.35      niallo    493:                if (verbose == 1)
                    494:                        printf("RCS file: %s\n", fpath);
1.48      xsa       495:
1.49      niallo    496:                if ((file = rcs_open(fpath, flags, fmode)) == NULL)
1.6       joris     497:                        continue;
1.1       deraadt   498:
1.56      joris     499:                if (rcsflags & RCS_CREATE)
                    500:                        rcs_set_description(file, NULL);
                    501:
                    502:                if (rcsflags & RCS_TFLAG)
                    503:                        rcs_set_description(file, descfile);
                    504:
                    505:                if (rcsflags & PRESERVETIME)
1.48      xsa       506:                        rcs_mtime = rcs_get_mtime(file->rf_path);
                    507:
1.56      joris     508:                if (nflag != NULL)
                    509:                        rcs_attach_symbol(file, nflag);
                    510:
1.24      joris     511:                if (logstr != NULL) {
                    512:                        if ((logmsg = strchr(logstr, ':')) == NULL) {
                    513:                                cvs_log(LP_ERR, "missing log message");
                    514:                                rcs_close(file);
                    515:                                continue;
                    516:                        }
                    517:
                    518:                        *logmsg++ = '\0';
                    519:                        if ((logrev = rcsnum_parse(logstr)) == NULL) {
1.48      xsa       520:                                cvs_log(LP_ERR,
                    521:                                    "'%s' bad revision number", logstr);
1.24      joris     522:                                rcs_close(file);
                    523:                                continue;
                    524:                        }
                    525:
                    526:                        if (rcs_rev_setlog(file, logrev, logmsg) < 0) {
                    527:                                cvs_log(LP_ERR,
                    528:                                    "failed to set logmsg for '%s' to '%s'",
                    529:                                    logstr, logmsg);
                    530:                                rcs_close(file);
1.25      joris     531:                                rcsnum_free(logrev);
1.24      joris     532:                                continue;
                    533:                        }
                    534:
                    535:                        rcsnum_free(logrev);
1.39      xsa       536:                }
                    537:
                    538:                /* entries to add from <oldfile> */
1.56      joris     539:                if (rcsflags & CO_ACLAPPEND) {
1.39      xsa       540:                        /* XXX */
                    541:                        if ((oldfile = rcs_open(ofpath, RCS_READ)) == NULL)
                    542:                                exit(1);
                    543:
                    544:                        TAILQ_FOREACH(acp, &(oldfile->rf_access), ra_list)
                    545:                                rcs_access_add(file, acp->ra_name);
                    546:
                    547:                        rcs_close(oldfile);
1.24      joris     548:                }
                    549:
1.1       deraadt   550:                /* entries to add to the access list */
                    551:                if (alist != NULL) {
                    552:                        unp = alist;
                    553:                        do {
                    554:                                sp = strchr(unp, ',');
                    555:                                if (sp != NULL)
                    556:                                        *(sp++) = '\0';
                    557:
                    558:                                rcs_access_add(file, unp);
                    559:
                    560:                                unp = sp;
                    561:                        } while (sp != NULL);
                    562:                }
                    563:
                    564:                if (comment != NULL)
                    565:                        rcs_comment_set(file, comment);
                    566:
                    567:                if (kflag != -1)
                    568:                        rcs_kwexp_set(file, kflag);
                    569:
                    570:                if (lkmode != -1)
                    571:                        rcs_lock_setmode(file, lkmode);
                    572:
                    573:                rcs_close(file);
1.48      xsa       574:
1.56      joris     575:                if (rcsflags & PRESERVETIME)
1.48      xsa       576:                        rcs_set_mtime(fpath, rcs_mtime);
1.9       joris     577:
1.14      xsa       578:                if (verbose == 1)
1.12      joris     579:                        printf("done\n");
1.1       deraadt   580:        }
1.24      joris     581:
                    582:        if (logstr != NULL)
1.53      joris     583:                xfree(logstr);
1.1       deraadt   584:
1.56      joris     585:        if (nflag != NULL)
                    586:                xfree(nflag);
                    587:
1.1       deraadt   588:        return (0);
1.56      joris     589: }
                    590:
                    591: static void
                    592: rcs_attach_symbol(RCSFILE *file, const char *symname)
                    593: {
                    594:        char *rnum;
                    595:        RCSNUM *rev;
                    596:        char rbuf[16];
                    597:        int rm;
                    598:
                    599:        rm = 0;
                    600:        rev = NULL;
                    601:        if ((rnum = strrchr(symname, ':')) != NULL) {
                    602:                if (rnum[1] == '\0')
                    603:                        rev = file->rf_head;
                    604:                *(rnum++) = '\0';
                    605:        } else {
                    606:                rm = 1;
                    607:        }
                    608:
                    609:        if (rev == NULL && rm != 1) {
                    610:                if ((rev = rcsnum_parse(rnum)) == NULL)
                    611:                        fatal("bad revision %s", rnum);
                    612:        }
                    613:
                    614:        if (rcsflags & RCS_NFLAG)
                    615:                rm = 1;
                    616:
                    617:        if (rm == 1) {
                    618:                if (rcs_sym_remove(file, symname) < 0) {
                    619:                        if ((rcs_errno == RCS_ERR_NOENT) &&
                    620:                            !(rcsflags & RCS_NFLAG))
                    621:                                cvs_log(LP_WARN,
                    622:                                    "can't delete nonexisting symbol %s", symname);
                    623:                } else {
                    624:                        if (rcsflags & RCS_NFLAG)
                    625:                                rm = 0;
                    626:                }
                    627:        }
                    628:
                    629:        if (rm == 0) {
                    630:                if ((rcs_sym_add(file, symname, rev) < 0) &&
                    631:                    (rcs_errno == RCS_ERR_DUPENT)) {
                    632:                        rcsnum_tostr(rcs_sym_getrev(file, symname),
                    633:                            rbuf, sizeof(rbuf));
                    634:                        fatal("symbolic name %s already bound to %s",
                    635:                            symname, rbuf);
                    636:                }
                    637:        }
                    638: }
                    639:
                    640: static void
                    641: rcs_set_description(RCSFILE *file, const char *in)
                    642: {
                    643:        BUF *bp;
                    644:        char *content, buf[128];
                    645:
                    646:        content = NULL;
                    647:        if (in != NULL) {
                    648:                bp = cvs_buf_load(in, BUF_AUTOEXT);
                    649:        } else {
                    650:                bp = cvs_buf_alloc(64, BUF_AUTOEXT);
                    651:
                    652:                printf(DESC_PROMPT);
                    653:                for (;;) {
                    654:                        fgets(buf, sizeof(buf), stdin);
                    655:                        if (feof(stdin) || ferror(stdin) || buf[0] == '.')
                    656:                                break;
                    657:                        cvs_buf_append(bp, buf, strlen(buf));
                    658:                        printf(">> ");
                    659:                }
                    660:        }
                    661:
                    662:        cvs_buf_putc(bp, '\0');
                    663:        content = cvs_buf_release(bp);
                    664:
                    665:        rcs_desc_set(file, content);
1.1       deraadt   666: }