home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OS9000 / APPS / rcs.lzh / rcs1 / rcsclean.c < prev    next >
Text File  |  1996-04-20  |  7KB  |  233 lines

  1. /*
  2.  *                     RCS rcsclean operation
  3.  */
  4.  
  5. static char rcsid[]=
  6. "$Id: rcsclean.c_v 1.1 93/04/02 01:28:12 hiro Exp $ Purdue CS";
  7. /*****************************************************************************
  8.  *                       remove unneded working files
  9.  *****************************************************************************
  10.  */
  11.  
  12. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  13.    Distributed under license by the Free Software Foundation, Inc.
  14.  
  15. This file is part of RCS.
  16.  
  17. RCS is free software; you can redistribute it and/or modify
  18. it under the terms of the GNU General Public License as published by
  19. the Free Software Foundation; either version 1, or (at your option)
  20. any later version.
  21.  
  22. RCS is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  25. GNU General Public License for more details.
  26.  
  27. You should have received a copy of the GNU General Public License
  28. along with RCS; see the file COPYING.  If not, write to
  29. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  30.  
  31. Report problems and direct all questions to:
  32.  
  33.     rcs-bugs@cs.purdue.edu
  34.  
  35. */
  36.  
  37.  
  38.  
  39.  
  40. /* $Log:    rcsclean.c_v $
  41.  * Revision 1.1  93/04/02  01:28:12  hiro
  42.  * Initial revision
  43.  * 
  44.  * Revision 1.1  90/07/19  15:20:57  momo
  45.  * Initial revision
  46.  * 
  47.  * Revision 4.4  89/05/01  15:12:21  narten
  48.  * changed copyright header to reflect current distribution rules
  49.  * 
  50.  * Revision 4.3  88/11/08  15:59:54  narten
  51.  * removed reference to TARGETDIR
  52.  * 
  53.  * Revision 4.2  87/10/18  10:30:43  narten
  54.  * Updating version numbers. Changes relative to 1.1 are actually
  55.  * relative to 4.1
  56.  * 
  57.  * Revision 1.2  87/09/24  13:59:13  narten
  58.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  59.  * warnings)
  60.  * 
  61.  * Revision 1.1  84/01/23  14:50:16  kcs
  62.  * Initial revision
  63.  * 
  64.  * Revision 4.1  83/12/15  12:26:18  wft
  65.  * Initial revision.
  66.  * 
  67.  */
  68. #include "rcsbase.h"
  69. #define ERRCODE 2                   /*error code for exit status            */
  70. static char rcsbaseid[] = RCSBASE;
  71.  
  72. extern int    cleanup();            /* cleanup after signals                */
  73. extern char * mktempfile();         /*temporary file name generator         */
  74. extern int    fterror();            /*forward for special fatal error func. */
  75. extern struct hshentry * genrevs(); /*generate delta numbers                */
  76. extern int    nerror;               /*counter for errors                    */
  77. extern int    quietflag;            /*suppresses diagnostics                */
  78. extern FILE * finptr;               /* RCS input file                       */
  79. extern FILE * fopen();
  80.  
  81. #if defined(MSDOS) || defined(OSK)
  82. extern char *gettmpdir();
  83. char tmpdir[NCPPN];
  84. #endif /* MSDOS */
  85.  
  86. char *RCSfilename;
  87. char *workfilename;
  88. char * tempfile;
  89. FILE * file1, * file2;              /*file descriptors for comparison       */
  90.  
  91. main (argc, argv)
  92. int argc; char **argv;
  93. {
  94.         char * cmdusage;
  95.         char command[NCPPN+revlength+40];
  96.     char * rev;                   /* revision number from command line  */
  97.         char numericrev[revlength];   /* holds expanded revision number     */
  98.     int  revnums;                 /* number of -r options               */
  99.         struct hshentry * gendeltas[hshsize];/*stores deltas to be generated*/
  100.         struct hshentry * target;
  101.         int  filecounter;
  102.     register int c1;              /* reading input                      */
  103.     int  result;                  /* result of comparison               */
  104.     int pairresult;               /* reulst of pairfilenames            */
  105.  
  106.         catchints();
  107.     cmdid = "rcsclean";
  108.     cmdusage = "command format:\n    rcsclean [-rrev] file";
  109.         filecounter=revnums=0;
  110.     quietflag=true; /* default no diagnostics */
  111.         while (--argc,++argv, argc>=1 && ((*argv)[0] == '-')) {
  112.                 switch ((*argv)[1]) {
  113.                 case 'r':
  114.         revno:  if ((*argv)[2]!='\0') {
  115.                             if (revnums==0) {
  116.                     rev= *argv+2; revnums=1;
  117.                             } else {
  118.                     fterror("too many revision numbers");
  119.                             }
  120.                         } /* do nothing for empty -r */
  121.                         break;
  122.         case 'D': /* debug option */
  123.             quietflag = false;
  124.             break;
  125.  
  126.                 default:
  127.             fterror("unknown option: %s\n%s", *argv,cmdusage);
  128.                 };
  129.         } /* end of option processing */
  130.  
  131.     if (argc<1) fterror("No input file\n%s",cmdusage);
  132.  
  133. #if defined(MSDOS) || defined(OSK)
  134.     strcpy( tmpdir, gettmpdir() );
  135. #endif /* MSDOS */
  136.  
  137.         /* now handle all filenames */
  138.         do {
  139.                 finptr=NULL;
  140.         pairresult=pairfilenames(argc,argv,false,false);
  141.  
  142.         if (pairresult==0) continue; /* error */
  143.         if (!(access(workfilename,4)==0)) {
  144.             diagnose("Can't open %s",workfilename);
  145.                         continue;
  146.         } elsif (pairresult == -1) {
  147.             warn("Can't find RCS file for %s",workfilename);
  148.             continue;
  149.         }
  150.                 diagnose("RCS file: %s",RCSfilename);
  151.                 if (!trysema(RCSfilename,false)) continue; /* give up */
  152.  
  153.  
  154.                 gettree(); /* reads in the delta tree */
  155.  
  156.                 if (Head==nil) {
  157.                         error("no revisions present");
  158.                         continue;
  159.                 }
  160.                 if (revnums==0)
  161.             rev=(Dbranch!=nil?Dbranch->num:Head->num); /* default rev1 */
  162.  
  163.         if (!expandsym(rev,numericrev)) continue;
  164.                 if (!(target=genrevs(numericrev,nil,nil,nil,gendeltas))) continue;
  165.  
  166. #if defined(MSDOS) || defined(OSK)
  167.         tempfile=mktempfile( tmpdir ,TMPFILE1);
  168. #else
  169.         tempfile=mktempfile("/tmp/",TMPFILE1);
  170. #endif /* MSDOS */
  171.         diagnose("retrieving revision %s",target->num);
  172.                 VOID sprintf(command,"%s -q -p%s %s > %s\n",
  173.             CO ,target->num,RCSfilename,tempfile);
  174.                 if (system(command)){
  175.                         error("co failed");
  176.                         continue;
  177.                 }
  178.         /* now do comparison */
  179.         if ((file1=fopen(tempfile,"r"))==NULL) {
  180.             error("Can't open checked out file %s",tempfile);
  181.             continue;
  182.         }
  183.         if ((file2=fopen(workfilename,"r"))==NULL) {
  184.             error("Can't open %s",workfilename);
  185.             continue;
  186.         }
  187.         result=1;
  188.         while ((c1=getc(file1))==getc(file2)) {
  189.             if (c1==EOF) {
  190.                 /* identical files; can remove working file */
  191.                 result=0;
  192.                 diagnose("files identical; %s removed",workfilename);
  193. #ifdef OSK
  194.                 fclose(file1); fclose(file2);
  195. #endif
  196.                 if (unlink(workfilename)!=0) {
  197.                     error("Can't unlink %s",workfilename);
  198.                 }
  199.                 break;
  200.             }
  201.         }
  202. #ifndef OSK
  203.         fclose(file1); fclose(file2);
  204. #endif
  205.  
  206.         if (result==1) diagnose ("files different");
  207.  
  208.  
  209.         } while (cleanup(),
  210.                  ++argv, --argc >=1);
  211.  
  212.  
  213.     if (nerror>0) {
  214.         exit(ERRCODE);
  215.     } else {
  216.         exit(result);
  217.     }
  218.  
  219. }
  220.  
  221.  
  222. fterror(e, e1, e2)
  223. char * e, * e1, * e2;
  224. /* prints error message and terminates program with ERRCODE */
  225. {       nerror++;
  226.         VOID fprintf(stderr,"%s error: ",cmdid);
  227.     VOID fprintf(stderr,e, e1, e2);
  228.         VOID fprintf(stderr,"\n%s aborted\n",cmdid);
  229.         VOID cleanup();
  230.     exit(ERRCODE);
  231. }
  232.  
  233.