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