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