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