home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / RCS_SRC.ZIP / SNOOP.C < prev    next >
C/C++ Source or Header  |  1991-01-15  |  4KB  |  126 lines

  1. /*
  2.  *                     Logging of RCS commands co and ci
  3.  */
  4. #ifndef lint
  5.  static char rcsid[]=
  6.  "$Header: /usr/src/local/bin/rcs/src/RCS/snoop.c,v 4.4 89/05/01 15:14:00 narten Exp $ Purdue CS";
  7. #endif
  8. /*******************************************************************
  9.  * This program appends argv[1] to the file SNOOPFILE.
  10.  * To avoid overlaps, it creates a lockfile with name lock in the same
  11.  * directory as SNOOPFILE. SNOOPFILE must be defined in the cc command. 
  12.  * Prints an error message if lockfile doesn't get deleted after
  13.  * MAXTRIES tries.
  14.  *******************************************************************
  15.  */
  16.  
  17. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  18.    Distributed under license by the Free Software Foundation, Inc.
  19.  
  20. This file is part of RCS.
  21.  
  22. RCS is free software; you can redistribute it and/or modify
  23. it under the terms of the GNU General Public License as published by
  24. the Free Software Foundation; either version 1, or (at your option)
  25. any later version.
  26.  
  27. RCS is distributed in the hope that it will be useful,
  28. but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30. GNU General Public License for more details.
  31.  
  32. You should have received a copy of the GNU General Public License
  33. along with RCS; see the file COPYING.  If not, write to
  34. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  35.  
  36. Report problems and direct all questions to:
  37.  
  38.     rcs-bugs@cs.purdue.edu
  39.  
  40. */
  41.  
  42.  
  43. /* $Log:    snoop.c,v $
  44.  * Revision 4.4  89/05/01  15:14:00  narten
  45.  * changed copyright header to reflect current distribution rules
  46.  * 
  47.  * Revision 4.3  87/12/18  11:46:52  narten
  48.  * more lint cleanups (Guy Harris)
  49.  * 
  50.  * Revision 4.2  87/10/18  10:41:47  narten
  51.  * Changing version numbers. Changes relative to 1.1 actually relative to 
  52.  * 4.1
  53.  * 
  54.  * Revision 1.2  87/09/24  14:01:41  narten
  55.  * Sources now pass through lint (if you ignore printf/sprintf/fprintf 
  56.  * warnings)
  57.  * 
  58.  * Revision 1.1  84/01/23  14:50:49  kcs
  59.  * Initial revision
  60.  * 
  61.  * Revision 4.1  83/03/28  13:23:42  wft
  62.  * No change; just new revision number.
  63.  * 
  64.  * Revision 3.2  82/12/04  17:14:31  wft
  65.  * Added rcsbase.h, changed SNOOPDIR to SNOOPFILE, reintroduced
  66.  * error message in case of permanent locking.
  67.  * 
  68.  * Revision 3.1  82/10/18  21:22:03  wft
  69.  * Number of polls now 20, no error message if critical section can't
  70.  * be entered.
  71.  * 
  72.  * Revision 2.3  82/07/01  23:49:28  wft
  73.  * changed copyright notice only.
  74.  * 
  75.  * Revision 2.2  82/06/03  20:00:10  wft
  76.  * changed name from rcslog to snoop, replaced LOGDIR with SNOOPDIR.
  77.  * 
  78.  * Revision 2.1  82/05/06  17:55:54  wft
  79.  * Initial revision
  80.  *
  81.  */
  82.  
  83.  
  84. #include "rcsbase.h"
  85. #define fflsbuf _flsbuf
  86. /* undo redefinition of putc in rcsbase.h */
  87.  
  88. char  lockfname[NCPPN];
  89. FILE * logfile;
  90. int lockfile;
  91.  
  92. #define MAXTRIES 20
  93.  
  94. main(argc,argv)
  95. int argc; char * argv[];
  96. /* writes argv[1] to SNOOPFILE and appends a newline. Invoked as follows:
  97.  * rcslog logmessage
  98.  */
  99. {       int tries;
  100.         register char * lastslash, *sp;
  101.  
  102.         VOID strcpy(lockfname,(char *) SNOOPFILE);
  103.         lastslash = sp = lockfname;
  104.         while (*sp) if (*sp++ =='/') lastslash=sp; /* points beyond / */
  105.         VOID strcpy(lastslash,",lockfile");
  106.         tries=0;
  107.         while (((lockfile=creat(lockfname, 000)) == -1) && (tries<=MAXTRIES)) {
  108.                 tries++;
  109.                 sleep(5);
  110.         }
  111.         if (tries<=MAXTRIES) {
  112.                 VOID close(lockfile);
  113.                 if ((logfile=fopen(SNOOPFILE,"a")) ==NULL) {
  114.                         VOID fprintf(stderr,"Can't open logfile %s\n",SNOOPFILE);
  115.                 } else {
  116.                         VOID fputs(argv[1],logfile);
  117.                         VOID putc('\n',logfile);
  118.                         VOID fclose(logfile);
  119.                 }
  120.                 VOID unlink(lockfname);
  121.         } else {
  122.                 VOID fprintf(stderr,"RCS logfile %s seems permanently locked.\n",SNOOPFILE);
  123.                 VOID fprintf(stderr,"Please alert system administrator\n");
  124.         }
  125. }
  126.