No empty .Rs/.Re
[netbsd-mini2440.git] / usr.bin / rcs / src / rcsmerge.c
blob0e40e528f9547dd35adef89243fc7d92222daf28
1 /*
2 * rcsmerge operation
3 */
4 #ifndef lint
5 static char rcsid[]=
6 "$Header: /pub/NetBSD/misc/repositories/cvsroot/src/usr.bin/rcs/src/Attic/rcsmerge.c,v 1.1 1993/03/21 09:58:09 cgd Exp $ Purdue CS";
7 #endif
8 /*****************************************************************************
9 * join 2 revisions with respect to a third
10 *****************************************************************************
13 /* Copyright (C) 1982, 1988, 1989 Walter Tichy
14 * All rights reserved.
16 * Redistribution and use in source and binary forms are permitted
17 * provided that the above copyright notice and this paragraph are
18 * duplicated in all such forms and that any documentation,
19 * advertising materials, and other materials related to such
20 * distribution and use acknowledge that the software was developed
21 * by Walter Tichy.
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26 * Report all problems and direct all questions to:
27 * rcs-bugs@cs.purdue.edu
40 /* $Log: rcsmerge.c,v $
41 * Revision 4.5 89/05/01 15:13:16 narten
42 * changed copyright header to reflect current distribution rules
44 * Revision 4.4 88/11/08 12:00:47 narten
45 * changes from eggert@sm.unisys.com (Paul Eggert)
47 * Revision 4.4 88/08/09 19:13:13 eggert
48 * Beware merging into a readonly file.
49 * Beware merging a revision to itself (no change).
50 * Use execv(), not system(); yield exit status like diff(1)'s.
52 * Revision 4.3 87/10/18 10:38:02 narten
53 * Updating version numbers. Changes relative to version 1.1
54 * actually relative to 4.1
56 * Revision 1.3 87/09/24 14:00:31 narten
57 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
58 * warnings)
60 * Revision 1.2 87/03/27 14:22:36 jenkins
61 * Port to suns
63 * Revision 1.1 84/01/23 14:50:36 kcs
64 * Initial revision
66 * Revision 4.1 83/03/28 11:14:57 wft
67 * Added handling of default branch.
69 * Revision 3.3 82/12/24 15:29:00 wft
70 * Added call to catchsig().
72 * Revision 3.2 82/12/10 21:32:02 wft
73 * Replaced getdelta() with gettree(); improved error messages.
75 * Revision 3.1 82/11/28 19:27:44 wft
76 * Initial revision.
79 #include "rcsbase.h"
80 #ifndef lint
81 static char rcsbaseid[] = RCSBASE;
82 #endif
83 static char co[] = CO;
84 static char merge[] = MERGE;
86 extern int cleanup(); /* cleanup after signals */
87 extern char * mktempfile(); /*temporary file name generator */
88 extern struct hshentry * genrevs(); /*generate delta numbers */
89 extern int nerror; /*counter for errors */
91 char *RCSfilename;
92 char *workfilename;
93 char * temp1file, * temp2file;
95 main (argc, argv)
96 int argc; char **argv;
98 char * cmdusage;
99 int revnums; /* counter for revision numbers given */
100 int tostdout;
101 int nochange;
102 char * rev1, * rev2; /*revision numbers*/
103 char commarg[revlength+3];
104 char numericrev[revlength]; /* holds expanded revision number */
105 struct hshentry * gendeltas[hshsize];/*stores deltas to be generated*/
106 struct hshentry * target;
108 catchints();
109 cmdid = "rcsmerge";
110 cmdusage = "command format:\n rcsmerge -p -rrev1 -rrev2 file\n rcsmerge -p -rrev1 file";
111 revnums=0;tostdout=false;nochange=false;
113 while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
114 switch ((*argv)[1]) {
115 case 'p':
116 tostdout=true;
117 /* falls into -r */
118 case 'r':
119 if ((*argv)[2]!='\0') {
120 if (revnums==0) {
121 rev1= *argv+2; revnums=1;
122 } elif (revnums==1) {
123 rev2= *argv+2; revnums=2;
124 } else {
125 faterror("too many revision numbers");
127 } /* do nothing for empty -r or -p */
128 break;
130 default:
131 faterror("unknown option: %s\n%s", *argv,cmdusage);
133 } /* end of option processing */
135 if (argc<1) faterror("No input file\n%s",cmdusage);
136 if (revnums<1) faterror("no base revision number given");
138 /* now handle all filenames */
140 if (pairfilenames(argc,argv,true,false)==1) {
142 if (argc>2 || (argc==2&&argv[1]!=nil))
143 warn("too many arguments");
144 diagnose("RCS file: %s",RCSfilename);
145 if (!(access(workfilename,tostdout?4:6)==0))
146 nowork();
148 if (!trysema(RCSfilename,false)) goto end; /* give up */
150 gettree(); /* reads in the delta tree */
152 if (Head==nil) faterror("no revisions present");
155 if (!expandsym(rev1,numericrev)) goto end;
156 if (!(target=genrevs(numericrev, (char *)nil, (char *)nil, (char *)nil,gendeltas))) goto end;
157 rev1=target->num;
158 if (revnums==1) /*get default for rev2 */
159 rev2=Dbranch!=nil?Dbranch->num:Head->num;
160 if (!expandsym(rev2,numericrev)) goto end;
161 if (!(target=genrevs(numericrev, (char *)nil, (char *)nil, (char *)nil,gendeltas))) goto end;
162 rev2=target->num;
164 if (strcmp(rev1,rev2) == 0) {
165 diagnose("Merging revision %s to itself (no change)",
166 rev1
168 nochange = true;
169 if (tostdout) {
170 FILE *w = fopen(workfilename,"r");
171 if (w==NULL)
172 nowork();
173 fastcopy(w,stdout);
175 goto end;
178 temp1file=mktempfile("/tmp/",TMPFILE1);
179 temp2file=mktempfile("/tmp/",TMPFILE2);
181 diagnose("retrieving revision %s",rev1);
182 VOID sprintf(commarg,"-p%s",rev1);
183 if (run((char*)nil,temp1file, co,"-q",commarg,RCSfilename,(char*)nil)){
184 faterror("co failed");
186 diagnose("retrieving revision %s",rev2);
187 VOID sprintf(commarg,"-p%s",rev2);
188 if (run((char*)nil,temp2file, co,"-q",commarg,RCSfilename,(char*)nil)){
189 faterror("co failed");
191 diagnose("Merging differences between %s and %s into %s%s",
192 rev1, rev2, workfilename,
193 tostdout?"; result to stdout":"");
195 if (
196 tostdout
197 ? run((char*)nil,(char*)nil,merge,"-p",workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)
198 : run((char*)nil,(char*)nil,merge, workfilename,temp1file,temp2file,workfilename,rev2,(char*)nil)) {
199 faterror("merge failed");
203 end:
204 VOID cleanup();
205 exit(2*(nerror!=0) + nochange);
210 nowork()
212 faterror("Can't open %s",workfilename);