Annotation of 43BSDReno/contrib/rcs/src/rcsclean.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *                     RCS rcsclean operation
                      3:  */
                      4: 
                      5: static char rcsid[]=
                      6: "$Header $ Purdue CS";
                      7: /*****************************************************************************
                      8:  *                       remove unneded working files
                      9:  *****************************************************************************
                     10:  */
                     11: 
                     12: /* Copyright (C) 1982, 1988, 1989 Walter Tichy
                     13:  * All rights reserved.
                     14:  *
                     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
                     20:  * by Walter Tichy.
                     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.
                     24:  *
                     25:  * Report all problems and direct all questions to:
                     26:  *   [email protected]
                     27:  * 
                     28: 
                     29: 
                     30: 
                     31: 
                     32: 
                     33: 
                     34: 
                     35: */
                     36: 
                     37: 
                     38: 
                     39: 
                     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
                     43:  * 
                     44:  * Revision 4.3  88/11/08  15:59:54  narten
                     45:  * removed reference to TARGETDIR
                     46:  * 
                     47:  * Revision 4.2  87/10/18  10:30:43  narten
                     48:  * Updating version numbers. Changes relative to 1.1 are actually
                     49:  * relative to 4.1
                     50:  * 
                     51:  * Revision 1.2  87/09/24  13:59:13  narten
                     52:  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
                     53:  * warnings)
                     54:  * 
                     55:  * Revision 1.1  84/01/23  14:50:16  kcs
                     56:  * Initial revision
                     57:  * 
                     58:  * Revision 4.1  83/12/15  12:26:18  wft
                     59:  * Initial revision.
                     60:  * 
                     61:  */
                     62: #include "rcsbase.h"
                     63: #define ERRCODE 2                   /*error code for exit status            */
                     64: static char rcsbaseid[] = RCSBASE;
                     65: 
                     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();
                     74: 
                     75: char *RCSfilename;
                     76: char *workfilename;
                     77: char * tempfile;
                     78: FILE * file1, * file2;              /*file descriptors for comparison       */
                     79: 
                     80: main (argc, argv)
                     81: int argc; char **argv;
                     82: {
                     83:         char * cmdusage;
                     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;
                     90:         int  filecounter;
                     91:        register int c1;              /* reading input                      */
                     92:        int  result;                  /* result of comparison               */
                     93:        int pairresult;               /* reulst of pairfilenames            */
                     94: 
                     95:         catchints();
                     96:        cmdid = "rcsclean";
                     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]) {
                    102:                 case 'r':
                    103:                revno:  if ((*argv)[2]!='\0') {
                    104:                             if (revnums==0) {
                    105:                                    rev= *argv+2; revnums=1;
                    106:                             } else {
                    107:                                    fterror("too many revision numbers");
                    108:                             }
                    109:                         } /* do nothing for empty -r */
                    110:                         break;
                    111:                case 'D': /* debug option */
                    112:                        quietflag = false;
                    113:                        break;
                    114: 
                    115:                 default:
                    116:                        fterror("unknown option: %s\n%s", *argv,cmdusage);
                    117:                 };
                    118:         } /* end of option processing */
                    119: 
                    120:        if (argc<1) fterror("No input file\n%s",cmdusage);
                    121: 
                    122:         /* now handle all filenames */
                    123:         do {
                    124:                 finptr=NULL;
                    125:                pairresult=pairfilenames(argc,argv,false,false);
                    126: 
                    127:                if (pairresult==0) continue; /* error */
                    128:                if (!(access(workfilename,4)==0)) {
                    129:                        diagnose("Can't open %s",workfilename);
                    130:                         continue;
                    131:                } elsif (pairresult == -1) {
                    132:                        warn("Can't find RCS file for %s",workfilename);
                    133:                        continue;
                    134:                }
                    135:                 diagnose("RCS file: %s",RCSfilename);
                    136:                 if (!trysema(RCSfilename,false)) continue; /* give up */
                    137: 
                    138: 
                    139:                 gettree(); /* reads in the delta tree */
                    140: 
                    141:                 if (Head==nil) {
                    142:                         error("no revisions present");
                    143:                         continue;
                    144:                 }
                    145:                 if (revnums==0)
                    146:                        rev=(Dbranch!=nil?Dbranch->num:Head->num); /* default rev1 */
                    147: 
                    148:                if (!expandsym(rev,numericrev)) continue;
                    149:                 if (!(target=genrevs(numericrev,nil,nil,nil,gendeltas))) continue;
                    150: 
                    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)){
                    156:                         error("co failed");
                    157:                         continue;
                    158:                 }
                    159:                /* now do comparison */
                    160:                if ((file1=fopen(tempfile,"r"))==NULL) {
                    161:                        error("Can't open checked out file %s",tempfile);
                    162:                        continue;
                    163:                }
                    164:                if ((file2=fopen(workfilename,"r"))==NULL) {
                    165:                        error("Can't open %s",workfilename);
                    166:                        continue;
                    167:                }
                    168:                result=1;
                    169:                while ((c1=getc(file1))==getc(file2)) {
                    170:                        if (c1==EOF) {
                    171:                                /* identical files; can remove working file */
                    172:                                result=0;
                    173:                                diagnose("files identical; %s removed",workfilename);
                    174:                                if (unlink(workfilename)!=0) {
                    175:                                        error("Can't unlink %s",workfilename);
                    176:                                }
                    177:                                break;
                    178:                        }
                    179:                }
                    180:                fclose(file1); fclose(file2);
                    181: 
                    182:                if (result==1) diagnose ("files different");
                    183: 
                    184: 
                    185:         } while (cleanup(),
                    186:                  ++argv, --argc >=1);
                    187: 
                    188: 
                    189:        if (nerror>0) {
                    190:                exit(ERRCODE);
                    191:        } else {
                    192:                exit(result);
                    193:        }
                    194: 
                    195: }
                    196: 
                    197: 
                    198: fterror(e, e1, e2)
                    199: char * e, * e1, * e2;
                    200: /* prints error message and terminates program with ERRCODE */
                    201: {       nerror++;
                    202:         VOID fprintf(stderr,"%s error: ",cmdid);
                    203:        VOID fprintf(stderr,e, e1, e2);
                    204:         VOID fprintf(stderr,"\n%s aborted\n",cmdid);
                    205:         VOID cleanup();
                    206:        exit(ERRCODE);
                    207: }
                    208: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.