2 * RCS rcsclean operation
7 /*****************************************************************************
8 * remove unneded working files
9 *****************************************************************************
12 /* Copyright (C) 1982, 1988, 1989 Walter Tichy
13 * All rights reserved.
15 * Redistribution and use in source and binary forms are permitted
16 * provided that the above copyright notice and this paragraph are
17 * duplicated in all such forms and that any documentation,
18 * advertising materials, and other materials related to such
19 * distribution and use acknowledge that the software was developed
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25 * Report all problems and direct all questions to:
26 * rcs-bugs@cs.purdue.edu
40 /* $Log: rcsclean.c,v $
41 * Revision 4.4 89/05/01 15:12:21 narten
42 * changed copyright header to reflect current distribution rules
44 * Revision 4.3 88/11/08 15:59:54 narten
45 * removed reference to TARGETDIR
47 * Revision 4.2 87/10/18 10:30:43 narten
48 * Updating version numbers. Changes relative to 1.1 are actually
51 * Revision 1.2 87/09/24 13:59:13 narten
52 * Sources now pass through lint (if you ignore printf/sprintf/fprintf
55 * Revision 1.1 84/01/23 14:50:16 kcs
58 * Revision 4.1 83/12/15 12:26:18 wft
63 #define ERRCODE 2 /*error code for exit status */
64 static char rcsbaseid
[] = RCSBASE
;
66 extern int cleanup(); /* cleanup after signals */
67 extern char * mktempfile(); /*temporary file name generator */
68 extern int fterror(); /*forward for special fatal error func. */
69 extern struct hshentry
* genrevs(); /*generate delta numbers */
70 extern int nerror
; /*counter for errors */
71 extern int quietflag
; /*suppresses diagnostics */
72 extern FILE * finptr
; /* RCS input file */
73 extern FILE * fopen();
78 FILE * file1
, * file2
; /*file descriptors for comparison */
81 int argc
; char **argv
;
84 char command
[NCPPN
+revlength
+40];
85 char * rev
; /* revision number from command line */
86 char numericrev
[revlength
]; /* holds expanded revision number */
87 int revnums
; /* number of -r options */
88 struct hshentry
* gendeltas
[hshsize
];/*stores deltas to be generated*/
89 struct hshentry
* target
;
91 register int c1
; /* reading input */
92 int result
; /* result of comparison */
93 int pairresult
; /* reulst of pairfilenames */
97 cmdusage
= "command format:\n rcsclean [-rrev] file";
98 filecounter
=revnums
=0;
99 quietflag
=true; /* default no diagnostics */
100 while (--argc
,++argv
, argc
>=1 && ((*argv
)[0] == '-')) {
101 switch ((*argv
)[1]) {
103 revno
: if ((*argv
)[2]!='\0') {
105 rev
= *argv
+2; revnums
=1;
107 fterror("too many revision numbers");
109 } /* do nothing for empty -r */
111 case 'D': /* debug option */
116 fterror("unknown option: %s\n%s", *argv
,cmdusage
);
118 } /* end of option processing */
120 if (argc
<1) fterror("No input file\n%s",cmdusage
);
122 /* now handle all filenames */
125 pairresult
=pairfilenames(argc
,argv
,false,false);
127 if (pairresult
==0) continue; /* error */
128 if (!(access(workfilename
,4)==0)) {
129 diagnose("Can't open %s",workfilename
);
131 } elsif (pairresult
== -1) {
132 warn("Can't find RCS file for %s",workfilename
);
135 diagnose("RCS file: %s",RCSfilename
);
136 if (!trysema(RCSfilename
,false)) continue; /* give up */
139 gettree(); /* reads in the delta tree */
142 error("no revisions present");
146 rev
=(Dbranch
!=nil
?Dbranch
->num
:Head
->num
); /* default rev1 */
148 if (!expandsym(rev
,numericrev
)) continue;
149 if (!(target
=genrevs(numericrev
,nil
,nil
,nil
,gendeltas
))) continue;
151 tempfile
=mktempfile("/tmp/",TMPFILE1
);
152 diagnose("retrieving revision %s",target
->num
);
153 VOID
sprintf(command
,"%s -q -p%s %s > %s\n",
154 CO
,target
->num
,RCSfilename
,tempfile
);
155 if (system(command
)){
159 /* now do comparison */
160 if ((file1
=fopen(tempfile
,"r"))==NULL
) {
161 error("Can't open checked out file %s",tempfile
);
164 if ((file2
=fopen(workfilename
,"r"))==NULL
) {
165 error("Can't open %s",workfilename
);
169 while ((c1
=getc(file1
))==getc(file2
)) {
171 /* identical files; can remove working file */
173 diagnose("files identical; %s removed",workfilename
);
174 if (unlink(workfilename
)!=0) {
175 error("Can't unlink %s",workfilename
);
180 fclose(file1
); fclose(file2
);
182 if (result
==1) diagnose ("files different");
199 char * e
, * e1
, * e2
;
200 /* prints error message and terminates program with ERRCODE */
202 VOID
fprintf(stderr
,"%s error: ",cmdid
);
203 VOID
fprintf(stderr
,e
, e1
, e2
);
204 VOID
fprintf(stderr
,"\n%s aborted\n",cmdid
);