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