xref: /dragonfly/gnu/usr.bin/rcs/merge/merge.c (revision 984263bc)
1 /* merge - three-way file merge */
2 
3 /* Copyright 1991, 1992, 1993, 1994, 1995 Paul Eggert
4    Distributed under license by the Free Software Foundation, Inc.
5 
6 This file is part of RCS.
7 
8 RCS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12 
13 RCS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with RCS; see the file COPYING.
20 If not, write to the Free Software Foundation,
21 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23 Report problems and direct all questions to:
24 
25     rcs-bugs@cs.purdue.edu
26 
27 */
28 
29 #include "rcsbase.h"
30 
31 static void badoption P((char const*));
32 
33 static char const usage[] =
34  "\nmerge: usage: merge [-AeEpqxX3] [-L lab [-L lab [-L lab]]] file1 file2 file3";
35 
36 	static void
37 badoption(a)
38 	char const *a;
39 {
40 	error("unknown option: %s%s", a, usage);
41 }
42 
43 
44 mainProg(mergeId, "merge", "$FreeBSD: src/gnu/usr.bin/rcs/merge/merge.c,v 1.5 1999/08/27 23:36:51 peter Exp $")
45 {
46 	register char const *a;
47 	char const *arg[3], *label[3], *edarg = 0;
48 	int labels, tostdout;
49 
50 	labels = 0;
51 	tostdout = false;
52 
53 	for (;  (a = *++argv)  &&  *a++ == '-';  --argc) {
54 		switch (*a++) {
55 			case 'A': case 'E': case 'e':
56 				if (edarg  &&  edarg[1] != (*argv)[1])
57 					error("%s and %s are incompatible",
58 						edarg, *argv
59 					);
60 				edarg = *argv;
61 				break;
62 
63 			case 'p': tostdout = true; break;
64 			case 'q': quietflag = true; break;
65 
66 			case 'L':
67 				if (3 <= labels)
68 					faterror("too many -L options");
69 				if (!(label[labels++] = *++argv))
70 					faterror("-L needs following argument");
71 				--argc;
72 				break;
73 
74 			case 'V':
75 				printf("RCS version %s\n", RCS_version_string);
76 				exitmain(0);
77 
78 			default:
79 				badoption(a - 2);
80 				continue;
81 		}
82 		if (*a)
83 			badoption(a - 2);
84 	}
85 
86 	if (argc != 4)
87 		faterror("%s arguments%s",
88 			argc<4 ? "not enough" : "too many",  usage
89 		);
90 
91 	/* This copy keeps us `const'-clean.  */
92 	arg[0] = argv[0];
93 	arg[1] = argv[1];
94 	arg[2] = argv[2];
95 
96 	for (;  labels < 3;  labels++)
97 		label[labels] = arg[labels];
98 
99 	if (nerror)
100 		exiterr();
101 	exitmain(merge(tostdout, edarg, label, arg));
102 }
103 
104 
105 #if RCS_lint
106 #	define exiterr mergeExit
107 #endif
108 	void
109 exiterr()
110 {
111 	tempunlink();
112 	_exit(DIFF_TROUBLE);
113 }
114