Annotation of src/usr.bin/cvs/rcs.c, Revision 1.92
1.92 ! joris 1: /* $OpenBSD: rcs.c,v 1.91 2005/10/16 17:44:15 joris Exp $ */
1.1 jfb 2: /*
3: * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org>
1.15 tedu 4: * All rights reserved.
1.1 jfb 5: *
1.15 tedu 6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
1.1 jfb 9: *
1.15 tedu 10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
1.1 jfb 12: * 2. The name of the author may not be used to endorse or promote products
1.15 tedu 13: * derived from this software without specific prior written permission.
1.1 jfb 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
1.15 tedu 24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.1 jfb 25: */
26:
27: #include <sys/param.h>
28: #include <sys/stat.h>
29:
1.55 xsa 30: #include <ctype.h>
31: #include <errno.h>
1.72 niallo 32: #include <fcntl.h>
1.63 joris 33: #include <libgen.h>
1.52 jfb 34: #include <pwd.h>
1.55 xsa 35: #include <stdarg.h>
1.1 jfb 36: #include <stdio.h>
37: #include <stdlib.h>
38: #include <string.h>
1.55 xsa 39: #include <unistd.h>
1.1 jfb 40:
1.55 xsa 41: #include "log.h"
1.1 jfb 42: #include "rcs.h"
1.81 niallo 43: #include "diff.h"
1.39 joris 44: #include "strtab.h"
1.1 jfb 45:
1.57 xsa 46: #define RCS_BUFSIZE 16384
47: #define RCS_BUFEXTSIZE 8192
1.1 jfb 48:
49:
50: /* RCS token types */
1.57 xsa 51: #define RCS_TOK_ERR -1
52: #define RCS_TOK_EOF 0
53: #define RCS_TOK_NUM 1
54: #define RCS_TOK_ID 2
55: #define RCS_TOK_STRING 3
56: #define RCS_TOK_SCOLON 4
57: #define RCS_TOK_COLON 5
58:
59:
60: #define RCS_TOK_HEAD 8
61: #define RCS_TOK_BRANCH 9
62: #define RCS_TOK_ACCESS 10
63: #define RCS_TOK_SYMBOLS 11
64: #define RCS_TOK_LOCKS 12
65: #define RCS_TOK_COMMENT 13
66: #define RCS_TOK_EXPAND 14
67: #define RCS_TOK_DATE 15
68: #define RCS_TOK_AUTHOR 16
69: #define RCS_TOK_STATE 17
70: #define RCS_TOK_NEXT 18
71: #define RCS_TOK_BRANCHES 19
72: #define RCS_TOK_DESC 20
73: #define RCS_TOK_LOG 21
74: #define RCS_TOK_TEXT 22
75: #define RCS_TOK_STRICT 23
1.1 jfb 76:
1.57 xsa 77: #define RCS_ISKEY(t) (((t) >= RCS_TOK_HEAD) && ((t) <= RCS_TOK_BRANCHES))
1.1 jfb 78:
79:
1.57 xsa 80: #define RCS_NOSCOL 0x01 /* no terminating semi-colon */
81: #define RCS_VOPT 0x02 /* value is optional */
1.1 jfb 82:
83:
84: /* opaque parse data */
85: struct rcs_pdata {
1.57 xsa 86: u_int rp_lines;
1.1 jfb 87:
1.57 xsa 88: char *rp_buf;
89: size_t rp_blen;
90: char *rp_bufend;
91: size_t rp_tlen;
1.1 jfb 92:
93: /* pushback token buffer */
1.57 xsa 94: char rp_ptok[128];
95: int rp_pttype; /* token type, RCS_TOK_ERR if no token */
1.1 jfb 96:
1.57 xsa 97: FILE *rp_file;
1.1 jfb 98: };
99:
100:
101: struct rcs_line {
1.57 xsa 102: char *rl_line;
103: int rl_lineno;
104: TAILQ_ENTRY(rcs_line) rl_list;
1.1 jfb 105: };
1.5 vincent 106: TAILQ_HEAD(rcs_tqh, rcs_line);
1.1 jfb 107:
108: struct rcs_foo {
1.57 xsa 109: int rl_nblines;
110: char *rl_data;
111: struct rcs_tqh rl_lines;
1.1 jfb 112: };
113:
1.57 xsa 114: #define RCS_TOKSTR(rfp) ((struct rcs_pdata *)rfp->rf_pdata)->rp_buf
115: #define RCS_TOKLEN(rfp) ((struct rcs_pdata *)rfp->rf_pdata)->rp_tlen
1.1 jfb 116:
117:
1.47 jfb 118:
119: /* invalid characters in RCS symbol names */
1.49 jfb 120: static const char rcs_sym_invch[] = RCS_SYM_INVALCHAR;
1.47 jfb 121:
1.51 jfb 122:
123: /* comment leaders, depending on the file's suffix */
124: static const struct rcs_comment {
1.57 xsa 125: const char *rc_suffix;
126: const char *rc_cstr;
1.51 jfb 127: } rcs_comments[] = {
128: { "1", ".\\\" " },
129: { "2", ".\\\" " },
130: { "3", ".\\\" " },
131: { "4", ".\\\" " },
132: { "5", ".\\\" " },
133: { "6", ".\\\" " },
134: { "7", ".\\\" " },
135: { "8", ".\\\" " },
136: { "9", ".\\\" " },
137: { "a", "-- " }, /* Ada */
138: { "ada", "-- " },
139: { "adb", "-- " },
140: { "asm", ";; " }, /* assembler (MS-DOS) */
141: { "ads", "-- " }, /* Ada */
142: { "bat", ":: " }, /* batch (MS-DOS) */
143: { "body", "-- " }, /* Ada */
144: { "c", " * " }, /* C */
145: { "c++", "// " }, /* C++ */
146: { "cc", "// " },
147: { "cpp", "// " },
148: { "cxx", "// " },
149: { "m", "// " }, /* Objective-C */
150: { "cl", ";;; " }, /* Common Lisp */
151: { "cmd", ":: " }, /* command (OS/2) */
152: { "cmf", "c " }, /* CM Fortran */
153: { "csh", "# " }, /* shell */
154: { "e", "# " }, /* efl */
155: { "epsf", "% " }, /* encapsulated postscript */
156: { "epsi", "% " }, /* encapsulated postscript */
157: { "el", "; " }, /* Emacs Lisp */
158: { "f", "c " }, /* Fortran */
159: { "for", "c " },
160: { "h", " * " }, /* C-header */
161: { "hh", "// " }, /* C++ header */
162: { "hpp", "// " },
163: { "hxx", "// " },
164: { "in", "# " }, /* for Makefile.in */
165: { "l", " * " }, /* lex */
166: { "mac", ";; " }, /* macro (DEC-10, MS-DOS, PDP-11, VMS, etc) */
167: { "mak", "# " }, /* makefile, e.g. Visual C++ */
168: { "me", ".\\\" " }, /* me-macros t/nroff */
169: { "ml", "; " }, /* mocklisp */
170: { "mm", ".\\\" " }, /* mm-macros t/nroff */
171: { "ms", ".\\\" " }, /* ms-macros t/nroff */
172: { "man", ".\\\" " }, /* man-macros t/nroff */
173: { "p", " * " }, /* pascal */
174: { "pas", " * " },
1.52 jfb 175: { "pl", "# " }, /* Perl (conflict with Prolog) */
176: { "pm", "# " }, /* Perl module */
1.51 jfb 177: { "ps", "% " }, /* postscript */
178: { "psw", "% " }, /* postscript wrap */
179: { "pswm", "% " }, /* postscript wrap */
180: { "r", "# " }, /* ratfor */
181: { "rc", " * " }, /* Microsoft Windows resource file */
182: { "red", "% " }, /* psl/rlisp */
183: { "sh", "# " }, /* shell */
184: { "sl", "% " }, /* psl */
185: { "spec", "-- " }, /* Ada */
186: { "tex", "% " }, /* tex */
187: { "y", " * " }, /* yacc */
188: { "ye", " * " }, /* yacc-efl */
189: { "yr", " * " }, /* yacc-ratfor */
190: };
191:
1.57 xsa 192: #define NB_COMTYPES (sizeof(rcs_comments)/sizeof(rcs_comments[0]))
1.51 jfb 193:
1.33 jfb 194: #ifdef notyet
1.20 jfb 195: static struct rcs_kfl {
1.57 xsa 196: char rk_char;
197: int rk_val;
1.20 jfb 198: } rcs_kflags[] = {
199: { 'k', RCS_KWEXP_NAME },
200: { 'v', RCS_KWEXP_VAL },
201: { 'l', RCS_KWEXP_LKR },
202: { 'o', RCS_KWEXP_OLD },
203: { 'b', RCS_KWEXP_NONE },
204: };
1.33 jfb 205: #endif
1.20 jfb 206:
1.1 jfb 207: static struct rcs_key {
1.57 xsa 208: char rk_str[16];
209: int rk_id;
210: int rk_val;
211: int rk_flags;
1.1 jfb 212: } rcs_keys[] = {
213: { "access", RCS_TOK_ACCESS, RCS_TOK_ID, RCS_VOPT },
1.41 jfb 214: { "author", RCS_TOK_AUTHOR, RCS_TOK_ID, 0 },
1.1 jfb 215: { "branch", RCS_TOK_BRANCH, RCS_TOK_NUM, RCS_VOPT },
216: { "branches", RCS_TOK_BRANCHES, RCS_TOK_NUM, RCS_VOPT },
217: { "comment", RCS_TOK_COMMENT, RCS_TOK_STRING, RCS_VOPT },
218: { "date", RCS_TOK_DATE, RCS_TOK_NUM, 0 },
219: { "desc", RCS_TOK_DESC, RCS_TOK_STRING, RCS_NOSCOL },
220: { "expand", RCS_TOK_EXPAND, RCS_TOK_STRING, RCS_VOPT },
221: { "head", RCS_TOK_HEAD, RCS_TOK_NUM, RCS_VOPT },
222: { "locks", RCS_TOK_LOCKS, RCS_TOK_ID, 0 },
223: { "log", RCS_TOK_LOG, RCS_TOK_STRING, RCS_NOSCOL },
224: { "next", RCS_TOK_NEXT, RCS_TOK_NUM, RCS_VOPT },
1.41 jfb 225: { "state", RCS_TOK_STATE, RCS_TOK_ID, RCS_VOPT },
1.1 jfb 226: { "strict", RCS_TOK_STRICT, 0, 0, },
227: { "symbols", RCS_TOK_SYMBOLS, 0, 0 },
228: { "text", RCS_TOK_TEXT, RCS_TOK_STRING, RCS_NOSCOL },
229: };
230:
1.57 xsa 231: #define RCS_NKEYS (sizeof(rcs_keys)/sizeof(rcs_keys[0]))
1.1 jfb 232:
1.33 jfb 233: /*
234: * Keyword expansion table
235: */
1.63 joris 236: #define RCS_KW_AUTHOR 0x1000
237: #define RCS_KW_DATE 0x2000
238: #define RCS_KW_LOG 0x4000
239: #define RCS_KW_NAME 0x8000
240: #define RCS_KW_RCSFILE 0x0100
241: #define RCS_KW_REVISION 0x0200
242: #define RCS_KW_SOURCE 0x0400
243: #define RCS_KW_STATE 0x0800
244: #define RCS_KW_FULLPATH 0x0010
245:
246: #define RCS_KW_ID \
247: (RCS_KW_RCSFILE | RCS_KW_REVISION | RCS_KW_DATE \
248: | RCS_KW_AUTHOR | RCS_KW_STATE)
249:
250: #define RCS_KW_HEADER (RCS_KW_ID | RCS_KW_FULLPATH)
251:
1.33 jfb 252: static struct rcs_kw {
1.57 xsa 253: char kw_str[16];
1.63 joris 254: int kw_type;
1.33 jfb 255: } rcs_expkw[] = {
1.63 joris 256: { "Author", RCS_KW_AUTHOR },
257: { "Date", RCS_KW_DATE },
258: { "Header", RCS_KW_HEADER },
259: { "Id", RCS_KW_ID },
260: { "Log", RCS_KW_LOG },
261: { "Name", RCS_KW_NAME },
262: { "RCSfile", RCS_KW_RCSFILE },
263: { "Revision", RCS_KW_REVISION },
264: { "Source", RCS_KW_SOURCE },
265: { "State", RCS_KW_STATE },
1.33 jfb 266: };
1.63 joris 267:
268: #define RCS_NKWORDS (sizeof(rcs_expkw)/sizeof(rcs_expkw[0]))
1.33 jfb 269:
1.32 jfb 270: static const char *rcs_errstrs[] = {
271: "No error",
272: "No such entry",
273: "Duplicate entry found",
274: "Bad RCS number",
1.48 jfb 275: "Invalid RCS symbol",
276: "Parse error",
1.32 jfb 277: };
278:
279: #define RCS_NERR (sizeof(rcs_errstrs)/sizeof(rcs_errstrs[0]))
280:
281:
282: int rcs_errno = RCS_ERR_NOERR;
283:
1.1 jfb 284:
1.57 xsa 285: static int rcs_write(RCSFILE *);
286: static int rcs_parse(RCSFILE *);
287: static int rcs_parse_admin(RCSFILE *);
288: static int rcs_parse_delta(RCSFILE *);
289: static int rcs_parse_deltatext(RCSFILE *);
290:
291: static int rcs_parse_access(RCSFILE *);
292: static int rcs_parse_symbols(RCSFILE *);
293: static int rcs_parse_locks(RCSFILE *);
294: static int rcs_parse_branches(RCSFILE *, struct rcs_delta *);
295: static void rcs_freedelta(struct rcs_delta *);
296: static void rcs_freepdata(struct rcs_pdata *);
297: static int rcs_gettok(RCSFILE *);
298: static int rcs_pushtok(RCSFILE *, const char *, int);
299: static int rcs_growbuf(RCSFILE *);
300: static int rcs_patch_lines(struct rcs_foo *, struct rcs_foo *);
301: static int rcs_strprint(const u_char *, size_t, FILE *);
302:
1.63 joris 303: static int rcs_expand_keywords(char *, struct rcs_delta *, char *, char *,
304: size_t, int);
1.57 xsa 305: static struct rcs_delta *rcs_findrev(RCSFILE *, const RCSNUM *);
306: static struct rcs_foo *rcs_splitlines(const char *);
307: static void rcs_freefoo(struct rcs_foo *);
1.26 jfb 308:
1.1 jfb 309: /*
310: * rcs_open()
311: *
312: * Open a file containing RCS-formatted information. The file's path is
1.26 jfb 313: * given in <path>, and the opening flags are given in <flags>, which is either
314: * RCS_READ, RCS_WRITE, or RCS_RDWR. If the open requests write access and
315: * the file does not exist, the RCS_CREATE flag must also be given, in which
316: * case it will be created with the mode specified in a third argument of
317: * type mode_t. If the file exists and RCS_CREATE is passed, the open will
318: * fail.
1.1 jfb 319: * Returns a handle to the opened file on success, or NULL on failure.
320: */
1.60 xsa 321: RCSFILE *
1.26 jfb 322: rcs_open(const char *path, int flags, ...)
1.1 jfb 323: {
1.26 jfb 324: int ret;
325: mode_t fmode;
1.1 jfb 326: RCSFILE *rfp;
327: struct stat st;
1.26 jfb 328: va_list vap;
329:
330: fmode = 0;
331: flags &= 0xffff; /* ditch any internal flags */
1.1 jfb 332:
1.26 jfb 333: if (((ret = stat(path, &st)) == -1) && (errno == ENOENT)) {
334: if (flags & RCS_CREATE) {
335: va_start(vap, flags);
336: fmode = va_arg(vap, mode_t);
337: va_end(vap);
338: } else {
1.50 jfb 339: rcs_errno = RCS_ERR_ERRNO;
1.26 jfb 340: cvs_log(LP_ERR, "RCS file `%s' does not exist", path);
341: return (NULL);
342: }
343: } else if ((ret == 0) && (flags & RCS_CREATE)) {
344: cvs_log(LP_ERR, "RCS file `%s' exists", path);
1.1 jfb 345: return (NULL);
346: }
347:
1.26 jfb 348: if ((rfp = (RCSFILE *)malloc(sizeof(*rfp))) == NULL) {
1.1 jfb 349: cvs_log(LP_ERRNO, "failed to allocate RCS file structure");
1.50 jfb 350: rcs_errno = RCS_ERR_ERRNO;
1.1 jfb 351: return (NULL);
352: }
353: memset(rfp, 0, sizeof(*rfp));
354:
1.26 jfb 355: if ((rfp->rf_path = strdup(path)) == NULL) {
1.50 jfb 356: rcs_errno = RCS_ERR_ERRNO;
1.1 jfb 357: cvs_log(LP_ERRNO, "failed to duplicate RCS file path");
1.26 jfb 358: free(rfp);
1.1 jfb 359: return (NULL);
360: }
361:
362: rfp->rf_ref = 1;
1.26 jfb 363: rfp->rf_flags = flags | RCS_SLOCK;
364: rfp->rf_mode = fmode;
1.1 jfb 365:
366: TAILQ_INIT(&(rfp->rf_delta));
1.29 jfb 367: TAILQ_INIT(&(rfp->rf_access));
1.1 jfb 368: TAILQ_INIT(&(rfp->rf_symbols));
369: TAILQ_INIT(&(rfp->rf_locks));
370:
1.26 jfb 371: if (rfp->rf_flags & RCS_CREATE) {
372: } else if (rcs_parse(rfp) < 0) {
1.1 jfb 373: rcs_close(rfp);
374: return (NULL);
375: }
376:
377: return (rfp);
378: }
379:
380: /*
381: * rcs_close()
382: *
383: * Close an RCS file handle.
384: */
385: void
386: rcs_close(RCSFILE *rfp)
387: {
388: struct rcs_delta *rdp;
1.71 moritz 389: struct rcs_access *rap;
1.13 jfb 390: struct rcs_lock *rlp;
391: struct rcs_sym *rsp;
1.1 jfb 392:
393: if (rfp->rf_ref > 1) {
394: rfp->rf_ref--;
395: return;
396: }
397:
1.26 jfb 398: if ((rfp->rf_flags & RCS_WRITE) && !(rfp->rf_flags & RCS_SYNCED))
399: rcs_write(rfp);
400:
1.1 jfb 401: while (!TAILQ_EMPTY(&(rfp->rf_delta))) {
402: rdp = TAILQ_FIRST(&(rfp->rf_delta));
403: TAILQ_REMOVE(&(rfp->rf_delta), rdp, rd_list);
404: rcs_freedelta(rdp);
1.71 moritz 405: }
406:
407: while (!TAILQ_EMPTY(&(rfp->rf_access))) {
408: rap = TAILQ_FIRST(&(rfp->rf_access));
409: TAILQ_REMOVE(&(rfp->rf_access), rap, ra_list);
410: cvs_strfree(rap->ra_name);
411: free(rap);
1.1 jfb 412: }
413:
1.13 jfb 414: while (!TAILQ_EMPTY(&(rfp->rf_symbols))) {
415: rsp = TAILQ_FIRST(&(rfp->rf_symbols));
416: TAILQ_REMOVE(&(rfp->rf_symbols), rsp, rs_list);
417: rcsnum_free(rsp->rs_num);
1.39 joris 418: cvs_strfree(rsp->rs_name);
1.13 jfb 419: free(rsp);
420: }
421:
422: while (!TAILQ_EMPTY(&(rfp->rf_locks))) {
423: rlp = TAILQ_FIRST(&(rfp->rf_locks));
424: TAILQ_REMOVE(&(rfp->rf_locks), rlp, rl_list);
425: rcsnum_free(rlp->rl_num);
1.77 joris 426: cvs_strfree(rlp->rl_name);
1.13 jfb 427: free(rlp);
428: }
429:
1.1 jfb 430: if (rfp->rf_head != NULL)
431: rcsnum_free(rfp->rf_head);
1.11 joris 432: if (rfp->rf_branch != NULL)
433: rcsnum_free(rfp->rf_branch);
1.1 jfb 434:
435: if (rfp->rf_path != NULL)
436: free(rfp->rf_path);
437: if (rfp->rf_comment != NULL)
1.39 joris 438: cvs_strfree(rfp->rf_comment);
1.1 jfb 439: if (rfp->rf_expand != NULL)
1.39 joris 440: cvs_strfree(rfp->rf_expand);
1.1 jfb 441: if (rfp->rf_desc != NULL)
1.39 joris 442: cvs_strfree(rfp->rf_desc);
1.1 jfb 443: free(rfp);
444: }
445:
446: /*
447: * rcs_write()
448: *
449: * Write the contents of the RCS file handle <rfp> to disk in the file whose
450: * path is in <rf_path>.
451: * Returns 0 on success, or -1 on failure.
452: */
1.27 jfb 453: static int
1.1 jfb 454: rcs_write(RCSFILE *rfp)
455: {
456: FILE *fp;
1.72 niallo 457: char buf[1024], numbuf[64], fn[19] = "";
458: void *bp;
1.29 jfb 459: struct rcs_access *ap;
1.1 jfb 460: struct rcs_sym *symp;
1.46 jfb 461: struct rcs_branch *brp;
1.1 jfb 462: struct rcs_delta *rdp;
1.75 joris 463: struct rcs_lock *lkp;
1.72 niallo 464: ssize_t nread;
465: int fd, from_fd, to_fd;
1.75 joris 466:
1.72 niallo 467: from_fd = to_fd = fd = -1;
1.1 jfb 468:
1.28 jfb 469: if (rfp->rf_flags & RCS_SYNCED)
1.1 jfb 470: return (0);
471:
1.72 niallo 472: strlcpy(fn, "/tmp/rcs.XXXXXXXXXX", sizeof(fn));
473: if ((fd = mkstemp(fn)) == -1 ||
474: (fp = fdopen(fd, "w+")) == NULL) {
475: if (fd != -1) {
476: unlink(fn);
477: close(fd);
478: }
1.50 jfb 479: rcs_errno = RCS_ERR_ERRNO;
1.72 niallo 480: cvs_log(LP_ERRNO, "failed to open temp RCS output file `%s'",
481: fn);
1.1 jfb 482: return (-1);
483: }
484:
1.28 jfb 485: if (rfp->rf_head != NULL)
486: rcsnum_tostr(rfp->rf_head, numbuf, sizeof(numbuf));
487: else
488: numbuf[0] = '\0';
489:
1.1 jfb 490: fprintf(fp, "head\t%s;\n", numbuf);
1.35 jfb 491:
492: if (rfp->rf_branch != NULL) {
493: rcsnum_tostr(rfp->rf_branch, numbuf, sizeof(numbuf));
494: fprintf(fp, "branch\t%s;\n", numbuf);
495: }
496:
1.29 jfb 497: fputs("access", fp);
498: TAILQ_FOREACH(ap, &(rfp->rf_access), ra_list) {
499: fprintf(fp, "\n\t%s", ap->ra_name);
500: }
501: fputs(";\n", fp);
1.1 jfb 502:
1.85 joris 503: fprintf(fp, "symbols");
1.1 jfb 504: TAILQ_FOREACH(symp, &(rfp->rf_symbols), rs_list) {
505: rcsnum_tostr(symp->rs_num, numbuf, sizeof(numbuf));
506: snprintf(buf, sizeof(buf), "%s:%s", symp->rs_name, numbuf);
1.85 joris 507: fprintf(fp, "\n\t%s", buf);
1.1 jfb 508: }
509: fprintf(fp, ";\n");
510:
1.75 joris 511: fprintf(fp, "locks");
512: TAILQ_FOREACH(lkp, &(rfp->rf_locks), rl_list) {
513: rcsnum_tostr(lkp->rl_num, numbuf, sizeof(numbuf));
514: fprintf(fp, "\n\t%s:%s", lkp->rl_name, numbuf);
515: }
516:
517: fprintf(fp, ";");
1.1 jfb 518:
1.26 jfb 519: if (rfp->rf_flags & RCS_SLOCK)
1.1 jfb 520: fprintf(fp, " strict;");
521: fputc('\n', fp);
522:
1.42 jfb 523: if (rfp->rf_comment != NULL) {
524: fputs("comment\t@", fp);
1.58 xsa 525: rcs_strprint((const u_char *)rfp->rf_comment,
526: strlen(rfp->rf_comment), fp);
1.42 jfb 527: fputs("@;\n", fp);
528: }
1.1 jfb 529:
1.42 jfb 530: if (rfp->rf_expand != NULL) {
531: fputs("expand @", fp);
1.58 xsa 532: rcs_strprint((const u_char *)rfp->rf_expand,
533: strlen(rfp->rf_expand), fp);
1.42 jfb 534: fputs("@;\n", fp);
535: }
1.1 jfb 536:
1.46 jfb 537: fputs("\n\n", fp);
1.1 jfb 538:
539: TAILQ_FOREACH(rdp, &(rfp->rf_delta), rd_list) {
540: fprintf(fp, "%s\n", rcsnum_tostr(rdp->rd_num, numbuf,
541: sizeof(numbuf)));
542: fprintf(fp, "date\t%d.%02d.%02d.%02d.%02d.%02d;",
1.44 jfb 543: rdp->rd_date.tm_year + 1900, rdp->rd_date.tm_mon + 1,
1.1 jfb 544: rdp->rd_date.tm_mday, rdp->rd_date.tm_hour,
545: rdp->rd_date.tm_min, rdp->rd_date.tm_sec);
546: fprintf(fp, "\tauthor %s;\tstate %s;\n",
547: rdp->rd_author, rdp->rd_state);
1.46 jfb 548: fputs("branches", fp);
549: TAILQ_FOREACH(brp, &(rdp->rd_branches), rb_list) {
550: fprintf(fp, " %s", rcsnum_tostr(brp->rb_num, numbuf,
551: sizeof(numbuf)));
552: }
553: fputs(";\n", fp);
1.1 jfb 554: fprintf(fp, "next\t%s;\n\n", rcsnum_tostr(rdp->rd_next,
555: numbuf, sizeof(numbuf)));
556: }
557:
1.42 jfb 558: fputs("\ndesc\n@", fp);
559: if (rfp->rf_desc != NULL)
1.58 xsa 560: rcs_strprint((const u_char *)rfp->rf_desc,
561: strlen(rfp->rf_desc), fp);
1.42 jfb 562: fputs("@\n\n", fp);
1.1 jfb 563:
564: /* deltatexts */
565: TAILQ_FOREACH(rdp, &(rfp->rf_delta), rd_list) {
566: fprintf(fp, "\n%s\n", rcsnum_tostr(rdp->rd_num, numbuf,
567: sizeof(numbuf)));
1.42 jfb 568: fputs("log\n@", fp);
1.58 xsa 569: rcs_strprint((const u_char *)rdp->rd_log,
570: strlen(rdp->rd_log), fp);
1.42 jfb 571: fputs("@\ntext\n@", fp);
572: rcs_strprint(rdp->rd_text, rdp->rd_tlen, fp);
573: fputs("@\n\n", fp);
1.1 jfb 574: }
575: fclose(fp);
1.73 joris 576:
1.72 niallo 577: /*
578: * We try to use rename() to atomically put the new file in place.
579: * If that fails, we try a copy.
580: */
581: if (rename(fn, rfp->rf_path) == -1) {
582: if (errno == EXDEV) {
583: /* rename() not supported so we have to copy. */
584: if ((chmod(rfp->rf_path, S_IWUSR) == -1)
585: && !(rfp->rf_flags & RCS_CREATE)) {
586: cvs_log(LP_ERRNO, "failed to chmod `%s'",
587: rfp->rf_path);
588: return (-1);
589: }
1.73 joris 590:
1.72 niallo 591: if ((from_fd = open(fn, O_RDONLY)) == -1) {
592: cvs_log(LP_ERRNO, "failed to open `%s'",
593: rfp->rf_path);
594: return (-1);
595: }
1.73 joris 596:
1.80 reyk 597: if ((to_fd = open(rfp->rf_path,
598: O_WRONLY|O_TRUNC|O_CREAT)) == -1) {
1.73 joris 599: cvs_log(LP_ERRNO, "failed to open `%s'", fn);
1.72 niallo 600: close(from_fd);
601: return (-1);
602: }
1.73 joris 603:
1.72 niallo 604: if ((bp = malloc(MAXBSIZE)) == NULL) {
1.73 joris 605: cvs_log(LP_ERRNO, "failed to allocate memory");
1.72 niallo 606: close(from_fd);
607: close(to_fd);
608: return (-1);
609: }
1.73 joris 610:
1.72 niallo 611: while ((nread = read(from_fd, bp, MAXBSIZE)) > 0) {
612: if (write(to_fd, bp, nread) != nread)
613: goto err;
614: }
1.73 joris 615:
1.72 niallo 616: if (nread < 0) {
617: err: if (unlink(rfp->rf_path) == -1)
618: cvs_log(LP_ERRNO,
619: "failed to unlink `%s'",
620: rfp->rf_path);
621: close(from_fd);
622: close(to_fd);
623: free(bp);
624: return (-1);
625: }
1.73 joris 626:
1.72 niallo 627: close(from_fd);
628: close(to_fd);
629: free(bp);
1.73 joris 630:
1.72 niallo 631: if (unlink(fn) == -1) {
632: cvs_log(LP_ERRNO,
1.73 joris 633: "failed to unlink `%s'", fn);
1.72 niallo 634: return (-1);
635: }
636: } else {
637: cvs_log(LP_ERRNO,
638: "failed to access temp RCS output file");
639: return (-1);
640: }
641: }
1.73 joris 642:
1.72 niallo 643: if ((chmod(rfp->rf_path, S_IRUSR|S_IRGRP|S_IROTH) == -1)) {
644: cvs_log(LP_ERRNO, "failed to chmod `%s'",
645: rfp->rf_path);
646: return (-1);
647: }
1.73 joris 648:
1.26 jfb 649: rfp->rf_flags |= RCS_SYNCED;
1.1 jfb 650:
651: return (0);
652: }
653:
654: /*
1.43 jfb 655: * rcs_head_get()
656: *
657: * Retrieve the revision number of the head revision for the RCS file <file>.
658: */
1.60 xsa 659: const RCSNUM *
1.43 jfb 660: rcs_head_get(RCSFILE *file)
661: {
662: return (file->rf_head);
663: }
664:
665: /*
666: * rcs_head_set()
667: *
668: * Set the revision number of the head revision for the RCS file <file> to
669: * <rev>, which must reference a valid revision within the file.
670: */
671: int
672: rcs_head_set(RCSFILE *file, const RCSNUM *rev)
673: {
674: struct rcs_delta *rd;
675:
676: if ((rd = rcs_findrev(file, rev)) == NULL)
677: return (-1);
678:
1.52 jfb 679: if ((file->rf_head == NULL) &&
680: ((file->rf_head = rcsnum_alloc()) == NULL))
681: return (-1);
682:
1.43 jfb 683: if (rcsnum_cpy(rev, file->rf_head, 0) < 0)
684: return (-1);
685:
1.70 moritz 686: file->rf_flags &= ~RCS_SYNCED;
1.43 jfb 687: return (0);
688: }
689:
690:
691: /*
1.35 jfb 692: * rcs_branch_get()
693: *
694: * Retrieve the default branch number for the RCS file <file>.
695: * Returns the number on success. If NULL is returned, then there is no
696: * default branch for this file.
697: */
1.60 xsa 698: const RCSNUM *
1.35 jfb 699: rcs_branch_get(RCSFILE *file)
700: {
701: return (file->rf_branch);
702: }
703:
704: /*
705: * rcs_branch_set()
706: *
707: * Set the default branch for the RCS file <file> to <bnum>.
708: * Returns 0 on success, -1 on failure.
709: */
710: int
711: rcs_branch_set(RCSFILE *file, const RCSNUM *bnum)
712: {
713: if ((file->rf_branch == NULL) &&
714: ((file->rf_branch = rcsnum_alloc()) == NULL))
715: return (-1);
716:
717: if (rcsnum_cpy(bnum, file->rf_branch, 0) < 0) {
718: rcsnum_free(file->rf_branch);
719: file->rf_branch = NULL;
720: return (-1);
721: }
722:
1.70 moritz 723: file->rf_flags &= ~RCS_SYNCED;
1.35 jfb 724: return (0);
725: }
726:
727: /*
1.29 jfb 728: * rcs_access_add()
729: *
730: * Add the login name <login> to the access list for the RCS file <file>.
731: * Returns 0 on success, or -1 on failure.
732: */
733: int
734: rcs_access_add(RCSFILE *file, const char *login)
735: {
736: struct rcs_access *ap;
737:
738: /* first look for duplication */
739: TAILQ_FOREACH(ap, &(file->rf_access), ra_list) {
740: if (strcmp(ap->ra_name, login) == 0) {
1.32 jfb 741: rcs_errno = RCS_ERR_DUPENT;
1.29 jfb 742: return (-1);
743: }
744: }
745:
746: ap = (struct rcs_access *)malloc(sizeof(*ap));
747: if (ap == NULL) {
1.50 jfb 748: rcs_errno = RCS_ERR_ERRNO;
1.29 jfb 749: cvs_log(LP_ERRNO, "failed to allocate RCS access entry");
750: return (-1);
751: }
752:
1.39 joris 753: ap->ra_name = cvs_strdup(login);
1.29 jfb 754: if (ap->ra_name == NULL) {
755: cvs_log(LP_ERRNO, "failed to duplicate user name");
756: free(ap);
757: return (-1);
758: }
759:
760: TAILQ_INSERT_TAIL(&(file->rf_access), ap, ra_list);
761:
762: /* not synced anymore */
763: file->rf_flags &= ~RCS_SYNCED;
764: return (0);
765: }
766:
767: /*
768: * rcs_access_remove()
769: *
770: * Remove an entry with login name <login> from the access list of the RCS
771: * file <file>.
772: * Returns 0 on success, or -1 on failure.
773: */
774: int
775: rcs_access_remove(RCSFILE *file, const char *login)
776: {
777: struct rcs_access *ap;
778:
779: TAILQ_FOREACH(ap, &(file->rf_access), ra_list)
780: if (strcmp(ap->ra_name, login) == 0)
781: break;
782:
783: if (ap == NULL) {
1.32 jfb 784: rcs_errno = RCS_ERR_NOENT;
1.29 jfb 785: return (-1);
786: }
787:
788: TAILQ_REMOVE(&(file->rf_access), ap, ra_list);
1.39 joris 789: cvs_strfree(ap->ra_name);
1.29 jfb 790: free(ap);
791:
792: /* not synced anymore */
793: file->rf_flags &= ~RCS_SYNCED;
794: return (0);
795: }
796:
797: /*
1.26 jfb 798: * rcs_sym_add()
1.1 jfb 799: *
800: * Add a symbol to the list of symbols for the RCS file <rfp>. The new symbol
801: * is named <sym> and is bound to the RCS revision <snum>.
802: * Returns 0 on success, or -1 on failure.
803: */
804: int
1.26 jfb 805: rcs_sym_add(RCSFILE *rfp, const char *sym, RCSNUM *snum)
1.1 jfb 806: {
807: struct rcs_sym *symp;
808:
1.47 jfb 809: if (!rcs_sym_check(sym)) {
810: rcs_errno = RCS_ERR_BADSYM;
1.69 moritz 811: return (-1);
1.47 jfb 812: }
813:
1.1 jfb 814: /* first look for duplication */
815: TAILQ_FOREACH(symp, &(rfp->rf_symbols), rs_list) {
816: if (strcmp(symp->rs_name, sym) == 0) {
1.32 jfb 817: rcs_errno = RCS_ERR_DUPENT;
1.1 jfb 818: return (-1);
819: }
820: }
821:
1.50 jfb 822: if ((symp = (struct rcs_sym *)malloc(sizeof(*symp))) == NULL) {
823: rcs_errno = RCS_ERR_ERRNO;
1.1 jfb 824: cvs_log(LP_ERRNO, "failed to allocate RCS symbol");
825: return (-1);
826: }
827:
1.50 jfb 828: if ((symp->rs_name = cvs_strdup(sym)) == NULL) {
829: rcs_errno = RCS_ERR_ERRNO;
1.10 joris 830: cvs_log(LP_ERRNO, "failed to duplicate symbol");
831: free(symp);
832: return (-1);
833: }
834:
1.50 jfb 835: if ((symp->rs_num = rcsnum_alloc()) == NULL) {
1.39 joris 836: cvs_strfree(symp->rs_name);
1.11 joris 837: free(symp);
838: return (-1);
839: }
1.1 jfb 840: rcsnum_cpy(snum, symp->rs_num, 0);
841:
842: TAILQ_INSERT_HEAD(&(rfp->rf_symbols), symp, rs_list);
843:
844: /* not synced anymore */
1.26 jfb 845: rfp->rf_flags &= ~RCS_SYNCED;
1.1 jfb 846: return (0);
847: }
848:
849: /*
1.27 jfb 850: * rcs_sym_remove()
851: *
852: * Remove the symbol with name <sym> from the symbol list for the RCS file
853: * <file>. If no such symbol is found, the call fails and returns with an
854: * error.
855: * Returns 0 on success, or -1 on failure.
856: */
857: int
858: rcs_sym_remove(RCSFILE *file, const char *sym)
859: {
860: struct rcs_sym *symp;
861:
1.47 jfb 862: if (!rcs_sym_check(sym)) {
863: rcs_errno = RCS_ERR_BADSYM;
1.69 moritz 864: return (-1);
1.47 jfb 865: }
866:
1.27 jfb 867: TAILQ_FOREACH(symp, &(file->rf_symbols), rs_list)
868: if (strcmp(symp->rs_name, sym) == 0)
869: break;
870:
871: if (symp == NULL) {
1.32 jfb 872: rcs_errno = RCS_ERR_NOENT;
1.27 jfb 873: return (-1);
874: }
875:
876: TAILQ_REMOVE(&(file->rf_symbols), symp, rs_list);
1.39 joris 877: cvs_strfree(symp->rs_name);
1.27 jfb 878: rcsnum_free(symp->rs_num);
879: free(symp);
880:
881: /* not synced anymore */
882: file->rf_flags &= ~RCS_SYNCED;
883: return (0);
884: }
885:
886: /*
887: * rcs_sym_getrev()
888: *
889: * Retrieve the RCS revision number associated with the symbol <sym> for the
890: * RCS file <file>. The returned value is a dynamically-allocated copy and
891: * should be freed by the caller once they are done with it.
892: * Returns the RCSNUM on success, or NULL on failure.
893: */
1.60 xsa 894: RCSNUM *
1.27 jfb 895: rcs_sym_getrev(RCSFILE *file, const char *sym)
896: {
897: RCSNUM *num;
898: struct rcs_sym *symp;
899:
1.47 jfb 900: if (!rcs_sym_check(sym)) {
901: rcs_errno = RCS_ERR_BADSYM;
902: return (NULL);
903: }
904:
1.27 jfb 905: num = NULL;
906: TAILQ_FOREACH(symp, &(file->rf_symbols), rs_list)
907: if (strcmp(symp->rs_name, sym) == 0)
908: break;
909:
1.36 jfb 910: if (symp == NULL)
911: rcs_errno = RCS_ERR_NOENT;
912: else if (((num = rcsnum_alloc()) != NULL) &&
1.27 jfb 913: (rcsnum_cpy(symp->rs_num, num, 0) < 0)) {
914: rcsnum_free(num);
915: num = NULL;
916: }
917:
918: return (num);
1.47 jfb 919: }
920:
921: /*
922: * rcs_sym_check()
923: *
924: * Check the RCS symbol name <sym> for any unsupported characters.
925: * Returns 1 if the tag is correct, 0 if it isn't valid.
926: */
927: int
928: rcs_sym_check(const char *sym)
929: {
930: int ret;
931: const char *cp;
932:
933: ret = 1;
934: cp = sym;
935: if (!isalpha(*cp++))
936: return (0);
937:
938: for (; *cp != '\0'; cp++)
939: if (!isgraph(*cp) || (strchr(rcs_sym_invch, *cp) != NULL)) {
940: ret = 0;
941: break;
942: }
943:
944: return (ret);
1.30 jfb 945: }
946:
947: /*
948: * rcs_lock_getmode()
949: *
950: * Retrieve the locking mode of the RCS file <file>.
951: */
952: int
953: rcs_lock_getmode(RCSFILE *file)
954: {
955: return (file->rf_flags & RCS_SLOCK) ? RCS_LOCK_STRICT : RCS_LOCK_LOOSE;
956: }
957:
958: /*
959: * rcs_lock_setmode()
960: *
961: * Set the locking mode of the RCS file <file> to <mode>, which must either
962: * be RCS_LOCK_LOOSE or RCS_LOCK_STRICT.
963: * Returns the previous mode on success, or -1 on failure.
964: */
965: int
966: rcs_lock_setmode(RCSFILE *file, int mode)
967: {
968: int pmode;
969: pmode = rcs_lock_getmode(file);
970:
971: if (mode == RCS_LOCK_STRICT)
972: file->rf_flags |= RCS_SLOCK;
973: else if (mode == RCS_LOCK_LOOSE)
974: file->rf_flags &= ~RCS_SLOCK;
975: else {
976: cvs_log(LP_ERRNO, "invalid lock mode %d", mode);
977: return (-1);
978: }
979:
1.70 moritz 980: file->rf_flags &= ~RCS_SYNCED;
1.30 jfb 981: return (pmode);
1.27 jfb 982: }
983:
984: /*
1.40 jfb 985: * rcs_lock_add()
986: *
987: * Add an RCS lock for the user <user> on revision <rev>.
988: * Returns 0 on success, or -1 on failure.
989: */
990: int
991: rcs_lock_add(RCSFILE *file, const char *user, RCSNUM *rev)
992: {
993: struct rcs_lock *lkp;
994:
995: /* first look for duplication */
996: TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list) {
997: if (strcmp(lkp->rl_name, user) == 0) {
998: rcs_errno = RCS_ERR_DUPENT;
999: return (-1);
1000: }
1001: }
1002:
1.50 jfb 1003: if ((lkp = (struct rcs_lock *)malloc(sizeof(*lkp))) == NULL) {
1004: rcs_errno = RCS_ERR_ERRNO;
1.40 jfb 1005: cvs_log(LP_ERRNO, "failed to allocate RCS lock");
1006: return (-1);
1007: }
1008:
1009: lkp->rl_name = cvs_strdup(user);
1010: if (lkp->rl_name == NULL) {
1011: cvs_log(LP_ERRNO, "failed to duplicate user name");
1012: free(lkp);
1013: return (-1);
1014: }
1.68 moritz 1015:
1016: if ((lkp->rl_num = rcsnum_alloc()) == NULL) {
1017: cvs_strfree(lkp->rl_name);
1018: free(lkp);
1019: return (-1);
1020: }
1021: rcsnum_cpy(rev, lkp->rl_num, 0);
1.40 jfb 1022:
1023: TAILQ_INSERT_TAIL(&(file->rf_locks), lkp, rl_list);
1024:
1025: /* not synced anymore */
1026: file->rf_flags &= ~RCS_SYNCED;
1027: return (0);
1028:
1029:
1030: }
1031:
1032:
1033: /*
1034: * rcs_lock_remove()
1035: *
1036: * Remove the RCS lock on revision <rev>.
1037: * Returns 0 on success, or -1 on failure.
1038: */
1039: int
1.56 joris 1040: rcs_lock_remove(RCSFILE *file, const RCSNUM *rev)
1.40 jfb 1041: {
1042: struct rcs_lock *lkp;
1043:
1044: TAILQ_FOREACH(lkp, &(file->rf_locks), rl_list)
1045: if (rcsnum_cmp(lkp->rl_num, rev, 0) == 0)
1046: break;
1047:
1048: if (lkp == NULL) {
1049: rcs_errno = RCS_ERR_NOENT;
1050: return (-1);
1051: }
1052:
1053: TAILQ_REMOVE(&(file->rf_locks), lkp, rl_list);
1054: rcsnum_free(lkp->rl_num);
1055: cvs_strfree(lkp->rl_name);
1056: free(lkp);
1057:
1058: /* not synced anymore */
1059: file->rf_flags &= ~RCS_SYNCED;
1060: return (0);
1061: }
1062:
1063: /*
1.27 jfb 1064: * rcs_desc_get()
1065: *
1066: * Retrieve the description for the RCS file <file>.
1067: */
1.57 xsa 1068: const char *
1.27 jfb 1069: rcs_desc_get(RCSFILE *file)
1070: {
1071: return (file->rf_desc);
1072: }
1073:
1074: /*
1075: * rcs_desc_set()
1076: *
1077: * Set the description for the RCS file <file>.
1078: * Returns 0 on success, or -1 on failure.
1079: */
1080: int
1081: rcs_desc_set(RCSFILE *file, const char *desc)
1082: {
1083: char *tmp;
1084:
1.39 joris 1085: if ((tmp = cvs_strdup(desc)) == NULL)
1.27 jfb 1086: return (-1);
1087:
1088: if (file->rf_desc != NULL)
1.39 joris 1089: cvs_strfree(file->rf_desc);
1.27 jfb 1090: file->rf_desc = tmp;
1091: file->rf_flags &= ~RCS_SYNCED;
1092:
1093: return (0);
1.51 jfb 1094: }
1095:
1096: /*
1097: * rcs_comment_lookup()
1098: *
1099: * Lookup the assumed comment leader based on a file's suffix.
1100: * Returns a pointer to the string on success, or NULL on failure.
1101: */
1.57 xsa 1102: const char *
1.51 jfb 1103: rcs_comment_lookup(const char *filename)
1104: {
1105: int i;
1106: const char *sp;
1107:
1108: if ((sp = strrchr(filename, '.')) == NULL) {
1109: rcs_errno = RCS_ERR_NOENT;
1110: return (NULL);
1111: }
1112: sp++;
1113:
1114: for (i = 0; i < (int)NB_COMTYPES; i++)
1115: if (strcmp(rcs_comments[i].rc_suffix, sp) == 0)
1116: return (rcs_comments[i].rc_cstr);
1117: return (NULL);
1.27 jfb 1118: }
1119:
1.33 jfb 1120: /*
1121: * rcs_comment_get()
1122: *
1123: * Retrieve the comment leader for the RCS file <file>.
1124: */
1.57 xsa 1125: const char *
1.33 jfb 1126: rcs_comment_get(RCSFILE *file)
1127: {
1128: return (file->rf_comment);
1129: }
1130:
1131: /*
1132: * rcs_comment_set()
1133: *
1134: * Set the comment leader for the RCS file <file>.
1135: * Returns 0 on success, or -1 on failure.
1136: */
1137: int
1138: rcs_comment_set(RCSFILE *file, const char *comment)
1139: {
1140: char *tmp;
1141:
1.39 joris 1142: if ((tmp = cvs_strdup(comment)) == NULL)
1.33 jfb 1143: return (-1);
1144:
1145: if (file->rf_comment != NULL)
1.39 joris 1146: cvs_strfree(file->rf_comment);
1.33 jfb 1147: file->rf_comment = tmp;
1148: file->rf_flags &= ~RCS_SYNCED;
1149:
1150: return (0);
1151: }
1.40 jfb 1152:
1153: /*
1154: * rcs_tag_resolve()
1155: *
1156: * Retrieve the revision number corresponding to the tag <tag> for the RCS
1157: * file <file>.
1158: */
1.60 xsa 1159: RCSNUM *
1.40 jfb 1160: rcs_tag_resolve(RCSFILE *file, const char *tag)
1161: {
1162: RCSNUM *num;
1163:
1164: if ((num = rcsnum_parse(tag)) == NULL) {
1165: num = rcs_sym_getrev(file, tag);
1166: }
1167:
1168: return (num);
1169: }
1170:
1.27 jfb 1171:
1172: /*
1.1 jfb 1173: * rcs_patch()
1174: *
1175: * Apply an RCS-format patch pointed to by <patch> to the file contents
1176: * found in <data>.
1177: * Returns 0 on success, or -1 on failure.
1178: */
1179: BUF*
1180: rcs_patch(const char *data, const char *patch)
1181: {
1.5 vincent 1182: struct rcs_foo *dlines, *plines;
1183: struct rcs_line *lp;
1.1 jfb 1184: size_t len;
1.5 vincent 1185: int lineno;
1.1 jfb 1186: BUF *res;
1187:
1188: len = strlen(data);
1189: res = cvs_buf_alloc(len, BUF_AUTOEXT);
1190: if (res == NULL)
1191: return (NULL);
1192:
1193: dlines = rcs_splitlines(data);
1.17 jfb 1194: if (dlines == NULL) {
1195: cvs_buf_free(res);
1.1 jfb 1196: return (NULL);
1.17 jfb 1197: }
1.5 vincent 1198:
1.1 jfb 1199: plines = rcs_splitlines(patch);
1.5 vincent 1200: if (plines == NULL) {
1.17 jfb 1201: cvs_buf_free(res);
1.5 vincent 1202: rcs_freefoo(dlines);
1.1 jfb 1203: return (NULL);
1.5 vincent 1204: }
1205:
1206: if (rcs_patch_lines(dlines, plines) < 0) {
1.17 jfb 1207: cvs_buf_free(res);
1.5 vincent 1208: rcs_freefoo(plines);
1209: rcs_freefoo(dlines);
1210: return (NULL);
1211: }
1212:
1213: lineno = 0;
1214: TAILQ_FOREACH(lp, &dlines->rl_lines, rl_list) {
1215: if (lineno != 0)
1216: cvs_buf_fappend(res, "%s\n", lp->rl_line);
1217: lineno++;
1218: }
1219:
1220: rcs_freefoo(dlines);
1221: rcs_freefoo(plines);
1222: return (res);
1223: }
1224:
1.7 jfb 1225: static int
1.5 vincent 1226: rcs_patch_lines(struct rcs_foo *dlines, struct rcs_foo *plines)
1227: {
1228: char op, *ep;
1229: struct rcs_line *lp, *dlp, *ndlp;
1230: int i, lineno, nbln;
1.1 jfb 1231:
1232: dlp = TAILQ_FIRST(&(dlines->rl_lines));
1233: lp = TAILQ_FIRST(&(plines->rl_lines));
1234:
1235: /* skip first bogus line */
1236: for (lp = TAILQ_NEXT(lp, rl_list); lp != NULL;
1237: lp = TAILQ_NEXT(lp, rl_list)) {
1238: op = *(lp->rl_line);
1239: lineno = (int)strtol((lp->rl_line + 1), &ep, 10);
1.82 joris 1240: if ((lineno > dlines->rl_nblines) || (lineno < 0) ||
1.1 jfb 1241: (*ep != ' ')) {
1242: cvs_log(LP_ERR,
1243: "invalid line specification in RCS patch");
1.61 joris 1244: return (-1);
1.1 jfb 1245: }
1246: ep++;
1247: nbln = (int)strtol(ep, &ep, 10);
1.82 joris 1248: if ((nbln < 0) || (*ep != '\0')) {
1.1 jfb 1249: cvs_log(LP_ERR,
1250: "invalid line number specification in RCS patch");
1.61 joris 1251: return (-1);
1.1 jfb 1252: }
1253:
1254: /* find the appropriate line */
1255: for (;;) {
1256: if (dlp == NULL)
1257: break;
1258: if (dlp->rl_lineno == lineno)
1259: break;
1260: if (dlp->rl_lineno > lineno) {
1261: dlp = TAILQ_PREV(dlp, rcs_tqh, rl_list);
1.14 deraadt 1262: } else if (dlp->rl_lineno < lineno) {
1.1 jfb 1263: ndlp = TAILQ_NEXT(dlp, rl_list);
1264: if (ndlp->rl_lineno > lineno)
1265: break;
1266: dlp = ndlp;
1267: }
1268: }
1269: if (dlp == NULL) {
1270: cvs_log(LP_ERR,
1271: "can't find referenced line in RCS patch");
1.61 joris 1272: return (-1);
1.1 jfb 1273: }
1274:
1275: if (op == 'd') {
1276: for (i = 0; (i < nbln) && (dlp != NULL); i++) {
1277: ndlp = TAILQ_NEXT(dlp, rl_list);
1278: TAILQ_REMOVE(&(dlines->rl_lines), dlp, rl_list);
1279: dlp = ndlp;
1280: }
1.14 deraadt 1281: } else if (op == 'a') {
1.1 jfb 1282: for (i = 0; i < nbln; i++) {
1283: ndlp = lp;
1284: lp = TAILQ_NEXT(lp, rl_list);
1285: if (lp == NULL) {
1286: cvs_log(LP_ERR, "truncated RCS patch");
1.5 vincent 1287: return (-1);
1.1 jfb 1288: }
1289: TAILQ_REMOVE(&(plines->rl_lines), lp, rl_list);
1290: TAILQ_INSERT_AFTER(&(dlines->rl_lines), dlp,
1291: lp, rl_list);
1292: dlp = lp;
1293:
1294: /* we don't want lookup to block on those */
1295: lp->rl_lineno = lineno;
1296:
1297: lp = ndlp;
1298: }
1.14 deraadt 1299: } else {
1.1 jfb 1300: cvs_log(LP_ERR, "unknown RCS patch operation `%c'", op);
1.5 vincent 1301: return (-1);
1.1 jfb 1302: }
1303:
1304: /* last line of the patch, done */
1305: if (lp->rl_lineno == plines->rl_nblines)
1306: break;
1307: }
1308:
1309: /* once we're done patching, rebuild the line numbers */
1.2 vincent 1310: lineno = 0;
1.5 vincent 1311: TAILQ_FOREACH(lp, &(dlines->rl_lines), rl_list)
1.1 jfb 1312: lp->rl_lineno = lineno++;
1313: dlines->rl_nblines = lineno - 1;
1314:
1.5 vincent 1315: return (0);
1.1 jfb 1316: }
1317:
1318: /*
1319: * rcs_getrev()
1320: *
1321: * Get the whole contents of revision <rev> from the RCSFILE <rfp>. The
1.4 vincent 1322: * returned buffer is dynamically allocated and should be released using
1323: * cvs_buf_free() once the caller is done using it.
1.1 jfb 1324: */
1325: BUF*
1.66 joris 1326: rcs_getrev(RCSFILE *rfp, RCSNUM *frev)
1.1 jfb 1327: {
1.63 joris 1328: int expmode, res;
1.1 jfb 1329: size_t len;
1330: void *bp;
1.66 joris 1331: RCSNUM *crev, *rev;
1.65 niallo 1332: BUF *rbuf, *dbuf = NULL;
1.1 jfb 1333: struct rcs_delta *rdp = NULL;
1.63 joris 1334: struct rcs_foo *lines;
1335: struct rcs_line *lp;
1336: char out[1024]; /* XXX */
1.1 jfb 1337:
1.28 jfb 1338: if (rfp->rf_head == NULL)
1339: return (NULL);
1.66 joris 1340:
1341: if (frev == RCS_HEAD_REV)
1342: rev = rfp->rf_head;
1343: else
1344: rev = frev;
1.28 jfb 1345:
1.1 jfb 1346: res = rcsnum_cmp(rfp->rf_head, rev, 0);
1347: if (res == 1) {
1.32 jfb 1348: rcs_errno = RCS_ERR_NOENT;
1.1 jfb 1349: return (NULL);
1.26 jfb 1350: }
1351:
1352: rdp = rcs_findrev(rfp, rfp->rf_head);
1353: if (rdp == NULL) {
1354: cvs_log(LP_ERR, "failed to get RCS HEAD revision");
1355: return (NULL);
1356: }
1357:
1.45 jfb 1358: len = rdp->rd_tlen;
1.26 jfb 1359: if ((rbuf = cvs_buf_alloc(len, BUF_AUTOEXT)) == NULL)
1360: return (NULL);
1361:
1362: cvs_buf_append(rbuf, rdp->rd_text, len);
1363:
1364: if (res != 0) {
1365: /* Apply patches backwards to get the right version.
1366: * This will need some rework to support sub branches.
1367: */
1368: do {
1.87 joris 1369: crev = rdp->rd_next;
1.26 jfb 1370: rdp = rcs_findrev(rfp, crev);
1371: if (rdp == NULL) {
1372: cvs_buf_free(rbuf);
1373: return (NULL);
1374: }
1.1 jfb 1375:
1.26 jfb 1376: if (cvs_buf_putc(rbuf, '\0') < 0) {
1.17 jfb 1377: cvs_buf_free(rbuf);
1.11 joris 1378: return (NULL);
1.17 jfb 1379: }
1.26 jfb 1380: bp = cvs_buf_release(rbuf);
1.45 jfb 1381: rbuf = rcs_patch((char *)bp, (char *)rdp->rd_text);
1.62 joris 1382: free(bp);
1.26 jfb 1383: if (rbuf == NULL)
1384: break;
1385: } while (rcsnum_cmp(crev, rev, 0) != 0);
1.1 jfb 1386: }
1387:
1.63 joris 1388: /*
1389: * Do keyword expansion if required.
1390: */
1391: if (rfp->rf_expand != NULL)
1392: expmode = rcs_kwexp_get(rfp);
1393: else
1394: expmode = RCS_KWEXP_DEFAULT;
1395:
1396: if ((rbuf != NULL) && !(expmode & RCS_KWEXP_NONE)) {
1397: if ((dbuf = cvs_buf_alloc(len, BUF_AUTOEXT)) == NULL)
1398: return (rbuf);
1399: if ((rdp = rcs_findrev(rfp, rev)) == NULL)
1400: return (rbuf);
1401:
1402: if (cvs_buf_putc(rbuf, '\0') < 0) {
1403: cvs_buf_free(dbuf);
1404: return (rbuf);
1405: }
1406:
1407: bp = cvs_buf_release(rbuf);
1408: if ((lines = rcs_splitlines((char *)bp)) != NULL) {
1409: res = 0;
1410: TAILQ_FOREACH(lp, &lines->rl_lines, rl_list) {
1411: if (res++ == 0)
1412: continue;
1413: rcs_expand_keywords(rfp->rf_path, rdp,
1414: lp->rl_line, out, sizeof(out), expmode);
1415: cvs_buf_fappend(dbuf, "%s\n", out);
1416: }
1417: rcs_freefoo(lines);
1418: }
1419: free(bp);
1420: }
1421:
1422: return (dbuf);
1.1 jfb 1423: }
1424:
1425: /*
1.52 jfb 1426: * rcs_rev_add()
1427: *
1.53 jfb 1428: * Add a revision to the RCS file <rf>. The new revision's number can be
1429: * specified in <rev> (which can also be RCS_HEAD_REV, in which case the
1430: * new revision will have a number equal to the previous head revision plus
1431: * one). The <msg> argument specifies the log message for that revision, and
1432: * <date> specifies the revision's date (a value of -1 is
1433: * equivalent to using the current time).
1.90 niallo 1434: * If <username> is NULL, set the author for this revision to the current user.
1435: * Otherwise, set it to <username>.
1.52 jfb 1436: * Returns 0 on success, or -1 on failure.
1437: */
1438: int
1.90 niallo 1439: rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date,
1440: const char *username)
1.52 jfb 1441: {
1442: time_t now;
1443: struct passwd *pw;
1.83 joris 1444: struct rcs_delta *ordp, *rdp;
1445: RCSNUM *old;
1446:
1447: if ((old = rcsnum_alloc()) == NULL)
1448: return (-1);
1.52 jfb 1449:
1450: if (rev == RCS_HEAD_REV) {
1.83 joris 1451: rcsnum_cpy(rf->rf_head, old, 0);
1.81 niallo 1452: rev = rcsnum_inc(rf->rf_head);
1.83 joris 1453: } else {
1454: if ((rdp = rcs_findrev(rf, rev)) != NULL) {
1455: rcs_errno = RCS_ERR_DUPENT;
1.92 ! joris 1456: rcsnum_free(old);
1.83 joris 1457: return (-1);
1458: }
1459:
1460: ordp = NULL;
1461: rcsnum_cpy(rev, old, 0);
1462: while (ordp == NULL) {
1463: old = rcsnum_dec(old);
1464: ordp = rcs_findrev(rf, old);
1465: }
1.52 jfb 1466: }
1467:
1468: if ((pw = getpwuid(getuid())) == NULL) {
1469: rcs_errno = RCS_ERR_ERRNO;
1.92 ! joris 1470: rcsnum_free(old);
1.52 jfb 1471: return (-1);
1472: }
1473:
1474: if ((rdp = (struct rcs_delta *)malloc(sizeof(*rdp))) == NULL) {
1475: rcs_errno = RCS_ERR_ERRNO;
1.92 ! joris 1476: rcsnum_free(old);
1.52 jfb 1477: return (-1);
1478: }
1479: memset(rdp, 0, sizeof(*rdp));
1480:
1481: TAILQ_INIT(&(rdp->rd_branches));
1482: TAILQ_INIT(&(rdp->rd_snodes));
1483:
1484: if ((rdp->rd_num = rcsnum_alloc()) == NULL) {
1485: rcs_freedelta(rdp);
1.92 ! joris 1486: rcsnum_free(old);
1.52 jfb 1487: return (-1);
1488: }
1489: rcsnum_cpy(rev, rdp->rd_num, 0);
1.83 joris 1490:
1491: if ((rdp->rd_next = rcsnum_alloc()) == NULL) {
1492: rcs_freedelta(rdp);
1.92 ! joris 1493: rcsnum_free(old);
1.83 joris 1494: return (-1);
1495: }
1.92 ! joris 1496:
1.83 joris 1497: rcsnum_cpy(old, rdp->rd_next, 0);
1498: rcsnum_free(old);
1.52 jfb 1499:
1.90 niallo 1500: if (username == NULL)
1501: username = pw->pw_name;
1502:
1503: if ((rdp->rd_author = cvs_strdup(username)) == NULL) {
1.52 jfb 1504: rcs_freedelta(rdp);
1.92 ! joris 1505: rcsnum_free(old);
1.52 jfb 1506: return (-1);
1507: }
1508:
1509: if ((rdp->rd_state = cvs_strdup(RCS_STATE_EXP)) == NULL) {
1510: rcs_freedelta(rdp);
1.92 ! joris 1511: rcsnum_free(old);
1.52 jfb 1512: return (-1);
1513: }
1514:
1515: if ((rdp->rd_log = cvs_strdup(msg)) == NULL) {
1516: rcs_errno = RCS_ERR_ERRNO;
1517: rcs_freedelta(rdp);
1.92 ! joris 1518: rcsnum_free(old);
1.52 jfb 1519: return (-1);
1520: }
1521:
1.53 jfb 1522: if (date != (time_t)(-1))
1523: now = date;
1524: else
1525: time(&now);
1.52 jfb 1526: gmtime_r(&now, &(rdp->rd_date));
1527:
1528: TAILQ_INSERT_HEAD(&(rf->rf_delta), rdp, rd_list);
1529: rf->rf_ndelta++;
1.81 niallo 1530:
1.64 niallo 1531: /* not synced anymore */
1532: rf->rf_flags &= ~RCS_SYNCED;
1.52 jfb 1533:
1534: return (0);
1535: }
1536:
1537: /*
1538: * rcs_rev_remove()
1539: *
1540: * Remove the revision whose number is <rev> from the RCS file <rf>.
1541: */
1542: int
1543: rcs_rev_remove(RCSFILE *rf, RCSNUM *rev)
1544: {
1545: int ret;
1546: struct rcs_delta *rdp;
1547:
1548: ret = 0;
1549: if (rev == RCS_HEAD_REV)
1550: rev = rf->rf_head;
1551:
1552: /* do we actually have that revision? */
1553: if ((rdp = rcs_findrev(rf, rev)) == NULL) {
1554: rcs_errno = RCS_ERR_NOENT;
1555: ret = -1;
1556: } else {
1557: /* XXX assumes it's not a sub node */
1558: TAILQ_REMOVE(&(rf->rf_delta), rdp, rd_list);
1559: rf->rf_ndelta--;
1560: rf->rf_flags &= ~RCS_SYNCED;
1561: }
1562:
1563: return (ret);
1564:
1565: }
1566:
1567: /*
1.1 jfb 1568: * rcs_findrev()
1569: *
1570: * Find a specific revision's delta entry in the tree of the RCS file <rfp>.
1571: * The revision number is given in <rev>.
1572: * Returns a pointer to the delta on success, or NULL on failure.
1573: */
1574: static struct rcs_delta*
1.43 jfb 1575: rcs_findrev(RCSFILE *rfp, const RCSNUM *rev)
1.1 jfb 1576: {
1577: u_int cmplen;
1578: struct rcs_delta *rdp;
1579: struct rcs_dlist *hp;
1.6 vincent 1580: int found;
1.26 jfb 1581:
1.1 jfb 1582: cmplen = 2;
1583: hp = &(rfp->rf_delta);
1584:
1.6 vincent 1585: do {
1586: found = 0;
1587: TAILQ_FOREACH(rdp, hp, rd_list) {
1588: if (rcsnum_cmp(rdp->rd_num, rev, cmplen) == 0) {
1589: if (cmplen == rev->rn_len)
1590: return (rdp);
1.1 jfb 1591:
1.6 vincent 1592: hp = &(rdp->rd_snodes);
1593: cmplen += 2;
1594: found = 1;
1595: break;
1596: }
1.1 jfb 1597: }
1.6 vincent 1598: } while (found && cmplen < rev->rn_len);
1.1 jfb 1599:
1600: return (NULL);
1.20 jfb 1601: }
1602:
1603: /*
1.26 jfb 1604: * rcs_kwexp_set()
1605: *
1606: * Set the keyword expansion mode to use on the RCS file <file> to <mode>.
1607: * Returns 0 on success, or -1 on failure.
1608: */
1609: int
1610: rcs_kwexp_set(RCSFILE *file, int mode)
1611: {
1612: int i;
1613: char *tmp, buf[8] = "";
1614:
1615: if (RCS_KWEXP_INVAL(mode))
1616: return (-1);
1617:
1618: i = 0;
1619: if (mode == RCS_KWEXP_NONE)
1620: buf[0] = 'b';
1621: else if (mode == RCS_KWEXP_OLD)
1622: buf[0] = 'o';
1623: else {
1624: if (mode & RCS_KWEXP_NAME)
1625: buf[i++] = 'k';
1626: if (mode & RCS_KWEXP_VAL)
1627: buf[i++] = 'v';
1628: if (mode & RCS_KWEXP_LKR)
1629: buf[i++] = 'l';
1630: }
1631:
1.39 joris 1632: if ((tmp = cvs_strdup(buf)) == NULL) {
1.26 jfb 1633: cvs_log(LP_ERRNO, "%s: failed to copy expansion mode",
1634: file->rf_path);
1635: return (-1);
1636: }
1637:
1.27 jfb 1638: if (file->rf_expand != NULL)
1.39 joris 1639: cvs_strfree(file->rf_expand);
1.26 jfb 1640: file->rf_expand = tmp;
1.64 niallo 1641: /* not synced anymore */
1642: file->rf_flags &= ~RCS_SYNCED;
1.26 jfb 1643:
1644: return (0);
1645: }
1646:
1647: /*
1648: * rcs_kwexp_get()
1649: *
1650: * Retrieve the keyword expansion mode to be used for the RCS file <file>.
1651: */
1652: int
1653: rcs_kwexp_get(RCSFILE *file)
1654: {
1655: return rcs_kflag_get(file->rf_expand);
1656: }
1657:
1658: /*
1.20 jfb 1659: * rcs_kflag_get()
1660: *
1661: * Get the keyword expansion mode from a set of character flags given in
1662: * <flags> and return the appropriate flag mask. In case of an error, the
1663: * returned mask will have the RCS_KWEXP_ERR bit set to 1.
1664: */
1665: int
1666: rcs_kflag_get(const char *flags)
1667: {
1668: int fl;
1669: size_t len;
1670: const char *fp;
1671:
1672: fl = 0;
1673: len = strlen(flags);
1674:
1675: for (fp = flags; *fp != '\0'; fp++) {
1676: if (*fp == 'k')
1677: fl |= RCS_KWEXP_NAME;
1678: else if (*fp == 'v')
1679: fl |= RCS_KWEXP_VAL;
1680: else if (*fp == 'l')
1681: fl |= RCS_KWEXP_LKR;
1682: else if (*fp == 'o') {
1683: if (len != 1)
1684: fl |= RCS_KWEXP_ERR;
1685: fl |= RCS_KWEXP_OLD;
1686: } else if (*fp == 'b') {
1687: if (len != 1)
1688: fl |= RCS_KWEXP_ERR;
1689: } else /* unknown letter */
1690: fl |= RCS_KWEXP_ERR;
1691: }
1692:
1693: return (fl);
1.32 jfb 1694: }
1695:
1696: /*
1697: * rcs_errstr()
1698: *
1699: * Get the error string matching the RCS error code <code>.
1700: */
1.57 xsa 1701: const char *
1.32 jfb 1702: rcs_errstr(int code)
1703: {
1.50 jfb 1704: const char *esp;
1705:
1706: if ((code < 0) || ((code >= (int)RCS_NERR) && (code != RCS_ERR_ERRNO)))
1707: esp = NULL;
1708: else if (code == RCS_ERR_ERRNO)
1709: esp = strerror(errno);
1710: else
1711: esp = rcs_errstrs[code];
1712: return (esp);
1.1 jfb 1713: }
1714:
1.21 jfb 1715: void
1716: rcs_kflag_usage(void)
1717: {
1718: fprintf(stderr, "Valid expansion modes include:\n"
1.22 jfb 1719: "\t-kkv\tGenerate keywords using the default form.\n"
1720: "\t-kkvl\tLike -kkv, except locker's name inserted.\n"
1721: "\t-kk\tGenerate only keyword names in keyword strings.\n"
1722: "\t-kv\tGenerate only keyword values in keyword strings.\n"
1723: "\t-ko\tGenerate old keyword string "
1.21 jfb 1724: "(no changes from checked in file).\n"
1.22 jfb 1725: "\t-kb\tGenerate binary file unmodified (merges not allowed).\n");
1.21 jfb 1726: }
1.1 jfb 1727:
1728: /*
1729: * rcs_parse()
1730: *
1731: * Parse the contents of file <path>, which are in the RCS format.
1732: * Returns 0 on success, or -1 on failure.
1733: */
1.26 jfb 1734: static int
1.1 jfb 1735: rcs_parse(RCSFILE *rfp)
1736: {
1737: int ret;
1738: struct rcs_pdata *pdp;
1739:
1.26 jfb 1740: if (rfp->rf_flags & RCS_PARSED)
1.1 jfb 1741: return (0);
1742:
1.26 jfb 1743: if ((pdp = (struct rcs_pdata *)malloc(sizeof(*pdp))) == NULL) {
1.50 jfb 1744: rcs_errno = RCS_ERR_ERRNO;
1.1 jfb 1745: cvs_log(LP_ERRNO, "failed to allocate RCS parser data");
1746: return (-1);
1747: }
1748: memset(pdp, 0, sizeof(*pdp));
1749:
1.18 jfb 1750: pdp->rp_lines = 0;
1.1 jfb 1751: pdp->rp_pttype = RCS_TOK_ERR;
1752:
1753: pdp->rp_file = fopen(rfp->rf_path, "r");
1754: if (pdp->rp_file == NULL) {
1.50 jfb 1755: rcs_errno = RCS_ERR_ERRNO;
1.1 jfb 1756: cvs_log(LP_ERRNO, "failed to open RCS file `%s'", rfp->rf_path);
1757: rcs_freepdata(pdp);
1758: return (-1);
1759: }
1760:
1.59 xsa 1761: pdp->rp_buf = (char *)malloc((size_t)RCS_BUFSIZE);
1.1 jfb 1762: if (pdp->rp_buf == NULL) {
1.50 jfb 1763: rcs_errno = RCS_ERR_ERRNO;
1.1 jfb 1764: cvs_log(LP_ERRNO, "failed to allocate RCS parser buffer");
1765: rcs_freepdata(pdp);
1766: return (-1);
1767: }
1768: pdp->rp_blen = RCS_BUFSIZE;
1.18 jfb 1769: pdp->rp_bufend = pdp->rp_buf + pdp->rp_blen - 1;
1.1 jfb 1770:
1771: /* ditch the strict lock */
1.26 jfb 1772: rfp->rf_flags &= ~RCS_SLOCK;
1.1 jfb 1773: rfp->rf_pdata = pdp;
1774:
1.31 jfb 1775: if ((ret = rcs_parse_admin(rfp)) < 0) {
1.1 jfb 1776: rcs_freepdata(pdp);
1777: return (-1);
1.31 jfb 1778: } else if (ret == RCS_TOK_NUM) {
1779: for (;;) {
1780: ret = rcs_parse_delta(rfp);
1781: if (ret == 0)
1782: break;
1783: else if (ret == -1) {
1784: rcs_freepdata(pdp);
1785: return (-1);
1786: }
1.1 jfb 1787: }
1788: }
1789:
1790: ret = rcs_gettok(rfp);
1791: if (ret != RCS_TOK_DESC) {
1.50 jfb 1792: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 1793: cvs_log(LP_ERR, "token `%s' found where RCS desc expected",
1794: RCS_TOKSTR(rfp));
1795: rcs_freepdata(pdp);
1796: return (-1);
1797: }
1798:
1799: ret = rcs_gettok(rfp);
1800: if (ret != RCS_TOK_STRING) {
1.50 jfb 1801: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 1802: cvs_log(LP_ERR, "token `%s' found where RCS desc expected",
1803: RCS_TOKSTR(rfp));
1804: rcs_freepdata(pdp);
1805: return (-1);
1806: }
1807:
1.39 joris 1808: rfp->rf_desc = cvs_strdup(RCS_TOKSTR(rfp));
1.10 joris 1809: if (rfp->rf_desc == NULL) {
1810: cvs_log(LP_ERRNO, "failed to duplicate rcs token");
1811: rcs_freepdata(pdp);
1812: return (-1);
1813: }
1.1 jfb 1814:
1815: for (;;) {
1816: ret = rcs_parse_deltatext(rfp);
1817: if (ret == 0)
1818: break;
1819: else if (ret == -1) {
1820: rcs_freepdata(pdp);
1821: return (-1);
1822: }
1823: }
1824:
1825: rcs_freepdata(pdp);
1826:
1827: rfp->rf_pdata = NULL;
1.26 jfb 1828: rfp->rf_flags |= RCS_PARSED | RCS_SYNCED;
1.1 jfb 1829:
1830: return (0);
1831: }
1832:
1833: /*
1834: * rcs_parse_admin()
1835: *
1836: * Parse the administrative portion of an RCS file.
1.31 jfb 1837: * Returns the type of the first token found after the admin section on
1838: * success, or -1 on failure.
1.1 jfb 1839: */
1840: static int
1841: rcs_parse_admin(RCSFILE *rfp)
1842: {
1843: u_int i;
1844: int tok, ntok, hmask;
1845: struct rcs_key *rk;
1846:
1847: /* hmask is a mask of the headers already encountered */
1848: hmask = 0;
1849: for (;;) {
1850: tok = rcs_gettok(rfp);
1851: if (tok == RCS_TOK_ERR) {
1.50 jfb 1852: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 1853: cvs_log(LP_ERR, "parse error in RCS admin section");
1854: return (-1);
1.31 jfb 1855: } else if ((tok == RCS_TOK_NUM) || (tok == RCS_TOK_DESC)) {
1856: /*
1857: * Assume this is the start of the first delta or
1858: * that we are dealing with an empty RCS file and
1859: * we just found the description.
1860: */
1.1 jfb 1861: rcs_pushtok(rfp, RCS_TOKSTR(rfp), tok);
1.31 jfb 1862: return (tok);
1.1 jfb 1863: }
1864:
1865: rk = NULL;
1.18 jfb 1866: for (i = 0; i < RCS_NKEYS; i++)
1.1 jfb 1867: if (rcs_keys[i].rk_id == tok)
1868: rk = &(rcs_keys[i]);
1869:
1870: if (hmask & (1 << tok)) {
1.50 jfb 1871: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 1872: cvs_log(LP_ERR, "duplicate RCS key");
1873: return (-1);
1874: }
1875: hmask |= (1 << tok);
1876:
1877: switch (tok) {
1878: case RCS_TOK_HEAD:
1879: case RCS_TOK_BRANCH:
1880: case RCS_TOK_COMMENT:
1881: case RCS_TOK_EXPAND:
1882: ntok = rcs_gettok(rfp);
1883: if (ntok == RCS_TOK_SCOLON)
1884: break;
1885: if (ntok != rk->rk_val) {
1.50 jfb 1886: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 1887: cvs_log(LP_ERR,
1888: "invalid value type for RCS key `%s'",
1889: rk->rk_str);
1890: }
1891:
1892: if (tok == RCS_TOK_HEAD) {
1.28 jfb 1893: if (rfp->rf_head == NULL) {
1894: rfp->rf_head = rcsnum_alloc();
1895: if (rfp->rf_head == NULL)
1896: return (-1);
1897: }
1.1 jfb 1898: rcsnum_aton(RCS_TOKSTR(rfp), NULL,
1899: rfp->rf_head);
1.14 deraadt 1900: } else if (tok == RCS_TOK_BRANCH) {
1.35 jfb 1901: if (rfp->rf_branch == NULL) {
1902: rfp->rf_branch = rcsnum_alloc();
1903: if (rfp->rf_branch == NULL)
1904: return (-1);
1905: }
1906: if (rcsnum_aton(RCS_TOKSTR(rfp), NULL,
1907: rfp->rf_branch) < 0)
1908: return (-1);
1.14 deraadt 1909: } else if (tok == RCS_TOK_COMMENT) {
1.39 joris 1910: rfp->rf_comment = cvs_strdup(RCS_TOKSTR(rfp));
1.10 joris 1911: if (rfp->rf_comment == NULL) {
1912: cvs_log(LP_ERRNO,
1913: "failed to duplicate rcs token");
1914: return (-1);
1915: }
1.14 deraadt 1916: } else if (tok == RCS_TOK_EXPAND) {
1.39 joris 1917: rfp->rf_expand = cvs_strdup(RCS_TOKSTR(rfp));
1.10 joris 1918: if (rfp->rf_expand == NULL) {
1919: cvs_log(LP_ERRNO,
1920: "failed to duplicate rcs token");
1921: return (-1);
1922: }
1.1 jfb 1923: }
1924:
1925: /* now get the expected semi-colon */
1926: ntok = rcs_gettok(rfp);
1927: if (ntok != RCS_TOK_SCOLON) {
1.50 jfb 1928: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 1929: cvs_log(LP_ERR,
1930: "missing semi-colon after RCS `%s' key",
1.26 jfb 1931: rk->rk_str);
1.1 jfb 1932: return (-1);
1933: }
1934: break;
1935: case RCS_TOK_ACCESS:
1.29 jfb 1936: if (rcs_parse_access(rfp) < 0)
1937: return (-1);
1.1 jfb 1938: break;
1939: case RCS_TOK_SYMBOLS:
1.29 jfb 1940: if (rcs_parse_symbols(rfp) < 0)
1941: return (-1);
1.1 jfb 1942: break;
1943: case RCS_TOK_LOCKS:
1.29 jfb 1944: if (rcs_parse_locks(rfp) < 0)
1945: return (-1);
1.1 jfb 1946: break;
1947: default:
1.50 jfb 1948: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 1949: cvs_log(LP_ERR,
1950: "unexpected token `%s' in RCS admin section",
1951: RCS_TOKSTR(rfp));
1952: return (-1);
1953: }
1954: }
1955:
1956: return (0);
1957: }
1958:
1959: /*
1960: * rcs_parse_delta()
1961: *
1962: * Parse an RCS delta section and allocate the structure to store that delta's
1963: * information in the <rfp> delta list.
1964: * Returns 1 if the section was parsed OK, 0 if it is the last delta, and
1965: * -1 on error.
1966: */
1967: static int
1968: rcs_parse_delta(RCSFILE *rfp)
1969: {
1970: int ret, tok, ntok, hmask;
1971: u_int i;
1972: char *tokstr;
1.3 vincent 1973: RCSNUM *datenum;
1.1 jfb 1974: struct rcs_delta *rdp;
1975: struct rcs_key *rk;
1976:
1977: rdp = (struct rcs_delta *)malloc(sizeof(*rdp));
1978: if (rdp == NULL) {
1.50 jfb 1979: rcs_errno = RCS_ERR_ERRNO;
1.1 jfb 1980: cvs_log(LP_ERRNO, "failed to allocate RCS delta structure");
1981: return (-1);
1982: }
1983: memset(rdp, 0, sizeof(*rdp));
1984:
1985: rdp->rd_num = rcsnum_alloc();
1.11 joris 1986: if (rdp->rd_num == NULL) {
1987: rcs_freedelta(rdp);
1988: return (-1);
1989: }
1.1 jfb 1990: rdp->rd_next = rcsnum_alloc();
1.11 joris 1991: if (rdp->rd_next == NULL) {
1992: rcs_freedelta(rdp);
1993: return (-1);
1994: }
1.1 jfb 1995:
1996: TAILQ_INIT(&(rdp->rd_branches));
1.52 jfb 1997: TAILQ_INIT(&(rdp->rd_snodes));
1.1 jfb 1998:
1999: tok = rcs_gettok(rfp);
2000: if (tok != RCS_TOK_NUM) {
1.52 jfb 2001: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2002: cvs_log(LP_ERR, "unexpected token `%s' at start of delta",
2003: RCS_TOKSTR(rfp));
2004: rcs_freedelta(rdp);
2005: return (-1);
2006: }
2007: rcsnum_aton(RCS_TOKSTR(rfp), NULL, rdp->rd_num);
2008:
2009: hmask = 0;
2010: ret = 0;
2011: tokstr = NULL;
2012:
2013: for (;;) {
2014: tok = rcs_gettok(rfp);
2015: if (tok == RCS_TOK_ERR) {
1.50 jfb 2016: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2017: cvs_log(LP_ERR, "parse error in RCS delta section");
2018: rcs_freedelta(rdp);
2019: return (-1);
1.14 deraadt 2020: } else if (tok == RCS_TOK_NUM || tok == RCS_TOK_DESC) {
1.15 tedu 2021: rcs_pushtok(rfp, RCS_TOKSTR(rfp), tok);
1.1 jfb 2022: ret = (tok == RCS_TOK_NUM ? 1 : 0);
2023: break;
2024: }
2025:
2026: rk = NULL;
1.18 jfb 2027: for (i = 0; i < RCS_NKEYS; i++)
1.1 jfb 2028: if (rcs_keys[i].rk_id == tok)
2029: rk = &(rcs_keys[i]);
2030:
2031: if (hmask & (1 << tok)) {
1.50 jfb 2032: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2033: cvs_log(LP_ERR, "duplicate RCS key");
2034: rcs_freedelta(rdp);
2035: return (-1);
2036: }
2037: hmask |= (1 << tok);
2038:
2039: switch (tok) {
2040: case RCS_TOK_DATE:
2041: case RCS_TOK_AUTHOR:
2042: case RCS_TOK_STATE:
2043: case RCS_TOK_NEXT:
2044: ntok = rcs_gettok(rfp);
2045: if (ntok == RCS_TOK_SCOLON) {
2046: if (rk->rk_flags & RCS_VOPT)
2047: break;
2048: else {
1.50 jfb 2049: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2050: cvs_log(LP_ERR, "missing mandatory "
2051: "value to RCS key `%s'",
2052: rk->rk_str);
2053: rcs_freedelta(rdp);
2054: return (-1);
2055: }
2056: }
2057:
2058: if (ntok != rk->rk_val) {
1.50 jfb 2059: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2060: cvs_log(LP_ERR,
2061: "invalid value type for RCS key `%s'",
2062: rk->rk_str);
2063: rcs_freedelta(rdp);
2064: return (-1);
2065: }
2066:
2067: if (tokstr != NULL)
1.41 jfb 2068: cvs_strfree(tokstr);
1.39 joris 2069: tokstr = cvs_strdup(RCS_TOKSTR(rfp));
1.10 joris 2070: if (tokstr == NULL) {
1.15 tedu 2071: cvs_log(LP_ERRNO,
1.10 joris 2072: "failed to duplicate rcs token");
2073: rcs_freedelta(rdp);
2074: return (-1);
2075: }
1.1 jfb 2076:
2077: /* now get the expected semi-colon */
2078: ntok = rcs_gettok(rfp);
2079: if (ntok != RCS_TOK_SCOLON) {
1.50 jfb 2080: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2081: cvs_log(LP_ERR,
2082: "missing semi-colon after RCS `%s' key",
1.26 jfb 2083: rk->rk_str);
1.41 jfb 2084: cvs_strfree(tokstr);
1.1 jfb 2085: rcs_freedelta(rdp);
2086: return (-1);
2087: }
2088:
2089: if (tok == RCS_TOK_DATE) {
1.25 jfb 2090: if ((datenum = rcsnum_parse(tokstr)) == NULL) {
1.41 jfb 2091: cvs_strfree(tokstr);
1.11 joris 2092: rcs_freedelta(rdp);
2093: return (-1);
2094: }
1.3 vincent 2095: if (datenum->rn_len != 6) {
1.50 jfb 2096: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2097: cvs_log(LP_ERR,
2098: "RCS date specification has %s "
2099: "fields",
1.3 vincent 2100: (datenum->rn_len > 6) ? "too many" :
1.1 jfb 2101: "missing");
1.41 jfb 2102: cvs_strfree(tokstr);
1.1 jfb 2103: rcs_freedelta(rdp);
1.37 tedu 2104: rcsnum_free(datenum);
2105: return (-1);
1.1 jfb 2106: }
1.3 vincent 2107: rdp->rd_date.tm_year = datenum->rn_id[0];
1.19 jfb 2108: if (rdp->rd_date.tm_year >= 1900)
2109: rdp->rd_date.tm_year -= 1900;
1.3 vincent 2110: rdp->rd_date.tm_mon = datenum->rn_id[1] - 1;
2111: rdp->rd_date.tm_mday = datenum->rn_id[2];
2112: rdp->rd_date.tm_hour = datenum->rn_id[3];
2113: rdp->rd_date.tm_min = datenum->rn_id[4];
2114: rdp->rd_date.tm_sec = datenum->rn_id[5];
2115: rcsnum_free(datenum);
1.14 deraadt 2116: } else if (tok == RCS_TOK_AUTHOR) {
1.1 jfb 2117: rdp->rd_author = tokstr;
2118: tokstr = NULL;
1.14 deraadt 2119: } else if (tok == RCS_TOK_STATE) {
1.1 jfb 2120: rdp->rd_state = tokstr;
2121: tokstr = NULL;
1.14 deraadt 2122: } else if (tok == RCS_TOK_NEXT) {
1.1 jfb 2123: rcsnum_aton(tokstr, NULL, rdp->rd_next);
2124: }
2125: break;
2126: case RCS_TOK_BRANCHES:
1.46 jfb 2127: if (rcs_parse_branches(rfp, rdp) < 0) {
2128: rcs_freedelta(rdp);
2129: return (-1);
2130: }
1.1 jfb 2131: break;
2132: default:
1.50 jfb 2133: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2134: cvs_log(LP_ERR,
2135: "unexpected token `%s' in RCS delta",
2136: RCS_TOKSTR(rfp));
2137: rcs_freedelta(rdp);
2138: return (-1);
2139: }
2140: }
2141:
1.13 jfb 2142: if (tokstr != NULL)
1.39 joris 2143: cvs_strfree(tokstr);
1.13 jfb 2144:
1.1 jfb 2145: TAILQ_INSERT_TAIL(&(rfp->rf_delta), rdp, rd_list);
1.26 jfb 2146: rfp->rf_ndelta++;
1.1 jfb 2147:
2148: return (ret);
2149: }
2150:
2151: /*
2152: * rcs_parse_deltatext()
2153: *
2154: * Parse an RCS delta text section and fill in the log and text field of the
2155: * appropriate delta section.
2156: * Returns 1 if the section was parsed OK, 0 if it is the last delta, and
2157: * -1 on error.
2158: */
2159: static int
2160: rcs_parse_deltatext(RCSFILE *rfp)
2161: {
2162: int tok;
2163: RCSNUM *tnum;
2164: struct rcs_delta *rdp;
2165:
2166: tok = rcs_gettok(rfp);
2167: if (tok == RCS_TOK_EOF)
2168: return (0);
2169:
2170: if (tok != RCS_TOK_NUM) {
1.50 jfb 2171: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2172: cvs_log(LP_ERR,
2173: "unexpected token `%s' at start of RCS delta text",
2174: RCS_TOKSTR(rfp));
2175: return (-1);
2176: }
1.13 jfb 2177:
2178: tnum = rcsnum_alloc();
2179: if (tnum == NULL)
2180: return (-1);
1.1 jfb 2181: rcsnum_aton(RCS_TOKSTR(rfp), NULL, tnum);
2182:
2183: TAILQ_FOREACH(rdp, &(rfp->rf_delta), rd_list) {
2184: if (rcsnum_cmp(tnum, rdp->rd_num, 0) == 0)
2185: break;
2186: }
1.13 jfb 2187: rcsnum_free(tnum);
2188:
1.1 jfb 2189: if (rdp == NULL) {
2190: cvs_log(LP_ERR, "RCS delta text `%s' has no matching delta",
2191: RCS_TOKSTR(rfp));
2192: return (-1);
2193: }
2194:
2195: tok = rcs_gettok(rfp);
2196: if (tok != RCS_TOK_LOG) {
1.50 jfb 2197: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2198: cvs_log(LP_ERR, "unexpected token `%s' where RCS log expected",
2199: RCS_TOKSTR(rfp));
2200: return (-1);
2201: }
2202:
2203: tok = rcs_gettok(rfp);
2204: if (tok != RCS_TOK_STRING) {
1.50 jfb 2205: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2206: cvs_log(LP_ERR, "unexpected token `%s' where RCS log expected",
2207: RCS_TOKSTR(rfp));
2208: return (-1);
2209: }
1.39 joris 2210: rdp->rd_log = cvs_strdup(RCS_TOKSTR(rfp));
1.1 jfb 2211: if (rdp->rd_log == NULL) {
2212: cvs_log(LP_ERRNO, "failed to copy RCS deltatext log");
2213: return (-1);
2214: }
2215:
2216: tok = rcs_gettok(rfp);
2217: if (tok != RCS_TOK_TEXT) {
1.50 jfb 2218: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2219: cvs_log(LP_ERR, "unexpected token `%s' where RCS text expected",
2220: RCS_TOKSTR(rfp));
2221: return (-1);
2222: }
2223:
2224: tok = rcs_gettok(rfp);
2225: if (tok != RCS_TOK_STRING) {
1.50 jfb 2226: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2227: cvs_log(LP_ERR, "unexpected token `%s' where RCS text expected",
2228: RCS_TOKSTR(rfp));
2229: return (-1);
2230: }
2231:
1.74 joris 2232: rdp->rd_text = (u_char *)malloc(RCS_TOKLEN(rfp) + 1);
1.1 jfb 2233: if (rdp->rd_text == NULL) {
2234: cvs_log(LP_ERRNO, "failed to copy RCS delta text");
2235: return (-1);
2236: }
1.74 joris 2237: strlcpy(rdp->rd_text, RCS_TOKSTR(rfp), (RCS_TOKLEN(rfp) + 1));
1.42 jfb 2238: rdp->rd_tlen = RCS_TOKLEN(rfp);
1.1 jfb 2239:
2240: return (1);
2241: }
2242:
2243: /*
2244: * rcs_parse_access()
2245: *
2246: * Parse the access list given as value to the `access' keyword.
2247: * Returns 0 on success, or -1 on failure.
2248: */
2249: static int
2250: rcs_parse_access(RCSFILE *rfp)
2251: {
2252: int type;
2253:
2254: while ((type = rcs_gettok(rfp)) != RCS_TOK_SCOLON) {
2255: if (type != RCS_TOK_ID) {
1.50 jfb 2256: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2257: cvs_log(LP_ERR, "unexpected token `%s' in access list",
2258: RCS_TOKSTR(rfp));
2259: return (-1);
2260: }
1.29 jfb 2261:
2262: if (rcs_access_add(rfp, RCS_TOKSTR(rfp)) < 0)
2263: return (-1);
1.1 jfb 2264: }
2265:
2266: return (0);
2267: }
2268:
2269: /*
2270: * rcs_parse_symbols()
2271: *
2272: * Parse the symbol list given as value to the `symbols' keyword.
2273: * Returns 0 on success, or -1 on failure.
2274: */
2275: static int
2276: rcs_parse_symbols(RCSFILE *rfp)
2277: {
2278: int type;
2279: struct rcs_sym *symp;
2280:
2281: for (;;) {
2282: type = rcs_gettok(rfp);
2283: if (type == RCS_TOK_SCOLON)
2284: break;
2285:
1.41 jfb 2286: if (type != RCS_TOK_ID) {
1.50 jfb 2287: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2288: cvs_log(LP_ERR, "unexpected token `%s' in symbol list",
2289: RCS_TOKSTR(rfp));
2290: return (-1);
2291: }
2292:
2293: symp = (struct rcs_sym *)malloc(sizeof(*symp));
2294: if (symp == NULL) {
1.50 jfb 2295: rcs_errno = RCS_ERR_ERRNO;
1.1 jfb 2296: cvs_log(LP_ERRNO, "failed to allocate RCS symbol");
2297: return (-1);
2298: }
1.39 joris 2299: symp->rs_name = cvs_strdup(RCS_TOKSTR(rfp));
1.10 joris 2300: if (symp->rs_name == NULL) {
2301: cvs_log(LP_ERRNO, "failed to duplicate rcs token");
2302: free(symp);
2303: return (-1);
2304: }
2305:
1.1 jfb 2306: symp->rs_num = rcsnum_alloc();
1.11 joris 2307: if (symp->rs_num == NULL) {
2308: cvs_log(LP_ERRNO, "failed to allocate rcsnum info");
1.39 joris 2309: cvs_strfree(symp->rs_name);
1.11 joris 2310: free(symp);
2311: return (-1);
2312: }
1.1 jfb 2313:
2314: type = rcs_gettok(rfp);
2315: if (type != RCS_TOK_COLON) {
1.50 jfb 2316: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2317: cvs_log(LP_ERR, "unexpected token `%s' in symbol list",
2318: RCS_TOKSTR(rfp));
1.11 joris 2319: rcsnum_free(symp->rs_num);
1.39 joris 2320: cvs_strfree(symp->rs_name);
1.1 jfb 2321: free(symp);
2322: return (-1);
2323: }
2324:
2325: type = rcs_gettok(rfp);
2326: if (type != RCS_TOK_NUM) {
1.50 jfb 2327: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2328: cvs_log(LP_ERR, "unexpected token `%s' in symbol list",
2329: RCS_TOKSTR(rfp));
1.11 joris 2330: rcsnum_free(symp->rs_num);
1.39 joris 2331: cvs_strfree(symp->rs_name);
1.1 jfb 2332: free(symp);
2333: return (-1);
2334: }
2335:
2336: if (rcsnum_aton(RCS_TOKSTR(rfp), NULL, symp->rs_num) < 0) {
2337: cvs_log(LP_ERR, "failed to parse RCS NUM `%s'",
2338: RCS_TOKSTR(rfp));
1.11 joris 2339: rcsnum_free(symp->rs_num);
1.39 joris 2340: cvs_strfree(symp->rs_name);
1.1 jfb 2341: free(symp);
2342: return (-1);
2343: }
2344:
1.43 jfb 2345: TAILQ_INSERT_TAIL(&(rfp->rf_symbols), symp, rs_list);
1.1 jfb 2346: }
2347:
2348: return (0);
2349: }
2350:
2351: /*
2352: * rcs_parse_locks()
2353: *
2354: * Parse the lock list given as value to the `locks' keyword.
2355: * Returns 0 on success, or -1 on failure.
2356: */
2357: static int
2358: rcs_parse_locks(RCSFILE *rfp)
2359: {
2360: int type;
2361: struct rcs_lock *lkp;
2362:
2363: for (;;) {
2364: type = rcs_gettok(rfp);
2365: if (type == RCS_TOK_SCOLON)
2366: break;
2367:
2368: if (type != RCS_TOK_ID) {
1.50 jfb 2369: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2370: cvs_log(LP_ERR, "unexpected token `%s' in lock list",
2371: RCS_TOKSTR(rfp));
2372: return (-1);
2373: }
2374:
2375: lkp = (struct rcs_lock *)malloc(sizeof(*lkp));
2376: if (lkp == NULL) {
2377: cvs_log(LP_ERRNO, "failed to allocate RCS lock");
2378: return (-1);
2379: }
1.76 joris 2380:
2381: if ((lkp->rl_name = cvs_strdup(RCS_TOKSTR(rfp))) == NULL) {
2382: cvs_log(LP_ERR, "failed to save locking user");
2383: free(lkp);
2384: return (-1);
2385: }
2386:
1.1 jfb 2387: lkp->rl_num = rcsnum_alloc();
1.11 joris 2388: if (lkp->rl_num == NULL) {
1.76 joris 2389: cvs_strfree(lkp->rl_name);
1.11 joris 2390: free(lkp);
2391: return (-1);
2392: }
1.1 jfb 2393:
2394: type = rcs_gettok(rfp);
2395: if (type != RCS_TOK_COLON) {
1.50 jfb 2396: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2397: cvs_log(LP_ERR, "unexpected token `%s' in symbol list",
2398: RCS_TOKSTR(rfp));
1.37 tedu 2399: rcsnum_free(lkp->rl_num);
1.76 joris 2400: cvs_strfree(lkp->rl_name);
1.1 jfb 2401: free(lkp);
2402: return (-1);
2403: }
2404:
2405: type = rcs_gettok(rfp);
2406: if (type != RCS_TOK_NUM) {
1.50 jfb 2407: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2408: cvs_log(LP_ERR, "unexpected token `%s' in symbol list",
2409: RCS_TOKSTR(rfp));
1.37 tedu 2410: rcsnum_free(lkp->rl_num);
1.76 joris 2411: cvs_strfree(lkp->rl_name);
1.1 jfb 2412: free(lkp);
2413: return (-1);
2414: }
2415:
2416: if (rcsnum_aton(RCS_TOKSTR(rfp), NULL, lkp->rl_num) < 0) {
2417: cvs_log(LP_ERR, "failed to parse RCS NUM `%s'",
2418: RCS_TOKSTR(rfp));
1.37 tedu 2419: rcsnum_free(lkp->rl_num);
1.76 joris 2420: cvs_strfree(lkp->rl_name);
1.1 jfb 2421: free(lkp);
2422: return (-1);
2423: }
2424:
2425: TAILQ_INSERT_HEAD(&(rfp->rf_locks), lkp, rl_list);
2426: }
2427:
2428: /* check if we have a `strict' */
2429: type = rcs_gettok(rfp);
2430: if (type != RCS_TOK_STRICT) {
2431: rcs_pushtok(rfp, RCS_TOKSTR(rfp), type);
1.14 deraadt 2432: } else {
1.26 jfb 2433: rfp->rf_flags |= RCS_SLOCK;
1.1 jfb 2434:
2435: type = rcs_gettok(rfp);
2436: if (type != RCS_TOK_SCOLON) {
1.50 jfb 2437: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2438: cvs_log(LP_ERR,
2439: "missing semi-colon after `strict' keyword");
2440: return (-1);
2441: }
2442: }
2443:
2444: return (0);
2445: }
2446:
2447: /*
2448: * rcs_parse_branches()
2449: *
2450: * Parse the list of branches following a `branches' keyword in a delta.
2451: * Returns 0 on success, or -1 on failure.
2452: */
2453: static int
2454: rcs_parse_branches(RCSFILE *rfp, struct rcs_delta *rdp)
2455: {
2456: int type;
2457: struct rcs_branch *brp;
2458:
2459: for (;;) {
2460: type = rcs_gettok(rfp);
2461: if (type == RCS_TOK_SCOLON)
2462: break;
2463:
2464: if (type != RCS_TOK_NUM) {
1.50 jfb 2465: rcs_errno = RCS_ERR_PARSE;
1.1 jfb 2466: cvs_log(LP_ERR,
2467: "unexpected token `%s' in list of branches",
2468: RCS_TOKSTR(rfp));
2469: return (-1);
2470: }
2471:
2472: brp = (struct rcs_branch *)malloc(sizeof(*brp));
2473: if (brp == NULL) {
1.50 jfb 2474: rcs_errno = RCS_ERR_ERRNO;
1.1 jfb 2475: cvs_log(LP_ERRNO, "failed to allocate RCS branch");
2476: return (-1);
2477: }
1.46 jfb 2478: brp->rb_num = rcsnum_parse(RCS_TOKSTR(rfp));
1.11 joris 2479: if (brp->rb_num == NULL) {
2480: free(brp);
2481: return (-1);
2482: }
1.1 jfb 2483:
2484: TAILQ_INSERT_TAIL(&(rdp->rd_branches), brp, rb_list);
2485: }
2486:
2487: return (0);
2488: }
2489:
2490: /*
2491: * rcs_freedelta()
2492: *
2493: * Free the contents of a delta structure.
2494: */
1.18 jfb 2495: static void
1.1 jfb 2496: rcs_freedelta(struct rcs_delta *rdp)
2497: {
1.12 jfb 2498: struct rcs_branch *rb;
1.1 jfb 2499: struct rcs_delta *crdp;
2500:
1.12 jfb 2501: if (rdp->rd_num != NULL)
2502: rcsnum_free(rdp->rd_num);
2503: if (rdp->rd_next != NULL)
2504: rcsnum_free(rdp->rd_next);
2505:
1.1 jfb 2506: if (rdp->rd_author != NULL)
1.39 joris 2507: cvs_strfree(rdp->rd_author);
1.1 jfb 2508: if (rdp->rd_state != NULL)
1.39 joris 2509: cvs_strfree(rdp->rd_state);
1.1 jfb 2510: if (rdp->rd_log != NULL)
1.39 joris 2511: cvs_strfree(rdp->rd_log);
1.1 jfb 2512: if (rdp->rd_text != NULL)
1.45 jfb 2513: free(rdp->rd_text);
1.12 jfb 2514:
2515: while ((rb = TAILQ_FIRST(&(rdp->rd_branches))) != NULL) {
2516: TAILQ_REMOVE(&(rdp->rd_branches), rb, rb_list);
2517: rcsnum_free(rb->rb_num);
2518: free(rb);
2519: }
1.1 jfb 2520:
2521: while ((crdp = TAILQ_FIRST(&(rdp->rd_snodes))) != NULL) {
2522: TAILQ_REMOVE(&(rdp->rd_snodes), crdp, rd_list);
2523: rcs_freedelta(crdp);
2524: }
2525:
2526: free(rdp);
2527: }
2528:
2529: /*
2530: * rcs_freepdata()
2531: *
2532: * Free the contents of the parser data structure.
2533: */
2534: static void
2535: rcs_freepdata(struct rcs_pdata *pd)
2536: {
2537: if (pd->rp_file != NULL)
2538: (void)fclose(pd->rp_file);
2539: if (pd->rp_buf != NULL)
2540: free(pd->rp_buf);
2541: free(pd);
2542: }
2543:
2544: /*
2545: * rcs_gettok()
2546: *
2547: * Get the next RCS token from the string <str>.
2548: */
2549: static int
2550: rcs_gettok(RCSFILE *rfp)
2551: {
2552: u_int i;
2553: int ch, last, type;
1.18 jfb 2554: size_t len;
2555: char *bp;
1.1 jfb 2556: struct rcs_pdata *pdp = (struct rcs_pdata *)rfp->rf_pdata;
2557:
2558: type = RCS_TOK_ERR;
2559: bp = pdp->rp_buf;
1.42 jfb 2560: pdp->rp_tlen = 0;
1.1 jfb 2561: *bp = '\0';
2562:
2563: if (pdp->rp_pttype != RCS_TOK_ERR) {
2564: type = pdp->rp_pttype;
2565: strlcpy(pdp->rp_buf, pdp->rp_ptok, pdp->rp_blen);
2566: pdp->rp_pttype = RCS_TOK_ERR;
2567: return (type);
2568: }
2569:
2570: /* skip leading whitespace */
2571: /* XXX we must skip backspace too for compatibility, should we? */
2572: do {
2573: ch = getc(pdp->rp_file);
2574: if (ch == '\n')
1.18 jfb 2575: pdp->rp_lines++;
1.1 jfb 2576: } while (isspace(ch));
2577:
2578: if (ch == EOF) {
2579: type = RCS_TOK_EOF;
1.14 deraadt 2580: } else if (ch == ';') {
1.1 jfb 2581: type = RCS_TOK_SCOLON;
1.14 deraadt 2582: } else if (ch == ':') {
1.1 jfb 2583: type = RCS_TOK_COLON;
1.14 deraadt 2584: } else if (isalpha(ch)) {
1.31 jfb 2585: type = RCS_TOK_ID;
1.1 jfb 2586: *(bp++) = ch;
1.18 jfb 2587: for (;;) {
1.1 jfb 2588: ch = getc(pdp->rp_file);
1.11 joris 2589: if (!isalnum(ch) && ch != '_' && ch != '-') {
1.1 jfb 2590: ungetc(ch, pdp->rp_file);
2591: break;
2592: }
2593: *(bp++) = ch;
1.42 jfb 2594: pdp->rp_tlen++;
1.18 jfb 2595: if (bp == pdp->rp_bufend - 1) {
2596: len = bp - pdp->rp_buf;
2597: if (rcs_growbuf(rfp) < 0) {
2598: type = RCS_TOK_ERR;
2599: break;
2600: }
2601: bp = pdp->rp_buf + len;
2602: }
1.1 jfb 2603: }
2604: *bp = '\0';
2605:
1.18 jfb 2606: if (type != RCS_TOK_ERR) {
2607: for (i = 0; i < RCS_NKEYS; i++) {
2608: if (strcmp(rcs_keys[i].rk_str,
2609: pdp->rp_buf) == 0) {
2610: type = rcs_keys[i].rk_id;
2611: break;
2612: }
1.1 jfb 2613: }
2614: }
1.14 deraadt 2615: } else if (ch == '@') {
1.1 jfb 2616: /* we have a string */
1.18 jfb 2617: type = RCS_TOK_STRING;
1.1 jfb 2618: for (;;) {
2619: ch = getc(pdp->rp_file);
2620: if (ch == '@') {
2621: ch = getc(pdp->rp_file);
2622: if (ch != '@') {
2623: ungetc(ch, pdp->rp_file);
2624: break;
2625: }
1.14 deraadt 2626: } else if (ch == '\n')
1.18 jfb 2627: pdp->rp_lines++;
1.1 jfb 2628:
2629: *(bp++) = ch;
1.42 jfb 2630: pdp->rp_tlen++;
1.18 jfb 2631: if (bp == pdp->rp_bufend - 1) {
2632: len = bp - pdp->rp_buf;
2633: if (rcs_growbuf(rfp) < 0) {
2634: type = RCS_TOK_ERR;
2635: break;
2636: }
2637: bp = pdp->rp_buf + len;
2638: }
1.1 jfb 2639: }
2640:
2641: *bp = '\0';
1.14 deraadt 2642: } else if (isdigit(ch)) {
1.1 jfb 2643: *(bp++) = ch;
2644: last = ch;
2645: type = RCS_TOK_NUM;
2646:
2647: for (;;) {
2648: ch = getc(pdp->rp_file);
1.18 jfb 2649: if (bp == pdp->rp_bufend)
1.1 jfb 2650: break;
2651: if (!isdigit(ch) && ch != '.') {
2652: ungetc(ch, pdp->rp_file);
2653: break;
2654: }
2655:
2656: if (last == '.' && ch == '.') {
2657: type = RCS_TOK_ERR;
2658: break;
2659: }
2660: last = ch;
2661: *(bp++) = ch;
1.42 jfb 2662: pdp->rp_tlen++;
1.1 jfb 2663: }
1.18 jfb 2664: *bp = '\0';
1.1 jfb 2665: }
2666:
2667: return (type);
2668: }
2669:
2670: /*
2671: * rcs_pushtok()
2672: *
2673: * Push a token back in the parser's token buffer.
2674: */
2675: static int
2676: rcs_pushtok(RCSFILE *rfp, const char *tok, int type)
2677: {
2678: struct rcs_pdata *pdp = (struct rcs_pdata *)rfp->rf_pdata;
2679:
2680: if (pdp->rp_pttype != RCS_TOK_ERR)
2681: return (-1);
2682:
2683: pdp->rp_pttype = type;
2684: strlcpy(pdp->rp_ptok, tok, sizeof(pdp->rp_ptok));
2685: return (0);
2686: }
2687:
2688:
2689: /*
2690: * rcs_splitlines()
2691: *
2692: * Split the contents of a file into a list of lines.
2693: */
2694: static struct rcs_foo*
2695: rcs_splitlines(const char *fcont)
2696: {
2697: char *dcp;
2698: struct rcs_foo *foo;
2699: struct rcs_line *lp;
2700:
2701: foo = (struct rcs_foo *)malloc(sizeof(*foo));
2702: if (foo == NULL) {
2703: cvs_log(LP_ERR, "failed to allocate line structure");
2704: return (NULL);
2705: }
2706: TAILQ_INIT(&(foo->rl_lines));
2707: foo->rl_nblines = 0;
2708: foo->rl_data = strdup(fcont);
2709: if (foo->rl_data == NULL) {
2710: cvs_log(LP_ERRNO, "failed to copy file contents");
2711: free(foo);
2712: return (NULL);
2713: }
2714:
2715: /*
2716: * Add a first bogus line with line number 0. This is used so we
2717: * can position the line pointer before 1 when changing the first line
2718: * in rcs_patch().
2719: */
2720: lp = (struct rcs_line *)malloc(sizeof(*lp));
1.38 joris 2721: if (lp == NULL) {
2722: rcs_freefoo(foo);
1.1 jfb 2723: return (NULL);
1.38 joris 2724: }
1.5 vincent 2725:
1.1 jfb 2726: lp->rl_line = NULL;
2727: lp->rl_lineno = 0;
2728: TAILQ_INSERT_TAIL(&(foo->rl_lines), lp, rl_list);
2729:
2730:
2731: for (dcp = foo->rl_data; *dcp != '\0';) {
2732: lp = (struct rcs_line *)malloc(sizeof(*lp));
2733: if (lp == NULL) {
1.38 joris 2734: rcs_freefoo(foo);
1.1 jfb 2735: cvs_log(LP_ERR, "failed to allocate line entry");
2736: return (NULL);
2737: }
2738:
2739: lp->rl_line = dcp;
2740: lp->rl_lineno = ++(foo->rl_nblines);
2741: TAILQ_INSERT_TAIL(&(foo->rl_lines), lp, rl_list);
2742:
2743: dcp = strchr(dcp, '\n');
2744: if (dcp == NULL) {
2745: break;
2746: }
2747: *(dcp++) = '\0';
2748: }
2749:
2750: return (foo);
1.5 vincent 2751: }
2752:
2753: static void
2754: rcs_freefoo(struct rcs_foo *fp)
2755: {
2756: struct rcs_line *lp;
2757:
2758: while ((lp = TAILQ_FIRST(&fp->rl_lines)) != NULL) {
2759: TAILQ_REMOVE(&fp->rl_lines, lp, rl_list);
2760: free(lp);
2761: }
2762: free(fp->rl_data);
2763: free(fp);
1.18 jfb 2764: }
2765:
2766: /*
2767: * rcs_growbuf()
2768: *
2769: * Attempt to grow the internal parse buffer for the RCS file <rf> by
2770: * RCS_BUFEXTSIZE.
2771: * In case of failure, the original buffer is left unmodified.
2772: * Returns 0 on success, or -1 on failure.
2773: */
2774: static int
2775: rcs_growbuf(RCSFILE *rf)
2776: {
2777: void *tmp;
2778: struct rcs_pdata *pdp = (struct rcs_pdata *)rf->rf_pdata;
2779:
2780: tmp = realloc(pdp->rp_buf, pdp->rp_blen + RCS_BUFEXTSIZE);
2781: if (tmp == NULL) {
1.50 jfb 2782: rcs_errno = RCS_ERR_ERRNO;
1.18 jfb 2783: cvs_log(LP_ERRNO, "failed to grow RCS parse buffer");
2784: return (-1);
2785: }
2786:
2787: pdp->rp_buf = (char *)tmp;
2788: pdp->rp_blen += RCS_BUFEXTSIZE;
2789: pdp->rp_bufend = pdp->rp_buf + pdp->rp_blen - 1;
1.42 jfb 2790:
2791: return (0);
2792: }
2793:
2794: /*
2795: * rcs_strprint()
2796: *
2797: * Output an RCS string <str> of size <slen> to the stream <stream>. Any
2798: * '@' characters are escaped. Otherwise, the string can contain arbitrary
2799: * binary data.
2800: */
2801: static int
2802: rcs_strprint(const u_char *str, size_t slen, FILE *stream)
2803: {
2804: const u_char *ap, *ep, *sp;
2805: size_t ret;
1.52 jfb 2806:
2807: if (slen == 0)
2808: return (0);
1.42 jfb 2809:
2810: ep = str + slen - 1;
2811:
2812: for (sp = str; sp <= ep;) {
2813: ap = memchr(sp, '@', ep - sp);
2814: if (ap == NULL)
2815: ap = ep;
2816: ret = fwrite(sp, sizeof(u_char), ap - sp + 1, stream);
2817:
2818: if (*ap == '@')
2819: putc('@', stream);
2820: sp = ap + 1;
1.63 joris 2821: }
2822:
2823: return (0);
2824: }
2825:
2826: /*
2827: * rcs_expand_keywords()
2828: *
2829: * Expand any RCS keywords in <line> into <out>
2830: */
2831: static int
2832: rcs_expand_keywords(char *rcsfile, struct rcs_delta *rdp, char *line, char *out,
2833: size_t len, int mode)
2834: {
2835: int kwtype;
2836: u_int i, j, found;
2837: char *c, *kwstr, *start;
2838: char expbuf[128], buf[128];
2839:
1.65 niallo 2840: kwtype = 0;
2841: kwstr = NULL;
1.63 joris 2842: i = 0;
2843:
2844: /*
2845: * Keyword formats:
2846: * $Keyword$
2847: * $Keyword: value$
2848: */
2849: memset(out, '\0', len);
2850: for (c = line; *c != '\0' && i < len; *c++) {
2851: out[i++] = *c;
2852: if (*c == '$') {
2853: /* remember start of this possible keyword */
2854: start = c;
2855:
2856: /* first following character has to be alphanumeric */
2857: *c++;
2858: if (!isalpha(*c)) {
2859: c = start;
2860: continue;
2861: }
2862:
2863: /* look for any matching keywords */
2864: found = 0;
2865: for (j = 0; j < RCS_NKWORDS; j++) {
2866: if (!strncmp(c, rcs_expkw[j].kw_str,
2867: strlen(rcs_expkw[j].kw_str))) {
2868: found = 1;
2869: kwstr = rcs_expkw[j].kw_str;
2870: kwtype = rcs_expkw[j].kw_type;
2871: break;
2872: }
2873: }
2874:
2875: /* unknown keyword, continue looking */
2876: if (found == 0) {
2877: c = start;
2878: continue;
2879: }
2880:
2881: /* next character has to be ':' or '$' */
2882: c += strlen(kwstr);
2883: if (*c != ':' && *c != '$') {
2884: c = start;
2885: continue;
2886: }
2887:
2888: /*
2889: * if the next character was ':' we need to look for
2890: * an '$' before the end of the line to be sure it is
2891: * in fact a keyword.
2892: */
2893: if (*c == ':') {
2894: while (*c++) {
2895: if (*c == '$' || *c == '\n')
2896: break;
2897: }
2898:
2899: if (*c != '$') {
2900: c = start;
2901: continue;
2902: }
2903: }
2904:
2905: /* start constructing the expansion */
2906: expbuf[0] = '\0';
2907:
2908: if (mode & RCS_KWEXP_NAME) {
2909: strlcat(expbuf, "$", sizeof(expbuf));
2910: strlcat(expbuf, kwstr, sizeof(expbuf));
2911: if (mode & RCS_KWEXP_VAL)
2912: strlcat(expbuf, ": ", sizeof(expbuf));
2913: }
2914:
2915: /*
1.80 reyk 2916: * order matters because of RCS_KW_ID and
2917: * RCS_KW_HEADER here
1.63 joris 2918: */
2919: if (mode & RCS_KWEXP_VAL) {
2920: if (kwtype & RCS_KW_RCSFILE) {
2921: if (!(kwtype & RCS_KW_FULLPATH))
1.80 reyk 2922: strlcat(expbuf,
2923: basename(rcsfile),
1.63 joris 2924: sizeof(expbuf));
2925: else
2926: strlcat(expbuf, rcsfile,
2927: sizeof(expbuf));
2928: strlcat(expbuf, " ", sizeof(expbuf));
2929: }
2930:
2931: if (kwtype & RCS_KW_REVISION) {
1.80 reyk 2932: rcsnum_tostr(rdp->rd_num, buf,
2933: sizeof(buf));
1.63 joris 2934: strlcat(buf, " ", sizeof(buf));
2935: strlcat(expbuf, buf, sizeof(expbuf));
2936: }
2937:
2938: if (kwtype & RCS_KW_DATE) {
2939: strftime(buf, sizeof(buf),
1.80 reyk 2940: "%Y/%m/%d %H:%M:%S ",
2941: &rdp->rd_date);
1.63 joris 2942: strlcat(expbuf, buf, sizeof(expbuf));
2943: }
2944:
2945: if (kwtype & RCS_KW_AUTHOR) {
2946: strlcat(expbuf, rdp->rd_author,
2947: sizeof(expbuf));
2948: strlcat(expbuf, " ", sizeof(expbuf));
2949: }
2950:
2951: if (kwtype & RCS_KW_STATE) {
2952: strlcat(expbuf, rdp->rd_state,
2953: sizeof(expbuf));
2954: strlcat(expbuf, " ", sizeof(expbuf));
2955: }
2956:
2957: /* order does not matter anymore below */
2958: if (kwtype & RCS_KW_LOG)
2959: strlcat(expbuf, " ", sizeof(expbuf));
2960:
2961: if (kwtype & RCS_KW_SOURCE) {
1.80 reyk 2962: strlcat(expbuf, rcsfile,
2963: sizeof(expbuf));
1.63 joris 2964: strlcat(expbuf, " ", sizeof(expbuf));
2965: }
2966:
2967: if (kwtype & RCS_KW_NAME)
2968: strlcat(expbuf, " ", sizeof(expbuf));
2969: }
2970:
2971: /* end the expansion */
2972: if (mode & RCS_KWEXP_NAME)
2973: strlcat(expbuf, "$", sizeof(expbuf));
2974:
2975: out[--i] = '\0';
2976: strlcat(out, expbuf, len);
2977: i += strlen(expbuf);
2978: }
1.42 jfb 2979: }
1.81 niallo 2980:
2981: return (0);
2982: }
2983:
2984: /*
2985: * rcs_deltatext_set()
2986: *
2987: * Set deltatext for <rev> in RCS file <rfp> to <dtext>
2988: * Returns -1 on error, 0 on success.
2989: */
2990: int
2991: rcs_deltatext_set(RCSFILE *rfp, RCSNUM *rev, const char *dtext)
2992: {
2993: size_t len;
2994: struct rcs_delta *rdp;
2995:
2996: if ((rdp = rcs_findrev(rfp, rev)) == NULL)
2997: return (-1);
2998:
2999: if (rdp->rd_text != NULL)
3000: free(rdp->rd_text);
3001:
3002: len = strlen(dtext);
3003: if ((rdp->rd_text = (u_char *)malloc(len)) == NULL)
3004: return (-1);
3005:
3006: rdp->rd_tlen = len - 1;
3007: strlcpy(rdp->rd_text, dtext, len);
1.18 jfb 3008:
1.86 joris 3009: return (0);
3010: }
3011:
3012: /*
3013: * rcs_rev_setlog()
3014: *
3015: * Sets the log message of revision <rev> to <logtext>
3016: */
3017: int
3018: rcs_rev_setlog(RCSFILE *rfp, RCSNUM *rev, const char *logtext)
3019: {
3020: struct rcs_delta *rdp;
3021: char buf[16];
3022:
3023: rcsnum_tostr(rev, buf, sizeof(buf));
3024: printf("setting log for %s to '%s'\n", buf, logtext);
3025:
3026: if ((rdp = rcs_findrev(rfp, rev)) == NULL)
3027: return (-1);
3028:
3029: if (rdp->rd_log != NULL)
3030: cvs_strfree(rdp->rd_log);
3031:
3032: if ((rdp->rd_log = cvs_strdup(logtext)) == NULL)
3033: return (-1);
3034:
3035: rfp->rf_flags &= ~RCS_SYNCED;
1.18 jfb 3036: return (0);
1.1 jfb 3037: }