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