Annotation of src/usr.bin/rcs/ci.c, Revision 1.116
1.116 ! ray 1: /* $OpenBSD: ci.c,v 1.115 2006/03/11 22:44:11 niallo Exp $ */
1.1 niallo 2: /*
1.98 niallo 3: * Copyright (c) 2005, 2006 Niall O'Higgins <niallo@openbsd.org>
1.1 niallo 4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following cinditions
8: * are met:
9: *
10: * 1. Redistributions of source cide must retain the above cipyright
11: * notice, this list of cinditions and the following disclaimer.
12: * 2. The name of the author may not be used to endorse or promote products
13: * derived from this software without specific prior written permission.
14: *
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
1.91 xsa 27: #include "includes.h"
1.1 niallo 28:
1.92 xsa 29: #include "rcsprog.h"
1.4 niallo 30: #include "diff.h"
1.9 niallo 31:
1.110 joris 32: #define CI_OPTSTRING "d::f::i::j::k::l::m:M::N:n:qr::s:Tt:u::Vw:x:z:"
1.107 deraadt 33: #define DATE_NOW -1
34: #define DATE_MTIME -2
35:
36: #define KW_ID "Id"
37: #define KW_AUTHOR "Author"
38: #define KW_DATE "Date"
39: #define KW_STATE "State"
40: #define KW_REVISION "Revision"
41:
42: #define KW_TYPE_ID 1
43: #define KW_TYPE_AUTHOR 2
44: #define KW_TYPE_DATE 3
45: #define KW_TYPE_STATE 4
46: #define KW_TYPE_REVISION 5
47:
48: #define KW_NUMTOKS_ID 10
49: #define KW_NUMTOKS_AUTHOR 3
50: #define KW_NUMTOKS_DATE 4
51: #define KW_NUMTOKS_STATE 3
52: #define KW_NUMTOKS_REVISION 3
1.58 niallo 53:
1.115 niallo 54: #define RCSNUM_ZERO_ENDING(x) (x->rn_id[x->rn_len - 1] == 0)
55:
1.98 niallo 56: extern struct rcs_kw rcs_expkw[];
57:
1.58 niallo 58: struct checkin_params {
59: int flags, openflags;
60: mode_t fmode;
61: time_t date;
62: RCSFILE *file;
63: RCSNUM *frev, *newrev;
64: char fpath[MAXPATHLEN], *rcs_msg, *username, *deltatext, *filename;
1.98 niallo 65: char *author, *state;
66: const char *symbol, *description;
1.58 niallo 67: };
68:
1.94 niallo 69: static int checkin_attach_symbol(struct checkin_params *);
70: static int checkin_checklock(struct checkin_params *);
1.68 xsa 71: static char *checkin_choose_rcsfile(const char *);
72: static char *checkin_diff_file(struct checkin_params *);
73: static char *checkin_getdesc(void);
74: static char *checkin_getinput(const char *);
75: static char *checkin_getlogmsg(RCSNUM *, RCSNUM *);
76: static int checkin_init(struct checkin_params *);
1.107 deraadt 77: static int checkin_keywordscan(char *, RCSNUM **, time_t *, char **,
1.98 niallo 78: char **);
1.107 deraadt 79: static int checkin_keywordtype(char *);
1.94 niallo 80: static int checkin_mtimedate(struct checkin_params *);
1.107 deraadt 81: static void checkin_parsekeyword(char *, RCSNUM **, time_t *, char **,
1.98 niallo 82: char **);
1.94 niallo 83: static int checkin_update(struct checkin_params *);
84: static void checkin_revert(struct checkin_params *);
1.4 niallo 85:
1.1 niallo 86: void
87: checkin_usage(void)
88: {
89: fprintf(stderr,
1.108 jmc 90: "usage: ci [-jMNqV] [-d[date]] [-f[rev]] [-i[rev]] [-j[rev]]\n"
1.107 deraadt 91: " [-k[rev]] [-l[rev]] [-M[rev]] [-mmsg] [-Nsymbol]\n"
92: " [-nsymbol] [-r[rev]] [-sstate] [-tfile|str] [-u[rev]]\n"
1.111 joris 93: " [-wusername] [-xsuffixes] [-ztz] file ...\n");
1.58 niallo 94: }
95:
1.55 niallo 96:
1.1 niallo 97:
98: /*
99: * checkin_main()
100: *
101: * Handler for the `ci' program.
102: * Returns 0 on success, or >0 on error.
103: */
104: int
105: checkin_main(int argc, char **argv)
106: {
1.58 niallo 107: int i, ch, status;
108: struct checkin_params pb;
1.1 niallo 109:
1.58 niallo 110: pb.date = DATE_NOW;
111: pb.file = NULL;
1.98 niallo 112: pb.rcs_msg = pb.username = pb.author = pb.state = NULL;
113: pb.symbol = pb.description = NULL;
1.58 niallo 114: pb.newrev = NULL;
115: pb.fmode = pb.flags = status = 0;
1.1 niallo 116:
1.58 niallo 117: pb.flags = INTERACTIVE;
1.90 niallo 118: pb.openflags = RCS_RDWR|RCS_CREATE|RCS_PARSE_FULLY;
1.9 niallo 119:
1.58 niallo 120: while ((ch = rcs_getopt(argc, argv, CI_OPTSTRING)) != -1) {
1.1 niallo 121: switch (ch) {
1.20 niallo 122: case 'd':
1.25 niallo 123: if (rcs_optarg == NULL)
1.58 niallo 124: pb.date = DATE_MTIME;
1.87 xsa 125: else if ((pb.date = cvs_date_parse(rcs_optarg)) <= 0)
126: fatal("invalid date");
1.20 niallo 127: break;
1.29 niallo 128: case 'f':
1.58 niallo 129: rcs_set_rev(rcs_optarg, &pb.newrev);
130: pb.flags |= FORCE;
1.29 niallo 131: break;
1.1 niallo 132: case 'h':
133: (usage)();
134: exit(0);
1.58 niallo 135: case 'i':
136: rcs_set_rev(rcs_optarg, &pb.newrev);
137: pb.openflags |= RCS_CREATE;
1.66 niallo 138: pb.flags |= CI_INIT;
1.58 niallo 139: break;
140: case 'j':
141: rcs_set_rev(rcs_optarg, &pb.newrev);
142: pb.openflags &= ~RCS_CREATE;
1.66 niallo 143: pb.flags &= ~CI_INIT;
1.58 niallo 144: break;
1.98 niallo 145: case 'k':
146: rcs_set_rev(rcs_optarg, &pb.newrev);
147: pb.flags |= CI_KEYWORDSCAN;
148: break;
1.30 niallo 149: case 'l':
1.58 niallo 150: rcs_set_rev(rcs_optarg, &pb.newrev);
151: pb.flags |= CO_LOCK;
1.54 niallo 152: break;
153: case 'M':
1.58 niallo 154: rcs_set_rev(rcs_optarg, &pb.newrev);
155: pb.flags |= CO_REVDATE;
1.30 niallo 156: break;
1.1 niallo 157: case 'm':
1.58 niallo 158: pb.rcs_msg = rcs_optarg;
1.87 xsa 159: if (pb.rcs_msg == NULL)
160: fatal("missing message for -m option");
1.58 niallo 161: pb.flags &= ~INTERACTIVE;
1.3 joris 162: break;
1.42 niallo 163: case 'N':
1.84 joris 164: pb.symbol = xstrdup(rcs_optarg);
1.87 xsa 165: if (rcs_sym_check(pb.symbol) != 1)
166: fatal("invalid symbol `%s'", pb.symbol);
1.58 niallo 167: pb.flags |= CI_SYMFORCE;
1.42 niallo 168: break;
1.38 niallo 169: case 'n':
1.84 joris 170: pb.symbol = xstrdup(rcs_optarg);
1.87 xsa 171: if (rcs_sym_check(pb.symbol) != 1)
172: fatal("invalid symbol `%s'", pb.symbol);
1.38 niallo 173: break;
1.3 joris 174: case 'q':
175: verbose = 0;
1.1 niallo 176: break;
1.30 niallo 177: case 'r':
1.58 niallo 178: rcs_set_rev(rcs_optarg, &pb.newrev);
179: pb.flags |= CI_DEFAULT;
1.9 niallo 180: break;
1.51 niallo 181: case 's':
1.58 niallo 182: pb.state = rcs_optarg;
1.87 xsa 183: if (rcs_state_check(pb.state) < 0)
184: fatal("invalid state `%s'", pb.state);
1.67 xsa 185: break;
186: case 'T':
187: pb.flags |= PRESERVETIME;
1.51 niallo 188: break;
1.80 niallo 189: case 't':
1.84 joris 190: pb.description = xstrdup(rcs_optarg);
1.80 niallo 191: break;
1.9 niallo 192: case 'u':
1.58 niallo 193: rcs_set_rev(rcs_optarg, &pb.newrev);
194: pb.flags |= CO_UNLOCK;
1.9 niallo 195: break;
1.30 niallo 196: case 'V':
197: printf("%s\n", rcs_version);
198: exit(0);
1.31 niallo 199: case 'w':
1.84 joris 200: pb.author = xstrdup(rcs_optarg);
1.64 xsa 201: break;
202: case 'x':
203: rcs_suffixes = rcs_optarg;
1.110 joris 204: break;
205: case 'z':
206: timezone_flag = rcs_optarg;
1.31 niallo 207: break;
1.1 niallo 208: default:
209: (usage)();
210: exit(1);
211: }
212: }
213:
1.24 joris 214: argc -= rcs_optind;
215: argv += rcs_optind;
216:
1.1 niallo 217: if (argc == 0) {
218: cvs_log(LP_ERR, "no input file");
219: (usage)();
220: exit(1);
221: }
222:
1.86 xsa 223: if ((pb.username = getlogin()) == NULL)
224: fatal("getlogin failed");
1.31 niallo 225:
226:
1.1 niallo 227: for (i = 0; i < argc; i++) {
1.58 niallo 228: pb.filename = argv[i];
1.1 niallo 229:
1.58 niallo 230: /*
231: * Test for existence of ,v file. If we are expected to
232: * create one, set NEWFILE flag.
233: */
1.71 niallo 234: if (rcs_statfile(pb.filename, pb.fpath, sizeof(pb.fpath)) < 0) {
235: if (pb.openflags & RCS_CREATE)
236: pb.flags |= NEWFILE;
237: else {
238: cvs_log(LP_ERR, "No existing RCS file");
239: status = 1;
240: continue;
241: }
1.66 niallo 242: } else {
243: if (pb.flags & CI_INIT) {
244: cvs_log(LP_ERR, "%s already exists", pb.fpath);
245: status = 1;
246: continue;
247: }
1.58 niallo 248: pb.openflags &= ~RCS_CREATE;
1.66 niallo 249: }
1.63 niallo 250: /*
251: * If we are to create a new ,v file, we must decide where it
252: * should go.
253: */
254: if (pb.flags & NEWFILE) {
255: char *fpath = checkin_choose_rcsfile(pb.filename);
256: if (fpath == NULL) {
257: status = 1;
258: continue;
259: }
260: strlcpy(pb.fpath, fpath, sizeof(pb.fpath));
1.84 joris 261: xfree(fpath);
1.63 niallo 262: }
263:
1.58 niallo 264: pb.file = rcs_open(pb.fpath, pb.openflags, pb.fmode);
265:
1.87 xsa 266: if (pb.file == NULL)
267: fatal("failed to open rcsfile '%s'", pb.fpath);
1.29 niallo 268:
1.58 niallo 269: if (verbose == 1)
270: printf("%s <-- %s\n", pb.fpath, pb.filename);
1.107 deraadt 271:
1.63 niallo 272: if (pb.flags & NEWFILE)
273: status = checkin_init(&pb);
1.15 niallo 274: else
1.63 niallo 275: status = checkin_update(&pb);
1.114 niallo 276:
277: /* reset NEWFILE flag */
278: pb.flags &= ~NEWFILE;
1.4 niallo 279: }
280:
1.114 niallo 281: if ((verbose == 1) && (status == 0))
1.93 xsa 282: printf("done\n");
283:
1.16 niallo 284: return (status);
1.4 niallo 285: }
286:
1.59 niallo 287: /*
288: * checkin_diff_file()
289: *
1.65 xsa 290: * Generate the diff between the working file and a revision.
1.59 niallo 291: * Returns pointer to a char array on success, NULL on failure.
292: */
1.4 niallo 293: static char *
1.58 niallo 294: checkin_diff_file(struct checkin_params *pb)
1.4 niallo 295: {
296: char path1[MAXPATHLEN], path2[MAXPATHLEN];
297: BUF *b1, *b2, *b3;
298: char rbuf[64], *deltatext;
299:
1.112 joris 300: b1 = b2 = b3 = NULL;
301: deltatext = NULL;
1.58 niallo 302: rcsnum_tostr(pb->frev, rbuf, sizeof(rbuf));
1.4 niallo 303:
1.58 niallo 304: if ((b1 = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) {
305: cvs_log(LP_ERR, "failed to load file: '%s'", pb->filename);
1.112 joris 306: goto out;
1.1 niallo 307: }
308:
1.58 niallo 309: if ((b2 = rcs_getrev(pb->file, pb->frev)) == NULL) {
1.4 niallo 310: cvs_log(LP_ERR, "failed to load revision");
1.112 joris 311: goto out;
1.4 niallo 312: }
313:
1.57 xsa 314: if ((b3 = cvs_buf_alloc((size_t)128, BUF_AUTOEXT)) == NULL) {
1.4 niallo 315: cvs_log(LP_ERR, "failed to allocated buffer for diff");
1.112 joris 316: goto out;
1.4 niallo 317: }
318:
1.50 xsa 319: strlcpy(path1, rcs_tmpdir, sizeof(path1));
320: strlcat(path1, "/diff1.XXXXXXXXXX", sizeof(path1));
1.112 joris 321: if (cvs_buf_write_stmp(b1, path1, 0600) == -1)
322: goto out;
323:
324: cvs_worklist_add(path1, &rcs_temp_files);
1.4 niallo 325: cvs_buf_free(b1);
1.112 joris 326: b1 = NULL;
1.4 niallo 327:
1.50 xsa 328: strlcpy(path2, rcs_tmpdir, sizeof(path2));
329: strlcat(path2, "/diff2.XXXXXXXXXX", sizeof(path2));
1.112 joris 330: if (cvs_buf_write_stmp(b2, path2, 0600) == -1)
331: goto out;
332:
333: cvs_worklist_add(path2, &rcs_temp_files);
1.4 niallo 334: cvs_buf_free(b2);
1.112 joris 335: b2 = NULL;
1.4 niallo 336:
1.5 niallo 337: diff_format = D_RCSDIFF;
1.4 niallo 338: cvs_diffreg(path1, path2, b3);
339:
340: cvs_buf_putc(b3, '\0');
341: deltatext = (char *)cvs_buf_release(b3);
1.112 joris 342: b3 = NULL;
343:
344: out:
345: cvs_worklist_run(&rcs_temp_files, cvs_worklist_unlink);
346:
347: if (b1 != NULL)
348: cvs_buf_free(b1);
349: if (b2 != NULL)
350: cvs_buf_free(b2);
351: if (b3 != NULL)
352: cvs_buf_free(b3);
1.4 niallo 353:
354: return (deltatext);
1.6 niallo 355: }
356:
357: /*
1.65 xsa 358: * checkin_getlogmsg()
1.59 niallo 359: *
1.6 niallo 360: * Get log message from user interactively.
1.59 niallo 361: * Returns pointer to a char array on success, NULL on failure.
1.6 niallo 362: */
363: static char *
1.34 niallo 364: checkin_getlogmsg(RCSNUM *rev, RCSNUM *rev2)
1.6 niallo 365: {
1.58 niallo 366: char *rcs_msg, nrev[16], prev[16];
1.6 niallo 367: RCSNUM *tmprev;
368:
1.7 niallo 369: rcs_msg = NULL;
1.6 niallo 370: tmprev = rcsnum_alloc();
371: rcsnum_cpy(rev, tmprev, 16);
1.9 niallo 372: rcsnum_tostr(tmprev, prev, sizeof(prev));
1.12 niallo 373: if (rev2 == NULL)
374: rcsnum_tostr(rcsnum_inc(tmprev), nrev, sizeof(nrev));
375: else
376: rcsnum_tostr(rev2, nrev, sizeof(nrev));
1.6 niallo 377: rcsnum_free(tmprev);
378:
1.47 niallo 379: if (verbose == 1)
380: printf("new revision: %s; previous revision: %s\n", nrev,
381: prev);
1.32 joris 382:
1.107 deraadt 383: rcs_msg = checkin_getinput("enter log message, terminated with a "
384: "single '.' or end of file:\n>> ");
1.58 niallo 385: return (rcs_msg);
386: }
387:
388:
389: /*
390: * checkin_getdesc()
391: *
392: * Get file description interactively.
1.59 niallo 393: * Returns pointer to a char array on success, NULL on failure.
1.58 niallo 394: */
395: static char *
396: checkin_getdesc()
397: {
398: char *description;
399:
1.107 deraadt 400: description = checkin_getinput("enter description, terminated with "
401: "single '.' or end of file:\n"
402: "NOTE: This is NOT the log message!\n>> ");
1.58 niallo 403: return (description);
404: }
405:
406: /*
407: * checkin_getinput()
408: *
1.59 niallo 409: * Get some input from the user, in RCS style, prompting with message <prompt>.
410: * Returns pointer to a char array on success, NULL on failure.
1.58 niallo 411: */
412: static char *
413: checkin_getinput(const char *prompt)
414: {
415: BUF *inputbuf;
416: char *input, buf[128];
417:
418: if ((inputbuf = cvs_buf_alloc((size_t)64, BUF_AUTOEXT)) == NULL) {
419: cvs_log(LP_ERR, "failed to allocate input buffer");
420: return (NULL);
421: }
422:
423: printf(prompt);
1.6 niallo 424: for (;;) {
425: fgets(buf, (int)sizeof(buf), stdin);
1.9 niallo 426: if (feof(stdin) || ferror(stdin) || buf[0] == '.')
1.6 niallo 427: break;
1.58 niallo 428: cvs_buf_append(inputbuf, buf, strlen(buf));
1.46 joris 429: printf(">> ");
1.6 niallo 430: }
1.32 joris 431:
1.58 niallo 432: cvs_buf_putc(inputbuf, '\0');
433: input = (char *)cvs_buf_release(inputbuf);
434:
435: return (input);
436: }
437:
438: /*
1.63 niallo 439: * checkin_update()
440: *
441: * Do a checkin to an existing RCS file.
442: *
443: * On success, return 0. On error return -1.
444: */
445: static int
446: checkin_update(struct checkin_params *pb)
447: {
1.77 xsa 448: char *filec, numb1[64], numb2[64];
1.63 niallo 449: BUF *bp;
450:
1.82 joris 451: /*
452: * XXX this is wrong, we need to get the revision the user
1.85 xsa 453: * has the lock for. So we can decide if we want to create a
1.82 joris 454: * branch or not. (if it's not current HEAD we need to branch).
455: */
1.63 niallo 456: pb->frev = pb->file->rf_head;
457:
1.115 niallo 458: /* If this is a zero-ending RCSNUM eg 4.0, increment it (eg to 4.1) */
459: if ((pb->newrev != NULL) && (RCSNUM_ZERO_ENDING(pb->newrev)))
460: pb->newrev = rcsnum_inc(pb->newrev);
461:
1.82 joris 462: if (checkin_checklock(pb) < 0)
463: return (-1);
464:
465: /* If revision passed on command line is less than HEAD, bail.
466: * XXX only applies to ci -r1.2 foo for example if HEAD is > 1.2 and
467: * there is no lock set for the user.
468: */
1.63 niallo 469: if ((pb->newrev != NULL)
470: && (rcsnum_cmp(pb->newrev, pb->frev, 0) > 0)) {
1.77 xsa 471: cvs_log(LP_ERR,
472: "%s: revision %s too low; must be higher than %s",
473: pb->file->rf_path,
474: rcsnum_tostr(pb->newrev, numb1, sizeof(numb1)),
475: rcsnum_tostr(pb->frev, numb2, sizeof(numb2)));
1.63 niallo 476: rcs_close(pb->file);
477: return (-1);
478: }
479:
1.104 niallo 480: /*
481: * Set the date of the revision to be the last modification
482: * time of the working file if -d has no argument.
483: */
484: if (pb->date == DATE_MTIME
485: && (checkin_mtimedate(pb) < 0))
486: return (-1);
487:
488: /* Date from argv/mtime must be more recent than HEAD */
489: if (pb->date != DATE_NOW) {
490: time_t head_date = rcs_rev_getdate(pb->file, pb->frev);
491: if (pb->date <= head_date) {
1.113 xsa 492: char dbuf1[256], dbuf2[256], *fmt;
493: struct tm *t, *t_head;
494:
495: fmt = "%Y/%m/%d %H:%M:%S";
496:
497: t = localtime(&pb->date);
498: strftime(dbuf1, sizeof(dbuf1), fmt, t);
499: t_head = localtime(&head_date);
500: strftime(dbuf2, sizeof(dbuf2), fmt, t_head);
501:
502: fatal("%s: Date %s preceeds %s in revision %s.",
503: pb->file->rf_path, dbuf1, dbuf2,
1.104 niallo 504: rcsnum_tostr(pb->frev, numb2, sizeof(numb2)));
505: }
506: }
507:
1.73 xsa 508: /* Load file contents */
1.63 niallo 509: if ((bp = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) {
1.106 niallo 510: rcs_close(pb->file);
1.63 niallo 511: return (-1);
512: }
513:
1.106 niallo 514: if (cvs_buf_putc(bp, '\0') < 0) {
515: rcs_close(pb->file);
1.63 niallo 516: return (-1);
1.106 niallo 517: }
1.63 niallo 518:
519: filec = (char *)cvs_buf_release(bp);
520:
1.73 xsa 521: /* Get RCS patch */
1.63 niallo 522: if ((pb->deltatext = checkin_diff_file(pb)) == NULL) {
523: cvs_log(LP_ERR, "failed to get diff");
1.106 niallo 524: rcs_close(pb->file);
1.63 niallo 525: return (-1);
526: }
527:
528: /*
529: * If -f is not specified and there are no differences, tell
530: * the user and revert to latest version.
531: */
532: if (!(pb->flags & FORCE) && (strlen(pb->deltatext) < 1)) {
533: checkin_revert(pb);
534: return (0);
535: }
536:
1.73 xsa 537: /* If no log message specified, get it interactively. */
1.63 niallo 538: if (pb->flags & INTERACTIVE)
539: pb->rcs_msg = checkin_getlogmsg(pb->frev, pb->newrev);
540:
1.82 joris 541: if (rcs_lock_remove(pb->file, pb->username, pb->frev) < 0) {
1.63 niallo 542: if (rcs_errno != RCS_ERR_NOENT)
1.82 joris 543: cvs_log(LP_WARN, "failed to remove lock");
544: else if (!(pb->flags & CO_LOCK))
545: cvs_log(LP_WARN, "previous revision was not locked; "
546: "ignoring -l option");
1.63 niallo 547: }
548:
1.73 xsa 549: /* Current head revision gets the RCS patch as rd_text */
1.87 xsa 550: if (rcs_deltatext_set(pb->file, pb->frev, pb->deltatext) == -1)
551: fatal("failed to set new rd_text for head rev");
1.63 niallo 552:
1.73 xsa 553: /* Now add our new revision */
1.63 niallo 554: if (rcs_rev_add(pb->file,
555: (pb->newrev == NULL ? RCS_HEAD_REV : pb->newrev),
1.82 joris 556: pb->rcs_msg, pb->date, pb->author) != 0) {
1.63 niallo 557: cvs_log(LP_ERR, "failed to add new revision");
1.106 niallo 558: rcs_close(pb->file);
1.63 niallo 559: return (-1);
560: }
561:
562: /*
563: * If we are checking in to a non-default (ie user-specified)
564: * revision, set head to this revision.
565: */
566: if (pb->newrev != NULL)
567: rcs_head_set(pb->file, pb->newrev);
568: else
569: pb->newrev = pb->file->rf_head;
570:
1.73 xsa 571: /* New head revision has to contain entire file; */
1.107 deraadt 572: if (rcs_deltatext_set(pb->file, pb->frev, filec) == -1)
1.87 xsa 573: fatal("failed to set new head revision");
1.63 niallo 574:
1.73 xsa 575: /* Attach a symbolic name to this revision if specified. */
1.63 niallo 576: if (pb->symbol != NULL
577: && (checkin_attach_symbol(pb) < 0))
578: return (-1);
579:
1.73 xsa 580: /* Set the state of this revision if specified. */
1.63 niallo 581: if (pb->state != NULL)
582: (void)rcs_state_set(pb->file, pb->newrev, pb->state);
583:
1.84 joris 584: xfree(pb->deltatext);
585: xfree(filec);
1.63 niallo 586: (void)unlink(pb->filename);
587:
1.73 xsa 588: /* Do checkout if -u or -l are specified. */
1.63 niallo 589: if (((pb->flags & CO_LOCK) || (pb->flags & CO_UNLOCK))
590: && !(pb->flags & CI_DEFAULT))
591: checkout_rev(pb->file, pb->newrev, pb->filename, pb->flags,
1.89 joris 592: pb->username, pb->author, NULL, NULL);
1.63 niallo 593:
594: /* File will NOW be synced */
595: rcs_close(pb->file);
596:
597: if (pb->flags & INTERACTIVE) {
1.84 joris 598: xfree(pb->rcs_msg);
1.63 niallo 599: pb->rcs_msg = NULL;
600: }
601: return (0);
602: }
603:
604: /*
1.58 niallo 605: * checkin_init()
1.65 xsa 606: *
1.58 niallo 607: * Does an initial check in, just enough to create the new ,v file
1.63 niallo 608: * On success, return 0. On error return -1.
1.58 niallo 609: */
1.63 niallo 610: static int
1.58 niallo 611: checkin_init(struct checkin_params *pb)
612: {
1.80 niallo 613: BUF *bp, *dp;
1.93 xsa 614: char *filec, numb[64];
1.115 niallo 615: int fetchlog = 0;
1.80 niallo 616: const char *rcs_desc;
1.58 niallo 617:
1.115 niallo 618: /* If this is a zero-ending RCSNUM eg 4.0, increment it (eg to 4.1) */
619: if ((pb->newrev != NULL) && (RCSNUM_ZERO_ENDING(pb->newrev))) {
620: pb->frev = rcsnum_alloc();
621: rcsnum_cpy(pb->newrev, pb->frev, 0);
622: pb->newrev = rcsnum_inc(pb->newrev);
623: fetchlog = 1;
624: }
625:
1.73 xsa 626: /* Load file contents */
1.58 niallo 627: if ((bp = cvs_buf_load(pb->filename, BUF_AUTOEXT)) == NULL) {
1.106 niallo 628: rcs_close(pb->file);
1.63 niallo 629: return (-1);
1.58 niallo 630: }
631:
1.106 niallo 632: if (cvs_buf_putc(bp, '\0') < 0) {
633: rcs_close(pb->file);
1.63 niallo 634: return (-1);
1.106 niallo 635: }
1.58 niallo 636:
637: filec = (char *)cvs_buf_release(bp);
638:
1.98 niallo 639: /* Get default values from working copy if -k specified */
640: if (pb->flags & CI_KEYWORDSCAN)
641: checkin_keywordscan(filec, &pb->newrev, &pb->date, &pb->state,
642: &pb->author);
643:
1.73 xsa 644: /* Get description from user */
1.80 niallo 645: if (pb->description == NULL)
646: rcs_desc = (const char *)checkin_getdesc();
647: else {
648: if (*pb->description == '-') {
649: pb->description++;
1.81 niallo 650: rcs_desc = (const char *)pb->description;
651: } else {
1.80 niallo 652: dp = cvs_buf_load(pb->description, BUF_AUTOEXT);
653: if (dp == NULL) {
654: cvs_log(LP_ERR,
655: "failed to load description file '%s'",
656: pb->description);
1.84 joris 657: xfree(filec);
1.106 niallo 658: rcs_close(pb->file);
1.80 niallo 659: return (-1);
660: }
661: if (cvs_buf_putc(dp, '\0') < 0) {
1.84 joris 662: xfree(filec);
1.106 niallo 663: rcs_close(pb->file);
1.80 niallo 664: return (-1);
665: }
666: rcs_desc = (const char *)cvs_buf_release(dp);
667: }
668: }
1.58 niallo 669: rcs_desc_set(pb->file, rcs_desc);
670:
1.115 niallo 671: /*
672: * If the user had specified a zero-ending revision number e.g. 4
673: * emulate odd GNU behaviour and fetch log message.
674: */
675: if (fetchlog == 1) {
676: pb->rcs_msg = checkin_getlogmsg(pb->frev, pb->newrev);
677: rcsnum_free(pb->frev);
678: }
1.97 niallo 679: /*
680: * Set the date of the revision to be the last modification
681: * time of the working file if -d has no argument.
682: */
683: if (pb->date == DATE_MTIME
684: && (checkin_mtimedate(pb) < 0))
685: return (-1);
686:
1.73 xsa 687: /* Now add our new revision */
1.96 niallo 688: if (rcs_rev_add(pb->file,
689: (pb->newrev == NULL ? RCS_HEAD_REV : pb->newrev),
1.107 deraadt 690: (pb->rcs_msg == NULL ? "Initial revision" : pb->rcs_msg),
1.103 niallo 691: pb->date, pb->author) != 0) {
1.58 niallo 692: cvs_log(LP_ERR, "failed to add new revision");
1.106 niallo 693: rcs_close(pb->file);
1.63 niallo 694: return (-1);
695: }
696: /*
697: * If we are checking in to a non-default (ie user-specified)
698: * revision, set head to this revision.
699: */
700: if (pb->newrev != NULL)
701: rcs_head_set(pb->file, pb->newrev);
702: else
703: pb->newrev = pb->file->rf_head;
704:
1.73 xsa 705: /* New head revision has to contain entire file; */
1.66 niallo 706: if (rcs_deltatext_set(pb->file, pb->file->rf_head, filec) == -1) {
1.63 niallo 707: cvs_log(LP_ERR, "failed to set new head revision");
1.106 niallo 708: rcs_close(pb->file);
1.63 niallo 709: return (-1);
1.58 niallo 710: }
1.73 xsa 711: /* Attach a symbolic name to this revision if specified. */
1.66 niallo 712: if (pb->symbol != NULL
713: && (checkin_attach_symbol(pb) < 0))
714: return (-1);
715:
1.73 xsa 716: /* Set the state of this revision if specified. */
1.66 niallo 717: if (pb->state != NULL)
718: (void)rcs_state_set(pb->file, pb->newrev, pb->state);
719:
1.84 joris 720: xfree(filec);
1.66 niallo 721: (void)unlink(pb->filename);
722:
1.73 xsa 723: /* Do checkout if -u or -l are specified. */
1.66 niallo 724: if (((pb->flags & CO_LOCK) || (pb->flags & CO_UNLOCK))
725: && !(pb->flags & CI_DEFAULT))
726: checkout_rev(pb->file, pb->newrev, pb->filename, pb->flags,
1.89 joris 727: pb->username, pb->author, NULL, NULL);
1.63 niallo 728:
1.93 xsa 729: printf("initial revision: %s\n",
730: rcsnum_tostr(pb->newrev, numb, sizeof(numb)));
731:
1.66 niallo 732: /* File will NOW be synced */
733: rcs_close(pb->file);
1.93 xsa 734:
1.63 niallo 735: return (0);
1.58 niallo 736: }
737:
1.59 niallo 738: /*
739: * checkin_attach_symbol()
740: *
741: * Attempt to attach the specified symbol to the revision.
742: * On success, return 0. On error return -1.
743: */
1.58 niallo 744: static int
745: checkin_attach_symbol(struct checkin_params *pb)
746: {
747: char rbuf[16];
748: int ret;
749: if (verbose == 1)
750: printf("symbol: %s\n", pb->symbol);
751: if (pb->flags & CI_SYMFORCE)
752: rcs_sym_remove(pb->file, pb->symbol);
753: if ((ret = rcs_sym_add(pb->file, pb->symbol, pb->newrev) == -1)
754: && (rcs_errno == RCS_ERR_DUPENT)) {
755: rcsnum_tostr(rcs_sym_getrev(pb->file, pb->symbol),
756: rbuf, sizeof(rbuf));
757: cvs_log(LP_ERR,
758: "symbolic name %s already bound to %s",
759: pb->symbol, rbuf);
760: rcs_close(pb->file);
761: return (-1);
762: } else if (ret == -1) {
763: cvs_log(LP_ERR, "problem adding symbol: %s",
764: pb->symbol);
765: rcs_close(pb->file);
766: return (-1);
767: }
768: return (0);
769: }
770:
1.59 niallo 771: /*
772: * checkin_revert()
773: *
774: * If there are no differences between the working file and the latest revision
775: * and the -f flag is not specified, simply revert to the latest version and
776: * warn the user.
777: *
778: */
1.58 niallo 779: static void
780: checkin_revert(struct checkin_params *pb)
781: {
782: char rbuf[16];
783:
784: rcsnum_tostr(pb->frev, rbuf, sizeof(rbuf));
785: cvs_log(LP_WARN,
786: "file is unchanged; reverting to previous revision %s",
787: rbuf);
788: (void)unlink(pb->filename);
789: if ((pb->flags & CO_LOCK) || (pb->flags & CO_UNLOCK))
790: checkout_rev(pb->file, pb->frev, pb->filename,
1.89 joris 791: pb->flags, pb->username, pb->author, NULL, NULL);
1.82 joris 792: rcs_lock_remove(pb->file, pb->username, pb->frev);
1.58 niallo 793: rcs_close(pb->file);
794: }
795:
1.59 niallo 796: /*
797: * checkin_checklock()
798: *
799: * Check for the existence of a lock on the file. If there are no locks, or it
800: * is not locked by the correct user, return -1. Otherwise, return 0.
801: */
1.58 niallo 802: static int
803: checkin_checklock(struct checkin_params *pb)
804: {
805: struct rcs_lock *lkp;
806:
1.82 joris 807: TAILQ_FOREACH(lkp, &(pb->file->rf_locks), rl_list) {
808: if ((!strcmp(lkp->rl_name, pb->username)) &&
809: (!rcsnum_cmp(lkp->rl_num, pb->frev, 0)))
810: return (0);
1.58 niallo 811: }
1.32 joris 812:
1.82 joris 813: cvs_log(LP_ERR,
814: "%s: no lock set by %s", pb->file->rf_path, pb->username);
815: rcs_close(pb->file);
816: return (-1);
1.61 niallo 817: }
818:
819: /*
1.62 niallo 820: * checkin_mtimedate()
1.61 niallo 821: *
822: * Set the date of the revision to be the last modification
1.62 niallo 823: * time of the working file.
1.61 niallo 824: *
825: * On success, return 0. On error return -1.
826: */
827: static int
1.62 niallo 828: checkin_mtimedate(struct checkin_params *pb)
1.61 niallo 829: {
830: struct stat sb;
831: if (stat(pb->filename, &sb) != 0) {
1.72 xsa 832: cvs_log(LP_ERRNO, "failed to stat `%s'", pb->filename);
1.61 niallo 833: rcs_close(pb->file);
834: return (-1);
835: }
836: pb->date = (time_t)sb.st_mtimespec.tv_sec;
1.58 niallo 837: return (0);
1.63 niallo 838: }
839:
840: /*
1.75 niallo 841: * checkin_choose_rcsfile()
1.63 niallo 842: *
1.116 ! ray 843: * Given a relative filename, decide where the corresponding RCS file
! 844: * should be. Tries each extension until a file is found. If no file
! 845: * was found, returns a path with the first extension.
1.63 niallo 846: *
847: * Returns pointer to a char array on success, NULL on failure.
848: */
849: static char *
850: checkin_choose_rcsfile(const char *filename)
851: {
852: struct stat sb;
1.116 ! ray 853: char *ext, name[MAXPATHLEN], *next, *ptr, rcsdir[MAXPATHLEN],
! 854: *ret, *suffixes, rcspath[MAXPATHLEN];
1.63 niallo 855:
1.116 ! ray 856: /* If -x flag was not given, use default. */
! 857: if (rcs_suffixes == NULL)
! 858: rcs_suffixes = RCS_DEFAULT_SUFFIX;
! 859:
! 860: /*
! 861: * If `filename' contains a directory, `rcspath' contains that
! 862: * directory, including a trailing slash. Otherwise `rcspath'
! 863: * contains an empty string.
! 864: */
! 865: if (strlcpy(rcspath, filename, sizeof(rcspath)) >= sizeof(rcspath))
! 866: return (NULL);
! 867: /* If `/' is found, end string after `/'. */
! 868: if ((ptr = strrchr(rcspath, '/')) != NULL)
! 869: *(++ptr) = '\0';
! 870: else
! 871: rcspath[0] = '\0';
! 872:
! 873: /* Append RCS/ to `rcspath' if it exists. */
! 874: if (strlcpy(rcsdir, rcspath, sizeof(rcsdir)) >= sizeof(rcsdir) ||
! 875: strlcat(rcsdir, RCSDIR, sizeof(rcsdir)) >= sizeof(rcsdir))
! 876: return (NULL);
! 877: if ((stat(rcsdir, &sb) == 0) && (sb.st_mode & S_IFDIR))
! 878: if (strlcpy(rcspath, rcsdir, sizeof(rcspath)) >= sizeof(rcspath) ||
! 879: strlcat(rcspath, "/", sizeof(rcspath)) >= sizeof(rcspath))
! 880: return (NULL);
! 881:
! 882: /* Name of file without path. */
! 883: if ((ptr = strrchr(filename, '/')) == NULL) {
! 884: if (strlcpy(name, filename, sizeof(name)) >= sizeof(name))
! 885: return (NULL);
! 886: } else {
! 887: /* Skip `/'. */
! 888: if (strlcpy(name, ptr + 1, sizeof(name)) >= sizeof(name))
! 889: return (NULL);
! 890: }
! 891:
! 892: /* Name of RCS file without an extension. */
! 893: if (strlcat(rcspath, name, sizeof(rcspath)) >= sizeof(rcspath))
! 894: return (NULL);
! 895:
! 896: /*
! 897: * If only the empty suffix was given, use existing rcspath.
! 898: * This ensures that there is at least one suffix for strsep().
! 899: */
! 900: if (strcmp(rcs_suffixes, "") == 0) {
! 901: if ((ret = strdup(rcspath)) == NULL);
! 902: fatal("out of memory");
! 903: return (ret);
! 904: }
! 905:
! 906: /*
! 907: * Cycle through slash-separated `rcs_suffixes', appending each
! 908: * extension to `rcspath' and testing if the file exists. If it
! 909: * does, return that string. Otherwise return path with first
! 910: * extension.
! 911: */
! 912: if ((suffixes = strdup(rcs_suffixes)) == NULL)
! 913: fatal("out of memory");
! 914: for (ret = NULL, next = suffixes; (ext = strsep(&next, "/")) != NULL;) {
! 915: char fpath[MAXPATHLEN];
! 916:
! 917: /* Construct RCS file path. */
! 918: if (strlcpy(fpath, rcspath, sizeof(fpath)) >= sizeof(fpath) ||
! 919: strlcat(fpath, ext, sizeof(fpath)) >= sizeof(fpath)) {
! 920: xfree(suffixes);
! 921: return (NULL);
1.76 niallo 922: }
1.116 ! ray 923:
! 924: /* Don't use `filename' as RCS file. */
! 925: if (strcmp(fpath, filename) == 0)
! 926: continue;
! 927:
! 928: if (stat(fpath, &sb) == 0) {
! 929: if ((ret = strdup(fpath)) == NULL)
! 930: fatal("out of memory");
! 931: break;
1.76 niallo 932: }
1.116 ! ray 933: }
! 934: xfree(suffixes);
! 935:
! 936: /*
! 937: * If `ret' is still NULL no RCS file with any extension exists
! 938: * so we use the first extension.
! 939: */
! 940: if (ret == NULL) {
1.63 niallo 941: /*
1.116 ! ray 942: * XXX - We shouldn't need to do strsep again,
! 943: * suffixes should now be NUL separated.
1.63 niallo 944: */
1.116 ! ray 945: if ((suffixes = strdup(rcs_suffixes)) == NULL)
! 946: fatal("out of memory");
! 947: next = suffixes;
! 948: /* Get first extension again. */
! 949: if ((ext = strsep(&next, "/")) == NULL) {
! 950: xfree(suffixes);
1.63 niallo 951: return (NULL);
952: }
1.116 ! ray 953: if (strlcat(rcspath, ext, sizeof(rcspath)) >= sizeof(rcspath)) {
! 954: xfree(suffixes);
! 955: return (NULL);
1.63 niallo 956: }
1.116 ! ray 957: if ((ret = strdup(rcspath)) == NULL)
! 958: fatal("out of memory");
! 959: xfree(suffixes);
1.76 niallo 960: }
1.116 ! ray 961:
! 962: return (ret);
1.98 niallo 963: }
964:
965: /*
966: * checkin_keywordscan()
967: *
968: * Searches working file for keyword values to determine its revision
969: * number, creation date and author, and uses these values instead of
970: * calculating them locally.
971: *
972: * Params: The data buffer to scan and pointers to pointers of variables in
973: * which to store the outputs.
974: *
975: * On success, return 0. On error return -1.
976: */
977: static int
978: checkin_keywordscan(char *data, RCSNUM **rev, time_t *date, char **author,
979: char **state)
980: {
981: size_t len;
982: u_int i, j, found, end;
983: char *c, *kwstr, *start, buf[128];
984:
985: c = start = kwstr = NULL;
986:
987: i = found = 0;
988:
989: len = strlen(data);
990: for (c = data; *c != '\0' && i < len; *c++) {
991: if (*c == '$') {
992: start = c;
993: *c++;
994: if (!isalpha(*c)) {
995: c = start;
996: continue;
997: }
998: /* look for any matching keywords */
1.107 deraadt 999: found = 0;
1000: for (j = 0; j < 10; j++) {
1001: if (!strncmp(c, rcs_expkw[j].kw_str,
1002: strlen(rcs_expkw[j].kw_str))) {
1003: found = 1;
1004: kwstr = rcs_expkw[j].kw_str;
1005: break;
1006: }
1007: }
1008:
1009: /* unknown keyword, continue looking */
1010: if (found == 0) {
1011: c = start;
1012: continue;
1013: }
1.98 niallo 1014:
1015: c += strlen(kwstr);
1016: if (*c != ':' && *c != '$') {
1017: c = start;
1018: continue;
1019: }
1020:
1021: if (*c == ':') {
1022: while (*c++) {
1023: if (*c == '$') {
1024: end = c - start + 2;
1025: if (end >= sizeof(buf))
1026: fatal("keyword buffer"
1027: " too small!");
1028: strlcpy(buf, start, end);
1029: checkin_parsekeyword(buf, rev,
1.107 deraadt 1030: date, author, state);
1.98 niallo 1031: break;
1032: }
1033: }
1034:
1035: if (*c != '$') {
1036: c = start;
1037: continue;
1038: }
1039: }
1040: }
1041: }
1042: if (found == 0)
1043: return (-1);
1044: else
1045: return (0);
1046: }
1047:
1048: /*
1049: * checkin_keywordtype()
1050: *
1051: * Given an RCS keyword string, determine what type of string it is.
1052: * This enables us to know what data should be in it.
1053: *
1054: * Returns type on success, or -1 on failure.
1.107 deraadt 1055: */
1.98 niallo 1056: static int
1057: checkin_keywordtype(char *keystring)
1058: {
1059: char *p;
1.107 deraadt 1060:
1.98 niallo 1061: p = keystring;
1062: *p++;
1063: if (strncmp(p, KW_ID, strlen(KW_ID)) == 0)
1064: return (KW_TYPE_ID);
1065: else if (strncmp(p, KW_AUTHOR, strlen(KW_AUTHOR)) == 0)
1066: return (KW_TYPE_AUTHOR);
1067: else if (strncmp(p, KW_DATE, strlen(KW_DATE)) == 0)
1068: return (KW_TYPE_DATE);
1069: else if (strncmp(p, KW_STATE, strlen(KW_STATE)) == 0)
1070: return (KW_TYPE_STATE);
1071: else if (strncmp(p, KW_REVISION, strlen(KW_REVISION)) == 0)
1072: return (KW_TYPE_REVISION);
1073: else
1074: return (-1);
1075: }
1076:
1077: /*
1078: * checkin_parsekeyword()
1079: *
1080: * Do the actual parsing of an RCS keyword string, setting the values passed
1081: * to the function to whatever is found.
1082: *
1083: */
1084: static void
1085: checkin_parsekeyword(char *keystring, RCSNUM **rev, time_t *date,
1086: char **author, char **state)
1087: {
1088: char *tokens[10], *p, *datestring;
1089: size_t len = 0;
1.99 niallo 1090: int i = 0;
1.107 deraadt 1091:
1092: /* Parse data out of the expanded keyword */
1.98 niallo 1093: switch (checkin_keywordtype(keystring)) {
1094: case KW_TYPE_ID:
1.101 niallo 1095: for ((p = strtok(keystring, " ")); p;
1.107 deraadt 1096: (p = strtok(NULL, " "))) {
1.99 niallo 1097: if (i < KW_NUMTOKS_ID - 1)
1098: tokens[i++] = p;
1.107 deraadt 1099: }
1.99 niallo 1100: tokens[i] = NULL;
1.98 niallo 1101: if (*author != NULL)
1102: xfree(*author);
1103: if (*state != NULL)
1104: xfree(*state);
1105: /* only parse revision if one is not already set */
1106: if (*rev == NULL) {
1107: if ((*rev = rcsnum_parse(tokens[2])) == NULL)
1108: fatal("could not parse rcsnum");
1109: }
1110: len = strlen(tokens[5]) + 1;
1111: *author = xmalloc(len);
1112: strlcpy(*author, tokens[5], len);
1113: len = strlen(tokens[6]) + 1;
1114: *state = xmalloc(len);
1115: strlcpy(*state, tokens[6], len);
1116: len = strlen(tokens[3]) + strlen(tokens[4]) + 2;
1117: datestring = xmalloc(len);
1118: strlcpy(datestring, tokens[3], len);
1119: strlcat(datestring, " ", len);
1120: strlcat(datestring, tokens[4], len);
1121: if ((*date = cvs_date_parse(datestring)) <= 0)
1122: fatal("could not parse date\n");
1123: xfree(datestring);
1124: break;
1125: case KW_TYPE_AUTHOR:
1.101 niallo 1126: for ((p = strtok(keystring, " ")); p;
1.107 deraadt 1127: (p = strtok(NULL, " "))) {
1.99 niallo 1128: if (i < KW_NUMTOKS_AUTHOR - 1)
1129: tokens[i++] = p;
1.107 deraadt 1130: }
1.98 niallo 1131: if (*author != NULL)
1132: xfree(*author);
1133: len = strlen(tokens[1]) + 1;
1134: *author = xmalloc(len);
1135: strlcpy(*author, tokens[1], len);
1136: break;
1137: case KW_TYPE_DATE:
1.101 niallo 1138: for ((p = strtok(keystring, " ")); p;
1.107 deraadt 1139: (p = strtok(NULL, " "))) {
1.99 niallo 1140: if (i < KW_NUMTOKS_DATE - 1)
1141: tokens[i++] = p;
1.98 niallo 1142: }
1143: len = strlen(tokens[1]) + strlen(tokens[2]) + 2;
1144: datestring = xmalloc(len);
1145: strlcpy(datestring, tokens[1], len);
1146: strlcat(datestring, " ", len);
1147: strlcat(datestring, tokens[2], len);
1148: if ((*date = cvs_date_parse(datestring)) <= 0)
1149: fatal("could not parse date\n");
1150: xfree(datestring);
1151: break;
1152: case KW_TYPE_STATE:
1.101 niallo 1153: for ((p = strtok(keystring, " ")); p;
1.107 deraadt 1154: (p = strtok(NULL, " "))) {
1.99 niallo 1155: if (i < KW_NUMTOKS_STATE - 1)
1156: tokens[i++] = p;
1.107 deraadt 1157: }
1.98 niallo 1158: if (*state != NULL)
1159: xfree(*state);
1160: len = strlen(tokens[1]) + 1;
1161: *state = xmalloc(len);
1162: strlcpy(*state, tokens[1], len);
1163: break;
1164: case KW_TYPE_REVISION:
1165: /* only parse revision if one is not already set */
1166: if (*rev != NULL)
1167: break;
1.102 niallo 1168: for ((p = strtok(keystring, " ")); p;
1.107 deraadt 1169: (p = strtok(NULL, " "))) {
1.99 niallo 1170: if (i < KW_NUMTOKS_REVISION - 1)
1171: tokens[i++] = p;
1.107 deraadt 1172: }
1.98 niallo 1173: if ((*rev = rcsnum_parse(tokens[1])) == NULL)
1174: fatal("could not parse rcsnum");
1175: break;
1176: }
1.1 niallo 1177: }