Annotation of src/usr.bin/rcs/merge.c, Revision 1.2
1.2 ! xsa 1: /* $OpenBSD: merge.c,v 1.1 2006/05/10 14:28:17 xsa Exp $ */
1.1 xsa 2: /*
3: * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org>
4: * All rights reserved.
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: *
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. The name of the author may not be used to endorse or promote products
13: * derived from this software without specific prior written permission.
14: *
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
16: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18: * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25: */
26:
27: #include "includes.h"
28:
29: #include "rcsprog.h"
30: #include "diff.h"
31:
32: int
33: merge_main(int argc, char **argv)
34: {
1.2 ! xsa 35: int ch, flags, labels, status;
! 36: char *fcont;
! 37: const char *label[3];
! 38: BUF *bp;
1.1 xsa 39: extern char *optarg;
40: extern int optind;
41:
42: flags = labels = 0;
1.2 ! xsa 43: status = D_ERROR;
1.1 xsa 44:
45: /*
46: * Using getopt(3) and not rcs_getopt() because merge(1)
47: * allows spaces between options and their arguments.
48: * Thus staying compatible with former implementation.
49: */
50: while ((ch = getopt(argc, argv, "AEeL:pqV")) != -1) {
51: switch(ch) {
52: case 'A': case 'E': case 'e':
53: break;
54: case 'L':
55: if (3 <= labels)
56: errx(D_ERROR, "too many -L options");
57: label[labels++] = optarg;
58: break;
59: case 'p':
60: flags |= PIPEOUT;
61: break;
62: case 'q':
63: flags |= QUIET;
64: break;
65: case 'V':
66: printf("%s\n", rcs_version);
67: exit(0);
68: default:
69: (usage)();
70: exit(D_ERROR);
71: }
72: }
73: argc -= optind;
74: argv += optind;
75:
76: if (argc != 3) {
77: warnx("%s arguments", (argc < 3) ? "not enough" : "too many");
78: (usage)();
79: exit(D_ERROR);
80: }
81:
1.2 ! xsa 82: for (; labels < 3; labels++)
! 83: label[labels] = argv[labels];
! 84:
! 85: /* XXX handle labels */
! 86: if ((bp = merge_diff3(argv, flags)) == NULL)
! 87: errx(D_ERROR, "failed to merge");
! 88:
! 89: if (diff3_conflicts != 0)
! 90: status = D_OVERLAPS;
! 91: else
! 92: status = 0;
! 93:
! 94: if (flags & PIPEOUT) {
! 95: rcs_buf_putc(bp, '\0');
! 96: fcont = rcs_buf_release(bp);
! 97: (void)printf("%s", fcont);
! 98: xfree(fcont);
! 99: } else {
! 100: /* XXX */
! 101: if (rcs_buf_write(bp, argv[0], 0644) < 0)
! 102: warnx("rcs_buf_write failed");
! 103:
! 104: rcs_buf_free(bp);
! 105: }
! 106:
! 107: return (status);
1.1 xsa 108: }
109:
110: void
111: merge_usage(void)
112: {
113: (void)fprintf(stderr,
114: "usage: merge [-AeEpqV] [-L lab [-L lab [-L lab]]] "
115: "file1 file2 file3\n");
116: }