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