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