|
|
1.1 root 1: /*
2: * RCS rcsclean operation
3: */
4: static char rcsid[]=
5: "$Header $ Purdue CS";
6: /*****************************************************************************
7: * remove unneded working files
8: *****************************************************************************
9: *
10: * Copyright (C) 1982 by Walter F. Tichy
11: * Purdue University
12: * Computer Science Department
13: * West Lafayette, IN 47907
14: *
15: * All rights reserved. No part of this software may be sold or distributed
16: * in any form or by any means without the prior written permission of the
17: * author.
18: * Report problems and direct all inquiries to Tichy@purdue (ARPA net).
19: */
20:
21:
22: /* $Log: rcsclean.c,v $
23: * Revision 4.2 87/10/18 10:30:43 narten
24: * Updating version numbers. Changes relative to 1.1 are actually
25: * relative to 4.1
26: *
27: * Revision 1.2 87/09/24 13:59:13 narten
28: * Sources now pass through lint (if you ignore printf/sprintf/fprintf
29: * warnings)
30: *
31: * Revision 1.1 84/01/23 14:50:16 kcs
32: * Initial revision
33: *
34: * Revision 4.1 83/12/15 12:26:18 wft
35: * Initial revision.
36: *
37: */
38: #include "rcsbase.h"
39: #define ERRCODE 2 /*error code for exit status */
40: static char rcsbaseid[] = RCSBASE;
41:
42: extern int cleanup(); /* cleanup after signals */
43: extern char * mktempfile(); /*temporary file name generator */
44: extern int fterror(); /*forward for special fatal error func. */
45: extern struct hshentry * genrevs(); /*generate delta numbers */
46: extern int nerror; /*counter for errors */
47: extern int quietflag; /*suppresses diagnostics */
48: extern FILE * finptr; /* RCS input file */
49: extern FILE * fopen();
50:
51: char *RCSfilename;
52: char *workfilename;
53: char * tempfile;
54: FILE * file1, * file2; /*file descriptors for comparison */
55:
56: main (argc, argv)
57: int argc; char **argv;
58: {
59: char * cmdusage;
60: char command[NCPPN+revlength+40];
61: char * rev; /* revision number from command line */
62: char numericrev[revlength]; /* holds expanded revision number */
63: int revnums; /* number of -r options */
64: struct hshentry * gendeltas[hshsize];/*stores deltas to be generated*/
65: struct hshentry * target;
66: int filecounter;
67: register int c1; /* reading input */
68: int result; /* result of comparison */
69: int pairresult; /* reulst of pairfilenames */
70:
71: catchints();
72: cmdid = "rcsclean";
73: cmdusage = "command format:\n rcsclean [-rrev] file";
74: filecounter=revnums=0;
75: quietflag=true; /* default no diagnostics */
76: while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
77: switch ((*argv)[1]) {
78: case 'r':
79: revno: if ((*argv)[2]!='\0') {
80: if (revnums==0) {
81: rev= *argv+2; revnums=1;
82: } else {
83: fterror("too many revision numbers");
84: }
85: } /* do nothing for empty -r */
86: break;
87: case 'D': /* debug option */
88: quietflag = false;
89: break;
90:
91: default:
92: fterror("unknown option: %s\n%s", *argv,cmdusage);
93: };
94: } /* end of option processing */
95:
96: if (argc<1) fterror("No input file\n%s",cmdusage);
97:
98: /* now handle all filenames */
99: do {
100: finptr=NULL;
101: pairresult=pairfilenames(argc,argv,false,false);
102:
103: if (pairresult==0) continue; /* error */
104: if (!(access(workfilename,4)==0)) {
105: diagnose("Can't open %s",workfilename);
106: continue;
107: } elsif (pairresult == -1) {
108: warn("Can't find RCS file for %s",workfilename);
109: continue;
110: }
111: diagnose("RCS file: %s",RCSfilename);
112: if (!trysema(RCSfilename,false)) continue; /* give up */
113:
114:
115: gettree(); /* reads in the delta tree */
116:
117: if (Head==nil) {
118: error("no revisions present");
119: continue;
120: }
121: if (revnums==0)
122: rev=(Dbranch!=nil?Dbranch->num:Head->num); /* default rev1 */
123:
124: if (!expandsym(rev,numericrev)) continue;
125: if (!(target=genrevs(numericrev,nil,nil,nil,gendeltas))) continue;
126:
127: tempfile=mktempfile("/tmp/",TMPFILE1);
128: diagnose("retrieving revision %s",target->num);
129: sprintf(command,"%s/co -q -p%s %s > %s\n",
130: TARGETDIR,target->num,RCSfilename,tempfile);
131: if (system(command)){
132: error("co failed");
133: continue;
134: }
135: /* now do comparison */
136: if ((file1=fopen(tempfile,"r"))==NULL) {
137: error("Can't open checked out file %s",tempfile);
138: continue;
139: }
140: if ((file2=fopen(workfilename,"r"))==NULL) {
141: error("Can't open %s",workfilename);
142: continue;
143: }
144: result=1;
145: while ((c1=getc(file1))==getc(file2)) {
146: if (c1==EOF) {
147: /* identical files; can remove working file */
148: result=0;
149: diagnose("files identical; %s removed",workfilename);
150: if (unlink(workfilename)!=0) {
151: error("Can't unlink %s",workfilename);
152: }
153: break;
154: }
155: }
156: fclose(file1); fclose(file2);
157:
158: if (result==1) diagnose ("files different");
159:
160:
161: } while (cleanup(),
162: ++argv, --argc >=1);
163:
164:
165: if (nerror>0) {
166: exit(ERRCODE);
167: } else {
168: exit(result);
169: }
170:
171: }
172:
173:
174: fterror(e, e1, e2)
175: char * e, * e1, * e2;
176: /* prints error message and terminates program with ERRCODE */
177: { nerror++;
178: VOID fprintf(stderr,"%s error: ",cmdid);
179: VOID fprintf(stderr,e, e1, e2);
180: VOID fprintf(stderr,"\n%s aborted\n",cmdid);
181: VOID cleanup();
182: exit(ERRCODE);
183: }
184:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.