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

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