Annotation of src/usr.bin/rcs/rcsprog.c, Revision 1.83
1.83 ! ray 1: /* $OpenBSD: rcsprog.c,v 1.82 2006/03/21 08:34:36 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.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.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':
529: rcs_suffixes = rcs_optarg;
1.51 xsa 530: break;
531: case 'z':
532: /*
533: * kept for compatibility
534: */
1.45 xsa 535: break;
1.1 deraadt 536: default:
1.2 deraadt 537: (usage)();
1.1 deraadt 538: exit(1);
539: }
540: }
541:
1.28 joris 542: argc -= rcs_optind;
543: argv += rcs_optind;
1.30 joris 544:
1.1 deraadt 545: if (argc == 0) {
546: cvs_log(LP_ERR, "no input file");
1.5 joris 547: (usage)();
1.1 deraadt 548: exit(1);
549: }
550:
551: for (i = 0; i < argc; i++) {
1.9 joris 552: if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
1.8 joris 553: continue;
1.6 joris 554:
1.35 niallo 555: if (verbose == 1)
556: printf("RCS file: %s\n", fpath);
1.48 xsa 557:
1.49 niallo 558: if ((file = rcs_open(fpath, flags, fmode)) == NULL)
1.6 joris 559: continue;
1.1 deraadt 560:
1.56 joris 561: if (rcsflags & RCS_CREATE)
562: rcs_set_description(file, NULL);
563:
564: if (rcsflags & RCS_TFLAG)
565: rcs_set_description(file, descfile);
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.79 xsa 614: char **aargv;
1.1 deraadt 615:
1.79 xsa 616: aargv = cvs_strsplit(alist, ",");
617: for (j = 0; aargv[j] != NULL; j++)
618: rcs_access_add(file, aargv[j]);
1.1 deraadt 619:
1.79 xsa 620: xfree(aargv);
1.1 deraadt 621: }
622:
623: if (comment != NULL)
624: rcs_comment_set(file, comment);
1.82 xsa 625:
626: if (elist != NULL) {
627: char **eargv;
628:
629: eargv = cvs_strsplit(elist, ",");
630: for (j = 0; eargv[j] != NULL; j++)
631: rcs_access_remove(file, eargv[j]);
632:
633: xfree(eargv);
634: } else if (rcsflags & RCS_EFLAG) {
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)
652: rcs_lock_setmode(file, lkmode);
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:
695: if (rcsflags & RCS_NFLAG)
696: rm = 1;
697:
698: if (rm == 1) {
699: if (rcs_sym_remove(file, symname) < 0) {
700: if ((rcs_errno == RCS_ERR_NOENT) &&
701: !(rcsflags & RCS_NFLAG))
702: cvs_log(LP_WARN,
703: "can't delete nonexisting symbol %s", symname);
704: } else {
705: if (rcsflags & RCS_NFLAG)
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: }