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";
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
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
60 * Revision 1.2 87/03/27 14:22:36 jenkins
63 * Revision 1.1 84/01/23 14:50:36 kcs
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
81 static char rcsbaseid
[] = RCSBASE
;
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 */
93 char * temp1file
, * temp2file
;
96 int argc
; char **argv
;
99 int revnums
; /* counter for revision numbers given */
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
;
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]) {
119 if ((*argv
)[2]!='\0') {
121 rev1
= *argv
+2; revnums
=1;
122 } elif (revnums
==1) {
123 rev2
= *argv
+2; revnums
=2;
125 faterror("too many revision numbers");
127 } /* do nothing for empty -r or -p */
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))
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
;
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
;
164 if (strcmp(rev1
,rev2
) == 0) {
165 diagnose("Merging revision %s to itself (no change)",
170 FILE *w
= fopen(workfilename
,"r");
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":"");
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");
205 exit(2*(nerror
!=0) + nochange
);
212 faterror("Can't open %s",workfilename
);