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