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

1.63    ! niallo      1: /*     $OpenBSD: rcsprog.c,v 1.62 2006/01/25 08:01:00 xsa 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.56      joris      67: static void rcs_set_description(RCSFILE *, const char *);
                     68: static void rcs_attach_symbol(RCSFILE *, const char *);
                     69:
1.31      joris      70: void
                     71: rcs_set_rev(const char *str, RCSNUM **rev)
                     72: {
1.63    ! niallo     73:        RCSNUM *t;
        !            74:
1.32      joris      75:        if (str == NULL)
                     76:                return;
                     77:
1.52      joris      78:        if ((*rev != NULL) && (*rev != RCS_HEAD_REV))
1.31      joris      79:                cvs_log(LP_WARN, "redefinition of revision number");
                     80:
1.55      xsa        81:        if ((*rev = rcsnum_parse(str)) == NULL)
                     82:                fatal("bad revision number '%s'", str);
1.63    ! niallo     83:         /*
        !            84:         * If 0 is specified as a revision number, exit and warn the user.
        !            85:         * This differs from GNU ci's plainly buggy behaviour, where 0 ends up
        !            86:         * being 0.1 and other weird stuff.
        !            87:         */
        !            88:        t = rcsnum_parse("0");
        !            89:        if (rcsnum_cmp(*rev, t, 0) == 0)
        !            90:                fatal("0 is not a valid revision number");
        !            91:        rcsnum_free(t);
        !            92:        /*
        !            93:         * If 1 is specified as revision number, silently assume 1.1.
        !            94:         * This is what GNU ci does.
        !            95:         */
        !            96:        t = rcsnum_parse(RCS_HEAD_INIT);
        !            97:        if (rcsnum_cmp(*rev, t, 0) > 0)
        !            98:                rcsnum_cpy(t, *rev, 0);
        !            99:        rcsnum_free(t);
        !           100:
1.47      xsa       101: }
                    102:
                    103: /*
                    104:  * rcs_get_mtime()
                    105:  *
                    106:  * Get <filename> last modified time.
                    107:  * Returns last modified time on success, or -1 on failure.
                    108:  */
                    109: time_t
                    110: rcs_get_mtime(const char *filename)
                    111: {
                    112:        struct stat st;
                    113:        time_t mtime;
                    114:
                    115:        if (stat(filename, &st) == -1) {
                    116:                cvs_log(LP_ERRNO, "failed to stat `%s'", filename);
                    117:                return (-1);
                    118:        }
                    119:        mtime = (time_t)st.st_mtimespec.tv_sec;
                    120:
                    121:        return (mtime);
                    122: }
                    123:
                    124: /*
                    125:  * rcs_set_mtime()
                    126:  *
                    127:  * Set <filename> last modified time to <mtime> if it's not set to -1.
                    128:  * Returns 0 on success, or -1 on failure.
                    129:  */
                    130: int
                    131: rcs_set_mtime(const char *filename, time_t mtime)
                    132: {
                    133:        static struct timeval tv[2];
                    134:
                    135:        if (mtime == -1)
                    136:                return (0);
                    137:
                    138:        tv[0].tv_sec = mtime;
                    139:        tv[1].tv_sec = tv[0].tv_sec;
                    140:
                    141:        if (utimes(filename, tv) == -1) {
                    142:                cvs_log(LP_ERRNO, "error setting utimes");
                    143:                return (-1);
                    144:        }
                    145:
                    146:        return (0);
1.31      joris     147: }
1.1       deraadt   148:
1.9       joris     149: int
1.29      joris     150: rcs_init(char *envstr, char **argv, int argvlen)
                    151: {
                    152:        u_int i;
                    153:        int argc, error;
                    154:        char linebuf[256],  *lp, *cp;
                    155:
                    156:        strlcpy(linebuf, envstr, sizeof(linebuf));
                    157:        memset(argv, 0, argvlen * sizeof(char *));
                    158:
                    159:        error = argc = 0;
                    160:        for (lp = linebuf; lp != NULL;) {
1.61      xsa       161:                cp = strsep(&lp, " \t\b\f\n\r\t\v");
1.29      joris     162:                if (cp == NULL)
                    163:                        break;
                    164:                else if (*cp == '\0')
                    165:                        continue;
                    166:
                    167:                if (argc == argvlen) {
                    168:                        error++;
                    169:                        break;
                    170:                }
                    171:
1.53      joris     172:                argv[argc] = xstrdup(cp);
1.29      joris     173:                argc++;
                    174:        }
                    175:
                    176:        if (error != 0) {
                    177:                for (i = 0; i < (u_int)argc; i++)
1.53      joris     178:                        xfree(argv[i]);
1.29      joris     179:                argc = -1;
                    180:        }
                    181:
                    182:        return (argc);
                    183: }
                    184:
                    185: int
1.28      joris     186: rcs_getopt(int argc, char **argv, const char *optstr)
                    187: {
                    188:        char *a;
                    189:        const char *c;
                    190:        static int i = 1;
                    191:        int opt, hasargument, ret;
                    192:
                    193:        hasargument = 0;
                    194:        rcs_optarg = NULL;
                    195:
                    196:        if (i >= argc)
                    197:                return (-1);
                    198:
                    199:        a = argv[i++];
                    200:        if (*a++ != '-')
                    201:                return (-1);
                    202:
                    203:        ret = 0;
                    204:        opt = *a;
                    205:        for (c = optstr; *c != '\0'; c++) {
                    206:                if (*c == opt) {
                    207:                        a++;
                    208:                        ret = opt;
                    209:
                    210:                        if (*(c + 1) == ':') {
                    211:                                if (*(c + 2) == ':') {
                    212:                                        if (*a != '\0')
                    213:                                                hasargument = 1;
                    214:                                } else {
                    215:                                        if (*a != '\0') {
                    216:                                                hasargument = 1;
                    217:                                        } else {
                    218:                                                ret = 1;
                    219:                                                break;
                    220:                                        }
                    221:                                }
                    222:                        }
                    223:
                    224:                        if (hasargument == 1)
                    225:                                rcs_optarg = a;
                    226:
                    227:                        if (ret == opt)
                    228:                                rcs_optind++;
                    229:                        break;
                    230:                }
                    231:        }
                    232:
                    233:        if (ret == 0)
                    234:                cvs_log(LP_ERR, "unknown option -%c", opt);
                    235:        else if (ret == 1)
                    236:                cvs_log(LP_ERR, "missing argument for option -%c", opt);
                    237:
                    238:        return (ret);
                    239: }
                    240:
                    241: int
1.9       joris     242: rcs_statfile(char *fname, char *out, size_t len)
                    243: {
1.62      xsa       244:        int found, strdir;
1.42      xsa       245:        char defaultsuffix[] = RCS_DEFAULT_SUFFIX;
1.9       joris     246:        char filev[MAXPATHLEN], fpath[MAXPATHLEN];
1.42      xsa       247:        char *ext, *slash;
1.9       joris     248:        struct stat st;
                    249:
1.42      xsa       250:        strdir = found = 0;
                    251:
                    252:        /* we might have gotten a RCS file as argument */
                    253:        if ((ext = strchr(fname, ',')) != NULL)
                    254:                *ext = '\0';
                    255:
                    256:        /* we might have gotten the RCS/ dir in the argument string */
                    257:        if (strstr(fname, RCSDIR) != NULL)
                    258:                strdir = 1;
                    259:
                    260:        if (rcs_suffixes != NULL)
                    261:                ext = rcs_suffixes;
                    262:        else
                    263:                ext = defaultsuffix;
1.43      xsa       264:
1.42      xsa       265:        for (;;) {
                    266:                /*
                    267:                 * GNU documentation says -x,v/ specifies two suffixes,
                    268:                 * namely the ,v one and an empty one (which matches
                    269:                 * everything).
                    270:                 * The problem is that they don't follow this rule at
                    271:                 * all, and their documentation seems flawed.
                    272:                 * We try to be compatible, so let's do so.
                    273:                 */
                    274:                if (*ext == '\0')
                    275:                        break;
                    276:
                    277:                if ((slash = strchr(ext, '/')) != NULL)
                    278:                        *slash = '\0';
1.9       joris     279:
1.62      xsa       280:                if (strlcpy(filev, fname, sizeof(filev)) >= sizeof(filev) ||
                    281:                    strlcat(filev, ext, sizeof(filev)) >= sizeof(filev))
1.55      xsa       282:                        fatal("rcs_statfile: path truncation");
1.42      xsa       283:
                    284:                if ((strdir == 0) &&
                    285:                    (stat(RCSDIR, &st) != -1) && (st.st_mode & S_IFDIR)) {
1.62      xsa       286:                        if (strlcpy(fpath, RCSDIR,
                    287:                            sizeof(fpath)) >= sizeof(fpath) ||
                    288:                            strlcat(fpath, "/",
                    289:                            sizeof(fpath)) >= sizeof(fpath) ||
                    290:                            strlcat(fpath, filev,
                    291:                            sizeof(fpath)) >= sizeof(fpath))
1.55      xsa       292:                                fatal("rcs_statfile: path truncation");
1.42      xsa       293:                } else {
1.62      xsa       294:                        if (strlcpy(fpath, filev,
                    295:                            sizeof(fpath)) >= sizeof(fpath))
1.57      xsa       296:                                fatal("rcs_statfile: path truncation");
1.42      xsa       297:                }
                    298:
1.56      joris     299:                if ((stat(fpath, &st) != -1) || (rcsflags & RCS_CREATE)) {
1.42      xsa       300:                        found++;
                    301:                        break;
                    302:                }
                    303:
                    304:                if (slash == NULL)
                    305:                        break;
                    306:
                    307:                *slash++ = '/';
                    308:                ext = slash;
1.9       joris     309:        }
                    310:
1.42      xsa       311:        if (found != 1) {
1.44      niallo    312:                if ((strcmp(__progname, "rcsclean") != 0)
                    313:                    && (strcmp(__progname, "ci") != 0))
1.20      joris     314:                        cvs_log(LP_ERRNO, "%s", fpath);
1.9       joris     315:                return (-1);
                    316:        }
                    317:
1.62      xsa       318:        if (strlcpy(out, fpath, len) >= len)
1.57      xsa       319:                fatal("rcs_statfile: path truncation");
1.9       joris     320:
                    321:        return (0);
                    322: }
1.1       deraadt   323:
                    324: int
                    325: main(int argc, char **argv)
                    326: {
                    327:        u_int i;
1.29      joris     328:        char *rcsinit, *cmd_argv[RCS_CMD_MAXARG];
                    329:        int ret, cmd_argc;
1.1       deraadt   330:
                    331:        ret = -1;
1.28      joris     332:        rcs_optind = 1;
1.9       joris     333:        cvs_log_init(LD_STD, 0);
1.1       deraadt   334:
1.29      joris     335:        cmd_argc = 0;
1.30      joris     336:        cmd_argv[cmd_argc++] = argv[0];
1.29      joris     337:        if ((rcsinit = getenv("RCSINIT")) != NULL) {
                    338:                ret = rcs_init(rcsinit, cmd_argv + 1,
                    339:                    RCS_CMD_MAXARG - 1);
                    340:                if (ret < 0) {
                    341:                        cvs_log(LP_ERRNO, "failed to prepend RCSINIT options");
                    342:                        exit (1);
                    343:                }
                    344:
                    345:                cmd_argc += ret;
                    346:        }
1.36      xsa       347:
                    348:        if ((rcs_tmpdir = getenv("TMPDIR")) == NULL)
                    349:                rcs_tmpdir = RCS_TMPDIR_DEFAULT;
1.29      joris     350:
                    351:        for (ret = 1; ret < argc; ret++)
                    352:                cmd_argv[cmd_argc++] = argv[ret];
                    353:
1.1       deraadt   354:        for (i = 0; i < (sizeof(programs)/sizeof(programs[0])); i++)
1.2       deraadt   355:                if (strcmp(__progname, programs[i].prog_name) == 0) {
                    356:                        usage = programs[i].prog_usage;
1.29      joris     357:                        ret = programs[i].prog_hdlr(cmd_argc, cmd_argv);
1.2       deraadt   358:                        break;
                    359:                }
1.1       deraadt   360:
1.23      niallo    361:        exit(ret);
1.1       deraadt   362: }
                    363:
                    364:
                    365: void
                    366: rcs_usage(void)
                    367: {
                    368:        fprintf(stderr,
1.50      xsa       369:            "usage: rcs [-hiLMTUV] [-Aoldfile] [-ausers] [-b[rev]] [-cstring]\n"
1.54      xsa       370:            "           [-eusers] [-kmode] [-mrev:msg] [-xsuffixes] [-ztz] 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: }