Annotation of src/usr.bin/rcs/merge.c, Revision 1.8
1.8 ! otto 1: /* $OpenBSD: merge.c,v 1.7 2010/07/23 21:46:05 ray 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:
1.5 xsa 27: #include <err.h>
28: #include <stdio.h>
29: #include <stdlib.h>
30: #include <unistd.h>
1.1 xsa 31:
32: #include "rcsprog.h"
33: #include "diff.h"
34:
35: int
36: merge_main(int argc, char **argv)
37: {
1.2 xsa 38: int ch, flags, labels, status;
39: const char *label[3];
40: BUF *bp;
1.1 xsa 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) {
1.4 xsa 52: case 'A':
53: /*
54: * kept for compatibility
55: */
56: break;
57: case 'E':
58: flags |= MERGE_EFLAG;
59: flags |= MERGE_OFLAG;
60: break;
61: case 'e':
62: flags |= MERGE_EFLAG;
1.1 xsa 63: break;
64: case 'L':
65: if (3 <= labels)
66: errx(D_ERROR, "too many -L options");
67: label[labels++] = optarg;
68: break;
69: case 'p':
70: flags |= PIPEOUT;
71: break;
72: case 'q':
73: flags |= QUIET;
74: break;
75: case 'V':
76: printf("%s\n", rcs_version);
77: exit(0);
78: default:
79: (usage)();
80: }
81: }
82: argc -= optind;
83: argv += optind;
84:
85: if (argc != 3) {
86: warnx("%s arguments", (argc < 3) ? "not enough" : "too many");
87: (usage)();
88: }
89:
1.2 xsa 90: for (; labels < 3; labels++)
91: label[labels] = argv[labels];
92:
93: /* XXX handle labels */
94: if ((bp = merge_diff3(argv, flags)) == NULL)
95: errx(D_ERROR, "failed to merge");
96:
97: if (diff3_conflicts != 0)
98: status = D_OVERLAPS;
99: else
100: status = 0;
101:
1.3 ray 102: if (flags & PIPEOUT)
1.7 ray 103: buf_write_fd(bp, STDOUT_FILENO);
1.3 ray 104: else {
1.2 xsa 105: /* XXX */
1.7 ray 106: if (buf_write(bp, argv[0], 0644) < 0)
107: warnx("buf_write failed");
1.2 xsa 108: }
1.7 ray 109: buf_free(bp);
1.2 xsa 110:
111: return (status);
1.1 xsa 112: }
113:
1.8 ! otto 114: __dead void
1.1 xsa 115: merge_usage(void)
116: {
117: (void)fprintf(stderr,
1.6 sobrado 118: "usage: merge [-EepqV] [-L label] file1 file2 file3\n");
1.8 ! otto 119:
! 120: exit(D_ERROR);
1.1 xsa 121: }