Annotation of src/usr.bin/rcs/rcsprog.c, Revision 1.96
1.96 ! ray 1: /* $OpenBSD: rcsprog.c,v 1.95 2006/04/10 08:08: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:
1.95 xsa 443: kflag = RCS_KWEXP_ERR;
444: lkmode = -1;
1.89 niallo 445: fmode = S_IRUSR|S_IRGRP|S_IROTH;
1.58 niallo 446: flags = RCS_RDWR|RCS_PARSE_FULLY;
1.92 ray 447: lrev = urev = descfile = nflag = NULL;
1.39 xsa 448: logstr = alist = comment = elist = NULL;
1.1 deraadt 449:
1.51 xsa 450: while ((ch = rcs_getopt(argc, argv, RCSPROG_OPTSTRING)) != -1) {
1.1 deraadt 451: switch (ch) {
452: case 'A':
1.39 xsa 453: if (rcs_statfile(rcs_optarg, ofpath, sizeof(ofpath)) < 0)
454: exit(1);
1.56 joris 455: rcsflags |= CO_ACLAPPEND;
1.1 deraadt 456: break;
457: case 'a':
1.28 joris 458: alist = rcs_optarg;
1.1 deraadt 459: break;
460: case 'c':
1.28 joris 461: comment = rcs_optarg;
1.1 deraadt 462: break;
463: case 'e':
1.28 joris 464: elist = rcs_optarg;
1.87 ray 465: rcsflags |= RCSPROG_EFLAG;
1.1 deraadt 466: break;
467: case 'h':
1.2 deraadt 468: (usage)();
1.1 deraadt 469: exit(0);
1.76 ray 470: /* NOTREACHED */
1.1 deraadt 471: case 'i':
472: flags |= RCS_CREATE;
473: break;
474: case 'k':
1.28 joris 475: kflag = rcs_kflag_get(rcs_optarg);
1.1 deraadt 476: if (RCS_KWEXP_INVAL(kflag)) {
477: cvs_log(LP_ERR,
478: "invalid keyword substitution mode `%s'",
1.28 joris 479: rcs_optarg);
1.1 deraadt 480: exit(1);
481: }
482: break;
483: case 'L':
484: if (lkmode == RCS_LOCK_LOOSE)
485: cvs_log(LP_WARN, "-U overriden by -L");
486: lkmode = RCS_LOCK_STRICT;
487: break;
1.92 ray 488: case 'l':
489: /* XXX - Check with -u flag. */
490: lrev = rcs_optarg;
491: rcsflags |= RCSPROG_LFLAG;
492: break;
1.24 joris 493: case 'm':
1.53 joris 494: logstr = xstrdup(rcs_optarg);
1.24 joris 495: break;
1.1 deraadt 496: case 'M':
497: /* ignore for the moment */
498: break;
1.56 joris 499: case 'n':
500: nflag = xstrdup(rcs_optarg);
501: break;
502: case 'N':
503: nflag = xstrdup(rcs_optarg);
1.87 ray 504: rcsflags |= RCSPROG_NFLAG;
1.56 joris 505: break;
1.12 joris 506: case 'q':
507: verbose = 0;
1.46 xsa 508: break;
1.56 joris 509: case 't':
510: descfile = rcs_optarg;
1.87 ray 511: rcsflags |= RCSPROG_TFLAG;
1.56 joris 512: break;
1.46 xsa 513: case 'T':
1.56 joris 514: rcsflags |= PRESERVETIME;
1.12 joris 515: break;
1.1 deraadt 516: case 'U':
517: if (lkmode == RCS_LOCK_STRICT)
518: cvs_log(LP_WARN, "-L overriden by -U");
519: lkmode = RCS_LOCK_LOOSE;
520: break;
1.92 ray 521: case 'u':
522: /* XXX - Check with -l flag. */
523: urev = rcs_optarg;
524: rcsflags |= RCSPROG_UFLAG;
525: break;
1.1 deraadt 526: case 'V':
527: printf("%s\n", rcs_version);
528: exit(0);
1.76 ray 529: /* NOTREACHED */
1.45 xsa 530: case 'x':
1.85 ray 531: /* Use blank extension if none given. */
532: rcs_suffixes = rcs_optarg ? rcs_optarg : "";
1.51 xsa 533: break;
534: case 'z':
535: /*
536: * kept for compatibility
537: */
1.45 xsa 538: break;
1.1 deraadt 539: default:
1.2 deraadt 540: (usage)();
1.1 deraadt 541: exit(1);
542: }
543: }
544:
1.28 joris 545: argc -= rcs_optind;
546: argv += rcs_optind;
1.30 joris 547:
1.1 deraadt 548: if (argc == 0) {
549: cvs_log(LP_ERR, "no input file");
1.5 joris 550: (usage)();
1.1 deraadt 551: exit(1);
552: }
553:
554: for (i = 0; i < argc; i++) {
1.9 joris 555: if (rcs_statfile(argv[i], fpath, sizeof(fpath)) < 0)
1.8 joris 556: continue;
1.6 joris 557:
1.35 niallo 558: if (verbose == 1)
559: printf("RCS file: %s\n", fpath);
1.48 xsa 560:
1.49 niallo 561: if ((file = rcs_open(fpath, flags, fmode)) == NULL)
1.6 joris 562: continue;
1.1 deraadt 563:
1.87 ray 564: if (rcsflags & RCSPROG_TFLAG)
565: rcs_set_description(file, descfile);
566: else if (flags & RCS_CREATE)
1.56 joris 567: rcs_set_description(file, NULL);
568:
569: if (rcsflags & PRESERVETIME)
1.48 xsa 570: rcs_mtime = rcs_get_mtime(file->rf_path);
571:
1.56 joris 572: if (nflag != NULL)
573: rcs_attach_symbol(file, nflag);
574:
1.24 joris 575: if (logstr != NULL) {
576: if ((logmsg = strchr(logstr, ':')) == NULL) {
577: cvs_log(LP_ERR, "missing log message");
578: rcs_close(file);
579: continue;
580: }
581:
582: *logmsg++ = '\0';
583: if ((logrev = rcsnum_parse(logstr)) == NULL) {
1.48 xsa 584: cvs_log(LP_ERR,
585: "'%s' bad revision number", logstr);
1.24 joris 586: rcs_close(file);
587: continue;
588: }
589:
590: if (rcs_rev_setlog(file, logrev, logmsg) < 0) {
591: cvs_log(LP_ERR,
592: "failed to set logmsg for '%s' to '%s'",
593: logstr, logmsg);
594: rcs_close(file);
1.25 joris 595: rcsnum_free(logrev);
1.24 joris 596: continue;
597: }
598:
599: rcsnum_free(logrev);
1.39 xsa 600: }
601:
602: /* entries to add from <oldfile> */
1.56 joris 603: if (rcsflags & CO_ACLAPPEND) {
1.39 xsa 604: /* XXX */
605: if ((oldfile = rcs_open(ofpath, RCS_READ)) == NULL)
606: exit(1);
607:
608: TAILQ_FOREACH(acp, &(oldfile->rf_access), ra_list)
609: rcs_access_add(file, acp->ra_name);
610:
611: rcs_close(oldfile);
1.24 joris 612: }
613:
1.1 deraadt 614: /* entries to add to the access list */
615: if (alist != NULL) {
1.86 pat 616: struct cvs_argvector *aargv;
1.1 deraadt 617:
1.79 xsa 618: aargv = cvs_strsplit(alist, ",");
1.86 pat 619: for (j = 0; aargv->argv[j] != NULL; j++)
620: rcs_access_add(file, aargv->argv[j]);
1.1 deraadt 621:
1.86 pat 622: cvs_argv_destroy(aargv);
1.1 deraadt 623: }
624:
625: if (comment != NULL)
626: rcs_comment_set(file, comment);
1.82 xsa 627:
628: if (elist != NULL) {
1.86 pat 629: struct cvs_argvector *eargv;
1.82 xsa 630:
631: eargv = cvs_strsplit(elist, ",");
1.86 pat 632: for (j = 0; eargv->argv[j] != NULL; j++)
633: rcs_access_remove(file, eargv->argv[j]);
1.82 xsa 634:
1.86 pat 635: cvs_argv_destroy(eargv);
1.87 ray 636: } else if (rcsflags & RCSPROG_EFLAG) {
1.82 xsa 637: struct rcs_access *rap;
638:
639: /* XXX rcs_access_remove(file, NULL); ?? */
640: while (!TAILQ_EMPTY(&(file->rf_access))) {
641: rap = TAILQ_FIRST(&(file->rf_access));
642: TAILQ_REMOVE(&(file->rf_access), rap, ra_list);
643: xfree(rap->ra_name);
644: xfree(rap);
645: }
646: /* not synced anymore */
647: file->rf_flags &= ~RCS_SYNCED;
648: }
1.1 deraadt 649:
1.95 xsa 650: rcs_kwexp_set(file, kflag);
1.1 deraadt 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");
1.96 ! ray 672: if (rcs_lock_add(file, username, rev) == -1)
1.92 ray 673: fatal("unable to lock file");
674: rcsnum_free(rev);
675: }
676:
677: if (rcsflags & RCSPROG_UFLAG) {
678: RCSNUM *rev;
679: const char *username;
680:
681: if ((username = getlogin()) == NULL)
682: fatal("could not get username");
683: if (urev == NULL) {
684: rev = rcsnum_alloc();
685: rcsnum_cpy(file->rf_head, rev, 0);
686: } else if ((rev = rcsnum_parse(urev)) == NULL) {
687: cvs_log(LP_ERR, "unable to unlock file");
688: rcs_close(file);
689: continue;
690: }
691: /* Make sure revision exists. */
692: if (rcs_findrev(file, rev) == NULL)
693: fatal("revision does not exist");
1.96 ! ray 694: if (rcs_lock_remove(file, username, rev) == -1)
1.92 ray 695: fatal("unable to unlock file");
696: rcsnum_free(rev);
697: }
1.1 deraadt 698:
699: rcs_close(file);
1.48 xsa 700:
1.56 joris 701: if (rcsflags & PRESERVETIME)
1.48 xsa 702: rcs_set_mtime(fpath, rcs_mtime);
1.9 joris 703:
1.14 xsa 704: if (verbose == 1)
1.12 joris 705: printf("done\n");
1.1 deraadt 706: }
1.24 joris 707:
708: if (logstr != NULL)
1.53 joris 709: xfree(logstr);
1.1 deraadt 710:
1.56 joris 711: if (nflag != NULL)
712: xfree(nflag);
713:
1.1 deraadt 714: return (0);
1.56 joris 715: }
716:
717: static void
718: rcs_attach_symbol(RCSFILE *file, const char *symname)
719: {
720: char *rnum;
721: RCSNUM *rev;
722: char rbuf[16];
723: int rm;
724:
725: rm = 0;
726: rev = NULL;
727: if ((rnum = strrchr(symname, ':')) != NULL) {
728: if (rnum[1] == '\0')
729: rev = file->rf_head;
730: *(rnum++) = '\0';
731: } else {
732: rm = 1;
733: }
734:
735: if (rev == NULL && rm != 1) {
736: if ((rev = rcsnum_parse(rnum)) == NULL)
737: fatal("bad revision %s", rnum);
738: }
739:
1.87 ray 740: if (rcsflags & RCSPROG_NFLAG)
1.56 joris 741: rm = 1;
742:
743: if (rm == 1) {
744: if (rcs_sym_remove(file, symname) < 0) {
745: if ((rcs_errno == RCS_ERR_NOENT) &&
1.87 ray 746: !(rcsflags & RCSPROG_NFLAG))
1.56 joris 747: cvs_log(LP_WARN,
748: "can't delete nonexisting symbol %s", symname);
749: } else {
1.87 ray 750: if (rcsflags & RCSPROG_NFLAG)
1.56 joris 751: rm = 0;
752: }
753: }
754:
755: if (rm == 0) {
756: if ((rcs_sym_add(file, symname, rev) < 0) &&
757: (rcs_errno == RCS_ERR_DUPENT)) {
758: rcsnum_tostr(rcs_sym_getrev(file, symname),
759: rbuf, sizeof(rbuf));
760: fatal("symbolic name %s already bound to %s",
761: symname, rbuf);
762: }
763: }
764: }
765:
1.88 ray 766: /*
767: * Load description from <in> to <file>.
768: * If <in> starts with a `-', <in> is taken as the description.
769: * Otherwise <in> is the name of the file containing the description.
770: * If <in> is NULL, the description is read from stdin.
771: */
1.56 joris 772: static void
773: rcs_set_description(RCSFILE *file, const char *in)
774: {
775: BUF *bp;
776: char *content, buf[128];
777:
778: content = NULL;
1.88 ray 779: /* Description is in file <in>. */
780: if (in != NULL && *in != '-')
1.56 joris 781: bp = cvs_buf_load(in, BUF_AUTOEXT);
1.88 ray 782: /* Description is in <in>. */
783: else if (in != NULL) {
784: size_t len;
785: const char *desc;
786:
787: /* Skip leading `-'. */
788: desc = in + 1;
789: len = strlen(desc);
790:
791: bp = cvs_buf_alloc(len + 1, BUF_AUTOEXT);
792: cvs_buf_append(bp, desc, len);
793: /* Get description from stdin. */
1.56 joris 794: } else {
795: bp = cvs_buf_alloc(64, BUF_AUTOEXT);
796:
1.90 xsa 797: if (isatty(STDIN_FILENO))
798: (void)fprintf(stderr, "%s", DESC_PROMPT);
1.56 joris 799: for (;;) {
1.88 ray 800: /* XXX - fgetln() may be more elegant. */
1.56 joris 801: fgets(buf, sizeof(buf), stdin);
1.88 ray 802: if (feof(stdin) || ferror(stdin) ||
803: strcmp(buf, ".\n") == 0 ||
804: strcmp(buf, ".") == 0)
1.56 joris 805: break;
806: cvs_buf_append(bp, buf, strlen(buf));
1.90 xsa 807: if (isatty(STDIN_FILENO))
808: (void)fprintf(stderr, ">> ");
1.56 joris 809: }
810: }
811:
812: cvs_buf_putc(bp, '\0');
813: content = cvs_buf_release(bp);
814:
815: rcs_desc_set(file, content);
1.70 joris 816: xfree(content);
1.1 deraadt 817: }